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

Function Maintenance

internal/cmd/plugin/maintenance/maintenance.go:38–94  ·  view source on GitHub ↗

Maintenance command implementation

(ctx context.Context,
	allNamespaces, reusePVC, confirmationRequired bool,
	clusterName string,
	setInProgressTo bool,
)

Source from the content-addressed store, hash-verified

36
37// Maintenance command implementation
38func Maintenance(ctx context.Context,
39 allNamespaces, reusePVC, confirmationRequired bool,
40 clusterName string,
41 setInProgressTo bool,
42) error {
43 clusters := tabby.New()
44 clusters.AddLine("The following are the new values for the clusters")
45 clusters.AddHeader(
46 "Namespace",
47 "Cluster Name",
48 "Maintenance",
49 "reusePVC")
50
51 var clusterList apiv1.ClusterList
52 var err error
53 if allNamespaces || clusterName == "" {
54 clusterList, err = getClusters(ctx, allNamespaces)
55 } else {
56 clusterList, err = getCluster(ctx, clusterName)
57 }
58 if err != nil {
59 return err
60 }
61
62 if len(clusterList.Items) == 0 {
63 if clusterName != "" {
64 return fmt.Errorf("cluster '%v' couldn't be found", clusterName)
65 }
66 return fmt.Errorf("no cluster could be listed or no permission to list clusters")
67 }
68
69 for _, item := range clusterList.Items {
70 clusters.AddLine(
71 item.Namespace,
72 item.Name,
73 fmt.Sprintf("%v => %v", item.IsNodeMaintenanceWindowInProgress(), setInProgressTo),
74 fmt.Sprintf("%v => %v", item.IsReusePVCEnabled(), reusePVC),
75 )
76 }
77
78 clusters.Print()
79 if confirmationRequired {
80 proceed := askToProceed()
81 if !proceed {
82 return nil
83 }
84 }
85
86 for _, item := range clusterList.Items {
87 err := patchNodeMaintenanceWindow(ctx, item, setInProgressTo, reusePVC)
88 if err != nil {
89 return fmt.Errorf("unable to set progress to cluster %v in namespace %v: %w", item.Name, item.Namespace, err)
90 }
91 }
92
93 return nil
94}
95

Callers 1

NewCmdFunction · 0.85

Calls 6

getClustersFunction · 0.85
askToProceedFunction · 0.85
IsReusePVCEnabledMethod · 0.80
getClusterFunction · 0.70

Tested by

no test coverage detected