Skip to content

Conversation

@rackerchris
Copy link
Contributor

Feature: Versatile HPA Management Script with Dry Run

This commit introduces the comprehensive manage_hpa.sh utility to safely lock and unlock Kubernetes Horizontal Pod Autoscalers (HPAs) across all namespaces. This is primarily intended for pre-maintenance operations where unexpected scaling must be prevented.

The script's core function is to set maxReplicas equal to minReplicas (locking the HPA) and then reliably restore the original maxReplicas value.

Key Features and Improvements

Toggle Modes (lock/unlock): The script operates via mandatory command-line arguments to clearly define the desired action.

Reversibility: In lock mode, the script saves all original HPA maxReplicas values to a configurable JSON file (hpa_originals.json by default). The unlock mode uses this file to restore original settings and then cleans up the file.

Optional Configuration File: The user can specify a custom filename for the HPA configuration file, allowing for parallel operations or custom naming conventions.

Safety First (--dry-run): Introduced a non-destructive dry run mode to preview all actions.

    The dry run output includes a table of current live HPA states (Current, Min, Max replicas) and the current lock status (config file existence).

    It prints the exact kubectl patch command and the JSON patch content that would be applied, ensuring transparent operation.

Execution Instructions

The script requires jq to be installed.

  1. Lock HPAs (Start Maintenance)

Saves original settings and sets maxReplicas = minReplicas.
Bash

Preview changes first (Recommended)

./manage_hpa.sh lock --dry-run

Execute actual lock using default config file

./manage_hpa.sh lock

  1. Unlock HPAs (End Maintenance)

Reads settings from the config file, restores maxReplicas, and deletes the config file.
Bash

Preview restoration

./manage_hpa.sh unlock --dry-run

Execute actual unlock using a custom config file

./manage_hpa.sh unlock my-maintenance-hpas.json

@cloudnull cloudnull merged commit c88f9bb into rackerlabs:main Nov 19, 2025
3 checks passed
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