-
Notifications
You must be signed in to change notification settings - Fork 15
HYPERFLEET-1289 - feat: tag e2e namespaces with hyperfleet.io/test-ru… #61
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: main
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 |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| #!/bin/bash | ||
| set -eo pipefail | ||
|
|
||
| LABEL_SELECTOR="${LABEL_SELECTOR:-hyperfleet.io/cluster-id}" | ||
| LABEL_SELECTOR="${LABEL_SELECTOR:-hyperfleet.io/cluster-id hyperfleet.io/test-run}" | ||
| AGE_MINUTES="${AGE_MINUTES:-180}" | ||
| MAESTRO_URL="${MAESTRO_URL:-http://maestro.maestro.svc.cluster.local:8000}" | ||
| DRY_RUN="${DRY_RUN:-false}" | ||
|
|
@@ -72,26 +72,31 @@ else | |
| fi | ||
|
|
||
| # --- Step 2: delete stale namespaces (non-blocking) --- | ||
| kubectl get namespaces -l "${LABEL_SELECTOR}" \ | ||
| -o go-template='{{range .items}}{{.metadata.name}}|{{.metadata.creationTimestamp}}|{{.status.phase}}{{"\n"}}{{end}}' \ | ||
| | while IFS='|' read -r ns_name created_at phase; do | ||
| [ -z "${ns_name}" ] && continue | ||
| [ "${phase}" != "Active" ] && continue | ||
| # LABEL_SELECTOR may contain multiple space-separated selectors; each is matched | ||
| # independently (OR semantics). Namespaces already Terminating are skipped. | ||
| IFS=' ' read -ra _selectors <<< "${LABEL_SELECTOR}" | ||
| for selector in "${_selectors[@]}"; do | ||
| kubectl get namespaces -l "${selector}" \ | ||
| -o go-template='{{range .items}}{{.metadata.name}}|{{.metadata.creationTimestamp}}|{{.status.phase}}{{"\n"}}{{end}}' \ | ||
| | while IFS='|' read -r ns_name created_at phase; do | ||
| [ -z "${ns_name}" ] && continue | ||
| [ "${phase}" != "Active" ] && continue | ||
|
|
||
| created_seconds=$(parse_timestamp "${created_at}") || continue | ||
| age=$((NOW - created_seconds)) | ||
| created_seconds=$(parse_timestamp "${created_at}") || continue | ||
| age=$((NOW - created_seconds)) | ||
|
|
||
| if [ "${age}" -gt "${AGE_SECONDS}" ]; then | ||
| age_m=$((age / 60)) | ||
| if [ "${DRY_RUN}" = "true" ]; then | ||
| echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [DRY-RUN] Would delete namespace '${ns_name}' (age=${age_m}m)" | ||
| else | ||
| echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [INFO] Deleting namespace '${ns_name}' (age=${age_m}m)" | ||
| kubectl delete namespace "${ns_name}" --wait=false \ | ||
| && echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [INFO] Delete requested for namespace '${ns_name}'" \ | ||
| || echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [WARN] Failed to delete namespace '${ns_name}'" | ||
| if [ "${age}" -gt "${AGE_SECONDS}" ]; then | ||
| age_m=$((age / 60)) | ||
| if [ "${DRY_RUN}" = "true" ]; then | ||
| echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [DRY-RUN] Would delete namespace '${ns_name}' (age=${age_m}m)" | ||
| else | ||
| echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [INFO] Deleting namespace '${ns_name}' (age=${age_m}m)" | ||
| kubectl delete namespace "${ns_name}" --wait=false \ | ||
|
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. Since this is a non-blocking call, it won't error out if the namespace failed to be deleted. With --wait=false, kubectl would almost never fail because it only validates that the DELETE request was accepted by the API server. I'm not sure what the alternative is because we don't want to block the deletion. But the namespace could just hang in terminating state forever and the logs from this script would be "Delete requested for namespace" |
||
| && echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [INFO] Delete requested for namespace '${ns_name}'" \ | ||
| || echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [WARN] Failed to delete namespace '${ns_name}'" | ||
| fi | ||
| fi | ||
| fi | ||
| done | ||
| done | ||
| done | ||
|
rh-amarin marked this conversation as resolved.
|
||
|
|
||
| echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [INFO] Namespace cleaner run complete" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,14 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | |
| app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Name for cluster-scoped resources (ClusterRole, ClusterRoleBinding). | ||
| Includes the release namespace so multiple installs don't collide. | ||
| */}} | ||
| {{- define "namespace-cleaner.clusterResourceName" -}} | ||
| {{- printf "%s-%s" (include "namespace-cleaner.fullname" .) .Release.Namespace | trunc 63 | trimSuffix "-" }} | ||
|
Comment on lines
+47
to
+48
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. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Preserve namespace uniqueness after truncation. This helper can still generate colliding cluster-scoped names when 🤖 Prompt for AI Agents |
||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Selector labels | ||
| */}} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.