|
|
|
@ -22,6 +22,7 @@ import (
|
|
|
|
|
|
|
|
|
|
"github.com/manifoldco/promptui"
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
"k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
|
|
|
|
|
|
"github.com/fluxcd/flux2/v2/internal/utils"
|
|
|
|
|
"github.com/fluxcd/flux2/v2/pkg/uninstall"
|
|
|
|
@ -59,9 +60,28 @@ func init() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !uninstallArgs.dryRun && !uninstallArgs.silent {
|
|
|
|
|
info, err := getFluxClusterInfo(ctx, kubeClient)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if !errors.IsNotFound(err) {
|
|
|
|
|
return fmt.Errorf("cluster info unavailable: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
promptLabel := "Are you sure you want to delete Flux and its custom resource definitions"
|
|
|
|
|
if !installManagedByFlux(info.managedBy) {
|
|
|
|
|
promptLabel = fmt.Sprintf("Flux is managed by %s! Are you sure you want to delete Flux and its CRDs using Flux CLI", info.managedBy)
|
|
|
|
|
}
|
|
|
|
|
prompt := promptui.Prompt{
|
|
|
|
|
Label: "Are you sure you want to delete Flux and its custom resource definitions",
|
|
|
|
|
Label: promptLabel,
|
|
|
|
|
IsConfirm: true,
|
|
|
|
|
}
|
|
|
|
|
if _, err := prompt.Run(); err != nil {
|
|
|
|
@ -69,14 +89,6 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.Actionf("deleting components in %s namespace", *kubeconfigArgs.Namespace)
|
|
|
|
|
uninstall.Components(ctx, logger, kubeClient, *kubeconfigArgs.Namespace, uninstallArgs.dryRun)
|
|
|
|
|
|
|
|
|
|