fix(common): set correct default for restartPolicy for cronjobs (#28356)

**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  #28118

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [x] 🪛 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
- [x] 📄 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
- [x] I made sure the title starts with `feat(chart-name):`,
`fix(chart-name):` or `chore(chart-name):`

** App addition**

If this PR is an app addition please make sure you have done the
following.

- [ ] 🖼️ 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._
This commit is contained in:
Stavros Kois
2024-10-26 18:55:53 +03:00
committed by GitHub
parent b16bd485cf
commit 006cae1856
12 changed files with 86 additions and 6 deletions
@@ -16,7 +16,6 @@ workload:
type: CronJob type: CronJob
schedule: "*/1 * * * *" schedule: "*/1 * * * *"
podSpec: podSpec:
restartPolicy: OnFailure
containers: containers:
main: main:
enabled: true enabled: true
@@ -84,6 +84,11 @@ tests:
parallelism: 5 parallelism: 5
ttlSecondsAfterFinished: 100 ttlSecondsAfterFinished: 100
activeDeadlineSeconds: 100 activeDeadlineSeconds: 100
- documentIndex: *cronJobDoc
isSubset:
path: spec.jobTemplate.spec.template.spec
content:
restartPolicy: OnFailure
- it: should set suspend to true - it: should set suspend to true
set: set:
@@ -58,3 +58,17 @@ tests:
asserts: asserts:
- failedTemplate: - failedTemplate:
errorMessage: CronJob - Namespace [my-extra-super-duper-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters. errorMessage: CronJob - Namespace [my-extra-super-duper-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters.
- it: should fail with restartPolicy "Always" for CronJob
set:
workload:
workload-name:
enabled: true
primary: true
type: CronJob
schedule: "* * * * *"
podSpec:
restartPolicy: Always
asserts:
- failedTemplate:
errorMessage: Expected [restartPolicy] to be one of [Never, OnFailure] for [CronJob] but got [Always]
@@ -123,7 +123,7 @@ tests:
gethomepage.dev/description: Helper chart to test different use cases of the common library gethomepage.dev/description: Helper chart to test different use cases of the common library
gethomepage.dev/href: https://test-host/test-path gethomepage.dev/href: https://test-host/test-path
gethomepage.dev/widget.url: https://test-release-name-common-test.test-release-namespace.svc:9443 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/icon: https://truecharts.org/img/hotlink-ok/chart-icons/common-test.webp
gethomepage.dev/widget.type: commontest gethomepage.dev/widget.type: commontest
gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent) gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent)
- documentIndex: *ingressDoc - documentIndex: *ingressDoc
@@ -183,7 +183,7 @@ tests:
gethomepage.dev/description: Helper chart to test different use cases of the common library gethomepage.dev/description: Helper chart to test different use cases of the common library
gethomepage.dev/href: https://test-host/test-path gethomepage.dev/href: https://test-host/test-path
gethomepage.dev/widget.url: http://test-release-name-common-test-my-service2.test-release-namespace.svc:80 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/icon: https://truecharts.org/img/hotlink-ok/chart-icons/common-test.webp
gethomepage.dev/widget.type: commontest gethomepage.dev/widget.type: commontest
gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent) gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent)
- documentIndex: *thirdIngressDoc - documentIndex: *thirdIngressDoc
@@ -205,7 +205,7 @@ tests:
gethomepage.dev/name: TestReleaseName gethomepage.dev/name: TestReleaseName
gethomepage.dev/description: Helper chart to test different use cases of the common library gethomepage.dev/description: Helper chart to test different use cases of the common library
gethomepage.dev/href: https://test-host/test-path 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/icon: https://truecharts.org/img/hotlink-ok/chart-icons/common-test.webp
gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent) gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent)
# Failures # Failures
@@ -55,6 +55,11 @@ tests:
parallelism: 5 parallelism: 5
ttlSecondsAfterFinished: 100 ttlSecondsAfterFinished: 100
activeDeadlineSeconds: 100 activeDeadlineSeconds: 100
- documentIndex: *jobDoc
isSubset:
path: spec.template.spec
content:
restartPolicy: OnFailure
- it: should set parallelism to 0 - it: should set parallelism to 0
set: set:
@@ -59,3 +59,16 @@ tests:
asserts: asserts:
- failedTemplate: - failedTemplate:
errorMessage: Job - Namespace [my-extra-super-duper-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters. errorMessage: Job - Namespace [my-extra-super-duper-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters.
- it: should fail with restartPolicy "Always" for Job
set:
workload:
workload-name:
enabled: true
primary: true
type: Job
podSpec:
restartPolicy: Always
asserts:
- failedTemplate:
errorMessage: Expected [restartPolicy] to be one of [Never, OnFailure] for [Job] but got [Always]
+1 -1
View File
@@ -48,4 +48,4 @@ sources:
- https://hub.docker.com/r/mikefarah/yq - https://hub.docker.com/r/mikefarah/yq
- https://hub.docker.com/r/traefik/whoami - https://hub.docker.com/r/traefik/whoami
type: library type: library
version: 25.1.0 version: 25.1.1
@@ -10,6 +10,11 @@ objectData: The object data to be used to render the Pod.
{{- $policy := "Always" -}} {{- $policy := "Always" -}}
{{- $jobTypes := (list "Job" "CronJob") -}}
{{- if mustHas $objectData.type $jobTypes -}}
{{- $policy = "OnFailure" -}}
{{- end -}}
{{/* Initialize from the "defaults" */}} {{/* Initialize from the "defaults" */}}
{{- with $rootCtx.Values.podOptions.restartPolicy -}} {{- with $rootCtx.Values.podOptions.restartPolicy -}}
{{- $policy = tpl . $rootCtx -}} {{- $policy = tpl . $rootCtx -}}
@@ -30,5 +35,10 @@ objectData: The object data to be used to render the Pod.
{{- fail (printf "Expected [restartPolicy] to be [Always] for [%s] but got [%s]" $objectData.type $policy) -}} {{- fail (printf "Expected [restartPolicy] to be [Always] for [%s] but got [%s]" $objectData.type $policy) -}}
{{- end -}} {{- end -}}
{{- if and (eq "Always" $policy) (mustHas $objectData.type $jobTypes) -}}
{{- $cronPolicies := mustWithout $policies "Always" -}}
{{- fail (printf "Expected [restartPolicy] to be one of [%s] for [%s] but got [%s]" (join ", " $cronPolicies) $objectData.type $policy) -}}
{{- end -}}
{{- $policy -}} {{- $policy -}}
{{- end -}} {{- end -}}
-1
View File
@@ -160,7 +160,6 @@ podOptions:
# If this key exists, takes precedence over the automated calculation # If this key exists, takes precedence over the automated calculation
# hostUsers: false # hostUsers: false
shareProcessNamespace: false shareProcessNamespace: false
restartPolicy: Always
dnsPolicy: ClusterFirst dnsPolicy: ClusterFirst
dnsConfig: dnsConfig:
options: options:
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
# https://github.com/helm-unittest/helm-unittest
# -- You need to install this helm plugin
# helm plugin install https://github.com/helm-unittest/helm-unittest
common_test_path="charts/library/common-test"
function cleanup {
if [ -d "$common_test_path/charts" ]; then
echo "🧹 Cleaning up charts..."
rm -r "$common_test_path/charts"
rm "$common_test_path/Chart.lock"
# Clean snapshots
rm -r "$common_test_path/**/__snapshot__" 2>/dev/null
fi
}
cleanup
echo "🔨 Building common..."
helm dependency update "$common_test_path"
echo "🧪 Running tests..."
helm unittest --update-snapshot -f "tests/*/*.yaml" "./$common_test_path" -v ./$common_test_path/unit-values.yaml
cleanup
@@ -20,6 +20,10 @@ Replace references to `$name` with the actual name you want to use.
- `.Values.workload.$name` - `.Values.workload.$name`
## Notes
Value of `workload.$name.podSpec.restartPolicy` can **not** be `Always` for this type of workload
## `schedule` ## `schedule`
Define the schedule Define the schedule
@@ -20,6 +20,10 @@ Replace references to `$name` with the actual name you want to use.
- `.Values.workload.$name` - `.Values.workload.$name`
## Notes
Value of `workload.$name.podSpec.restartPolicy` can **not** be `Always` for this type of workload
--- ---
## `completionMode` ## `completionMode`