@@ -270,24 +270,27 @@ func (s *StatefulSetSyncer) createOrUpdate(ctx context.Context) (controllerutil.
270270 }
271271 }
272272 // Deep copy the old statefulset from StatefulSetSyncer.
273- existing := s .sfs .DeepCopyObject ()
273+ existing := s .sfs .DeepCopy ()
274274 // Sync data from mysqlcluster.spec to statefulset.
275275 if err = s .mutate (); err != nil {
276276 return controllerutil .OperationResultNone , err
277277 }
278278 // Check if statefulset changed.
279- if equality . Semantic . DeepEqual (existing , s . sfs ) {
279+ if ! s . sfsUpdated (existing ) {
280280 return controllerutil .OperationResultNone , nil
281281 }
282- s .log .Info ("update statefulset" , "name" , s .Name , "diff" , deep .Equal (existing , s .sfs ))
283282
284283 // If changed, update statefulset.
285284 if err := s .cli .Update (ctx , s .sfs ); err != nil {
286285 return controllerutil .OperationResultNone , err
287286 }
288- // Update every pods of statefulset.
289- if err := s .updatePod (ctx ); err != nil {
290- return controllerutil .OperationResultNone , err
287+ // Need roll update.
288+ if ! equality .Semantic .DeepEqual (existing .Spec .Template , s .sfs .Spec .Template ) {
289+ s .log .Info ("update statefulset pods" , "name" , s .Name , "diff" , deep .Equal (existing .Spec .Template , s .sfs .Spec .Template ))
290+ // Update every pods of statefulset.
291+ if err := s .updatePod (ctx ); err != nil {
292+ return controllerutil .OperationResultNone , err
293+ }
291294 }
292295 // Update pvc.
293296 if err := s .updatePVC (ctx ); err != nil {
@@ -579,3 +582,10 @@ func (s *StatefulSetSyncer) backupIsRunning(ctx context.Context) (bool, error) {
579582 }
580583 return false , nil
581584}
585+
586+ // Updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden.
587+ func (s * StatefulSetSyncer ) sfsUpdated (existing * appsv1.StatefulSet ) bool {
588+ return existing .Spec .Replicas != s .sfs .Spec .Replicas ||
589+ ! equality .Semantic .DeepEqual (existing .Spec .Template , s .sfs .Spec .Template ) ||
590+ existing .Spec .UpdateStrategy != s .sfs .Spec .UpdateStrategy
591+ }
0 commit comments