Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 2248824: [release-4.14] Requeue DRPolicy if no mirrorpeers found #184

Merged
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
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