Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating helm chart content

Tags:

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?

like image 995
Jan Hudec Avatar asked Feb 07 '18 13:02

Jan Hudec


2 Answers

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.

like image 155
GHETTO.CHiLD Avatar answered Sep 17 '22 16:09

GHETTO.CHiLD


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
like image 43
mkingston Avatar answered Sep 17 '22 16:09

mkingston