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

Properly error out when input file doesn't exist #1640

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

blag
Copy link

@blag blag commented Nov 25, 2024

Description of the change

This fixes a bug in the kubeseal CLI where it silently and errorneously does nothing and returns a 0 (eg: success) exit code when a specified --secret-file does not exist (or is unreadable).

$ kubeseal \
    --kubeconfig ${KUBECONFIG:-~/.kube/config} \
    --controller-namespace=sealed-secrets \
    --controller-name=sealed-secrets-controller \
    --secret-file doesntexist.yaml; echo $?
0

It looks like there was a simple oversight in #1030, and as noted in that PR:

As with all refactors, bugs could be introduced.

I just tweaked the exit logic to output an error message and exit with nonzero status, which I think is much more reasonable behavior as it is both less surprising and also follows what other POSIX-y CLIs do when they are pointed to files that don't exist.

Benefits

Instead of silently doing nothing and erroneously returning a success status/exit code, this will now clearly indicate that the problem occurred and programmatically indicate a non-successful result. I'm not super happy with the error message (I think it could be written better), but this is my first PR for a Go project, so I'm not sure what the culture of error messages is in the Go community (constructive guidance will be welcome and appreciated!).

Possible drawbacks

Anybody who has been relying on the previous -- non-standard -- behavior will be impacted by this change. But, also as noted in #1030:

The currently exposed kubeseal interface must be considered unstable, it will change going forward.

Applicable issues

  • fixes #

Additional information

This is my first ever foray into Golang, so I might need more hand-holding than your average contributor, especially around how to test this. TIA. 😄

Edit: Added example.

@blag blag force-pushed the properly-error-on-missing-input-file branch from bbc4b2a to 8ceafd2 Compare November 25, 2024 08:42
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

Successfully merging this pull request may close these issues.

1 participant