From fc4abe6da99d73145130624745b46dafe4314b6e Mon Sep 17 00:00:00 2001 From: f41gh7 Date: Fri, 11 Nov 2022 14:28:49 +0100 Subject: [PATCH] controllers: correctly set CurrentRevision for Statefulset it must fix an issue https://github.com/VictoriaMetrics/operator/issues/547 --- controllers/factory/k8stools/sts.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/controllers/factory/k8stools/sts.go b/controllers/factory/k8stools/sts.go index 133f7735..cdd0b536 100644 --- a/controllers/factory/k8stools/sts.go +++ b/controllers/factory/k8stools/sts.go @@ -191,6 +191,8 @@ func performRollingUpdateOnSts(ctx context.Context, wasRecreated bool, rclient c // we check first pod revision label after re-creation // it must contain valid statefulset revision // See more at https://github.com/VictoriaMetrics/operator/issues/344 + // It's needed for correct update restore process, when it was interrupted for some reason + // we have to check Current and Update revisions. updatedPodRev := pod.Labels[podRevisionLabel] var newRev string // cases: @@ -215,6 +217,13 @@ func performRollingUpdateOnSts(ctx context.Context, wasRecreated bool, rclient c l.Info("pod was updated", "pod", pod.Name) time.Sleep(time.Second * 1) } + // another hack for correct update finish. + if sts.Status.UpdateRevision != sts.Status.CurrentRevision { + sts.Status.CurrentRevision = sts.Status.UpdateRevision + if err := rclient.Status().Update(ctx, sts); err != nil { + return fmt.Errorf("cannot update sts current revesion after sts updated finished, err: %w", err) + } + } return nil