Skip to content

Commit

Permalink
Merge branch 'master' into revert-previous-change-remove-service-port…
Browse files Browse the repository at this point in the history
…-override
  • Loading branch information
aslafy-z committed Jul 5, 2023
2 parents 4abd386 + c2f9956 commit 58f68dc
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

All notable changes to this project will be documented here.

### v2.1.13
### v2.1.14
- Fix: Reverts [PR-243](https://github.com/stakater/application/pull/243), This can already be configured via `paths` [PR-247](https://github.com/stakater/application/pull/247)

### 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
- Update: Changelog updates. This release shouldnt have been made as the head commit had [`[skip ci]`](https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs). [PR-248](https://github.com/stakater/application/pull/248)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To uninstall the chart:

helm delete <name-of-the-chart>

## Paramaters
## Parameters

| Name | Description | Value |
| ---| ---------------------------------------------------------------------------------------------|---------------------------------------------|
Expand Down Expand Up @@ -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` |

Expand Down
2 changes: 1 addition & 1 deletion application/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type: application

# Helm chart Version

version: 2.1.12
version: 2.1.13


keywords:
Expand Down
9 changes: 6 additions & 3 deletions application/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

{{/*
Expand Down Expand Up @@ -39,7 +40,9 @@ Common labels
*/}}
{{- define "application.labels" -}}
helm.sh/chart: {{ include "application.chart" . }}
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" . }}
{{- end }}
Expand All @@ -56,4 +59,4 @@ Allow the release namespace to be overridden
*/}}
{{- define "application.namespace" -}}
{{- default .Release.Namespace .Values.namespaceOverride -}}
{{- end -}}
{{- end -}}
11 changes: 6 additions & 5 deletions application/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ spec:
{{- end }}
containers:
- name: {{ $name }}
{{- if $job.image.digest }}
image: "{{ $job.image.repository }}@{{ $job.image.digest }}"
{{- else if $job.image.tag }}
image: "{{ $job.image.repository }}:{{ $job.image.tag }}"
{{- 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 }}
Expand Down
13 changes: 7 additions & 6 deletions application/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ spec:
name: proxy-tls
{{- end }}
- name: {{ template "application.name" . }}
{{- 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 }}"
{{- 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 }}
Expand Down Expand Up @@ -295,4 +296,4 @@ spec:
{{- else }}
serviceAccountName: {{ template "application.name" . }}
{{- end }}
{{- end }}
{{- end }}
79 changes: 79 additions & 0 deletions application/tests/cronjob_test.yaml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions application/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,55 @@ 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
- equal:
path: metadata.labels["app.kubernetes.io/version"]
value: 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
- isNull:
path: metadata.labels["app.kubernetes.io/version"]

- 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
2 changes: 1 addition & 1 deletion application/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ deployment:
# Image of the app container
image:
repository: repository/image-name
tag: v1.0.0
tag: ''
digest: '' # if set to a non empty value, digest takes precedence on the tag
pullPolicy: IfNotPresent
dnsConfig:
Expand Down

0 comments on commit 58f68dc

Please sign in to comment.