mirror of
https://github.com/fluxcd/flux2.git
synced 2025-11-02 10:48:03 +08:00
Delete custom resources during uninstall
Remove Kustomizations, GitRepositories and HelmRepositories before deleting the toolkit controllers and CRDs.
This commit is contained in:
@ -19,10 +19,12 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
|
||||
)
|
||||
|
||||
var uninstallCmd = &cobra.Command{
|
||||
@ -33,24 +35,24 @@ var uninstallCmd = &cobra.Command{
|
||||
tk uninstall --dry-run --namespace=gitops-system
|
||||
|
||||
# Uninstall all components and delete custom resource definitions
|
||||
tk uninstall --crds --namespace=gitops-system
|
||||
tk uninstall --resources --crds --namespace=gitops-system
|
||||
`,
|
||||
RunE: uninstallCmdRun,
|
||||
}
|
||||
|
||||
var (
|
||||
uninstallCRDs bool
|
||||
uninstallKustomizations bool
|
||||
uninstallDryRun bool
|
||||
uninstallSilent bool
|
||||
uninstallCRDs bool
|
||||
uninstallResources bool
|
||||
uninstallDryRun bool
|
||||
uninstallSilent bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
uninstallCmd.Flags().BoolVarP(&uninstallKustomizations, "kustomizations", "", false,
|
||||
"removes all Kustomizations previously installed")
|
||||
uninstallCmd.Flags().BoolVarP(&uninstallCRDs, "crds", "", false,
|
||||
uninstallCmd.Flags().BoolVar(&uninstallResources, "resources", false,
|
||||
"removes custom resources such as Kustomizations, GitRepositories and HelmRepositories")
|
||||
uninstallCmd.Flags().BoolVar(&uninstallCRDs, "crds", false,
|
||||
"removes all CRDs previously installed")
|
||||
uninstallCmd.Flags().BoolVarP(&uninstallDryRun, "dry-run", "", false,
|
||||
uninstallCmd.Flags().BoolVar(&uninstallDryRun, "dry-run", false,
|
||||
"only print the object that would be deleted")
|
||||
uninstallCmd.Flags().BoolVarP(&uninstallSilent, "silent", "s", false,
|
||||
"delete components without asking for confirmation")
|
||||
@ -75,18 +77,19 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if uninstallKustomizations {
|
||||
logger.Actionf("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")
|
||||
if uninstallResources {
|
||||
logger.Actionf("uninstalling custom resources")
|
||||
for _, kind := range []string{
|
||||
kustomizev1.KustomizationKind,
|
||||
sourcev1.GitRepositoryKind,
|
||||
sourcev1.HelmRepositoryKind,
|
||||
} {
|
||||
command := fmt.Sprintf("kubectl -n %s delete %s --all --timeout=%s %s",
|
||||
namespace, kind, 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
|
||||
logger.Waitingf("waiting on GC")
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
|
||||
kinds := "namespace,clusterroles,clusterrolebindings"
|
||||
|
||||
@ -17,18 +17,18 @@ tk uninstall [flags]
|
||||
tk uninstall --dry-run --namespace=gitops-system
|
||||
|
||||
# Uninstall all components and delete custom resource definitions
|
||||
tk uninstall --crds --namespace=gitops-system
|
||||
tk uninstall --resources --crds --namespace=gitops-system
|
||||
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
--crds removes all CRDs previously installed
|
||||
--dry-run only print the object that would be deleted
|
||||
-h, --help help for uninstall
|
||||
--kustomizations removes all Kustomizations previously installed
|
||||
-s, --silent delete components without asking for confirmation
|
||||
--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
|
||||
-s, --silent delete components without asking for confirmation
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
Reference in New Issue
Block a user