Skip to content

Commit 55b52e1

Browse files
fix: rolling update process (#422)
Signed-off-by: Ihor Hrytskiv <[email protected]>
1 parent e598316 commit 55b52e1

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

internal/controller/dragonfly_controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (r *DragonflyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
8686
return ctrl.Result{}, fmt.Errorf("failed to get statefulset: %w", err)
8787
}
8888

89-
if result, err := dfi.allPodsHealthy(ctx, statefulSet.Status.UpdateRevision); !result.IsZero() || err != nil {
89+
if result, err := dfi.allPodsHealthyAndHaveRole(ctx, statefulSet.Status.UpdateRevision); !result.IsZero() || err != nil {
9090
return result, err
9191
}
9292

@@ -95,6 +95,11 @@ func (r *DragonflyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
9595
return ctrl.Result{}, fmt.Errorf("failed to get replicas: %w", err)
9696
}
9797

98+
if len(replicas.Items) != int(dfi.df.Spec.Replicas)-1 {
99+
dfi.log.Info("waiting for all replicas to be configured", "expected", int(dfi.df.Spec.Replicas)-1, "current", len(replicas.Items))
100+
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
101+
}
102+
98103
// We want to update the replicas first then the master
99104
// We want to have at most one updated replica in full sync phase at a time
100105
// if not, requeue
@@ -104,7 +109,7 @@ func (r *DragonflyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
104109

105110
// if we are here it means that all latest replicas are in stable sync
106111
// delete older version replicas
107-
if result, err := dfi.updatedReplicas(ctx, replicas, statefulSet.Status.UpdateRevision); !result.IsZero() || err != nil {
112+
if result, err := dfi.updateReplicas(ctx, replicas, statefulSet.Status.UpdateRevision); !result.IsZero() || err != nil {
108113
return result, err
109114
}
110115

internal/controller/dragonfly_instance.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,8 @@ func (dfi *DragonflyInstance) deleteRoleLabel(ctx context.Context, pod *corev1.P
748748
return nil
749749
}
750750

751-
// allPodsHealthy checks whether all pods are healthy, and deletes pods that are outdated and failed to start
752-
func (dfi *DragonflyInstance) allPodsHealthy(ctx context.Context, updateRevision string) (ctrl.Result, error) {
751+
// allPodsHealthyAndHaveRole checks whether all pods are healthy, and deletes pods that are outdated and failed to start
752+
func (dfi *DragonflyInstance) allPodsHealthyAndHaveRole(ctx context.Context, updateRevision string) (ctrl.Result, error) {
753753
pods, err := dfi.getPods(ctx)
754754
if err != nil {
755755
return ctrl.Result{}, fmt.Errorf("failed to get dragonfly pods: %w", err)
@@ -773,6 +773,11 @@ func (dfi *DragonflyInstance) allPodsHealthy(ctx context.Context, updateRevision
773773
dfi.log.Info("waiting for pod to finish startup", "pod", pod.Name)
774774
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
775775
}
776+
777+
if !roleExists(&pod) {
778+
dfi.log.Info("waiting for pod to be assigned a role", "pod", pod.Name)
779+
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
780+
}
776781
}
777782

778783
return ctrl.Result{}, nil
@@ -801,8 +806,12 @@ func (dfi *DragonflyInstance) verifyUpdatedReplicas(ctx context.Context, replica
801806
return ctrl.Result{}, nil
802807
}
803808

804-
// updatedReplicas updates the replicas to the latest version
805-
func (dfi *DragonflyInstance) updatedReplicas(ctx context.Context, replicas *corev1.PodList, updateRevision string) (ctrl.Result, error) {
809+
// updateReplicas updates the replicas to the latest version
810+
func (dfi *DragonflyInstance) updateReplicas(ctx context.Context, replicas *corev1.PodList, updateRevision string) (ctrl.Result, error) {
811+
_, err := dfi.getMaster(ctx)
812+
if err != nil {
813+
return ctrl.Result{}, fmt.Errorf("failed to get master before deleting replica: %w", err)
814+
}
806815
for _, replica := range replicas.Items {
807816
if !isPodOnLatestVersion(&replica, updateRevision) {
808817
dfi.log.Info("deleting replica", "pod", replica.Name)

0 commit comments

Comments
 (0)