I am developing a chart and I had an error in it—incorrectly placed imagePullSecrets
. When I tried to install it via
helm install ./mychart
the misplaced element was simply ignored and I wondered what is wrong.
When I did
helm template ./mychart | kubectl apply --dry-run -f -
it instead printed:
error: error validating "STDIN": error validating data: ValidationError(Deployment.spec.template.spec.containers[0]): unknown field "imagePullSecrets" in io.k8s.api.core.v1.Container
which clearly shows what is wrong. I am not sure whether it matches what the tiller actually does with the expanded templates.
But if I just do a
helm install --dry-run --debug ./mychart
it just shows the expanded template and looks OK.
So how do I correctly verify all my templates match corresponding schemata with helm?
You can lint the chart by going helm lint ./mychart
which should print the following if an issue is found:
$ helm lint ./mychart
==> Linting ./mychart
[ERROR] Chart.yaml: version is required
[INFO] Chart.yaml: icon is recommended
Error: 1 chart(s) linted, 1 chart(s) failed
See helm lint.
Use kubeconform.
helm template ./mychart | kubeconform -strict
If you have CRDs you may need to use kubeconform -ignore-missing-schemas
. I would recommend supplying the schema version: kubeconform -kubernetes-version 1.18
.
A recommendation: specialise your charts and validate them. Examples follow.
Simple:
helm template --set some.key="val" | kubeconform -strict
Complex:
VALUES_FILE=$(cat << EOF
some:
key: "val"
another:
key:
another: "val"
EOF
)
# It is important to quote "$VALUES_FILE" to ensure line breaks and indentation are preserved
echo "$VALUES_FILE" | helm template -f - | kubeconform -strict
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With