-
Notifications
You must be signed in to change notification settings - Fork 36
/
operator_uninstall.go
52 lines (44 loc) · 2.59 KB
/
operator_uninstall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
internalaction "github.com/operator-framework/kubectl-operator/internal/pkg/action"
"github.com/operator-framework/kubectl-operator/pkg/action"
)
func newOperatorUninstallCmd(cfg *action.Configuration) *cobra.Command {
u := internalaction.NewOperatorUninstall(cfg)
u.Logf = log.Printf
cmd := &cobra.Command{
Use: "uninstall <operator>",
Short: "Uninstall an operator and operands",
Long: `Uninstall removes the subscription, operator and optionally operands managed by the operator as well as the
relevant operatorgroup.
This command first finds and deletes the subscription associated with the operator. It then
lists all operands found throughout the cluster for the operator
specified on the command line if one is found. Since the scope of an operator is restricted by
its operator group, the this search will include namespace-scoped operands from the
operator group's target namespaces and all cluster-scoped operands.
The operand-deletion strategy is then considered if any operands are found on-cluster. One of cancel|ignore|delete.
By default, the strategy is "cancel", which means that if any operands are found when deleting the operator abort the uninstall.
The "ignore" strategy keeps the operands on cluster and only deletes the operator itself.
The "delete" strategy deletes both the operands, and after they have finished finalizing, the operator itself.
Setting delete-operator-groups to true will delete the operatorgroup in the provided namespace if no other active subscriptions
are currently in that namespace. The operatorgroup will be removed even if the operator is not found.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
u.Package = args[0]
if err := u.Run(cmd.Context()); err != nil {
log.Fatalf("uninstall operator: %v", err)
}
log.Printf("operator %q uninstalled", u.Package)
},
}
bindOperatorUninstallFlags(cmd.Flags(), u)
return cmd
}
func bindOperatorUninstallFlags(fs *pflag.FlagSet, u *internalaction.OperatorUninstall) {
fs.BoolVar(&u.DeleteOperatorGroups, "delete-operator-groups", false, "delete operator groups if no other operators remain")
fs.StringSliceVar(&u.DeleteOperatorGroupNames, "delete-operator-group-names", nil, "specific operator group names to delete (only effective with --delete-operator-groups)")
fs.VarP(&u.OperandStrategy, "operand-strategy", "os", "determines how to handle operands when deleting the operator, one of cancel|ignore|delete (default cancel)")
}