diff --git a/cmd/gotk/uninstall.go b/cmd/gotk/uninstall.go index 4c85f90a..4df40c8f 100644 --- a/cmd/gotk/uninstall.go +++ b/cmd/gotk/uninstall.go @@ -22,6 +22,7 @@ import ( "github.com/manifoldco/promptui" "github.com/spf13/cobra" + "k8s.io/apimachinery/pkg/types" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1" sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" @@ -48,7 +49,7 @@ var ( ) func init() { - uninstallCmd.Flags().BoolVar(&uninstallResources, "resources", false, + uninstallCmd.Flags().BoolVar(&uninstallResources, "resources", true, "removes custom resources such as Kustomizations, GitRepositories and HelmRepositories") uninstallCmd.Flags().BoolVar(&uninstallCRDs, "crds", false, "removes all CRDs previously installed") @@ -64,6 +65,11 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() + kubeClient, err := utils.kubeClient(kubeconfig) + if err != nil { + return err + } + dryRun := "" if uninstallDryRun { dryRun = "--dry-run=client" @@ -77,7 +83,20 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error { } } - if uninstallResources { + // suspend bootstrap kustomization if it exists + kustomizationName := types.NamespacedName{ + Namespace: namespace, + Name: namespace, + } + var kustomization kustomizev1.Kustomization + if err := kubeClient.Get(ctx, kustomizationName, &kustomization); err == nil { + kustomization.Spec.Suspend = true + if err := kubeClient.Update(ctx, &kustomization); err != nil { + return fmt.Errorf("unable to suspend kustomization '%s': %w", kustomizationName.String(), err) + } + } + + if uninstallResources || uninstallCRDs { logger.Actionf("uninstalling custom resources") for _, kind := range []string{ kustomizev1.KustomizationKind, diff --git a/docs/cmd/gotk_uninstall.md b/docs/cmd/gotk_uninstall.md index 35704036..b5f9e0e9 100644 --- a/docs/cmd/gotk_uninstall.md +++ b/docs/cmd/gotk_uninstall.md @@ -27,7 +27,7 @@ gotk uninstall [flags] --crds removes all CRDs previously installed --dry-run only print the object that would be deleted -h, --help help for uninstall - --resources removes custom resources such as Kustomizations, GitRepositories and HelmRepositories + --resources removes custom resources such as Kustomizations, GitRepositories and HelmRepositories (default true) -s, --silent delete components without asking for confirmation ``` diff --git a/docs/guides/installation.md b/docs/guides/installation.md index 5aacc7cc..fc91ecf6 100644 --- a/docs/guides/installation.md +++ b/docs/guides/installation.md @@ -353,7 +353,7 @@ gotk create helmrelease sealed-secrets \ --chart-version="1.10.x" ``` -### Monitoring with Prometheus and Grafana +## Monitoring with Prometheus and Grafana The GitOps Toolkit comes with an optional monitoring stack. You can install the stack in the `gitops-system` namespace with: @@ -379,3 +379,14 @@ If you wish to use your own Prometheus and Grafana instances, then you can impor When using Prometheus Operator you should create `PodMonitor` objects to configure scraping. When Prometheus is running outside of the `gitops-system` namespace, you have to create a network policy that allows traffic on port `8080` from the namespace where Prometheus is deployed. + +## Uninstall + +You can uninstall the toolkit components with: + +```sh +gotk uninstall --crds +``` + +The above command will delete the toolkit custom resources definitions, the controllers +and the namespace where they were installed.