From 436112252d4b51f515fe521ebc367618f9611ff8 Mon Sep 17 00:00:00 2001 From: Joshua Casey Date: Mon, 19 Aug 2024 10:37:53 -0500 Subject: [PATCH] Lint fixes --- internal/concierge/impersonator/impersonator.go | 2 +- internal/controllerlib/controller.go | 6 +++--- internal/controllerlib/option.go | 7 +++++-- internal/controllerlib/queue.go | 4 ++-- internal/registry/clientsecretrequest/rest.go | 6 +++--- internal/supervisor/server/server.go | 2 +- internal/testutil/actions.go | 7 ++++--- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/internal/concierge/impersonator/impersonator.go b/internal/concierge/impersonator/impersonator.go index 16ab0ccf8..c6d3179a2 100644 --- a/internal/concierge/impersonator/impersonator.go +++ b/internal/concierge/impersonator/impersonator.go @@ -176,7 +176,7 @@ func newInternal( // See sanity checks at the end of this function. serverConfig.LoopbackClientConfig.BearerToken = "" - // match KAS exactly since our long running operations are just a proxy to it + // match KAS exactly since our long-running operations are just a proxy to it // this must be kept in sync with github.com/kubernetes/kubernetes/cmd/kube-apiserver/app/server.go // this is nothing to stress about - it has not changed since the beginning of Kube: // v1.6 no-op move away from regex to request info https://github.com/kubernetes/kubernetes/pull/38119 diff --git a/internal/controllerlib/controller.go b/internal/controllerlib/controller.go index 9ce2e4841..3f0e42d94 100644 --- a/internal/controllerlib/controller.go +++ b/internal/controllerlib/controller.go @@ -1,4 +1,4 @@ -// Copyright 2020-2023 the Pinniped contributors. All Rights Reserved. +// Copyright 2020-2024 the Pinniped contributors. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 package controllerlib @@ -61,7 +61,7 @@ func New(config Config, opts ...Option) Controller { } // set up defaults - WithRateLimiter(workqueue.DefaultControllerRateLimiter())(c) + WithRateLimiter(workqueue.DefaultTypedControllerRateLimiter[any]())(c) WithRecorder(klogRecorder{})(c) for _, opt := range opts { @@ -74,7 +74,7 @@ func New(config Config, opts ...Option) Controller { type controller struct { config Config - queue workqueue.RateLimitingInterface + queue workqueue.TypedRateLimitingInterface[any] queueWrapper Queue maxRetries int recorder events.EventRecorder diff --git a/internal/controllerlib/option.go b/internal/controllerlib/option.go index f74958268..89548e3be 100644 --- a/internal/controllerlib/option.go +++ b/internal/controllerlib/option.go @@ -31,9 +31,12 @@ func WithInitialEvent(key Key) Option { }) } -func WithRateLimiter(limiter workqueue.RateLimiter) Option { +func WithRateLimiter(limiter workqueue.TypedRateLimiter[any]) Option { return func(c *controller) { - c.queue = workqueue.NewNamedRateLimitingQueue(limiter, c.Name()) + cfg := workqueue.TypedRateLimitingQueueConfig[any]{ + Name: c.Name(), + } + c.queue = workqueue.NewTypedRateLimitingQueueWithConfig(limiter, cfg) c.queueWrapper = &queueWrapper{queue: c.queue} } } diff --git a/internal/controllerlib/queue.go b/internal/controllerlib/queue.go index 7de4040b8..f5da4e6b4 100644 --- a/internal/controllerlib/queue.go +++ b/internal/controllerlib/queue.go @@ -1,4 +1,4 @@ -// Copyright 2020 the Pinniped contributors. All Rights Reserved. +// Copyright 2020-2024 the Pinniped contributors. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 package controllerlib @@ -23,7 +23,7 @@ type Queue interface { var _ Queue = &queueWrapper{} type queueWrapper struct { - queue workqueue.RateLimitingInterface + queue workqueue.TypedRateLimitingInterface[any] } func (q *queueWrapper) Add(key Key) { diff --git a/internal/registry/clientsecretrequest/rest.go b/internal/registry/clientsecretrequest/rest.go index 3973fa55b..4ac86fb59 100644 --- a/internal/registry/clientsecretrequest/rest.go +++ b/internal/registry/clientsecretrequest/rest.go @@ -240,9 +240,9 @@ func (r *REST) validateRequest( // Ensure namespace on the object is correct, or error if a conflicting namespace was set in the object. requestNamespace, ok := genericapirequest.NamespaceFrom(ctx) if !ok { - msg := "no namespace information found in request context" - traceValidationFailure(tracer, msg) - return nil, apierrors.NewInternalError(errors.New(msg)) + const errorMsg = "no namespace information found in request context" + traceValidationFailure(tracer, errorMsg) + return nil, apierrors.NewInternalError(errors.New(errorMsg)) } if err := rest.EnsureObjectNamespaceMatchesRequestNamespace(requestNamespace, clientSecretRequest); err != nil { traceValidationFailure(tracer, err.Error()) diff --git a/internal/supervisor/server/server.go b/internal/supervisor/server/server.go index c2fdceb4b..5aa4270af 100644 --- a/internal/supervisor/server/server.go +++ b/internal/supervisor/server/server.go @@ -611,7 +611,7 @@ func runSupervisor(ctx context.Context, podInfo *downward.PodInfo, cfg *supervis // Run the server. Its post-start hook will start the controllers. Its pre shutdown hook will be called when ctx is // cancelled, and that hook should graceful stop the controllers and give up the leader election lease. See the // code for these hooks in internal/supervisor/apiserver.go. - err = server.GenericAPIServer.PrepareRun().Run(ctx.Done()) + err = server.GenericAPIServer.PrepareRun().RunWithContext(ctx) if err != nil { return err } diff --git a/internal/testutil/actions.go b/internal/testutil/actions.go index f78ee892e..5523e686f 100644 --- a/internal/testutil/actions.go +++ b/internal/testutil/actions.go @@ -17,20 +17,21 @@ func ScrubListOptionsForActions(t *testing.T, actions []coretesting.Action) []co scrubbedActions := make([]coretesting.Action, 0, len(actions)) for _, action := range actions { - if action.GetVerb() == "watch" { + switch action.GetVerb() { + case "watch": watchAction, ok := action.(coretesting.WatchActionImpl) require.True(t, ok) watchAction.ListOptions.AllowWatchBookmarks = false watchAction.ListOptions.TimeoutSeconds = nil scrubbedActions = append(scrubbedActions, watchAction) - } else if action.GetVerb() == "list" { + case "list": listAction, ok := action.(coretesting.ListActionImpl) require.True(t, ok) listAction.ListOptions.ResourceVersion = "" listAction.ListOptions.TimeoutSeconds = nil listAction.ListOptions.Limit = 0 scrubbedActions = append(scrubbedActions, listAction) - } else { + default: scrubbedActions = append(scrubbedActions, action) } }