Errors out in case requested plugin exists

Partially fixes issues/2385 - helm install silently updates the plugin, if it pre-existed
pull/2400/head
Sushil Kumar 7 years ago
parent 6344f1d8e9
commit c84fb11a68

@ -40,6 +40,10 @@ type Installer interface {
// Install installs a plugin to $HELM_HOME. // Install installs a plugin to $HELM_HOME.
func Install(i Installer) error { func Install(i Installer) error {
if _, pathErr := os.Stat(i.Path()); !os.IsNotExist(pathErr) {
return errors.New("plugin already exists")
}
return i.Install() return i.Install()
} }

@ -31,7 +31,7 @@ func TestLocalInstaller(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(hh) defer os.RemoveAll(hh)
home := helmpath.Home(hh) home := helmpath.Home(hh)
if err := os.MkdirAll(home.Plugins(), 0755); err != nil { if err := os.MkdirAll(home.Plugins(), 0755); err != nil {
@ -43,7 +43,7 @@ func TestLocalInstaller(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(tdir) defer os.RemoveAll(tdir)
if err := ioutil.WriteFile(filepath.Join(tdir, "plugin.yaml"), []byte{}, 0644); err != nil { if err := ioutil.WriteFile(filepath.Join(tdir, "plugin.yaml"), []byte{}, 0644); err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -18,6 +18,7 @@ package installer // import "k8s.io/helm/pkg/plugin/installer"
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"testing" "testing"
"k8s.io/helm/pkg/helm/helmpath" "k8s.io/helm/pkg/helm/helmpath"
@ -53,7 +54,7 @@ func TestVCSInstaller(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(hh) defer os.RemoveAll(hh)
home := helmpath.Home(hh) home := helmpath.Home(hh)
if err := os.MkdirAll(home.Plugins(), 0755); err != nil { if err := os.MkdirAll(home.Plugins(), 0755); err != nil {
@ -61,8 +62,9 @@ func TestVCSInstaller(t *testing.T) {
} }
source := "https://github.com/adamreese/helm-env" source := "https://github.com/adamreese/helm-env"
testRepoPath, _ := filepath.Abs("../testdata/plugdir/echo")
repo := &testRepo{ repo := &testRepo{
local: "../testdata/plugdir/echo", local: testRepoPath,
tags: []string{"0.1.0", "0.1.1"}, tags: []string{"0.1.0", "0.1.1"},
} }
@ -89,6 +91,13 @@ func TestVCSInstaller(t *testing.T) {
if i.Path() != home.Path("plugins", "helm-env") { if i.Path() != home.Path("plugins", "helm-env") {
t.Errorf("expected path '$HELM_HOME/plugins/helm-env', got %q", i.Path()) t.Errorf("expected path '$HELM_HOME/plugins/helm-env', got %q", i.Path())
} }
// Install again to test plugin exists error
if err := Install(i); err == nil {
t.Error("expected error for plugin exists, got none")
} else if err.Error() != "plugin already exists" {
t.Errorf("expected error for plugin exists, got (%v)", err)
}
} }
func TestVCSInstallerNonExistentVersion(t *testing.T) { func TestVCSInstallerNonExistentVersion(t *testing.T) {
@ -96,7 +105,7 @@ func TestVCSInstallerNonExistentVersion(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(hh) defer os.RemoveAll(hh)
home := helmpath.Home(hh) home := helmpath.Home(hh)
if err := os.MkdirAll(home.Plugins(), 0755); err != nil { if err := os.MkdirAll(home.Plugins(), 0755); err != nil {

Loading…
Cancel
Save