-
Notifications
You must be signed in to change notification settings - Fork 2
ROX-35269: clean up managed clusters before destroying infra-pr GKE clusters #1868
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||
| --- | ||||
| apiVersion: argoproj.io/v1alpha1 | ||||
| kind: WorkflowTemplate | ||||
| metadata: | ||||
| name: cleanup-infra-clusters | ||||
| namespace: default | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Should not be necessary. |
||||
| spec: | ||||
| templates: | ||||
| # Stops all infra-managed Argo workflows on a target cluster before it | ||||
| # is destroyed, giving each workflow's onExit handler time to clean up | ||||
| # cloud resources. | ||||
| - name: cleanup | ||||
| inputs: | ||||
| artifacts: | ||||
| - name: kubeconfig | ||||
| path: /tmp/kubeconfig | ||||
| optional: true | ||||
| activeDeadlineSeconds: 3600 | ||||
| script: | ||||
| image: quay.io/argoproj/argocli:latest | ||||
| command: [bash] | ||||
| source: | | ||||
| set -uo pipefail | ||||
|
|
||||
| if [ ! -f /tmp/kubeconfig ]; then | ||||
| echo "No kubeconfig artifact available. Skipping cleanup." | ||||
| exit 0 | ||||
| fi | ||||
|
|
||||
| export KUBECONFIG=/tmp/kubeconfig | ||||
| export ARGO_NAMESPACE=default | ||||
|
|
||||
| get_active_workflows() { | ||||
| argo list --status Running,Pending -l infra.stackrox.com/cluster-id -o name | ||||
| } | ||||
|
|
||||
| ACTIVE=$(get_active_workflows) | ||||
| if [ -z "$ACTIVE" ]; then | ||||
| echo "No active workflows found. Skipping cleanup." | ||||
| exit 0 | ||||
| fi | ||||
|
|
||||
| echo "Stopping all active workflows to trigger their destroy phases." | ||||
| for wf in $ACTIVE; do | ||||
| echo "Stopping workflow: ${wf}" | ||||
| argo stop "$wf" || true | ||||
| done | ||||
|
|
||||
| DEADLINE=$((SECONDS + 3000)) | ||||
|
Comment on lines
+18
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if 50 minutes are sufficient in practice. I'll try to find some metrics for this (EDIT: we don't have good metrics, so worth a try to start with these). |
||||
| while [ $SECONDS -lt $DEADLINE ]; do | ||||
| REMAINING=$(get_active_workflows) | ||||
| if [ -z "$REMAINING" ]; then | ||||
| echo "All managed workflows completed." | ||||
| exit 0 | ||||
| fi | ||||
| COUNT=$(echo "$REMAINING" | wc -l | tr -d ' ') | ||||
| echo "Waiting for ${COUNT} workflow(s) to complete..." | ||||
| sleep 30 | ||||
| done | ||||
|
|
||||
| echo "Timed out waiting for managed workflows. Proceeding with cluster destroy." | ||||
|
stehessel marked this conversation as resolved.
|
||||
| exit 1 | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying the namespace is not necessary.