MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / NewCmd

Function NewCmd

internal/cmd/plugin/maintenance/cmd.go:31–92  ·  view source on GitHub ↗

NewCmd creates the new 'maintenance' command

()

Source from the content-addressed store, hash-verified

29
30// NewCmd creates the new 'maintenance' command
31func NewCmd() *cobra.Command {
32 var allNamespaces,
33 reusePVC,
34 confirmationRequired bool
35
36 maintenanceCmd := &cobra.Command{
37 Use: "maintenance [set/unset]",
38 Short: "Sets or removes maintenance mode from clusters",
39 GroupID: plugin.GroupIDCluster,
40 }
41
42 maintenanceCmd.AddCommand(&cobra.Command{
43 Use: "set CLUSTER",
44 Short: "Sets maintenance mode",
45 Long: "This command will set maintenance mode on a single cluster or on all clusters " +
46 "in the current namespace if not specified differently through flags",
47 Args: cobra.MaximumNArgs(1),
48 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
49 return plugin.CompleteClusters(cmd.Context(), args, toComplete), cobra.ShellCompDirectiveNoFileComp
50 },
51 RunE: func(cmd *cobra.Command, args []string) error {
52 var clusterName string
53 if len(args) > 0 {
54 if allNamespaces {
55 return fmt.Errorf("can not specify --all-namespaces and a cluster: %s", args[0])
56 }
57 clusterName = args[0]
58 }
59 return Maintenance(cmd.Context(), allNamespaces, reusePVC, confirmationRequired, clusterName, true)
60 },
61 })
62
63 maintenanceCmd.AddCommand(&cobra.Command{
64 Use: "unset CLUSTER",
65 Short: "Removes maintenance mode",
66 Long: "This command will unset maintenance mode on a single cluster or on all clusters " +
67 "in the current namespace if not specified differently through flags",
68 Args: cobra.MaximumNArgs(1),
69 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
70 return plugin.CompleteClusters(cmd.Context(), args, toComplete), cobra.ShellCompDirectiveNoFileComp
71 },
72 RunE: func(cmd *cobra.Command, args []string) error {
73 var clusterName string
74 if len(args) > 0 {
75 if allNamespaces {
76 return fmt.Errorf("can not specify --all-namespaces and a cluster: %s", args[0])
77 }
78 clusterName = args[0]
79 }
80 return Maintenance(cmd.Context(), allNamespaces, reusePVC, confirmationRequired, clusterName, false)
81 },
82 })
83
84 maintenanceCmd.PersistentFlags().BoolVarP(&allNamespaces,
85 "all-namespaces", "A", false, "Apply operation to all clusters in all namespaces")
86 maintenanceCmd.PersistentFlags().BoolVar(&reusePVC,
87 "reusePVC", false, "Optional flag to set 'reusePVC' to true")
88 maintenanceCmd.PersistentFlags().BoolVarP(&confirmationRequired,

Callers 1

mainFunction · 0.92

Calls 2

CompleteClustersFunction · 0.92
MaintenanceFunction · 0.85

Tested by

no test coverage detected