From ceed18d245af041bfc41b9f5221e014e32ad8f71 Mon Sep 17 00:00:00 2001 From: Nikhil Thomas Date: Wed, 23 Mar 2022 15:51:11 +0530 Subject: [PATCH] Replace imperative Requeue calls with a declarative Requeue event Replace explicit Requeue reconciler-event (enqueue) calls with an a return error (event) of type `requeueKeyError` This approach lets the knative generated reconciler code to do the requeuing when we pass our intent by returning an `event` of type `requeueKeyError`. Signed-off-by: Nikhil Thomas --- pkg/apis/operator/v1alpha1/const.go | 10 +++++- .../kubernetes/tektonchain/controller.go | 3 -- .../kubernetes/tektonchain/tektonchain.go | 21 ++++--------- .../kubernetes/tektondashboard/controller.go | 3 -- .../tektondashboard/tektondashboard.go | 22 ++++--------- .../kubernetes/tektonhub/controller.go | 3 -- .../kubernetes/tektonhub/tektonhub.go | 15 +++------ .../tektoninstallerset/controller.go | 3 -- .../tektoninstallerset/tektoninstallerset.go | 15 +++------ .../kubernetes/tektonpipeline/controller.go | 3 -- .../tektonpipeline/tektonpipeline.go | 22 +++++-------- .../kubernetes/tektontrigger/controller.go | 3 -- .../kubernetes/tektontrigger/tektontrigger.go | 31 +++++++------------ .../tektonaddon/communityClusterTasks.go | 8 ++--- .../openshift/tektonaddon/controller.go | 3 -- .../openshift/tektonaddon/tektonaddon.go | 18 +++-------- .../shared/tektonconfig/controller.go | 3 -- .../shared/tektonconfig/tektonconfig.go | 21 ++++--------- 18 files changed, 64 insertions(+), 143 deletions(-) diff --git a/pkg/apis/operator/v1alpha1/const.go b/pkg/apis/operator/v1alpha1/const.go index b84a0400e2..82bc11ff11 100644 --- a/pkg/apis/operator/v1alpha1/const.go +++ b/pkg/apis/operator/v1alpha1/const.go @@ -16,7 +16,11 @@ limitations under the License. package v1alpha1 -import "fmt" +import ( + "fmt" + "knative.dev/pkg/controller" + "time" +) const ( // operatorVersion @@ -47,6 +51,8 @@ const ( InstallerSetType = "operator.tekton.dev/type" UpgradePending = "upgrade pending" + + RequeueDelay = 10 * time.Second ) var ( @@ -55,6 +61,8 @@ var ( // that we proceed ahead with updated object RECONCILE_AGAIN_ERR = fmt.Errorf("reconcile again and proceed") + REQUEUE_EVENT_AFTER = controller.NewRequeueAfter(RequeueDelay) + // DEPENDENCY_UPGRADE_PENDING_ERR // When a reconciler cannot proceed due to an upgrade in progress of a dependency DEPENDENCY_UPGRADE_PENDING_ERR = fmt.Errorf("dependency upgrade pending") diff --git a/pkg/reconciler/kubernetes/tektonchain/controller.go b/pkg/reconciler/kubernetes/tektonchain/controller.go index 821c84eb7b..8ee54bd301 100644 --- a/pkg/reconciler/kubernetes/tektonchain/controller.go +++ b/pkg/reconciler/kubernetes/tektonchain/controller.go @@ -72,9 +72,6 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro } impl := tektonChainreconciler.NewImpl(ctx, c) - // Add enqueue func in reconciler - c.enqueueAfter = impl.EnqueueAfter - logger.Info("Setting up event handlers for Tekton Chain") tektonChaininformer.Get(ctx).Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) diff --git a/pkg/reconciler/kubernetes/tektonchain/tektonchain.go b/pkg/reconciler/kubernetes/tektonchain/tektonchain.go index 45ef6b56ac..fe9e2d4504 100644 --- a/pkg/reconciler/kubernetes/tektonchain/tektonchain.go +++ b/pkg/reconciler/kubernetes/tektonchain/tektonchain.go @@ -19,8 +19,6 @@ package tektonchain import ( "context" "fmt" - "time" - mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" @@ -45,9 +43,7 @@ type Reconciler struct { // particular version manifest mf.Manifest // Platform-specific behavior to affect the transform - // enqueueAfter enqueues a obj after a duration - enqueueAfter func(obj interface{}, after time.Duration) - extension common.Extension + extension common.Extension // chainVersion describes the current chain version chainVersion string operatorVersion string @@ -176,8 +172,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonChain Get(ctx, existingInstallerSet, metav1.GetOptions{}) if err == nil { tc.Status.MarkNotReady("Waiting for previous installer set to get deleted") - r.enqueueAfter(tc, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } if !apierrors.IsNotFound(err) { logger.Error("failed to get InstallerSet: %s", err) @@ -233,8 +228,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonChain // after updating installer set enqueue after a duration // to allow changes to get deployed - r.enqueueAfter(tc, 20*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } } @@ -244,18 +238,15 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonChain ready := installedTIS.Status.GetCondition(apis.ConditionReady) if ready == nil { tc.Status.MarkInstallerSetNotReady("Waiting for installation") - r.enqueueAfter(tc, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } if ready.Status == corev1.ConditionUnknown { tc.Status.MarkInstallerSetNotReady("Waiting for installation") - r.enqueueAfter(tc, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } else if ready.Status == corev1.ConditionFalse { tc.Status.MarkInstallerSetNotReady(ready.Message) - r.enqueueAfter(tc, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } // Mark InstallerSet Ready diff --git a/pkg/reconciler/kubernetes/tektondashboard/controller.go b/pkg/reconciler/kubernetes/tektondashboard/controller.go index 27e6fb17b9..c7a09703b4 100644 --- a/pkg/reconciler/kubernetes/tektondashboard/controller.go +++ b/pkg/reconciler/kubernetes/tektondashboard/controller.go @@ -76,9 +76,6 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro } impl := tektonDashboardreconciler.NewImpl(ctx, c) - // Add enqueue func in reconciler - c.enqueueAfter = impl.EnqueueAfter - logger.Info("Setting up event handlers for tekton-dashboard") tektonDashboardInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) diff --git a/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go b/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go index 29d5149abd..9fdacf3395 100644 --- a/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go +++ b/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go @@ -19,8 +19,6 @@ package tektondashboard import ( "context" "fmt" - "time" - mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" @@ -51,8 +49,6 @@ type Reconciler struct { // a particular version with readonly value as false fullaccessManifest mf.Manifest // Platform-specific behavior to affect the transform - // enqueueAfter enqueues a obj after a duration - enqueueAfter func(obj interface{}, after time.Duration) extension common.Extension pipelineInformer pipelineinformer.TektonPipelineInformer operatorVersion string @@ -137,8 +133,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb if err.Error() == common.PipelineNotReady { td.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - r.enqueueAfter(td, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } // (tektonpipeline.opeator.tekton.dev instance not available yet) @@ -210,8 +205,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb Get(ctx, existingInstallerSet, metav1.GetOptions{}) if err == nil { td.Status.MarkNotReady("Waiting for previous installer set to get deleted") - r.enqueueAfter(td, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } if !apierrors.IsNotFound(err) { logger.Error("failed to get InstallerSet: %s", err) @@ -263,8 +257,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb // after updating installer set enqueue after a duration // to allow changes to get deployed - r.enqueueAfter(td, 20*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } } @@ -274,18 +267,15 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb ready := installedTIS.Status.GetCondition(apis.ConditionReady) if ready == nil { td.Status.MarkInstallerSetNotReady("Waiting for installation") - r.enqueueAfter(td, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } if ready.Status == corev1.ConditionUnknown { td.Status.MarkInstallerSetNotReady("Waiting for installation") - r.enqueueAfter(td, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } else if ready.Status == corev1.ConditionFalse { td.Status.MarkInstallerSetNotReady(ready.Message) - r.enqueueAfter(td, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } // Mark InstallerSet Ready diff --git a/pkg/reconciler/kubernetes/tektonhub/controller.go b/pkg/reconciler/kubernetes/tektonhub/controller.go index 38abdcec22..9b391414ef 100644 --- a/pkg/reconciler/kubernetes/tektonhub/controller.go +++ b/pkg/reconciler/kubernetes/tektonhub/controller.go @@ -68,9 +68,6 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro } impl := tektonHubReconciler.NewImpl(ctx, c) - // Add enqueue func in reconciler - c.enqueueAfter = impl.EnqueueAfter - logger.Info("Setting up event handlers") tektonHubInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) diff --git a/pkg/reconciler/kubernetes/tektonhub/tektonhub.go b/pkg/reconciler/kubernetes/tektonhub/tektonhub.go index bbb4dc4ac7..71ee227958 100644 --- a/pkg/reconciler/kubernetes/tektonhub/tektonhub.go +++ b/pkg/reconciler/kubernetes/tektonhub/tektonhub.go @@ -20,12 +20,10 @@ package tektonhub import ( "context" "fmt" - "path/filepath" - "time" - corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "path/filepath" mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" @@ -51,8 +49,6 @@ type Reconciler struct { manifest mf.Manifest // Platform-specific behavior to affect the transform extension common.Extension - // enqueueAfter enqueues a obj after a duration - enqueueAfter func(obj interface{}, after time.Duration) } var ( @@ -175,8 +171,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, th *v1alpha1.TektonHub) func (r *Reconciler) handleError(err error, th *v1alpha1.TektonHub) error { if err == v1alpha1.RECONCILE_AGAIN_ERR { - r.enqueueAfter(th, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } return err } @@ -184,8 +179,7 @@ func (r *Reconciler) handleError(err error, th *v1alpha1.TektonHub) error { func (r *Reconciler) manageUiComponent(ctx context.Context, th *v1alpha1.TektonHub, hubDir, version string) error { if err := r.validateUiConfigMap(ctx, th); err != nil { th.Status.MarkUiDependencyMissing(fmt.Sprintf("UI config map not present: %v", err.Error())) - r.enqueueAfter(th, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } th.Status.MarkUiDependenciesInstalled() @@ -217,8 +211,7 @@ func (r *Reconciler) manageApiComponent(ctx context.Context, th *v1alpha1.Tekton // Validate whether the secrets and configmap are created for API if err := r.validateApiDependencies(ctx, th); err != nil { th.Status.MarkApiDependencyMissing("api secrets not present") - r.enqueueAfter(th, 10*time.Second) - return err + return v1alpha1.REQUEUE_EVENT_AFTER } th.Status.MarkApiDependenciesInstalled() diff --git a/pkg/reconciler/kubernetes/tektoninstallerset/controller.go b/pkg/reconciler/kubernetes/tektoninstallerset/controller.go index 754bfcd28c..0794ce5b6c 100644 --- a/pkg/reconciler/kubernetes/tektoninstallerset/controller.go +++ b/pkg/reconciler/kubernetes/tektoninstallerset/controller.go @@ -59,9 +59,6 @@ func NewExtendedController() injection.ControllerConstructor { } impl := tektonInstallerReconciler.NewImpl(ctx, c) - // Add enqueue func in reconciler - c.enqueueAfter = impl.EnqueueAfter - logger.Info("Setting up event handlers for TektonInstallerSet") tektonInstallerinformer.Get(ctx).Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) diff --git a/pkg/reconciler/kubernetes/tektoninstallerset/tektoninstallerset.go b/pkg/reconciler/kubernetes/tektoninstallerset/tektoninstallerset.go index 9ac793566b..df5598d2ed 100644 --- a/pkg/reconciler/kubernetes/tektoninstallerset/tektoninstallerset.go +++ b/pkg/reconciler/kubernetes/tektoninstallerset/tektoninstallerset.go @@ -19,8 +19,6 @@ package tektoninstallerset import ( "context" "fmt" - "time" - "github.com/go-logr/logr" mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" @@ -36,7 +34,6 @@ type Reconciler struct { operatorClientSet clientset.Interface mfClient mf.Client mfLogger logr.Logger - enqueueAfter func(obj interface{}, after time.Duration) } // Reconciler implements controller.Reconciler @@ -148,8 +145,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, installerSet *v1alpha1.T err = installer.IsWebhookReady() if err != nil { installerSet.Status.MarkWebhookNotReady(err.Error()) - r.enqueueAfter(installerSet, time.Second*10) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } // Update Status for Webhook @@ -159,8 +155,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, installerSet *v1alpha1.T err = installer.IsControllerReady() if err != nil { installerSet.Status.MarkControllerNotReady(err.Error()) - r.enqueueAfter(installerSet, time.Second*10) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } // Update Ready status of Controller @@ -179,8 +174,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, installerSet *v1alpha1.T err = installer.AllDeploymentsReady() if err != nil { installerSet.Status.MarkAllDeploymentsNotReady(err.Error()) - r.enqueueAfter(installerSet, time.Second*10) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } // Mark all deployments ready @@ -191,8 +185,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, installerSet *v1alpha1.T func (r *Reconciler) handleError(err error, installerSet *v1alpha1.TektonInstallerSet) error { if err == v1alpha1.RECONCILE_AGAIN_ERR { - r.enqueueAfter(installerSet, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } return err } diff --git a/pkg/reconciler/kubernetes/tektonpipeline/controller.go b/pkg/reconciler/kubernetes/tektonpipeline/controller.go index 894b31b5fc..d242ae9062 100644 --- a/pkg/reconciler/kubernetes/tektonpipeline/controller.go +++ b/pkg/reconciler/kubernetes/tektonpipeline/controller.go @@ -74,9 +74,6 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro } impl := tektonPipelineReconciler.NewImpl(ctx, c) - // Add enqueue func in reconciler - c.enqueueAfter = impl.EnqueueAfter - logger.Info("Setting up event handlers for TektonPipeline") tektonPipelineInformer.Get(ctx).Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) diff --git a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go index 9b5f886a7d..2d13dfe599 100644 --- a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go +++ b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go @@ -19,8 +19,6 @@ package tektonpipeline import ( "context" "fmt" - "time" - mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" @@ -58,8 +56,6 @@ type Reconciler struct { manifest mf.Manifest // Platform-specific behavior to affect the transform extension common.Extension - // enqueueAfter enqueues a obj after a duration - enqueueAfter func(obj interface{}, after time.Duration) // metrics handles metrics for pipeline install metrics *Recorder kubeClientSet kubernetes.Interface @@ -212,8 +208,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tp *v1alpha1.TektonPipel Get(ctx, existingInstallerSet, metav1.GetOptions{}) if err == nil { tp.Status.MarkNotReady("Waiting for previous installer set to get deleted") - r.enqueueAfter(tp, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } if !apierrors.IsNotFound(err) { logger.Error("failed to get InstallerSet: %s", err) @@ -257,8 +252,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tp *v1alpha1.TektonPipel // after updating installer set enqueue after a duration // to allow changes to get deployed - r.enqueueAfter(tp, 20*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } } @@ -268,14 +262,12 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tp *v1alpha1.TektonPipel ready := installedTIS.Status.GetCondition(apis.ConditionReady) if ready == nil { tp.Status.MarkInstallerSetNotReady("Waiting for installation") - r.enqueueAfter(tp, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } if ready.Status == corev1.ConditionUnknown { tp.Status.MarkInstallerSetNotReady("Waiting for installation") - r.enqueueAfter(tp, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } else if ready.Status == corev1.ConditionFalse { tp.Status.MarkInstallerSetNotReady(ready.Message) manifest := r.manifest @@ -284,8 +276,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tp *v1alpha1.TektonPipel return err } err = common.PreemptDeadlock(ctx, &manifest, r.kubeClientSet, v1alpha1.PipelineResourceName) - r.enqueueAfter(tp, 10*time.Second) - return err + if err != nil { + logger.Error("preempt deadlock error: %v", err) + } + return v1alpha1.REQUEUE_EVENT_AFTER } // Mark InstallerSet Ready diff --git a/pkg/reconciler/kubernetes/tektontrigger/controller.go b/pkg/reconciler/kubernetes/tektontrigger/controller.go index a8cf3c025d..1775203739 100644 --- a/pkg/reconciler/kubernetes/tektontrigger/controller.go +++ b/pkg/reconciler/kubernetes/tektontrigger/controller.go @@ -78,9 +78,6 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro } impl := tektonTriggerreconciler.NewImpl(ctx, c) - // Add enqueue func in reconciler - c.enqueueAfter = impl.EnqueueAfter - logger.Info("Setting up event handlers for TektonTrigger") tektonTriggerinformer.Get(ctx).Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) diff --git a/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go b/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go index 8c435eb346..7776bd3b40 100644 --- a/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go +++ b/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go @@ -19,8 +19,6 @@ package tektontrigger import ( "context" "fmt" - "time" - mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" @@ -62,11 +60,9 @@ type Reconciler struct { metrics *Recorder pipelineInformer pipelineinformer.TektonPipelineInformer - // enqueueAfter enqueues a obj after a duration - enqueueAfter func(obj interface{}, after time.Duration) - triggersVersion string - operatorVersion string - kubeClientSet kubernetes.Interface + triggersVersion string + operatorVersion string + kubeClientSet kubernetes.Interface } var ( @@ -135,8 +131,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg if err.Error() == common.PipelineNotReady { tt.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - r.enqueueAfter(tt, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } // (tektonpipeline.operator.tekton.dev instance not available yet) tt.Status.MarkDependencyMissing("tekton-pipelines does not exist") @@ -226,8 +221,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg Get(ctx, existingInstallerSet, metav1.GetOptions{}) if err == nil { tt.Status.MarkNotReady("Waiting for previous installer set to get deleted") - r.enqueueAfter(tt, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } if !apierrors.IsNotFound(err) { logger.Error("failed to get InstallerSet: %s", err) @@ -273,8 +267,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg // after updating installer set enqueue after a duration // to allow changes to get deployed - r.enqueueAfter(tt, 20*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } } @@ -284,14 +277,12 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg ready := installedTIS.Status.GetCondition(apis.ConditionReady) if ready == nil { tt.Status.MarkInstallerSetNotReady("Waiting for installation") - r.enqueueAfter(tt, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } if ready.Status == corev1.ConditionUnknown { tt.Status.MarkInstallerSetNotReady("Waiting for installation") - r.enqueueAfter(tt, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } else if ready.Status == corev1.ConditionFalse { tt.Status.MarkInstallerSetNotReady(ready.Message) manifest := r.manifest @@ -300,8 +291,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg return err } err = common.PreemptDeadlock(ctx, &manifest, r.kubeClientSet, v1alpha1.TriggerResourceName) - r.enqueueAfter(tt, 10*time.Second) - return err + if err != nil { + logger.Error("preempt deadlock error: %v", err) + } + return v1alpha1.REQUEUE_EVENT_AFTER } // Mark InstallerSet Ready diff --git a/pkg/reconciler/openshift/tektonaddon/communityClusterTasks.go b/pkg/reconciler/openshift/tektonaddon/communityClusterTasks.go index 83d58bc967..2997f27bed 100644 --- a/pkg/reconciler/openshift/tektonaddon/communityClusterTasks.go +++ b/pkg/reconciler/openshift/tektonaddon/communityClusterTasks.go @@ -19,13 +19,14 @@ package tektonaddon import ( "context" "fmt" + "strings" + "time" + mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/reconciler/common" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/logging" - "strings" - "time" ) var communityClusterTaskLS = metav1.LabelSelector{ @@ -103,8 +104,7 @@ func (r *Reconciler) ensureCommunityClusterTasks(ctx context.Context, ta *v1alph // Continue if failed to resolve community task URL. // (Ex: on disconnected cluster community tasks won't be reachable because of proxy). logging.FromContext(ctx).Error("Failed to get community task: Skipping community tasks installation ", err) - r.enqueueAfter(r, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } if err := r.communityTransform(ctx, &communityClusterTaskManifest, ta); err != nil { diff --git a/pkg/reconciler/openshift/tektonaddon/controller.go b/pkg/reconciler/openshift/tektonaddon/controller.go index 8744d4a9a4..cc04b5420c 100644 --- a/pkg/reconciler/openshift/tektonaddon/controller.go +++ b/pkg/reconciler/openshift/tektonaddon/controller.go @@ -79,9 +79,6 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro } impl := tektonAddonreconciler.NewImpl(ctx, c) - // Add enqueue func in reconciler - c.enqueueAfter = impl.EnqueueAfter - logger.Info("Setting up event handlers for TektonAddon") tektonAddoninformer.Get(ctx).Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) diff --git a/pkg/reconciler/openshift/tektonaddon/tektonaddon.go b/pkg/reconciler/openshift/tektonaddon/tektonaddon.go index 4b0491d135..5b1c674697 100644 --- a/pkg/reconciler/openshift/tektonaddon/tektonaddon.go +++ b/pkg/reconciler/openshift/tektonaddon/tektonaddon.go @@ -19,10 +19,6 @@ package tektonaddon import ( "context" "fmt" - "os" - "path/filepath" - "time" - mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" @@ -33,6 +29,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/logging" pkgreconciler "knative.dev/pkg/reconciler" + "os" + "path/filepath" ) // Reconciler implements controller.Reconciler for TektonAddon resources. @@ -41,9 +39,6 @@ type Reconciler struct { operatorClientSet clientset.Interface extension common.Extension - // enqueueAfter enqueues a obj after a duration - enqueueAfter func(obj interface{}, after time.Duration) - pipelineInformer informer.TektonPipelineInformer triggerInformer informer.TektonTriggerInformer @@ -123,8 +118,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon if err.Error() == common.PipelineNotReady { ta.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - r.enqueueAfter(ta, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } // (tektonpipeline.operator.tekton.dev instance not available yet) ta.Status.MarkDependencyMissing("tekton-pipelines does not exist") @@ -135,8 +129,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon if err.Error() == common.TriggerNotReady { ta.Status.MarkDependencyInstalling("tekton-triggers is still installing") // wait for trigger status to change - r.enqueueAfter(ta, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } // (tektontrigger.operator.tekton.dev instance not available yet) ta.Status.MarkDependencyMissing("tekton-triggers does not exist") @@ -194,8 +187,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon if err := r.extension.PostReconcile(ctx, ta); err != nil { if err == v1alpha1.RECONCILE_AGAIN_ERR { - r.enqueueAfter(ta, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } ta.Status.MarkPostReconcilerFailed(err.Error()) return err diff --git a/pkg/reconciler/shared/tektonconfig/controller.go b/pkg/reconciler/shared/tektonconfig/controller.go index 66031b73f1..45dd4f1593 100644 --- a/pkg/reconciler/shared/tektonconfig/controller.go +++ b/pkg/reconciler/shared/tektonconfig/controller.go @@ -74,9 +74,6 @@ func NewExtensibleController(generator common.ExtensionGenerator) injection.Cont } impl := tektonConfigreconciler.NewImpl(ctx, c) - // Add enqueue func in reconciler - c.enqueueAfter = impl.EnqueueAfter - logger.Info("Setting up event handlers for TektonConfig") tektonConfiginformer.Get(ctx).Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) diff --git a/pkg/reconciler/shared/tektonconfig/tektonconfig.go b/pkg/reconciler/shared/tektonconfig/tektonconfig.go index 8e0142827b..968d3dd1b0 100644 --- a/pkg/reconciler/shared/tektonconfig/tektonconfig.go +++ b/pkg/reconciler/shared/tektonconfig/tektonconfig.go @@ -19,8 +19,6 @@ package tektonconfig import ( "context" "fmt" - "time" - mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" @@ -43,9 +41,7 @@ type Reconciler struct { // operatorClientSet allows us to configure operator objects operatorClientSet clientset.Interface // Platform-specific behavior to affect the transform - extension common.Extension - // enqueueAfter enqueues a obj after a duration - enqueueAfter func(obj interface{}, after time.Duration) + extension common.Extension manifest mf.Manifest operatorVersion string } @@ -106,8 +102,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi if err := r.extension.PreReconcile(ctx, tc); err != nil { if err == v1alpha1.RECONCILE_AGAIN_ERR { - r.enqueueAfter(tc, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } tc.Status.MarkPreInstallFailed(err.Error()) return err @@ -119,8 +114,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi if _, err := pipeline.EnsureTektonPipelineExists(ctx, r.operatorClientSet.OperatorV1alpha1().TektonPipelines(), tc); err != nil { tc.Status.MarkComponentNotReady(fmt.Sprintf("TektonPipeline: %s", err.Error())) if err == v1alpha1.RECONCILE_AGAIN_ERR { - r.enqueueAfter(tc, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } return nil } @@ -129,14 +123,12 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi if tc.Spec.Profile == v1alpha1.ProfileAll || tc.Spec.Profile == v1alpha1.ProfileBasic { if _, err := trigger.EnsureTektonTriggerExists(ctx, r.operatorClientSet.OperatorV1alpha1().TektonTriggers(), tc); err != nil { tc.Status.MarkComponentNotReady(fmt.Sprintf("TektonTrigger: %s", err.Error())) - r.enqueueAfter(tc, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } } else { if err := trigger.TektonTriggerCRDelete(ctx, r.operatorClientSet.OperatorV1alpha1().TektonTriggers(), v1alpha1.TriggerResourceName); err != nil { tc.Status.MarkComponentNotReady(fmt.Sprintf("TektonTrigger: %s", err.Error())) - r.enqueueAfter(tc, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } } @@ -149,8 +141,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi if err := r.extension.PostReconcile(ctx, tc); err != nil { tc.Status.MarkPostInstallFailed(err.Error()) - r.enqueueAfter(tc, 10*time.Second) - return nil + return v1alpha1.REQUEUE_EVENT_AFTER } tc.Status.MarkPostInstallComplete()