@@ -106,27 +106,16 @@ func (c *Cluster) removeFailuresAnnotation() error {
106
106
return nil
107
107
}
108
108
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 }}}
121
111
122
112
patchReq , err := json .Marshal (metadataReq )
123
113
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 )
125
115
}
126
116
for _ , pod := range pods {
127
117
_ , err = c .KubeClient .Pods (c .Namespace ).Patch (context .TODO (), pod .Name , types .StrategicMergePatchType , patchReq , metav1.PatchOptions {})
128
118
if err != nil {
129
- c .logger .Errorf ("failed to %s critical operation label for pod %s: %v" , action , pod .Name , err )
130
119
return err
131
120
}
132
121
}
@@ -252,12 +241,13 @@ func (c *Cluster) majorVersionUpgrade() error {
252
241
c .logger .Infof ("healthy cluster ready to upgrade, current: %d desired: %d" , c .currentMajorVersion , desiredVersion )
253
242
if c .currentMajorVersion < desiredVersion {
254
243
defer func () error {
255
- if err = c .criticalOperationLabel (pods , false ); err != nil {
244
+ if err = c .criticalOperationLabel (pods , nil ); err != nil {
256
245
return fmt .Errorf ("failed to remove critical-operation label: %s" , err )
257
246
}
258
247
return nil
259
248
}()
260
- if err = c .criticalOperationLabel (pods , true ); err != nil {
249
+ val := "true"
250
+ if err = c .criticalOperationLabel (pods , & val ); err != nil {
261
251
return fmt .Errorf ("failed to assign critical-operation label: %s" , err )
262
252
}
263
253
0 commit comments