Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions chart/newsfragments/53190.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow Dag processor pod labels to be configured separately with ``dagProcessor.podLabels``.
12 changes: 9 additions & 3 deletions chart/templates/dag-processor/dag-processor-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
{{- $containerSecurityContextLogGroomerSidecar := include "containerSecurityContext" (list .Values.dagProcessor.logGroomerSidecar .Values) }}
{{- $containerSecurityContextWaitForMigrations := include "containerSecurityContext" (list .Values.dagProcessor.waitForMigrations .Values) }}
{{- $containerLifecycleHooks := or .Values.dagProcessor.containerLifecycleHooks .Values.containerLifecycleHooks }}
{{- $deploymentLabels := .Values.labels }}
{{- $podLabels := .Values.dagProcessor.labels }}
{{- if ne .Values.dagProcessor.podLabels nil }}
{{- $deploymentLabels = mustMerge (deepCopy .Values.dagProcessor.labels) .Values.labels }}
{{- $podLabels = .Values.dagProcessor.podLabels }}
{{- end }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -41,7 +47,7 @@ metadata:
release: {{ .Release.Name }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service }}
{{- with .Values.labels }}
{{- with $deploymentLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- if .Values.dagProcessor.annotations }}
Expand All @@ -66,8 +72,8 @@ spec:
tier: airflow
component: dag-processor
release: {{ .Release.Name }}
{{- if or .Values.labels .Values.dagProcessor.labels }}
{{- mustMerge .Values.dagProcessor.labels .Values.labels | toYaml | nindent 8 }}
{{- if or .Values.labels $podLabels }}
{{- mustMerge (deepCopy $podLabels) .Values.labels | toYaml | nindent 8 }}
{{- end }}
annotations:
checksum/metadata-secret: {{ include (print $.Template.BasePath "/secrets/metadata-connection-secret.yaml") . | sha256sum }}
Expand Down
76 changes: 76 additions & 0 deletions chart/tests/helm_tests/dagprocessor/test_labels_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,82 @@ def test_should_add_component_specific_labels(self):
== "test_component_label_value"
)

def test_should_preserve_component_labels_on_pods_when_pod_labels_are_unset(self):
docs = render_chart(
values={
"labels": {
"test_global_label": "test_global_label_value",
"common_label": "global_value",
},
"dagProcessor": {
"labels": {
"test_component_label": "test_component_label_value",
"common_label": "component_value",
},
},
},
show_only=[self.TEMPLATE_FILE],
)

deployment_labels = jmespath.search("metadata.labels", docs[0])
pod_labels = jmespath.search("spec.template.metadata.labels", docs[0])
assert deployment_labels["test_global_label"] == "test_global_label_value"
assert "test_component_label" not in deployment_labels
assert deployment_labels["common_label"] == "global_value"
assert pod_labels["test_global_label"] == "test_global_label_value"
assert pod_labels["test_component_label"] == "test_component_label_value"
assert pod_labels["common_label"] == "component_value"

def test_should_separate_deployment_and_pod_labels(self):
docs = render_chart(
values={
"labels": {
"test_global_label": "test_global_label_value",
"common_label": "global_value",
},
"dagProcessor": {
"labels": {
"test_component_label": "test_component_label_value",
"common_label": "component_value",
},
"podLabels": {
"test_pod_label": "test_pod_label_value",
"common_label": "pod_value",
},
},
},
show_only=[self.TEMPLATE_FILE],
)

deployment_labels = jmespath.search("metadata.labels", docs[0])
pod_labels = jmespath.search("spec.template.metadata.labels", docs[0])
assert deployment_labels["test_global_label"] == "test_global_label_value"
assert deployment_labels["test_component_label"] == "test_component_label_value"
assert "test_pod_label" not in deployment_labels
assert deployment_labels["common_label"] == "component_value"
assert pod_labels["test_global_label"] == "test_global_label_value"
assert "test_component_label" not in pod_labels
assert pod_labels["test_pod_label"] == "test_pod_label_value"
assert pod_labels["common_label"] == "pod_value"

def test_should_treat_empty_pod_labels_as_separate(self):
docs = render_chart(
values={
"labels": {"test_global_label": "test_global_label_value"},
"dagProcessor": {
"labels": {"test_component_label": "test_component_label_value"},
"podLabels": {},
},
},
show_only=[self.TEMPLATE_FILE],
)

deployment_labels = jmespath.search("metadata.labels", docs[0])
pod_labels = jmespath.search("spec.template.metadata.labels", docs[0])
assert deployment_labels["test_component_label"] == "test_component_label_value"
assert "test_component_label" not in pod_labels
assert pod_labels["test_global_label"] == "test_global_label_value"

def test_should_merge_global_and_component_specific_labels(self):
"""Test adding both .Values.labels and .Values.dagProcessor.labels."""
docs = render_chart(
Expand Down
13 changes: 12 additions & 1 deletion chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4883,13 +4883,24 @@
}
},
"labels": {
"description": "Labels specific to dag processor objects and pods",
"description": "Labels for dag processor objects. If podLabels is not set, these labels are applied to pods but not the Deployment for backward compatibility.",
"type": "object",
"default": {},
"additionalProperties": {
"type": "string"
}
},
"podLabels": {
"description": "Labels for dag processor pods. Set to an empty object to use only global labels on pods.",
"type": [
"object",
"null"
],
"default": null,
"additionalProperties": {
"type": "string"
}
},
"env": {
"description": "Add additional env vars to dag processor.",
"type": "array",
Expand Down
6 changes: 5 additions & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2316,9 +2316,13 @@ dagProcessor:
securityContexts:
container: {}

# Labels specific to dag processor objects
# Labels for dag processor objects. If podLabels is not set, these labels are
# applied to pods but not the Deployment for backward compatibility.
labels: {}

# Labels for dag processor pods. Set to {} to use only global labels on pods.
podLabels: ~

# Environment variables to add to dag processor container
env: []

Expand Down