Skip to content

[platform] Autoscale the autoscaler - #1198

Merged
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
feat/vpa-for-vpa
Jul 15, 2025
Merged

Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
feat/vpa-for-vpa

Conversation

@lllamnyp

@lllamnyp Timofei Larkin (lllamnyp) commented Jul 14, 2025 •

Copy link
Copy Markdown
Member

What this PR does

The Vertical Pod Autoscaler is a component with resource requirements highly dependent on the environment it is running in, hence it also needs to be autoscaled to reduce the number of configuration parameters that platform admins need to manage. This patch introduces an ancillary autoscaler that watches only the primary autoscaler's namespace and adjusts its resource requests and limits, since the autoscaler cannot autoscale itself. In turn, the primary autoscaler can autoscale the ancillary autoscaler.

Release note

[platform] Implement autoscaling for the Vertical Pod Autoscaler itself.

Summary by CodeRabbit

  • New Features

    • Added an option to enable a dedicated Vertical Pod Autoscaler (VPA) for managing the VPA itself, including new namespace and resource creation when enabled.
  • Configuration

    • Introduced a new setting to toggle the VPA-for-VPA feature.
    • Updated resource configuration for the recommender component by removing specific CPU and memory settings.

The Vertical Pod Autoscaler is a component with resource requirements
highly dependent on the environment it is running in, hence it also
needs to be autoscaled to reduce the number of configuration parameters
that platform admins need to manage. This patch introduces an ancillary
autoscaler that watches only the primary autoscaler's namespace and
adjusts its resource requests and limits, since the autoscaler cannot
autoscale itself. In turn, the primary autoscaler can autoscale the
ancillary autoscaler.

[platform] Implement autoscaling for the Vertical Pod Autoscaler itself.

Signed-off-by: Timofei Larkin <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 14, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

A new Helm template file was added to conditionally deploy a dedicated namespace, HelmRelease, and two VerticalPodAutoscaler resources for managing the VPA itself. The configuration introduces a vpaForVPA boolean flag and removes resource specifications for the recommender in the values file.

Changes

File(s) Change Summary
packages/system/vertical-pod-autoscaler/templates/vpa-for-vpa.yaml Added a Helm template to deploy a namespace, HelmRelease, and two VPA resources for VPA management.
packages/system/vertical-pod-autoscaler/values.yaml Added vpaForVPA boolean flag; removed resources block from vertical-pod-autoscaler.recommender.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Helm
    participant Kubernetes
    participant Flux
    participant VPA

    User->>Helm: Set vpaForVPA=true
    Helm->>Kubernetes: Deploy namespace cozy-vpa-for-vpa
    Helm->>Flux: Create HelmRelease vpa-for-vpa
    Flux->>Kubernetes: Deploy cozy-vertical-pod-autoscaler in cozy-vpa-for-vpa
    Helm->>Kubernetes: Create VPA in release namespace (targets VPA deployment)
    Helm->>Kubernetes: Create VPA in cozy-vpa-for-vpa (targets recommender)
    Kubernetes->>VPA: Apply update policies via recommender
Loading

Possibly related PRs

  • cozystack/cozystack#781: Both PRs involve deployment and management of Vertical Pod Autoscaler components, with one focusing on deployment templates and the other on CRD releases.

Suggested reviewers

  • kvaps
  • xy2

Poem

In the garden of cozy pods,
A VPA now tends its own odds.
With namespaces neat and releases new,
It scales itself—how clever, who knew?
A rabbit hops by, quite impressed,
"Auto-scaling autoscalers? That's truly the best!"
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary of Changes

Hello Timofei Larkin (@lllamnyp), I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a self-autoscaling mechanism for the Vertical Pod Autoscaler (VPA) itself. It achieves this by introducing a dedicated, ancillary VPA instance that monitors and adjusts the resource requirements of the primary VPA. This design addresses the challenge of the VPA being unable to autoscale its own components, leading to more efficient resource utilization and reduced manual configuration for platform administrators.

Highlights

  • Ancillary VPA Deployment: Introduced a new Helm template (vpa-for-vpa.yaml) to deploy an ancillary Vertical Pod Autoscaler (VPA) instance in its own dedicated namespace (cozy-vpa-for-vpa). This new VPA is specifically configured to monitor and adjust the resource requests and limits of the primary VPA's recommender component.
  • Self-Management Loop: Established a self-management loop where the ancillary VPA autoscales the primary VPA, and conversely, the primary VPA is configured to autoscale the ancillary VPA. This ensures both components are dynamically resourced.
  • Dynamic Resource Allocation: Removed the hardcoded CPU and memory resource requests and limits for the primary VPA's recommender component in values.yaml. This change allows the newly introduced ancillary VPA to dynamically manage these resources, optimizing the primary VPA's performance and resource consumption.
  • Feature Flag: Enabled the vpaForVPA feature flag in values.yaml to activate the deployment of the ancillary VPA and its associated configurations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a clever mechanism to allow the Vertical Pod Autoscaler to autoscale itself by deploying an ancillary VPA instance. The primary VPA autoscales the ancillary one, and the ancillary VPA autoscales the primary one.

The implementation using a HelmRelease to deploy the ancillary VPA is sound. The configuration for both VPA instances and their corresponding VerticalPodAutoscaler resources appears correct to achieve the intended cross-autoscaling.

I have one suggestion to improve the stability of this setup by locking the chart version for the ancillary VPA to match the primary one. This will prevent unexpected upgrades and ensure both instances run the same code.

kind: HelmRepository
name: cozystack-system
namespace: cozy-system
version: '>= 0.0.0-0'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using a loose version constraint like >= 0.0.0-0 for the ancillary VPA's Helm chart can introduce instability. This will cause Flux to pull the latest available version from the Helm repository, which might be an unstable pre-release or a version with breaking changes, and could differ from the primary VPA's version.

To ensure stability and consistency, it's recommended to lock the chart version. A good practice is to use the same version as the parent chart, ensuring both VPA instances are synchronized.

      version: '{{ .Chart.Version }}'

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
packages/system/vertical-pod-autoscaler/templates/vpa-for-vpa.yaml (2)

42-43: Inconsistent flag value may recurse indefinitely

Inside the nested HelmRelease you set:

values:
  vpaForVPA: false

This prevents the sub-chart from creating yet another “autoscaler of the autoscaler”, which is correct, but the intent is not obvious from the first glance. A short comment would avoid future accidents where someone flips this back to true.


1-3: yamllint false-positive: silence the linter on Helm templates

CI is red due to YAMLlint complaining about the leading {{- if … }}.
Add a directive to disable linting for this template file:

+{{/* yamllint disable-file */}}
 {{- if .Values.vpaForVPA }}

This keeps the pipeline green without relaxing linting globally.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1a4a58 and 83e0ab3.

📒 Files selected for processing (2)
  • packages/system/vertical-pod-autoscaler/templates/vpa-for-vpa.yaml (1 hunks)
  • packages/system/vertical-pod-autoscaler/values.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
packages/system/vertical-pod-autoscaler/templates/vpa-for-vpa.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

@@ -1,3 +1,5 @@
vpaForVPA: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Flag defaults to true: be explicit about rollout impact

Introducing vpaForVPA: true enables the ancillary autoscaler by default. This flips behaviour for every cluster that consumes this chart and may create extra namespaces / controllers unexpectedly.

Consider one of:

-vpaForVPA: true
+vpaForVPA: false   # opt-in – set to true per-cluster once validated

and upgrade clusters incrementally, or at a minimum document the behavioural change clearly in the chart’s CHANGELOG.


#!/usr/bin/env bash
set -eux

echo "=== packages/system/vertical-pod-autoscaler/values.yaml ==="
sed -n '1,50p' packages/system/vertical-pod-autoscaler/values.yaml || true

echo "=== Search for vpaForVPA usage in templates and other files ==="
rg "vpaForVPA" -n -C3 || true


Be explicit about rollout impact: change default vpaForVPA to false

Introducing a new flag that defaults to true will immediately enable the ancillary autoscaler in every cluster that upgrades this chart—potentially creating extra namespaces/controllers without warning. To mitigate unexpected behavior:

  • In packages/system/vertical-pod-autoscaler/values.yaml, update:
    - vpaForVPA: true
    + vpaForVPA: false   # opt-in feature; set to true per-cluster after validation
  • Document this change clearly in the chart’s CHANGELOG.md under breaking changes:

    Changed default for vpaForVPA from true to false. Consumers must explicitly opt in (--set vpaForVPA=true) to enable the ancillary autoscaler.

Roll out the new default incrementally—verify on staging clusters before wider deployment.

📝 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
vpaForVPA: true
# packages/system/vertical-pod-autoscaler/values.yaml
vpaForVPA: false # opt-in feature; set to true per-cluster after validation
🤖 Prompt for AI Agents
In packages/system/vertical-pod-autoscaler/values.yaml at line 1, change the
default value of vpaForVPA from true to false to prevent automatic enabling of
the ancillary autoscaler on upgrade. Additionally, update the chart's
CHANGELOG.md to document this breaking change, specifying that users must
explicitly set vpaForVPA to true to enable the feature. This ensures safer
rollout and clear communication of the change.

Comment on lines +68 to +70
apiVersion: apps/v1
kind: Deployment
name: {{ dig "vertical-pod-autoscaler" "nameOverride" "" .Values.AsMap | default "vertical-pod-autoscaler" | trunc 63 | trimSuffix "-" }}-recommender

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Template fails: .Values.AsMap is not a Helm object

dig should receive .Values, not .Values.AsMap (which does not exist and will raise “unable to cast to map”).

-    name: {{ dig "vertical-pod-autoscaler" "nameOverride" "" .Values.AsMap | default "vertical-pod-autoscaler" | trunc 63 | trimSuffix "-" }}-recommender
+    name: {{ dig "vertical-pod-autoscaler" "nameOverride" "" .Values | default "vertical-pod-autoscaler" | trunc 63 | trimSuffix "-" }}-recommender
📝 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
apiVersion: apps/v1
kind: Deployment
name: {{ dig "vertical-pod-autoscaler" "nameOverride" "" .Values.AsMap | default "vertical-pod-autoscaler" | trunc 63 | trimSuffix "-" }}-recommender
apiVersion: apps/v1
kind: Deployment
name: {{ dig "vertical-pod-autoscaler" "nameOverride" "" .Values | default "vertical-pod-autoscaler" | trunc 63 | trimSuffix "-" }}-recommender
🤖 Prompt for AI Agents
In packages/system/vertical-pod-autoscaler/templates/vpa-for-vpa.yaml around
lines 68 to 70, the template uses `.Values.AsMap` which does not exist and
causes a casting error. Replace `.Values.AsMap` with `.Values` in the `dig`
function call to correctly reference the Helm values object and avoid the
template failure.

@kvaps Andrei Kvapil (kvaps) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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