kubernetes-sigs / kubectl-validate

Apache License 2.0
121 stars 31 forks source link

Ignore non CRD files in directories used in --local-crds #110

Closed monotek closed 2 months ago

monotek commented 2 months ago

What happened?

I ran into an issue recently, when the --local-crds directory contains non CRD files.

kubectl-validate --local-crds ./test/ ./test/
Error: no kind "PodDisruptionBudget" is registered for version "policy/v1" in scheme "pkg/runtime/scheme.go:100"

What did you expect to happen?

Non CRD file shout have been ignored and k8s manifest been validated

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

Just place your resource manifests and CRDs in the same directory.

For example place a crd and a pdb in the same directory "test":

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: kialis.kiali.io
spec:
  group: kiali.io
  names:
    kind: Kiali
    listKind: KialiList
    plural: kialis
    singular: kiali
  scope: Namespaced
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        type: object
        x-kubernetes-preserve-unknown-fields: true
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: postgres
  namespace: visual-regression-tracker
spec:
  minAvailable: 1
  selector:
    matchLabels:
      application: spilo
      cluster-name: vrt-postgres-db
      spilo-role: replica

Run kubectl-validate:

kubectl-validate --local-crds ./test/ ./test/
Error: no kind "PodDisruptionBudget" is registered for version "policy/v1" in scheme "pkg/runtime/scheme.go:100"

Anything else we need to know?

No response

Kubernetes version

kubectl-valdiate version: 0.0.3 ```console $ kubectl version WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version. Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.0", GitCommit:"b46a3f887ca979b1a5d14fd39cb1af43e7e5d12d", GitTreeState:"clean", BuildDate:"2022-12-08T19:58:30Z", GoVersion:"go1.19.4", Compiler:"gc", Platform:"linux/amd64"} Kustomize Version: v4.5.7 Server Version: version.Info{Major:"1", Minor:"28", GitVersion:"v1.28.5", GitCommit:"9cf543f4f17cbc5b74c24880e77590eeb1af683c", GitTreeState:"clean", BuildDate:"2024-01-31T09:07:34Z", GoVersion:"go1.20.12", Compiler:"gc", Platform:"linux/amd64"} WARNING: version difference between client (1.26) and server (1.28) exceeds the supported minor version skew of +/-1 ```
alexzielenski commented 2 months ago

Definitely a bug we want to fix.

In addition to this I think it also makes sense to default the local CRD source to the user provided yaml files. Especially now that we support multiple CRD file sources.

Schnides123 commented 2 months ago

I can take a look at this

alexzielenski commented 2 months ago

/assign should be fixed by #118

sorry @Schnides123 I ended up fixing this one myself