Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm - OIDC delete-expired-clients #115

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 57 additions & 13 deletions gen3-integration-tests/utils/gen3_admin_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

load_dotenv()

fence_delete_clients_logs = ""


def get_portal_config():
"""Fetch portal config from the GUI"""
Expand Down Expand Up @@ -169,21 +171,57 @@ def run_gen3_job(
raise Exception("Build number not found")
# Local Helm Deployments
elif os.getenv("GEN3_INSTANCE_TYPE") == "HELM_LOCAL":
# job_pod = f"{job_name}-{uuid.uuid4()}"
cmd = ["kubectl", "delete", "job", job_name]
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if not result.returncode == 0:
logger.info(
f"Unable to delete {job_name} - {result.stderr.decode('utf-8')}"
if job_name == "fence-delete-expired-clients":
global fence_delete_clients_logs
# Get the pod name for fence app
cmd = ["kubectl", "get", "pods", "-l", "app=fence"]
result = subprocess.run(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
cmd = ["kubectl", "create", "job", f"--from=cronjob/{job_name}", job_name]
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
logger.info(f"{job_name} job triggered - {result.stdout.decode('utf-8')}")
else:
raise Exception(
f"{job_name} failed to start - {result.stderr.decode('utf-8')}"
if result.returncode == 0:
fence_pod_name = result.stdout.splitlines()[-1].split()[0]
krishnaa05 marked this conversation as resolved.
Show resolved Hide resolved
else:
raise Exception("Unable to retrieve fence-deployment pod")
# Delete expired clients
delete_explired_clients_cmd = [
"kubectl",
"exec",
"-it",
krishnaa05 marked this conversation as resolved.
Show resolved Hide resolved
fence_pod_name,
"--",
"fence-create",
"client-delete-expired",
]
delete_explired_client_result = subprocess.run(
delete_explired_clients_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
timeout=10,
)
fence_delete_clients_logs = delete_explired_client_result.stdout.strip()
if not result.returncode == 0:
raise Exception(
f"Unable to delete expired clients. Response: {delete_explired_client_result.stderr.strip()}"
)
else:
# job_pod = f"{job_name}-{uuid.uuid4()}"
cmd = ["kubectl", "delete", "job", job_name]
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if not result.returncode == 0:
logger.info(
f"Unable to delete {job_name} - {result.stderr.decode('utf-8')}"
)
cmd = ["kubectl", "create", "job", f"--from=cronjob/{job_name}", job_name]
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
logger.info(
f"{job_name} job triggered - {result.stdout.decode('utf-8')}"
)
else:
raise Exception(
f"{job_name} failed to start - {result.stderr.decode('utf-8')}"
)


def check_job_pod(
Expand Down Expand Up @@ -218,6 +256,12 @@ def check_job_pod(
raise Exception("Build number not found")
# Local Helm Deployments
elif os.getenv("GEN3_INSTANCE_TYPE") == "HELM_LOCAL":
if job_name == "fence-delete-expired-clients":
"""
We dont need to validate it on local helm as command
is run directly and not in a job.
"""
return {"logs.txt": fence_delete_clients_logs}
# Wait for the job pod to start
cmd = [
"kubectl",
Expand Down
Loading