-
Notifications
You must be signed in to change notification settings - Fork 197
/
cleanup.go
43 lines (40 loc) · 1.32 KB
/
cleanup.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
package cmd
import (
"context"
"github.com/aquasecurity/starboard/pkg/starboard"
"github.com/spf13/cobra"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func NewCleanupCmd(buildInfo starboard.BuildInfo, cf *genericclioptions.ConfigFlags) *cobra.Command {
cmd := &cobra.Command{
Use: "uninstall",
Aliases: []string{"cleanup"},
Short: "Delete Kubernetes resources created by Starboard",
RunE: func(cmd *cobra.Command, args []string) error {
kubeConfig, err := cf.ToRESTConfig()
if err != nil {
return err
}
kubeClientset, err := kubernetes.NewForConfig(kubeConfig)
if err != nil {
return err
}
apiExtensionsClientset, err := apiextensionsv1.NewForConfig(kubeConfig)
if err != nil {
return err
}
scheme := starboard.NewScheme()
kubeClient, err := client.New(kubeConfig, client.Options{Scheme: scheme})
if err != nil {
return err
}
configManager := starboard.NewConfigManager(kubeClientset, starboard.NamespaceName)
installer := NewInstaller(buildInfo, kubeClientset, apiExtensionsClientset, kubeClient, configManager)
return installer.Uninstall(context.Background())
},
}
return cmd
}