instrumenta / kubeval

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

kubeval don't recognize extra field at root level #34

Closed surajnarwade closed 5 years ago

surajnarwade commented 7 years ago

I have a file sample file as,

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    batman: true
    io.kompose.service: redis-master
  name: redis-master
spec:
  replicas: 1
  template:
    metadata:
      labels:
        io.kompose.service: redis-master
    spec:
      containers:
      - image: gcr.io/google_containers/redis:e2e
        name: redis-master
        ports:
        - containerPort: 6379
      restartPolicy: Always

in which batman is extra key which kubeval recognize very well with strict mode,

$ kubval deployment.yaml --strict
The document redis-master-deployment.yaml contains an invalid Deployment
---> batman: Additional property batman is not allowed

But If I provide extra key superman at root level as below,

apiVersion: extensions/v1beta1
kind: Deployment
superman: true
metadata:
  labels:
    io.kompose.service: redis-master
  name: redis-master
spec:
  replicas: 1
  template:
    metadata:
      labels:
        io.kompose.service: redis-master
    spec:
      containers:
      - image: gcr.io/google_containers/redis:e2e
        name: redis-master
        ports:
        - containerPort: 6379
      restartPolicy: Always

Kubeval fails to validate

$ kubval deployment.yaml --strict
The document redis-master-deployment.yaml contains a valid Deployment
garethr commented 6 years ago

Ah, thanks. It appears I don't have the additionalAttributes property in the schema at the top level. I'll get this fixed.

Anuraag-Advani commented 5 years ago

Yes also add

"required": [
    "apiVersion", 
    "kind", 
    "metadata", 
    "data"
  ], 

to the top level

grzesuav commented 5 years ago

@garethr it should be raised here or in https://github.com/instrumenta/kubernetes-json-schema ?

garethr commented 5 years ago

Here is fine, I've jut not had time to address unfortunately.

garethr commented 5 years ago

I've just resolved this now for the master schemas. I'll regenerate the per-versions schemas over the next week or so with this fix.