forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.go
128 lines (115 loc) · 5.07 KB
/
uninstall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package commands
import (
"fmt"
"github.com/argoproj/argo/pkg/apis/workflow"
"github.com/argoproj/argo/workflow/common"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apierr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func init() {
RootCmd.AddCommand(uninstallCmd)
uninstallCmd.Flags().StringVar(&uninstallArgs.controllerName, "controller-name", common.DefaultControllerDeploymentName, "name of controller deployment")
uninstallCmd.Flags().StringVar(&uninstallArgs.uiName, "ui-name", ArgoUIDeploymentName, "name of ui deployment")
uninstallCmd.Flags().StringVar(&uninstallArgs.configMap, "configmap", common.DefaultConfigMapName(common.DefaultControllerDeploymentName), "name of configmap to uninstall")
uninstallCmd.Flags().StringVar(&uninstallArgs.namespace, "install-namespace", common.DefaultControllerNamespace, "uninstall from a specific namespace")
}
type uninstallFlags struct {
controllerName string // --controller-name
uiName string // --ui-name
configMap string // --configmap
namespace string // --install-namespace
}
var uninstallArgs uninstallFlags
var uninstallCmd = &cobra.Command{
Use: "uninstall",
Short: "uninstall Argo",
Run: uninstall,
}
func uninstall(cmd *cobra.Command, args []string) {
clientset = initKubeClient()
fmt.Printf("Uninstalling from namespace '%s'\n", uninstallArgs.namespace)
// Delete the UI service
svcClient := clientset.CoreV1().Services(uninstallArgs.namespace)
err := svcClient.Delete(ArgoUIServiceName, &metav1.DeleteOptions{})
if err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete service '%s': %v", ArgoUIServiceName, err)
}
fmt.Printf("Service '%s' in namespace '%s' not found\n", ArgoUIServiceName, uninstallArgs.namespace)
} else {
fmt.Printf("Service '%s' deleted\n", ArgoUIServiceName)
}
// Delete the UI and workflow-controller deployment
deploymentsClient := clientset.AppsV1beta2().Deployments(uninstallArgs.namespace)
deletePolicy := metav1.DeletePropagationForeground
for _, depName := range []string{uninstallArgs.uiName, uninstallArgs.controllerName} {
err := deploymentsClient.Delete(depName, &metav1.DeleteOptions{PropagationPolicy: &deletePolicy})
if err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete deployment '%s': %v", depName, err)
}
fmt.Printf("Deployment '%s' in namespace '%s' not found\n", depName, uninstallArgs.namespace)
} else {
fmt.Printf("Deployment '%s' deleted\n", depName)
}
}
// Delete the configmap
cmClient := clientset.CoreV1().ConfigMaps(uninstallArgs.namespace)
err = cmClient.Delete(uninstallArgs.configMap, &metav1.DeleteOptions{})
if err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete ConfigMap '%s': %v", uninstallArgs.configMap, err)
}
fmt.Printf("ConfigMap '%s' in namespace '%s' not found\n", uninstallArgs.configMap, uninstallArgs.namespace)
} else {
fmt.Printf("ConfigMap '%s' deleted\n", uninstallArgs.configMap)
}
// Delete controller and UI role binding
for _, bindingName := range []string{ArgoControllerClusterRoleBinding, ArgoUIClusterRoleBinding} {
if err := clientset.RbacV1().ClusterRoleBindings().Delete(bindingName, &metav1.DeleteOptions{}); err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete ClusterRoleBinding: %v\n", err)
}
fmt.Printf("ClusterRoleBinding '%s' not found\n", bindingName)
} else {
fmt.Printf("ClusterRoleBinding '%s' deleted\n", bindingName)
}
}
// Delete controller and UI the cluster role
for _, roleName := range []string{ArgoControllerClusterRole, ArgoUIClusterRole} {
if err := clientset.RbacV1().ClusterRoles().Delete(roleName, &metav1.DeleteOptions{}); err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete ClusterRole: %v\n", err)
}
fmt.Printf("ClusterRole '%s' not found\n", roleName)
} else {
fmt.Printf("ClusterRole '%s' deleted\n", roleName)
}
}
// Delete controller and UI service account
for _, serviceAccount := range []string{ArgoControllerServiceAccount, ArgoUIServiceAccount} {
if err := clientset.CoreV1().ServiceAccounts(uninstallArgs.namespace).Delete(serviceAccount, &metav1.DeleteOptions{}); err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete ServiceAccount: %v\n", err)
}
fmt.Printf("ServiceAccount '%s' in namespace '%s' not found\n", serviceAccount, uninstallArgs.namespace)
} else {
fmt.Printf("ServiceAccount '%s' deleted\n", serviceAccount)
}
}
// Delete the workflow CRD
apiextensionsclientset := apiextensionsclient.NewForConfigOrDie(restConfig)
crdClient := apiextensionsclientset.Apiextensions().CustomResourceDefinitions()
err = crdClient.Delete(workflow.FullName, nil)
if err != nil {
if !apierr.IsNotFound(err) {
log.Fatalf("Failed to delete CustomResourceDefinition '%s': %v", workflow.FullName, err)
}
fmt.Printf("CustomResourceDefinition '%s' not found\n", workflow.FullName)
} else {
fmt.Printf("CustomResourceDefinition '%s' deleted\n", workflow.FullName)
}
}