fix no requeue when return requeueError (#1041)
Some checks failed
Post / coverage (push) Failing after 35m11s
Post / images (amd64) (push) Failing after 8m52s
Post / images (arm64) (push) Failing after 8m9s
Post / image manifest (push) Has been skipped
Post / trigger clusteradm e2e (push) Has been skipped
Scorecard supply-chain security / Scorecard analysis (push) Failing after 1m48s
Close stale issues and PRs / stale (push) Successful in 1m4s

Signed-off-by: Zhiwei Yin <zyin@redhat.com>
This commit is contained in:
Zhiwei Yin
2025-06-18 11:40:27 +08:00
committed by GitHub
parent 567caa2fe9
commit e11e84fcce
2 changed files with 30 additions and 7 deletions

View File

@@ -2,11 +2,11 @@ package gc
import (
"context"
"errors"
"strings"
"github.com/openshift/library-go/pkg/controller/factory"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -98,6 +98,10 @@ func (r *GCController) sync(ctx context.Context, controllerContext factory.SyncC
gcErr := r.gcResourcesController.reconcile(ctx, copyCluster, clusterName)
if cluster == nil {
if errors.Is(gcErr, requeueError) {
controllerContext.Queue().AddAfter(clusterName, requeueError.RequeueTime)
return nil
}
return gcErr
}
@@ -117,6 +121,10 @@ func (r *GCController) sync(ctx context.Context, controllerContext factory.SyncC
return err
}
if errors.Is(gcErr, requeueError) {
controllerContext.Queue().AddAfter(clusterName, requeueError.RequeueTime)
return nil
}
if gcErr != nil {
return gcErr
}

View File

@@ -2,6 +2,7 @@ package managedcluster
import (
"context"
"errors"
"fmt"
"time"
@@ -11,7 +12,7 @@ import (
operatorhelpers "github.com/openshift/library-go/pkg/operator/v1helpers"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
@@ -121,8 +122,13 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
logger := klog.FromContext(ctx)
logger.V(4).Info("Reconciling ManagedCluster", "managedClusterName", managedClusterName)
managedCluster, err := c.clusterLister.Get(managedClusterName)
if errors.IsNotFound(err) {
return c.removeClusterRbac(ctx, managedClusterName, true)
if apierrors.IsNotFound(err) {
err = c.removeClusterRbac(ctx, managedClusterName, true)
if errors.Is(err, requeueError) {
syncCtx.Queue().AddAfter(managedClusterName, requeueError.RequeueTime)
return nil
}
return err
}
if err != nil {
return err
@@ -137,6 +143,10 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
err = c.removeClusterRbac(ctx, managedClusterName, true)
if err != nil {
if errors.Is(err, requeueError) {
syncCtx.Queue().AddAfter(managedClusterName, requeueError.RequeueTime)
return nil
}
return err
}
@@ -193,7 +203,12 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
}
// Remove the cluster role binding files for registration-agent and work-agent.
return c.removeClusterRbac(ctx, managedClusterName, managedCluster.Spec.HubAcceptsClient)
err = c.removeClusterRbac(ctx, managedClusterName, managedCluster.Spec.HubAcceptsClient)
if errors.Is(err, requeueError) {
syncCtx.Queue().AddAfter(managedClusterName, requeueError.RequeueTime)
return nil
}
return err
}
// TODO consider to add the managedcluster-namespace.yaml back to staticFiles,
@@ -306,7 +321,7 @@ func (c *managedClusterController) removeClusterRbac(ctx context.Context, cluste
}
works, err := c.manifestWorkLister.ManifestWorks(clusterName).List(labels.Everything())
if err != nil && !errors.IsNotFound(err) {
if err != nil && !apierrors.IsNotFound(err) {
errs = append(errs, err)
return operatorhelpers.NewMultiLineAggregate(errs)
}
@@ -320,7 +335,7 @@ func (c *managedClusterController) removeClusterRbac(ctx context.Context, cluste
func (c *managedClusterController) removeFinalizerFromWorkRoleBinding(ctx context.Context, clusterName string) error {
workRoleBinding, err := c.roleBindingLister.RoleBindings(clusterName).Get(workRoleBindingName(clusterName))
switch {
case errors.IsNotFound(err):
case apierrors.IsNotFound(err):
return nil
case err != nil:
return err