instrumenta / kubeval

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

Fails when a missing required field in type Service #75

Closed jtslear closed 6 years ago

jtslear commented 6 years ago

Given the following example:

---
kind: Service
apiVersion: v1
metadata:
  name: example-app
spec:
  selector:
        app: example-app
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080

The spec requires that spec.ports[0].name be provided. Kubernetes makes this nice, but in the context of throwing kubeval inside of CI/CD, it's best if this is caught prior to trying to perform an apply.

Ref: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#serviceport-v1-core

Log info:

The document /Users/redacted/dir/path/example-svc.yml contains a valid Service
The Service "example-app" is invalid:
* spec.ports[0].name: Required value
garethr commented 6 years ago

Testing this out kubeval correctly reports this as a valid Service.

Name that names on ports are are "Optional if only one ServicePort is defined on this service."

Unfortunately this distinction isn't describable in JSON Schema in the OpenAPI specs, on which kubeval relies.