Skip to content

feat(helm): add podLabels for controller and UI pod templates#2237

Open
elihai-risk wants to merge 4 commits into
kagent-dev:mainfrom
elihai-risk:feat/controller-ui-pod-labels
Open

feat(helm): add podLabels for controller and UI pod templates#2237
elihai-risk wants to merge 4 commits into
kagent-dev:mainfrom
elihai-risk:feat/controller-ui-pod-labels

Conversation

@elihai-risk

Copy link
Copy Markdown

What

Adds a global podLabels value plus per-component controller.podLabels / ui.podLabels overrides, merged into the pod template labels of the controller and UI Deployments — mirroring the existing podAnnotations pattern (component | default global).

Why

Many clusters enforce admission policies (e.g. OPA Gatekeeper required-labels, cost/ownership label policies) that validate labels on the pod template, not on Deployment metadata. Today:

We hit this deploying kagent 0.9.11 in a Gatekeeper-enforced cluster: the controller/UI Deployments were denied admission and we had to vendor the chart just for these two label blocks. This PR closes the gap upstream.

Notes

  • No behavior change by default (podLabels: {}); selector labels always take precedence by ordering.
  • Includes helm-unittest coverage: default no-op, global merge, per-component override, selector labels intact (5 tests, all passing; the pre-existing agent-nodeselector_test.yaml failure on main is unrelated).

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 14, 2026 14:30
@elihai-risk elihai-risk requested a review from a team as a code owner July 14, 2026 14:30
EItanya
EItanya previously approved these changes Jul 14, 2026
@EItanya

EItanya commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Thanks so much for the contribution, you'll need to pass DCO in order to merge, you can click the job to see which commits aren't signed correctly

Copilot AI 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.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds support for configuring additional labels on the controller and UI pod templates via a new global podLabels value plus per-component overrides, along with helm-unittest coverage.

Changes:

  • Introduces podLabels (global) and controller.podLabels / ui.podLabels values.
  • Renders the configured labels into controller/UI Deployment pod template labels.
  • Adds helm-unittest tests validating default/no-op and basic merging/override behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
helm/kagent/values.yaml Adds new values for global + per-component pod template labels.
helm/kagent/templates/controller-deployment.yaml Renders merged pod labels into the controller pod template.
helm/kagent/templates/ui-deployment.yaml Renders merged pod labels into the UI pod template.
helm/kagent/tests/pod-labels_test.yaml Adds unit tests for default behavior and override scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +27 to +30
{{- include "kagent.controller.selectorLabels" . | nindent 8 }}
{{- with .Values.controller.podLabels | default .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
Comment on lines +25 to +29
labels:
{{- include "kagent.ui.selectorLabels" . | nindent 8 }}
{{- with .Values.ui.podLabels | default .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
Comment thread helm/kagent/values.yaml Outdated
Comment on lines +234 to +236
# -- Additional labels to add to the controller pod template
# (overrides the global `podLabels` when set)
podLabels: {}
Comment on lines +15 to +21
- it: should merge global podLabels into the controller pod template
template: controller-deployment.yaml
set:
podLabels:
team: platform
cost-center: ai
asserts:
@github-actions github-actions Bot added the enhancement New feature or request label Jul 14, 2026
Add a global `podLabels` value plus per-component `controller.podLabels`
and `ui.podLabels` overrides, merged into the pod template labels of the
controller and UI Deployments (mirroring the existing podAnnotations
pattern).

Motivation: clusters commonly enforce admission policies (e.g. OPA
Gatekeeper required-labels) that validate labels on the *pod template*,
not on Deployment metadata. Agent pods already support this via
controller.agentDeployment.podLabels (kagent-dev#1534); this closes the gap for
the controller and UI pods, which currently render only selector labels
and cannot pass such policies without forking the chart.

Includes helm-unittest coverage (default no-op, global merge, per-
component override, selector labels intact).

Signed-off-by: Elihai Blomberg <elihai.blomberg@riskified.com>
@elihai-risk elihai-risk force-pushed the feat/controller-ui-pod-labels branch from 90ae6fd to fa6c57e Compare July 14, 2026 14:53
Address review feedback: emitting podLabels after the selector labels
allowed overriding selector keys (duplicate YAML keys, last-wins), which
could invalidate the Deployment (matchLabels/template mismatch). Build one
merged map instead - global podLabels, then component podLabels (per-key
override), then selector labels last so they can never be overridden.
Clarify the values.yaml docs accordingly and add selector-protection
tests (7 tests total).

Signed-off-by: Elihai Blomberg <elihai.blomberg@riskified.com>
@elihai-risk

Copy link
Copy Markdown
Author

Thanks for the review! Pushed a follow-up addressing the feedback:

  • Selector-label override risk (controller + UI): now building a single merged map — global podLabels → component podLabels (per-key override) → selector labels applied last, so they can never be overridden and no duplicate YAML keys are emitted.
  • values.yaml wording: clarified that component podLabels merge per-key over the global ones (not a whole-map replace), and that selector labels are always protected.
  • Tests: added selector-protection cases for both deployments (asserting app.kubernetes.io/name/instance survive an override attempt) — 7 tests total, all passing.

DCO is fixed as well (all commits signed off).

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants