Skip to content

Commit 32f066b

Browse files
committed
G2P-4380 bug related to help ugrade
1 parent 065f0d9 commit 32f066b

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

automation/lib/env-phase2.sh

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,33 @@ env_phase2_step1_commons() {
8686
# Ensure helm repo is configured (for remote charts)
8787
ensure_helm_repo || return 1
8888

89-
# Check if already installed
89+
# Always fresh install. If a stale/failed release exists, uninstall it first.
90+
# openg2p-commons uses post-install hooks (keycloak-init, client-secrets-sync,
91+
# postgres-init) that only run on install, not upgrade. Also, bitnami subcharts
92+
# require current passwords on upgrade which are lost if the previous install
93+
# failed. A clean install is the reliable path.
9094
if helm status "$release_name" -n "$env_name" &>/dev/null; then
91-
log_info "Helm release '${release_name}' already exists in '${env_name}'."
92-
log_info "Running helm upgrade..."
93-
local helm_action="upgrade"
94-
else
95-
log_info "Installing openg2p-commons..."
96-
local helm_action="install"
95+
log_warn "Stale Helm release '${release_name}' found in '${env_name}'. Uninstalling first..."
96+
helm uninstall "$release_name" -n "$env_name" --wait --timeout 5m || {
97+
log_warn "helm uninstall returned non-zero. Continuing with install..."
98+
}
99+
# Clean up leftover secrets and PVCs that can cause conflicts on reinstall
100+
log_info "Cleaning up leftover secrets and PVCs..."
101+
kubectl -n "$env_name" delete secrets -l "app.kubernetes.io/instance=${release_name}" --ignore-not-found > /dev/null 2>&1 || true
102+
kubectl -n "$env_name" delete pvc -l "app.kubernetes.io/instance=${release_name}" --ignore-not-found > /dev/null 2>&1 || true
103+
# Recreate the keycloak-client-manager secret (was deleted by label cleanup)
104+
if [[ -n "$cm_pass" ]] && ! kubectl -n "$env_name" get secret keycloak-client-manager &>/dev/null; then
105+
kubectl -n "$env_name" create secret generic keycloak-client-manager \
106+
--from-literal=keycloak-client-manager-password="$cm_pass" > /dev/null 2>&1 || true
107+
fi
108+
sleep 5
97109
fi
98110

111+
log_info "Installing openg2p-commons..."
112+
99113
# Build helm command
100114
local -a helm_args=(
101-
"$helm_action" "$release_name" "$chart_ref"
115+
install "$release_name" "$chart_ref"
102116
-n "$env_name"
103117
--set "global.baseDomain=${base_domain}"
104118
--set "global.keycloakBaseUrl=${keycloak_url}"
@@ -126,12 +140,12 @@ env_phase2_step1_commons() {
126140
log_info "Keycloak: ${keycloak_url}"
127141
log_info "User: ${cm_user}"
128142
log_info ""
129-
log_info "Running: helm ${helm_action} ${release_name} ..."
143+
log_info "Running: helm install ${release_name} ..."
130144
log_info "(this may take 15-20 minutes — Helm waits for all hooks to complete)"
131145
echo ""
132146

133147
if ! helm "${helm_args[@]}"; then
134-
log_error "Helm ${helm_action} failed for openg2p-commons" \
148+
log_error "Helm install failed for openg2p-commons" \
135149
"The chart installation did not complete successfully" \
136150
"Check pod status and logs" \
137151
"kubectl get pods -n ${env_name} --field-selector=status.phase!=Running"
@@ -145,7 +159,7 @@ env_phase2_step1_commons() {
145159
return 1
146160
fi
147161

148-
log_success "Helm ${helm_action} completed for openg2p-commons."
162+
log_success "openg2p-commons installed successfully."
149163

150164
# Verify deployments are ready
151165
log_info "Verifying all deployments are ready..."

0 commit comments

Comments
 (0)