Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating multi document files #303

Open
szantopeter opened this issue Jun 14, 2021 · 6 comments
Open

Validating multi document files #303

szantopeter opened this issue Jun 14, 2021 · 6 comments

Comments

@szantopeter
Copy link

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?

@dshuvar
Copy link

dshuvar commented Jun 17, 2021

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

@yannh
Copy link

yannh commented Jul 3, 2021

@szantopeter I also believe this should be supported? It is tested here

kubeval/acceptance.bats

Lines 57 to 65 in 062c99a

@test "Pass when parsing a multi-document config file" {
run bin/kubeval fixtures/multi_valid.yaml
[ "$status" -eq 0 ]
}
@test "Fail when parsing a multi-document config file with one invalid resource" {
run bin/kubeval fixtures/multi_invalid.yaml
[ "$status" -eq 1 ]
}

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

@pgoudreau
Copy link

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)

@Sam13
Copy link

Sam13 commented Jan 5, 2022

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
Copy link

Sam13 commented Jan 7, 2022

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

@mart-vi
Copy link

mart-vi commented Mar 30, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants