Skip to content

Commit

Permalink
controllers: adds fixes for correct sts UpdateRevision updates
Browse files Browse the repository at this point in the history
kubernetes controller manager do not change it for correct value after rolling update
we check and change it manually, it should fix metrics and possible issues with statefulset updates
#554
  • Loading branch information
f41gh7 committed Nov 17, 2022
1 parent 4a7e873 commit 6757af6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions controllers/factory/k8stools/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ func performRollingUpdateOnSts(ctx context.Context, wasRecreated bool, rclient c

if !updatedNeeded {
l.Info("update isn't needed")
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
}

Expand Down Expand Up @@ -218,8 +224,13 @@ func performRollingUpdateOnSts(ctx context.Context, wasRecreated bool, rclient c
time.Sleep(time.Second * 1)
}
// another hack for correct update finish.
if sts.Status.UpdateRevision != sts.Status.CurrentRevision {
sts.Status.CurrentRevision = sts.Status.UpdateRevision
updateRev := sts.Status.UpdateRevision
if err := rclient.Get(ctx, types.NamespacedName{Name: sts.Name, Namespace: sts.Namespace}, sts); err != nil {
return fmt.Errorf("cannot reload sts object for update field check: %w", err)
}
if updateRev != sts.Status.CurrentRevision {
sts.Status.CurrentRevision = updateRev
sts.Status.UpdateRevision = updateRev
if err := rclient.Status().Update(ctx, sts); err != nil {
return fmt.Errorf("cannot update sts current revesion after sts updated finished, err: %w", err)
}
Expand Down

0 comments on commit 6757af6

Please sign in to comment.