@@ -312,20 +312,36 @@ func hasContainerName(containers []corev1.Container, name string) bool {
312
312
313
313
func (r * ReconcilePerconaServerMongoDBRestore ) finishPhysicalRestore (ctx context.Context , cluster * api.PerconaServerMongoDB ) (bool , error ) {
314
314
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
+ }
316
320
if ! sts .DeletionTimestamp .IsZero () {
317
321
return nil
318
322
}
319
323
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
+ }
322
328
}
323
329
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
327
332
}
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
+ })
329
345
}); client .IgnoreNotFound (err ) != nil {
330
346
return false , errors .Wrap (err , "delete restore in progress annotation" )
331
347
}
0 commit comments