From 93ddc7e9b52aa8fddca003104008d1b7e240bc33 Mon Sep 17 00:00:00 2001 From: Etai Lev Ran Date: Tue, 29 Jul 2025 14:44:40 +0300 Subject: [PATCH 1/2] update golangci-lint to v2 Signed-off-by: Etai Lev Ran --- .golangci.yml | 59 +++++++++++++++++++++++++++++++-------------------- Makefile | 6 +++--- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d1b1e112a..6fc800967 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,41 +1,54 @@ +version: "2" run: - timeout: 5m allow-parallel-runners: true - -# Settings related to issues -issues: - # Which dirs to exclude: issues from them won't be reported - exclude-dirs: - - bin linters: - disable-all: true + default: none enable: - copyloopvar - dupword - durationcheck + - errcheck - fatcontext - ginkgolinter + - goconst - gocritic - govet + - ineffassign - loggercheck + - makezero - misspell + - nakedret - perfsprint + - prealloc - revive + - staticcheck - unconvert - - makezero - - errcheck - - goconst - - gofmt - - goimports - - gosimple - - ineffassign - - nakedret - - prealloc - - typecheck - unparam - unused - -linters-settings: - revive: - rules: - - name: comment-spacings + settings: + revive: + rules: + - name: comment-spacings + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - bin + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - bin + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index d924f60a6..9e6e5a7ba 100644 --- a/Makefile +++ b/Makefile @@ -149,7 +149,7 @@ test-e2e: ## Run end-to-end tests against an existing Kubernetes cluster. .PHONY: lint lint: golangci-lint ## Run golangci-lint linter - $(GOLANGCI_LINT) run + $(GOLANGCI_LINT) run --timeout 5m .PHONY: lint-fix lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes @@ -373,7 +373,7 @@ GCI = $(LOCALBIN)/gci KUSTOMIZE_VERSION ?= v5.4.3 CONTROLLER_TOOLS_VERSION ?= v0.16.1 ENVTEST_VERSION ?= release-0.19 -GOLANGCI_LINT_VERSION ?= v1.62.2 +GOLANGCI_LINT_VERSION ?= v2.3.0 HELM_VERSION ?= v3.17.1 KUBECTL_VALIDATE_VERSION ?= v0.0.4 GCI_VERSION ?= v0.13.6 @@ -396,7 +396,7 @@ $(ENVTEST): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) .PHONY: yq yq: ## Download yq locally if necessary. From 45db9d45b32547ce3caed5715dce3da3ecf9bf33 Mon Sep 17 00:00:00 2001 From: Etai Lev Ran Date: Tue, 29 Jul 2025 14:46:03 +0300 Subject: [PATCH 2/2] fix v2 lint issues Signed-off-by: Etai Lev Ran --- conformance/conformance.go | 2 +- .../tests/basic/gateway_following_epp_routing.go | 5 ++--- conformance/utils/kubernetes/helpers.go | 6 +++--- pkg/bbr/handlers/request.go | 15 +++++++-------- pkg/epp/datastore/datastore.go | 4 ++-- pkg/epp/util/testing/wrappers.go | 4 ++-- pkg/generator/main.go | 6 +++--- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/conformance/conformance.go b/conformance/conformance.go index 97ce63eb2..c71656e4e 100644 --- a/conformance/conformance.go +++ b/conformance/conformance.go @@ -296,7 +296,7 @@ func ensureGatewayAvailableAndReady(t *testing.T, k8sClient client.Client, opts extTimeoutConf := inferenceconfig.DefaultInferenceExtensionTimeoutConfig() // Use the GatewayMustHaveAddress timeout from the suite's base TimeoutConfig for the Gateway object to appear. - waitForGatewayCreationTimeout := extTimeoutConf.TimeoutConfig.GatewayMustHaveAddress + waitForGatewayCreationTimeout := extTimeoutConf.GatewayMustHaveAddress logDebugf(t, opts.Debug, "Waiting up to %v for Gateway object %s/%s to appear after manifest application...", waitForGatewayCreationTimeout, gatewayNN.Namespace, gatewayNN.Name) diff --git a/conformance/tests/basic/gateway_following_epp_routing.go b/conformance/tests/basic/gateway_following_epp_routing.go index 83d0e2b5a..e95463331 100644 --- a/conformance/tests/basic/gateway_following_epp_routing.go +++ b/conformance/tests/basic/gateway_following_epp_routing.go @@ -33,7 +33,6 @@ import ( "sigs.k8s.io/gateway-api-inference-extension/conformance/tests" k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes" "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic" - trafficutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic" ) func init() { @@ -94,12 +93,12 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{ for i := 0; i < len(pods); i++ { // Send an initial request targeting a single pod and wait for it to be successful to ensure the Gateway and EPP // are functioning correctly before running the main test cases. - trafficutils.MakeRequestAndExpectSuccess( + traffic.MakeRequestAndExpectSuccess( t, s.RoundTripper, s.TimeoutConfig, gwAddr, - trafficutils.Request{ + traffic.Request{ Host: hostname, Path: path, Headers: map[string]string{eppSelectionHeaderName: podIPs[i]}, diff --git a/conformance/utils/kubernetes/helpers.go b/conformance/utils/kubernetes/helpers.go index 888478807..83aa3dae8 100644 --- a/conformance/utils/kubernetes/helpers.go +++ b/conformance/utils/kubernetes/helpers.go @@ -72,7 +72,7 @@ func checkCondition(t *testing.T, conditions []metav1.Condition, expectedConditi func InferencePoolMustHaveCondition(t *testing.T, c client.Reader, poolNN types.NamespacedName, expectedCondition metav1.Condition) { t.Helper() // Marks this function as a test helper - var timeoutConfig config.InferenceExtensionTimeoutConfig = config.DefaultInferenceExtensionTimeoutConfig() + var timeoutConfig = config.DefaultInferenceExtensionTimeoutConfig() var lastObservedPool *inferenceapi.InferencePool var lastError error var conditionFound bool @@ -165,7 +165,7 @@ func InferencePoolMustHaveNoParents(t *testing.T, c client.Reader, poolNN types. var lastObservedPool *inferenceapi.InferencePool var lastError error - var timeoutConfig config.InferenceExtensionTimeoutConfig = config.DefaultInferenceExtensionTimeoutConfig() + var timeoutConfig = config.DefaultInferenceExtensionTimeoutConfig() ctx := context.Background() waitErr := wait.PollUntilContextTimeout( @@ -286,7 +286,7 @@ func HTTPRouteAndInferencePoolMustBeAcceptedAndRouteAccepted( gatewayNN types.NamespacedName, poolNN types.NamespacedName) { t.Helper() - var timeoutConfig config.InferenceExtensionTimeoutConfig = config.DefaultInferenceExtensionTimeoutConfig() + var timeoutConfig = config.DefaultInferenceExtensionTimeoutConfig() HTTPRouteMustBeAcceptedAndResolved(t, c, timeoutConfig.TimeoutConfig, routeNN, gatewayNN) InferencePoolMustBeRouteAccepted(t, c, poolNN) diff --git a/pkg/bbr/handlers/request.go b/pkg/bbr/handlers/request.go index 1145e6ecf..98cd24578 100644 --- a/pkg/bbr/handlers/request.go +++ b/pkg/bbr/handlers/request.go @@ -23,7 +23,6 @@ import ( basepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" eppb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3" - extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/gateway-api-inference-extension/pkg/bbr/metrics" @@ -122,13 +121,13 @@ func (s *Server) HandleRequestBody(ctx context.Context, requestBodyBytes []byte) } func addStreamedBodyResponse(responses []*eppb.ProcessingResponse, requestBodyBytes []byte) []*eppb.ProcessingResponse { - return append(responses, &extProcPb.ProcessingResponse{ - Response: &extProcPb.ProcessingResponse_RequestBody{ - RequestBody: &extProcPb.BodyResponse{ - Response: &extProcPb.CommonResponse{ - BodyMutation: &extProcPb.BodyMutation{ - Mutation: &extProcPb.BodyMutation_StreamedResponse{ - StreamedResponse: &extProcPb.StreamedBodyResponse{ + return append(responses, &eppb.ProcessingResponse{ + Response: &eppb.ProcessingResponse_RequestBody{ + RequestBody: &eppb.BodyResponse{ + Response: &eppb.CommonResponse{ + BodyMutation: &eppb.BodyMutation{ + Mutation: &eppb.BodyMutation_StreamedResponse{ + StreamedResponse: &eppb.StreamedBodyResponse{ Body: requestBodyBytes, EndOfStream: true, }, diff --git a/pkg/epp/datastore/datastore.go b/pkg/epp/datastore/datastore.go index 7275d6fff..bf6c1aecb 100644 --- a/pkg/epp/datastore/datastore.go +++ b/pkg/epp/datastore/datastore.go @@ -175,7 +175,7 @@ func (ds *datastore) ModelSetIfOlder(infModel *v1alpha2.InferenceModel) bool { existing, exists := ds.models[infModel.Spec.ModelName] if exists { diffObj := infModel.Name != existing.Name || infModel.Namespace != existing.Namespace - if diffObj && existing.ObjectMeta.CreationTimestamp.Before(&infModel.ObjectMeta.CreationTimestamp) { + if diffObj && existing.CreationTimestamp.Before(&infModel.CreationTimestamp) { return false } } @@ -205,7 +205,7 @@ func (ds *datastore) ModelResync(ctx context.Context, reader client.Reader, mode !m.DeletionTimestamp.IsZero() { // ignore objects marked for deletion continue } - if oldest == nil || m.ObjectMeta.CreationTimestamp.Before(&oldest.ObjectMeta.CreationTimestamp) { + if oldest == nil || m.CreationTimestamp.Before(&oldest.CreationTimestamp) { oldest = m } } diff --git a/pkg/epp/util/testing/wrappers.go b/pkg/epp/util/testing/wrappers.go index 24102dc19..c5b02da4e 100644 --- a/pkg/epp/util/testing/wrappers.go +++ b/pkg/epp/util/testing/wrappers.go @@ -101,7 +101,7 @@ func (p *PodWrapper) IP(ip string) *PodWrapper { func (p *PodWrapper) DeletionTimestamp() *PodWrapper { now := metav1.Now() p.ObjectMeta.DeletionTimestamp = &now - p.ObjectMeta.Finalizers = []string{"finalizer"} + p.Finalizers = []string{"finalizer"} return p } @@ -160,7 +160,7 @@ func (m *InferenceModelWrapper) Criticality(criticality v1alpha2.Criticality) *I func (m *InferenceModelWrapper) DeletionTimestamp() *InferenceModelWrapper { now := metav1.Now() m.ObjectMeta.DeletionTimestamp = &now - m.ObjectMeta.Finalizers = []string{"finalizer"} + m.Finalizers = []string{"finalizer"} return m } diff --git a/pkg/generator/main.go b/pkg/generator/main.go index 641cc127b..3cb70a508 100644 --- a/pkg/generator/main.go +++ b/pkg/generator/main.go @@ -79,10 +79,10 @@ func main() { crdRaw := parser.CustomResourceDefinitions[groupKind] // Inline version of "addAttribution(&crdRaw)" ... - if crdRaw.ObjectMeta.Annotations == nil { - crdRaw.ObjectMeta.Annotations = map[string]string{} + if crdRaw.Annotations == nil { + crdRaw.Annotations = map[string]string{} } - crdRaw.ObjectMeta.Annotations[version.BundleVersionAnnotation] = version.BundleVersion + crdRaw.Annotations[version.BundleVersionAnnotation] = version.BundleVersion // Prevent the top level metadata for the CRD to be generated regardless of the intention in the arguments crd.FixTopLevelMetadata(crdRaw)