kubeval
kubeval copied to clipboard
Validating multi document files
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?
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
@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!
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)
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
Update: Seems to work with latest version of kubeval (v0.16.1). Official Docker image is outdated #312
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.