From a825efcfacec237f1be37197cc2638f32dbb5505 Mon Sep 17 00:00:00 2001 From: Simon Lauger Date: Fri, 24 Mar 2023 18:40:25 +0100 Subject: [PATCH 01/10] fix: make deployment.image.tag and job.image.tag optional --- application/templates/_helpers.tpl | 4 +++- application/templates/cronjob.yaml | 10 ++++++++-- application/templates/deployment.yaml | 12 +++++++++--- application/values.yaml | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/application/templates/_helpers.tpl b/application/templates/_helpers.tpl index fba89c90..48f1ef03 100644 --- a/application/templates/_helpers.tpl +++ b/application/templates/_helpers.tpl @@ -39,7 +39,9 @@ Common labels */}} {{- define "application.labels" -}} helm.sh/chart: {{ include "application.chart" . }} +{{- if .Values.deployment.image.tag }} app.kubernetes.io/version: {{ include "application.version" . | quote }} +{{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/part-of: {{ include "application.name" . }} {{- end }} @@ -56,4 +58,4 @@ Allow the release namespace to be overridden */}} {{- define "application.namespace" -}} {{- default .Release.Namespace .Values.namespaceOverride -}} -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/application/templates/cronjob.yaml b/application/templates/cronjob.yaml index 229b15f8..f835740f 100644 --- a/application/templates/cronjob.yaml +++ b/application/templates/cronjob.yaml @@ -43,11 +43,17 @@ spec: {{- end }} containers: - name: {{ $name }} + {{- if $job.image.tag }} {{- if $job.image.digest }} - image: "{{ $job.image.repository }}@{{ $job.image.digest }}" - {{- else if $job.image.tag }} + image: "{{ $job.image.repository }}:{{ $job.image.tag }}@{{ $job.image.digest }}" + {{- else }} image: "{{ $job.image.repository }}:{{ $job.image.tag }}" {{- end }} + {{- else if $job.image.digest }} + image: "{{ $job.image.repository }}@{{ $job.image.digest }}" + {{- else }} + image: "{{ $job.image.repository }}" + {{- end }} {{- if $job.image.imagePullPolicy }} imagePullPolicy: {{ $job.image.imagePullPolicy }} {{ end }} diff --git a/application/templates/deployment.yaml b/application/templates/deployment.yaml index e6673cc6..eeff5d20 100644 --- a/application/templates/deployment.yaml +++ b/application/templates/deployment.yaml @@ -130,11 +130,17 @@ spec: name: proxy-tls {{- end }} - name: {{ template "application.name" . }} + {{- if .Values.deployment.image.tag }} {{- if .Values.deployment.image.digest }} - image: "{{ .Values.deployment.image.repository }}@{{ .Values.deployment.image.digest }}" - {{- else if .Values.deployment.image.tag }} + image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}@{{ .Values.deployment.image.digest }}" + {{- else }} image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}" {{- end }} + {{- else if .Values.deployment.image.digest }} + image: "{{ .Values.deployment.image.repository }}@{{ .Values.deployment.image.digest }}" + {{- else }} + image: "{{ .Values.deployment.image.repository }}" + {{- end }} imagePullPolicy: {{ .Values.deployment.image.pullPolicy }} {{- if .Values.deployment.command }} command: {{- include "application.tplvalues.render" (dict "value" .Values.deployment.command "context" $) | nindent 12 }} @@ -295,4 +301,4 @@ spec: {{- else }} serviceAccountName: {{ template "application.name" . }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/application/values.yaml b/application/values.yaml index 9c559e38..74feffa6 100644 --- a/application/values.yaml +++ b/application/values.yaml @@ -190,7 +190,7 @@ deployment: # Image of the app container image: repository: repository/image-name - tag: v1.0.0 + tag: null digest: '' # if set to a non empty value, digest takes precedence on the tag pullPolicy: IfNotPresent dnsConfig: From b55f443cb20f16faf4609403a05b02397c5acadb Mon Sep 17 00:00:00 2001 From: Simon Lauger Date: Fri, 24 Mar 2023 21:03:23 +0100 Subject: [PATCH 02/10] docs: update documentation and changelog --- CHANGELOG.md | 4 ++++ README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5b69455..baa6a2f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented here. +### v2.2.0 + +- Fix: make deployment.image.tag and job.image.tag optional [PR-234](https://github.com/stakater/application/pull/234) + ### v2.1.11 - Feature: Add topologySpreadConstraints [PR-239](https://github.com/stakater/application/pull/239) diff --git a/README.md b/README.md index f7902973..ae2c97d4 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ To uninstall the chart: | Name | Description | Value | | ------------------------ | -------------------------------------------------------------------------------------------- | --------------- | | deployment.image.repository | Image repository for the application | `repository/image-name` | -| deployment.image.tag | Tag of the application image | `v1.0.0` | +| deployment.image.tag | Tag of the application image | `null` | | deployment.image.digest | Digest of the application image | `` | | deployment.image.pullPolicy | Pull policy for the application image | `IfNotPresent` | From edb3106403ec582c2ff6202d56d040453ec80063 Mon Sep 17 00:00:00 2001 From: Simon Lauger Date: Mon, 27 Mar 2023 09:52:09 +0200 Subject: [PATCH 03/10] fix: default to empty string instead of null --- application/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/values.yaml b/application/values.yaml index 74feffa6..918a0ef5 100644 --- a/application/values.yaml +++ b/application/values.yaml @@ -190,7 +190,7 @@ deployment: # Image of the app container image: repository: repository/image-name - tag: null + tag: '' digest: '' # if set to a non empty value, digest takes precedence on the tag pullPolicy: IfNotPresent dnsConfig: From 3efeba92490dbbd121b4cb09b7d976c035b6751c Mon Sep 17 00:00:00 2001 From: d3adb5 Date: Tue, 11 Apr 2023 15:31:17 -0700 Subject: [PATCH 04/10] refactor: simplify logic in determining image string Simplify the logic in determining the image string for containers in a CronJob or Deployment resource. --- application/templates/cronjob.yaml | 17 ++++++----------- application/templates/deployment.yaml | 17 ++++++----------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/application/templates/cronjob.yaml b/application/templates/cronjob.yaml index f835740f..a2352a85 100644 --- a/application/templates/cronjob.yaml +++ b/application/templates/cronjob.yaml @@ -43,17 +43,12 @@ spec: {{- end }} containers: - name: {{ $name }} - {{- if $job.image.tag }} - {{- if $job.image.digest }} - image: "{{ $job.image.repository }}:{{ $job.image.tag }}@{{ $job.image.digest }}" - {{- else }} - image: "{{ $job.image.repository }}:{{ $job.image.tag }}" - {{- end }} - {{- else if $job.image.digest }} - image: "{{ $job.image.repository }}@{{ $job.image.digest }}" - {{- else }} - image: "{{ $job.image.repository }}" - {{- end }} + + {{- $image := required (print "Undefined image repo for container '" $name "'") $job.image.repository }} + {{- with $job.image.tag }} {{- $image = print $image ":" . }} {{- end }} + {{- with $job.image.digest }} {{- $image = print $image "@" . }} {{- end }} + image: {{ $image }} + {{- if $job.image.imagePullPolicy }} imagePullPolicy: {{ $job.image.imagePullPolicy }} {{ end }} diff --git a/application/templates/deployment.yaml b/application/templates/deployment.yaml index eeff5d20..bbe14c63 100644 --- a/application/templates/deployment.yaml +++ b/application/templates/deployment.yaml @@ -130,17 +130,12 @@ spec: name: proxy-tls {{- end }} - name: {{ template "application.name" . }} - {{- if .Values.deployment.image.tag }} - {{- if .Values.deployment.image.digest }} - image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}@{{ .Values.deployment.image.digest }}" - {{- else }} - image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}" - {{- end }} - {{- else if .Values.deployment.image.digest }} - image: "{{ .Values.deployment.image.repository }}@{{ .Values.deployment.image.digest }}" - {{- else }} - image: "{{ .Values.deployment.image.repository }}" - {{- end }} + + {{- $image := required "Undefined image for application container" .Values.deployment.image.repository }} + {{- with .Values.deployment.image.tag }} {{- $image = print $image ":" . }} {{- end }} + {{- with .Values.deployment.image.digest }} {{- $image = print $image "@" . }} {{- end }} + image: {{ $image }} + imagePullPolicy: {{ .Values.deployment.image.pullPolicy }} {{- if .Values.deployment.command }} command: {{- include "application.tplvalues.render" (dict "value" .Values.deployment.command "context" $) | nindent 12 }} From 765352203e9c20b8d551b66d7067443e72ad340f Mon Sep 17 00:00:00 2001 From: d3adb5 Date: Tue, 11 Apr 2023 15:40:23 -0700 Subject: [PATCH 05/10] test: add unit tests to test image tag & digest behavior Add unit test to test assembly of the container image string when tag and digest are given or omitted. --- application/tests/cronjob_test.yaml | 79 ++++++++++++++++++++++++++ application/tests/deployment_test.yaml | 47 +++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 application/tests/cronjob_test.yaml diff --git a/application/tests/cronjob_test.yaml b/application/tests/cronjob_test.yaml new file mode 100644 index 00000000..2cbb6cef --- /dev/null +++ b/application/tests/cronjob_test.yaml @@ -0,0 +1,79 @@ +suite: CronJob + +templates: + - cronjob.yaml + +tests: + - it: does not fail rendering when job image tag and digest are absent + set: + cronJob: + enabled: true + jobs: + example: + image: + repository: example-image + tag: "" + digest: "" + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].image + value: example-image + + - it: fails rendering when job image repository is not given + set: + cronJob: + enabled: true + jobs: + example: + image: + repository: "" + tag: doesnt + digest: matter + asserts: + - failedTemplate: + errorMessage: "Undefined image repo for container 'example'" + + - it: uses tag when defined + set: + cronJob: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + digest: "" + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].image + value: example-image:example-tag + + - it: uses digest when defined + set: + cronJob: + enabled: true + jobs: + example: + image: + repository: example-image + tag: "" + digest: sha256:example-digest + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].image + value: example-image@sha256:example-digest + + - it: uses both tag and digest when given both + set: + cronJob: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + digest: sha256:example-digest + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].image + value: example-image:example-tag@sha256:example-digest diff --git a/application/tests/deployment_test.yaml b/application/tests/deployment_test.yaml index 5e4b46ad..1c368a35 100644 --- a/application/tests/deployment_test.yaml +++ b/application/tests/deployment_test.yaml @@ -23,3 +23,50 @@ tests: content: image: openshift/oauth-proxy:latest any: true + + - it: does not fail to render when image tag and digest are not given + set: + deployment.image.repository: example-image + deployment.image.tag: "" + deployment.image.digest: "" + asserts: + - equal: + path: spec.template.spec.containers[0].image + value: example-image + + - it: fails to render when image repository is not present + set: + deployment.image.repository: "" + asserts: + - failedTemplate: + errorMessage: "Undefined image for application container" + + - it: uses image tag when given + set: + deployment.image.repository: example-image + deployment.image.tag: example-tag + deployment.image.digest: "" + asserts: + - equal: + path: spec.template.spec.containers[0].image + value: example-image:example-tag + + - it: uses image digest when given + set: + deployment.image.repository: example-image + deployment.image.tag: "" + deployment.image.digest: sha256:example-digest + asserts: + - equal: + path: spec.template.spec.containers[0].image + value: example-image@sha256:example-digest + + - it: uses both image digest and tag when given both + set: + deployment.image.repository: example-image + deployment.image.tag: example-tag + deployment.image.digest: sha256:example-digest + asserts: + - equal: + path: spec.template.spec.containers[0].image + value: example-image:example-tag@sha256:example-digest From a6d0cbfd4dac7ddecb81f47c0ee5a78008cbd15f Mon Sep 17 00:00:00 2001 From: d3adb5 Date: Tue, 11 Apr 2023 16:17:49 -0700 Subject: [PATCH 06/10] chore: apply conditional to version label partial tpl Check whether the output of the 'application.version' partial template is empty instead of the image tag when deciding whether to add the Kubernetes recommended application version label. The partial template was adjusted to avoid crashes when applying the regexReplace function. --- application/templates/_helpers.tpl | 7 ++++--- application/tests/deployment_test.yaml | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/application/templates/_helpers.tpl b/application/templates/_helpers.tpl index 48f1ef03..48f8166d 100644 --- a/application/templates/_helpers.tpl +++ b/application/templates/_helpers.tpl @@ -11,7 +11,8 @@ Define the name of the chart/application. Define the name of the chart/application. */}} {{- define "application.version" -}} -{{ regexReplaceAll "[^a-zA-Z0-9_\\.\\-]" .Values.deployment.image.tag "-" | trunc 63 | trimSuffix "-" -}} + {{- $version := default "" .Values.deployment.image.tag -}} + {{- regexReplaceAll "[^a-zA-Z0-9_\\.\\-]" $version "-" | trunc 63 | trimSuffix "-" -}} {{- end -}} {{/* @@ -39,8 +40,8 @@ Common labels */}} {{- define "application.labels" -}} helm.sh/chart: {{ include "application.chart" . }} -{{- if .Values.deployment.image.tag }} -app.kubernetes.io/version: {{ include "application.version" . | quote }} +{{- with include "application.version" . }} +app.kubernetes.io/version: {{ quote . }} {{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/part-of: {{ include "application.name" . }} diff --git a/application/tests/deployment_test.yaml b/application/tests/deployment_test.yaml index 1c368a35..c98cae84 100644 --- a/application/tests/deployment_test.yaml +++ b/application/tests/deployment_test.yaml @@ -50,6 +50,9 @@ tests: - equal: path: spec.template.spec.containers[0].image value: example-image:example-tag + - equal: + path: metadata.labels["app.kubernetes.io/version"] + value: example-tag - it: uses image digest when given set: @@ -60,6 +63,8 @@ tests: - equal: path: spec.template.spec.containers[0].image value: example-image@sha256:example-digest + - isNull: + path: metadata.labels["app.kubernetes.io/version"] - it: uses both image digest and tag when given both set: From 95b58c9c84f04303625f747a571896bbefe916c0 Mon Sep 17 00:00:00 2001 From: d3adb5 Date: Sat, 15 Apr 2023 23:50:56 -0700 Subject: [PATCH 07/10] fix: run unit tests from the pr head (#251) * ci: run unit tests introduced in each pr Checkout the pull request head instead of the base branch in the job that runs unit tests so that newly introduced unit tests are executed as well. * ci: name the unit tests jobs Give the job that runs unit tests a pretty name. --- .github/workflows/pull_request.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 78f5592d..5fd37b43 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -92,9 +92,12 @@ jobs: SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }} unittest: + name: Unit Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + ref: ${{github.event.pull_request.head.sha}} - uses: d3adb5/helm-unittest-action@v2 with: charts: application From 273848180d8797827084c7299759796cec3a955b Mon Sep 17 00:00:00 2001 From: stakater-user Date: Sun, 16 Apr 2023 11:54:24 +0000 Subject: [PATCH 08/10] [skip-ci] Update artifacts --- application/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/Chart.yaml b/application/Chart.yaml index 3494c24a..6d7d34e0 100644 --- a/application/Chart.yaml +++ b/application/Chart.yaml @@ -6,7 +6,7 @@ type: application # Helm chart Version -version: 2.1.12 +version: 2.1.13 keywords: From 4a38a0f6ee61ba6398180866027fa1e3ce1d320c Mon Sep 17 00:00:00 2001 From: samcday Date: Sat, 10 Jun 2023 11:04:25 +0200 Subject: [PATCH 09/10] fix: README typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae2c97d4..333aaf39 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ To uninstall the chart: helm delete -## Paramaters +## Parameters | Name | Description | Value | | ---| ---------------------------------------------------------------------------------------------|---------------------------------------------| From c2f995627991fdd8b6e3ab944552d0710453e79a Mon Sep 17 00:00:00 2001 From: mustafaStakater <101177975+mustafaStakater@users.noreply.github.com> Date: Wed, 5 Jul 2023 14:58:24 +0500 Subject: [PATCH 10/10] [skip actions] chore: update chlog (#252) Co-authored-by: Hussnain Ahmad --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baa6a2f0..c42619b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,12 @@ All notable changes to this project will be documented here. -### v2.2.0 - +### v2.1.13 - Fix: make deployment.image.tag and job.image.tag optional [PR-234](https://github.com/stakater/application/pull/234) +### v2.1.12 +- Caused by Change Log update + ### v2.1.11 - Feature: Add topologySpreadConstraints [PR-239](https://github.com/stakater/application/pull/239)