diff --git a/cmd/argocd/commands/uninstall.go b/cmd/argocd/commands/uninstall.go index 62d5810c9fff9..e3485cebd8f5c 100644 --- a/cmd/argocd/commands/uninstall.go +++ b/cmd/argocd/commands/uninstall.go @@ -11,8 +11,10 @@ import ( // NewUninstallCommand returns a new instance of `argocd install` command func NewUninstallCommand() *cobra.Command { var ( - clientConfig clientcmd.ClientConfig - installOpts install.InstallOptions + clientConfig clientcmd.ClientConfig + installOpts install.InstallOptions + deleteNamespace bool + deleteCRD bool ) var command = &cobra.Command{ Use: "uninstall", @@ -28,9 +30,11 @@ func NewUninstallCommand() *cobra.Command { } installer, err := install.NewInstaller(conf, installOpts) errors.CheckError(err) - installer.Uninstall() + installer.Uninstall(deleteNamespace, deleteCRD) }, } clientConfig = cli.AddKubectlFlagsToCmd(command) + command.Flags().BoolVar(&deleteNamespace, "delete-namespace", false, "Also delete the namespace during uninstall") + command.Flags().BoolVar(&deleteCRD, "delete-crd", false, "Also delete the Application CRD during uninstall") return command } diff --git a/install/install.go b/install/install.go index 4d93f84b7a275..81be997a055e8 100644 --- a/install/install.go +++ b/install/install.go @@ -96,15 +96,23 @@ func (i *Installer) Install() { i.InstallArgoCDRepoServer() } -func (i *Installer) Uninstall() { +func (i *Installer) Uninstall(deleteNamespace, deleteCRD bool) { manifests := i.box.List() for _, manifestPath := range manifests { if strings.HasSuffix(manifestPath, ".yaml") || strings.HasSuffix(manifestPath, ".yml") { var obj unstructured.Unstructured i.unmarshalManifest(manifestPath, &obj) - if obj.GetKind() == "Namespace" { - // Don't delete namespaces - continue + switch strings.ToLower(obj.GetKind()) { + case "namespace": + if !deleteNamespace { + log.Infof("Skipped deletion of Namespace: '%s'", obj.GetName()) + continue + } + case "customresourcedefinition": + if !deleteCRD { + log.Infof("Skipped deletion of CustomResourceDefinition: '%s'", obj.GetName()) + continue + } } i.MustUninstallResource(&obj) }