Skip to content

fix(affinity): update affinity on server and aggregator to be automatically set - #898

Open
pinkneyj wants to merge 3 commits into
Cloudzero:developfrom
pinkneyj:develop
Open

fix(affinity): update affinity on server and aggregator to be automatically set#898
pinkneyj wants to merge 3 commits into
Cloudzero:developfrom
pinkneyj:develop

Conversation

@pinkneyj

@pinkneyj pinkneyj commented Jul 3, 2026

Copy link
Copy Markdown

Why?

Affinity is not automatically set for aggregator and server.

What

This change does this, based on code already in webhook-deploy.yaml Although changes have recently been made to set aggregator affinity (#881) and the server affinity can already be set, this just removes the need to do that yourself.
This is also a copy of: Cloudzero/cloudzero-charts#224 but believe this is the repo the change should be made in.

How Tested

Deployed locally. Gives values as expected and can be overridden.

@pinkneyj
pinkneyj requested a review from a team as a code owner July 3, 2026 11:08
@pinkneyj pinkneyj changed the title update affinity on server and aggregator to be automatically set fix(affinity): update affinity on server and aggregator to be automatically set Jul 3, 2026
@greptile-apps

greptile-apps Bot commented Aug 5, 2026

Copy link
Copy Markdown

Greptile Summary

This PR automatically supplies preferred pod anti-affinity for server and aggregator pods while preserving user overrides and shared affinity defaults.

  • Adds a weight-100 hostname anti-affinity preference for server pods.
  • Adds the equivalent preference for aggregator pods.
  • Reuses the affinity merge pattern already used by the webhook deployment.
  • Leaves the new rendering behavior without focused Helm regression coverage.

Confidence Score: 4/5

The PR appears safe to merge, with the non-blocking concern that its new Helm rendering behavior lacks focused regression coverage.

The affinity merge follows an established chart pattern and preserves user overrides, but no dedicated test protects the newly generated server and aggregator selectors, weights, topology keys, and override behavior.

Files Needing Attention: helm/templates/agent-deploy.yaml, helm/templates/aggregator-deploy.yaml

Important Files Changed

Filename Overview
helm/templates/agent-deploy.yaml Adds automatic preferred anti-affinity for server pods with user values taking precedence; focused regression coverage is missing.
helm/templates/aggregator-deploy.yaml Adds the matching automatic anti-affinity behavior for aggregator pods, with the same testing gap.
helm/README.md No substantive behavioral documentation change is visible in the supplied diff.

Fix All in Claude Code

Prompt To Fix All With AI
### Issue 1
helm/templates/agent-deploy.yaml:350-352
**Missing anti-affinity regression coverage**

The new server and aggregator anti-affinity rendering lacks focused Helm tests for the generated selector, weight, topology key, and user override behavior, so regressions in this scheduling policy can pass without detection.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "remove whitespace" | Re-trigger Greptile

Comment on lines +350 to +352
{{- $podAntiAffinity := dict "podAntiAffinity" (dict "preferredDuringSchedulingIgnoredDuringExecution" (list (dict "weight" 100 "podAffinityTerm" (dict "labelSelector" (dict "matchLabels" (dict "app.kubernetes.io/name" "server")) "topologyKey" "kubernetes.io/hostname")))) }}
{{- $userAffinity := deepCopy (.Values.server.affinity | default (dict)) }}
{{- include "cloudzero-agent.generateAffinity" (dict "default" .Values.defaults.affinity "affinity" (merge $userAffinity $podAntiAffinity)) | nindent 6 }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Missing anti-affinity regression coverage

The new server and aggregator anti-affinity rendering lacks focused Helm tests for the generated selector, weight, topology key, and user override behavior, so regressions in this scheduling policy can pass without detection.

Context Used: CLAUDE.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: helm/templates/agent-deploy.yaml
Line: 350-352

Comment:
**Missing anti-affinity regression coverage**

The new server and aggregator anti-affinity rendering lacks focused Helm tests for the generated selector, weight, topology key, and user override behavior, so regressions in this scheduling policy can pass without detection.

**Context Used:** CLAUDE.md ([source](https://github.com/cloudzero/cloudzero-agent/blob/main/CLAUDE.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

@dmepham

dmepham commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Hi @pinkneyj , thank you again for another contribution! This is definitely a good change and I would certainly like to get this behavior merged in, one way or another. The anti-affinity term looks good to me, and you've followed [the pattern that already exists in the webhook-server template](https://github.com/Cloudzero/cloudzero-agent/blob/develop/helm/templates/webhook-deploy.yaml#L106-L120).

But, your change has surfaced an opportunity for improvement in the chart generally. In the existing templates and in the proposed change, we're baking in an opinionated setting for pod affinity that cannot be removed or overridden. It's a reasonable default behavior, but we also want to allow users the flexibility to choose. What I would propose instead is to move this default - for the agent-deploy, the aggregator-deploy, and the webhook-server deploy - into the values.yaml file, declared on each component's own affinity key. This would mean that:

  1. All components get the default affinity setting.
  2. Users have better visibility into the setting.
  3. Users can remove, override, or alter the setting.

Let me know what you think. If you're up for the change in this PR, then that's great. Otherwise, we can handle it on our side. Thank you again for the PR!

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