-
Notifications
You must be signed in to change notification settings - Fork 25
/
uninstall.go
65 lines (55 loc) · 2.27 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
package installation
import (
"fmt"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/fluxninja/aperture/v2/cmd/aperturectl/cmd/utils"
"github.com/fluxninja/aperture/v2/operator/api"
_ "github.com/fluxninja/aperture/v2/operator/api/agent/v1alpha1"
_ "github.com/fluxninja/aperture/v2/operator/api/controller/v1alpha1"
)
func init() {
UnInstallCmd.PersistentFlags().StringVar(&kubeConfig, "kube-config", "", "Path to the Kubernetes cluster config. Defaults to '~/.kube/config'")
UnInstallCmd.PersistentFlags().StringVar(&version, "version", apertureLatestVersion, "Version of the Aperture")
UnInstallCmd.PersistentFlags().StringVar(&valuesFile, "values-file", "", "Values YAML file containing parameters to customize the installation")
UnInstallCmd.PersistentFlags().StringVar(&namespace, "namespace", defaultNS, "Namespace from which the component will be uninstalled. Defaults to 'default' namespace")
UnInstallCmd.PersistentFlags().IntVar(&timeout, "timeout", 300, "Timeout of waiting for uninstallation hooks completion")
UnInstallCmd.AddCommand(controllerUnInstallCmd)
UnInstallCmd.AddCommand(agentUnInstallCmd)
UnInstallCmd.AddCommand(istioConfigUnInstallCmd)
}
// UnInstallCmd is the command to uninstall Aperture Controller and Aperture Agent from Kubernetes.
var UnInstallCmd = &cobra.Command{
Use: "uninstall",
Short: "Uninstall Aperture components",
Long: `
Use this command to uninstall Aperture Controller and Agent from your Kubernetes cluster.`,
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var err error
kubeRestConfig, err = utils.GetKubeConfig(kubeConfig)
if err != nil {
return err
}
err = api.SchemeBuilder.AddToScheme(scheme.Scheme)
if err != nil {
return fmt.Errorf("failed to create Kubernetes client: %w", err)
}
kubeClient, err = client.New(kubeRestConfig, client.Options{
Scheme: scheme.Scheme,
})
if err != nil {
return fmt.Errorf("failed to create Kubernetes client: %w", err)
}
latestVersion, err = utils.ResolveLatestVersion()
if err != nil {
return err
}
if version == "" || version == apertureLatestVersion {
version = latestVersion
}
return nil
},
}