yannh / kubeconform

A FAST Kubernetes manifests validator, with support for Custom Resources!
Apache License 2.0
2.07k stars 116 forks source link

Exit code incorrect when path does not exists #228

Closed glenndehaan closed 11 months ago

glenndehaan commented 11 months ago

When running kubeconform it seems that when a path does not exists the exit code will still be 0 and not 1. An example:

/ # helm template /mnt/charts/i-do-not-exist | kubeconform -kubernetes-version 1.24.0 -verbose -summary
Error: path "/mnt/charts/i-do-not-exist" not found
Summary: 0 resource found parsing stdin - Valid: 0, Invalid: 0, Errors: 0, Skipped: 0
/ # echo $?
0

I run kubeconform inside GitLab's CI/CD, and when removing a chart I found that the pipeline would not fail because kubeconform exits with a 0.

yannh commented 11 months ago

Hi @glenndehaan , I think this is not related to kubeconform, what's failing here is your helm template command. Try the following if you re using bash: set -o pipefail

See: https://stackoverflow.com/questions/68465355/what-is-the-meaning-of-set-o-pipefail-in-bash-script . Hope this helps!

glenndehaan commented 11 months ago

Hi @yannh Yeah you are right. I forgot about the fact that the error comes from helm and not kubeconform. Sorry for the confusion. The fix listed above works indeed, also for others who might read this: This fix also works on Alpine Linux.