Skip to content

Commit 68030f3

Browse files
committed
Small refactoring
1 parent 9897c15 commit 68030f3

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

pkg/cluster/majorversionupgrade.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,16 @@ func (c *Cluster) removeFailuresAnnotation() error {
106106
return nil
107107
}
108108

109-
func (c *Cluster) criticalOperationLabel(pods []v1.Pod, active bool) error {
110-
var action string
111-
var metadataReq map[string]map[string]map[string]*string
112-
113-
if active {
114-
action = "assign"
115-
val := "true"
116-
metadataReq = map[string]map[string]map[string]*string{"metadata": {"labels": {"critical-operation": &val}}}
117-
} else {
118-
action = "remove"
119-
metadataReq = map[string]map[string]map[string]*string{"metadata": {"labels": {"critical-operation": nil}}}
120-
}
109+
func (c *Cluster) criticalOperationLabel(pods []v1.Pod, value *string) error {
110+
metadataReq := map[string]map[string]map[string]*string{"metadata": {"labels": {"critical-operation": value}}}
121111

122112
patchReq, err := json.Marshal(metadataReq)
123113
if err != nil {
124-
return fmt.Errorf("could not marshal ObjectMeta to %s critical operation label: %v", action, err)
114+
return fmt.Errorf("could not marshal ObjectMeta: %v", err)
125115
}
126116
for _, pod := range pods {
127117
_, err = c.KubeClient.Pods(c.Namespace).Patch(context.TODO(), pod.Name, types.StrategicMergePatchType, patchReq, metav1.PatchOptions{})
128118
if err != nil {
129-
c.logger.Errorf("failed to %s critical operation label for pod %s: %v", action, pod.Name, err)
130119
return err
131120
}
132121
}
@@ -252,12 +241,13 @@ func (c *Cluster) majorVersionUpgrade() error {
252241
c.logger.Infof("healthy cluster ready to upgrade, current: %d desired: %d", c.currentMajorVersion, desiredVersion)
253242
if c.currentMajorVersion < desiredVersion {
254243
defer func() error {
255-
if err = c.criticalOperationLabel(pods, false); err != nil {
244+
if err = c.criticalOperationLabel(pods, nil); err != nil {
256245
return fmt.Errorf("failed to remove critical-operation label: %s", err)
257246
}
258247
return nil
259248
}()
260-
if err = c.criticalOperationLabel(pods, true); err != nil {
249+
val := "true"
250+
if err = c.criticalOperationLabel(pods, &val); err != nil {
261251
return fmt.Errorf("failed to assign critical-operation label: %s", err)
262252
}
263253

0 commit comments

Comments
 (0)