chore: remove redundant local declarations in GitLab init script

- Cleaned up unnecessary `local` keyword usage for `_wait_start` and `_now` variables to improve clarity and alignment with the script's style.
This commit is contained in:
chrisfu 2026-04-14 17:11:52 -07:00
parent 7bae08db5d
commit 285d9fc185

View File

@ -292,6 +292,50 @@ check_gitlab_post_apply_blocked() {
fi
if [[ "$converged" == "1" ]]; then
# Wait for PVC provisioning if autoclean was performed
log "Waiting for PVC repo-data-gitlab-gitaly-0 to be provisioned and Bound..."
local pvc_name="repo-data-gitlab-gitaly-0"
local pvc_start=$(date +%s)
local pvc_timeout=600
while true; do
local pvc_sc=$(kubectl -n "$NAMESPACE" get pvc "$pvc_name" -o jsonpath='{.spec.storageClassName}' 2>/dev/null || true)
local pvc_phase=$(kubectl -n "$NAMESPACE" get pvc "$pvc_name" -o jsonpath='{.status.phase}' 2>/dev/null || true)
if [[ -n "$pvc_phase" ]]; then
log "PVC ${pvc_name}: storageClass=[${pvc_sc}], phase=[${pvc_phase}]"
if [[ "$pvc_phase" == "Bound" ]]; then
if [[ "$pvc_sc" == "standard" ]]; then
log "PVC ${pvc_name} successfully provisioned on 'standard' storage."
break
else
log "PVC ${pvc_name} is Bound but uses storageClass: ${pvc_sc} (expected 'standard')."
# If it's already bound to standard-rwo, it might be an old one that wasn't deleted,
# or the operator didn't update it yet. But we should eventually see 'standard'.
fi
fi
# Check for provisioning failures (events)
local provisioning_fail=$(kubectl -n "$NAMESPACE" get events --field-selector involvedObject.name="$pvc_name",involvedObject.kind=PersistentVolumeClaim -o jsonpath='{range .items[?(@.reason=="FailedBinding" || @.reason=="ProvisioningFailed")]}{.message}{"\n"}{end}' 2>/dev/null | tail -n 1 || true)
if [[ -n "$provisioning_fail" ]]; then
if [[ "$provisioning_fail" == *"quota"* || "$provisioning_fail" == *"QUOTA"* ]]; then
repair_blocked "Gitaly PVC provisioning failed (Quota Exceeded)" \
"PVC: ${pvc_name}. Error: ${provisioning_fail}. Fix: Check GKE SSD_TOTAL_GB quota and ensure Gitaly uses 'standard' storageClass."
else
log "PVC ${pvc_name} provisioning event: ${provisioning_fail}"
fi
fi
else
log "PVC ${pvc_name} not found yet (awaiting operator/provisioner action)..."
fi
if (( $(date +%s) - pvc_start > pvc_timeout )); then
local last_msg=$(kubectl -n "$NAMESPACE" get events --field-selector involvedObject.name="$pvc_name" --sort-by='.lastTimestamp' -o jsonpath='{.items[-1:].message}' 2>/dev/null || true)
repair_blocked "Gitaly PVC failed to bind after ${pvc_timeout}s" \
"PVC: ${pvc_name}. Status: ${pvc_phase:-NotFound}. Last event: ${last_msg}. Fix: Check storage provider and quota."
fi
sleep 15
done
export GITALY_AUTOCLEAN_PERFORMED=0
fi
@ -339,7 +383,7 @@ check_gitlab_post_apply_blocked() {
unschedulable_gitaly=$(kubectl -n "$NAMESPACE" get pods -l "app=gitaly" -o jsonpath='{range .items[?(@.status.conditions[?(@.type=="PodScheduled")].status=="False")]}{.metadata.name}:{.status.conditions[?(@.type=="PodScheduled")].reason}{"\n"}{end}' 2>/dev/null | grep "Unschedulable" || true)
if [[ -n "$unschedulable_gitaly" ]]; then
repair_blocked "Gitaly pod(s) unschedulable" \
"Resource: pod -l app=gitaly. Value: Unschedulable. Fix: GKE requires dynamic storage (standard-rwo) and no hostname nodeSelector. Ensure PV/PVC were repaired."
"Resource: pod -l app=gitaly. Value: Unschedulable. Fix: GKE requires dynamic storage (standard) and no hostname nodeSelector. Ensure PV/PVC were repaired."
fi
fi
@ -1231,9 +1275,9 @@ GITALY_STORAGE_CLASS="${GITLAB_GITALY_STORAGE_CLASS:-}"
if [[ "$MODE" == "k8s" ]]; then
if [[ -z "$GITALY_STORAGE_CLASS" || "$GITALY_STORAGE_CLASS" == "gitlab-gitaly-static" ]]; then
if [[ "$GITALY_STORAGE_CLASS" == "gitlab-gitaly-static" ]]; then
warn "Stripping legacy storageClass 'gitlab-gitaly-static' in k8s mode; using 'standard-rwo'."
warn "Stripping legacy storageClass 'gitlab-gitaly-static' in k8s mode; using 'standard'."
fi
GITALY_STORAGE_CLASS="standard-rwo"
GITALY_STORAGE_CLASS="standard"
fi
else
if [[ -z "$GITALY_STORAGE_CLASS" ]]; then