Skip to content

Commit

Permalink
Merge pull request #184 from openshift-cherrypick-robot/cherry-pick-1…
Browse files Browse the repository at this point in the history
…83-to-release-4.14

Bug 2248824: [release-4.14] Requeue DRPolicy if no mirrorpeers found
  • Loading branch information
openshift-merge-bot[bot] authored Nov 10, 2023
2 parents 19839c6 + 7e7440b commit 2bf2e3a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions controllers/drpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/red-hat-storage/odf-multicluster-orchestrator/addons/setup"
"sort"
"time"

"github.com/red-hat-storage/odf-multicluster-orchestrator/addons/setup"

addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -20,6 +21,7 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
clusterv1 "open-cluster-management.io/api/cluster/v1"
Expand Down Expand Up @@ -101,7 +103,7 @@ func (r *DRPolicyReconciler) getMirrorPeerForClusterSet(ctx context.Context, clu

if len(mpList.Items) == 0 {
klog.Info("no mirrorpeers found on hub yet")
return nil, fmt.Errorf("resource not found")
return nil, k8serrors.NewNotFound(schema.GroupResource{Group: multiclusterv1alpha1.GroupVersion.Group, Resource: "MirrorPeer"}, "MirrorPeerList")
}
for _, mp := range mpList.Items {
if (mp.Spec.Items[0].ClusterName == clusterSet[0] && mp.Spec.Items[1].ClusterName == clusterSet[1]) ||
Expand Down Expand Up @@ -131,8 +133,8 @@ func (r *DRPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
// find mirrorpeer for clusterset for the storagecluster namespaces
mirrorPeer, err := r.getMirrorPeerForClusterSet(ctx, drpolicy.Spec.DRClusters)
if err != nil {
if err.Error() == "resource not found" {
return ctrl.Result{}, nil
if k8serrors.IsNotFound(err) {
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
}
klog.Error("error occurred while trying to fetch MirrorPeer for given DRPolicy")
return ctrl.Result{}, err
Expand Down

0 comments on commit 2bf2e3a

Please sign in to comment.