@@ -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