kubernetes-sigs / kubectl-validate

Apache License 2.0
161 stars 40 forks source link

Can't validate multiple Objects in a Single Manifest #123

Open philippe-granet opened 7 months ago

philippe-granet commented 7 months ago

What happened?

I can't validate multiple Objects in a Single Manifest

What did you expect to happen?

It should fail if one of the objects in a manifest file is invalid

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

Using a manifest.yaml file with multiple Objects:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: validkind

---
apiVersion: v1
kind: configmap
metadata:
  name: invalidkind

and running kubectl-validate manifest.yaml, it return:

manifest.yaml...OK

but it should fail with this error message:

manifest.yaml...ERROR
failed to retrieve validator: kind configmap not found in v1 groupversion
Error: validation failed

Anything else we need to know?

No response

Kubernetes version

Using kubectl-validate 0.0.3
philippe-granet commented 7 months ago

I think you should replace this: https://github.com/kubernetes-sigs/kubectl-validate/blob/69421c1fde098c82b51f3f46a32a5a948e1fef8e/pkg/utils/yaml.go#L14-L26 by something like this:

func SplitYamlDocuments(fileBytes Document) ([]Document, error) {
    var documents [][]byte
    decoder := utilyaml.NewDocumentDecoder(ioutil.NopCloser(bytes.NewReader(fileBytes)))
    for {
        document, err := decoder.Read([]byte{})
        ...
}
k8s-triage-robot commented 4 months ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

philippe-granet commented 4 months ago

/remove-lifecycle stale

k8s-triage-robot commented 1 month ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

philippe-granet commented 1 month ago

/remove-lifecycle stale