From 727734850e0900905f624cbbcfc6e6532a487222 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Wed, 10 Jun 2020 18:49:38 +0300 Subject: [PATCH] Add kustomizations removal to uninstall cmd --- cmd/tk/uninstall.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/tk/uninstall.go b/cmd/tk/uninstall.go index b01cbb2e..9fb9d236 100644 --- a/cmd/tk/uninstall.go +++ b/cmd/tk/uninstall.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "time" "github.com/manifoldco/promptui" "github.com/spf13/cobra" @@ -24,12 +25,15 @@ cluster role bindings and CRDs.`, } var ( - uninstallCRDs bool - uninstallDryRun bool - uninstallSilent bool + uninstallCRDs bool + uninstallKustomizations bool + uninstallDryRun bool + uninstallSilent bool ) func init() { + uninstallCmd.Flags().BoolVarP(&uninstallKustomizations, "kustomizations", "", false, + "removes all kustomizations previously installed") uninstallCmd.Flags().BoolVarP(&uninstallCRDs, "crds", "", false, "removes all CRDs previously installed") uninstallCmd.Flags().BoolVarP(&uninstallDryRun, "dry-run", "", false, @@ -57,6 +61,20 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error { } } + if uninstallKustomizations { + logAction("uninstalling kustomizations") + command := fmt.Sprintf("kubectl -n %s delete kustomizations --all --timeout=%s %s", + namespace, timeout.String(), dryRun) + if _, err := utils.execCommand(ctx, ModeOS, command); err != nil { + return fmt.Errorf("uninstall failed") + } + + // TODO: use the kustomizations snapshots to create a list of objects + // that are subject to deletion and wait for all of them to be terminated + logWaiting("waiting on GC") + time.Sleep(30 * time.Second) + } + kinds := "namespace,clusterroles,clusterrolebindings" if uninstallCRDs { kinds += ",crds"