Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 40 additions & 32 deletions internal/controller/mantlebackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,15 @@ func (r *MantleBackupReconciler) provisionRBDSnapshot(
// snapshot corresponding to the given MantleBackup, so that we can make
// sure that every MantleBackup that has a RBD snapshot is labelled with
// local-backup-target-pvc-uid.
if _, err := ctrl.CreateOrUpdate(ctx, r.Client, backup, func() error {
if backup.Labels == nil {
backup.Labels = map[string]string{}
}
backup.Labels[labelLocalBackupTargetPVCUID] = string(target.pvc.GetUID())
return nil
}); err != nil {
key := client.ObjectKeyFromObject(backup)
if err := r.Get(ctx, key, backup); err != nil {
return err
}
if backup.Labels == nil {
backup.Labels = map[string]string{}
}
backup.Labels[labelLocalBackupTargetPVCUID] = string(target.pvc.GetUID())
if err := r.Update(ctx, backup); err != nil {
return err
}

Expand Down Expand Up @@ -952,38 +954,44 @@ func (r *MantleBackupReconciler) annotateExportTargetMantleBackup(
incremental bool,
sourceName *string,
) error {
_, err := ctrl.CreateOrUpdate(ctx, r.Client, target, func() error {
annot := target.GetAnnotations()
if annot == nil {
annot = map[string]string{}
}
if incremental {
annot[annotSyncMode] = syncModeIncremental
annot[annotDiffFrom] = *sourceName
} else {
annot[annotSyncMode] = syncModeFull
}
target.SetAnnotations(annot)
return nil
})
return err
key := client.ObjectKeyFromObject(target)
if err := r.Get(ctx, key, target); err != nil {
return err
}

annot := target.GetAnnotations()
if annot == nil {
annot = map[string]string{}
}
if incremental {
annot[annotSyncMode] = syncModeIncremental
annot[annotDiffFrom] = *sourceName
} else {
annot[annotSyncMode] = syncModeFull
}
target.SetAnnotations(annot)

return r.Update(ctx, target)
}

func (r *MantleBackupReconciler) annotateExportSourceMantleBackup(
ctx context.Context,
source *mantlev1.MantleBackup,
target *mantlev1.MantleBackup,
) error {
_, err := ctrl.CreateOrUpdate(ctx, r.Client, source, func() error {
annot := source.GetAnnotations()
if annot == nil {
annot = map[string]string{}
}
annot[annotDiffTo] = target.GetName()
source.SetAnnotations(annot)
return nil
})
return err
key := client.ObjectKeyFromObject(source)
if err := r.Get(ctx, key, source); err != nil {
return err
}

annot := source.GetAnnotations()
if annot == nil {
annot = map[string]string{}
}
annot[annotDiffTo] = target.GetName()
source.SetAnnotations(annot)

return r.Update(ctx, source)
}

// startExport reconciles export Jobs and PVCs. Note that it might update
Expand Down
44 changes: 21 additions & 23 deletions internal/controller/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,33 +267,31 @@ func (s *SecondaryServer) SetSynchronizing(
return nil, errors.New("diffTo is invalid")
}

if _, err := ctrl.CreateOrUpdate(ctx, s.client, &source, func() error {
annot := source.GetAnnotations()
if annot == nil {
annot = map[string]string{}
}
annot[annotDiffTo] = req.Name
source.SetAnnotations(annot)
return nil
}); err != nil {
return nil, err
}
}

if _, err := ctrl.CreateOrUpdate(ctx, s.client, &target, func() error {
annot := target.GetAnnotations()
annot := source.GetAnnotations()
if annot == nil {
annot = map[string]string{}
}
if req.DiffFrom == nil {
annot[annotSyncMode] = syncModeFull
} else {
annot[annotSyncMode] = syncModeIncremental
annot[annotDiffFrom] = *req.DiffFrom
annot[annotDiffTo] = req.Name
source.SetAnnotations(annot)

if err := s.client.Update(ctx, &source); err != nil {
return nil, err
}
target.SetAnnotations(annot)
return nil
}); err != nil {
}

annot := target.GetAnnotations()
if annot == nil {
annot = map[string]string{}
}
if req.DiffFrom == nil {
annot[annotSyncMode] = syncModeFull
} else {
annot[annotSyncMode] = syncModeIncremental
annot[annotDiffFrom] = *req.DiffFrom
}
target.SetAnnotations(annot)

if err := s.client.Update(ctx, &target); err != nil {
return nil, err
}

Expand Down