Skip to content

Commit

Permalink
feat: adding a deployment template to generate image name/tag with ab…
Browse files Browse the repository at this point in the history
…ility to override the values
  • Loading branch information
nexus49 committed Dec 13, 2024
1 parent e0496b7 commit 0879b4f
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 5 deletions.
2 changes: 1 addition & 1 deletion charts/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ description: A Helm chart for Kubernetes

type: library

version: 0.1.9
version: 0.2.0
20 changes: 20 additions & 0 deletions charts/common/templates/_deploymentHelpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,23 @@ securityContext:
runAsGroup: {{ include "common.getKeyValue" (dict "Values" .Values "key" "securityContext.runAsGroup") }}
fsGroup: {{ include "common.getKeyValue" (dict "Values" .Values "key" "securityContext.fsGroup") }}
{{- end }}

{{- define "common.image.tag" -}}
{{- if (.Values.image).tag }}
{{- .Values.image.tag }}
{{- else }}
{{- .Chart.AppVersion }}
{{- end }}
{{- end }}

{{- define "common.image.name" -}}
{{- if (.Values.image).name }}
{{- .Values.image.name }}
{{- else }}
{{- .Chart.Name }}
{{- end }}
{{- end }}

{{- define "common.image" -}}
{{ include "common.image.name" . }}:{{ include "common.image.tag" . }}
{{- end }}
6 changes: 3 additions & 3 deletions charts/common/test-chart/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
- name: common
repository: file://..
version: 0.1.8
digest: sha256:eee7e1ccb5821b28c6d01a54bdc5ff4a12887b1306b137d6a8b4610f71ed619a
generated: "2024-12-09T16:40:26.404366+01:00"
version: 0.2.0
digest: sha256:7954fcb7393cd799f0e93e9e6a4cf9ddfdd234136a449dbb0c656945fd090528
generated: "2024-12-13T08:25:57.253349+01:00"
2 changes: 1 addition & 1 deletion charts/common/test-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ appVersion: "1.16.0"

dependencies:
- name: common
version: 0.1.8
version: 0.2.0
repository: file://..
Binary file removed charts/common/test-chart/charts/common-0.1.8.tgz
Binary file not shown.
Binary file added charts/common/test-chart/charts/common-0.2.0.tgz
Binary file not shown.
26 changes: 26 additions & 0 deletions charts/common/test-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "common.entity.name" . }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
revisionHistoryLimit: {{ include "common.getKeyValue" (dict "Values" .Values "key" "deployment.revisionHistoryLimit") }}
selector:
matchLabels:
service: {{ include "common.entity.name" . }}
template:
metadata:
spec:
serviceAccountName: {{ include "common.entity.name" . }}
containers:
image: {{ include "common.image" . }}
imagePullPolicy: {{ include "common.imagePullPolicy" . }}
name: manager
{{ include "common.container.securityContext" . | nindent 10 }}
ports:
{{ include "common.PortsMetricsHealth" . | nindent 10 }}
{{ include "common.operatorHealthAndReadyness" . | nindent 10 }}
{{ include "common.resources" . | nindent 10 }}
terminationGracePeriodSeconds: {{ include "common.terminationGracePeriodSeconds" .}}
177 changes: 177 additions & 0 deletions charts/common/test-chart/tests/__snapshot__/deployment_test.yaml.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
test name override:
1: |
apiVersion: apps/v1
kind: Deployment
metadata:
name: RELEASE-NAME-test-chart
spec:
revisionHistoryLimit: 3
selector:
matchLabels:
service: RELEASE-NAME-test-chart
template:
metadata: null
spec:
containers:
automountServiceAccountToken: true
image: my-image:0.1.0
imagePullPolicy: Always
livenessProbe:
failureThreshold: 1
httpGet:
path: /healthz
port: 8081
periodSeconds: 10
name: manager
ports:
- containerPort: 8080
name: metrics
protocol: TCP
- containerPort: 8081
name: health-port
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 100m
memory: 512Mi
requests:
cpu: 40m
memory: 50Mi
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: RELEASE-NAME
startupProbe:
failureThreshold: 30
httpGet:
path: /readyz
port: 8081
periodSeconds: 10
serviceAccountName: RELEASE-NAME-test-chart
terminationGracePeriodSeconds: 10
test tag default:
1: |
apiVersion: apps/v1
kind: Deployment
metadata:
name: RELEASE-NAME-test-chart
spec:
revisionHistoryLimit: 3
selector:
matchLabels:
service: RELEASE-NAME-test-chart
template:
metadata: null
spec:
containers:
automountServiceAccountToken: true
image: test-chart:0.1.0
imagePullPolicy: Always
livenessProbe:
failureThreshold: 1
httpGet:
path: /healthz
port: 8081
periodSeconds: 10
name: manager
ports:
- containerPort: 8080
name: metrics
protocol: TCP
- containerPort: 8081
name: health-port
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 100m
memory: 512Mi
requests:
cpu: 40m
memory: 50Mi
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: RELEASE-NAME
startupProbe:
failureThreshold: 30
httpGet:
path: /readyz
port: 8081
periodSeconds: 10
serviceAccountName: RELEASE-NAME-test-chart
terminationGracePeriodSeconds: 10
test tag override:
1: |
apiVersion: apps/v1
kind: Deployment
metadata:
name: RELEASE-NAME-test-chart
spec:
revisionHistoryLimit: 3
selector:
matchLabels:
service: RELEASE-NAME-test-chart
template:
metadata: null
spec:
containers:
automountServiceAccountToken: true
image: test-chart:1.0.0
imagePullPolicy: Always
livenessProbe:
failureThreshold: 1
httpGet:
path: /healthz
port: 8081
periodSeconds: 10
name: manager
ports:
- containerPort: 8080
name: metrics
protocol: TCP
- containerPort: 8081
name: health-port
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 100m
memory: 512Mi
requests:
cpu: 40m
memory: 50Mi
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
serviceAccountName: RELEASE-NAME
startupProbe:
failureThreshold: 30
httpGet:
path: /readyz
port: 8081
periodSeconds: 10
serviceAccountName: RELEASE-NAME-test-chart
terminationGracePeriodSeconds: 10
24 changes: 24 additions & 0 deletions charts/common/test-chart/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
suite: deployment
templates:
- deployment.yaml
values:
- ../values.yaml
chart:
namespace: default
appVersion: 0.1.0
tests:
- it: test tag default
asserts:
- matchSnapshot: {}
- it: test tag override
set:
image:
tag: 1.0.0
asserts:
- matchSnapshot: {}
- it: test name override
set:
image:
name: my-image
asserts:
- matchSnapshot: {}

0 comments on commit 0879b4f

Please sign in to comment.