kubernetes-sigs/kubectl-validate

Cannot validate Local CRDs

Opened this issue · 0 comments

What happened?

The README suggests that manifests with custom resources can be validated against a cluster in a given kubectl context. If working offline or without a cluster connection, the --local-crds flag can be used to supply local type definitions to validate against instead. The output of --help also suggests that the --version flag is required when running without a connection to a k8s cluster.

Running kubectl-validate with --local-crds and a reachable cluster that does not have the CRDs installed fails within 0.3 seconds with the following error:

failed to retrieve validator: failed to locate OpenAPI spec for GV: 

Running kubectl-validate with --local-crds and with the cluster in the given context unreachable fails with the same error, but after 30 seconds.

Running kubectl config unset current-context first and then kubectl-validate with --local-crds fails again with the same error, but also instantly.

What did you expect to happen?

I expect kubectl-validate to skip connecting to any cluster if the --local-crds flag is given.

How can we reproduce it (as minimally and precisely as possible)?

kubectl config unset current-context
kubectl validate myCustomResource.yaml --local-crds ./path/to/my/crds --version 1.31

Anything else we need to know?

This comment seems to give a hint that kubectl-validate is always trying to connect to a cluster, regardless of whether --local-crds is given or not:
https://github.com/kubernetes-sigs/kubectl-validate/blob/main/pkg/cmd/validate.go#L195-L196

There is a related feature request to support validation without depending on a running cluster, that was closed because of inactivity:
#131

Kubernetes version

$ kubectl version
Client Version: v1.32.0
Kustomize Version: v5.5.0
The connection to the server localhost:8080 was refused - did you specify the right host or port?