-
Notifications
You must be signed in to change notification settings - Fork 695
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
Make the kubeseal CLI have a skinny main #939
Conversation
Tip: The diff might be more confusing that actually looking at the resulted main.go and main_test.go now to have a sense of what has remained there. The "pkg/kubeseal" code is mostly copy& paste from main except for those bits that could not be moved. See main final state as a whole here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I found a weird bug on the refactor and it ended up being because In order to detect other instances of $ cat /tmp/imports-new-main.txt /tmp/imports-new-kubeseal.txt | sort -u | grep -v '^$' > /tmp/new-code-imports
$ sort -u < /tmp/imports-old-main.txt |grep -v '^$' > /tmp/expected-code-imports
$ diff /tmp/expected-code-imports /tmp/new-code-imports
13a14
> "github.com/bitnami-labs/sealed-secrets/pkg/kubeseal"
28c29
< "k8s.io/klog/v2"
---
> "k8s.io/klog" This happened because Note the Test code showed no differences, so we are fine there: $ cat /tmp/imports-new-main_test.txt /tmp/imports-new-kubeseal_test.txt | sort -u | grep -v '^$' > /tmp/new-test-imports
$ sort -u < /tmp/imports-old-main_test.txt |grep -v '^$' > /tmp/expected-test-imports
$ diff /tmp/expected-test-imports /tmp/new-test-imports
$ Fix for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description of the change
The CLI had way too much code within the main package.
This change moves most of the kubeseal CLI code to a package "pkg/kubeseal", leaving a simple "main" which is only concerned with CLI flags and other command line perks.
Note that the changes are minimal, and only functions affected by the split of code between main and the package are really affected. The rest is code copied to another package.
Other changes included:
Benefits
Code in the new pkg is accesible from other packages and can be further refactored and improved.
Possible drawbacks
This is still a mostly mechanical code move, it does not yet address making the
kubeseal
code look and feel like a proper library to be consumed by code outside of a CLI context. This was left out of scope intentionally to make progress on smaller incremental steps.Additional information
Once this code is merged, the intent going forward is to start refactoring things out of the big
Run
function in small steps. The expectation of the final result is that a smaller (and skinny) version of such "run" might go back to themain
code but it will only decide what operations or behaviors ofkubeseal
will be invoked by each CLI execution. Many of those behaviors or operations will become new functions withinkubeseal
. Hopefully we can get rid of using theFlags
struct withinkubeseal
.