@@ -2,6 +2,7 @@ package managedcluster
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"time"
7
8
@@ -11,7 +12,7 @@ import (
11
12
operatorhelpers "github.com/openshift/library-go/pkg/operator/v1helpers"
12
13
corev1 "k8s.io/api/core/v1"
13
14
rbacv1 "k8s.io/api/rbac/v1"
14
- "k8s.io/apimachinery/pkg/api/errors"
15
+ apierrors "k8s.io/apimachinery/pkg/api/errors"
15
16
"k8s.io/apimachinery/pkg/api/meta"
16
17
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
18
"k8s.io/apimachinery/pkg/labels"
@@ -121,8 +122,13 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
121
122
logger := klog .FromContext (ctx )
122
123
logger .V (4 ).Info ("Reconciling ManagedCluster" , "managedClusterName" , managedClusterName )
123
124
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
126
132
}
127
133
if err != nil {
128
134
return err
@@ -137,6 +143,10 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
137
143
138
144
err = c .removeClusterRbac (ctx , managedClusterName , true )
139
145
if err != nil {
146
+ if errors .Is (err , requeueError ) {
147
+ syncCtx .Queue ().AddAfter (managedClusterName , requeueError .RequeueTime )
148
+ return nil
149
+ }
140
150
return err
141
151
}
142
152
@@ -193,7 +203,12 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
193
203
}
194
204
195
205
// 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
197
212
}
198
213
199
214
// TODO consider to add the managedcluster-namespace.yaml back to staticFiles,
@@ -306,7 +321,7 @@ func (c *managedClusterController) removeClusterRbac(ctx context.Context, cluste
306
321
}
307
322
308
323
works , err := c .manifestWorkLister .ManifestWorks (clusterName ).List (labels .Everything ())
309
- if err != nil && ! errors .IsNotFound (err ) {
324
+ if err != nil && ! apierrors .IsNotFound (err ) {
310
325
errs = append (errs , err )
311
326
return operatorhelpers .NewMultiLineAggregate (errs )
312
327
}
@@ -320,7 +335,7 @@ func (c *managedClusterController) removeClusterRbac(ctx context.Context, cluste
320
335
func (c * managedClusterController ) removeFinalizerFromWorkRoleBinding (ctx context.Context , clusterName string ) error {
321
336
workRoleBinding , err := c .roleBindingLister .RoleBindings (clusterName ).Get (workRoleBindingName (clusterName ))
322
337
switch {
323
- case errors .IsNotFound (err ):
338
+ case apierrors .IsNotFound (err ):
324
339
return nil
325
340
case err != nil :
326
341
return err
0 commit comments