Skip to content

Commit

Permalink
chore(labels): adds pod.lifecycle label to pod labels (#660)
Browse files Browse the repository at this point in the history
**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ 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?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ 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._
  • Loading branch information
stavros-k authored Dec 25, 2023
1 parent 7165028 commit d8ae55f
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 23 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/common_library_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/common-test/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/common-test/tests/cronjob/metadata_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions library/common-test/tests/daemonset/metadata_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions library/common-test/tests/deployment/metadata_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions library/common-test/tests/ingress/homepage_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/common-test/tests/job/metadata_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions library/common-test/tests/pod/topologySpreadConstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions library/common-test/tests/statefulset/metadata_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion library/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 17.0.2
version: 17.1.0
2 changes: 1 addition & 1 deletion library/common/templates/class/_cronjob.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion library/common/templates/class/_daemonset.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion library/common/templates/class/_deployment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion library/common/templates/class/_job.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion library/common/templates/class/_statefulset.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

Expand Down
20 changes: 20 additions & 0 deletions library/common/templates/lib/metadata/_podLabels.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

0 comments on commit d8ae55f

Please sign in to comment.