|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/codefresh-io/venona/venonactl/pkg/store" |
| 5 | + |
| 6 | + "github.com/codefresh-io/venona/venonactl/pkg/plugins" |
| 7 | + "github.com/spf13/cobra" |
| 8 | + "github.com/spf13/viper" |
| 9 | +) |
| 10 | + |
| 11 | +var uninstallAppProxyCmdOptions struct { |
| 12 | + kube struct { |
| 13 | + context string |
| 14 | + namespace string |
| 15 | + } |
| 16 | + templateValues []string |
| 17 | + templateFileValues []string |
| 18 | + templateValueFiles []string |
| 19 | +} |
| 20 | + |
| 21 | +var uninstallAppProxytCmd = &cobra.Command{ |
| 22 | + Use: "app-proxy", |
| 23 | + Short: "Uninstall Codefresh's App-Proxy component", |
| 24 | + Run: func(cmd *cobra.Command, args []string) { |
| 25 | + |
| 26 | + // get valuesMap from --values <values.yaml> --set-value k=v --set-file k=<context-of file> |
| 27 | + templateValuesMap, err := templateValuesToMap( |
| 28 | + uninstallAppProxyCmdOptions.templateValueFiles, |
| 29 | + uninstallAppProxyCmdOptions.templateValues, |
| 30 | + uninstallAppProxyCmdOptions.templateFileValues) |
| 31 | + if err != nil { |
| 32 | + dieOnError(err) |
| 33 | + } |
| 34 | + // Merge cmd options with template |
| 35 | + mergeValueStr(templateValuesMap, "ConfigPath", &kubeConfigPath) |
| 36 | + mergeValueStr(templateValuesMap, "CodefreshHost", &cfAPIHost) |
| 37 | + mergeValueStr(templateValuesMap, "Namespace", &uninstallAppProxyCmdOptions.kube.namespace) |
| 38 | + mergeValueStr(templateValuesMap, "Context", &uninstallAppProxyCmdOptions.kube.context) |
| 39 | + |
| 40 | + s := store.GetStore() |
| 41 | + lgr := createLogger("UninstallAppProxy", verbose, logFormatter) |
| 42 | + buildBasicStore(lgr) |
| 43 | + extendStoreWithKubeClient(lgr) |
| 44 | + fillKubernetesAPI(lgr, uninstallAppProxyCmdOptions.kube.context, uninstallAppProxyCmdOptions.kube.namespace, false) |
| 45 | + |
| 46 | + builder := plugins.NewBuilder(lgr) |
| 47 | + |
| 48 | + if cfAPIHost == "" { |
| 49 | + cfAPIHost = "https://g.codefresh.io" |
| 50 | + } |
| 51 | + s.CodefreshAPI = &store.CodefreshAPI{ |
| 52 | + Host: cfAPIHost, |
| 53 | + } |
| 54 | + s.AgentAPI = &store.AgentAPI{ |
| 55 | + Token: "", |
| 56 | + Id: "", |
| 57 | + } |
| 58 | + |
| 59 | + deleteOptions := &plugins.DeleteOptions{} |
| 60 | + deleteOptions.KubeBuilder = getKubeClientBuilder( |
| 61 | + uninstallAppProxyCmdOptions.kube.context, |
| 62 | + uninstallAppProxyCmdOptions.kube.namespace, |
| 63 | + kubeConfigPath, |
| 64 | + false) |
| 65 | + |
| 66 | + builder.Add(plugins.AppProxyPluginType) |
| 67 | + deleteOptions.ClusterNamespace = uninstallAppProxyCmdOptions.kube.namespace |
| 68 | + values := s.BuildValues() |
| 69 | + values = mergeMaps(values, templateValuesMap) |
| 70 | + for _, p := range builder.Get() { |
| 71 | + err := p.Delete(deleteOptions, values) |
| 72 | + if err != nil { |
| 73 | + dieOnError(err) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + lgr.Info("Deletion of app-proxy is completed") |
| 78 | + }, |
| 79 | +} |
| 80 | + |
| 81 | +func init() { |
| 82 | + uninstallCommand.AddCommand(uninstallAppProxytCmd) |
| 83 | + viper.BindEnv("kube-namespace", "KUBE_NAMESPACE") |
| 84 | + viper.BindEnv("kube-context", "KUBE_CONTEXT") |
| 85 | + uninstallAppProxytCmd.Flags().StringVar(&uninstallAppProxyCmdOptions.kube.namespace, "kube-namespace", viper.GetString("kube-namespace"), "Name of the namespace from which the app-proxy should be uninstalled [$KUBE_NAMESPACE]") |
| 86 | + uninstallAppProxytCmd.Flags().StringVar(&uninstallAppProxyCmdOptions.kube.context, "kube-context-name", viper.GetString("kube-context"), "Name of the kubernetes context from which the app-proxy should be uninstalled (default is current-context) [$KUBE_CONTEXT]") |
| 87 | + uninstallAppProxytCmd.Flags().StringArrayVar(&uninstallAppProxyCmdOptions.templateValues, "set-value", []string{}, "Set values for templates --set-value agentId=12345") |
| 88 | + uninstallAppProxytCmd.Flags().StringArrayVar(&uninstallAppProxyCmdOptions.templateFileValues, "set-file", []string{}, "Set values for templates from file") |
| 89 | + uninstallAppProxytCmd.Flags().StringArrayVarP(&uninstallAppProxyCmdOptions.templateValueFiles, "values", "f", []string{}, "Specify values in a YAML file") |
| 90 | + |
| 91 | +} |
0 commit comments