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

cli: support install command #713

Merged
merged 4 commits into from
Sep 16, 2021
Merged

cli: support install command #713

merged 4 commits into from
Sep 16, 2021

Conversation

ndhanushkodi
Copy link
Contributor

@ndhanushkodi ndhanushkodi commented Sep 3, 2021

(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.
  • For details about flags and their intended behavior visit the RFC, linked here.
  • 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 function WithInterrupt() that we take from signalcontext.go in Waypoint's internal/pkg.

How I've tested this PR:

  • Created rather simple unit tests that validate two different helper functions inside of install.go. The first helper function we test is validateFlags() which performs a lot of the basic sanity checks before starting the install. The second helper is validLabel() which makes sure that the namespace the user passes is legal, in that if follows RFC 1123 label convention.
  • In addition to the actual unit tests, a lot of manual ad-hoc testing took place. Follow the instructions below to build the CLI and test the various flags, especially the -set ones, and see how they interact with one another.
  • Note that more rigorous acceptance tests are soon to come after monorepo is finished. These tests will actually run the installation through and validate it worked properly.

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:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

Co-authored-by: Saad Jamal [email protected]
Co-authored-by: Nitya Dhanushkodi [email protected]

Copy link
Contributor Author

@ndhanushkodi ndhanushkodi left a 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
Copy link
Contributor Author

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

cli/README.md Outdated Show resolved Hide resolved
cli/README.md Show resolved Hide resolved
@@ -0,0 +1,94 @@
package install
Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

cli/cmd/install/install.go Show resolved Hide resolved
@ndhanushkodi ndhanushkodi requested review from thisisnotashwin, a team and t-eckert and removed request for a team September 10, 2021 05:38
@ndhanushkodi ndhanushkodi force-pushed the cli-install branch 2 times, most recently from 953b3a7 to e77da79 Compare September 10, 2021 06:02
cli/README.md Outdated Show resolved Hide resolved
cli/cmd/version/version.go Show resolved Hide resolved
Copy link
Contributor

@thisisnotashwin thisisnotashwin left a 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!

cli/cmd/install/presets.go Outdated Show resolved Hide resolved
cli/cmd/install/presets.go Outdated Show resolved Hide resolved
cli/cmd/install/install_test.go Outdated Show resolved Hide resolved
cli/cmd/install/install_test.go Outdated Show resolved Hide resolved
cli/cmd/install/install_test.go Outdated Show resolved Hide resolved
cli/cmd/install/install_test.go Outdated Show resolved Hide resolved
c.Run([]string{"-auto-approve", "-f=../../config.yaml"})
}

func TestCheckForPreviousPVCs(t *testing.T) {
Copy link
Contributor

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) {
Copy link
Contributor

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.

cli/cmd/install/install_test.go Show resolved Hide resolved
)

// BaseCommand is embedded in all commands to provide common logic and data.
type BaseCommand struct {
Copy link
Contributor

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!!

@ndhanushkodi ndhanushkodi mentioned this pull request Sep 15, 2021
2 tasks
@ndhanushkodi
Copy link
Contributor Author

ndhanushkodi commented Sep 15, 2021

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!

Copy link
Contributor

@thisisnotashwin thisisnotashwin left a 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!!

cli/cmd/install/install.go Show resolved Hide resolved
})

f = c.set.NewSet("Global Options")
f.StringVar(&flag.StringVar{
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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!

Copy link
Contributor

@t-eckert t-eckert left a 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.

@ndhanushkodi ndhanushkodi force-pushed the cli-install branch 2 times, most recently from 4857b15 to 749c942 Compare September 16, 2021 01:43
ndhanushkodi and others added 2 commits September 15, 2021 19:30
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]>
@ndhanushkodi
Copy link
Contributor Author

Thanks so much for the review and fast turnaround on a big PR @t-eckert and @thisisnotashwin!

@ndhanushkodi ndhanushkodi changed the title cli: install command (and move it to main repository) cli: support install command Sep 16, 2021
@ndhanushkodi ndhanushkodi merged commit 9496831 into main Sep 16, 2021
@ndhanushkodi ndhanushkodi deleted the cli-install branch September 16, 2021 05:04
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.

3 participants