forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathistio_teardown.go
53 lines (47 loc) · 1.58 KB
/
istio_teardown.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
package testutils
import (
"strings"
. "github.com/onsi/gomega"
"github.com/solo-io/go-utils/kubeutils"
apiexts "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
func TeardownWithPrefix(kube kubernetes.Interface, prefix string) {
clusterroles, err := kube.RbacV1beta1().ClusterRoles().List(metav1.ListOptions{})
if err == nil {
for _, cr := range clusterroles.Items {
if strings.Contains(cr.Name, prefix) {
kube.RbacV1beta1().ClusterRoles().Delete(cr.Name, nil)
}
}
}
clusterrolebindings, err := kube.RbacV1beta1().ClusterRoleBindings().List(metav1.ListOptions{})
if err == nil {
for _, cr := range clusterrolebindings.Items {
if strings.Contains(cr.Name, prefix) {
kube.RbacV1beta1().ClusterRoleBindings().Delete(cr.Name, nil)
}
}
}
webhooks, err := kube.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().List(metav1.ListOptions{})
if err == nil {
for _, wh := range webhooks.Items {
if strings.Contains(wh.Name, prefix) {
kube.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Delete(wh.Name, nil)
}
}
}
cfg, err := kubeutils.GetConfig("", "")
Expect(err).NotTo(HaveOccurred())
exts, err := apiexts.NewForConfig(cfg)
Expect(err).NotTo(HaveOccurred())
crds, err := exts.ApiextensionsV1beta1().CustomResourceDefinitions().List(metav1.ListOptions{})
if err == nil {
for _, cr := range crds.Items {
if strings.Contains(cr.Name, prefix) {
exts.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(cr.Name, nil)
}
}
}
}