From 27d8a723f0d77fbea600ce12b621147fbbe2f28a Mon Sep 17 00:00:00 2001 From: chrisfu Date: Thu, 16 Apr 2026 17:12:38 -0700 Subject: [PATCH] chore: scale down over-replicated GitLab deployments to target replica count of 1 --- etc/init_gitlab.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/etc/init_gitlab.sh b/etc/init_gitlab.sh index f6e5ad2..d271e88 100755 --- a/etc/init_gitlab.sh +++ b/etc/init_gitlab.sh @@ -2604,6 +2604,45 @@ if [[ "${GITLAB_NO_WAIT:-0}" != "1" ]]; then fi fi +# --------------------------------------------------------------------------- +# Requirement: Explicitly scale down over-replicated GitLab deployments +# Some components may remain at 2 replicas even after CR is Available. +# --------------------------------------------------------------------------- +log "Verifying GitLab deployment replica counts (desired=1)..." +_over_replicated_found=0 +# Explicit list of components to verify and scale if needed (Requirement 2) +for _dep_suffix in "gitlab-shell" "kas" "registry" "sidekiq-all-in-1-v2"; do + _dep_name="${GITLAB_RELEASE}-${_dep_suffix}" + + # Read live spec.replicas (Requirement 2 & 6) + _live_replicas=$(kubectl --context "$KUBECTL_CONTEXT" -n "$NAMESPACE" get deployment "$_dep_name" -o jsonpath='{.spec.replicas}' 2>/dev/null || echo "0") + + if [[ -n "$_live_replicas" && "$_live_replicas" -gt 1 ]]; then + log "Deployment ${_dep_name} is over-replicated: live=${_live_replicas}, desired=1. Scaling down..." + # Explicit scale down (Requirement 3) + kubectl --context "$KUBECTL_CONTEXT" -n "$NAMESPACE" scale deployment "$_dep_name" --replicas=1 + _over_replicated_found=1 + else + log "Deployment ${_dep_name} replica count is correct: live=${_live_replicas:-0}, desired=1" + fi +done + +if [[ "$_over_replicated_found" == "1" ]]; then + log "Waiting for rollout of scaled-down deployments..." + for _dep_suffix in "gitlab-shell" "kas" "registry" "sidekiq-all-in-1-v2"; do + _dep_name="${GITLAB_RELEASE}-${_dep_suffix}" + kubectl --context "$KUBECTL_CONTEXT" -n "$NAMESPACE" rollout status deployment/"$_dep_name" --timeout=300s || true + done + + # Final verification (Requirement 4 & 6) + log "Final replica count verification (after corrective action):" + for _dep_suffix in "gitlab-shell" "kas" "registry" "sidekiq-all-in-1-v2"; do + _dep_name="${GITLAB_RELEASE}-${_dep_suffix}" + _final_replicas=$(kubectl --context "$KUBECTL_CONTEXT" -n "$NAMESPACE" get deployment "$_dep_name" -o jsonpath='{.spec.replicas}' 2>/dev/null || echo "0") + log "Deployment ${_dep_name}: final_live=${_final_replicas}, desired=1" + done +fi + # --------------------------------------------------------------------------- # Public ingress for configured GitLab domain -> gitlab-webservice # The GitLab Operator creates the Ingress; this block ensures a stable public