From 7dd88385ef1a651b35dd4ff1d33930394f30bcc4 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Fri, 30 Oct 2026 23:06:50 -0600 Subject: [PATCH] Adopt existing platform Helm releases before planning --- lib/jeannie/pipeline.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index ceeaeaf..b2bc0c6 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -397,6 +397,21 @@ adopt_tofu_helm_release() { tofu -chdir="${REPO_ROOT}/${stack}" import -input=false "${resource_address}" "${namespace}/${release_name}" } +untaint_existing_helm_release() { + local stack="$1" + local resource_address="$2" + local state_output + + if ! tofu_state_has_resource "${stack}" "${resource_address}"; then + return 0 + fi + state_output="$(tofu -chdir="${REPO_ROOT}/${stack}" state show "${resource_address}")" || return 1 + if grep -Fq '(tainted)' <<<"${state_output}"; then + echo "Clearing stale taint from existing Helm release ${resource_address}..." + tofu -chdir="${REPO_ROOT}/${stack}" untaint "${resource_address}" + fi +} + adopt_tofu_kubernetes_resource() { local stack="$1" local resource_address="$2" @@ -650,6 +665,7 @@ adopt_platform_existing_resources() { adopt_tofu_helm_release "${stack}" "helm_release.calico_crds" "tigera-operator" "calico-crds" adopt_tofu_helm_release "${stack}" "helm_release.calico" "tigera-operator" "calico" adopt_tofu_helm_release "${stack}" "helm_release.openebs" "openebs" "openebs" + adopt_tofu_helm_release "${stack}" "helm_release.metrics_server[\"enabled\"]" "kube-system" "metrics-server" adopt_tofu_helm_release "${stack}" "helm_release.metallb[\"enabled\"]" "metallb-system" "metallb" adopt_tofu_helm_release "${stack}" "helm_release.traefik[\"enabled\"]" "traefik" "traefik" adopt_tofu_helm_release "${stack}" "helm_release.argocd" "argocd" "argocd" @@ -1005,6 +1021,9 @@ run_tofu_stack() { fi done fi + if [[ "${stack}" == "bootstrap/platform" ]]; then + untaint_existing_helm_release "${stack}" 'helm_release.metrics_server["enabled"]' + fi if [[ "${stack}" == "bootstrap/apps" ]] && ! tofu_apply_has_targets "${apply_args[@]}"; then adopt_apps_existing_resources fi @@ -1048,6 +1067,10 @@ run_tofu_plan_stack() { fi tofu -chdir="${REPO_ROOT}/${stack}" init + if [[ "${stack}" == "bootstrap/platform" ]]; then + adopt_platform_existing_resources + untaint_existing_helm_release "${stack}" 'helm_release.metrics_server["enabled"]' + fi tofu -chdir="${REPO_ROOT}/${stack}" plan "${plan_args[@]}" }