Skip to content

Commit f7628e1

Browse files
committed
docs: add jsonschema for values.yaml
Adding a jsonschema allows user to fail early as the user configuration in the is validated at installation time already. For that reason, there has been added additional validation that couldn't be performed using jsonschema in the helm helper file. Moreover, as we now have our dear conny in artifacthub we can enhance our artifacthub page by adding a jsonschema as artifacthub parses the file and shows its content in a nice format.
1 parent 7ba605f commit f7628e1

File tree

5 files changed

+1787
-1
lines changed

5 files changed

+1787
-1
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ Fixes #
1414
- [ ] PR follows [Contributing Guide](../docs/CONTRIBUTING.md)
1515
- [ ] Added tests (if necessary)
1616
- [ ] Extended README/Documentation (if necessary)
17+
- [ ] Adjusted `helm/values.schema.json` according to new changes if `helm/values.yaml` has been touched
1718
- [ ] Adjusted versions of image and Helm chart in `values.yaml` and `Chart.yaml` (if necessary)
1819

helm/templates/_helpers.tpl

+68
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,71 @@ Extract Kubernetes Minor Version.
184184
readOnly: true
185185
{{- end -}}
186186
{{- end -}}
187+
{{- define "checkForAlertTemplates" -}}
188+
{{ $files := .Files }}
189+
{{- if .Values.alerting }}
190+
{{- if .Values.alerting.admit_request }}
191+
{{- if .Values.alerting.admit_request.templates }}
192+
{{- range .Values.alerting.admit_request.templates }}
193+
{{- $filename := .template -}}
194+
{{- $file := printf "alert_payload_templates/%s.json" $filename | $files.Get }}
195+
{{- if $file }}
196+
{{- else }}
197+
{{- fail (printf "The value of the alert template must be chosen such that <template>.json matches one of the file names in the ./alert_payload_templates directory, but there is no %s.json file in that directory or the file is empty." $filename) }}
198+
{{- end }}
199+
{{- end }}
200+
{{- end }}
201+
{{- end }}
202+
{{- if .Values.alerting.reject_request }}
203+
{{- if .Values.alerting.reject_request.templates }}
204+
{{- range .Values.alerting.reject_request.templates }}
205+
{{- $filename := .template -}}
206+
{{- $file := printf "alert_payload_templates/%s.json" $filename | $files.Get }}
207+
{{- if $file }}
208+
{{- else }}
209+
{{- fail (printf "The value of the alert template must be chosen such that <template>.json matches one of the file names in the ./alert_payload_templates directory, but there is no %s.json file in that directory or the file is empty." $filename) }}
210+
{{- end }}
211+
{{- end }}
212+
{{- end }}
213+
{{- end }}
214+
{{- end }}
215+
{{- end -}}
216+
217+
{{- define "validatePolicy" -}}
218+
{{- $validatornames := list }}
219+
{{ range .Values.validators }}
220+
{{- $validator := deepCopy . }}
221+
{{ $validatornames = append $validatornames $validator.name }}
222+
{{- end }}
223+
{{- range .Values.policy }}
224+
{{- $policy := deepCopy . -}}
225+
{{- if $policy.validator }}
226+
{{- if has $policy.validator $validatornames }}
227+
{{- else }}
228+
{{- fail (printf "Validator %s has not been defined and cannot be used in a policy." $policy.validator)}}
229+
{{- end }}
230+
{{- $validtrustroots := list }}
231+
{{ range $.Values.validators }}
232+
{{- $validator := deepCopy .}}
233+
{{- if eq $validator.name $policy.validator}}
234+
{{range $validator.trust_roots }}
235+
{{ $trustroot := deepCopy .}}
236+
{{- $validtrustroots = append $validtrustroots $trustroot.name }}
237+
{{- end }}
238+
{{- end }}
239+
{{- end }}
240+
{{- if $policy.with }}
241+
{{- if has $policy.with.trust_root $validtrustroots }}
242+
{{- else if eq $policy.with.trust_root "default" }}
243+
{{- else }}
244+
{{- fail (printf "Validator %s has no %s trust root defined." $policy.validator $policy.with.trust_root)}}
245+
{{- end }}
246+
{{- end}}
247+
{{- else }}
248+
{{- if has "default" $validatornames }}
249+
{{- else }}
250+
{{- fail (printf "Policy for images matching '%s' has no explicit validator defined such that the validator named 'default' is going to be used, but there is no validator named 'default' defined." $policy.pattern)}}
251+
{{- end }}
252+
{{- end }}
253+
{{- end }}
254+
{{- end }}

helm/templates/alertconfig.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{ include "checkForAlertTemplates" . }}
2+
13
apiVersion: v1
24
kind: ConfigMap
35
metadata:
@@ -28,4 +30,4 @@ stringData:
2830
{{- if .Values.alerting}}
2931
alertconfig.json: |
3032
{{ mustToJson .Values.alerting | nindent 4 }}
31-
{{- end }}
33+
{{- end }}

helm/templates/config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{ include "validatePolicy" . }}
2+
13
apiVersion: v1
24
kind: ConfigMap
35
metadata:

0 commit comments

Comments
 (0)