instrumenta / kubeval

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

Issue with commented out array values #14

Closed elblivion closed 7 years ago

elblivion commented 7 years ago

For a Kubernetes Dashboard spec, also downloaded, the k8s API happily accepts this:

    spec:
      containers:
        <...>
        args:
          # Uncomment the following line to manually specify Kubernetes API server Host
          # If not specified, Dashboard will attempt to auto discover the API server and connect
          # to it. Uncomment only if the default does not work.
          # - --apiserver-host=http://my-address:port

Kubeval, however, doesn't like it:

The document ../../contentful/cf-infra-stacks/kubeconfigs/staging/us-east-1/delivery-k8s-002/kubernetes-dashboard/dashboard.yaml is not a valid Deployment
--> spec.template.spec.containers.0.args: Invalid type. Expected: array, given: null
garethr commented 7 years ago

The schema says this has not be an array https://github.com/garethr/kubernetes-json-schema/blob/master/master-standalone/deployment.json#L2720-L2726.

If Kubernetes accepts this it should instead be described as:

"type": [ "array", "null" ]

I'll post something to SIG API Machinery and see if this is correct. If so I'll file an upstream bug and also in the meantime splice this into the generated schemas.

garethr commented 7 years ago

So, the use of protocol buffers in Kubernetes means that it can't distinguish between null and empty arrays. And OpenAPI 2.0 doesn't support multiple types as shown in the comment above. Tracking this for upstream in the linked issue, which also has more context.

I've just updated the upstream schemas with this fix: https://github.com/garethr/kubernetes-json-schema/commit/12719afdc584f6a5f8a28432d4c56c8691b7f841

I've also added tests to kubeval to demonstrate it working as intended: https://github.com/garethr/kubeval/commit/b635ef571a4fb8d314f534a54dea39af69259f65