Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var FinalizeCmd = &cobra.Command{ Use: "finalize [type1[,type2,...]] [name1,name2 [name3 ...]]", Aliases: []string{"fin", "f"}, Args: cobra.ArbitraryArgs, GroupID: cmdgroups.ClusterInteraction, Short: "Remove finalizers from k8s resources", Long: `This command can remove all or only specific finalizers from specific or all resources. Examples: > kpu finalize secret foo -n bar Removes all finalizers from the secret 'foo' in the namespace 'bar'. > kpu finalize --all -n bar Removes all finalizers from all resources in the namespace 'bar'. > kpu finalize -f foo.bar.baz/foobar --all -A Removes the finalizer 'foo.bar.baz/foobar' from all resources in all namespaces. Note that this affects only namespace-scoped resources due to the default value 'namespaced' for --scope. > kpu finalize secret,configmap foo bar -f foo.bar.baz/foobar -f foo.bar.baz/asdf Removes the finalizers 'foo.bar.baz/foobar' and 'foo.bar.baz/asdf' from the secrets and configmaps named 'foo' and 'bar' in the default namespace. `, Run: func(cmd *cobra.Command, args []string) { ValidateFinalizeCommand(args) k, err := utils.LoadKubeconfig(k8sOptions.KubeconfigPath) if err != nil { utils.Fatal(1, "error loading kubeconfig: %s", err.Error()) } var resourceTypes []string if len(args) > 0 { resourceTypes = strings.Split(args[0], ",") } var resourceNames []string if len(args) > 1 { resourceNames = []string{} for _, arg := range args[1:] { resourceNames = append(resourceNames, strings.Split(arg, ",")...) } resourceNames = slices.DeleteFunc(resourceNames, func(s string) bool { return s == "" }) } affectedResources, errs := k.ListResources(cmd.Context(), resourceTypes, resourceNames, scope, k8sOptions) if !suppressWarnings { for _, e := range errs { fmt.Fprintf(os.Stderr, "warning: %s\n", e.Error()) } } if len(affectedResources) == 0 { fmt.Println("No resources would be affected by this command.") os.Exit(0) } if !autoConfirmation { p := strings.Builder{} p.WriteString("This will remove all ") if len(finalizers) > 0 { p.WriteString(utils.NaturalLanguageJoin(finalizers, ", ", true)) p.WriteString(" ") } p.WriteString("finalizers from the following ") if len(affectedResources) == 1 { p.WriteString("resource:\n") } else { fmt.Fprint(&p, len(affectedResources)) p.WriteString(" resources:\n") } for _, obj := range affectedResources { p.WriteString(utils.GVKToString(obj.GroupVersionKind())) p.WriteString("\t") ns := obj.GetNamespace() if ns != "" { p.WriteString(ns) p.WriteString("/") } p.WriteString(obj.GetName()) p.WriteString("\n") } p.WriteString("Do you want to continue?") if !utils.PromptForConfirmation(p.String(), false) { fmt.Println("Command aborted.") os.Exit(0) } } errOccurred := false for _, obj := range affectedResources { changed, err := k.RemoveFinalizers(cmd.Context(), &obj, finalizers...) if err != nil { fmt.Printf("error patching %s: %s\n", utils.ResourceIdentifier(&obj), err.Error()) errOccurred = true } else { if changed { fmt.Printf("%s patched\n", utils.ResourceIdentifier(&obj)) } else { fmt.Printf("%s unchanged\n", utils.ResourceIdentifier(&obj)) } } } if errOccurred { os.Exit(1) } }, }
FinalizeCmd represents the finalize command
Functions ¶
func ValidateFinalizeCommand ¶
func ValidateFinalizeCommand(args []string)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.