@@ -125,12 +125,6 @@ func (r *MariaDBReconciler) reconcilePhysicalBackupInit(ctx context.Context, mar
125125 ); ! result .IsZero () || err != nil {
126126 return result , err
127127 }
128- if err := r .cleanupInitJobs (ctx , mariadb ); err != nil {
129- return ctrl.Result {}, err
130- }
131- if err := r .cleanupPhysicalBackupStagingPVC (ctx , mariadb ); err != nil {
132- return ctrl.Result {}, err
133- }
134128 } else {
135129 logger .Info ("Provisioning StatefulSet" , "replicas" , mariadb .Spec .Replicas )
136130 if err := r .upscaleStatefulSet (ctx , mariadb , mariadb .Spec .Replicas ); err != nil {
@@ -142,6 +136,15 @@ func (r *MariaDBReconciler) reconcilePhysicalBackupInit(ctx context.Context, mar
142136 return ctrl.Result {}, fmt .Errorf ("error ensuring replication configured: %v" , err )
143137 }
144138
139+ if bootstrapFrom .VolumeSnapshotRef == nil {
140+ if err := r .cleanupInitJobs (ctx , mariadb ); err != nil {
141+ return ctrl.Result {}, err
142+ }
143+ if err := r .cleanupPhysicalBackupStagingPVC (ctx , mariadb ); err != nil {
144+ return ctrl.Result {}, err
145+ }
146+ }
147+
145148 if err := r .patchStatus (ctx , mariadb , func (status * mariadbv1alpha1.MariaDBStatus ) error {
146149 condition .SetInitialized (status )
147150 condition .SetRestoredPhysicalBackup (status )
@@ -327,6 +330,18 @@ func (r *MariaDBReconciler) reconcileRollingInitJobs(ctx context.Context, mariad
327330
328331func (r * MariaDBReconciler ) reconcileAndWaitForInitJob (ctx context.Context , mariadb * mariadbv1alpha1.MariaDB ,
329332 key types.NamespacedName , podIndex int , logger logr.Logger , restoreOpts ... builder.RestoreOpt ) (ctrl.Result , error ) {
333+ pod , err := r .getPodIfExists (ctx , types.NamespacedName {
334+ Name : stsobj .PodName (mariadb .ObjectMeta , podIndex ),
335+ Namespace : mariadb .Namespace ,
336+ })
337+ if err != nil {
338+ return ctrl.Result {}, err
339+ }
340+ if pod != nil && pod .Status .Phase == corev1 .PodRunning {
341+ logger .V (1 ).Info ("Pod already running. Skipping init Job" , "pod" , pod .Name )
342+ return ctrl.Result {}, nil
343+ }
344+
330345 var job batchv1.Job
331346 if err := r .Get (ctx , key , & job ); err != nil {
332347 if apierrors .IsNotFound (err ) {
0 commit comments