@@ -312,20 +312,36 @@ func hasContainerName(containers []corev1.Container, name string) bool {
312312
313313func (r * ReconcilePerconaServerMongoDBRestore ) finishPhysicalRestore (ctx context.Context , cluster * api.PerconaServerMongoDB ) (bool , error ) {
314314 stsIsUpdated := true
315- if err := r .updateMongodSts (ctx , cluster , func (sts * appsv1.StatefulSet ) error {
315+ if err := r .iterateOverMongodSts (ctx , cluster , func (s * appsv1.StatefulSet ) error {
316+ sts := new (appsv1.StatefulSet )
317+ if err := r .client .Get (ctx , client .ObjectKeyFromObject (s ), sts ); err != nil {
318+ return err
319+ }
316320 if ! sts .DeletionTimestamp .IsZero () {
317321 return nil
318322 }
319323
320- if ! hasContainerName (sts .Spec .Template .Spec .Containers , naming .ContainerBackupAgent ) {
321- return errors .Errorf ("statefulsets weren't deleted" )
324+ if sts .Labels [naming .LabelKubernetesComponent ] != naming .ComponentArbiter {
325+ if ! hasContainerName (sts .Spec .Template .Spec .Containers , naming .ContainerBackupAgent ) {
326+ return errors .Errorf ("statefulset %s wasn't deleted" , sts .Name )
327+ }
322328 }
323329
324- if sts .Annotations [psmdbv1 .AnnotationRestoreInProgress ] != "true" {
325- stsIsUpdated = false
326- sts .Annotations [psmdbv1 .AnnotationRestoreInProgress ] = "true"
330+ if sts .Annotations [psmdbv1 .AnnotationRestoreInProgress ] == "true" {
331+ return nil
327332 }
328- return nil
333+
334+ stsIsUpdated = false
335+
336+ return retry .RetryOnConflict (retry .DefaultBackoff , func () error {
337+ if err := r .client .Get (ctx , client .ObjectKeyFromObject (s ), sts ); err != nil {
338+ return err
339+ }
340+
341+ sts .Annotations [psmdbv1 .AnnotationRestoreInProgress ] = "true"
342+
343+ return r .client .Update (ctx , sts )
344+ })
329345 }); client .IgnoreNotFound (err ) != nil {
330346 return false , errors .Wrap (err , "delete restore in progress annotation" )
331347 }
0 commit comments