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

Merged

Conversation

blag
Copy link
Contributor

@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.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
miri64 Martine Lenders
Signed-off-by: blag <[email protected]>
@blag blag force-pushed the properly-error-on-missing-input-file branch from bbc4b2a to 8ceafd2 Compare November 25, 2024 08:42
@alvneiayu alvneiayu merged commit 46e1372 into bitnami-labs:main Dec 5, 2024
15 checks passed
@blag blag deleted the properly-error-on-missing-input-file branch December 5, 2024 22:40
@blag
Copy link
Contributor Author

blag commented Dec 5, 2024

Thanks! 😄

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Dec 6, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
miri64 Martine Lenders
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [bitnami-labs/sealed-secrets](https://github.com/bitnami-labs/sealed-secrets) | patch | `v0.27.2` -> `v0.27.3` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>bitnami-labs/sealed-secrets (bitnami-labs/sealed-secrets)</summary>

### [`v0.27.3`](https://github.com/bitnami-labs/sealed-secrets/blob/HEAD/RELEASE-NOTES.md#v0273)

[Compare Source](bitnami-labs/sealed-secrets@v0.27.2...v0.27.3)

-   Bump k8s.io/apimachinery from 0.31.2 to 0.31.3 ([#&#8203;1642](bitnami-labs/sealed-secrets#1642))
-   Bump k8s.io/code-generator from 0.31.2 to 0.31.3 ([#&#8203;1643](bitnami-labs/sealed-secrets#1643))
-   Bump github.com/onsi/gomega from 1.35.1 to 1.36.0 ([#&#8203;1645](bitnami-labs/sealed-secrets#1645))
-   re-introduce install instructions with to releases ([#&#8203;1649](bitnami-labs/sealed-secrets#1649))
-   Properly error out when input file doesn't exist ([#&#8203;1640](bitnami-labs/sealed-secrets#1640))
-   Bump github.com/onsi/ginkgo/v2 from 2.21.0 to 2.22.0 ([#&#8203;1641](bitnami-labs/sealed-secrets#1641))
-   Bump golang.org/x/crypto from 0.28.0 to 0.29.0 ([#&#8203;1635](bitnami-labs/sealed-secrets#1635))
-   Configure max retries ([#&#8203;1633](bitnami-labs/sealed-secrets#1633))
-   Label "app.kubernetes.io/instance" in the Prometheus metric ([#&#8203;1620](bitnami-labs/sealed-secrets#1620))
-   Bump github.com/onsi/gomega from 1.34.2 to 1.35.1 ([#&#8203;1624](bitnami-labs/sealed-secrets#1624))
-   Adding keyttl and keycutofftime options to helm chart ([#&#8203;1610](bitnami-labs/sealed-secrets#1610))
-   Bump github.com/onsi/ginkgo/v2 from 2.20.2 to 2.21.0 ([#&#8203;1623](bitnami-labs/sealed-secrets#1623))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
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.

None yet

2 participants