From 6136521c944119d6d6942cd367ea5d6ac1b16433 Mon Sep 17 00:00:00 2001 From: Sebastian Florek Date: Fri, 13 Sep 2024 14:00:49 +0200 Subject: [PATCH] fix lint --- pkg/controller/controller.go | 36 +++++++------------ pkg/controller/namespaces/reconciler.go | 15 ++++---- pkg/controller/namespaces/socket_publisher.go | 2 +- pkg/controller/pipelinegates/reconciler.go | 4 +-- .../pipelinegates/socket_publisher.go | 3 +- pkg/controller/restore/reconciler.go | 11 +++--- pkg/controller/restore/socket_publisher.go | 5 +-- pkg/controller/service/reconciler.go | 4 +-- pkg/controller/service/socket_publisher.go | 2 +- pkg/controller/stacks/reconciler.go | 13 +++---- pkg/controller/stacks/socket_publisher.go | 2 +- 11 files changed, 46 insertions(+), 51 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index f5d0407e..a67e0e36 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -6,13 +6,14 @@ import ( "sync" "time" - "github.com/pluralsh/deployment-operator/pkg/websocket" "k8s.io/apimachinery/pkg/types" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/client-go/util/workqueue" "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/pluralsh/deployment-operator/pkg/websocket" + logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -51,7 +52,7 @@ type Controller struct { // Queue is an listeningQueue that listens for events from Informers and adds object keys to // the Queue for processing - Queue workqueue.RateLimitingInterface + Queue workqueue.TypedRateLimitingInterface[string] // mu is used to synchronize Controller setup mu sync.Mutex @@ -129,7 +130,7 @@ func (c *Controller) Start(ctx context.Context) { // processNextWorkItem will read a single work item off the workqueue and // attempt to process it, by calling the reconcileHandler. func (c *Controller) processNextWorkItem(ctx context.Context) bool { - obj, shutdown := c.Queue.Get() + id, shutdown := c.Queue.Get() if shutdown { // Stop working return false @@ -141,35 +142,24 @@ func (c *Controller) processNextWorkItem(ctx context.Context) bool { // not call Forget if a transient error occurs, instead the item is // put back on the workqueue and attempted again after a back-off // period. - defer c.Queue.Done(obj) - c.reconcileHandler(ctx, obj) + defer c.Queue.Done(id) + c.reconcileHandler(ctx, id) return true } -func (c *Controller) reconcileHandler(ctx context.Context, obj interface{}) { +func (c *Controller) reconcileHandler(ctx context.Context, id string) { log := log.FromContext(ctx) - // Make sure that the object is a valid request. - req, ok := obj.(string) - if !ok { - // As the item in the workqueue is actually invalid, we call - // Forget here else we'd go into a loop of attempting to - // process a work item that is invalid. - c.Queue.Forget(obj) - // Return true, don't take a break - return - } - reconcileID := uuid.NewUUID() ctx = addReconcileID(ctx, reconcileID) // RunInformersAndControllers the syncHandler, passing it the Namespace/Name string of the // resource to be synced. log.V(5).Info("Reconciling") - result, err := c.Reconcile(ctx, req) + result, err := c.Reconcile(ctx, id) switch { case err != nil: - c.Queue.AddRateLimited(req) + c.Queue.AddRateLimited(id) if !result.IsZero() { log.V(1).Info("Warning: Reconciler returned both a non-zero result and a non-nil error. The result will always be ignored if the error is non-nil and the non-nil error causes reqeueuing with exponential backoff. For more details, see: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile#Reconciler") @@ -181,16 +171,16 @@ func (c *Controller) reconcileHandler(ctx context.Context, obj interface{}) { // along with a non-nil error. But this is intended as // We need to drive to stable reconcile loops before queuing due // to result.RequestAfter - c.Queue.Forget(obj) - c.Queue.AddAfter(req, result.RequeueAfter) + c.Queue.Forget(id) + c.Queue.AddAfter(id, result.RequeueAfter) case result.Requeue: log.V(5).Info("Reconcile done, requeueing") - c.Queue.AddRateLimited(req) + c.Queue.AddRateLimited(id) default: log.V(5).Info("Reconcile successful") // Finally, if no error occurs we Forget this item so it does not // get queued again until another change happens. - c.Queue.Forget(obj) + c.Queue.Forget(id) } } diff --git a/pkg/controller/namespaces/reconciler.go b/pkg/controller/namespaces/reconciler.go index e832cab2..067a90e4 100644 --- a/pkg/controller/namespaces/reconciler.go +++ b/pkg/controller/namespaces/reconciler.go @@ -8,11 +8,6 @@ import ( "time" console "github.com/pluralsh/console/go/client" - clienterrors "github.com/pluralsh/deployment-operator/internal/errors" - "github.com/pluralsh/deployment-operator/internal/utils" - "github.com/pluralsh/deployment-operator/pkg/client" - "github.com/pluralsh/deployment-operator/pkg/controller" - "github.com/pluralsh/deployment-operator/pkg/websocket" "github.com/pluralsh/polly/algorithms" v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -21,12 +16,18 @@ import ( ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + clienterrors "github.com/pluralsh/deployment-operator/internal/errors" + "github.com/pluralsh/deployment-operator/internal/utils" + "github.com/pluralsh/deployment-operator/pkg/client" + "github.com/pluralsh/deployment-operator/pkg/controller" + "github.com/pluralsh/deployment-operator/pkg/websocket" ) type NamespaceReconciler struct { ConsoleClient client.Client K8sClient ctrlclient.Client - NamespaceQueue workqueue.RateLimitingInterface + NamespaceQueue workqueue.TypedRateLimitingInterface[string] NamespaceCache *client.Cache[console.ManagedNamespaceFragment] } @@ -34,7 +35,7 @@ func NewNamespaceReconciler(consoleClient client.Client, k8sClient ctrlclient.Cl return &NamespaceReconciler{ ConsoleClient: consoleClient, K8sClient: k8sClient, - NamespaceQueue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()), + NamespaceQueue: workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[string]()), NamespaceCache: client.NewCache[console.ManagedNamespaceFragment](refresh, func(id string) (*console.ManagedNamespaceFragment, error) { return consoleClient.GetNamespace(id) }), diff --git a/pkg/controller/namespaces/socket_publisher.go b/pkg/controller/namespaces/socket_publisher.go index 12aaa803..6b1e70f9 100644 --- a/pkg/controller/namespaces/socket_publisher.go +++ b/pkg/controller/namespaces/socket_publisher.go @@ -8,7 +8,7 @@ import ( ) type socketPublisher struct { - restoreQueue workqueue.RateLimitingInterface + restoreQueue workqueue.TypedRateLimitingInterface[string] restoreCache *client.Cache[console.ManagedNamespaceFragment] } diff --git a/pkg/controller/pipelinegates/reconciler.go b/pkg/controller/pipelinegates/reconciler.go index 80b92949..42690ece 100644 --- a/pkg/controller/pipelinegates/reconciler.go +++ b/pkg/controller/pipelinegates/reconciler.go @@ -31,7 +31,7 @@ type GateReconciler struct { Config *rest.Config Clientset *kubernetes.Clientset GateCache *client.Cache[console.PipelineGateFragment] - GateQueue workqueue.RateLimitingInterface + GateQueue workqueue.TypedRateLimitingInterface[string] UtilFactory util.Factory discoveryClient *discovery.DiscoveryClient pinger *ping.Pinger @@ -51,7 +51,7 @@ func NewGateReconciler(consoleClient client.Client, k8sClient ctrlclient.Client, return consoleClient.GetClusterGate(id) }) - gateQueue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()) + gateQueue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[string]()) f := utils.NewFactory(config) diff --git a/pkg/controller/pipelinegates/socket_publisher.go b/pkg/controller/pipelinegates/socket_publisher.go index ed9b4584..c1977742 100644 --- a/pkg/controller/pipelinegates/socket_publisher.go +++ b/pkg/controller/pipelinegates/socket_publisher.go @@ -2,13 +2,14 @@ package pipelinegates import ( console "github.com/pluralsh/console/go/client" + "github.com/pluralsh/deployment-operator/pkg/client" "k8s.io/client-go/util/workqueue" ) type socketPublisher struct { - gateQueue workqueue.RateLimitingInterface + gateQueue workqueue.TypedRateLimitingInterface[string] gateCache *client.Cache[console.PipelineGateFragment] } diff --git a/pkg/controller/restore/reconciler.go b/pkg/controller/restore/reconciler.go index 34b6b8e0..67a5e6aa 100644 --- a/pkg/controller/restore/reconciler.go +++ b/pkg/controller/restore/reconciler.go @@ -6,9 +6,6 @@ import ( "time" console "github.com/pluralsh/console/go/client" - "github.com/pluralsh/deployment-operator/pkg/client" - plrlerrors "github.com/pluralsh/deployment-operator/pkg/errors" - "github.com/pluralsh/deployment-operator/pkg/websocket" velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -16,6 +13,10 @@ import ( ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + "github.com/pluralsh/deployment-operator/pkg/client" + plrlerrors "github.com/pluralsh/deployment-operator/pkg/errors" + "github.com/pluralsh/deployment-operator/pkg/websocket" ) var ( @@ -46,7 +47,7 @@ var ( type RestoreReconciler struct { ConsoleClient client.Client K8sClient ctrlclient.Client - RestoreQueue workqueue.RateLimitingInterface + RestoreQueue workqueue.TypedRateLimitingInterface[string] RestoreCache *client.Cache[console.ClusterRestoreFragment] Namespace string } @@ -55,7 +56,7 @@ func NewRestoreReconciler(consoleClient client.Client, k8sClient ctrlclient.Clie return &RestoreReconciler{ ConsoleClient: consoleClient, K8sClient: k8sClient, - RestoreQueue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()), + RestoreQueue: workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[string]()), RestoreCache: client.NewCache[console.ClusterRestoreFragment](refresh, func(id string) (*console.ClusterRestoreFragment, error) { return consoleClient.GetClusterRestore(id) }), diff --git a/pkg/controller/restore/socket_publisher.go b/pkg/controller/restore/socket_publisher.go index bff5b537..1e6f2194 100644 --- a/pkg/controller/restore/socket_publisher.go +++ b/pkg/controller/restore/socket_publisher.go @@ -2,12 +2,13 @@ package restore import ( console "github.com/pluralsh/console/go/client" - "github.com/pluralsh/deployment-operator/pkg/client" "k8s.io/client-go/util/workqueue" + + "github.com/pluralsh/deployment-operator/pkg/client" ) type socketPublisher struct { - restoreQueue workqueue.RateLimitingInterface + restoreQueue workqueue.TypedRateLimitingInterface[string] restoreCache *client.Cache[console.ClusterRestoreFragment] } diff --git a/pkg/controller/service/reconciler.go b/pkg/controller/service/reconciler.go index 11ab424c..c657184d 100644 --- a/pkg/controller/service/reconciler.go +++ b/pkg/controller/service/reconciler.go @@ -57,7 +57,7 @@ type ServiceReconciler struct { Clientset *kubernetes.Clientset Applier *applier.Applier Destroyer *apply.Destroyer - SvcQueue workqueue.RateLimitingInterface + SvcQueue workqueue.TypedRateLimitingInterface[string] SvcCache *client.Cache[console.GetServiceDeploymentForAgent_ServiceDeployment] ManifestCache *manifests.ManifestCache UtilFactory util.Factory @@ -84,7 +84,7 @@ func NewServiceReconciler(ctx context.Context, consoleClient client.Client, conf return consoleClient.GetService(id) }) - svcQueue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()) + svcQueue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[string]()) manifestCache := manifests.NewCache(manifestTTL, deployToken, consoleURL) diff --git a/pkg/controller/service/socket_publisher.go b/pkg/controller/service/socket_publisher.go index 68f7ecbf..93a9decf 100644 --- a/pkg/controller/service/socket_publisher.go +++ b/pkg/controller/service/socket_publisher.go @@ -10,7 +10,7 @@ import ( ) type socketPublisher struct { - svcQueue workqueue.RateLimitingInterface + svcQueue workqueue.TypedRateLimitingInterface[string] svcCache *client.Cache[console.GetServiceDeploymentForAgent_ServiceDeployment] manCache *manifests.ManifestCache } diff --git a/pkg/controller/stacks/reconciler.go b/pkg/controller/stacks/reconciler.go index f2af842d..58acf597 100644 --- a/pkg/controller/stacks/reconciler.go +++ b/pkg/controller/stacks/reconciler.go @@ -6,21 +6,22 @@ import ( "time" console "github.com/pluralsh/console/go/client" - clienterrors "github.com/pluralsh/deployment-operator/internal/errors" - "github.com/pluralsh/deployment-operator/pkg/client" - "github.com/pluralsh/deployment-operator/pkg/controller" - "github.com/pluralsh/deployment-operator/pkg/websocket" "github.com/pluralsh/polly/algorithms" "k8s.io/client-go/util/workqueue" ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + clienterrors "github.com/pluralsh/deployment-operator/internal/errors" + "github.com/pluralsh/deployment-operator/pkg/client" + "github.com/pluralsh/deployment-operator/pkg/controller" + "github.com/pluralsh/deployment-operator/pkg/websocket" ) type StackReconciler struct { ConsoleClient client.Client K8sClient ctrlclient.Client - StackQueue workqueue.RateLimitingInterface + StackQueue workqueue.TypedRateLimitingInterface[string] StackCache *client.Cache[console.StackRunFragment] Namespace string ConsoleURL string @@ -32,7 +33,7 @@ func NewStackReconciler(consoleClient client.Client, k8sClient ctrlclient.Client return &StackReconciler{ ConsoleClient: consoleClient, K8sClient: k8sClient, - StackQueue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()), + StackQueue: workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[string]()), StackCache: client.NewCache[console.StackRunFragment](refresh, func(id string) (*console.StackRunFragment, error) { return consoleClient.GetStackRun(id) }), diff --git a/pkg/controller/stacks/socket_publisher.go b/pkg/controller/stacks/socket_publisher.go index 4005993c..5bc75d59 100644 --- a/pkg/controller/stacks/socket_publisher.go +++ b/pkg/controller/stacks/socket_publisher.go @@ -8,7 +8,7 @@ import ( ) type socketPublisher struct { - stackRunQueue workqueue.RateLimitingInterface + stackRunQueue workqueue.TypedRateLimitingInterface[string] stackRunCache *client.Cache[console.StackRunFragment] }