From 540ecc9e1edeb7b3f797d8b075287cf3939cd0f2 Mon Sep 17 00:00:00 2001 From: Matteo Porta Date: Wed, 30 Sep 2026 16:46:01 +0200 Subject: [PATCH] fix(shield): keep component labels from overriding sysdig/component and GKE Autopilot labels Sprig's merge keeps the value from the leftmost source on a key collision. cluster.labels, host.labels and host_windows.labels were merged before the chart's own component labels, so a user value for sysdig/component (or, on GKE Autopilot, the autopilot.gke.io/no-connect and cloud.google.com/matching-allowlist labels) replaced the built-in one. Merge the built-in labels first. Global labels were already merged after them. --- charts/shield/Chart.yaml | 2 +- charts/shield/templates/cluster/_labels.tpl | 2 +- charts/shield/templates/host/_labels.tpl | 2 +- .../shield/templates/host/_windows_labels.tpl | 2 +- .../shield/tests/cluster/deployment_test.yaml | 11 ++++++++ .../tests/host/daemonset-windows_test.yaml | 10 +++++++ charts/shield/tests/host/daemonset_test.yaml | 26 +++++++++++++++++++ 7 files changed, 51 insertions(+), 4 deletions(-) diff --git a/charts/shield/Chart.yaml b/charts/shield/Chart.yaml index f0f0c86d9..89220054d 100644 --- a/charts/shield/Chart.yaml +++ b/charts/shield/Chart.yaml @@ -13,5 +13,5 @@ maintainers: - name: mavimo email: marcovito.moscaritolo@sysdig.com type: application -version: 1.55.0 +version: 1.55.1 appVersion: "1.0.0" diff --git a/charts/shield/templates/cluster/_labels.tpl b/charts/shield/templates/cluster/_labels.tpl index e37156f4c..bcb7e7413 100644 --- a/charts/shield/templates/cluster/_labels.tpl +++ b/charts/shield/templates/cluster/_labels.tpl @@ -2,7 +2,7 @@ Common labels */}} {{- define "cluster.labels" -}} - {{- $labels := merge (dict) .Values.cluster.labels (include "cluster.self_labels" . | fromYaml) (include "shield.labels" . | fromYaml) }} + {{- $labels := merge (dict) (include "cluster.self_labels" . | fromYaml) .Values.cluster.labels (include "shield.labels" . | fromYaml) }} {{- with $labels -}} {{- . | toYaml -}} {{- end -}} diff --git a/charts/shield/templates/host/_labels.tpl b/charts/shield/templates/host/_labels.tpl index e1a98c627..111c6bca1 100644 --- a/charts/shield/templates/host/_labels.tpl +++ b/charts/shield/templates/host/_labels.tpl @@ -13,7 +13,7 @@ GKE Autopilot labels Common labels */}} {{- define "host.labels" -}} - {{- $labels := merge (dict) .Values.host.labels (include "host.gke_autopilot_labels" . | fromYaml) (include "host.self_labels" . | fromYaml) (include "shield.labels" . | fromYaml) }} + {{- $labels := merge (dict) (include "host.self_labels" . | fromYaml) (include "host.gke_autopilot_labels" . | fromYaml) .Values.host.labels (include "shield.labels" . | fromYaml) }} {{- with $labels -}} {{- . | toYaml -}} {{- end -}} diff --git a/charts/shield/templates/host/_windows_labels.tpl b/charts/shield/templates/host/_windows_labels.tpl index 5a0f32ae6..9a2a3d0cc 100644 --- a/charts/shield/templates/host/_windows_labels.tpl +++ b/charts/shield/templates/host/_windows_labels.tpl @@ -2,7 +2,7 @@ Common labels */}} {{- define "host.windows.labels" -}} - {{- $labels := merge (dict) .Values.host_windows.labels (include "host.windows.self_labels" . | fromYaml) (include "shield.labels" . | fromYaml) }} + {{- $labels := merge (dict) (include "host.windows.self_labels" . | fromYaml) .Values.host_windows.labels (include "shield.labels" . | fromYaml) }} {{- with $labels -}} {{- . | toYaml -}} {{- end -}} diff --git a/charts/shield/tests/cluster/deployment_test.yaml b/charts/shield/tests/cluster/deployment_test.yaml index 5dab37f92..d7dd825c0 100644 --- a/charts/shield/tests/cluster/deployment_test.yaml +++ b/charts/shield/tests/cluster/deployment_test.yaml @@ -1893,3 +1893,14 @@ tests: path: metadata.labels["env"] value: component-workload template: templates/cluster/deployment.yaml + + - it: cluster.labels cannot override the built-in sysdig/component label + set: + cluster: + labels: + sysdig/component: override + asserts: + - equal: + path: metadata.labels["sysdig/component"] + value: cluster + template: templates/cluster/deployment.yaml diff --git a/charts/shield/tests/host/daemonset-windows_test.yaml b/charts/shield/tests/host/daemonset-windows_test.yaml index ea6a8c379..52c380a25 100644 --- a/charts/shield/tests/host/daemonset-windows_test.yaml +++ b/charts/shield/tests/host/daemonset-windows_test.yaml @@ -615,3 +615,13 @@ tests: - equal: path: metadata.labels["env"] value: component-workload + + - it: host_windows.labels cannot override the built-in sysdig/component label + set: + host_windows: + labels: + sysdig/component: override + asserts: + - equal: + path: metadata.labels["sysdig/component"] + value: host diff --git a/charts/shield/tests/host/daemonset_test.yaml b/charts/shield/tests/host/daemonset_test.yaml index 38d2db1c1..96163bcff 100644 --- a/charts/shield/tests/host/daemonset_test.yaml +++ b/charts/shield/tests/host/daemonset_test.yaml @@ -1372,3 +1372,29 @@ tests: - equal: path: metadata.labels["env"] value: component-workload + + - it: host.labels cannot override the built-in sysdig/component label + set: + host: + labels: + sysdig/component: override + asserts: + - equal: + path: metadata.labels["sysdig/component"] + value: host + + - it: host.labels cannot override the GKE Autopilot labels + values: + - ../values/gke-autopilot.yaml + set: + gke_autopilot_allowlist: sysdig-agent-v2.0.0 + host: + labels: + autopilot.gke.io/no-connect: "false" + cloud.google.com/matching-allowlist: override + asserts: + - isSubset: + path: metadata.labels + content: + autopilot.gke.io/no-connect: "true" + cloud.google.com/matching-allowlist: sysdig-agent-v2.0.0