diff --git a/helm/kagent/templates/controller-deployment.yaml b/helm/kagent/templates/controller-deployment.yaml index 74619235af..e3da0fc0ee 100644 --- a/helm/kagent/templates/controller-deployment.yaml +++ b/helm/kagent/templates/controller-deployment.yaml @@ -24,7 +24,10 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} labels: - {{- include "kagent.controller.selectorLabels" . | nindent 8 }} + {{- /* extra pod labels: component merged over global, selector labels + applied last so they can never be overridden */}} + {{- $podLabels := mergeOverwrite (dict) (.Values.podLabels | default dict) (.Values.controller.podLabels | default dict) (include "kagent.controller.selectorLabels" . | fromYaml) }} + {{- toYaml $podLabels | nindent 8 }} spec: {{- with .Values.controller.imagePullSecrets | default .Values.imagePullSecrets }} imagePullSecrets: diff --git a/helm/kagent/templates/ui-deployment.yaml b/helm/kagent/templates/ui-deployment.yaml index 2057a44760..f57e9a2627 100644 --- a/helm/kagent/templates/ui-deployment.yaml +++ b/helm/kagent/templates/ui-deployment.yaml @@ -23,7 +23,10 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} labels: - {{- include "kagent.ui.selectorLabels" . | nindent 8 }} + {{- /* extra pod labels: component merged over global, selector labels + applied last so they can never be overridden */}} + {{- $podLabels := mergeOverwrite (dict) (.Values.podLabels | default dict) (.Values.ui.podLabels | default dict) (include "kagent.ui.selectorLabels" . | fromYaml) }} + {{- toYaml $podLabels | nindent 8 }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: diff --git a/helm/kagent/tests/pod-labels_test.yaml b/helm/kagent/tests/pod-labels_test.yaml new file mode 100644 index 0000000000..652c38ecd1 --- /dev/null +++ b/helm/kagent/tests/pod-labels_test.yaml @@ -0,0 +1,94 @@ +suite: test controller and UI pod labels +templates: + - controller-deployment.yaml + - controller-configmap.yaml + - postgresql-secret.yaml + - ui-deployment.yaml + - ui-nginx-configmap.yaml +tests: + - it: should not add extra pod labels by default (controller) + template: controller-deployment.yaml + asserts: + - notExists: + path: spec.template.metadata.labels.team + + - it: should merge global podLabels into the controller pod template + template: controller-deployment.yaml + set: + podLabels: + team: platform + cost-center: ai + asserts: + - equal: + path: spec.template.metadata.labels.team + value: platform + - equal: + path: spec.template.metadata.labels["cost-center"] + value: ai + # selector labels must remain intact + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: kagent + + - it: should let controller.podLabels override the global podLabels + template: controller-deployment.yaml + set: + podLabels: + team: platform + controller: + podLabels: + team: controller-team + asserts: + - equal: + path: spec.template.metadata.labels.team + value: controller-team + + - it: should merge global podLabels into the UI pod template + template: ui-deployment.yaml + set: + podLabels: + team: platform + asserts: + - equal: + path: spec.template.metadata.labels.team + value: platform + + - it: should let ui.podLabels override the global podLabels + template: ui-deployment.yaml + set: + podLabels: + team: platform + ui: + podLabels: + team: ui-team + asserts: + - equal: + path: spec.template.metadata.labels.team + value: ui-team + + - it: should not allow podLabels to override controller selector labels + template: controller-deployment.yaml + set: + podLabels: + app.kubernetes.io/name: hijacked + controller: + podLabels: + app.kubernetes.io/instance: hijacked + asserts: + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: kagent + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/instance"] + value: RELEASE-NAME + + - it: should not allow podLabels to override UI selector labels + template: ui-deployment.yaml + set: + ui: + podLabels: + app.kubernetes.io/name: hijacked + asserts: + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: kagent diff --git a/helm/kagent/values.yaml b/helm/kagent/values.yaml index 106c52c50e..4a32d1a20f 100644 --- a/helm/kagent/values.yaml +++ b/helm/kagent/values.yaml @@ -32,6 +32,11 @@ annotations: {} podAnnotations: {} +# -- Additional labels to add to all pod templates (merged into pod labels of +# the controller and UI Deployments; can be overridden per component). +# Useful for admission policies that require specific labels on pods. +podLabels: {} + # -- Additional labels to add to all Kubernetes resources labels: {} # environment: production @@ -226,6 +231,11 @@ controller: podAnnotations: {} + # -- Additional labels for the controller pod template, merged over the + # global `podLabels` (per-key; component keys win). Selector labels can + # never be overridden. + podLabels: {} + # -- Node taints which will be tolerated for `Pod` [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/). tolerations: [] @@ -426,6 +436,11 @@ ui: podAnnotations: {} + # -- Additional labels for the UI pod template, merged over the + # global `podLabels` (per-key; component keys win). Selector labels can + # never be overridden. + podLabels: {} + # -- Node taints which will be tolerated for `Pod` [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/). tolerations: []