This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
110 lines (92 loc) · 2.16 KB
/
main.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
package main
import (
"io/ioutil"
"log"
"os"
"path"
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
const CommandSBUPrepare = "sbu-prepare"
const CommandFinalClean = "final-clean"
/*
The application expects environment varialbe "KUBECONFIG" to be set, then uninstalls Service Catalog and removes all SC resources.
*/
func main() {
command := CommandFinalClean
if len(os.Args) > 1 {
command = os.Args[1]
}
kubeconfigPath := os.Getenv("KUBECONFIG")
if kubeconfigPath == "" {
home, err := os.UserHomeDir()
if err != nil {
panic(err)
}
kubeconfigPath = path.Join(home, ".kube/config")
}
log.Printf("Using kubeconfig file: %s", kubeconfigPath)
// read the kubeconfig
kcContent, err := ioutil.ReadFile(kubeconfigPath)
if err != nil {
if os.IsNotExist(err) {
// empty kubeconfig content means - use "in cluster config"
log.Println("Kubeconfig does not exists, using in-cluster config")
kcContent = []byte{}
} else {
panic(err)
}
}
cleaner, err := NewCleaner(kcContent)
if err != nil {
panic(err)
}
defer cleaner.printStats()
if command == CommandSBUPrepare {
log.Println("Removing service-catalog-addons release")
err = cleaner.RemoveRelease(ServiceCatalogAddonsReleaseName)
if err != nil {
panic(err)
}
log.Println("Removing finalizers and ownerreferences from SBU")
err = cleaner.PrepareSBUForRemoval()
if err != nil {
panic(err)
}
return
}
if command == CommandFinalClean {
log.Println("Removing Service Catalog release")
err = cleaner.RemoveRelease(ServiceCatalogReleaseName)
if err != nil {
panic(err)
}
log.Println("Removing Helm Broker release")
err = cleaner.RemoveRelease(HelmBrokerReleaseName)
if err != nil {
panic(err)
}
err = cleaner.ensureServiceCatalogNotRunning()
if err != nil {
panic(err)
}
log.Println("Removing finalizers")
err = cleaner.PrepareForRemoval()
if err != nil {
panic(err)
}
log.Println()
log.Println("Deleting resources")
if command == CommandFinalClean {
err = cleaner.RemoveResources()
if err != nil {
panic(err)
}
}
log.Println("Deleting CRDs")
err = cleaner.RemoveCRDs()
if err != nil {
panic(err)
}
return
}
}