Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Disclaimer:
I was playing around with
kubefirst
andk3d
on GitHub and was checking out the code, since I'm currently traveling and looking for some OSS projects to contribute. The PR turned out to be way bigger than anticipated... I understand in case you guys don't want to invest the time in reviewing. I could also split up and open up multiple PRs containing the changes described next, in case some changes are of interest. I am also willing to expand these changes to the other supported cloud provider.I want to suggest some alternative approaches when building CLI apps with
cobra
, I choosek3d
as an example, since I am able to fully e2e test it locally.The changes can be summarized into:
prechecks
the
k3d create
now has a precheck suite, where certain assertions can be made (env var exists, command is available, ...) and eventually error and thus inform the user early on about missing dependencies, before creating any resources. This can be easily tested and expanded for other prechecks.decluttered the main function
I was able to declutter the main function to more idomatic way and moved the bubbletea and logging initialiaztion in
cobra.OnInitialize()
, as well as the bubbletea quitting in thePostRun()
:split up the
k3d create
logic in functionsThe biggest change might be the split up of the
runK3dCreate
function into functions. Where possible, I avoided if/else for more readability. To do so, I added a struct that contains all required options and sane defaults for creating the k3d cluster. I believe this way the code is more readable and most important testable, since I haven't found any tests so far.. I think some refactors in the underlying libs (kubefirst/runtime, kubefrist/kubefirst-api etc) might be worth itThis allows us to eadily call functions based on the current gitprovider:
other smaller changes
TF_CLI_ARGS="-no-color"
to tf apply runs for having no color encodings in the logfilekubefirst k3d
command by passing custom flags and envs