instrumenta / kubeval

Validate your Kubernetes configuration files, supports multiple Kubernetes versions
https://kubeval.com
Other
3.16k stars 229 forks source link

kubeval fails to validate if the file starts with '#' #78

Closed Jenil2910 closed 6 years ago

Jenil2910 commented 6 years ago

File: example.yaml

#to-be-omitted
---
apiVersion: v1
kind: Pod
metadata:
  name: pv-recycler
  namespace: default
spec:
#specifications
  restartPolicy: Never
  volumes:
  - name: vol
    hostPath:
      path: /any/path/it/will/be/replaced
  containers:
  - name: pv-recycler
    image: "k8s.gcr.io/busybox"
    command: ["/bin/sh", "-c", "test -e /scrub && rm -rf /scrub/..?* /scrub/.[!.]* /scrub/*  && test -z \"$(ls -A /scrub)\" || exit 1"]
    volumeMounts:
    - name: vol
      mountPath: /scrub

Log:

1 error occurred:

* Missing a kind key

EDIT: inner '#' causes no problem.

ghost commented 6 years ago

We also ran into this issue when using an optional helm template like the following:

{{- if .Values.ingress.enabled -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-chart
spec:
  rules:
    - host: my-host
      http:
        paths:
          - path: /
            backend:
              serviceName: my-service
              servicePort: https
{{- end }}

When .Values.ingress.enabled equals true we get:

---
# Source: my-chart/templates/ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
    - host: my-host
      http:
        paths:
          - path: /
            backend:
              serviceName: my-service
              servicePort: https

When it equals false:

---
# Source: my-chart/templates/ingress.yaml

Combining this with kubeval and setting ingress.enabled to false...

$ helm template my-chart --set ingress.enabled=false -x templates/ingress.yaml | kubeval

Actual output:

1 error occurred:

* Missing a kind key

Expected output with an exit code of 0:

The document stdin is empty

When .Values.ingress.enabled is true it works as expected:

$ helm template my-chart --set ingress.enabled=true -x templates/ingress.yaml | kubeval
The document stdin contains a valid Ingress
hoesler commented 6 years ago

Duplicate of https://github.com/garethr/kubeval/pull/61 ?