-
Notifications
You must be signed in to change notification settings - Fork 323
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
cli: support install command #713
Conversation
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.
Migrated the review comments from https://github.com/hashicorp/consul-k8s-cli/pull/2 so we can address them here
@@ -0,0 +1,5 @@ | |||
// Package flag is a thin layer over the stdlib flag package that provides |
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.
@ reviewers: you don't need to review all of the files in this package unless you want to see how it works since it is from another package
@@ -0,0 +1,94 @@ | |||
package install |
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.
@kschoche's comment:
These tests look great!
I know that testing CLI bits is challenging, but I'm wondering if we can add testing around skipConfirm and dryRun having expected behaviour?
Does it make sense to have some additional tests around how we're using step, and also somehow have at least a happy-path test of the actual command?
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.
Hey @kschoche, so I tried to give this a shot (skipConfirm and dryRun) and in theory it could have been possible by creating a fake actionConfig that fakes out the kubeclient and helm registry client. I got to the point of almost being able to create a fake actionConfig, but the Helm go SDK has the registry package under an "internal" folder, so I can't import the structs without copying that entire package. Since it would require a bit of jumping through hoops to mock out anything related to Helm, I think it may be worth covering dryRun and skipConfirm and potentially any other behaviour involving the Run() function via acceptance tests?
953b3a7
to
e77da79
Compare
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.
Heyo!! This is such great work!! The amount of effort that has gone into this is so clear!! Have some comments that should hopefully be straightforward!
c.Run([]string{"-auto-approve", "-f=../../config.yaml"}) | ||
} | ||
|
||
func TestCheckForPreviousPVCs(t *testing.T) { |
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.
This could be migrated to being a table test.
require.NoError(t, err) | ||
} | ||
|
||
func TestCheckForPreviousSecrets(t *testing.T) { |
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.
This can be a table test as well.
) | ||
|
||
// BaseCommand is embedded in all commands to provide common logic and data. | ||
type BaseCommand struct { |
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.
I love this pattern SO much!!
Thanks @thisisnotashwin!! I think I've addressed everything but the table tests, so I'm just going to go ahead and re-request your review to see if there's anything else blocking while I fix that tomorrow! |
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.
Thanks so much for the quick turnaround on the PR Nitya! This looks great. I think we can migrate to table tests later! Such an excellent PR!!
}) | ||
|
||
f = c.set.NewSet("Global Options") | ||
f.StringVar(&flag.StringVar{ |
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.
Given that by default people keep the kubeconfig file at ~/.kube/config
, I think it would make sense to use that as the default.
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.
In the default case, for any command that uses helm, we'll want to respect Helm's order of evaluation to get the kube context. I think if we were to explicitly set this to ~/.kube/config, then we wouldn't be able to respect the Helm library's "backups" for finding a kubeconfig (i.e an env var, etc.).
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.
Cool, then this is just me not knowing yet :) Thanks!
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.
Fantastic work, I think this will be a huge improvement for new users coming to Consul on K8s.
4857b15
to
749c942
Compare
consul-k8s install installs the latest Helm chart onto your Kubernetes cluster after performing a few verification steps. common/flag is copied from Waypoint’s internal/pkg/flag. It is a thin layer over the standard Go flag package that provides features such as aliasing and global flags. It was created specifically for mitchellh/cli. common/terminal package is adapted from the Waypoint Plugin SDK and excludes the Status interface and Step interface as described in doc.go. It allows us to have a consistent UI output with style. common/base.go describes a base command that can be embedded into all commands, and pass in common functionality like UI and ctx. This pattern was adapted from Waypoint. Co-authored-by: Saad Jamal <[email protected]>
8b22214
to
5f3b109
Compare
Thanks so much for the review and fast turnaround on a big PR @t-eckert and @thisisnotashwin! |
(This description is lightly edited from the original PR Saad created: https://github.com/hashicorp/consul-k8s-cli/pull/2 We migrated the PR here and migrated some of the review comments as well)
Changes proposed in this PR:
consul-k8s install
installs the latest Helm chart onto your Kubernetes cluster after performing a few verification steps. Note that once the CLI is moved into the monorepo, the version of the Helm chart deployed will match the version in the repository.common/flag
is copied from Waypoint’s internal/pkg subdirectory here. It is a thin layer over the standard Go flag package that provides features such as aliasing and global flags. It was created specifically for mitchellh/cli. See also this Slack thread for the decision to use it.common/terminal
package is adapted from the Waypoint Plugin SDK and excludes the Status interface and Step interface as described in doc.go. It allows us to have a consistent UI output with style.common/base.go
describes a base command that can be embedded into all commands, and pass in common functionality like UI and ctx. This pattern was adapted from Waypoint.common/utils.go
contains a functionWithInterrupt()
that we take from signalcontext.go in Waypoint's internal/pkg.How I've tested this PR:
validateFlags()
which performs a lot of the basic sanity checks before starting the install. The second helper isvalidLabel()
which makes sure that the namespace the user passes is legal, in that if follows RFC 1123 label convention.How I expect reviewers to test this PR:
Try it out :
git clone https://github.com/hashicorp/consul-k8s-cli.git
cd consul-k8s-cli
go build -o consul-k8s
consul-k8s install
Try this with different flags and various configurations. Note that if you are running on minikube, it is recommended to install with
-preset=demo
. That way server.replicas is set to 1. I also found it helpful to specify the namespace when manually testing via-namespace=not-peppertrout
.Code review :
Pay careful attention to install.go, specifically the pre-install checks. If you see anything you believe should be pulled out into an individual function and/or tested more thoroughly please comment!
Checklist:
Co-authored-by: Saad Jamal [email protected]
Co-authored-by: Nitya Dhanushkodi [email protected]