mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-23 16:11:48 +00:00
Display better uninstall prompt if flux is managed by a different tool
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
parent
2f15ad972b
commit
9cd4a7215f
2 changed files with 27 additions and 11 deletions
|
|
@ -91,7 +91,7 @@ func getFluxClusterInfo(ctx context.Context, c client.Client) (fluxClusterInfo,
|
||||||
// promptui.ErrAbort if the user doesn't confirm, or an error encountered.
|
// promptui.ErrAbort if the user doesn't confirm, or an error encountered.
|
||||||
func confirmFluxInstallOverride(info fluxClusterInfo) error {
|
func confirmFluxInstallOverride(info fluxClusterInfo) error {
|
||||||
// no need to display prompt if installation is managed by Flux
|
// no need to display prompt if installation is managed by Flux
|
||||||
if info.managedBy == "" || info.managedBy == "flux" {
|
if installManagedByFlux(info.managedBy) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,3 +104,7 @@ func confirmFluxInstallOverride(info fluxClusterInfo) error {
|
||||||
_, err := prompt.Run()
|
_, err := prompt.Run()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func installManagedByFlux(manager string) bool {
|
||||||
|
return manager == "" || manager == "flux"
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/v2/internal/utils"
|
"github.com/fluxcd/flux2/v2/internal/utils"
|
||||||
"github.com/fluxcd/flux2/v2/pkg/uninstall"
|
"github.com/fluxcd/flux2/v2/pkg/uninstall"
|
||||||
|
|
@ -59,16 +60,6 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
if !uninstallArgs.dryRun && !uninstallArgs.silent {
|
|
||||||
prompt := promptui.Prompt{
|
|
||||||
Label: "Are you sure you want to delete Flux and its custom resource definitions",
|
|
||||||
IsConfirm: true,
|
|
||||||
}
|
|
||||||
if _, err := prompt.Run(); err != nil {
|
|
||||||
return fmt.Errorf("aborting")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
|
@ -77,6 +68,27 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
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: promptLabel,
|
||||||
|
IsConfirm: true,
|
||||||
|
}
|
||||||
|
if _, err := prompt.Run(); err != nil {
|
||||||
|
return fmt.Errorf("aborting")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.Actionf("deleting components in %s namespace", *kubeconfigArgs.Namespace)
|
logger.Actionf("deleting components in %s namespace", *kubeconfigArgs.Namespace)
|
||||||
uninstall.Components(ctx, logger, kubeClient, *kubeconfigArgs.Namespace, uninstallArgs.dryRun)
|
uninstall.Components(ctx, logger, kubeClient, *kubeconfigArgs.Namespace, uninstallArgs.dryRun)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue