kubeval icon indicating copy to clipboard operation
kubeval copied to clipboard

Validating multi document files

Open szantopeter opened this issue 3 years ago • 6 comments

I want to validate the output of kustomize build. It puts multiple documents into a single yaml separated by --- . I noticed that only the first document is validated. Would it be possible to validate every yaml document within a file?

szantopeter avatar Jun 14 '21 13:06 szantopeter

looks like this possible. for example my deployment.yaml contains is two abstractions separated by one ---.

when I do: kubeval apps/bases/projectx/newservice/deployment.yaml I see the output:

PASS - apps/bases/projectx/newservice/deployment.yaml contains a valid Deployment (projectx.new-service)
PASS - apps/bases/projectx/newservice/deployment.yaml contains a valid PersistentVolumeClaim (new-service-claim0)

but my favorite command option with kubeval is kubeval -d . -i kustomization.yaml,gotk-components.yaml,gotk-sync.yaml,gotk-sync.yaml,another.yaml

dshuvar avatar Jun 17 '21 00:06 dshuvar

@szantopeter I also believe this should be supported? It is tested here https://github.com/instrumenta/kubeval/blob/062c99a2ad6554ca5798c07599fa6c06db975325/acceptance.bats#L57-L65

Do you want to give an example that doesnt work, and expand how you are using kubeval? Thanks!

yannh avatar Jul 03 '21 12:07 yannh

I'm having the same issue using docker images docker run -it -v ${PWD}:/fixtures garethr/kubeval -d fixtures using the fixtures/multi_valid.yaml I just get the following as output.

PASS - fixtures/multi-valid.yaml contains a valid Service (redis-master)

pgoudreau avatar Jul 22 '21 15:07 pgoudreau

It seems to work when piping via stdin but not when passing the filename:

docker run -it --rm --entrypoint sh -v ${PWD}:/fixtures garethr/kubeval -c "cat /fixtures/multi_invalid.yaml | kubeval"

gives

WARN - stdin contains an invalid Service (redis-master) - spec.ports.0.port: Invalid type. Expected: integer, given: string
PASS - stdin contains a valid ReplicationController (redis-master)
PASS - stdin contains a valid Service (redis-slave)
PASS - stdin contains a valid ReplicationController (redis-slave)
PASS - stdin contains a valid Service (frontend)
PASS - stdin contains a valid ReplicationController (frontend)

where

docker run -it --rm --entrypoint sh -v ${PWD}:/fixtures garethr/kubeval -c "kubeval fixtures/multi_invalid.yaml"

or

docker run -it --rm -v ${PWD}:/fixtures garethr/kubeval fixtures/multi_invalid.yaml

just gives

WARN - fixtures/multi_invalid.yaml contains an invalid Service (redis-master) - spec.ports.0.port: Invalid type. Expected: integer, given: string

Sam13 avatar Jan 05 '22 14:01 Sam13

Update: Seems to work with latest version of kubeval (v0.16.1). Official Docker image is outdated #312

Sam13 avatar Jan 07 '22 15:01 Sam13

I had issue when one part of yaml contained configMap that contained windows style end of line sequence (CRLF) instead of linux style ending. Then all other documents contained after this configMap were skipped. PS. I tested it with latest v0.16.1.

mart-vi avatar Mar 30 '22 12:03 mart-vi