From 7283efecfaab83c480ed73edd55ed5c3052dceb2 Mon Sep 17 00:00:00 2001 From: Ajo Augustine Date: Tue, 11 Jun 2024 15:41:29 -0500 Subject: [PATCH] feat/check and update fence jobs (#2564) * check and update image for fence jobs * check and update image for fence jobs * Update gitops.sh * Update gitops.sh * Update gitops.sh * update-fence-cronjobs added to gitops.sh * update gitops.sh documentation --- doc/gitops.md | 7 +++++++ gen3/bin/gitops.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/doc/gitops.md b/doc/gitops.md index 64c30597b..e860fb390 100644 --- a/doc/gitops.md +++ b/doc/gitops.md @@ -176,3 +176,10 @@ It takes a module as argument, like: vpc, eks. ``` gen3 gitops tfapply eks ``` + +### update-fence-cronjobs +Checks and updates the image for specific fence-related cronjobs (`fence-delete-expired-clients` and `fence-cleanup-expired-ga4gh-info`), if they do not match the image specified in the `manifest-versions` ConfigMap. + +``` +gen3 gitops update-fence-cronjobs +``` diff --git a/gen3/bin/gitops.sh b/gen3/bin/gitops.sh index bc0358499..975cf6e0d 100644 --- a/gen3/bin/gitops.sh +++ b/gen3/bin/gitops.sh @@ -461,7 +461,7 @@ gen3_gitops_sync() { # update fence ConfigMap before roll-all if [[ "$fence_roll" = true ]]; then gen3 update_config manifest-fence "$(gen3 gitops folder)/manifests/fence/fence-config-public.yaml" - fi + fi if [[ "$covid_cronjob_roll" = true ]]; then if g3k_config_lookup '.global."covid19_data_bucket"'; then @@ -503,6 +503,10 @@ gen3_gitops_sync() { fi curl -X POST --data-urlencode "payload={\"text\": \"Gitops-sync Cron: ${resStr} - Syncing dict and images on ${tmpHostname}\", \"attachments\": [{${dictAttachment}}, {${versionsAttachment}}, {${portalAttachment}}, {${fenceAttachment}}, {${etlAttachment}}, {${covidAttachment}}]}" "${slackWebHook}" fi + # update fence jobs + if [[ "$versions_roll" = true ]]; then + gen3_gitops_update_fence_cron_jobs + fi else echo "no changes detected, not rolling" fi @@ -527,6 +531,43 @@ gen3_gitops_rsync() { ssh "$target" "bash -ic 'gen3 gitops sync'" } +# +# Update fence cronjobs +# +gen3_gitops_update_fence_cron_jobs() { + # Fetch the manifest-versions ConfigMap and extract the fence image + local fence_manifest_image=$(kubectl get cm manifest-versions -o jsonpath='{.data.fence}') + + # List of fence-related cronjobs + local fence_cronjobs=("fence-delete-expired-clients" "fence-cleanup-expired-ga4gh-info") + + # Function to check and update cronjobs + update_cronjob() { + local cronjob_name=$1 + local manifest_image=$2 + + gen3_log_info "Checking cronjob $cronjob_name..." + + # Extract cronjob schedule directly using kubectl with jsonpath + local cronjob_schedule=$(kubectl get cronjobs.batch $cronjob_name -o jsonpath='{.spec.schedule}') + + # Check if the cronjob exists + if [[ -z "$cronjob_schedule" ]]; then + gen3_log_info "Cronjob $cronjob_name does not exist." + return + fi + + # Update cronjob with the image in manifest-versions ConfigMap + gen3_log_info "Updating cronjob $cronjob_name to use image $manifest_image..." + gen3 job cron $cronjob_name "$cronjob_schedule" + } + + # Loop through each fence-related cronjob and check/update if needed + for cronjob in "${fence_cronjobs[@]}"; do + update_cronjob "$cronjob" "$fence_manifest_image" + done +} + # # Get the local manifest and cloud-automation folders in sync with github # @@ -1105,6 +1146,9 @@ if [[ -z "$GEN3_SOURCE_ONLY" ]]; then "sync") gen3_gitops_sync "$@" ;; + "update-fence-cronjobs") + gen3_gitops_update_fence_cron_jobs "$@" + ;; "taglist") gen3_gitops_repo_taglist "$@" ;;