github.com/strongmonkey/helm@v2.7.2+incompatible/cmd/helm/installer/uninstall.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package installer // import "k8s.io/helm/cmd/helm/installer" 18 19 import ( 20 apierrors "k8s.io/apimachinery/pkg/api/errors" 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 "k8s.io/kubernetes/pkg/apis/extensions" 23 "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" 24 coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion" 25 "k8s.io/kubernetes/pkg/kubectl" 26 ) 27 28 const ( 29 deploymentName = "tiller-deploy" 30 serviceName = "tiller-deploy" 31 secretName = "tiller-secret" 32 ) 33 34 // Uninstall uses Kubernetes client to uninstall Tiller. 35 func Uninstall(client internalclientset.Interface, opts *Options) error { 36 if err := deleteService(client.Core(), opts.Namespace); err != nil { 37 return err 38 } 39 if err := deleteDeployment(client, opts.Namespace); err != nil { 40 return err 41 } 42 return deleteSecret(client.Core(), opts.Namespace) 43 } 44 45 // deleteService deletes the Tiller Service resource 46 func deleteService(client coreclient.ServicesGetter, namespace string) error { 47 err := client.Services(namespace).Delete(serviceName, &metav1.DeleteOptions{}) 48 return ingoreNotFound(err) 49 } 50 51 // deleteDeployment deletes the Tiller Deployment resource 52 // We need to use the reaper instead of the kube API because GC for deployment dependents 53 // is not yet supported at the k8s server level (<= 1.5) 54 func deleteDeployment(client internalclientset.Interface, namespace string) error { 55 reaper, _ := kubectl.ReaperFor(extensions.Kind("Deployment"), client) 56 err := reaper.Stop(namespace, deploymentName, 0, nil) 57 return ingoreNotFound(err) 58 } 59 60 // deleteSecret deletes the Tiller Secret resource 61 func deleteSecret(client coreclient.SecretsGetter, namespace string) error { 62 err := client.Secrets(namespace).Delete(secretName, &metav1.DeleteOptions{}) 63 return ingoreNotFound(err) 64 } 65 66 func ingoreNotFound(err error) error { 67 if apierrors.IsNotFound(err) { 68 return nil 69 } 70 return err 71 }