From d8ae55f0d328288aa7e15fed278cfe714de25cf3 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Mon, 25 Dec 2023 17:37:23 +0200 Subject: [PATCH] chore(labels): adds pod.lifecycle label to pod labels (#660) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes # **⚙️ Type of change** - [x] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [x] ⚖️ My code follows the style guidelines of this project - [x] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [x] ⚠️ My changes generate no new warnings - [x] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [x] ⬆️ I increased versions for any altered app according to semantic versioning **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --- .github/workflows/common_library_tests.yaml | 12 +++++----- library/common-test/Chart.yaml | 2 +- .../tests/cronjob/metadata_test.yaml | 1 + .../tests/daemonset/metadata_test.yaml | 3 +++ .../tests/deployment/metadata_test.yaml | 3 +++ .../tests/ingress/homepage_test.yaml | 8 +++---- .../common-test/tests/job/metadata_test.yaml | 1 + .../tests/pod/topologySpreadConstraints.yaml | 22 +++++++++++++++---- .../tests/statefulset/metadata_test.yaml | 3 +++ library/common/Chart.yaml | 2 +- library/common/templates/class/_cronjob.tpl | 2 +- library/common/templates/class/_daemonset.tpl | 2 +- .../common/templates/class/_deployment.tpl | 2 +- library/common/templates/class/_job.tpl | 2 +- .../common/templates/class/_statefulset.tpl | 2 +- .../lib/ingress/integrations/_homepage.tpl | 4 ++-- .../templates/lib/metadata/_podLabels.tpl | 20 +++++++++++++++++ 17 files changed, 68 insertions(+), 23 deletions(-) diff --git a/.github/workflows/common_library_tests.yaml b/.github/workflows/common_library_tests.yaml index cb098478..0a2ec59d 100644 --- a/.github/workflows/common_library_tests.yaml +++ b/.github/workflows/common_library_tests.yaml @@ -23,7 +23,7 @@ jobs: matrix: helm-version: - v3.12.3 - - v3.13.2 + - v3.13.3 steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 @@ -62,7 +62,7 @@ jobs: matrix: helm-version: - v3.12.3 - - v3.13.2 + - v3.13.3 steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 @@ -110,7 +110,7 @@ jobs: # We run tests on Helm version of latest SCALE, fluxcd and latest helm release helm-version: - v3.12.3 - - v3.13.2 + - v3.13.3 values: - basic-values.yaml - configmap-values.yaml @@ -259,7 +259,7 @@ jobs: # # We run tests on Helm version of latest SCALE release # helm-version: # - v3.12.3 -# - v3.13.2 +# - v3.13.3 # values: # - basic-values.yaml # - configmap-values.yaml @@ -323,7 +323,7 @@ jobs: # # We run tests on Helm version of latest SCALE release # helm-version: # - v3.12.3 -# - v3.13.2 +# - v3.13.3 # values: # - ingress-values.yaml # - metrics-values.yaml @@ -383,7 +383,7 @@ jobs: # # We run tests on Helm version of latest SCALE release # helm-version: # - v3.12.3 -# - v3.13.2 +# - v3.13.3 # values: # - vpn-gluetun-values.yaml # - vpn-tailscale-values.yaml diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index 2f93a722..3b1b3583 100644 --- a/library/common-test/Chart.yaml +++ b/library/common-test/Chart.yaml @@ -3,7 +3,7 @@ appVersion: "" dependencies: - name: common repository: file://../common - version: ~17.0.0 + version: ~17.1.0 deprecated: false description: Helper chart to test different use cases of the common library home: https://github.com/truecharts/apps/tree/master/charts/library/common-test diff --git a/library/common-test/tests/cronjob/metadata_test.yaml b/library/common-test/tests/cronjob/metadata_test.yaml index 80e51cd3..e593862a 100644 --- a/library/common-test/tests/cronjob/metadata_test.yaml +++ b/library/common-test/tests/cronjob/metadata_test.yaml @@ -80,6 +80,7 @@ tests: path: spec.jobTemplate.spec.template.metadata.labels value: pod.name: workload-name + pod.lifecycle: fleeting app: common-test-1.0.0 release: test-release-name app.kubernetes.io/instance: test-release-name diff --git a/library/common-test/tests/daemonset/metadata_test.yaml b/library/common-test/tests/daemonset/metadata_test.yaml index 8ce25c65..541ce02f 100644 --- a/library/common-test/tests/daemonset/metadata_test.yaml +++ b/library/common-test/tests/daemonset/metadata_test.yaml @@ -86,6 +86,7 @@ tests: path: spec.template.metadata.labels value: pod.name: workload-name + pod.lifecycle: permanent app: common-test-1.0.0 release: test-release-name app.kubernetes.io/instance: test-release-name @@ -140,6 +141,7 @@ tests: path: spec.template.metadata.labels content: pod.name: other-workload-name + pod.lifecycle: permanent app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test - documentIndex: &otherDaemonSetDoc 1 @@ -165,6 +167,7 @@ tests: path: spec.template.metadata.labels content: pod.name: workload-name + pod.lifecycle: permanent app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test diff --git a/library/common-test/tests/deployment/metadata_test.yaml b/library/common-test/tests/deployment/metadata_test.yaml index 2d632731..199233ea 100644 --- a/library/common-test/tests/deployment/metadata_test.yaml +++ b/library/common-test/tests/deployment/metadata_test.yaml @@ -86,6 +86,7 @@ tests: path: spec.template.metadata.labels value: pod.name: workload-name + pod.lifecycle: permanent app: common-test-1.0.0 release: test-release-name app.kubernetes.io/instance: test-release-name @@ -140,6 +141,7 @@ tests: path: spec.template.metadata.labels content: pod.name: other-workload-name + pod.lifecycle: permanent app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test - documentIndex: &otherDeploymentDoc 1 @@ -165,6 +167,7 @@ tests: path: spec.template.metadata.labels content: pod.name: workload-name + pod.lifecycle: permanent app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test diff --git a/library/common-test/tests/ingress/homepage_test.yaml b/library/common-test/tests/ingress/homepage_test.yaml index 251db17e..aec74941 100644 --- a/library/common-test/tests/ingress/homepage_test.yaml +++ b/library/common-test/tests/ingress/homepage_test.yaml @@ -125,7 +125,7 @@ tests: gethomepage.dev/widget.url: https://test-release-name-common-test.test-release-namespace.svc:9443 gethomepage.dev/icon: https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png gethomepage.dev/widget.type: commontest - gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name + gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent) - documentIndex: *ingressDoc equal: path: metadata.name @@ -150,7 +150,7 @@ tests: gethomepage.dev/widget.url: some-url gethomepage.dev/weight: "1" gethomepage.dev/widget.type: some-type - gethomepage.dev/pod-selector: pod.name in (main,other) + gethomepage.dev/pod-selector: pod.name in (main,other),pod.lifecycle in (permanent) gethomepage.dev/widget.some-key: some-value gethomepage.dev/widget.some-other-key: some-other-value gethomepage.dev/widget.some-key-slice: some-value-slice @@ -177,7 +177,7 @@ tests: gethomepage.dev/widget.url: http://test-release-name-common-test-my-service2.test-release-namespace.svc:80 gethomepage.dev/icon: https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png gethomepage.dev/widget.type: commontest - gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name + gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent) - documentIndex: *thirdIngressDoc equal: path: metadata.name @@ -198,7 +198,7 @@ tests: gethomepage.dev/description: Helper chart to test different use cases of the common library gethomepage.dev/href: https://test-host/test-path gethomepage.dev/icon: https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png - gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name + gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent) # Failures - it: should fail with podSelector not a slice diff --git a/library/common-test/tests/job/metadata_test.yaml b/library/common-test/tests/job/metadata_test.yaml index c4591673..7d0a6569 100644 --- a/library/common-test/tests/job/metadata_test.yaml +++ b/library/common-test/tests/job/metadata_test.yaml @@ -79,6 +79,7 @@ tests: path: spec.template.metadata.labels value: pod.name: workload-name + pod.lifecycle: fleeting app: common-test-1.0.0 release: test-release-name app.kubernetes.io/instance: test-release-name diff --git a/library/common-test/tests/pod/topologySpreadConstraints.yaml b/library/common-test/tests/pod/topologySpreadConstraints.yaml index e1788eb1..0752ec3d 100644 --- a/library/common-test/tests/pod/topologySpreadConstraints.yaml +++ b/library/common-test/tests/pod/topologySpreadConstraints.yaml @@ -101,6 +101,13 @@ tests: type: Deployment podSpec: {} asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/instance: test-release-name + app.kubernetes.io/name: common-test + pod.name: workload-name1 - documentIndex: *deploymentDoc equal: path: spec.template.spec.topologySpreadConstraints @@ -109,7 +116,7 @@ tests: matchLabels: app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test - pod.name: test-release-name-common-test + pod.name: workload-name1 maxSkew: 1 nodeAffinityPolicy: Honor nodeTaintsPolicy: Honor @@ -119,7 +126,7 @@ tests: matchLabels: app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test - pod.name: test-release-name-common-test + pod.name: workload-name1 maxSkew: 1 nodeAffinityPolicy: Honor nodeTaintsPolicy: Honor @@ -166,6 +173,13 @@ tests: nodeAffinityPolicy: Honor nodeTaintsPolicy: Honor asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/instance: test-release-name + app.kubernetes.io/name: common-test + pod.name: workload-name1 - documentIndex: *deploymentDoc equal: path: spec.template.spec.topologySpreadConstraints @@ -174,7 +188,7 @@ tests: matchLabels: app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test - pod.name: test-release-name-common-test + pod.name: workload-name1 maxSkew: 1 nodeAffinityPolicy: Honor nodeTaintsPolicy: Honor @@ -184,7 +198,7 @@ tests: matchLabels: app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test - pod.name: test-release-name-common-test + pod.name: workload-name1 maxSkew: 1 nodeAffinityPolicy: Honor nodeTaintsPolicy: Honor diff --git a/library/common-test/tests/statefulset/metadata_test.yaml b/library/common-test/tests/statefulset/metadata_test.yaml index f7765fac..a7b6ad79 100644 --- a/library/common-test/tests/statefulset/metadata_test.yaml +++ b/library/common-test/tests/statefulset/metadata_test.yaml @@ -86,6 +86,7 @@ tests: path: spec.template.metadata.labels value: pod.name: workload-name + pod.lifecycle: permanent app: common-test-1.0.0 release: test-release-name app.kubernetes.io/instance: test-release-name @@ -140,6 +141,7 @@ tests: path: spec.template.metadata.labels content: pod.name: other-workload-name + pod.lifecycle: permanent app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test - documentIndex: &otherStatefulSetDoc 1 @@ -165,6 +167,7 @@ tests: path: spec.template.metadata.labels content: pod.name: workload-name + pod.lifecycle: permanent app.kubernetes.io/instance: test-release-name app.kubernetes.io/name: common-test diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 5cb7c42c..d42e83fb 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 17.0.2 +version: 17.1.0 diff --git a/library/common/templates/class/_cronjob.tpl b/library/common/templates/class/_cronjob.tpl index 3efcc584..77a319b2 100644 --- a/library/common/templates/class/_cronjob.tpl +++ b/library/common/templates/class/_cronjob.tpl @@ -33,7 +33,7 @@ spec: metadata: {{- $labels := (mustMerge ($objectData.podSpec.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml) - (include "tc.v1.common.lib.metadata.podLabels" $rootCtx | fromYaml) + (include "tc.v1.common.lib.metadata.podLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) (include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: diff --git a/library/common/templates/class/_daemonset.tpl b/library/common/templates/class/_daemonset.tpl index 4bfd2af6..90787de9 100644 --- a/library/common/templates/class/_daemonset.tpl +++ b/library/common/templates/class/_daemonset.tpl @@ -36,7 +36,7 @@ spec: metadata: {{- $labels := (mustMerge ($objectData.podSpec.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml) - (include "tc.v1.common.lib.metadata.podLabels" $rootCtx | fromYaml) + (include "tc.v1.common.lib.metadata.podLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) (include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: diff --git a/library/common/templates/class/_deployment.tpl b/library/common/templates/class/_deployment.tpl index 3238a5c1..56657bea 100644 --- a/library/common/templates/class/_deployment.tpl +++ b/library/common/templates/class/_deployment.tpl @@ -36,7 +36,7 @@ spec: metadata: {{- $labels := (mustMerge ($objectData.podSpec.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml) - (include "tc.v1.common.lib.metadata.podLabels" $rootCtx | fromYaml) + (include "tc.v1.common.lib.metadata.podLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) (include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: diff --git a/library/common/templates/class/_job.tpl b/library/common/templates/class/_job.tpl index e6630cf3..8ddba5a8 100644 --- a/library/common/templates/class/_job.tpl +++ b/library/common/templates/class/_job.tpl @@ -33,7 +33,7 @@ spec: metadata: {{- $labels := (mustMerge ($objectData.podSpec.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml) - (include "tc.v1.common.lib.metadata.podLabels" $rootCtx | fromYaml) + (include "tc.v1.common.lib.metadata.podLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) (include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: diff --git a/library/common/templates/class/_statefulset.tpl b/library/common/templates/class/_statefulset.tpl index 289ba824..c07e5fec 100644 --- a/library/common/templates/class/_statefulset.tpl +++ b/library/common/templates/class/_statefulset.tpl @@ -36,7 +36,7 @@ spec: metadata: {{- $labels := (mustMerge ($objectData.podSpec.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml) - (include "tc.v1.common.lib.metadata.podLabels" $rootCtx | fromYaml) + (include "tc.v1.common.lib.metadata.podLabels" (dict "rootCtx" $rootCtx "objectData" $objectData) | fromYaml) (include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $objectData.shortName) | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} labels: diff --git a/library/common/templates/lib/ingress/integrations/_homepage.tpl b/library/common/templates/lib/ingress/integrations/_homepage.tpl index 4711dcb0..2f103f7b 100644 --- a/library/common/templates/lib/ingress/integrations/_homepage.tpl +++ b/library/common/templates/lib/ingress/integrations/_homepage.tpl @@ -56,9 +56,9 @@ {{- $_ := set $objectData.annotations "gethomepage.dev/weight" (. | toString) -}} {{- end -}} - {{- $selector := printf "app.kubernetes.io/instance=%s" $rootCtx.Release.Name -}} + {{- $selector := printf "app.kubernetes.io/instance=%s,pod.lifecycle in (permanent)" $rootCtx.Release.Name -}} {{- with $homepage.podSelector -}} - {{- $selector = (printf "pod.name in (%s)" (join "," .)) -}} + {{- $selector = (printf "pod.name in (%s),pod.lifecycle in (permanent)" (join "," .)) -}} {{- end -}} {{- $_ := set $objectData.annotations "gethomepage.dev/pod-selector" $selector -}} diff --git a/library/common/templates/lib/metadata/_podLabels.tpl b/library/common/templates/lib/metadata/_podLabels.tpl index a227d36e..0f6b5370 100644 --- a/library/common/templates/lib/metadata/_podLabels.tpl +++ b/library/common/templates/lib/metadata/_podLabels.tpl @@ -3,4 +3,24 @@ {{ include "tc.v1.common.lib.metadata.podLabels" $ }} */}} {{- define "tc.v1.common.lib.metadata.podLabels" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $type := $objectData.type -}} + + {{- $label := "" -}} + {{- $fleeting := (list "CronJob" "Job") -}} + {{- if (mustHas $type $fleeting) -}} + {{- $label = "fleeting" -}} + {{- end -}} + + {{- $permanent := (list "Deployment" "StatefulSet" "DaemonSet") -}} + {{- if (mustHas $type $permanent) -}} + {{- $label = "permanent" -}} + {{- end -}} + + {{- if not $label -}} + {{- fail "PodLabels - Template used in a place that is not designed to be used" -}} + {{- end }} +pod.lifecycle: {{ $label }} {{- end -}}