Skip to content

BAC-492 - Prevent Rollout From Losing spec.replicas During ArgoCD Syn…#62

Closed
churma wants to merge 3 commits intomasterfrom
bac-492-prevent-rollout-from-losing-spec-replicas
Closed

BAC-492 - Prevent Rollout From Losing spec.replicas During ArgoCD Syn…#62
churma wants to merge 3 commits intomasterfrom
bac-492-prevent-rollout-from-losing-spec-replicas

Conversation

@churma
Copy link
Contributor

@churma churma commented Jan 7, 2026

…c When Re-enabling HPA

Why? 🤔

We need this change because…

What? 📃

Please add a summary for this pull requests

Additional Links 🔗

Summary by CodeRabbit

  • New Features

    • Added an automated preparation step to handle HPA-related transitions before application syncs.
  • Bug Fixes

    • Improved ArgoCD synchronization stability for autoscaled applications by removing stale replica configuration that could interfere with HPA/rollout transitions.

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

Walkthrough

Adds a conditional CI step "Prepare HPA transition" to the Argo deploy workflow and a new script src/scripts/argo_hpa_transition.sh that cleans spec.replicas from a Rollout's last-applied-configuration annotation when HPA is enabled, with validation and guarded exit paths.

Changes

Cohort / File(s) Summary
Workflow — Argo deploy step
src/commands/argo-deploy-application.yml
Adds a conditional step "Prepare HPA transition" that sets ARGO_PARAMETERS_FILE, RELEASE_NAME, and NAMESPACE, then executes include(scripts/argo_hpa_transition.sh) before Upsert and checks.
Script — HPA transition logic
src/scripts/argo_hpa_transition.sh
New Bash script that validates env vars, checks rendered parameters for autoscaling.enabled == true, locates the Rollout, removes spec.replicas from the kubectl.kubernetes.io/last-applied-configuration annotation using jq, and re-annotates the resource. Uses guarded exits and colored status messages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 3
❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete with placeholder text in all required sections; 'Why?' and 'What?' sections contain only template prompts without actual content describing the change, rationale, or implementation details. Replace placeholder text in 'Why?' and 'What?' sections with substantive explanations of the problem being solved and implementation details, and optionally fill the 'Additional Links' section with relevant issue/ticket references.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (5 files):

⚔️ src/commands/argo-deploy-application.yml (content)
⚔️ src/jobs/argo-deploy.yml (content)
⚔️ src/scripts/argo_app_previous_status.sh (content)
⚔️ src/scripts/argo_cli_common.sh (content)
⚔️ src/scripts/argo_rollout_status_common.sh (content)

These conflicts must be resolved before merging into master.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: preventing Rollout from losing spec.replicas during ArgoCD sync when re-enabling HPA, directly matching the changeset content.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bac-492-prevent-rollout-from-losing-spec-replicas
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch bac-492-prevent-rollout-from-losing-spec-replicas
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

churma and others added 2 commits January 8, 2026 15:31
Implement HPA transition preparation script and update ArgoCD deployment steps to clean spec.replicas from last-applied-configuration. This change prevents conflicts during HPA transitions by ensuring the correct replica count is maintained.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/scripts/argo_hpa_transition.sh`:
- Around line 48-55: The hpa_enabled extraction is brittle for quoted or
capitalized values; update the hpa_enabled assignment (the variable computed
from "$parameters_file") to strip surrounding quotes and whitespace and
normalize to lowercase before comparing to "true". Locate the hpa_enabled
assignment and replace the current pipeline with one that extracts the value
token, removes surrounding quotes, trims whitespace, and lowercases it (so
values like "true", True, TRUE all normalize to true) and then keep the existing
if [[ "$hpa_enabled" != "true" ]]; check.
- Around line 35-46: The validation currently only checks that the
parameters_file variable is set; update the check so it also fails fast when the
file path is missing or not readable. Replace the single-variable check for
parameters_file with a compound test like [[ -z "$parameters_file" || ! -r
"$parameters_file" ]] and add a clear label such as "ARGO_PARAMETERS_FILE
(missing or unreadable)" to missing_vars so the script exits immediately if the
file does not exist or is not readable; keep the rest of the missing_vars
handling (usage and exit 2) unchanged.

Comment on lines +35 to +46
# Validate required variables
local missing_vars=()
[[ -z "$parameters_file" ]] && missing_vars+=("ARGO_PARAMETERS_FILE")
[[ -z "$release_name" ]] && missing_vars+=("RELEASE_NAME")
[[ -z "$namespace" ]] && missing_vars+=("NAMESPACE")

if [[ ${#missing_vars[@]} -gt 0 ]]; then
echo -e "${RED}Error: The following required environment variables are missing:${NC}"
printf ' - %s\n' "${missing_vars[@]}"
usage
exit 2
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fail fast if ARGO_PARAMETERS_FILE is missing or unreadable.

Right now only the variable is checked; if the file path is wrong, Line 50 will silently evaluate to "not enabled" and skip cleanup, reintroducing the replica-loss bug.

🛠️ Suggested fix
   if [[ ${`#missing_vars`[@]} -gt 0 ]]; then
     echo -e "${RED}Error: The following required environment variables are missing:${NC}"
     printf '  - %s\n' "${missing_vars[@]}"
     usage
     exit 2
   fi
+
+  if [[ ! -r "$parameters_file" ]]; then
+    echo -e "${RED}Error: ARGO_PARAMETERS_FILE '$parameters_file' not found or not readable.${NC}"
+    exit 2
+  fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Validate required variables
local missing_vars=()
[[ -z "$parameters_file" ]] && missing_vars+=("ARGO_PARAMETERS_FILE")
[[ -z "$release_name" ]] && missing_vars+=("RELEASE_NAME")
[[ -z "$namespace" ]] && missing_vars+=("NAMESPACE")
if [[ ${#missing_vars[@]} -gt 0 ]]; then
echo -e "${RED}Error: The following required environment variables are missing:${NC}"
printf ' - %s\n' "${missing_vars[@]}"
usage
exit 2
fi
# Validate required variables
local missing_vars=()
[[ -z "$parameters_file" ]] && missing_vars+=("ARGO_PARAMETERS_FILE")
[[ -z "$release_name" ]] && missing_vars+=("RELEASE_NAME")
[[ -z "$namespace" ]] && missing_vars+=("NAMESPACE")
if [[ ${`#missing_vars`[@]} -gt 0 ]]; then
echo -e "${RED}Error: The following required environment variables are missing:${NC}"
printf ' - %s\n' "${missing_vars[@]}"
usage
exit 2
fi
if [[ ! -r "$parameters_file" ]]; then
echo -e "${RED}Error: ARGO_PARAMETERS_FILE '$parameters_file' not found or not readable.${NC}"
exit 2
fi
🤖 Prompt for AI Agents
In `@src/scripts/argo_hpa_transition.sh` around lines 35 - 46, The validation
currently only checks that the parameters_file variable is set; update the check
so it also fails fast when the file path is missing or not readable. Replace the
single-variable check for parameters_file with a compound test like [[ -z
"$parameters_file" || ! -r "$parameters_file" ]] and add a clear label such as
"ARGO_PARAMETERS_FILE (missing or unreadable)" to missing_vars so the script
exits immediately if the file does not exist or is not readable; keep the rest
of the missing_vars handling (usage and exit 2) unchanged.

Comment on lines +48 to +55
# Check if autoscaling is being enabled in this deploy
local hpa_enabled
hpa_enabled=$(grep -A1 'name: autoscaling\.enabled' "$parameters_file" | grep 'value:' | awk '{print $2}' || echo "false")

if [[ "$hpa_enabled" != "true" ]]; then
echo -e "${GREEN}HPA not enabled in this deploy, skipping.${NC}"
return 0
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

HPA enablement parsing is brittle for quoted/uppercase values.

If the parameters file uses value: "true" or value: True, Line 50 returns a non‑true string and the cleanup is skipped. Normalize and strip quotes before comparison.

🛠️ Suggested fix
-  hpa_enabled=$(grep -A1 'name: autoscaling\.enabled' "$parameters_file" | grep 'value:' | awk '{print $2}' || echo "false")
+  hpa_enabled=$(awk '
+    $0 ~ /name: autoscaling\.enabled/ {found=1; next}
+    found && $1=="value:" {
+      gsub(/"/,"",$2);
+      print tolower($2);
+      exit
+    }
+  ' "$parameters_file")
+  hpa_enabled=${hpa_enabled:-false}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Check if autoscaling is being enabled in this deploy
local hpa_enabled
hpa_enabled=$(grep -A1 'name: autoscaling\.enabled' "$parameters_file" | grep 'value:' | awk '{print $2}' || echo "false")
if [[ "$hpa_enabled" != "true" ]]; then
echo -e "${GREEN}HPA not enabled in this deploy, skipping.${NC}"
return 0
fi
# Check if autoscaling is being enabled in this deploy
local hpa_enabled
hpa_enabled=$(awk '
$0 ~ /name: autoscaling\.enabled/ {found=1; next}
found && $1=="value:" {
gsub(/"/,"",$2);
print tolower($2);
exit
}
' "$parameters_file")
hpa_enabled=${hpa_enabled:-false}
if [[ "$hpa_enabled" != "true" ]]; then
echo -e "${GREEN}HPA not enabled in this deploy, skipping.${NC}"
return 0
fi
🤖 Prompt for AI Agents
In `@src/scripts/argo_hpa_transition.sh` around lines 48 - 55, The hpa_enabled
extraction is brittle for quoted or capitalized values; update the hpa_enabled
assignment (the variable computed from "$parameters_file") to strip surrounding
quotes and whitespace and normalize to lowercase before comparing to "true".
Locate the hpa_enabled assignment and replace the current pipeline with one that
extracts the value token, removes surrounding quotes, trims whitespace, and
lowercases it (so values like "true", True, TRUE all normalize to true) and then
keep the existing if [[ "$hpa_enabled" != "true" ]]; check.

@juanariastn
Copy link
Contributor

Closed in favor of:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants