Skip to content

Commit 39042ef

Browse files
authored
feat: add DaemonSet support to the helm chart (#62)
Adds the `kind` value which defaults to `Deployment` but can be set to `DaemonSet` if desired. Replica and HPA configuration is ignored if `kind` is `DaemonSet`. Furthermore this change updates the `apiVersion` for the `HorizontalPodAutoscaler` to `autoscaling/v2` since `autoscaling/v2beta1` is deprecated and removed in Kubernetes 1.25. This required some minor changes to the configuration schema.
1 parent 0002ade commit 39042ef

File tree

6 files changed

+115
-83
lines changed

6 files changed

+115
-83
lines changed

charts/pod-image-swap-webhook/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: pod-image-swap-webhook
33
description: A webhook that replaces Pod images based on configuration values.
44
type: application
5-
version: 0.0.3
5+
version: 0.1.0
66
appVersion: "v0.0.3"

charts/pod-image-swap-webhook/templates/_helpers.tpl

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,86 @@ Create the name of the service account to use
6060
{{- default "default" .Values.serviceAccount.name }}
6161
{{- end }}
6262
{{- end }}
63+
64+
{{/*
65+
The pod template used by the Deployment and DaemonSet resources
66+
*/}}
67+
{{- define "pod-image-swap-webhook.podTemplate" -}}
68+
metadata:
69+
{{- with .Values.podAnnotations }}
70+
annotations:
71+
{{- toYaml . | nindent 4 }}
72+
{{- end }}
73+
labels:
74+
# Revision forces recreation of pods on upgrade.
75+
# Required to refresh the server certificate and key.
76+
revision: {{ .Release.Revision | quote }}
77+
{{- include "pod-image-swap-webhook.selectorLabels" . | nindent 4 }}
78+
{{- with .Values.podLabels }}
79+
{{- toYaml . | nindent 4 }}
80+
{{- end }}
81+
spec:
82+
{{- with .Values.imagePullSecrets }}
83+
imagePullSecrets:
84+
{{- toYaml . | nindent 4 }}
85+
{{- end }}
86+
serviceAccountName: {{ include "pod-image-swap-webhook.serviceAccountName" . }}
87+
securityContext:
88+
{{- toYaml .Values.podSecurityContext | nindent 4 }}
89+
containers:
90+
- name: {{ .Chart.Name }}
91+
securityContext:
92+
{{- toYaml .Values.securityContext | nindent 8 }}
93+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
94+
imagePullPolicy: {{ .Values.image.pullPolicy }}
95+
env:
96+
- name: PISW_CONFIG_PATH
97+
value: /config/config.yaml
98+
- name: PISW_CERT_DIR
99+
value: /certs
100+
ports:
101+
- name: metrics
102+
containerPort: 8080
103+
protocol: TCP
104+
- name: healthz
105+
containerPort: 8081
106+
protocol: TCP
107+
- name: webhook
108+
containerPort: 9443
109+
protocol: TCP
110+
livenessProbe:
111+
httpGet:
112+
path: /healthz
113+
port: healthz
114+
readinessProbe:
115+
httpGet:
116+
path: /readyz
117+
port: healthz
118+
resources:
119+
{{- toYaml .Values.resources | nindent 8 }}
120+
volumeMounts:
121+
- name: config
122+
mountPath: /config/config.yaml
123+
subPath: config.yaml
124+
- name: certs
125+
mountPath: /certs
126+
volumes:
127+
- configMap:
128+
name: {{ include "pod-image-swap-webhook.fullname" . }}
129+
name: config
130+
- secret:
131+
secretName: {{ include "pod-image-swap-webhook.fullname" . }}
132+
name: certs
133+
{{- with .Values.nodeSelector }}
134+
nodeSelector:
135+
{{- toYaml . | nindent 4 }}
136+
{{- end }}
137+
{{- with .Values.affinity }}
138+
affinity:
139+
{{- toYaml . | nindent 4 }}
140+
{{- end }}
141+
{{- with .Values.tolerations }}
142+
tolerations:
143+
{{- toYaml . | nindent 4 }}
144+
{{- end }}
145+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- if eq .Values.kind "DaemonSet" -}}
2+
apiVersion: apps/v1
3+
kind: DaemonSet
4+
metadata:
5+
name: {{ include "pod-image-swap-webhook.fullname" . }}
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
{{- include "pod-image-swap-webhook.labels" . | nindent 4 }}
9+
spec:
10+
selector:
11+
matchLabels:
12+
{{- include "pod-image-swap-webhook.selectorLabels" . | nindent 6 }}
13+
template:
14+
{{- include "pod-image-swap-webhook.podTemplate" . | nindent 4 }}
15+
{{- end }}
Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if eq .Values.kind "Deployment" -}}
12
apiVersion: apps/v1
23
kind: Deployment
34
metadata:
@@ -13,80 +14,5 @@ spec:
1314
matchLabels:
1415
{{- include "pod-image-swap-webhook.selectorLabels" . | nindent 6 }}
1516
template:
16-
metadata:
17-
{{- with .Values.podAnnotations }}
18-
annotations:
19-
{{- toYaml . | nindent 8 }}
20-
{{- end }}
21-
labels:
22-
# Revision forces recreation of pods on upgrade.
23-
# Required to refresh the server certificate and key.
24-
revision: {{ .Release.Revision | quote }}
25-
{{- include "pod-image-swap-webhook.selectorLabels" . | nindent 8 }}
26-
{{- with .Values.podLabels }}
27-
{{- toYaml . | nindent 8 }}
28-
{{- end }}
29-
spec:
30-
{{- with .Values.imagePullSecrets }}
31-
imagePullSecrets:
32-
{{- toYaml . | nindent 8 }}
33-
{{- end }}
34-
serviceAccountName: {{ include "pod-image-swap-webhook.serviceAccountName" . }}
35-
securityContext:
36-
{{- toYaml .Values.podSecurityContext | nindent 8 }}
37-
containers:
38-
- name: {{ .Chart.Name }}
39-
securityContext:
40-
{{- toYaml .Values.securityContext | nindent 12 }}
41-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
42-
imagePullPolicy: {{ .Values.image.pullPolicy }}
43-
env:
44-
- name: PISW_CONFIG_PATH
45-
value: /config/config.yaml
46-
- name: PISW_CERT_DIR
47-
value: /certs
48-
ports:
49-
- name: metrics
50-
containerPort: 8080
51-
protocol: TCP
52-
- name: healthz
53-
containerPort: 8081
54-
protocol: TCP
55-
- name: webhook
56-
containerPort: 9443
57-
protocol: TCP
58-
livenessProbe:
59-
httpGet:
60-
path: /healthz
61-
port: healthz
62-
readinessProbe:
63-
httpGet:
64-
path: /readyz
65-
port: healthz
66-
resources:
67-
{{- toYaml .Values.resources | nindent 12 }}
68-
volumeMounts:
69-
- name: config
70-
mountPath: /config/config.yaml
71-
subPath: config.yaml
72-
- name: certs
73-
mountPath: /certs
74-
volumes:
75-
- configMap:
76-
name: {{ include "pod-image-swap-webhook.fullname" . }}
77-
name: config
78-
- secret:
79-
secretName: {{ include "pod-image-swap-webhook.fullname" . }}
80-
name: certs
81-
{{- with .Values.nodeSelector }}
82-
nodeSelector:
83-
{{- toYaml . | nindent 8 }}
84-
{{- end }}
85-
{{- with .Values.affinity }}
86-
affinity:
87-
{{- toYaml . | nindent 8 }}
88-
{{- end }}
89-
{{- with .Values.tolerations }}
90-
tolerations:
91-
{{- toYaml . | nindent 8 }}
92-
{{- end }}
17+
{{- include "pod-image-swap-webhook.podTemplate" . | nindent 4 }}
18+
{{- end }}

charts/pod-image-swap-webhook/templates/hpa.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{{- if .Values.hpa.create }}
2-
apiVersion: autoscaling/v2beta1
1+
{{- if and .Values.hpa.create (eq .Values.kind "Deployment") }}
2+
apiVersion: autoscaling/v2
33
kind: HorizontalPodAutoscaler
44
metadata:
55
name: {{ include "pod-image-swap-webhook.fullname" . }}
@@ -18,12 +18,16 @@ spec:
1818
- type: Resource
1919
resource:
2020
name: cpu
21-
targetAverageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
21+
target:
22+
type: Utilization
23+
averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
2224
{{- end }}
2325
{{- if .Values.hpa.targetMemoryUtilizationPercentage }}
2426
- type: Resource
2527
resource:
2628
name: memory
27-
targetAverageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
29+
target:
30+
type: Utilization
31+
averageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
2832
{{- end }}
2933
{{- end }}

charts/pod-image-swap-webhook/values.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Default values for pod-image-swap-webhook.
22

3-
# Ignored if `hpa.create` is set to `true`.
3+
# Valid values are `Deployment` and `DaemonSet`.
4+
kind: Deployment
5+
6+
# Ignored if `hpa.create` is set to `true` or if `kind` is `DaemonSet`.
47
replicaCount: 2
58

69
image:
@@ -45,6 +48,7 @@ resources: {}
4548
# memory: 20Mi
4649

4750
hpa:
51+
# Ignored if `kind` is `DaemonSet`.
4852
create: true
4953
minReplicas: 2
5054
maxReplicas: 6

0 commit comments

Comments
 (0)