Skip to content

Commit

Permalink
Catch already exist create error on RS and RD
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <[email protected]>
  • Loading branch information
kaovilai committed Nov 7, 2022
1 parent 2e43d7a commit d065f6c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions controllers/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"

k8serrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -65,7 +66,7 @@ func (r *VolumeSnapshotBackupReconciler) MirrorPVC(log logr.Logger) (bool, error

return r.buildPVCClone(pvcClone, &vsClone)
})
if err != nil {
if err != nil && !k8serrors.IsAlreadyExists(err){
r.Log.Info(fmt.Sprintf("err building pvc clone: %v", err))
return false, err
}
Expand Down Expand Up @@ -170,7 +171,7 @@ func (r *VolumeSnapshotBackupReconciler) BindPVCToDummyPod(log logr.Logger) (boo
return err
})

if err != nil {
if err != nil && !k8serrors.IsAlreadyExists(err){
return false, err
}
if op == controllerutil.OperationResultCreated || op == controllerutil.OperationResultUpdated {
Expand Down
3 changes: 2 additions & 1 deletion controllers/replicationdestination.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (r *VolumeSnapshotRestoreReconciler) CreateReplicationDestination(log logr.

return r.buildReplicationDestination(repDestination, &vsr, &resticSecret)
})
if err != nil {
if err != nil && !k8serrors.IsAlreadyExists(err){
// don't error out if create errors due to replicationDestination already exists
return false, err
}

Expand Down
3 changes: 2 additions & 1 deletion controllers/replicationsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func (r *VolumeSnapshotBackupReconciler) CreateReplicationSource(log logr.Logger

return r.buildReplicationSource(repSource, &vsb, &clonedPVC)
})
if err != nil {
if err != nil && !k8serrors.IsAlreadyExists(err){
// don't error out if create errors due to replicationSource already exists
return false, err
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/restic.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (r *VolumeSnapshotBackupReconciler) CreateVSBResticSecret(log logr.Logger)

return BuildResticSecret(&resticSecret, rsecret, resticrepo)
})
if err != nil {
if err != nil && !k8serrors.IsAlreadyExists(err){
return false, err
}

Expand Down Expand Up @@ -148,7 +148,7 @@ func (r *VolumeSnapshotRestoreReconciler) CreateVSRResticSecret(log logr.Logger)

return BuildResticSecret(&resticSecret, newResticSecret, resticrepo)
})
if err != nil {
if err != nil && !k8serrors.IsAlreadyExists(err){
return false, err
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/volumesnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *VolumeSnapshotBackupReconciler) MirrorVolumeSnapshotContent(log logr.Lo
return r.buildVolumeSnapshotContentClone(vscClone, &vsb)
})

if err != nil {
if err != nil && !k8serrors.IsAlreadyExists(err){
return false, err
}

Expand Down Expand Up @@ -114,7 +114,7 @@ func (r *VolumeSnapshotBackupReconciler) MirrorVolumeSnapshot(log logr.Logger) (

return r.buildVolumeSnapshotClone(vsClone, &vscClone)
})
if err != nil {
if err != nil && !k8serrors.IsAlreadyExists(err){
return false, err
}
if op == controllerutil.OperationResultCreated || op == controllerutil.OperationResultUpdated {
Expand Down

0 comments on commit d065f6c

Please sign in to comment.