Skip to content

Commit 0a843f7

Browse files
Laffs2k5minsiyang
authored andcommitted
feat: helm chart add extensibility
This adds support from additional volumes, volume mounts and init containers. See snyk-monitor/README.md for details and documentation.
1 parent 8ef0db0 commit 0a843f7

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

snyk-monitor/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,54 @@ You can provide custom CA certificates to use for validating TLS connections by
277277

278278
If running Snyk on-prem, you can also use a custom CA certificate to validate the connection to kubernetes-upstream for sending scan results by providing the certificate under the following path in the ConfigMap: /srv/app/certs/ca.pem
279279

280+
## Helm chart extensibility ##
281+
282+
### Additional Kubernetes volumes and volume mounts ###
283+
284+
The helm chart supports mounting custom volumes in addition to the built-in ones through the use of `extraVolumes` and `extraVolumeMounts`.
285+
286+
**Note** that `extraVolumes` are available to all containers in the snyk-monitor deployment (including any init containers), whilst `extraVolumeMounts` applies only to the main snyk-monitor container.
287+
288+
#### Example ####
289+
290+
Let's say you need to mount in an additional kubernetes secret that is created outside of the snyk-monitor chart. You would define the following in your `values.yaml`:
291+
292+
```yaml
293+
extraVolumes:
294+
# this volume will be available to all containers in the deployment
295+
- name: "my-k8s-secret"
296+
secret:
297+
secretName: "name-of-my-k8s-secret-resource" # kubernetes secret created elsewhere
298+
299+
extraVolumeMounts:
300+
# this mounts the kubernetes secret into the main snyk-monitor container
301+
- mountPath: "/mnt/additional-secrets"
302+
name: "my-k8s-secret"
303+
readOnly: true
304+
```
305+
306+
### Additional init containers ###
307+
308+
The helm chart supports specifying additional init containers that will run before the main snyk-monitor container through the use of `extraInitContainers`. This field is templated ie. Helm will parse any helm template directives within the specification.
309+
310+
#### Example ####
311+
312+
Continuing on with the example above for additional volumes, let's say you need to have a secret copied into a specific path in the main snyk-monitor container before it is started. You would define the following in your `values.yaml`:
313+
314+
```yaml
315+
extraInitContainers:
316+
- name: install-my-secret
317+
# notice how the image specification is templated. This would result in running the same
318+
# image as the built-in 'volume-permissions' init container.
319+
image: "{{ .Values.initContainerImage.repository }}:{{ .Values.initContainerImage.tag }}"
320+
command: ['sh', '-c', 'cp -f /mnt/my-secrets/my-secret /srv/app/my-secret || :']
321+
volumeMounts:
322+
# this brings the kubernetes secret from the previous example into this init container
323+
- mountPath: "/mnt/my-secrets"
324+
name: "my-k8s-secret"
325+
readOnly: true
326+
```
327+
280328
## Terms and conditions ##
281329

282330
*The Snyk Container Kubernetes integration uses Red Hat UBI (Universal Base Image).*

snyk-monitor/templates/deployment.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ spec:
7474
capabilities:
7575
drop:
7676
- ALL
77+
{{- if .Values.extraInitContainers -}}
78+
{{ tpl (toYaml .Values.extraInitContainers) . | nindent 8 }}
79+
{{- end }}
7780
containers:
7881
- name: {{ include "snyk-monitor.name" . }}
7982
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
@@ -97,6 +100,9 @@ spec:
97100
- name: excluded-namespaces
98101
mountPath: "/etc/config"
99102
{{- end }}
103+
{{- if .Values.extraVolumeMounts }}
104+
{{- toYaml .Values.extraVolumeMounts | nindent 10 }}
105+
{{- end }}
100106
env:
101107
- name: NODE_EXTRA_CA_CERTS
102108
value: {{ .Values.extraCaCerts }}
@@ -224,6 +230,9 @@ spec:
224230
configMap:
225231
name: {{ .Release.Name }}-excluded-namespaces
226232
{{- end }}
233+
{{- if .Values.extraVolumes }}
234+
{{- toYaml .Values.extraVolumes | nindent 8 }}
235+
{{- end }}
227236
{{- with .Values.nodeSelector }}
228237
nodeSelector:
229238
{{- toYaml . | nindent 8 }}

snyk-monitor/values.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ excludedNamespaces:
128128
# fsGroup: <-- here
129129
securityContext:
130130
fsGroup:
131-
131+
132132
# Set node tolerations for snyk-monitor
133133
tolerations: []
134134

@@ -151,3 +151,20 @@ sysdig:
151151

152152
strategy:
153153
type: RollingUpdate
154+
155+
# Additional volumes for the deployment, available to all containers
156+
extraVolumes: []
157+
# - name: my-empty-dir
158+
# emptyDir: {}
159+
160+
# Additional volume mounts for the snyk-monitor container
161+
extraVolumeMounts: []
162+
# - name: extras
163+
# mountPath: /mnt/my-empty-dir
164+
# readOnly: true
165+
166+
# Additional init containers, templated
167+
extraInitContainers: []
168+
# - name: wait-for-condition
169+
# image: "{{ .Values.initContainerImage.repository }}:{{ .Values.initContainerImage.tag }}"
170+
# command: ['sh', '-c', 'sleep 10 || :']

0 commit comments

Comments
 (0)