Skip to content

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

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

fix(affinity): update affinity on server and aggregator to be automatically set#898
pinkneyj wants to merge 4 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

The PR relocates the webhook anti-affinity default into chart values and adds equivalent automatic defaults for server and aggregator workloads.

  • Adds preferred hostname anti-affinity defaults for server, aggregator, and webhook-server pods.
  • Updates webhook rendering to consume the value-based affinity configuration.
  • Adds focused Helm regression tests for server and aggregator defaults and overrides.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported regression-coverage gap is addressed by focused tests for both affected workloads.

Important Files Changed

Filename Overview
helm/templates/webhook-deploy.yaml Replaces the template-local webhook anti-affinity construction with the shared value-driven affinity helper.
helm/tests/server_aggregator_default_antiaffinity_test.yaml Adds focused coverage for server and aggregator selectors, weights, topology keys, and explicit overrides, resolving the previous testing concern.
helm/values.yaml Defines documented soft pod anti-affinity defaults for server, webhook-server, and aggregator workloads.

Reviews (2): Last reviewed commit: "update default affinities" | Re-trigger Greptile

Comment thread helm/templates/agent-deploy.yaml Outdated
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!

@pinkneyj

Copy link
Copy Markdown
Author

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!

Hey @dmepham thanks for this response. I've made some changes based on your suggestions, do have a look when is convenient to do so.

Thanks in advance!

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