From 32178fb840be652ab2d556af078545fc02994788 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Wed, 7 Oct 2026 12:31:36 -0600 Subject: [PATCH] fix: adopt existing Helm releases before platform apply --- lib/jeannie/pipeline.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index d0789f6..0dc4242 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -297,7 +297,7 @@ cleanup_stale_helm_release_secrets() { -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.metadata.labels.status}{"\n"}{end}' 2>/dev/null | while IFS=$'\t' read -r secret status; do case "${status}" in - pending-install|pending-upgrade|pending-rollback|failed|uninstalling) + pending-install|pending-upgrade|pending-rollback|failed|uninstalling|uninstalled) echo "Deleting stale Helm release secret ${namespace}/${secret} with status=${status}..." kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${namespace}" delete secret "${secret}" ;; @@ -317,6 +317,22 @@ helm_release_deployed_secret_exists() { [[ -n "${secret_name}" ]] } +helm_release_exists_for_adoption() { + local namespace="$1" + local release_name="$2" + + if helm_release_deployed_secret_exists "${namespace}" "${release_name}"; then + return 0 + fi + + if command -v helm >/dev/null 2>&1 && + helm --kubeconfig "${KUBECONFIG_PATH}" -n "${namespace}" status "${release_name}" >/dev/null 2>&1; then + return 0 + fi + + return 1 +} + kubernetes_resource_exists() { local namespace="$1" local resource_kind="$2" @@ -336,17 +352,17 @@ adopt_tofu_helm_release() { local namespace="$3" local release_name="$4" local has_state=false - local has_deployed_release=false + local has_existing_release=false if tofu_state_has_resource "${stack}" "${resource_address}"; then has_state=true fi cleanup_stale_helm_release_secrets "${namespace}" "${release_name}" - if helm_release_deployed_secret_exists "${namespace}" "${release_name}"; then - has_deployed_release=true + if helm_release_exists_for_adoption "${namespace}" "${release_name}"; then + has_existing_release=true fi - if [[ "${has_state}" == "true" && "${has_deployed_release}" == "false" ]]; then + if [[ "${has_state}" == "true" && "${has_existing_release}" == "false" ]]; then echo "Removing stale Helm release state for ${namespace}/${release_name} from ${stack} (${resource_address}) because no deployed Helm release exists..." tofu -chdir="${REPO_ROOT}/${stack}" state rm "${resource_address}" return 0 @@ -355,7 +371,7 @@ adopt_tofu_helm_release() { if [[ "${has_state}" == "true" ]]; then return 0 fi - if [[ "${has_deployed_release}" == "false" ]]; then + if [[ "${has_existing_release}" == "false" ]]; then return 0 fi