From 45931118924ca4a3df01bbb0da3b0e74719abc10 Mon Sep 17 00:00:00 2001
From: Matt Butcher <mbutcher@engineyard.com>
Date: Mon, 1 Aug 2016 13:25:11 -0600
Subject: [PATCH] fix(helm): rename --reuse-name to --replace

Closes #1010
---
 cmd/helm/install.go          | 6 +++---
 cmd/helm/install_test.go     | 4 ++--
 cmd/tiller/release_server.go | 4 +++-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/cmd/helm/install.go b/cmd/helm/install.go
index e80527b48..9d7e84a72 100644
--- a/cmd/helm/install.go
+++ b/cmd/helm/install.go
@@ -59,7 +59,7 @@ type installCmd struct {
 	chartPath    string
 	dryRun       bool
 	disableHooks bool
-	reuseName    bool
+	replace      bool
 	out          io.Writer
 	client       helm.Interface
 	values       *values
@@ -98,7 +98,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
 	f.StringVar(&inst.namespace, "namespace", "default", "the namespace to install the release into")
 	f.BoolVar(&inst.dryRun, "dry-run", false, "simulate an install")
 	f.BoolVar(&inst.disableHooks, "no-hooks", false, "prevent hooks from running during install")
-	f.BoolVar(&inst.reuseName, "reuse-name", false, "force Tiller to re-use the given name, even if that name is already used. This is unsafe in production")
+	f.BoolVar(&inst.replace, "replace", false, "re-use the given name, even if that name is already used. This is unsafe in production")
 	f.Var(inst.values, "set", "set values on the command line. Separate values with commas: key1=val1,key2=val2")
 	return cmd
 }
@@ -119,7 +119,7 @@ func (i *installCmd) run() error {
 		helm.ValueOverrides(rawVals),
 		helm.ReleaseName(i.name),
 		helm.InstallDryRun(i.dryRun),
-		helm.InstallReuseName(i.reuseName),
+		helm.InstallReuseName(i.replace),
 		helm.InstallDisableHooks(i.disableHooks))
 	if err != nil {
 		return prettyError(err)
diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go
index 41663a337..9db48cb47 100644
--- a/cmd/helm/install_test.go
+++ b/cmd/helm/install_test.go
@@ -59,9 +59,9 @@ func TestInstall(t *testing.T) {
 		},
 		// Install, re-use name
 		{
-			name:     "install and reuse name",
+			name:     "install and replace release",
 			args:     []string{"testdata/testcharts/alpine"},
-			flags:    strings.Split("--name aeneas --reuse-name", " "),
+			flags:    strings.Split("--name aeneas --replace", " "),
 			expected: "aeneas",
 			resp:     releaseMock(&releaseOptions{name: "aeneas"}),
 		},
diff --git a/cmd/tiller/release_server.go b/cmd/tiller/release_server.go
index 42494cff6..061a76c4b 100644
--- a/cmd/tiller/release_server.go
+++ b/cmd/tiller/release_server.go
@@ -240,10 +240,12 @@ func (s *releaseServer) uniqName(start string, reuse bool) (string, error) {
 	if start != "" {
 		if rel, err := s.env.Releases.Read(start); err == storage.ErrNotFound {
 			return start, nil
-		} else if reuse && rel.Info.Status.Code == release.Status_DELETED {
+		} else if st := rel.Info.Status.Code; reuse && (st == release.Status_DELETED || st == release.Status_FAILED) {
 			// Allowe re-use of names if the previous release is marked deleted.
 			log.Printf("reusing name %q", start)
 			return start, nil
+		} else if reuse {
+			return "", errors.New("cannot re-use a name that is still in use")
 		}
 
 		return "", fmt.Errorf("a release named %q already exists", start)
-- 
GitLab