Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
update uninstall to use InstallOpts from rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
krantzinator committed Jan 13, 2021
1 parent b1bfa2d commit 7f99eb4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 19 deletions.
38 changes: 25 additions & 13 deletions internal/cli/uninstall.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cli

import (
"fmt"
"strings"
"time"

"github.com/posener/complete"

Expand All @@ -14,16 +16,16 @@ import (
type UninstallCommand struct {
*baseCommand

platform string
snapshotPath string
skipSnapshot bool
flagConfirm bool
deleteContext bool
platform string
snapshotFilename string
skipSnapshot bool
flagConfirm bool
deleteContext bool
}

func (c *UninstallCommand) Run(args []string) int {
ctx := c.Ctx
log := c.Log.Named("install")
log := c.Log.Named("uninstall")
defer c.Close()

// Initialize. If we fail, we just exit since Init handles the UI.
Expand Down Expand Up @@ -67,9 +69,16 @@ func (c *UninstallCommand) Run(args []string) int {
if !c.skipSnapshot {
s.Update("Generating server snapshot...")
defer s.Abort()
// sn := fmt.Sprintf("%s-%d", c.snapshotPath, time.Now().Unix())
// generate snapshot
// s.Update("Snapshot %q generated", sn")
// config := snapshot.Config{
// Client: c.project.Client(),
// }
// w, err := os.Create(c.snapshotFilename)
// if err = config.WriteSnapshot(ctx, w); err != nil {
// fmt.Fprintf(os.Stderr, "Error generating snapshot: %s", err)
// return 1
// }
// s.Update("Snapshot %q generated", c.snapshotFilename)
} else {
s.Update("skip-snapshot set; not generating server snapshot")
s.Status(terminal.StatusWarn)
Expand All @@ -88,7 +97,10 @@ func (c *UninstallCommand) Run(args []string) int {
return 1
}

err = p.Uninstall(ctx, c.ui, log)
err = p.Uninstall(ctx, &serverinstall.InstallOpts{
Log: log,
UI: c.ui,
})
if err != nil {
// point to current docs on manual server cleanup
c.ui.Output(
Expand Down Expand Up @@ -157,10 +169,10 @@ func (c *UninstallCommand) Flags() *flag.Sets {
})

f.StringVar(&flag.StringVar{
Name: "snapshot-path",
Target: &c.snapshotPath,
Default: "",
Usage: "Path of the file to write the snapshot to.",
Name: "snapshot-filename",
Target: &c.snapshotFilename,
Default: fmt.Sprintf("sever-snapshot-%d", time.Now().Unix()),
Usage: "Filename to write the snapshot to.",
})

f.BoolVar(&flag.BoolVar{
Expand Down
5 changes: 3 additions & 2 deletions internal/serverinstall/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,10 @@ func (i *DockerInstaller) InstallFlags(set *flag.Set) {
}

func (i *DockerInstaller) Uninstall(
ctx context.Context, ui terminal.UI, log hclog.Logger,
ctx context.Context,
opts *InstallOpts,
) error {
sg := ui.StepGroup()
sg := opts.UI.StepGroup()
defer sg.Wait()

// bulk of this copied from PR#660
Expand Down
4 changes: 2 additions & 2 deletions internal/serverinstall/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ func (i *K8sInstaller) InstallFlags(set *flag.Set) {
})
}

func (i *K8sInstaller) Uninstall(ctx context.Context, ui terminal.UI, log hclog.Logger) error {

func (i *K8sInstaller) Uninstall(ctx context.Context, opts *InstallOpts) error {
// TODO
// deleteStatefulSet()
// delete pvc
// delete svc
Expand Down
3 changes: 2 additions & 1 deletion internal/serverinstall/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ func (i *NomadInstaller) InstallFlags(set *flag.Set) {
})
}

func (i *NomadInstaller) Uninstall(ctx context.Context, ui terminal.UI, log hclog.Logger) error {
func (i *NomadInstaller) Uninstall(ctx context.Context, opts *InstallOpts) error {
// TODO
return nil
}

Expand Down
8 changes: 7 additions & 1 deletion internal/serverinstall/serverinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ type Installer interface {
// specify flags for the install CLI. The flags should be prefixed with
// the platform name to avoid conflicts with other flags.
InstallFlags(*flag.Set)
Uninstall(context.Context, terminal.UI, hclog.Logger) error

// Uninstall expects the Waypoint server to be uninstalled.
Uninstall(context.Context, *InstallOpts) error

// UninstallFlags is called prior to Uninstall and allows the Uninstaller to
// specify flags for the uninstall CLI. The flags should be prefixed with the
// platform name to avoid conflicts with other flags.
UninstallFlags(*flag.Set)
}

Expand Down

0 comments on commit 7f99eb4

Please sign in to comment.