Skip to content

Commit

Permalink
feat/check and update fence jobs (#2564)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ajoaugustine authored Jun 11, 2024
1 parent 68f34db commit 7283efe
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/gitops.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
46 changes: 45 additions & 1 deletion gen3/bin/gitops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
#
Expand Down Expand Up @@ -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 "$@"
;;
Expand Down

0 comments on commit 7283efe

Please sign in to comment.