Skip to content

Commit

Permalink
cleanup and add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ndhanushkodi committed Sep 16, 2021
1 parent f325256 commit dd282f4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 27 deletions.
49 changes: 49 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and proceed to run the binary.

## Commands
* [consul-k8s install](#consul-k8s-install)
* [consul-k8s uninstall](#consul-k8s-uninstall)

### consul-k8s install
This command installs Consul on a Kubernetes cluster. It allows `demo` and `secure` installations via preset configurations
Expand Down Expand Up @@ -81,3 +82,51 @@ Global Options:
Path to kubeconfig file. This is aliased as "-c".
```

### consul-k8s uninstall
This command uninstalls Consul on Kubernetes, while prompting whether to uninstall the release and whether to delete all
related resources such as PVCs, Secrets, and ServiceAccounts.

Get started with:
```bash
consul-k8s uninstall
```

```
Usage: kubectl consul uninstall [options]
Uninstall Consul and clean up all data.
Any data store in Consul will not be recoverable.
Command Options:
-auto-approve
Skip approval prompt for uninstalling Consul. The default is false.
-name=<string>
Name of the installation. This will be prefixed to resources installed
on the cluster.
-namespace=<string>
Namespace for the Consul installation.
-skip-wipe-data
Skip deleting all PVCs, Secrets, and Service Accounts associated with
Consul Helm installation without prompting for approval to delete. The
default is false.
-wipe-data
Delete all PVCs, Secrets, and Service Accounts associated with Consul
Helm installation without prompting for approval to delete. Only use
this when persisted data from previous installations is no longer
necessary. The default is false.
Global Options:
-context=<string>
Kubernetes context to use.
-kubeconfig=<string>
Path to kubeconfig file. This is aliased as "-c".
```
7 changes: 4 additions & 3 deletions cli/cmd/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ func (c *Command) init() {
}

c.help = c.set.Help()

// c.Init() calls the embedded BaseCommand's initialization function.
c.Init()
}

func (c *Command) Run(args []string) int {
c.once.Do(c.init)
// Note that `c.init` and `c.Init` are NOT the same thing. One initializes the command struct,
// the other the UI. It looks similar because BaseCommand is embedded in Command.
c.Init()

defer func() {
if err := c.Close(); err != nil {
c.UI.Output(err.Error())
Expand Down
47 changes: 23 additions & 24 deletions cli/cmd/uninstall/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,6 @@ import (
"k8s.io/client-go/kubernetes/fake"
)

// Helper function which sets up a Command struct for you.
func getInitializedCommand(t *testing.T) *Command {
t.Helper()
log := hclog.New(&hclog.LoggerOptions{
Name: "cli",
Level: hclog.Info,
Output: os.Stdout,
})
ctx, _ := context.WithCancel(context.Background())

baseCommand := &common.BaseCommand{
Ctx: ctx,
Log: log,
}

c := &Command{
BaseCommand: baseCommand,
}
c.init()
c.Init()
return c
}

func TestDeletePVCs(t *testing.T) {
c := getInitializedCommand(t)
c.kubernetes = fake.NewSimpleClientset()
Expand Down Expand Up @@ -77,7 +54,7 @@ func TestDeleteSecrets(t *testing.T) {
},
},
}
secret2 := &v1.PersistentVolumeClaim{
secret2 := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "consul-test-secret2",
Labels: map[string]string{
Expand Down Expand Up @@ -125,3 +102,25 @@ func TestDeleteServiceAccounts(t *testing.T) {
require.NoError(t, err)
require.Len(t, sas.Items, 0)
}

// getInitializedCommand sets up a command struct for tests.
func getInitializedCommand(t *testing.T) *Command {
t.Helper()
log := hclog.New(&hclog.LoggerOptions{
Name: "cli",
Level: hclog.Info,
Output: os.Stdout,
})
ctx, _ := context.WithCancel(context.Background())

baseCommand := &common.BaseCommand{
Ctx: ctx,
Log: log,
}

c := &Command{
BaseCommand: baseCommand,
}
c.init()
return c
}

0 comments on commit dd282f4

Please sign in to comment.