Commit 43ce6b57 authored by Baofa Fan's avatar Baofa Fan Committed by Adam Reese

delete secret when helm reset (#2715)

* delete secret when helm reset

* add test

* expected 3 actions
parent b5552067
......@@ -251,7 +251,6 @@ func createSecret(client corev1.SecretsGetter, opts *Options) error {
// generateSecret builds the secret object that hold Tiller secrets.
func generateSecret(opts *Options) (*v1.Secret, error) {
const secretName = "tiller-secret"
labels := generateLabels(map[string]string{"name": "tiller"})
secret := &v1.Secret{
......
......@@ -28,6 +28,7 @@ import (
const (
deploymentName = "tiller-deploy"
serviceName = "tiller-deploy"
secretName = "tiller-secret"
)
// Uninstall uses Kubernetes client to uninstall Tiller.
......@@ -35,7 +36,10 @@ func Uninstall(client internalclientset.Interface, opts *Options) error {
if err := deleteService(client.Core(), opts.Namespace); err != nil {
return err
}
return deleteDeployment(client, opts.Namespace)
if err := deleteDeployment(client, opts.Namespace); err != nil {
return err
}
return deleteSecret(client.Core(), opts.Namespace)
}
// deleteService deletes the Tiller Service resource
......@@ -53,6 +57,12 @@ func deleteDeployment(client internalclientset.Interface, namespace string) erro
return ingoreNotFound(err)
}
// deleteSecret deletes the Tiller Secret resource
func deleteSecret(client coreclient.SecretsGetter, namespace string) error {
err := client.Secrets(namespace).Delete(secretName, &metav1.DeleteOptions{})
return ingoreNotFound(err)
}
func ingoreNotFound(err error) error {
if apierrors.IsNotFound(err) {
return nil
......
......@@ -34,8 +34,8 @@ func TestUninstall(t *testing.T) {
t.Errorf("unexpected error: %#+v", err)
}
if actions := fc.Actions(); len(actions) != 6 {
t.Errorf("unexpected actions: %v, expected 6 actions got %d", actions, len(actions))
if actions := fc.Actions(); len(actions) != 7 {
t.Errorf("unexpected actions: %v, expected 7 actions got %d", actions, len(actions))
}
}
......@@ -50,8 +50,8 @@ func TestUninstall_serviceNotFound(t *testing.T) {
t.Errorf("unexpected error: %#+v", err)
}
if actions := fc.Actions(); len(actions) != 6 {
t.Errorf("unexpected actions: %v, expected 6 actions got %d", actions, len(actions))
if actions := fc.Actions(); len(actions) != 7 {
t.Errorf("unexpected actions: %v, expected 7 actions got %d", actions, len(actions))
}
}
......@@ -66,7 +66,23 @@ func TestUninstall_deploymentNotFound(t *testing.T) {
t.Errorf("unexpected error: %#+v", err)
}
if actions := fc.Actions(); len(actions) != 6 {
t.Errorf("unexpected actions: %v, expected 6 actions got %d", actions, len(actions))
if actions := fc.Actions(); len(actions) != 7 {
t.Errorf("unexpected actions: %v, expected 7 actions got %d", actions, len(actions))
}
}
func TestUninstall_secretNotFound(t *testing.T) {
fc := &fake.Clientset{}
fc.AddReactor("delete", "secrets", func(action testcore.Action) (bool, runtime.Object, error) {
return true, nil, apierrors.NewNotFound(api.Resource("secrets"), "1")
})
opts := &Options{Namespace: api.NamespaceDefault}
if err := Uninstall(fc, opts); err != nil {
t.Errorf("unexpected error: %#+v", err)
}
if actions := fc.Actions(); len(actions) != 7 {
t.Errorf("unexpected actions: %v, expect 7 actions got %d", actions, len(actions))
}
}
......@@ -52,8 +52,8 @@ func TestResetCmd(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
actions := fc.Actions()
if len(actions) != 2 {
t.Errorf("Expected 2 actions, got %d", len(actions))
if len(actions) != 3 {
t.Errorf("Expected 3 actions, got %d", len(actions))
}
expected := "Tiller (the Helm server-side component) has been uninstalled from your Kubernetes Cluster."
if !strings.Contains(buf.String(), expected) {
......@@ -86,8 +86,8 @@ func TestResetCmd_removeHelmHome(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
actions := fc.Actions()
if len(actions) != 2 {
t.Errorf("Expected 2 actions, got %d", len(actions))
if len(actions) != 3 {
t.Errorf("Expected 3 actions, got %d", len(actions))
}
expected := "Tiller (the Helm server-side component) has been uninstalled from your Kubernetes Cluster."
if !strings.Contains(buf.String(), expected) {
......@@ -157,8 +157,8 @@ func TestReset_forceFlag(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
actions := fc.Actions()
if len(actions) != 2 {
t.Errorf("Expected 2 actions, got %d", len(actions))
if len(actions) != 3 {
t.Errorf("Expected 3 actions, got %d", len(actions))
}
expected := "Tiller (the Helm server-side component) has been uninstalled from your Kubernetes Cluster."
if !strings.Contains(buf.String(), expected) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment