0

I have the following line on a GitHub Action:

find kubernetes-manifests -regextype egrep -regex '.*ya?ml$' -exec kubeconform "{}" \;

Unfortunately, kubeconform doesn't return 1 or anything else on errors; it is always 0 and some message.

Is it possible to catch the output, check if it is empty, and if it is empty, exit 0; otherwise, echo the output and exit 1?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Rodrigo
  • 135
  • 4
  • 45
  • 107
  • 1
    The usage examples in the documentation (https://github.com/yannh/kubeconform#Usage-examples) show the `kubeconform` binary exiting with 1 when validating an invalid manifest and exiting with 0 when validating a valid manifest. – j_b Jan 12 '23 at 20:23
  • Maybe OP's problem is that `find` does not forward the exit status of `-exec ... {} \;`. Try `-exec ... {} +` or `-quit`. – Socowi Jan 12 '23 at 20:29
  • @j_b, then why my GitHub action is passing when I have an invalid YAML? Is it because I'm using it on a find/exec? – Rodrigo Jan 12 '23 at 20:29
  • 2
    Switch to `xargs` or this might help: [How to get the exit code of commands started by find?](https://unix.stackexchange.com/q/392970/74329) – Cyrus Jan 12 '23 at 20:29
  • 3
    Instead of `find` or `xargs` bash built-ins should be sufficient: `shopt -s nullglob globstar; kubeconform **/*yaml **/*yml`. – Socowi Jan 12 '23 at 20:31
  • @Socowi shopt worked like a charm – Rodrigo Jan 12 '23 at 20:36

1 Answers1

1

Switch from \; to + to preserve exit code of kubeconform.

Cyrus
  • 84,225
  • 14
  • 89
  • 153