Rename Delete to Uninstall [#4]
Helm3 renamed its delete command to uninstall. We should still accept helm_command=delete for drone-helm compatibility, but the internals should use Helm's preferred name.
This commit is contained in:
parent
f373004bd2
commit
161960e55e
|
@ -59,8 +59,8 @@ func determineSteps(cfg Config) *func(Config) []Step {
|
||||||
switch cfg.Command {
|
switch cfg.Command {
|
||||||
case "upgrade":
|
case "upgrade":
|
||||||
return &upgrade
|
return &upgrade
|
||||||
case "delete":
|
case "uninstall", "delete":
|
||||||
return &del
|
return &uninstall
|
||||||
case "lint":
|
case "lint":
|
||||||
return &lint
|
return &lint
|
||||||
case "help":
|
case "help":
|
||||||
|
@ -70,7 +70,7 @@ func determineSteps(cfg Config) *func(Config) []Step {
|
||||||
case "push", "tag", "deployment", "pull_request", "promote", "rollback":
|
case "push", "tag", "deployment", "pull_request", "promote", "rollback":
|
||||||
return &upgrade
|
return &upgrade
|
||||||
case "delete":
|
case "delete":
|
||||||
return &del
|
return &uninstall
|
||||||
default:
|
default:
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
@ -109,9 +109,9 @@ var upgrade = func(cfg Config) []Step {
|
||||||
return steps
|
return steps
|
||||||
}
|
}
|
||||||
|
|
||||||
var del = func(cfg Config) []Step {
|
var uninstall = func(cfg Config) []Step {
|
||||||
steps := initKube(cfg)
|
steps := initKube(cfg)
|
||||||
steps = append(steps, &run.Delete{
|
steps = append(steps, &run.Uninstall{
|
||||||
Release: cfg.Release,
|
Release: cfg.Release,
|
||||||
DryRun: cfg.DryRun,
|
DryRun: cfg.DryRun,
|
||||||
})
|
})
|
||||||
|
|
|
@ -130,8 +130,8 @@ func (suite *PlanTestSuite) TestDel() {
|
||||||
Release: "jetta_id_love_to_change_the_world",
|
Release: "jetta_id_love_to_change_the_world",
|
||||||
}
|
}
|
||||||
|
|
||||||
steps := del(cfg)
|
steps := uninstall(cfg)
|
||||||
suite.Require().Equal(2, len(steps), "del should return 2 steps")
|
suite.Require().Equal(2, len(steps), "uninstall should return 2 steps")
|
||||||
|
|
||||||
suite.Require().IsType(&run.InitKube{}, steps[0])
|
suite.Require().IsType(&run.InitKube{}, steps[0])
|
||||||
init, _ := steps[0].(*run.InitKube)
|
init, _ := steps[0].(*run.InitKube)
|
||||||
|
@ -146,9 +146,9 @@ func (suite *PlanTestSuite) TestDel() {
|
||||||
|
|
||||||
suite.Equal(expected, init)
|
suite.Equal(expected, init)
|
||||||
|
|
||||||
suite.Require().IsType(&run.Delete{}, steps[1])
|
suite.Require().IsType(&run.Uninstall{}, steps[1])
|
||||||
actual, _ := steps[1].(*run.Delete)
|
actual, _ := steps[1].(*run.Uninstall)
|
||||||
expected = &run.Delete{
|
expected = &run.Uninstall{
|
||||||
Release: "jetta_id_love_to_change_the_world",
|
Release: "jetta_id_love_to_change_the_world",
|
||||||
DryRun: true,
|
DryRun: true,
|
||||||
}
|
}
|
||||||
|
@ -213,12 +213,21 @@ func (suite *PlanTestSuite) TestDeterminePlanUpgradeFromDroneEvent() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *PlanTestSuite) TestDeterminePlanUninstallCommand() {
|
||||||
|
cfg := Config{
|
||||||
|
Command: "uninstall",
|
||||||
|
}
|
||||||
|
stepsMaker := determineSteps(cfg)
|
||||||
|
suite.Same(&uninstall, stepsMaker)
|
||||||
|
}
|
||||||
|
|
||||||
|
// helm_command = delete is provided as an alias for backwards-compatibility with drone-helm
|
||||||
func (suite *PlanTestSuite) TestDeterminePlanDeleteCommand() {
|
func (suite *PlanTestSuite) TestDeterminePlanDeleteCommand() {
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
Command: "delete",
|
Command: "delete",
|
||||||
}
|
}
|
||||||
stepsMaker := determineSteps(cfg)
|
stepsMaker := determineSteps(cfg)
|
||||||
suite.Same(&del, stepsMaker)
|
suite.Same(&uninstall, stepsMaker)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestDeterminePlanDeleteFromDroneEvent() {
|
func (suite *PlanTestSuite) TestDeterminePlanDeleteFromDroneEvent() {
|
||||||
|
@ -226,7 +235,7 @@ func (suite *PlanTestSuite) TestDeterminePlanDeleteFromDroneEvent() {
|
||||||
DroneEvent: "delete",
|
DroneEvent: "delete",
|
||||||
}
|
}
|
||||||
stepsMaker := determineSteps(cfg)
|
stepsMaker := determineSteps(cfg)
|
||||||
suite.Same(&del, stepsMaker)
|
suite.Same(&uninstall, stepsMaker)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestDeterminePlanLintCommand() {
|
func (suite *PlanTestSuite) TestDeterminePlanLintCommand() {
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
package run
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete is an execution step that calls `helm upgrade` when executed.
|
|
||||||
type Delete struct {
|
|
||||||
Release string
|
|
||||||
DryRun bool
|
|
||||||
cmd cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute executes the `helm upgrade` command.
|
|
||||||
func (d *Delete) Execute(_ Config) error {
|
|
||||||
return d.cmd.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare gets the Delete ready to execute.
|
|
||||||
func (d *Delete) Prepare(cfg Config) error {
|
|
||||||
if d.Release == "" {
|
|
||||||
return fmt.Errorf("release is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
args := []string{"--kubeconfig", cfg.KubeConfig}
|
|
||||||
|
|
||||||
if cfg.Namespace != "" {
|
|
||||||
args = append(args, "--namespace", cfg.Namespace)
|
|
||||||
}
|
|
||||||
if cfg.Debug {
|
|
||||||
args = append(args, "--debug")
|
|
||||||
}
|
|
||||||
|
|
||||||
args = append(args, "delete")
|
|
||||||
|
|
||||||
if d.DryRun {
|
|
||||||
args = append(args, "--dry-run")
|
|
||||||
}
|
|
||||||
|
|
||||||
args = append(args, d.Release)
|
|
||||||
|
|
||||||
d.cmd = command(helmBin, args...)
|
|
||||||
d.cmd.Stdout(cfg.Stdout)
|
|
||||||
d.cmd.Stderr(cfg.Stderr)
|
|
||||||
|
|
||||||
if cfg.Debug {
|
|
||||||
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", d.cmd.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
51
internal/run/uninstall.go
Normal file
51
internal/run/uninstall.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package run
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Uninstall is an execution step that calls `helm uninstall` when executed.
|
||||||
|
type Uninstall struct {
|
||||||
|
Release string
|
||||||
|
DryRun bool
|
||||||
|
cmd cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute executes the `helm uninstall` command.
|
||||||
|
func (u *Uninstall) Execute(_ Config) error {
|
||||||
|
return u.cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare gets the Uninstall ready to execute.
|
||||||
|
func (u *Uninstall) Prepare(cfg Config) error {
|
||||||
|
if u.Release == "" {
|
||||||
|
return fmt.Errorf("release is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{"--kubeconfig", cfg.KubeConfig}
|
||||||
|
|
||||||
|
if cfg.Namespace != "" {
|
||||||
|
args = append(args, "--namespace", cfg.Namespace)
|
||||||
|
}
|
||||||
|
if cfg.Debug {
|
||||||
|
args = append(args, "--debug")
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, "uninstall")
|
||||||
|
|
||||||
|
if u.DryRun {
|
||||||
|
args = append(args, "--dry-run")
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, u.Release)
|
||||||
|
|
||||||
|
u.cmd = command(helmBin, args...)
|
||||||
|
u.cmd.Stdout(cfg.Stdout)
|
||||||
|
u.cmd.Stderr(cfg.Stderr)
|
||||||
|
|
||||||
|
if cfg.Debug {
|
||||||
|
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", u.cmd.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteTestSuite struct {
|
type UninstallTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
ctrl *gomock.Controller
|
ctrl *gomock.Controller
|
||||||
mockCmd *Mockcmd
|
mockCmd *Mockcmd
|
||||||
|
@ -16,7 +16,7 @@ type DeleteTestSuite struct {
|
||||||
originalCommand func(string, ...string) cmd
|
originalCommand func(string, ...string) cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DeleteTestSuite) BeforeTest(_, _ string) {
|
func (suite *UninstallTestSuite) BeforeTest(_, _ string) {
|
||||||
suite.ctrl = gomock.NewController(suite.T())
|
suite.ctrl = gomock.NewController(suite.T())
|
||||||
suite.mockCmd = NewMockcmd(suite.ctrl)
|
suite.mockCmd = NewMockcmd(suite.ctrl)
|
||||||
|
|
||||||
|
@ -27,18 +27,18 @@ func (suite *DeleteTestSuite) BeforeTest(_, _ string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DeleteTestSuite) AfterTest(_, _ string) {
|
func (suite *UninstallTestSuite) AfterTest(_, _ string) {
|
||||||
command = suite.originalCommand
|
command = suite.originalCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteTestSuite(t *testing.T) {
|
func TestUninstallTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(DeleteTestSuite))
|
suite.Run(t, new(UninstallTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DeleteTestSuite) TestPrepareAndExecute() {
|
func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
||||||
defer suite.ctrl.Finish()
|
defer suite.ctrl.Finish()
|
||||||
|
|
||||||
d := Delete{
|
u := Uninstall{
|
||||||
Release: "zayde_wølf_king",
|
Release: "zayde_wølf_king",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,15 +61,15 @@ func (suite *DeleteTestSuite) TestPrepareAndExecute() {
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
KubeConfig: "/root/.kube/config",
|
KubeConfig: "/root/.kube/config",
|
||||||
}
|
}
|
||||||
suite.NoError(d.Prepare(cfg))
|
suite.NoError(u.Prepare(cfg))
|
||||||
expected := []string{"--kubeconfig", "/root/.kube/config", "delete", "zayde_wølf_king"}
|
expected := []string{"--kubeconfig", "/root/.kube/config", "uninstall", "zayde_wølf_king"}
|
||||||
suite.Equal(expected, actual)
|
suite.Equal(expected, actual)
|
||||||
|
|
||||||
d.Execute(cfg)
|
u.Execute(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DeleteTestSuite) TestPrepareDryRunFlag() {
|
func (suite *UninstallTestSuite) TestPrepareDryRunFlag() {
|
||||||
d := Delete{
|
u := Uninstall{
|
||||||
Release: "firefox_ak_wildfire",
|
Release: "firefox_ak_wildfire",
|
||||||
DryRun: true,
|
DryRun: true,
|
||||||
}
|
}
|
||||||
|
@ -80,13 +80,13 @@ func (suite *DeleteTestSuite) TestPrepareDryRunFlag() {
|
||||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||||
|
|
||||||
suite.NoError(d.Prepare(cfg))
|
suite.NoError(u.Prepare(cfg))
|
||||||
expected := []string{"--kubeconfig", "/root/.kube/config", "delete", "--dry-run", "firefox_ak_wildfire"}
|
expected := []string{"--kubeconfig", "/root/.kube/config", "uninstall", "--dry-run", "firefox_ak_wildfire"}
|
||||||
suite.Equal(expected, suite.actualArgs)
|
suite.Equal(expected, suite.actualArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DeleteTestSuite) TestPrepareNamespaceFlag() {
|
func (suite *UninstallTestSuite) TestPrepareNamespaceFlag() {
|
||||||
d := Delete{
|
u := Uninstall{
|
||||||
Release: "carly_simon_run_away_with_me",
|
Release: "carly_simon_run_away_with_me",
|
||||||
}
|
}
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
|
@ -97,14 +97,14 @@ func (suite *DeleteTestSuite) TestPrepareNamespaceFlag() {
|
||||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||||
|
|
||||||
suite.NoError(d.Prepare(cfg))
|
suite.NoError(u.Prepare(cfg))
|
||||||
expected := []string{"--kubeconfig", "/root/.kube/config",
|
expected := []string{"--kubeconfig", "/root/.kube/config",
|
||||||
"--namespace", "emotion", "delete", "carly_simon_run_away_with_me"}
|
"--namespace", "emotion", "uninstall", "carly_simon_run_away_with_me"}
|
||||||
suite.Equal(expected, suite.actualArgs)
|
suite.Equal(expected, suite.actualArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DeleteTestSuite) TestPrepareDebugFlag() {
|
func (suite *UninstallTestSuite) TestPrepareDebugFlag() {
|
||||||
d := Delete{
|
u := Uninstall{
|
||||||
Release: "just_a_band_huff_and_puff",
|
Release: "just_a_band_huff_and_puff",
|
||||||
}
|
}
|
||||||
stderr := strings.Builder{}
|
stderr := strings.Builder{}
|
||||||
|
@ -125,17 +125,17 @@ func (suite *DeleteTestSuite) TestPrepareDebugFlag() {
|
||||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||||
suite.mockCmd.EXPECT().Stderr(&stderr).AnyTimes()
|
suite.mockCmd.EXPECT().Stderr(&stderr).AnyTimes()
|
||||||
|
|
||||||
suite.NoError(d.Prepare(cfg))
|
suite.NoError(u.Prepare(cfg))
|
||||||
suite.Equal(fmt.Sprintf("Generated command: '%s --kubeconfig /root/.kube/config "+
|
suite.Equal(fmt.Sprintf("Generated command: '%s --kubeconfig /root/.kube/config "+
|
||||||
"--debug delete just_a_band_huff_and_puff'\n", helmBin), stderr.String())
|
"--debug uninstall just_a_band_huff_and_puff'\n", helmBin), stderr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DeleteTestSuite) TestPrepareRequiresRelease() {
|
func (suite *UninstallTestSuite) TestPrepareRequiresRelease() {
|
||||||
// These aren't really expected, but allowing them gives clearer test-failure messages
|
// These aren't really expected, but allowing them gives clearer test-failure messages
|
||||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||||
|
|
||||||
d := Delete{}
|
u := Uninstall{}
|
||||||
err := d.Prepare(Config{})
|
err := u.Prepare(Config{})
|
||||||
suite.EqualError(err, "release is required", "Delete.Release should be mandatory")
|
suite.EqualError(err, "release is required", "Uninstall.Release should be mandatory")
|
||||||
}
|
}
|
Loading…
Reference in a new issue