Skip to content

Commit e11e84f

Browse files
authored
fix no requeue when return requeueError (#1041)
Signed-off-by: Zhiwei Yin <[email protected]>
1 parent 567caa2 commit e11e84f

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

pkg/registration/hub/gc/controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package gc
22

33
import (
44
"context"
5+
"errors"
56
"strings"
67

78
"github.com/openshift/library-go/pkg/controller/factory"
89
"github.com/openshift/library-go/pkg/operator/events"
9-
"github.com/pkg/errors"
1010
apierrors "k8s.io/apimachinery/pkg/api/errors"
1111
"k8s.io/apimachinery/pkg/api/meta"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -98,6 +98,10 @@ func (r *GCController) sync(ctx context.Context, controllerContext factory.SyncC
9898

9999
gcErr := r.gcResourcesController.reconcile(ctx, copyCluster, clusterName)
100100
if cluster == nil {
101+
if errors.Is(gcErr, requeueError) {
102+
controllerContext.Queue().AddAfter(clusterName, requeueError.RequeueTime)
103+
return nil
104+
}
101105
return gcErr
102106
}
103107

@@ -117,6 +121,10 @@ func (r *GCController) sync(ctx context.Context, controllerContext factory.SyncC
117121
return err
118122
}
119123

124+
if errors.Is(gcErr, requeueError) {
125+
controllerContext.Queue().AddAfter(clusterName, requeueError.RequeueTime)
126+
return nil
127+
}
120128
if gcErr != nil {
121129
return gcErr
122130
}

pkg/registration/hub/managedcluster/controller.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package managedcluster
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"time"
78

@@ -11,7 +12,7 @@ import (
1112
operatorhelpers "github.com/openshift/library-go/pkg/operator/v1helpers"
1213
corev1 "k8s.io/api/core/v1"
1314
rbacv1 "k8s.io/api/rbac/v1"
14-
"k8s.io/apimachinery/pkg/api/errors"
15+
apierrors "k8s.io/apimachinery/pkg/api/errors"
1516
"k8s.io/apimachinery/pkg/api/meta"
1617
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1718
"k8s.io/apimachinery/pkg/labels"
@@ -121,8 +122,13 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
121122
logger := klog.FromContext(ctx)
122123
logger.V(4).Info("Reconciling ManagedCluster", "managedClusterName", managedClusterName)
123124
managedCluster, err := c.clusterLister.Get(managedClusterName)
124-
if errors.IsNotFound(err) {
125-
return c.removeClusterRbac(ctx, managedClusterName, true)
125+
if apierrors.IsNotFound(err) {
126+
err = c.removeClusterRbac(ctx, managedClusterName, true)
127+
if errors.Is(err, requeueError) {
128+
syncCtx.Queue().AddAfter(managedClusterName, requeueError.RequeueTime)
129+
return nil
130+
}
131+
return err
126132
}
127133
if err != nil {
128134
return err
@@ -137,6 +143,10 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
137143

138144
err = c.removeClusterRbac(ctx, managedClusterName, true)
139145
if err != nil {
146+
if errors.Is(err, requeueError) {
147+
syncCtx.Queue().AddAfter(managedClusterName, requeueError.RequeueTime)
148+
return nil
149+
}
140150
return err
141151
}
142152

@@ -193,7 +203,12 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
193203
}
194204

195205
// Remove the cluster role binding files for registration-agent and work-agent.
196-
return c.removeClusterRbac(ctx, managedClusterName, managedCluster.Spec.HubAcceptsClient)
206+
err = c.removeClusterRbac(ctx, managedClusterName, managedCluster.Spec.HubAcceptsClient)
207+
if errors.Is(err, requeueError) {
208+
syncCtx.Queue().AddAfter(managedClusterName, requeueError.RequeueTime)
209+
return nil
210+
}
211+
return err
197212
}
198213

199214
// TODO consider to add the managedcluster-namespace.yaml back to staticFiles,
@@ -306,7 +321,7 @@ func (c *managedClusterController) removeClusterRbac(ctx context.Context, cluste
306321
}
307322

308323
works, err := c.manifestWorkLister.ManifestWorks(clusterName).List(labels.Everything())
309-
if err != nil && !errors.IsNotFound(err) {
324+
if err != nil && !apierrors.IsNotFound(err) {
310325
errs = append(errs, err)
311326
return operatorhelpers.NewMultiLineAggregate(errs)
312327
}
@@ -320,7 +335,7 @@ func (c *managedClusterController) removeClusterRbac(ctx context.Context, cluste
320335
func (c *managedClusterController) removeFinalizerFromWorkRoleBinding(ctx context.Context, clusterName string) error {
321336
workRoleBinding, err := c.roleBindingLister.RoleBindings(clusterName).Get(workRoleBindingName(clusterName))
322337
switch {
323-
case errors.IsNotFound(err):
338+
case apierrors.IsNotFound(err):
324339
return nil
325340
case err != nil:
326341
return err

0 commit comments

Comments
 (0)