Skip to content

Commit c8063eb

Browse files
hughcapetFxKu
andauthored
Protect Pods from disruptions during upgrades (zalando#2844)
Co-authored-by: Felix Kunde <[email protected]>
1 parent a56ecaa commit c8063eb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: pkg/cluster/majorversionupgrade.go

+27
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ func (c *Cluster) removeFailuresAnnotation() error {
106106
return nil
107107
}
108108

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}}}
111+
112+
patchReq, err := json.Marshal(metadataReq)
113+
if err != nil {
114+
return fmt.Errorf("could not marshal ObjectMeta: %v", err)
115+
}
116+
for _, pod := range pods {
117+
_, err = c.KubeClient.Pods(c.Namespace).Patch(context.TODO(), pod.Name, types.StrategicMergePatchType, patchReq, metav1.PatchOptions{})
118+
if err != nil {
119+
return err
120+
}
121+
}
122+
return nil
123+
}
124+
109125
/*
110126
Execute upgrade when mode is set to manual or full or when the owning team is allowed for upgrade (and mode is "off").
111127
@@ -224,6 +240,17 @@ func (c *Cluster) majorVersionUpgrade() error {
224240
if allRunning && masterPod != nil {
225241
c.logger.Infof("healthy cluster ready to upgrade, current: %d desired: %d", c.currentMajorVersion, desiredVersion)
226242
if c.currentMajorVersion < desiredVersion {
243+
defer func() error {
244+
if err = c.criticalOperationLabel(pods, nil); err != nil {
245+
return fmt.Errorf("failed to remove critical-operation label: %s", err)
246+
}
247+
return nil
248+
}()
249+
val := "true"
250+
if err = c.criticalOperationLabel(pods, &val); err != nil {
251+
return fmt.Errorf("failed to assign critical-operation label: %s", err)
252+
}
253+
227254
podName := &spec.NamespacedName{Namespace: masterPod.Namespace, Name: masterPod.Name}
228255
c.logger.Infof("triggering major version upgrade on pod %s of %d pods", masterPod.Name, numberOfPods)
229256
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Major Version Upgrade", "starting major version upgrade on pod %s of %d pods", masterPod.Name, numberOfPods)

0 commit comments

Comments
 (0)