From c7471aa9c13a199b5b2f13239a37d54c923a1ccf Mon Sep 17 00:00:00 2001 From: Vicente Ferrara Date: Thu, 19 Sep 2024 00:18:12 +0000 Subject: [PATCH] lint fixes --- build/report/report.go | 1 - cmd/allocator/main.go | 18 +-- cmd/allocator/main_test.go | 8 +- cmd/ping/main.go | 2 +- cmd/ping/udp_test.go | 2 +- cmd/sdk-server/main_test.go | 2 +- pkg/apis/agones/v1/gameserver_test.go | 6 +- .../allocation/v1/gameserverallocation.go | 2 +- pkg/cloudproduct/gke/gke.go | 4 +- pkg/fleetautoscalers/controller_test.go | 72 +++++------ pkg/fleetautoscalers/fleetautoscalers_test.go | 8 +- pkg/fleets/controller_test.go | 114 +++++++++--------- pkg/fleets/fleets_test.go | 4 +- pkg/gameserverallocations/allocation_cache.go | 4 +- .../allocation_cache_test.go | 8 +- pkg/gameserverallocations/allocator_test.go | 24 ++-- pkg/gameserverallocations/cache_test.go | 2 +- pkg/gameserverallocations/controller.go | 2 +- pkg/gameserverallocations/controller_test.go | 49 ++++---- pkg/gameserverallocations/find_test.go | 4 +- pkg/gameserverallocations/metrics_test.go | 8 +- pkg/gameservers/controller.go | 2 +- pkg/gameservers/controller_test.go | 84 ++++++------- pkg/gameservers/health.go | 2 +- pkg/gameservers/health_test.go | 18 +-- pkg/gameservers/migration_test.go | 10 +- pkg/gameservers/missing_test.go | 16 +-- pkg/gameservers/pernodecounter_test.go | 2 +- pkg/gameserversets/allocation_overflow.go | 2 +- .../allocation_overflow_test.go | 6 +- pkg/gameserversets/controller.go | 3 +- pkg/gameserversets/controller_test.go | 32 ++--- .../gameserver_state_cache_test.go | 2 +- pkg/gameserversets/gameserversets_test.go | 2 +- pkg/metrics/controller.go | 8 +- pkg/metrics/controller_test.go | 6 +- pkg/metrics/kubernetes_client.go | 2 +- pkg/portallocator/portallocator_test.go | 14 +-- pkg/sdkserver/helper_test.go | 10 +- pkg/sdkserver/localsdk.go | 25 ++-- pkg/sdkserver/localsdk_test.go | 22 ++-- pkg/sdkserver/sdkserver.go | 32 ++--- pkg/sdkserver/sdkserver_test.go | 50 ++++---- pkg/testing/apihooks.go | 4 +- pkg/util/apiserver/apiserver.go | 6 +- pkg/util/crd/crd.go | 2 +- pkg/util/crd/crd_test.go | 4 +- pkg/util/https/https.go | 2 +- pkg/util/https/server.go | 4 +- pkg/util/https/server_test.go | 2 +- pkg/util/runtime/runtime.go | 2 +- pkg/util/runtime/runtime_test.go | 2 +- pkg/util/workerqueue/workerqueue_test.go | 14 +-- sdks/go/alpha_test.go | 14 +-- sdks/go/beta_test.go | 12 +- sdks/go/sdk_test.go | 26 ++-- test/e2e/allocator/pod_termination_test.go | 2 +- test/e2e/allocator_test.go | 4 +- test/e2e/fleet_test.go | 44 +++---- test/e2e/fleetautoscaler_test.go | 24 ++-- test/e2e/framework/framework.go | 17 +-- test/e2e/gameserver_test.go | 12 +- test/e2e/gameserverallocation_test.go | 4 +- 63 files changed, 449 insertions(+), 446 deletions(-) diff --git a/build/report/report.go b/build/report/report.go index 810b89c5d0..bfdfd579ea 100644 --- a/build/report/report.go +++ b/build/report/report.go @@ -153,7 +153,6 @@ func main() { } if err != nil { log.Fatalf("error listing builds: %v", err) - break } createTime := resp.CreateTime.AsTime() if createTime.Before(windowStart) { diff --git a/cmd/allocator/main.go b/cmd/allocator/main.go index 4c6caea7df..d4f7f016fa 100644 --- a/cmd/allocator/main.go +++ b/cmd/allocator/main.go @@ -382,10 +382,10 @@ func runHTTP(listenCtx context.Context, workerCtx context.Context, h *serviceHan if err == http.ErrServerClosed { logger.WithError(err).Info("HTTP/HTTPS server closed") os.Exit(0) - } else { - logger.WithError(err).Fatal("Unable to start HTTP/HTTPS listener") - os.Exit(1) } + logger.WithError(err).Fatal("Unable to start HTTP/HTTPS listener") + os.Exit(1) + }() } @@ -411,10 +411,10 @@ func runGRPC(ctx context.Context, h *serviceHandler, grpcHealth *grpchealth.Serv if err != nil { logger.WithError(err).Fatal("allocation service crashed") os.Exit(1) - } else { - logger.Info("allocation server closed") - os.Exit(0) } + logger.Info("allocation server closed") + os.Exit(0) + }() } @@ -534,7 +534,7 @@ func (h *serviceHandler) getGRPCServerOptions() []grpc.ServerOption { return append([]grpc.ServerOption{grpc.Creds(credentials.NewTLS(cfg))}, opts...) } -func (h *serviceHandler) getTLSCert(ch *tls.ClientHelloInfo) (*tls.Certificate, error) { +func (h *serviceHandler) getTLSCert(_ *tls.ClientHelloInfo) (*tls.Certificate, error) { h.tlsMutex.RLock() defer h.tlsMutex.RUnlock() return h.tlsCert, nil @@ -542,7 +542,7 @@ func (h *serviceHandler) getTLSCert(ch *tls.ClientHelloInfo) (*tls.Certificate, // verifyClientCertificate verifies that the client certificate is accepted // This method is used as GetConfigForClient is cross lang incompatible. -func (h *serviceHandler) verifyClientCertificate(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error { +func (h *serviceHandler) verifyClientCertificate(rawCerts [][]byte, _ [][]*x509.Certificate) error { opts := x509.VerifyOptions{ Roots: h.caCertPool, CurrentTime: time.Now(), @@ -645,7 +645,7 @@ type serviceHandler struct { } // Allocate implements the Allocate gRPC method definition -func (h *serviceHandler) Allocate(ctx context.Context, in *pb.AllocationRequest) (*pb.AllocationResponse, error) { +func (h *serviceHandler) Allocate(_ context.Context, in *pb.AllocationRequest) (*pb.AllocationResponse, error) { logger.WithField("request", in).Infof("allocation request received.") gsa := converters.ConvertAllocationRequestToGSA(in) gsa.ApplyDefaults() diff --git a/cmd/allocator/main_test.go b/cmd/allocator/main_test.go index dacdbad168..df729d8714 100644 --- a/cmd/allocator/main_test.go +++ b/cmd/allocator/main_test.go @@ -37,7 +37,7 @@ func TestAllocateHandler(t *testing.T) { t.Parallel() h := serviceHandler{ - allocationCallback: func(gsa *allocationv1.GameServerAllocation) (k8sruntime.Object, error) { + allocationCallback: func(_ *allocationv1.GameServerAllocation) (k8sruntime.Object, error) { return &allocationv1.GameServerAllocation{ ObjectMeta: metav1.ObjectMeta{ Namespace: "default", @@ -71,7 +71,7 @@ func TestAllocateHandlerReturnsError(t *testing.T) { t.Parallel() h := serviceHandler{ - allocationCallback: func(gsa *allocationv1.GameServerAllocation) (k8sruntime.Object, error) { + allocationCallback: func(_ *allocationv1.GameServerAllocation) (k8sruntime.Object, error) { return nil, k8serror.NewBadRequest("error") }, } @@ -110,7 +110,7 @@ func TestHandlingStatus(t *testing.T) { errorMessage := "GameServerAllocation is invalid" h := serviceHandler{ - allocationCallback: func(gsa *allocationv1.GameServerAllocation) (k8sruntime.Object, error) { + allocationCallback: func(_ *allocationv1.GameServerAllocation) (k8sruntime.Object, error) { return &metav1.Status{ Status: metav1.StatusFailure, Message: errorMessage, @@ -142,7 +142,7 @@ func TestBadReturnType(t *testing.T) { t.Parallel() h := serviceHandler{ - allocationCallback: func(gsa *allocationv1.GameServerAllocation) (k8sruntime.Object, error) { + allocationCallback: func(_ *allocationv1.GameServerAllocation) (k8sruntime.Object, error) { return &corev1.Secret{}, nil }, } diff --git a/cmd/ping/main.go b/cmd/ping/main.go index 3eea91961c..0cb94390f1 100644 --- a/cmd/ping/main.go +++ b/cmd/ping/main.go @@ -82,7 +82,7 @@ func serveHTTP(ctlConf config, h healthcheck.Handler) func() { // add health check as well mux.HandleFunc("/live", h.LiveEndpoint) - mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { if _, err := w.Write([]byte(ctlConf.HTTPResponse)); err != nil { w.WriteHeader(http.StatusInternalServerError) logger.WithError(err).Error("Error responding to http request") diff --git a/cmd/ping/udp_test.go b/cmd/ping/udp_test.go index b8bc44e713..aeeb366f07 100644 --- a/cmd/ping/udp_test.go +++ b/cmd/ping/udp_test.go @@ -114,7 +114,7 @@ func TestUDPServerHealth(t *testing.T) { cancel() - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(_ context.Context) (bool, error) { return u.Health() != nil, nil }) diff --git a/cmd/sdk-server/main_test.go b/cmd/sdk-server/main_test.go index be2b45ed66..7c52d4d7d2 100644 --- a/cmd/sdk-server/main_test.go +++ b/cmd/sdk-server/main_test.go @@ -52,7 +52,7 @@ func TestHealthCheckWrapper(t *testing.T) { {"non-empty body", bytes.NewBuffer([]byte(`{}`)), http.StatusOK}, } - testWrapper := healthCheckWrapper(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + testWrapper := healthCheckWrapper(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })) diff --git a/pkg/apis/agones/v1/gameserver_test.go b/pkg/apis/agones/v1/gameserver_test.go index 2d59f2e1d4..4bedddef29 100644 --- a/pkg/apis/agones/v1/gameserver_test.go +++ b/pkg/apis/agones/v1/gameserver_test.go @@ -206,8 +206,8 @@ func TestGameServerApplyDefaults(t *testing.T) { expected expected }{ "set basic defaults on a very simple gameserver": { - gameServer: defaultGameServerAnd(func(gss *GameServerSpec) {}), - expected: wantDefaultAnd(func(e *expected) {}), + gameServer: defaultGameServerAnd(func(_ *GameServerSpec) {}), + expected: wantDefaultAnd(func(_ *expected) {}), }, "PlayerTracking=true": { featureFlags: string(runtime.FeaturePlayerTracking) + "=true", @@ -347,7 +347,7 @@ func TestGameServerApplyDefaults(t *testing.T) { }), }, "defaults are eviction.safe: Never": { - gameServer: defaultGameServerAnd(func(gss *GameServerSpec) {}), + gameServer: defaultGameServerAnd(func(_ *GameServerSpec) {}), expected: wantDefaultAnd(func(e *expected) { e.evictionSafeSpec = EvictionSafeNever e.evictionSafeStatus = EvictionSafeNever diff --git a/pkg/apis/allocation/v1/gameserverallocation.go b/pkg/apis/allocation/v1/gameserverallocation.go index 277e0e46bf..2e92775811 100644 --- a/pkg/apis/allocation/v1/gameserverallocation.go +++ b/pkg/apis/allocation/v1/gameserverallocation.go @@ -343,7 +343,7 @@ func (la *ListAction) ListActions(list string, gs *agonesv1.GameServer) error { errs = errors.Join(errs, capErr) } } - if la.AddValues != nil && len(la.AddValues) > 0 { + if len(la.AddValues) > 0 { cntErr := gs.AppendListValues(list, la.AddValues) if cntErr != nil { errs = errors.Join(errs, cntErr) diff --git a/pkg/cloudproduct/gke/gke.go b/pkg/cloudproduct/gke/gke.go index 144c131295..32efaa7d08 100644 --- a/pkg/cloudproduct/gke/gke.go +++ b/pkg/cloudproduct/gke/gke.go @@ -261,8 +261,8 @@ type autopilotPortAllocator struct { maxPort int32 } -func (*autopilotPortAllocator) Run(_ context.Context) error { return nil } -func (*autopilotPortAllocator) DeAllocate(gs *agonesv1.GameServer) {} +func (*autopilotPortAllocator) Run(_ context.Context) error { return nil } +func (*autopilotPortAllocator) DeAllocate(_ *agonesv1.GameServer) {} func checkPassthroughPortPolicyForAutopilot(portPolicy agonesv1.PortPolicy) bool { // Autopilot can have Dynamic or Passthrough diff --git a/pkg/fleetautoscalers/controller_test.go b/pkg/fleetautoscalers/controller_test.go index 2dbb45bf0c..17ddb503d9 100644 --- a/pkg/fleetautoscalers/controller_test.go +++ b/pkg/fleetautoscalers/controller_test.go @@ -295,20 +295,20 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { Time: time.Now(), } - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) - m.AgonesClient.AddReactor("update", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleetautoscaler should not update") return false, nil, nil }) - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("update", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleet should not update") return false, nil, nil }) @@ -335,7 +335,7 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { fUpdated := false fasUpdated := false - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) @@ -351,7 +351,7 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { return true, fas, nil }) - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) @@ -393,7 +393,7 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { fUpdated := false fasUpdated := false - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) @@ -409,7 +409,7 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { return true, fas, nil }) - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) @@ -451,20 +451,20 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { fas.Spec.Policy.Webhook.URL = &(server.URL) fas.Spec.Policy.Webhook.Service = nil - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) - m.AgonesClient.AddReactor("update", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleetautoscaler should not update") return false, nil, nil }) - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("update", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleet should not update") return false, nil, nil }) @@ -491,7 +491,7 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { fUpdated := false fasUpdated := false - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) @@ -507,7 +507,7 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { return true, fas, nil }) - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) @@ -545,20 +545,20 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { Time: time.Now(), } - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) - m.AgonesClient.AddReactor("update", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleetautoscaler should not update") return true, nil, nil }) - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("update", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleet should not update") return false, nil, nil @@ -584,16 +584,16 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { fas.Status.CurrentReplicas = 10 fas.Status.DesiredReplicas = 10 - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) - m.AgonesClient.AddReactor("update", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleetautoscaler should not update") return false, nil, nil }) - m.AgonesClient.AddReactor("update", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleet should not update") return false, nil, nil }) @@ -614,7 +614,7 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { fas.Status.CurrentReplicas = 5 updated := false - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) @@ -644,7 +644,7 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { fas.Status.DesiredReplicas = 10 fas.Status.CurrentReplicas = 5 - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) @@ -675,11 +675,11 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { Type: "WRONG TYPE", } - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) @@ -702,11 +702,11 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { Type: "WRONG TYPE", } - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) @@ -730,11 +730,11 @@ func TestControllerSyncFleetAutoscaler(t *testing.T) { c, m := newFakeController() fas, f := defaultFixtures() - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) @@ -817,7 +817,7 @@ func TestControllerScaleFleet(t *testing.T) { fas, f := defaultFixtures() replicas := f.Spec.Replicas - m.AgonesClient.AddReactor("update", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleet should not update") return false, nil, nil }) @@ -868,7 +868,7 @@ func TestControllerUpdateStatus(t *testing.T) { fas.Status.DesiredReplicas = 20 fas.Status.LastScaleTime = nil - m.AgonesClient.AddReactor("update", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "should not update") return false, nil, nil }) @@ -885,7 +885,7 @@ func TestControllerUpdateStatus(t *testing.T) { c, m := newFakeController() fas, _ := defaultFixtures() - m.AgonesClient.AddReactor("update", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, nil, errors.New("random-err") }) @@ -987,7 +987,7 @@ func TestControllerUpdateStatusUnableToScale(t *testing.T) { fas.Status.CurrentReplicas = 0 fas.Status.DesiredReplicas = 0 - m.AgonesClient.AddReactor("update", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "fleetautoscaler should not update") return false, nil, nil }) @@ -1048,12 +1048,12 @@ func TestControllerAddUpdateDeleteFasThread(t *testing.T) { var counter int64 c, m := newFakeController() - c.workerqueue.SyncHandler = func(ctx context.Context, s string) error { + c.workerqueue.SyncHandler = func(_ context.Context, _ string) error { atomic.AddInt64(&counter, 1) return nil } - m.ExtClient.AddReactor("get", "customresourcedefinitions", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.ExtClient.AddReactor("get", "customresourcedefinitions", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, agtesting.NewEstablishedCRD(), nil }) @@ -1138,7 +1138,7 @@ func TestControllerCleanFasThreads(t *testing.T) { c, m := newFakeController() fas, _ := defaultFixtures() - m.AgonesClient.AddReactor("list", "fleetautoscalers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleetautoscalers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &autoscalingv1.FleetAutoscalerList{Items: []autoscalingv1.FleetAutoscaler{*fas}}, nil }) diff --git a/pkg/fleetautoscalers/fleetautoscalers_test.go b/pkg/fleetautoscalers/fleetautoscalers_test.go index cdb07f9d7c..48a27b3588 100644 --- a/pkg/fleetautoscalers/fleetautoscalers_test.go +++ b/pkg/fleetautoscalers/fleetautoscalers_test.go @@ -103,7 +103,7 @@ func (t testServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - _, err = io.WriteString(w, string(result)) + _, err = w.Write(result) if err != nil { http.Error(w, "Error writing json from /address", http.StatusInternalServerError) return @@ -181,7 +181,7 @@ func TestComputeDesiredFleetSize(t *testing.T) { f.Status.ReadyReplicas = tc.statusReadyReplicas m := agtesting.NewMocks() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{}}, nil }) @@ -1435,7 +1435,7 @@ func TestApplyCounterPolicy(t *testing.T) { assert.NoError(t, err) m := agtesting.NewMocks() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: tc.gsList}, nil }) @@ -2115,7 +2115,7 @@ func TestApplyListPolicy(t *testing.T) { assert.NoError(t, err) m := agtesting.NewMocks() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: tc.gsList}, nil }) diff --git a/pkg/fleets/controller_test.go b/pkg/fleets/controller_test.go index 7db2b75cf6..a86b077fac 100644 --- a/pkg/fleets/controller_test.go +++ b/pkg/fleets/controller_test.go @@ -61,7 +61,7 @@ func TestControllerSyncFleet(t *testing.T) { c, m := newFakeController() created := false - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) @@ -96,20 +96,20 @@ func TestControllerSyncFleet(t *testing.T) { gsSet.ObjectMeta.UID = "4321" gsSet.Spec.Replicas = f.Spec.Replicas - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("create", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("create", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "gameserverset should not be created") return true, nil, nil }) - m.AgonesClient.AddReactor("update", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "gameserverset should not have been updated") return true, nil, nil }) @@ -132,11 +132,11 @@ func TestControllerSyncFleet(t *testing.T) { gsSet.Spec.Replicas = f.Spec.Replicas + 10 updated := false - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) @@ -170,11 +170,11 @@ func TestControllerSyncFleet(t *testing.T) { gsSet.Spec.Scheduling = apis.Distributed updated := false - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) @@ -213,11 +213,11 @@ func TestControllerSyncFleet(t *testing.T) { updated := false created := false - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) @@ -276,20 +276,20 @@ func TestControllerSyncFleet(t *testing.T) { gsSet.Spec.Scheduling = f.Spec.Scheduling gsSet.Status.Replicas = 5 - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("create", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("create", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "gameserverset should not have been created") return false, nil, nil }) - m.AgonesClient.AddReactor("update", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "gameserverset should not have been updated") return false, nil, nil }) @@ -315,7 +315,7 @@ func TestControllerSyncFleet(t *testing.T) { c, m := newFakeController() c.gameServerSetLister = &fakeGSSListerWithErr{} - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) @@ -344,11 +344,11 @@ func TestControllerSyncFleet(t *testing.T) { // make sure there is at least one replica, or the logic will escape before the check. gsSet.Spec.Replicas = 1 - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) @@ -367,15 +367,15 @@ func TestControllerSyncFleet(t *testing.T) { // make gsSet.Spec.Template and f.Spec.Template different in order to make 'rest' list not empty gsSet.Spec.Template.Name = "qqqqqqqqqqqqqqqqqqq" - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("delete", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("delete", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, nil, errors.New("random-err") }) @@ -392,15 +392,15 @@ func TestControllerSyncFleet(t *testing.T) { gsSet := f.GameServerSet() - m.AgonesClient.AddReactor("list", "fleets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "fleets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("create", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("create", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, nil, errors.New("random-err") }) @@ -508,7 +508,7 @@ func TestControllerRun(t *testing.T) { received := make(chan string) defer close(received) - m.ExtClient.AddReactor("get", "customresourcedefinitions", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.ExtClient.AddReactor("get", "customresourcedefinitions", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, agtesting.NewEstablishedCRD(), nil }) @@ -589,7 +589,7 @@ func TestControllerUpdateFleetStatus(t *testing.T) { gsSet2.Status.AllocatedReplicas = 2 m.AgonesClient.AddReactor("list", "gameserversets", - func(action k8stesting.Action) (bool, runtime.Object, error) { + func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet1, *gsSet2}}, nil }) @@ -663,7 +663,7 @@ func TestControllerUpdateFleetPlayerStatus(t *testing.T) { } m.AgonesClient.AddReactor("list", "gameserversets", - func(action k8stesting.Action) (bool, runtime.Object, error) { + func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet1, *gsSet2}}, nil }) @@ -741,7 +741,7 @@ func TestControllerUpdateFleetCounterStatus(t *testing.T) { } m.AgonesClient.AddReactor("list", "gameserversets", - func(action k8stesting.Action) (bool, runtime.Object, error) { + func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet1, *gsSet2}}, nil }) @@ -831,7 +831,7 @@ func TestControllerUpdateFleetListStatus(t *testing.T) { } m.AgonesClient.AddReactor("list", "gameserversets", - func(action k8stesting.Action) (bool, runtime.Object, error) { + func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet1, *gsSet2}}, nil }) @@ -905,12 +905,12 @@ func TestFleetDropCountsAndListsStatus(t *testing.T) { updated := false m.AgonesClient.AddReactor("list", "gameserversets", - func(action k8stesting.Action) (bool, runtime.Object, error) { + func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gss}}, nil }) m.AgonesClient.AddReactor("list", "fleets", - func(action k8stesting.Action) (bool, runtime.Object, error) { + func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.FleetList{Items: []agonesv1.Fleet{*f}}, nil }) @@ -1020,7 +1020,7 @@ func TestControllerRecreateDeployment(t *testing.T) { t.Run("error on update", func(t *testing.T) { c, m := newFakeController() - m.AgonesClient.AddReactor("update", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, nil, errors.New("random-err") }) @@ -1185,7 +1185,7 @@ func TestControllerUpsertGameServerSet(t *testing.T) { gsSet.ObjectMeta.UID = "1234" gsSet.Spec.Replicas = replicas + 10 - m.AgonesClient.AddReactor("update", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, nil, errors.New("random-err") }) @@ -1198,7 +1198,7 @@ func TestControllerUpsertGameServerSet(t *testing.T) { c, m := newFakeController() gsSet := f.GameServerSet() - m.AgonesClient.AddReactor("update", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, nil, errors.New("random-err") }) @@ -1215,11 +1215,11 @@ func TestControllerUpsertGameServerSet(t *testing.T) { gsSet.ObjectMeta.UID = "1234" gsSet.Spec.Replicas = replicas - m.AgonesClient.AddReactor("create", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("create", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "should not create") return false, nil, nil }) - m.AgonesClient.AddReactor("update", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "should not update") return false, nil, nil }) @@ -1427,7 +1427,7 @@ func TestControllerRollingUpdateDeploymentGSSUpdateFailedErrExpected(t *testing. c, m := newFakeController() // triggered inside rollingUpdateRest - m.AgonesClient.AddReactor("update", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, nil, errors.New("random-err") }) @@ -1865,91 +1865,91 @@ type fakeGSSListerWithErr struct { } // GameServerSetLister interface implementation -func (fgsl *fakeGSSListerWithErr) List(selector labels.Selector) (ret []*v1.GameServerSet, err error) { +func (fgsl *fakeGSSListerWithErr) List(_ labels.Selector) (ret []*v1.GameServerSet, err error) { return nil, errors.New("random-err") } -func (fgsl *fakeGSSListerWithErr) GameServerSets(namespace string) agonesv1client.GameServerSetNamespaceLister { +func (fgsl *fakeGSSListerWithErr) GameServerSets(_ string) agonesv1client.GameServerSetNamespaceLister { panic("not implemented") } type fakeFleetsGetterWithErr struct{} // FleetsGetter interface implementation -func (ffg *fakeFleetsGetterWithErr) Fleets(namespace string) agonesv1clientset.FleetInterface { +func (ffg *fakeFleetsGetterWithErr) Fleets(_ string) agonesv1clientset.FleetInterface { return &fakeFleetsGetterWithErr{} } -func (ffg *fakeFleetsGetterWithErr) Create(ctx context.Context, fleet *v1.Fleet, opts metav1.CreateOptions) (*v1.Fleet, error) { +func (ffg *fakeFleetsGetterWithErr) Create(_ context.Context, _ *v1.Fleet, _ metav1.CreateOptions) (*v1.Fleet, error) { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) Update(ctx context.Context, fleet *v1.Fleet, opts metav1.UpdateOptions) (*v1.Fleet, error) { +func (ffg *fakeFleetsGetterWithErr) Update(_ context.Context, _ *v1.Fleet, _ metav1.UpdateOptions) (*v1.Fleet, error) { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) UpdateStatus(ctx context.Context, fleet *v1.Fleet, opts metav1.UpdateOptions) (*v1.Fleet, error) { +func (ffg *fakeFleetsGetterWithErr) UpdateStatus(_ context.Context, _ *v1.Fleet, _ metav1.UpdateOptions) (*v1.Fleet, error) { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { +func (ffg *fakeFleetsGetterWithErr) Delete(_ context.Context, _ string, _ metav1.DeleteOptions) error { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { +func (ffg *fakeFleetsGetterWithErr) DeleteCollection(_ context.Context, _ metav1.DeleteOptions, _ metav1.ListOptions) error { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Fleet, error) { +func (ffg *fakeFleetsGetterWithErr) Get(_ context.Context, _ string, _ metav1.GetOptions) (*v1.Fleet, error) { return nil, errors.New("err-from-fleet-getter") } -func (ffg *fakeFleetsGetterWithErr) List(ctx context.Context, opts metav1.ListOptions) (*v1.FleetList, error) { +func (ffg *fakeFleetsGetterWithErr) List(_ context.Context, _ metav1.ListOptions) (*v1.FleetList, error) { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +func (ffg *fakeFleetsGetterWithErr) Watch(_ context.Context, _ metav1.ListOptions) (watch.Interface, error) { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Fleet, err error) { +func (ffg *fakeFleetsGetterWithErr) Patch(_ context.Context, _ string, _ types.PatchType, _ []byte, _ metav1.PatchOptions, _ ...string) (result *v1.Fleet, err error) { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) Apply(ctx context.Context, fleet *applyconfigurations.FleetApplyConfiguration, opts metav1.ApplyOptions) (*v1.Fleet, error) { +func (ffg *fakeFleetsGetterWithErr) Apply(_ context.Context, _ *applyconfigurations.FleetApplyConfiguration, _ metav1.ApplyOptions) (*v1.Fleet, error) { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) ApplyStatus(ctx context.Context, fleet *applyconfigurations.FleetApplyConfiguration, opts metav1.ApplyOptions) (*v1.Fleet, error) { +func (ffg *fakeFleetsGetterWithErr) ApplyStatus(_ context.Context, _ *applyconfigurations.FleetApplyConfiguration, _ metav1.ApplyOptions) (*v1.Fleet, error) { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) GetScale(ctx context.Context, fleetName string, options metav1.GetOptions) (*autoscalingv1.Scale, error) { +func (ffg *fakeFleetsGetterWithErr) GetScale(_ context.Context, _ string, _ metav1.GetOptions) (*autoscalingv1.Scale, error) { panic("not implemented") } -func (ffg *fakeFleetsGetterWithErr) UpdateScale(ctx context.Context, fleetName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (*autoscalingv1.Scale, error) { +func (ffg *fakeFleetsGetterWithErr) UpdateScale(_ context.Context, _ string, _ *autoscalingv1.Scale, _ metav1.UpdateOptions) (*autoscalingv1.Scale, error) { panic("not implemented") } type fakeFleetListerWithErr struct{} // FleetLister interface implementation -func (ffl *fakeFleetListerWithErr) List(selector labels.Selector) (ret []*v1.Fleet, err error) { +func (ffl *fakeFleetListerWithErr) List(_ labels.Selector) (ret []*v1.Fleet, err error) { return nil, errors.New("err-from-fleet-lister") } -func (ffl *fakeFleetListerWithErr) Fleets(namespace string) agonesv1client.FleetNamespaceLister { +func (ffl *fakeFleetListerWithErr) Fleets(_ string) agonesv1client.FleetNamespaceLister { return &fakeFleetNamespaceListerWithErr{} } type fakeFleetNamespaceListerWithErr struct{} // FleetNamespaceLister interface implementation -func (ffnl *fakeFleetNamespaceListerWithErr) List(selector labels.Selector) (ret []*v1.Fleet, err error) { +func (ffnl *fakeFleetNamespaceListerWithErr) List(_ labels.Selector) (ret []*v1.Fleet, err error) { return nil, errors.New("err-from-namespace-lister") } -func (ffnl *fakeFleetNamespaceListerWithErr) Get(name string) (*v1.Fleet, error) { +func (ffnl *fakeFleetNamespaceListerWithErr) Get(_ string) (*v1.Fleet, error) { return nil, errors.New("err-from-namespace-lister") } diff --git a/pkg/fleets/fleets_test.go b/pkg/fleets/fleets_test.go index e5f56638af..e933123649 100644 --- a/pkg/fleets/fleets_test.go +++ b/pkg/fleets/fleets_test.go @@ -57,7 +57,7 @@ func TestListGameServerSetsByFleetOwner(t *testing.T) { gsSet4.ObjectMeta.OwnerReferences = nil m := agtesting.NewMocks() - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet1, *gsSet2, *gsSet3, *gsSet4}}, nil }) @@ -91,7 +91,7 @@ func TestListGameServersByFleetOwner(t *testing.T) { m := agtesting.NewMocks() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) diff --git a/pkg/gameserverallocations/allocation_cache.go b/pkg/gameserverallocations/allocation_cache.go index ba90824b80..75c53afd80 100644 --- a/pkg/gameserverallocations/allocation_cache.go +++ b/pkg/gameserverallocations/allocation_cache.go @@ -264,7 +264,7 @@ func (c *AllocationCache) ListSortedGameServersPriorities(gsa *allocationv1.Game // SyncGameServers synchronises the GameServers to Gameserver cache. This is called when a failure // happened during the allocation. This method will sync and make sure the cache is up to date. -func (c *AllocationCache) SyncGameServers(ctx context.Context, key string) error { +func (c *AllocationCache) SyncGameServers(_ context.Context, key string) error { c.loggerForGameServerKey(key).Debug("Refreshing Allocation Gameserver cache") return c.syncCache() @@ -288,7 +288,7 @@ func (c *AllocationCache) syncCache() error { // first remove the gameservers are not in the list anymore tobeDeletedGSInCache := make([]string, 0) - c.cache.Range(func(key string, gs *agonesv1.GameServer) bool { + c.cache.Range(func(key string, _ *agonesv1.GameServer) bool { if _, ok := currGameservers[key]; !ok { tobeDeletedGSInCache = append(tobeDeletedGSInCache, key) } diff --git a/pkg/gameserverallocations/allocation_cache_test.go b/pkg/gameserverallocations/allocation_cache_test.go index 3dac0d1fb4..bde3bfc222 100644 --- a/pkg/gameserverallocations/allocation_cache_test.go +++ b/pkg/gameserverallocations/allocation_cache_test.go @@ -187,7 +187,7 @@ func TestAllocationCacheListSortedGameServers(t *testing.T) { gsList := v.list - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) @@ -481,7 +481,7 @@ func TestListSortedGameServersPriorities(t *testing.T) { cache, m := newFakeAllocationCache() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: testScenario.list}, nil }) @@ -514,9 +514,9 @@ func TestAllocatorRunCacheSync(t *testing.T) { assertCacheEntries := func(expected int) { count := 0 - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(_ context.Context) (done bool, err error) { count = 0 - cache.cache.Range(func(key string, gs *agonesv1.GameServer) bool { + cache.cache.Range(func(_ string, _ *agonesv1.GameServer) bool { count++ return true }) diff --git a/pkg/gameserverallocations/allocator_test.go b/pkg/gameserverallocations/allocator_test.go index 6902287358..457baddedc 100644 --- a/pkg/gameserverallocations/allocator_test.go +++ b/pkg/gameserverallocations/allocator_test.go @@ -58,7 +58,7 @@ func TestAllocatorAllocate(t *testing.T) { gsList[3].ObjectMeta.DeletionTimestamp = &n - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) @@ -81,7 +81,7 @@ func TestAllocatorAllocate(t *testing.T) { require.NoError(t, a.Run(ctx)) // wait for it to be up and running - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (done bool, err error) { return a.allocationCache.workerqueue.RunCount() == 1, nil }) require.NoError(t, err) @@ -145,7 +145,7 @@ func TestAllocatorAllocatePriority(t *testing.T) { gsList[2].Status.NodeName = n1 gsList[3].Status.NodeName = n1 - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) @@ -164,7 +164,7 @@ func TestAllocatorAllocatePriority(t *testing.T) { require.NoError(t, a.Run(ctx)) // wait for it to be up and running - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (done bool, err error) { return a.allocationCache.workerqueue.RunCount() == 1, nil }) require.NoError(t, err) @@ -431,7 +431,7 @@ func TestAllocationApplyAllocationError(t *testing.T) { m := agtesting.NewMocks() ctx := context.Background() - m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("update", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, nil, errors.New("failed to update") }) @@ -461,7 +461,7 @@ func TestAllocatorAllocateOnGameServerUpdateError(t *testing.T) { // make sure there is more than can be retried, so there is always at least some. gsLen := allocationRetry.Steps * 2 _, gsList := defaultFixtures(gsLen) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { @@ -525,7 +525,7 @@ func TestAllocatorRunLocalAllocations(t *testing.T) { gsList[0].Status.NodeName = "special" a, m := newFakeAllocator() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) updateCount := 0 @@ -682,7 +682,7 @@ func TestAllocatorRunLocalAllocationsCountsAndLists(t *testing.T) { gsList := []agonesv1.GameServer{gs1, gs2, gs3, gs4, gs5, gs6} - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) @@ -985,7 +985,7 @@ func TestAllocatorCreateRestClientError(t *testing.T) { a, m := newFakeAllocator() m.KubeClient.AddReactor("list", "secrets", - func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &corev1.SecretList{ Items: []corev1.Secret{{ Data: map[string][]byte{ @@ -1012,7 +1012,7 @@ func TestAllocatorCreateRestClientError(t *testing.T) { a, m := newFakeAllocator() m.KubeClient.AddReactor("list", "secrets", - func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &corev1.SecretList{ Items: []corev1.Secret{{ Data: map[string][]byte{ @@ -1040,7 +1040,7 @@ func TestAllocatorCreateRestClientError(t *testing.T) { a, m := newFakeAllocator() m.KubeClient.AddReactor("list", "secrets", - func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, getTestSecret("secret-name", clientCert), nil }) @@ -1059,7 +1059,7 @@ func TestAllocatorCreateRestClientError(t *testing.T) { a, m := newFakeAllocator() m.KubeClient.AddReactor("list", "secrets", - func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, getTestSecret("secret-name", []byte("XXX")), nil }) diff --git a/pkg/gameserverallocations/cache_test.go b/pkg/gameserverallocations/cache_test.go index 35f5db6a0e..561977612e 100644 --- a/pkg/gameserverallocations/cache_test.go +++ b/pkg/gameserverallocations/cache_test.go @@ -43,7 +43,7 @@ func TestGameServerCacheEntry(t *testing.T) { cache.Store("gs3", gs3) count := 0 - cache.Range(func(key string, gs *agonesv1.GameServer) bool { + cache.Range(func(_ string, _ *agonesv1.GameServer) bool { count++ return count != 2 }) diff --git a/pkg/gameserverallocations/controller.go b/pkg/gameserverallocations/controller.go index 75d311bce3..0e8826a66e 100644 --- a/pkg/gameserverallocations/controller.go +++ b/pkg/gameserverallocations/controller.go @@ -124,7 +124,7 @@ func (c *Extensions) processAllocationRequest(ctx context.Context, w http.Respon if r.Method != http.MethodPost { log.Warn("allocation handler only supports POST") http.Error(w, "Method not supported", http.StatusMethodNotAllowed) - return + return nil } gsa, err := c.allocationDeserialization(r, namespace) diff --git a/pkg/gameserverallocations/controller_test.go b/pkg/gameserverallocations/controller_test.go index 5185db105b..56bac3baaa 100644 --- a/pkg/gameserverallocations/controller_test.go +++ b/pkg/gameserverallocations/controller_test.go @@ -73,7 +73,7 @@ func TestControllerAllocator(t *testing.T) { c, m := newFakeController() gsWatch := watch.NewFake() m.AgonesClient.AddWatchReactor("gameservers", k8stesting.DefaultWatchReactor(gsWatch, nil)) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) @@ -98,7 +98,7 @@ func TestControllerAllocator(t *testing.T) { assert.FailNow(t, err.Error()) } // wait for it to be up and running - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (done bool, err error) { return c.allocator.allocationCache.workerqueue.RunCount() == 1, nil }) assert.NoError(t, err) @@ -206,7 +206,7 @@ func TestMultiClusterAllocationFromLocal(t *testing.T) { c, m := newFakeController() fleetName := addReactorForGameServer(&m) - m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &multiclusterv1.GameServerAllocationPolicyList{ Items: []multiclusterv1.GameServerAllocationPolicy{ { @@ -236,7 +236,7 @@ func TestMultiClusterAllocationFromLocal(t *testing.T) { assert.FailNow(t, err.Error()) } // wait for it to be up and running - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (done bool, err error) { return c.allocator.allocationCache.workerqueue.RunCount() == 1, nil }) assert.NoError(t, err) @@ -271,7 +271,7 @@ func TestMultiClusterAllocationFromLocal(t *testing.T) { c, m := newFakeController() fleetName := addReactorForGameServer(&m) - m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &multiclusterv1.GameServerAllocationPolicyList{ Items: []multiclusterv1.GameServerAllocationPolicy{}, }, nil @@ -284,7 +284,7 @@ func TestMultiClusterAllocationFromLocal(t *testing.T) { assert.FailNow(t, err.Error()) } // wait for it to be up and running - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (done bool, err error) { return c.allocator.allocationCache.workerqueue.RunCount() == 1, nil }) assert.NoError(t, err) @@ -314,7 +314,7 @@ func TestMultiClusterAllocationFromLocal(t *testing.T) { t.Run("Could not find a Ready GameServer", func(t *testing.T) { c, m := newFakeController() - m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &multiclusterv1.GameServerAllocationPolicyList{ Items: []multiclusterv1.GameServerAllocationPolicy{ { @@ -344,7 +344,7 @@ func TestMultiClusterAllocationFromLocal(t *testing.T) { assert.FailNow(t, err.Error()) } // wait for it to be up and running - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (done bool, err error) { return c.allocator.allocationCache.workerqueue.RunCount() == 1, nil }) assert.NoError(t, err) @@ -388,7 +388,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { // Allocation policy reactor secretName := clusterName + "secret" targetedNamespace := "tns" - m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &multiclusterv1.GameServerAllocationPolicyList{ Items: []multiclusterv1.GameServerAllocationPolicy{ { @@ -412,7 +412,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { }) m.KubeClient.AddReactor("list", "secrets", - func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, getTestSecret(secretName, nil), nil }) @@ -439,7 +439,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { }, } - c.allocator.remoteAllocationCallback = func(ctx context.Context, e string, dialOpt grpc.DialOption, request *pb.AllocationRequest) (*pb.AllocationResponse, error) { + c.allocator.remoteAllocationCallback = func(_ context.Context, e string, _ grpc.DialOption, _ *pb.AllocationRequest) (*pb.AllocationResponse, error) { assert.Equal(t, endpoint+":443", e) serverResponse := pb.AllocationResponse{ GameServerName: expectedGSName, @@ -462,7 +462,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { retry := 0 endpoint := "z.z.z.z" - c.allocator.remoteAllocationCallback = func(ctx context.Context, endpoint string, dialOpt grpc.DialOption, request *pb.AllocationRequest) (*pb.AllocationResponse, error) { + c.allocator.remoteAllocationCallback = func(_ context.Context, _ string, _ grpc.DialOption, _ *pb.AllocationRequest) (*pb.AllocationResponse, error) { if count == 0 { serverResponse := pb.AllocationResponse{} count++ @@ -475,7 +475,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { // Allocation policy reactor secretName := clusterName + "secret" - m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &multiclusterv1.GameServerAllocationPolicyList{ Items: []multiclusterv1.GameServerAllocationPolicy{ { @@ -515,7 +515,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { }) m.KubeClient.AddReactor("list", "secrets", - func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, getTestSecret(secretName, clientCert), nil }) @@ -556,7 +556,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { healthyEndpoint := "healthy_endpoint:443" expectedGSName := "mocked" - c.allocator.remoteAllocationCallback = func(ctx context.Context, endpoint string, dialOpt grpc.DialOption, request *pb.AllocationRequest) (*pb.AllocationResponse, error) { + c.allocator.remoteAllocationCallback = func(_ context.Context, endpoint string, _ grpc.DialOption, _ *pb.AllocationRequest) (*pb.AllocationResponse, error) { if endpoint == unhealthyEndpoint { return nil, errors.New("test error message") } @@ -570,7 +570,8 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { // Allocation policy reactor secretName := clusterName + "secret" - m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + + m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &multiclusterv1.GameServerAllocationPolicyList{ Items: []multiclusterv1.GameServerAllocationPolicy{ { @@ -593,7 +594,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { }) m.KubeClient.AddReactor("list", "secrets", - func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, getTestSecret(secretName, clientCert), nil }) @@ -630,14 +631,14 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { fleetName := addReactorForGameServer(&m) calls := 0 - c.allocator.remoteAllocationCallback = func(ctx context.Context, endpoint string, dialOpt grpc.DialOption, request *pb.AllocationRequest) (*pb.AllocationResponse, error) { + c.allocator.remoteAllocationCallback = func(_ context.Context, _ string, _ grpc.DialOption, _ *pb.AllocationRequest) (*pb.AllocationResponse, error) { calls++ return nil, errors.New("Error") } // Allocation policy reactor secretName := clusterName + "secret" - m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &multiclusterv1.GameServerAllocationPolicyList{ Items: []multiclusterv1.GameServerAllocationPolicy{ { @@ -660,7 +661,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { }) m.KubeClient.AddReactor("list", "secrets", - func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, getTestSecret(secretName, clientCert), nil }) @@ -700,7 +701,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { // Mock server to return DeadlineExceeded on the first call and success on subsequent ones calls := 0 - c.allocator.remoteAllocationCallback = func(ctx context.Context, endpoint string, dialOpt grpc.DialOption, request *pb.AllocationRequest) (*pb.AllocationResponse, error) { + c.allocator.remoteAllocationCallback = func(_ context.Context, _ string, _ grpc.DialOption, _ *pb.AllocationRequest) (*pb.AllocationResponse, error) { calls++ if calls == 1 { return nil, status.Errorf(codes.DeadlineExceeded, "remote allocation call timeout") @@ -710,7 +711,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { // Allocation policy reactor secretName := clusterName + "secret" - m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserverallocationpolicies", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &multiclusterv1.GameServerAllocationPolicyList{ Items: []multiclusterv1.GameServerAllocationPolicy{ { @@ -733,7 +734,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) { }) m.KubeClient.AddReactor("list", "secrets", - func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, getTestSecret(secretName, clientCert), nil }) @@ -785,7 +786,7 @@ func addReactorForGameServer(m *agtesting.Mocks) string { f, gsList := defaultFixtures(3) gsWatch := watch.NewFake() m.AgonesClient.AddWatchReactor("gameservers", k8stesting.DefaultWatchReactor(gsWatch, nil)) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { diff --git a/pkg/gameserverallocations/find_test.go b/pkg/gameserverallocations/find_test.go index 613ecce634..42628e4a4e 100644 --- a/pkg/gameserverallocations/find_test.go +++ b/pkg/gameserverallocations/find_test.go @@ -253,7 +253,7 @@ func TestFindGameServerForAllocationPacked(t *testing.T) { controller, m := newFakeController() c := controller.allocator.allocationCache - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: v.list}, nil }) @@ -316,7 +316,7 @@ func TestFindGameServerForAllocationDistributed(t *testing.T) { Status: agonesv1.GameServerStatus{NodeName: "node3", State: agonesv1.GameServerStateReady}}, } - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { return true, &agonesv1.GameServerList{Items: gsList}, nil }) diff --git a/pkg/gameserverallocations/metrics_test.go b/pkg/gameserverallocations/metrics_test.go index 2189620132..b484dde309 100644 --- a/pkg/gameserverallocations/metrics_test.go +++ b/pkg/gameserverallocations/metrics_test.go @@ -37,20 +37,20 @@ type mockGameServerNamespaceLister struct { gameServer *agonesv1.GameServer } -func (s *mockGameServerLister) List(selector labels.Selector) (ret []*agonesv1.GameServer, err error) { +func (s *mockGameServerLister) List(_ labels.Selector) (ret []*agonesv1.GameServer, err error) { return ret, nil } -func (s *mockGameServerLister) GameServers(namespace string) gameserverv1.GameServerNamespaceLister { +func (s *mockGameServerLister) GameServers(_ string) gameserverv1.GameServerNamespaceLister { s.gameServersCalled = true return s.gameServerNamespaceLister } -func (s mockGameServerNamespaceLister) Get(name string) (*agonesv1.GameServer, error) { +func (s mockGameServerNamespaceLister) Get(_ string) (*agonesv1.GameServer, error) { return s.gameServer, nil } -func (s mockGameServerNamespaceLister) List(selector labels.Selector) (ret []*agonesv1.GameServer, err error) { +func (s mockGameServerNamespaceLister) List(_ labels.Selector) (ret []*agonesv1.GameServer, err error) { return ret, nil } diff --git a/pkg/gameservers/controller.go b/pkg/gameservers/controller.go index 3fa79d86c2..7eaafcdc8c 100644 --- a/pkg/gameservers/controller.go +++ b/pkg/gameservers/controller.go @@ -889,7 +889,7 @@ func (c *Controller) syncGameServerStartingState(ctx context.Context, gs *agones } // Ensure the pod IPs are populated - if pod.Status.PodIPs == nil || len(pod.Status.PodIPs) == 0 { + if len(pod.Status.PodIPs) == 0 { return gs, workerqueue.NewTraceError(errors.Errorf("pod IPs not yet populated for Pod %s", pod.ObjectMeta.Name)) } diff --git a/pkg/gameservers/controller_test.go b/pkg/gameservers/controller_test.go index 88bd8221d1..79f8ccd054 100644 --- a/pkg/gameservers/controller_test.go +++ b/pkg/gameservers/controller_test.go @@ -85,7 +85,7 @@ func TestControllerSyncGameServer(t *testing.T) { watchPods := watch.NewFake() mocks.KubeClient.AddWatchReactor("pods", k8stesting.DefaultWatchReactor(watchPods, nil)) - mocks.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.NodeList{Items: []corev1.Node{node}}, nil }) mocks.KubeClient.AddReactor("create", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -104,7 +104,7 @@ func TestControllerSyncGameServer(t *testing.T) { }, 5*time.Second, time.Second) return true, pod, nil }) - mocks.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gameServers := &agonesv1.GameServerList{Items: []agonesv1.GameServer{*fixture}} return true, gameServers, nil }) @@ -199,13 +199,13 @@ func TestControllerSyncGameServerWithDevIP(t *testing.T) { fixture.ApplyDefaults() - mocks.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { return false, nil, k8serrors.NewMethodNotSupported(schema.GroupResource{}, "list nodes should not be called") }) - mocks.KubeClient.AddReactor("create", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("create", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return false, nil, k8serrors.NewMethodNotSupported(schema.GroupResource{}, "creating a pod with dev mode is not supported") }) - mocks.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gameServers := &agonesv1.GameServerList{Items: []agonesv1.GameServer{*fixture}} return true, gameServers, nil }) @@ -243,7 +243,7 @@ func TestControllerSyncGameServerWithDevIP(t *testing.T) { gsFixture.ApplyDefaults() gsFixture.Status.State = agonesv1.GameServerStateRequestReady - mocks.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gameServers := &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gsFixture}} return true, gameServers, nil }) @@ -276,11 +276,11 @@ func TestControllerSyncGameServerWithDevIP(t *testing.T) { fixture.ApplyDefaults() fixture.Status.State = agonesv1.GameServerStateAllocated - mocks.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gameServers := &agonesv1.GameServerList{Items: []agonesv1.GameServer{*fixture}} return true, gameServers, nil }) - mocks.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.AgonesClient.AddReactor("update", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { require.Fail(t, "should not update") return true, nil, nil }) @@ -325,7 +325,7 @@ func TestControllerWatchGameServers(t *testing.T) { podWatch := watch.NewFake() m.AgonesClient.AddWatchReactor("gameservers", k8stesting.DefaultWatchReactor(gsWatch, nil)) m.KubeClient.AddWatchReactor("pods", k8stesting.DefaultWatchReactor(podWatch, nil)) - m.ExtClient.AddReactor("get", "customresourcedefinitions", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.ExtClient.AddReactor("get", "customresourcedefinitions", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, agtesting.NewEstablishedCRD(), nil }) @@ -647,7 +647,7 @@ func TestControllerSyncGameServerDeletionTimestamp(t *testing.T) { assert.Nil(t, err) deleted := false - mocks.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) mocks.KubeClient.AddReactor("delete", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -677,10 +677,10 @@ func TestControllerSyncGameServerDeletionTimestamp(t *testing.T) { pod, err := fixture.Pod(agtesting.FakeAPIHooks{}) assert.Nil(t, err) - mocks.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) - mocks.KubeClient.AddReactor("delete", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("delete", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, nil, errors.New("Delete-err") }) @@ -771,7 +771,7 @@ func TestControllerSyncGameServerPortAllocationState(t *testing.T) { Status: agonesv1.GameServerStatus{State: agonesv1.GameServerStatePortAllocation}, } fixture.ApplyDefaults() - mocks.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.NodeList{Items: []corev1.Node{{ObjectMeta: metav1.ObjectMeta{Name: nodeFixtureName}}}}, nil }) @@ -819,7 +819,7 @@ func TestControllerSyncGameServerPortAllocationState(t *testing.T) { Status: agonesv1.GameServerStatus{State: agonesv1.GameServerStatePortAllocation}, } fixture.ApplyDefaults() - mocks.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.NodeList{Items: []corev1.Node{{ObjectMeta: metav1.ObjectMeta{Name: nodeFixtureName}}}}, nil }) @@ -1067,10 +1067,10 @@ func TestControllerSyncGameServerCreatingState(t *testing.T) { pod, err := fixture.Pod(agtesting.FakeAPIHooks{}) assert.Nil(t, err) - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) - m.KubeClient.AddReactor("create", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("create", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { podCreated = true return true, nil, nil }) @@ -1098,7 +1098,7 @@ func TestControllerSyncGameServerCreatingState(t *testing.T) { podCreated := false gsUpdated := false - mocks.KubeClient.AddReactor("create", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("create", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { podCreated = true return true, nil, k8serrors.NewInvalid(schema.GroupKind{}, "test", field.ErrorList{}) }) @@ -1156,10 +1156,10 @@ func TestControllerSyncGameServerStartingState(t *testing.T) { pod.Status.PodIPs = []corev1.PodIP{{IP: ipv6Fixture}} gsUpdated := false - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.NodeList{Items: []corev1.Node{node}}, nil }) - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -1196,10 +1196,10 @@ func TestControllerSyncGameServerStartingState(t *testing.T) { require.NoError(t, err) pod.Spec.NodeName = nodeFixtureName - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.NodeList{Items: []corev1.Node{node}}, nil }) - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -1224,10 +1224,10 @@ func TestControllerSyncGameServerStartingState(t *testing.T) { pod.Spec.NodeName = nodeFixtureName pod.Status.PodIPs = []corev1.PodIP{{IP: ipv6Fixture}} - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.NodeList{Items: []corev1.Node{node}}, nil }) - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -1362,7 +1362,7 @@ func TestControllerCreateGameServerPod(t *testing.T) { podCreated := false gsUpdated := false - mocks.KubeClient.AddReactor("create", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("create", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { podCreated = true return true, nil, k8serrors.NewInvalid(schema.GroupKind{}, "test", field.ErrorList{}) }) @@ -1393,7 +1393,7 @@ func TestControllerCreateGameServerPod(t *testing.T) { podCreated := false gsUpdated := false - mocks.KubeClient.AddReactor("create", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.KubeClient.AddReactor("create", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { podCreated = true return true, nil, k8serrors.NewForbidden(schema.GroupResource{}, "test", errors.New("test")) }) @@ -1444,7 +1444,7 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) { gsUpdated := false podUpdated := false - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -1492,7 +1492,7 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) { } podUpdated := false - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -1537,10 +1537,10 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) { gsUpdated := false podUpdated := false - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) - m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gsUpdated = true return true, nil, nil }) @@ -1581,7 +1581,7 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) { gsUpdated := false podUpdated := false - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -1592,7 +1592,7 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) { assert.Equal(t, containerID, gs.Annotations[agonesv1.GameServerReadyContainerIDAnnotation]) return true, gs, nil }) - m.KubeClient.AddReactor("update", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("update", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { podUpdated = true return true, nil, nil }) @@ -1631,11 +1631,11 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) { ipFixture := "12.12.12.12" nodeFixture := corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: nodeFixtureName}, Status: corev1.NodeStatus{Addresses: []corev1.NodeAddress{{Address: ipFixture, Type: corev1.NodeExternalIP}}}} - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.NodeList{Items: []corev1.Node{nodeFixture}}, nil }) - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -1691,7 +1691,7 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) { gsUpdated := false podUpdated := false - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -1744,14 +1744,14 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) { gsUpdated := false podUpdated := false - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) - m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gsUpdated = true return true, nil, nil }) - m.KubeClient.AddReactor("update", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("update", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { podUpdated = true return true, nil, nil }) @@ -1777,14 +1777,14 @@ func TestControllerSyncGameServerRequestReadyState(t *testing.T) { gsUpdated := false podUpdated := false - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) - m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gsUpdated = true return true, nil, nil }) - m.KubeClient.AddReactor("update", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("update", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { podUpdated = true return true, nil, nil }) @@ -2221,7 +2221,7 @@ func testNoChange(t *testing.T, state agonesv1.GameServerState, f func(*Controll Spec: newSingleContainerSpec(), Status: agonesv1.GameServerStatus{State: state}} fixture.ApplyDefaults() updated := false - mocks.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.AgonesClient.AddReactor("update", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { updated = true return true, nil, nil }) @@ -2241,7 +2241,7 @@ func testWithNonZeroDeletionTimestamp(t *testing.T, f func(*Controller, *agonesv Spec: newSingleContainerSpec(), Status: agonesv1.GameServerStatus{State: agonesv1.GameServerStateShutdown}} fixture.ApplyDefaults() updated := false - mocks.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + mocks.AgonesClient.AddReactor("update", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { updated = true return true, nil, nil }) diff --git a/pkg/gameservers/health.go b/pkg/gameservers/health.go index 416d9c6384..59c0c41380 100644 --- a/pkg/gameservers/health.go +++ b/pkg/gameservers/health.go @@ -87,7 +87,7 @@ func NewHealthController( hc.recorder = eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "health-controller"}) _, _ = podInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ - UpdateFunc: func(oldObj, newObj interface{}) { + UpdateFunc: func(_, newObj interface{}) { pod := newObj.(*corev1.Pod) if pod.ObjectMeta.DeletionTimestamp.IsZero() && isGameServerPod(pod) && hc.isUnhealthy(pod) { hc.workerqueue.Enqueue(pod) diff --git a/pkg/gameservers/health_test.go b/pkg/gameservers/health_test.go index f0b6591186..3e14e3a7b7 100644 --- a/pkg/gameservers/health_test.go +++ b/pkg/gameservers/health_test.go @@ -133,13 +133,13 @@ func TestHealthControllerSkipUnhealthyGameContainer(t *testing.T) { expected: expected{result: false}, }, "before ready, with no terminated container": { - setup: func(gs *agonesv1.GameServer, pod *corev1.Pod) { + setup: func(gs *agonesv1.GameServer, _ *corev1.Pod) { gs.Status.State = agonesv1.GameServerStateScheduled }, expected: expected{result: false}, }, "after ready, with no terminated container": { - setup: func(gs *agonesv1.GameServer, pod *corev1.Pod) { + setup: func(gs *agonesv1.GameServer, _ *corev1.Pod) { gs.Status.State = agonesv1.GameServerStateAllocated }, expected: expected{result: false}, @@ -181,7 +181,7 @@ func TestHealthControllerSkipUnhealthyGameContainer(t *testing.T) { expected: expected{result: true}, }, "pod is missing!": { - setup: func(server *agonesv1.GameServer, pod *corev1.Pod) { + setup: func(_ *agonesv1.GameServer, pod *corev1.Pod) { pod.ObjectMeta.Name = "missing" }, expected: expected{result: false}, @@ -206,7 +206,7 @@ func TestHealthControllerSkipUnhealthyGameContainer(t *testing.T) { v.setup(gs, pod) - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) @@ -307,7 +307,7 @@ func TestHealthControllerSyncGameServer(t *testing.T) { got := false updated := false - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { list := &corev1.PodList{Items: []corev1.Pod{}} if test.podStatus != nil { pod, err := gs.Pod(agtesting.FakeAPIHooks{}) @@ -317,7 +317,7 @@ func TestHealthControllerSyncGameServer(t *testing.T) { } return true, list, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { got = true return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{gs}}, nil }) @@ -352,11 +352,11 @@ func TestHealthControllerSyncGameServerUpdateFailed(t *testing.T) { Status: agonesv1.GameServerStatus{State: agonesv1.GameServerStateAllocated}} gs.ApplyDefaults() - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { list := &corev1.PodList{Items: []corev1.Pod{}} return true, list, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{gs}}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -414,7 +414,7 @@ func TestHealthControllerRun(t *testing.T) { podWatch.Add(pod.DeepCopy()) go hc.Run(stop, 1) // nolint: errcheck - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { return hc.workerqueue.RunCount() == 1, nil }) assert.NoError(t, err) diff --git a/pkg/gameservers/migration_test.go b/pkg/gameservers/migration_test.go index 7c002add6d..ed01b5f181 100644 --- a/pkg/gameservers/migration_test.go +++ b/pkg/gameservers/migration_test.go @@ -54,7 +54,7 @@ func TestMigrationControllerSyncGameServer(t *testing.T) { }, expected: expected{ updated: false, - updateTests: func(t *testing.T, gs *agonesv1.GameServer) {}, + updateTests: func(_ *testing.T, _ *agonesv1.GameServer) {}, postTests: func(t *testing.T, m agtesting.Mocks) { agtesting.AssertNoEvent(t, m.FakeRecorder.Events) }, @@ -68,7 +68,7 @@ func TestMigrationControllerSyncGameServer(t *testing.T) { }, expected: expected{ updated: false, - updateTests: func(t *testing.T, gs *agonesv1.GameServer) {}, + updateTests: func(_ *testing.T, _ *agonesv1.GameServer) {}, postTests: func(t *testing.T, m agtesting.Mocks) { agtesting.AssertNoEvent(t, m.FakeRecorder.Events) }, @@ -160,14 +160,14 @@ func TestMigrationControllerSyncGameServer(t *testing.T) { gs, pod, node = v.setup(gs, pod, node) // populate - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs}}, nil }) - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.NodeList{Items: []corev1.Node{*node}}, nil }) - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil }) diff --git a/pkg/gameservers/missing_test.go b/pkg/gameservers/missing_test.go index 40a049764b..6c7567fced 100644 --- a/pkg/gameservers/missing_test.go +++ b/pkg/gameservers/missing_test.go @@ -54,7 +54,7 @@ func TestMissingPodControllerSyncGameServer(t *testing.T) { }, }, "pod doesn't exist: game server is fine": { - setup: func(gs *agonesv1.GameServer, pod *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { + setup: func(gs *agonesv1.GameServer, _ *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { return gs, nil }, expected: expected{ @@ -68,7 +68,7 @@ func TestMissingPodControllerSyncGameServer(t *testing.T) { }, }, "pod doesn't exist: game server not found": { - setup: func(gs *agonesv1.GameServer, pod *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { + setup: func(_ *agonesv1.GameServer, _ *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { return nil, nil }, expected: expected{ @@ -78,7 +78,7 @@ func TestMissingPodControllerSyncGameServer(t *testing.T) { }, }, "pod doesn't exist: game server is being deleted": { - setup: func(gs *agonesv1.GameServer, pod *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { + setup: func(gs *agonesv1.GameServer, _ *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { now := metav1.Now() gs.ObjectMeta.DeletionTimestamp = &now return gs, nil @@ -90,7 +90,7 @@ func TestMissingPodControllerSyncGameServer(t *testing.T) { }, }, "pod doesn't exist: game server is already Unhealthy": { - setup: func(gs *agonesv1.GameServer, pod *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { + setup: func(gs *agonesv1.GameServer, _ *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { gs.Status.State = agonesv1.GameServerStateUnhealthy return gs, nil }, @@ -101,7 +101,7 @@ func TestMissingPodControllerSyncGameServer(t *testing.T) { }, }, "pod is not a gameserver pod": { - setup: func(gs *agonesv1.GameServer, pod *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { + setup: func(gs *agonesv1.GameServer, _ *corev1.Pod) (*agonesv1.GameServer, *corev1.Pod) { return gs, &corev1.Pod{ObjectMeta: gs.ObjectMeta} }, expected: expected{ @@ -130,13 +130,13 @@ func TestMissingPodControllerSyncGameServer(t *testing.T) { assert.NoError(t, err) gs, pod = v.setup(gs, pod) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { if gs != nil { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs}}, nil } return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{}}, nil }) - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { if pod != nil { return true, &corev1.PodList{Items: []corev1.Pod{*pod}}, nil } @@ -184,7 +184,7 @@ func TestMissingPodControllerRun(t *testing.T) { exist := atomic.Bool{} exist.Store(false) - m.KubeClient.AddReactor("list", "pods", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "pods", func(_ k8stesting.Action) (bool, runtime.Object, error) { if exist.Load() { pod, err := gs.Pod(agtesting.FakeAPIHooks{}) require.NoError(t, err) diff --git a/pkg/gameservers/pernodecounter_test.go b/pkg/gameservers/pernodecounter_test.go index f84ff76627..b0d0b20f2b 100644 --- a/pkg/gameservers/pernodecounter_test.go +++ b/pkg/gameservers/pernodecounter_test.go @@ -172,7 +172,7 @@ func TestPerNodeCounterRun(t *testing.T) { gs4.ObjectMeta.Name = "gs4" gs4.Status.State = agonesv1.GameServerStateAllocated - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs1, *gs2, *gs3, *gs4}}, nil }) diff --git a/pkg/gameserversets/allocation_overflow.go b/pkg/gameserversets/allocation_overflow.go index 45f6c9ad3b..f3a49778fe 100644 --- a/pkg/gameserversets/allocation_overflow.go +++ b/pkg/gameserversets/allocation_overflow.go @@ -75,7 +75,7 @@ func NewAllocatorOverflowController( health.AddLivenessCheck("gameserverset-allocationoverflow-workerqueue", c.workerqueue.Healthy) _, _ = gsSetInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ - UpdateFunc: func(oldObj, newObj interface{}) { + UpdateFunc: func(_, newObj interface{}) { newGss := newObj.(*agonesv1.GameServerSet) // Only process if there is an AllocationOverflow, and it has labels or annotations. diff --git a/pkg/gameserversets/allocation_overflow_test.go b/pkg/gameserversets/allocation_overflow_test.go index ffde7cf8b8..dcc88c11a7 100644 --- a/pkg/gameserversets/allocation_overflow_test.go +++ b/pkg/gameserversets/allocation_overflow_test.go @@ -124,10 +124,10 @@ func TestAllocationOverflowSyncGameServerSet(t *testing.T) { } c, m := newFakeAllocationOverflowController() - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: list}, nil }) return gsSet, c, m @@ -162,7 +162,7 @@ func TestAllocationOverflowSyncGameServerSet(t *testing.T) { gsSet, c, m := setup(func(gs *agonesv1.GameServer) { gs.ObjectMeta.Labels["colour"] = "green" }) - cancel := run(c, m, gsSet, func(action k8stesting.Action) (bool, runtime.Object, error) { + cancel := run(c, m, gsSet, func(_ k8stesting.Action) (bool, runtime.Object, error) { require.Fail(t, "should not update") return true, nil, nil }) diff --git a/pkg/gameserversets/controller.go b/pkg/gameserversets/controller.go index 03799e180e..4292f886e4 100644 --- a/pkg/gameserversets/controller.go +++ b/pkg/gameserversets/controller.go @@ -155,7 +155,7 @@ func NewController( _, _ = gsInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: c.gameServerEventHandler, - UpdateFunc: func(oldObj, newObj interface{}) { + UpdateFunc: func(_, newObj interface{}) { gs := newObj.(*agonesv1.GameServer) // ignore if already being deleted if gs.ObjectMeta.DeletionTimestamp == nil { @@ -607,6 +607,7 @@ func parallelize(gameServers chan *agonesv1.GameServer, parallelism int, work fu for range gameServers { // drain any remaining game servers in the channel, in case we did not consume them all + continue } // return first error from the channel, or nil if all successful. diff --git a/pkg/gameserversets/controller_test.go b/pkg/gameserversets/controller_test.go index 753431993c..c3c86d9616 100644 --- a/pkg/gameserversets/controller_test.go +++ b/pkg/gameserversets/controller_test.go @@ -557,7 +557,7 @@ func TestControllerWatchGameServers(t *testing.T) { received := make(chan string) defer close(received) - m.ExtClient.AddReactor("get", "customresourcedefinitions", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.ExtClient.AddReactor("get", "customresourcedefinitions", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, agtesting.NewEstablishedCRD(), nil }) gsSetWatch := watch.NewFake() @@ -650,17 +650,17 @@ func TestSyncGameServerSet(t *testing.T) { list[1].Status.State = agonesv1.GameServerStateShutdown c, m := newFakeController() - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: list}, nil }) - m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "gameserver should not update") return false, nil, nil }) - m.AgonesClient.AddReactor("create", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("create", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { assert.FailNow(t, "new gameservers should not be created") return false, nil, nil @@ -683,10 +683,10 @@ func TestSyncGameServerSet(t *testing.T) { count := 0 c, m := newFakeController() - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: list}, nil }) @@ -729,10 +729,10 @@ func TestSyncGameServerSet(t *testing.T) { count := 0 c, m := newFakeController() - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: list}, nil }) @@ -775,10 +775,10 @@ func TestSyncGameServerSet(t *testing.T) { count := 0 c, m := newFakeController() - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: list}, nil }) @@ -815,13 +815,13 @@ func TestSyncGameServerSet(t *testing.T) { count := 0 c, m := newFakeController() - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: list}, nil }) - m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("update", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { count++ return true, nil, nil }) @@ -848,10 +848,10 @@ func TestSyncGameServerSet(t *testing.T) { var deleted []string c, m := newFakeController() - m.AgonesClient.AddReactor("list", "gameserversets", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameserversets", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerSetList{Items: []agonesv1.GameServerSet{*gsSet}}, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: list}, nil }) m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { diff --git a/pkg/gameserversets/gameserver_state_cache_test.go b/pkg/gameserversets/gameserver_state_cache_test.go index e2e2900ee6..7009c60258 100644 --- a/pkg/gameserversets/gameserver_state_cache_test.go +++ b/pkg/gameserversets/gameserver_state_cache_test.go @@ -79,7 +79,7 @@ func TestGameServerSetCacheEntry(t *testing.T) { }{ { desc: "EmptyList", - setup: func(c *gameServerSetCacheEntry) {}, + setup: func(_ *gameServerSetCacheEntry) {}, list: nil, expected: nil, }, diff --git a/pkg/gameserversets/gameserversets_test.go b/pkg/gameserversets/gameserversets_test.go index 937cc4389b..d8dbc84420 100644 --- a/pkg/gameserversets/gameserversets_test.go +++ b/pkg/gameserversets/gameserversets_test.go @@ -229,7 +229,7 @@ func TestListGameServersByGameServerSetOwner(t *testing.T) { gs4.ObjectMeta.OwnerReferences = nil m := agtesting.NewMocks() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs1, *gs2, gs3, *gs4}}, nil }) diff --git a/pkg/metrics/controller.go b/pkg/metrics/controller.go index 3232c76860..887e105ae0 100644 --- a/pkg/metrics/controller.go +++ b/pkg/metrics/controller.go @@ -89,8 +89,8 @@ type Controller struct { // NewController returns a new metrics controller func NewController( - kubeClient kubernetes.Interface, - agonesClient versioned.Interface, + _ kubernetes.Interface, + _ versioned.Interface, kubeInformerFactory informers.SharedInformerFactory, agonesInformerFactory externalversions.SharedInformerFactory) *Controller { @@ -129,7 +129,7 @@ func NewController( _, _ = fInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: c.recordFleetChanges, - UpdateFunc: func(old, next interface{}) { + UpdateFunc: func(_, next interface{}) { c.recordFleetChanges(next) }, DeleteFunc: c.recordFleetDeletion, @@ -441,7 +441,7 @@ func (c *Controller) calcDuration(oldGs, newGs *agonesv1.GameServer) (duration f val, ok := c.gameServerStateLastChange.Get(oldGSKey) if !ok { err = fmt.Errorf("could not find expected key %s", oldGSKey) - return + return 0, err } c.gameServerStateLastChange.Remove(oldGSKey) duration = currentTime - val.(float64) diff --git a/pkg/metrics/controller_test.go b/pkg/metrics/controller_test.go index d42d6e4f40..c16f6c57df 100644 --- a/pkg/metrics/controller_test.go +++ b/pkg/metrics/controller_test.go @@ -44,7 +44,7 @@ type metricExporter struct { metrics []*metricdata.Metric } -func (e *metricExporter) ExportMetrics(ctx context.Context, metrics []*metricdata.Metric) error { +func (e *metricExporter) ExportMetrics(_ context.Context, metrics []*metricdata.Metric) error { e.metrics = metrics return nil } @@ -533,13 +533,13 @@ func TestControllerGameServersNodeState(t *testing.T) { resetMetrics() m := agtesting.NewMocks() - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { n1 := nodeWithName("node1") n2 := nodeWithName("node2") n3 := nodeWithName("node3") return true, &corev1.NodeList{Items: []corev1.Node{*n1, *n2, *n3}}, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, k8sruntime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, k8sruntime.Object, error) { gs1 := gameServerWithNode("node1") gs2 := gameServerWithNode("node2") gs3 := gameServerWithNode("node2") diff --git a/pkg/metrics/kubernetes_client.go b/pkg/metrics/kubernetes_client.go index bc0f9be690..4a5591dd1c 100644 --- a/pkg/metrics/kubernetes_client.go +++ b/pkg/metrics/kubernetes_client.go @@ -200,7 +200,7 @@ func (c *clientGoMetricAdapter) Register() { workqueue.SetProvider(c) } -func (clientGoMetricAdapter) Increment(ctx context.Context, code string, method string, host string) { +func (clientGoMetricAdapter) Increment(ctx context.Context, code string, method string, _ string) { RecordWithTags(ctx, []tag.Mutator{tag.Insert(keyStatusCode, code), tag.Insert(keyVerb, method)}, httpRequestTotalStats.M(int64(1))) } diff --git a/pkg/portallocator/portallocator_test.go b/pkg/portallocator/portallocator_test.go index fca169f845..94273ecefc 100644 --- a/pkg/portallocator/portallocator_test.go +++ b/pkg/portallocator/portallocator_test.go @@ -295,7 +295,7 @@ func TestPortRangeAllocatorAllocate(t *testing.T) { m := agtesting.NewMocks() pa := newRangeAllocator(agonesv1.DefaultPortRange, 10, 20, m.KubeInformerFactory, m.AgonesInformerFactory) - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { nl := &corev1.NodeList{Items: []corev1.Node{n1}} return true, nl, nil }) @@ -389,7 +389,7 @@ func TestPortRangeAllocatorMultithreadAllocate(t *testing.T) { m := agtesting.NewMocks() pa := newRangeAllocator(agonesv1.DefaultPortRange, 10, 20, m.KubeInformerFactory, m.AgonesInformerFactory) - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(k8stesting.Action) (bool, runtime.Object, error) { nl := &corev1.NodeList{Items: []corev1.Node{n1, n2}} return true, nl, nil }) @@ -428,7 +428,7 @@ func TestPortRangeAllocatorDeAllocate(t *testing.T) { m := agtesting.NewMocks() pa := newRangeAllocator(agonesv1.DefaultPortRange, 10, 20, m.KubeInformerFactory, m.AgonesInformerFactory) nodes := []corev1.Node{n1, n2, n3} - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { nl := &corev1.NodeList{Items: nodes} return true, nl, nil }) @@ -469,12 +469,12 @@ func TestPortRangeAllocatorSyncPortAllocations(t *testing.T) { m := agtesting.NewMocks() pa := newRangeAllocator(agonesv1.DefaultPortRange, 10, 20, m.KubeInformerFactory, m.AgonesInformerFactory) - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { nl := &corev1.NodeList{Items: []corev1.Node{n1, n2, n3}} return true, nl, nil }) - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gs1 := agonesv1.GameServer{ObjectMeta: metav1.ObjectMeta{Name: "gs1", UID: "1"}, Spec: agonesv1.GameServerSpec{ Ports: []agonesv1.GameServerPort{{PortPolicy: agonesv1.Dynamic, HostPort: 10}}, @@ -565,7 +565,7 @@ func TestPortRangeAllocatorSyncDeleteGameServer(t *testing.T) { pa := newRangeAllocator(agonesv1.DefaultPortRange, 10, 20, m.KubeInformerFactory, m.AgonesInformerFactory) - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { nl := &corev1.NodeList{Items: []corev1.Node{n1, n2, n3}} return true, nl, nil }) @@ -624,7 +624,7 @@ func TestNodePortAllocation(t *testing.T) { m := agtesting.NewMocks() pa := newRangeAllocator(agonesv1.DefaultPortRange, 10, 20, m.KubeInformerFactory, m.AgonesInformerFactory) nodes := []corev1.Node{n1, n2, n3} - m.KubeClient.AddReactor("list", "nodes", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.KubeClient.AddReactor("list", "nodes", func(_ k8stesting.Action) (bool, runtime.Object, error) { nl := &corev1.NodeList{Items: nodes} return true, nl, nil }) diff --git a/pkg/sdkserver/helper_test.go b/pkg/sdkserver/helper_test.go index 23f2acce9b..78f5cb7a0c 100644 --- a/pkg/sdkserver/helper_test.go +++ b/pkg/sdkserver/helper_test.go @@ -31,7 +31,7 @@ import ( func testHTTPHealth(t *testing.T, url string, expectedResponse string, expectedStatus int) { // do a poll, because this code could run before the health check becomes live - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 20*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 20*time.Second, true, func(_ context.Context) (done bool, err error) { resp, err := http.Get(url) if err != nil { logrus.WithError(err).Error("Error connecting to ", url) @@ -89,11 +89,11 @@ func (m *emptyMockStream) Context() context.Context { panic("implement me") } -func (m *emptyMockStream) SendMsg(msg interface{}) error { +func (m *emptyMockStream) SendMsg(_ interface{}) error { panic("implement me") } -func (m *emptyMockStream) RecvMsg(msg interface{}) error { +func (m *emptyMockStream) RecvMsg(_ interface{}) error { panic("implement me") } @@ -131,10 +131,10 @@ func (m *gameServerMockStream) Context() netcontext.Context { return m.ctx } -func (*gameServerMockStream) SendMsg(m interface{}) error { +func (*gameServerMockStream) SendMsg(_ interface{}) error { panic("implement me") } -func (*gameServerMockStream) RecvMsg(m interface{}) error { +func (*gameServerMockStream) RecvMsg(_ interface{}) error { panic("implement me") } diff --git a/pkg/sdkserver/localsdk.go b/pkg/sdkserver/localsdk.go index 3b54a9fbd8..2f5a2ce4ce 100644 --- a/pkg/sdkserver/localsdk.go +++ b/pkg/sdkserver/localsdk.go @@ -427,7 +427,7 @@ func (l *LocalSDKServer) stopReserveTimer() { // PlayerConnect should be called when a player connects. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (l *LocalSDKServer) PlayerConnect(ctx context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { +func (l *LocalSDKServer) PlayerConnect(_ context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return &alpha.Bool{Bool: false}, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -461,7 +461,7 @@ func (l *LocalSDKServer) PlayerConnect(ctx context.Context, id *alpha.PlayerID) // PlayerDisconnect should be called when a player disconnects. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (l *LocalSDKServer) PlayerDisconnect(ctx context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { +func (l *LocalSDKServer) PlayerDisconnect(_ context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return &alpha.Bool{Bool: false}, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -495,7 +495,7 @@ func (l *LocalSDKServer) PlayerDisconnect(ctx context.Context, id *alpha.PlayerI // IsPlayerConnected returns if the playerID is currently connected to the GameServer. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (l *LocalSDKServer) IsPlayerConnected(c context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { +func (l *LocalSDKServer) IsPlayerConnected(_ context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return &alpha.Bool{Bool: false}, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -524,7 +524,7 @@ func (l *LocalSDKServer) IsPlayerConnected(c context.Context, id *alpha.PlayerID // GetConnectedPlayers returns the list of the currently connected player ids. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (l *LocalSDKServer) GetConnectedPlayers(c context.Context, empty *alpha.Empty) (*alpha.PlayerIDList, error) { +func (l *LocalSDKServer) GetConnectedPlayers(_ context.Context, _ *alpha.Empty) (*alpha.PlayerIDList, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return nil, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -546,7 +546,7 @@ func (l *LocalSDKServer) GetConnectedPlayers(c context.Context, empty *alpha.Emp // GetPlayerCount returns the current player count. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (l *LocalSDKServer) GetPlayerCount(ctx context.Context, _ *alpha.Empty) (*alpha.Count, error) { +func (l *LocalSDKServer) GetPlayerCount(_ context.Context, _ *alpha.Empty) (*alpha.Count, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return nil, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -612,7 +612,7 @@ func (l *LocalSDKServer) GetPlayerCapacity(_ context.Context, _ *alpha.Empty) (* // GetCounter returns a Counter. Returns not found if the counter does not exist. // [Stage:Beta] // [FeatureFlag:CountsAndLists] -func (l *LocalSDKServer) GetCounter(ctx context.Context, in *beta.GetCounterRequest) (*beta.Counter, error) { +func (l *LocalSDKServer) GetCounter(_ context.Context, in *beta.GetCounterRequest) (*beta.Counter, error) { if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists) } @@ -638,7 +638,7 @@ func (l *LocalSDKServer) GetCounter(ctx context.Context, in *beta.GetCounterRequ // Returns error if the Count is out of range [0,Capacity]. // [Stage:Beta] // [FeatureFlag:CountsAndLists] -func (l *LocalSDKServer) UpdateCounter(ctx context.Context, in *beta.UpdateCounterRequest) (*beta.Counter, error) { +func (l *LocalSDKServer) UpdateCounter(_ context.Context, in *beta.UpdateCounterRequest) (*beta.Counter, error) { if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists) } @@ -697,7 +697,7 @@ func (l *LocalSDKServer) UpdateCounter(ctx context.Context, in *beta.UpdateCount // GetList returns a List. Returns not found if the List does not exist. // [Stage:Beta] // [FeatureFlag:CountsAndLists] -func (l *LocalSDKServer) GetList(ctx context.Context, in *beta.GetListRequest) (*beta.List, error) { +func (l *LocalSDKServer) GetList(_ context.Context, in *beta.GetListRequest) (*beta.List, error) { if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists) } @@ -721,7 +721,7 @@ func (l *LocalSDKServer) GetList(ctx context.Context, in *beta.GetListRequest) ( // then the default value for the variable will be set (i.e. 0 for "capacity", empty list for "values"). // [Stage:Beta] // [FeatureFlag:CountsAndLists] -func (l *LocalSDKServer) UpdateList(ctx context.Context, in *beta.UpdateListRequest) (*beta.List, error) { +func (l *LocalSDKServer) UpdateList(_ context.Context, in *beta.UpdateListRequest) (*beta.List, error) { if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists) } @@ -773,7 +773,7 @@ func (l *LocalSDKServer) UpdateList(ctx context.Context, in *beta.UpdateListRequ // Returns out of range if the List is already at Capacity. // [Stage:Beta] // [FeatureFlag:CountsAndLists] -func (l *LocalSDKServer) AddListValue(ctx context.Context, in *beta.AddListValueRequest) (*beta.List, error) { +func (l *LocalSDKServer) AddListValue(_ context.Context, in *beta.AddListValueRequest) (*beta.List, error) { if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists) } @@ -806,7 +806,7 @@ func (l *LocalSDKServer) AddListValue(ctx context.Context, in *beta.AddListValue // Returns not found if the value is not in the List. // [Stage:Beta] // [FeatureFlag:CountsAndLists] -func (l *LocalSDKServer) RemoveListValue(ctx context.Context, in *beta.RemoveListValueRequest) (*beta.List, error) { +func (l *LocalSDKServer) RemoveListValue(_ context.Context, in *beta.RemoveListValueRequest) (*beta.List, error) { if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists) } @@ -873,9 +873,8 @@ func (l *LocalSDKServer) compare() { // we don't care if the mutex gets unlocked on exit, so ignore the warning. // nolint: gocritic os.Exit(1) - } else { - l.logger.Info("Received requests match expected list. Test run was successful") } + l.logger.Info("Received requests match expected list. Test run was successful") } } diff --git a/pkg/sdkserver/localsdk_test.go b/pkg/sdkserver/localsdk_test.go index 44d310b2ce..d103713902 100644 --- a/pkg/sdkserver/localsdk_test.go +++ b/pkg/sdkserver/localsdk_test.go @@ -184,7 +184,7 @@ func TestLocalSDKServerSetLabel(t *testing.T) { assertInitialWatchUpdate(t, stream) // make sure length of l.updateObservers is at least 1 - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { ret := false l.updateObservers.Range(func(_, _ interface{}) bool { ret = true @@ -253,7 +253,7 @@ func TestLocalSDKServerSetAnnotation(t *testing.T) { assertInitialWatchUpdate(t, stream) // make sure length of l.updateObservers is at least 1 - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { ret := false l.updateObservers.Range(func(_, _ interface{}) bool { ret = true @@ -300,7 +300,7 @@ func TestLocalSDKServerWatchGameServer(t *testing.T) { assertInitialWatchUpdate(t, stream) // wait for watching to begin - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { found := false l.updateObservers.Range(func(_, _ interface{}) bool { found = true @@ -346,7 +346,7 @@ func TestLocalSDKServerPlayerCapacity(t *testing.T) { assertInitialWatchUpdate(t, stream) // wait for watching to begin - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { found := false l.updateObservers.Range(func(_, _ interface{}) bool { found = true @@ -494,7 +494,7 @@ func TestLocalSDKServerPlayerConnectAndDisconnect(t *testing.T) { assertInitialWatchUpdate(t, stream) // wait for watching to begin - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { found := false l.updateObservers.Range(func(_, _ interface{}) bool { found = true @@ -644,7 +644,7 @@ func TestLocalSDKServerGetCounter(t *testing.T) { assertInitialWatchUpdate(t, stream) // wait for watching to begin - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { found := false l.updateObservers.Range(func(_, _ interface{}) bool { found = true @@ -720,7 +720,7 @@ func TestLocalSDKServerUpdateCounter(t *testing.T) { assertInitialWatchUpdate(t, stream) // wait for watching to begin - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { found := false l.updateObservers.Range(func(_, _ interface{}) bool { found = true @@ -868,7 +868,7 @@ func TestLocalSDKServerGetList(t *testing.T) { assertInitialWatchUpdate(t, stream) // wait for watching to begin - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { found := false l.updateObservers.Range(func(_, _ interface{}) bool { found = true @@ -944,7 +944,7 @@ func TestLocalSDKServerUpdateList(t *testing.T) { assertInitialWatchUpdate(t, stream) // wait for watching to begin - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { found := false l.updateObservers.Range(func(_, _ interface{}) bool { found = true @@ -1140,7 +1140,7 @@ func TestLocalSDKServerAddListValue(t *testing.T) { assertInitialWatchUpdate(t, stream) // wait for watching to begin - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { found := false l.updateObservers.Range(func(_, _ interface{}) bool { found = true @@ -1232,7 +1232,7 @@ func TestLocalSDKServerRemoveListValue(t *testing.T) { assertInitialWatchUpdate(t, stream) // wait for watching to begin - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { found := false l.updateObservers.Range(func(_, _ interface{}) bool { found = true diff --git a/pkg/sdkserver/sdkserver.go b/pkg/sdkserver/sdkserver.go index 641bc3e90b..9d72571037 100644 --- a/pkg/sdkserver/sdkserver.go +++ b/pkg/sdkserver/sdkserver.go @@ -200,14 +200,14 @@ func NewSDKServer(gameServerName, namespace string, kubeClient kubernetes.Interf eventBroadcaster.StartRecordingToSink(&k8sv1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) s.recorder = eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "gameserver-sidecar"}) - mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { _, err := w.Write([]byte("ok")) if err != nil { s.logger.WithError(err).Error("could not send ok response on healthz") w.WriteHeader(http.StatusInternalServerError) } }) - mux.HandleFunc("/gshealthz", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/gshealthz", func(w http.ResponseWriter, _ *http.Request) { s.ensureHealthChecksRunning() if s.healthy() { _, err := w.Write([]byte("ok")) @@ -530,7 +530,7 @@ func (s *SDKServer) enqueueState(state agonesv1.GameServerState) { // Ready enters the RequestReady state change for this GameServer into // the workqueue so it can be updated -func (s *SDKServer) Ready(ctx context.Context, e *sdk.Empty) (*sdk.Empty, error) { +func (s *SDKServer) Ready(_ context.Context, e *sdk.Empty) (*sdk.Empty, error) { s.logger.Debug("Received Ready request, adding to queue") s.stopReserveTimer() s.enqueueState(agonesv1.GameServerStateRequestReady) @@ -538,7 +538,7 @@ func (s *SDKServer) Ready(ctx context.Context, e *sdk.Empty) (*sdk.Empty, error) } // Allocate enters an Allocate state change into the workqueue, so it can be updated -func (s *SDKServer) Allocate(ctx context.Context, e *sdk.Empty) (*sdk.Empty, error) { +func (s *SDKServer) Allocate(_ context.Context, e *sdk.Empty) (*sdk.Empty, error) { s.stopReserveTimer() s.enqueueState(agonesv1.GameServerStateAllocated) return e, nil @@ -547,7 +547,7 @@ func (s *SDKServer) Allocate(ctx context.Context, e *sdk.Empty) (*sdk.Empty, err // Shutdown enters the Shutdown state change for this GameServer into // the workqueue so it can be updated. If gracefulTermination feature is enabled, // Shutdown will block on GameServer being shutdown. -func (s *SDKServer) Shutdown(ctx context.Context, e *sdk.Empty) (*sdk.Empty, error) { +func (s *SDKServer) Shutdown(_ context.Context, e *sdk.Empty) (*sdk.Empty, error) { s.logger.Debug("Received Shutdown request, adding to queue") s.stopReserveTimer() s.enqueueState(agonesv1.GameServerStateShutdown) @@ -631,7 +631,7 @@ func (s *SDKServer) WatchGameServer(_ *sdk.Empty, stream sdk.SDK_WatchGameServer } // Reserve moves this GameServer to the Reserved state for the Duration specified -func (s *SDKServer) Reserve(ctx context.Context, d *sdk.Duration) (*sdk.Empty, error) { +func (s *SDKServer) Reserve(_ context.Context, d *sdk.Duration) (*sdk.Empty, error) { s.stopReserveTimer() e := &sdk.Empty{} @@ -678,7 +678,7 @@ func (s *SDKServer) stopReserveTimer() { // PlayerConnect should be called when a player connects. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (s *SDKServer) PlayerConnect(ctx context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { +func (s *SDKServer) PlayerConnect(_ context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return &alpha.Bool{Bool: false}, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -708,7 +708,7 @@ func (s *SDKServer) PlayerConnect(ctx context.Context, id *alpha.PlayerID) (*alp // PlayerDisconnect should be called when a player disconnects. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (s *SDKServer) PlayerDisconnect(ctx context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { +func (s *SDKServer) PlayerDisconnect(_ context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return &alpha.Bool{Bool: false}, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -739,7 +739,7 @@ func (s *SDKServer) PlayerDisconnect(ctx context.Context, id *alpha.PlayerID) (* // This is always accurate, even if the value hasn’t been updated to the GameServer status yet. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (s *SDKServer) IsPlayerConnected(ctx context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { +func (s *SDKServer) IsPlayerConnected(_ context.Context, id *alpha.PlayerID) (*alpha.Bool, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return &alpha.Bool{Bool: false}, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -762,7 +762,7 @@ func (s *SDKServer) IsPlayerConnected(ctx context.Context, id *alpha.PlayerID) ( // This is always accurate, even if the value hasn’t been updated to the GameServer status yet. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (s *SDKServer) GetConnectedPlayers(c context.Context, empty *alpha.Empty) (*alpha.PlayerIDList, error) { +func (s *SDKServer) GetConnectedPlayers(_ context.Context, _ *alpha.Empty) (*alpha.PlayerIDList, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return nil, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -775,7 +775,7 @@ func (s *SDKServer) GetConnectedPlayers(c context.Context, empty *alpha.Empty) ( // GetPlayerCount returns the current player count. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (s *SDKServer) GetPlayerCount(ctx context.Context, _ *alpha.Empty) (*alpha.Count, error) { +func (s *SDKServer) GetPlayerCount(_ context.Context, _ *alpha.Empty) (*alpha.Count, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return nil, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -787,7 +787,7 @@ func (s *SDKServer) GetPlayerCount(ctx context.Context, _ *alpha.Empty) (*alpha. // SetPlayerCapacity to change the game server's player capacity. // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (s *SDKServer) SetPlayerCapacity(ctx context.Context, count *alpha.Count) (*alpha.Empty, error) { +func (s *SDKServer) SetPlayerCapacity(_ context.Context, count *alpha.Count) (*alpha.Empty, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return nil, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -802,7 +802,7 @@ func (s *SDKServer) SetPlayerCapacity(ctx context.Context, count *alpha.Count) ( // GetPlayerCapacity returns the current player capacity, as set by SDK.SetPlayerCapacity() // [Stage:Alpha] // [FeatureFlag:PlayerTracking] -func (s *SDKServer) GetPlayerCapacity(ctx context.Context, _ *alpha.Empty) (*alpha.Count, error) { +func (s *SDKServer) GetPlayerCapacity(_ context.Context, _ *alpha.Empty) (*alpha.Count, error) { if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) { return nil, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking) } @@ -814,7 +814,7 @@ func (s *SDKServer) GetPlayerCapacity(ctx context.Context, _ *alpha.Empty) (*alp // GetCounter returns a Counter. Returns error if the counter does not exist. // [Stage:Beta] // [FeatureFlag:CountsAndLists] -func (s *SDKServer) GetCounter(ctx context.Context, in *beta.GetCounterRequest) (*beta.Counter, error) { +func (s *SDKServer) GetCounter(_ context.Context, in *beta.GetCounterRequest) (*beta.Counter, error) { if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists) } @@ -865,7 +865,7 @@ func (s *SDKServer) GetCounter(ctx context.Context, in *beta.GetCounterRequest) // Returns error if the Count is out of range [0,Capacity]. // [Stage:Beta] // [FeatureFlag:CountsAndLists] -func (s *SDKServer) UpdateCounter(ctx context.Context, in *beta.UpdateCounterRequest) (*beta.Counter, error) { +func (s *SDKServer) UpdateCounter(_ context.Context, in *beta.UpdateCounterRequest) (*beta.Counter, error) { if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists) } @@ -1015,7 +1015,7 @@ func (s *SDKServer) updateCounter(ctx context.Context) error { // GetList returns a List. Returns not found if the List does not exist. // [Stage:Beta] // [FeatureFlag:CountsAndLists] -func (s *SDKServer) GetList(ctx context.Context, in *beta.GetListRequest) (*beta.List, error) { +func (s *SDKServer) GetList(_ context.Context, in *beta.GetListRequest) (*beta.List, error) { if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists) } diff --git a/pkg/sdkserver/sdkserver_test.go b/pkg/sdkserver/sdkserver_test.go index 441e80a90c..d3476e82a8 100644 --- a/pkg/sdkserver/sdkserver_test.go +++ b/pkg/sdkserver/sdkserver_test.go @@ -103,7 +103,7 @@ func TestSidecarRun(t *testing.T) { }, }, "unhealthy": { - f: func(sc *SDKServer, ctx context.Context) { + f: func(sc *SDKServer, _ context.Context) { time.Sleep(1 * time.Second) sc.checkHealthUpdateState() // normally invoked from health check loop time.Sleep(2 * time.Second) // exceed 1s timeout @@ -184,7 +184,7 @@ func TestSidecarRun(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -314,7 +314,7 @@ func TestSDKServerSyncGameServer(t *testing.T) { Labels: map[string]string{}, Annotations: map[string]string{}}, } - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -380,7 +380,7 @@ func TestSidecarUpdateState(t *testing.T) { updated := false - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gs := agonesv1.GameServer{ ObjectMeta: metav1.ObjectMeta{Name: sc.gameServerName, Namespace: sc.namespace, ResourceVersion: "0"}, Status: agonesv1.GameServerStatus{}, @@ -391,7 +391,7 @@ func TestSidecarUpdateState(t *testing.T) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{gs}}, nil }) - m.AgonesClient.AddReactor("patch", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("patch", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { updated = true return true, nil, nil }) @@ -476,7 +476,7 @@ func TestSidecarUnhealthyMessage(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -621,7 +621,7 @@ func TestSidecarHTTPHealthCheck(t *testing.T) { // now we control time - so slow machines won't fail anymore sc.clock = fc - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { gs := agonesv1.GameServer{ ObjectMeta: metav1.ObjectMeta{Name: sc.gameServerName, Namespace: sc.namespace}, Spec: agonesv1.GameServerSpec{ @@ -674,7 +674,7 @@ func TestSDKServerGetGameServer(t *testing.T) { } m := agtesting.NewMocks() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*fixture}}, nil }) @@ -947,7 +947,7 @@ func TestSDKServerReserveTimeoutOnRun(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { n := metav1.NewTime(metav1.Now().Add(time.Second)) gsCopy := gs.DeepCopy() gsCopy.Status.ReservedUntil = &n @@ -1007,7 +1007,7 @@ func TestSDKServerReserveTimeout(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -1291,7 +1291,7 @@ func TestSDKServerUpdateCounter(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -1444,7 +1444,7 @@ func TestSDKServerAddListValue(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -1593,7 +1593,7 @@ func TestSDKServerRemoveListValue(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -1784,7 +1784,7 @@ func TestSDKServerUpdateList(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -1912,7 +1912,7 @@ func TestSDKServerPlayerCapacity(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -1937,7 +1937,7 @@ func TestSDKServerPlayerCapacity(t *testing.T) { // check initial value comes through // async, so check after a period - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { count, err := sc.GetPlayerCapacity(context.Background(), &alpha.Empty{}) return count.Count == 10, err }) @@ -1981,7 +1981,7 @@ func TestSDKServerPlayerConnectAndDisconnectWithoutPlayerTracking(t *testing.T) } m := agtesting.NewMocks() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*fixture}}, nil }) @@ -2003,7 +2003,7 @@ func TestSDKServerPlayerConnectAndDisconnectWithoutPlayerTracking(t *testing.T) // check initial value comes through // async, so check after a period e := &alpha.Empty{} - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { count, err := sc.GetPlayerCapacity(context.Background(), e) assert.Nil(t, count) @@ -2066,7 +2066,7 @@ func TestSDKServerPlayerConnectAndDisconnect(t *testing.T) { } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -2089,7 +2089,7 @@ func TestSDKServerPlayerConnectAndDisconnect(t *testing.T) { // check initial value comes through // async, so check after a period e := &alpha.Empty{} - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { count, err := sc.GetPlayerCapacity(context.Background(), e) return count.Count == capacity, err }) @@ -2233,7 +2233,7 @@ func TestSDKServerGracefulTerminationInterrupt(t *testing.T) { Spec: agonesv1.GameServerSpec{Health: agonesv1.Health{Disabled: true}}, } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) sc, err := defaultSidecar(m) @@ -2298,7 +2298,7 @@ func TestSDKServerGracefulTerminationShutdown(t *testing.T) { Spec: agonesv1.GameServerSpec{Health: agonesv1.Health{Disabled: true}}, } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -2363,7 +2363,7 @@ func TestSDKServerGracefulTerminationGameServerStateChannel(t *testing.T) { Spec: agonesv1.GameServerSpec{Health: agonesv1.Health{Disabled: true}}, } gs.ApplyDefaults() - m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) { + m.AgonesClient.AddReactor("list", "gameservers", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*gs.DeepCopy()}}, nil }) @@ -2398,7 +2398,7 @@ func defaultSidecar(m agtesting.Mocks) (*SDKServer, error) { } func waitForMessage(sc *SDKServer) error { - return wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(ctx context.Context) (done bool, err error) { + return wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(_ context.Context) (done bool, err error) { sc.healthMutex.RLock() defer sc.healthMutex.RUnlock() return sc.clock.Now().UTC() == sc.healthLastUpdated, nil @@ -2406,7 +2406,7 @@ func waitForMessage(sc *SDKServer) error { } func waitConnectedStreamCount(sc *SDKServer, count int) error { //nolint:unparam // Keep flexibility. - return wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) { + return wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 10*time.Second, true, func(_ context.Context) (bool, error) { sc.streamMutex.RLock() defer sc.streamMutex.RUnlock() return len(sc.connectedStreams) == count, nil diff --git a/pkg/testing/apihooks.go b/pkg/testing/apihooks.go index 9e61217c0b..8b409dd7bd 100644 --- a/pkg/testing/apihooks.go +++ b/pkg/testing/apihooks.go @@ -38,11 +38,11 @@ func (f FakeAPIHooks) ValidateScheduling(_ apis.SchedulingStrategy, _ *field.Pat } // MutateGameServerPod is called by createGameServerPod to allow for product specific pod mutation. -func (f FakeAPIHooks) MutateGameServerPod(_ *agonesv1.GameServerSpec, pod *corev1.Pod) error { +func (f FakeAPIHooks) MutateGameServerPod(_ *agonesv1.GameServerSpec, _ *corev1.Pod) error { return nil } // SetEviction is called by gs.Pod to enforce GameServer.Status.Eviction. -func (f FakeAPIHooks) SetEviction(_ *agonesv1.Eviction, pod *corev1.Pod) error { +func (f FakeAPIHooks) SetEviction(_ *agonesv1.Eviction, _ *corev1.Pod) error { return nil } diff --git a/pkg/util/apiserver/apiserver.go b/pkg/util/apiserver/apiserver.go index 8476970f4e..b5b70a0129 100644 --- a/pkg/util/apiserver/apiserver.go +++ b/pkg/util/apiserver/apiserver.go @@ -99,7 +99,7 @@ func NewAPIServer(mux *http.ServeMux) *APIServer { // We don't *have* to have a v3 openapi api, so just do an empty one for now, and we can expand as needed. // If we implement /v3/ we can likely omit the /v2/ handler since only one is needed. // This at least stops the K8s api pinging us for the spec all the time. - mux.HandleFunc("/openapi/v3", https.ErrorHTTPHandler(s.logger, func(w http.ResponseWriter, r *http.Request) error { + mux.HandleFunc("/openapi/v3", https.ErrorHTTPHandler(s.logger, func(w http.ResponseWriter, _ *http.Request) error { w.Header().Set(ContentTypeHeader, k8sruntime.ContentTypeJSON) err := json.NewEncoder(w).Encode(s.openapiv3Discovery) if err != nil { @@ -112,7 +112,7 @@ func NewAPIServer(mux *http.ServeMux) *APIServer { // kube-openapi could be a potential library to look at for future if we want to be more specific. // This at least stops the K8s api pinging us for every iteration of a api descriptor that may exist s.openapiv2.SwaggerProps.Info = &spec.Info{InfoProps: spec.InfoProps{Title: "allocation.agones.dev"}} - mux.HandleFunc("/openapi/v2", https.ErrorHTTPHandler(s.logger, func(w http.ResponseWriter, r *http.Request) error { + mux.HandleFunc("/openapi/v2", https.ErrorHTTPHandler(s.logger, func(w http.ResponseWriter, _ *http.Request) error { w.Header().Set(ContentTypeHeader, k8sruntime.ContentTypeJSON) err := json.NewEncoder(w).Encode(s.openapiv2) if err != nil { @@ -123,7 +123,7 @@ func NewAPIServer(mux *http.ServeMux) *APIServer { // We don't currently support a root /apis, but since Aggregate Discovery expects // a 406, let's give it what it wants, otherwise namespaces don't successfully terminate on <= 1.27.2 - mux.HandleFunc("/apis", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/apis", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotAcceptable) w.Header().Set(ContentTypeHeader, k8sruntime.ContentTypeJSON) }) diff --git a/pkg/util/crd/crd.go b/pkg/util/crd/crd.go index e80a77fc3a..791433849d 100644 --- a/pkg/util/crd/crd.go +++ b/pkg/util/crd/crd.go @@ -29,7 +29,7 @@ import ( // WaitForEstablishedCRD blocks until CRD comes to an Established state. // Has a deadline of 60 seconds for this to occur. -func WaitForEstablishedCRD(ctx context.Context, crdGetter apiextclientv1.CustomResourceDefinitionInterface, name string, logger *logrus.Entry) error { +func WaitForEstablishedCRD(_ context.Context, crdGetter apiextclientv1.CustomResourceDefinitionInterface, name string, logger *logrus.Entry) error { return wait.PollUntilContextTimeout(context.Background(), time.Second, 60*time.Second, true, func(ctx context.Context) (done bool, err error) { crd, err := crdGetter.Get(ctx, name, metav1.GetOptions{}) if err != nil { diff --git a/pkg/util/crd/crd_test.go b/pkg/util/crd/crd_test.go index 172d9955f9..72287158d3 100644 --- a/pkg/util/crd/crd_test.go +++ b/pkg/util/crd/crd_test.go @@ -41,7 +41,7 @@ func TestWaitForEstablishedCRD(t *testing.T) { t.Run("CRD already established", func(t *testing.T) { extClient := &extfake.Clientset{} - extClient.AddReactor("get", "customresourcedefinitions", func(action k8stesting.Action) (bool, runtime.Object, error) { + extClient.AddReactor("get", "customresourcedefinitions", func(_ k8stesting.Action) (bool, runtime.Object, error) { return true, crd, nil }) @@ -54,7 +54,7 @@ func TestWaitForEstablishedCRD(t *testing.T) { m := sync.RWMutex{} established := false - extClient.AddReactor("get", "customresourcedefinitions", func(action k8stesting.Action) (bool, runtime.Object, error) { + extClient.AddReactor("get", "customresourcedefinitions", func(_ k8stesting.Action) (bool, runtime.Object, error) { m.RLock() defer m.RUnlock() if established { diff --git a/pkg/util/https/https.go b/pkg/util/https/https.go index dc23304f5f..dac0292b57 100644 --- a/pkg/util/https/https.go +++ b/pkg/util/https/https.go @@ -30,7 +30,7 @@ type ErrorHandlerFunc func(http.ResponseWriter, *http.Request) error // FourZeroFour is the standard 404 handler. func FourZeroFour(logger *logrus.Entry, w http.ResponseWriter, r *http.Request) { - f := ErrorHTTPHandler(logger, func(writer http.ResponseWriter, request *http.Request) error { + f := ErrorHTTPHandler(logger, func(_ http.ResponseWriter, _ *http.Request) error { body, err := io.ReadAll(r.Body) if err != nil { return errors.Wrap(err, "error in default handler") diff --git a/pkg/util/https/server.go b/pkg/util/https/server.go index 4d7c4e50c0..d9f15b8251 100644 --- a/pkg/util/https/server.go +++ b/pkg/util/https/server.go @@ -94,7 +94,7 @@ func (s *Server) setupServer() { } // getCertificate returns the current TLS certificate -func (s *Server) getCertificate(hello *cryptotls.ClientHelloInfo) (*cryptotls.Certificate, error) { +func (s *Server) getCertificate(_ *cryptotls.ClientHelloInfo) (*cryptotls.Certificate, error) { s.certServer.certMu.Lock() defer s.certServer.certMu.Unlock() return s.certServer.certs, nil @@ -131,7 +131,7 @@ func (s *Server) Run(ctx context.Context, _ int) error { _ = s.tls.Shutdown(context.Background()) }() - s.logger.WithField("server", s).Infof("https server started on port :" + s.port) + s.logger.WithField("server", s).Infof("https server started on port :%s", s.port) err := s.tls.ListenAndServeTLS(s.certFile, s.keyFile) if err == http.ErrServerClosed { diff --git a/pkg/util/https/server_test.go b/pkg/util/https/server_test.go index f9c6232128..6c4232944a 100644 --- a/pkg/util/https/server_test.go +++ b/pkg/util/https/server_test.go @@ -33,7 +33,7 @@ func (ts *testServer) Shutdown(_ context.Context) error { } // ListenAndServeTLS(certFile, keyFile string) error -func (ts *testServer) ListenAndServeTLS(certFile, keyFile string) error { +func (ts *testServer) ListenAndServeTLS(_, _ string) error { ts.server.StartTLS() return nil } diff --git a/pkg/util/runtime/runtime.go b/pkg/util/runtime/runtime.go index b497b5718b..bc3167e7e0 100644 --- a/pkg/util/runtime/runtime.go +++ b/pkg/util/runtime/runtime.go @@ -48,7 +48,7 @@ func init() { }, }) - runtime.ErrorHandlers[0] = func(_ context.Context, err error, msg string, keysAndValues ...interface{}) { + runtime.ErrorHandlers[0] = func(_ context.Context, err error, _ string, _ ...interface{}) { if stackTrace, ok := err.(stackTracer); ok { var stack []string for _, f := range stackTrace.StackTrace() { diff --git a/pkg/util/runtime/runtime_test.go b/pkg/util/runtime/runtime_test.go index ba3c239429..54a0a75291 100644 --- a/pkg/util/runtime/runtime_test.go +++ b/pkg/util/runtime/runtime_test.go @@ -30,7 +30,7 @@ func TestHandleError(t *testing.T) { defer func() { runtime.ErrorHandlers = old }() var result error runtime.ErrorHandlers = []runtime.ErrorHandler{ - func(_ context.Context, err error, msg string, keysAndValues ...interface{}) { + func(_ context.Context, err error, _ string, _ ...interface{}) { result = err }, } diff --git a/pkg/util/workerqueue/workerqueue_test.go b/pkg/util/workerqueue/workerqueue_test.go index d68533fda5..ed073d2149 100644 --- a/pkg/util/workerqueue/workerqueue_test.go +++ b/pkg/util/workerqueue/workerqueue_test.go @@ -36,7 +36,7 @@ func TestWorkerQueueRun(t *testing.T) { received := make(chan string) defer close(received) - syncHandler := func(ctx context.Context, name string) error { + syncHandler := func(_ context.Context, name string) error { assert.Equal(t, "default/test", name) received <- name return nil @@ -79,7 +79,7 @@ func TestWorkerQueueHealthy(t *testing.T) { go wq.Run(ctx, 1) // Yield to the scheduler to ensure the worker queue goroutine can run. - err := wait.PollUntilContextTimeout(context.Background(), 100*time.Millisecond, 3*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), 100*time.Millisecond, 3*time.Second, true, func(_ context.Context) (done bool, err error) { if (wq.RunCount() == 1) && wq.Healthy() == nil { return true, nil } @@ -93,7 +93,7 @@ func TestWorkerQueueHealthy(t *testing.T) { // Yield to the scheduler again to ensure the worker queue goroutine can // finish. - err = wait.PollUntilContextTimeout(context.Background(), 100*time.Millisecond, 3*time.Second, true, func(ctx context.Context) (done bool, err error) { + err = wait.PollUntilContextTimeout(context.Background(), 100*time.Millisecond, 3*time.Second, true, func(_ context.Context) (done bool, err error) { if (wq.RunCount() == 0) && wq.Healthy() != nil { return true, nil } @@ -121,7 +121,7 @@ func TestWorkQueueHealthCheck(t *testing.T) { go wq.Run(ctx, workersCount) // Wait for worker to actually start - err := wait.PollUntilContextTimeout(context.Background(), 100*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextTimeout(context.Background(), 100*time.Millisecond, 5*time.Second, true, func(_ context.Context) (bool, error) { rc := wq.RunCount() logrus.WithField("runcount", rc).Info("Checking run count before liveness check") return rc == workersCount, nil @@ -130,7 +130,7 @@ func TestWorkQueueHealthCheck(t *testing.T) { f := func(t *testing.T, url string, status int) { // sometimes the http server takes a bit to start up - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(_ context.Context) (done bool, err error) { resp, err := http.Get(url) assert.Nil(t, err) defer resp.Body.Close() // nolint: errcheck @@ -155,7 +155,7 @@ func TestWorkQueueHealthCheck(t *testing.T) { cancel() // closing can take a short while - err = wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(_ context.Context) (bool, error) { rc := wq.RunCount() logrus.WithField("runcount", rc).Info("Checking run count") return rc == 0, nil @@ -171,7 +171,7 @@ func TestWorkerQueueEnqueueAfter(t *testing.T) { t.Parallel() updated := make(chan bool) - syncHandler := func(ctx context.Context, s string) error { + syncHandler := func(_ context.Context, _ string) error { updated <- true return nil } diff --git a/sdks/go/alpha_test.go b/sdks/go/alpha_test.go index 3100c1f7d9..9ba11fe035 100644 --- a/sdks/go/alpha_test.go +++ b/sdks/go/alpha_test.go @@ -79,35 +79,35 @@ type alphaMock struct { playerDisconnected string } -func (a *alphaMock) PlayerConnect(ctx context.Context, id *alpha.PlayerID, opts ...grpc.CallOption) (*alpha.Bool, error) { +func (a *alphaMock) PlayerConnect(_ context.Context, id *alpha.PlayerID, _ ...grpc.CallOption) (*alpha.Bool, error) { a.playerConnected = id.PlayerID a.playerCount++ return &alpha.Bool{Bool: true}, nil } -func (a *alphaMock) PlayerDisconnect(ctx context.Context, id *alpha.PlayerID, opts ...grpc.CallOption) (*alpha.Bool, error) { +func (a *alphaMock) PlayerDisconnect(_ context.Context, id *alpha.PlayerID, _ ...grpc.CallOption) (*alpha.Bool, error) { a.playerDisconnected = id.PlayerID a.playerCount-- return &alpha.Bool{Bool: true}, nil } -func (a *alphaMock) IsPlayerConnected(ctx context.Context, id *alpha.PlayerID, opts ...grpc.CallOption) (*alpha.Bool, error) { +func (a *alphaMock) IsPlayerConnected(_ context.Context, id *alpha.PlayerID, _ ...grpc.CallOption) (*alpha.Bool, error) { return &alpha.Bool{Bool: id.PlayerID == a.playerConnected}, nil } -func (a *alphaMock) GetConnectedPlayers(ctx context.Context, in *alpha.Empty, opts ...grpc.CallOption) (*alpha.PlayerIDList, error) { +func (a *alphaMock) GetConnectedPlayers(_ context.Context, _ *alpha.Empty, _ ...grpc.CallOption) (*alpha.PlayerIDList, error) { return &alpha.PlayerIDList{List: []string{a.playerConnected}}, nil } -func (a *alphaMock) SetPlayerCapacity(ctx context.Context, in *alpha.Count, opts ...grpc.CallOption) (*alpha.Empty, error) { +func (a *alphaMock) SetPlayerCapacity(_ context.Context, in *alpha.Count, _ ...grpc.CallOption) (*alpha.Empty, error) { a.capacity = in.Count return &alpha.Empty{}, nil } -func (a *alphaMock) GetPlayerCapacity(ctx context.Context, in *alpha.Empty, opts ...grpc.CallOption) (*alpha.Count, error) { +func (a *alphaMock) GetPlayerCapacity(_ context.Context, _ *alpha.Empty, _ ...grpc.CallOption) (*alpha.Count, error) { return &alpha.Count{Count: a.capacity}, nil } -func (a *alphaMock) GetPlayerCount(ctx context.Context, in *alpha.Empty, opts ...grpc.CallOption) (*alpha.Count, error) { +func (a *alphaMock) GetPlayerCount(_ context.Context, _ *alpha.Empty, _ ...grpc.CallOption) (*alpha.Count, error) { return &alpha.Count{Count: a.playerCount}, nil } diff --git a/sdks/go/beta_test.go b/sdks/go/beta_test.go index d651ca31c1..b5b68a4a92 100644 --- a/sdks/go/beta_test.go +++ b/sdks/go/beta_test.go @@ -282,14 +282,14 @@ type betaMock struct { lists map[string]*beta.List } -func (b *betaMock) GetCounter(ctx context.Context, in *beta.GetCounterRequest, opts ...grpc.CallOption) (*beta.Counter, error) { +func (b *betaMock) GetCounter(_ context.Context, in *beta.GetCounterRequest, _ ...grpc.CallOption) (*beta.Counter, error) { if counter, ok := b.counters[in.Name]; ok { return counter, nil } return nil, errors.Errorf("counter not found: %s", in.Name) } -func (b *betaMock) UpdateCounter(ctx context.Context, in *beta.UpdateCounterRequest, opts ...grpc.CallOption) (*beta.Counter, error) { +func (b *betaMock) UpdateCounter(ctx context.Context, in *beta.UpdateCounterRequest, _ ...grpc.CallOption) (*beta.Counter, error) { counter, err := b.GetCounter(ctx, &beta.GetCounterRequest{Name: in.CounterUpdateRequest.Name}) if err != nil { return nil, err @@ -325,7 +325,7 @@ func (b *betaMock) UpdateCounter(ctx context.Context, in *beta.UpdateCounterRequ // GetList returns the list of betaMock. Note: unlike the SDK Server, this does not return // a list with any pending batched changes applied. -func (b *betaMock) GetList(ctx context.Context, in *beta.GetListRequest, opts ...grpc.CallOption) (*beta.List, error) { +func (b *betaMock) GetList(_ context.Context, in *beta.GetListRequest, _ ...grpc.CallOption) (*beta.List, error) { if in == nil { return nil, errors.Errorf("GetListRequest cannot be nil") } @@ -337,7 +337,7 @@ func (b *betaMock) GetList(ctx context.Context, in *beta.GetListRequest, opts .. // Note: unlike the SDK Server, UpdateList does not batch changes and instead updates the list // directly. -func (b *betaMock) UpdateList(ctx context.Context, in *beta.UpdateListRequest, opts ...grpc.CallOption) (*beta.List, error) { +func (b *betaMock) UpdateList(_ context.Context, in *beta.UpdateListRequest, _ ...grpc.CallOption) (*beta.List, error) { if in == nil { return nil, errors.Errorf("UpdateListRequest cannot be nil") } @@ -358,7 +358,7 @@ func (b *betaMock) UpdateList(ctx context.Context, in *beta.UpdateListRequest, o // Note: unlike the SDK Server, AddListValue does not batch changes and instead updates the list // directly. -func (b *betaMock) AddListValue(ctx context.Context, in *beta.AddListValueRequest, opts ...grpc.CallOption) (*beta.List, error) { +func (b *betaMock) AddListValue(_ context.Context, in *beta.AddListValueRequest, _ ...grpc.CallOption) (*beta.List, error) { if in == nil { return nil, errors.Errorf("AddListValueRequest cannot be nil") } @@ -381,7 +381,7 @@ func (b *betaMock) AddListValue(ctx context.Context, in *beta.AddListValueReques // Note: unlike the SDK Server, RemoveListValue does not batch changes and instead updates the list // directly. -func (b *betaMock) RemoveListValue(ctx context.Context, in *beta.RemoveListValueRequest, opts ...grpc.CallOption) (*beta.List, error) { +func (b *betaMock) RemoveListValue(_ context.Context, in *beta.RemoveListValueRequest, _ ...grpc.CallOption) (*beta.List, error) { if in == nil { return nil, errors.Errorf("RemoveListValueRequest cannot be nil") } diff --git a/sdks/go/sdk_test.go b/sdks/go/sdk_test.go index 2881a1ad7c..60535a6073 100644 --- a/sdks/go/sdk_test.go +++ b/sdks/go/sdk_test.go @@ -143,44 +143,44 @@ type sdkMock struct { annotations map[string]string } -func (m *sdkMock) SetLabel(ctx context.Context, in *sdk.KeyValue, opts ...grpc.CallOption) (*sdk.Empty, error) { +func (m *sdkMock) SetLabel(_ context.Context, in *sdk.KeyValue, _ ...grpc.CallOption) (*sdk.Empty, error) { m.labels["agones.dev/sdk-"+in.Key] = in.Value return &sdk.Empty{}, nil } -func (m *sdkMock) SetAnnotation(ctx context.Context, in *sdk.KeyValue, opts ...grpc.CallOption) (*sdk.Empty, error) { +func (m *sdkMock) SetAnnotation(_ context.Context, in *sdk.KeyValue, _ ...grpc.CallOption) (*sdk.Empty, error) { m.annotations["agones.dev/sdk-"+in.Key] = in.Value return &sdk.Empty{}, nil } -func (m *sdkMock) WatchGameServer(ctx context.Context, in *sdk.Empty, opts ...grpc.CallOption) (sdk.SDK_WatchGameServerClient, error) { +func (m *sdkMock) WatchGameServer(_ context.Context, _ *sdk.Empty, _ ...grpc.CallOption) (sdk.SDK_WatchGameServerClient, error) { return m.wm, nil } -func (m *sdkMock) GetGameServer(ctx context.Context, in *sdk.Empty, opts ...grpc.CallOption) (*sdk.GameServer, error) { +func (m *sdkMock) GetGameServer(_ context.Context, _ *sdk.Empty, _ ...grpc.CallOption) (*sdk.GameServer, error) { return &sdk.GameServer{}, nil } -func (m *sdkMock) Ready(ctx context.Context, e *sdk.Empty, opts ...grpc.CallOption) (*sdk.Empty, error) { +func (m *sdkMock) Ready(_ context.Context, e *sdk.Empty, _ ...grpc.CallOption) (*sdk.Empty, error) { m.ready = true return e, nil } -func (m *sdkMock) Allocate(ctx context.Context, e *sdk.Empty, opts ...grpc.CallOption) (*sdk.Empty, error) { +func (m *sdkMock) Allocate(_ context.Context, e *sdk.Empty, _ ...grpc.CallOption) (*sdk.Empty, error) { m.allocated = true return e, nil } -func (m *sdkMock) Shutdown(ctx context.Context, e *sdk.Empty, opts ...grpc.CallOption) (*sdk.Empty, error) { +func (m *sdkMock) Shutdown(_ context.Context, e *sdk.Empty, _ ...grpc.CallOption) (*sdk.Empty, error) { m.shutdown = true return e, nil } -func (m *sdkMock) Health(ctx context.Context, opts ...grpc.CallOption) (sdk.SDK_HealthClient, error) { +func (m *sdkMock) Health(_ context.Context, _ ...grpc.CallOption) (sdk.SDK_HealthClient, error) { return m.hm, nil } -func (m *sdkMock) Reserve(ctx context.Context, in *sdk.Duration, opts ...grpc.CallOption) (*sdk.Empty, error) { +func (m *sdkMock) Reserve(_ context.Context, in *sdk.Duration, _ ...grpc.CallOption) (*sdk.Empty, error) { m.reserved = in return &sdk.Empty{}, nil } @@ -214,11 +214,11 @@ func (h *healthMock) Context() context.Context { panic("implement me") } -func (h *healthMock) SendMsg(m interface{}) error { +func (h *healthMock) SendMsg(_ interface{}) error { panic("implement me") } -func (h *healthMock) RecvMsg(m interface{}) error { +func (h *healthMock) RecvMsg(_ interface{}) error { panic("implement me") } @@ -246,10 +246,10 @@ func (*watchMock) Context() context.Context { panic("implement me") } -func (*watchMock) SendMsg(m interface{}) error { +func (*watchMock) SendMsg(_ interface{}) error { panic("implement me") } -func (*watchMock) RecvMsg(m interface{}) error { +func (*watchMock) RecvMsg(_ interface{}) error { panic("implement me") } diff --git a/test/e2e/allocator/pod_termination_test.go b/test/e2e/allocator/pod_termination_test.go index 9aff4b9bd8..51c8be614e 100644 --- a/test/e2e/allocator/pod_termination_test.go +++ b/test/e2e/allocator/pod_termination_test.go @@ -91,7 +91,7 @@ func TestAllocatorAfterDeleteReplica(t *testing.T) { } // Wait and keep making calls till we know the draining time has passed - _ = wait.PollUntilContextTimeout(context.Background(), retryInterval, retryTimeout, true, func(ctx context.Context) (bool, error) { + _ = wait.PollUntilContextTimeout(context.Background(), retryInterval, retryTimeout, true, func(_ context.Context) (bool, error) { response, err := grpcClient.Allocate(context.Background(), request) logger.Infof("err = %v (code = %v), response = %v", err, status.Code(err), response) helper.ValidateAllocatorResponse(t, response) diff --git a/test/e2e/allocator_test.go b/test/e2e/allocator_test.go index 4e79a3831b..a393dabf54 100644 --- a/test/e2e/allocator_test.go +++ b/test/e2e/allocator_test.go @@ -277,7 +277,7 @@ func TestRestAllocatorWithDeprecatedRequired(t *testing.T) { } // wait for the allocation system to come online - err = wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 5*time.Minute, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 5*time.Minute, true, func(_ context.Context) (bool, error) { resp, err := client.Do(req) if err != nil { logrus.WithError(err).Info("failed Allocate rest request") @@ -523,7 +523,7 @@ func TestRestAllocatorWithSelectors(t *testing.T) { // wait for the allocation system to come online var response pb.AllocationResponse - err = wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 5*time.Minute, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 5*time.Minute, true, func(_ context.Context) (bool, error) { resp, err := client.Do(req) if err != nil { logrus.WithError(err).Info("failed Allocate rest request") diff --git a/test/e2e/fleet_test.go b/test/e2e/fleet_test.go index 440d8851bf..dc74d4014a 100644 --- a/test/e2e/fleet_test.go +++ b/test/e2e/fleet_test.go @@ -139,7 +139,7 @@ func TestFleetScaleWithDualAllocations(t *testing.T) { framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas)) _ = framework.CreateAndApplyAllocation(t, flt) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 1 }) @@ -189,7 +189,7 @@ func TestFleetScaleWithDualAllocations(t *testing.T) { // Scale the fleet down to 2 replicas. framework.ScaleFleet(t, log, flt, 2) - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { log.WithField("fleet", fmt.Sprintf("%+v", fleet.Status)).Info("Checking after 2 more allocations, and scaling to 2") return fleet.Status.AllocatedReplicas == 3 && fleet.Status.ReadyReplicas == 0 }) @@ -198,7 +198,7 @@ func TestFleetScaleWithDualAllocations(t *testing.T) { // Then scale the fleet back to 10 replicas. framework.ScaleFleet(t, log, flt, 5) require.NoError(t, err) - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { log.WithField("fleet", fmt.Sprintf("%+v", fleet.Status)).Info("Checking after scaling back to 5") return fleet.Status.AllocatedReplicas == 3 && fleet.Status.ReadyReplicas == 2 }) @@ -229,7 +229,7 @@ func TestFleetScaleUpAllocateEditAndScaleDownToZero(t *testing.T) { // Allocate 1 replica gsa := framework.CreateAndApplyAllocation(t, flt) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 1 }) @@ -269,7 +269,7 @@ func TestFleetScaleUpAllocateEditAndScaleDownToZero(t *testing.T) { require.NoError(t, err) // RollingUpdate has happened due to changing Port, so waiting the complete of the RollingUpdate - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.ReadyReplicas == 4 }) @@ -286,11 +286,11 @@ func TestFleetScaleUpAllocateEditAndScaleDownToZero(t *testing.T) { framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(0)) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 0 }) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.Replicas == 0 }) @@ -332,7 +332,7 @@ func TestFleetScaleUpEditAndScaleDown(t *testing.T) { framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(targetScale)) gsa := framework.CreateAndApplyAllocation(t, flt) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 1 }) @@ -382,7 +382,7 @@ func TestFleetScaleUpEditAndScaleDown(t *testing.T) { framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(1)) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 0 }) }) @@ -481,7 +481,7 @@ func TestFleetRollingUpdate(t *testing.T) { // Wait for at least half of the fleet to have be cycled (either Allocated or shutting down) // before updating the fleet. - err = framework.WaitForFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + err = framework.WaitForFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.ReadyReplicas < halfScale }) } @@ -573,7 +573,7 @@ func TestFleetRollingUpdate(t *testing.T) { framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(1)) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 0 }) }) @@ -669,7 +669,7 @@ func TestScaleFleetUpAndDownWithGameServerAllocation(t *testing.T) { gsa, err = framework.AgonesClient.AllocationV1().GameServerAllocations(framework.Namespace).Create(ctx, gsa, metav1.CreateOptions{}) require.NoError(t, err) assert.Equal(t, allocationv1.GameServerAllocationAllocated, gsa.Status.State) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 1 }) @@ -689,7 +689,7 @@ func TestScaleFleetUpAndDownWithGameServerAllocation(t *testing.T) { require.NoError(t, err) framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(1)) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 0 }) }) @@ -753,7 +753,7 @@ func TestFleetUpdates(t *testing.T) { require.NoError(t, err) // let's make sure we're fully Ready - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return flt.Spec.Replicas == fleet.Status.ReadyReplicas }) @@ -798,7 +798,7 @@ func TestUpdateGameServerConfigurationInFleet(t *testing.T) { gsa, err = framework.AgonesClient.AllocationV1().GameServerAllocations(framework.Namespace).Create(ctx, gsa, metav1.CreateOptions{}) require.NoError(t, err) assert.Equal(t, allocationv1.GameServerAllocationAllocated, gsa.Status.State) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 1 }) @@ -849,7 +849,7 @@ func TestReservedGameServerInFleet(t *testing.T) { assert.NoError(t, err) // make sure counts are correct - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.ReadyReplicas == 2 && fleet.Status.ReservedReplicas == 1 }) @@ -865,7 +865,7 @@ func TestReservedGameServerInFleet(t *testing.T) { }) // check against gameservers directly too, just to be extra sure - err = wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 5*time.Minute, true, func(ctx context.Context) (done bool, err error) { + err = wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 5*time.Minute, true, func(_ context.Context) (done bool, err error) { list, err := framework.ListGameServersFromFleet(flt) if err != nil { return true, err @@ -1593,7 +1593,7 @@ func TestFleetAggregatedPlayerStatus(t *testing.T) { msg := "PLAYER_CONNECT " + fmt.Sprintf("%d", i) logrus.WithField("msg", msg).WithField("gs", gs.ObjectMeta.Name).Info("Sending Player Connect") // retry on failure. Will stop flakiness of UDP packets being sent/received. - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Minute, true, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Minute, true, func(_ context.Context) (done bool, err error) { reply, err := framework.SendGameServerUDP(t, gs, msg) if err != nil { logrus.WithError(err).Warn("error with udp packet") @@ -1638,7 +1638,7 @@ func TestFleetAggregatedCounterStatus(t *testing.T) { // allocate two of them. framework.CreateAndApplyAllocation(t, flt) framework.CreateAndApplyAllocation(t, flt) - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 2 }) @@ -1721,7 +1721,7 @@ func TestFleetAggregatedListStatus(t *testing.T) { // allocate two of them. framework.CreateAndApplyAllocation(t, flt) framework.CreateAndApplyAllocation(t, flt) - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 2 }) @@ -1799,7 +1799,7 @@ func TestFleetAllocationOverflow(t *testing.T) { // allocate two of them. framework.CreateAndApplyAllocation(t, flt) framework.CreateAndApplyAllocation(t, flt) - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 2 }) @@ -1839,7 +1839,7 @@ func TestFleetAllocationOverflow(t *testing.T) { framework.ScaleFleet(t, log, flt, 0) // wait for scale down - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 2 && fleet.Status.ReadyReplicas == 0 }) diff --git a/test/e2e/fleetautoscaler_test.go b/test/e2e/fleetautoscaler_test.go index ae2efc17cb..5cdc2b1801 100644 --- a/test/e2e/fleetautoscaler_test.go +++ b/test/e2e/fleetautoscaler_test.go @@ -96,7 +96,7 @@ func TestAutoscalerBasicFunctions(t *testing.T) { // do an allocation and watch the fleet scale up gsa := framework.CreateAndApplyAllocation(t, flt) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 1 }) @@ -115,7 +115,7 @@ func TestAutoscalerBasicFunctions(t *testing.T) { require.True(t, fas.Status.AbleToScale, "Could not get AbleToScale status") // check that we are able to scale - framework.WaitForFleetAutoScalerCondition(t, fas, func(log *logrus.Entry, fas *autoscalingv1.FleetAutoscaler) bool { + framework.WaitForFleetAutoScalerCondition(t, fas, func(_ *logrus.Entry, fas *autoscalingv1.FleetAutoscaler) bool { return !fas.Status.ScalingLimited }) @@ -124,7 +124,7 @@ func TestAutoscalerBasicFunctions(t *testing.T) { require.NoError(t, err, "could not patch fleetautoscaler") // check that we are not able to scale - framework.WaitForFleetAutoScalerCondition(t, fas, func(log *logrus.Entry, fas *autoscalingv1.FleetAutoscaler) bool { + framework.WaitForFleetAutoScalerCondition(t, fas, func(_ *logrus.Entry, fas *autoscalingv1.FleetAutoscaler) bool { return fas.Status.ScalingLimited }) @@ -132,7 +132,7 @@ func TestAutoscalerBasicFunctions(t *testing.T) { gp := int64(1) err = stable.GameServers(framework.Namespace).Delete(ctx, gsa.Status.GameServerName, metav1.DeleteOptions{GracePeriodSeconds: &gp}) require.NoError(t, err) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 0 && fleet.Status.ReadyReplicas == 1 && fleet.Status.Replicas == 1 @@ -233,7 +233,7 @@ func TestFleetAutoScalerRollingUpdate(t *testing.T) { assert.True(t, fas.Status.AbleToScale, "Could not get AbleToScale status") // check that we are able to scale - framework.WaitForFleetAutoScalerCondition(t, fas, func(log *logrus.Entry, fas *autoscalingv1.FleetAutoscaler) bool { + framework.WaitForFleetAutoScalerCondition(t, fas, func(_ *logrus.Entry, fas *autoscalingv1.FleetAutoscaler) bool { return !fas.Status.ScalingLimited }) @@ -623,11 +623,11 @@ func TestFleetAutoscalerTLSWebhook(t *testing.T) { assert.FailNow(t, "Failed creating autoscaler, aborting TestTlsWebhook") } framework.CreateAndApplyAllocation(t, flt) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == 1 }) - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.Replicas > initialReplicasCount }) } @@ -1010,7 +1010,7 @@ func TestCounterAutoscalerAllocated(t *testing.T) { _, err := framework.AgonesClient.AllocationV1().GameServerAllocations(flt.ObjectMeta.Namespace).Create(ctx, gsa.DeepCopy(), metav1.CreateOptions{}) require.NoError(t, err) } - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { log.WithField("fleet", fmt.Sprintf("%+v", fleet.Status)).Info("Checking for game server allocations") return fleet.Status.AllocatedReplicas == testCase.wantAllocatedGs }) @@ -1036,7 +1036,7 @@ func TestCounterAutoscalerAllocated(t *testing.T) { assert.NoError(t, err) defer fleetautoscalers.Delete(ctx, fas.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint:errcheck - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == testCase.wantAllocatedGs && fleet.Status.ReadyReplicas == testCase.wantReadyGs }) }) @@ -1294,7 +1294,7 @@ func TestListAutoscalerAllocated(t *testing.T) { _, err := framework.AgonesClient.AllocationV1().GameServerAllocations(flt.ObjectMeta.Namespace).Create(ctx, gsa.DeepCopy(), metav1.CreateOptions{}) require.NoError(t, err) } - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { log.WithField("fleet", fmt.Sprintf("%+v", fleet.Status)).Info("Checking for game server allocations") return fleet.Status.AllocatedReplicas == testCase.wantAllocatedGs }) @@ -1320,7 +1320,7 @@ func TestListAutoscalerAllocated(t *testing.T) { assert.NoError(t, err) defer fleetautoscalers.Delete(ctx, fas.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint:errcheck - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == testCase.wantAllocatedGs && fleet.Status.ReadyReplicas == testCase.wantReadyGs }) @@ -1334,7 +1334,7 @@ func TestListAutoscalerAllocated(t *testing.T) { require.NoError(t, err) } - framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { log.WithField("fleet", fmt.Sprintf("%+v", fleet.Status)).Info("Checking for second game server allocations") return fleet.Status.AllocatedReplicas == (testCase.wantAllocatedGs+testCase.wantSecondAllocation) && fleet.Status.ReadyReplicas == testCase.wantSecondReady diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 11a05fd28e..cf2e8cc465 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -256,7 +256,7 @@ func (f *Framework) WaitForGameServerState(t *testing.T, gs *agonesv1.GameServer var checkGs *agonesv1.GameServer - err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, timeout, true, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, timeout, true, func(_ context.Context) (bool, error) { var err error checkGs, err = f.AgonesClient.AgonesV1().GameServers(gs.Namespace).Get(context.Background(), gs.Name, metav1.GetOptions{}) @@ -293,7 +293,7 @@ func (f *Framework) WaitForGameServerState(t *testing.T, gs *agonesv1.GameServer // Each Allocated GameServer gets deleted allocDuration after it was Allocated. // GameServers will continue to be Allocated until a message is passed to the done channel. func (f *Framework) CycleAllocations(ctx context.Context, t *testing.T, flt *agonesv1.Fleet, period time.Duration, allocDuration time.Duration) { - err := wait.PollUntilContextCancel(ctx, period, true, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextCancel(ctx, period, true, func(_ context.Context) (bool, error) { gsa := GetAllocation(flt) gsa, err := f.AgonesClient.AllocationV1().GameServerAllocations(flt.Namespace).Create(context.Background(), gsa, metav1.CreateOptions{}) if err != nil || gsa.Status.State != allocationv1.GameServerAllocationAllocated { @@ -350,7 +350,7 @@ func (f *Framework) AssertFleetCondition(t *testing.T, flt *agonesv1.Fleet, cond func (f *Framework) WaitForFleetCondition(t *testing.T, flt *agonesv1.Fleet, condition func(*logrus.Entry, *agonesv1.Fleet) bool) error { log := TestLogger(t).WithField("fleet", flt.Name) log.Info("waiting for fleet condition") - err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, f.WaitForState, true, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, f.WaitForState, true, func(_ context.Context) (bool, error) { fleet, err := f.AgonesClient.AgonesV1().Fleets(flt.ObjectMeta.Namespace).Get(context.Background(), flt.ObjectMeta.Name, metav1.GetOptions{}) if err != nil { return true, err @@ -386,7 +386,7 @@ func (f *Framework) WaitForFleetCondition(t *testing.T, flt *agonesv1.Fleet, con func (f *Framework) WaitForFleetAutoScalerCondition(t *testing.T, fas *autoscaling.FleetAutoscaler, condition func(log *logrus.Entry, fas *autoscaling.FleetAutoscaler) bool) { log := TestLogger(t).WithField("fleetautoscaler", fas.Name) log.Info("waiting for fleetautoscaler condition") - err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 2*time.Minute, true, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 2*time.Minute, true, func(_ context.Context) (bool, error) { fleetautoscaler, err := f.AgonesClient.AutoscalingV1().FleetAutoscalers(fas.ObjectMeta.Namespace).Get(context.Background(), fas.ObjectMeta.Name, metav1.GetOptions{}) if err != nil { return true, err @@ -449,7 +449,7 @@ func (f *Framework) WaitForFleetGameServersCondition(flt *agonesv1.Fleet, // specified by a callback and the size of GameServers to match fleet's Spec.Replicas. func (f *Framework) WaitForFleetGameServerListCondition(flt *agonesv1.Fleet, cond func(servers []agonesv1.GameServer) bool) error { - return wait.PollUntilContextTimeout(context.Background(), 2*time.Second, f.WaitForState, true, func(ctx context.Context) (done bool, err error) { + return wait.PollUntilContextTimeout(context.Background(), 2*time.Second, f.WaitForState, true, func(_ context.Context) (done bool, err error) { gsList, err := f.ListGameServersFromFleet(flt) if err != nil { return false, err @@ -566,7 +566,7 @@ func (f *Framework) SendUDP(t *testing.T, address, msg string) (string, error) { b := make([]byte, 1024) var n int // sometimes we get I/O timeout, so let's do a retry - err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, time.Minute, true, func(ctx context.Context) (bool, error) { + err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, time.Minute, true, func(_ context.Context) (bool, error) { conn, err := net.Dial("udp", address) if err != nil { log.WithError(err).Info("could not dial address") @@ -656,7 +656,10 @@ func SendTCP(address, msg string) (string, error) { }() // writes to the tcp connection - fmt.Fprintf(conn, msg+"\n") + _, err = fmt.Fprintln(conn, msg) + if err != nil { + return "", err + } response, err := bufio.NewReader(conn).ReadString('\n') if err != nil { diff --git a/test/e2e/gameserver_test.go b/test/e2e/gameserver_test.go index 52981b1ae2..42111ec6c9 100644 --- a/test/e2e/gameserver_test.go +++ b/test/e2e/gameserver_test.go @@ -100,7 +100,7 @@ func TestHostName(t *testing.T) { setup: func(gs *agonesv1.GameServer) { gs.ObjectMeta.GenerateName = "game-server-1.0-" }, - test: func(gs *agonesv1.GameServer, pod *corev1.Pod) { + test: func(_ *agonesv1.GameServer, pod *corev1.Pod) { expected := "game-server-1-0-" // since it's a generated name, we just check the beginning. assert.Equal(t, expected, pod.Spec.Hostname[:len(expected)]) @@ -383,7 +383,7 @@ func TestGameServerRestartBeforeReadyCrash(t *testing.T) { } logger.Info("crashing, and waiting to see restart") - err = messageAndWait(newGs, "CRASH", func(gs *agonesv1.GameServer, pod *corev1.Pod) bool { + err = messageAndWait(newGs, "CRASH", func(_ *agonesv1.GameServer, pod *corev1.Pod) bool { for _, c := range pod.Status.ContainerStatuses { if c.Name == newGs.Spec.Container && c.RestartCount > 0 { logger.Info("successfully crashed. Moving on!") @@ -407,7 +407,7 @@ func TestGameServerRestartBeforeReadyCrash(t *testing.T) { // for this to come back up -- or we could get a delayed CRASH, so we have to // wait for the process to restart again to fire the SDK.Ready() logger.Info("marking GameServer as ready") - err = messageAndWait(newGs, "READY", func(gs *agonesv1.GameServer, pod *corev1.Pod) bool { + err = messageAndWait(newGs, "READY", func(gs *agonesv1.GameServer, _ *corev1.Pod) bool { if gs.Status.State == agonesv1.GameServerStateReady { logger.Info("ready! Moving On!") return true @@ -419,7 +419,7 @@ func TestGameServerRestartBeforeReadyCrash(t *testing.T) { // now crash, should be unhealthy, since it's after being Ready logger.Info("crashing again, should be unhealthy") // retry on crash, as with the restarts, sometimes Go takes a moment to send this through. - err = messageAndWait(newGs, "CRASH", func(gs *agonesv1.GameServer, pod *corev1.Pod) bool { + err = messageAndWait(newGs, "CRASH", func(gs *agonesv1.GameServer, _ *corev1.Pod) bool { logger.WithField("gs", gs.ObjectMeta.Name).WithField("state", gs.Status.State). Info("checking final crash state") if gs.Status.State == agonesv1.GameServerStateUnhealthy { @@ -691,7 +691,7 @@ func TestGameServerWithPortsMappedToMultipleContainers(t *testing.T) { timeOut := 60 * time.Second expectedMsg1 := "Ping 1" - errPoll := wait.PollUntilContextTimeout(context.Background(), interval, timeOut, true, func(ctx context.Context) (done bool, err error) { + errPoll := wait.PollUntilContextTimeout(context.Background(), interval, timeOut, true, func(_ context.Context) (done bool, err error) { res, err := framework.SendGameServerUDPToPort(t, readyGs, firstPort, expectedMsg1) if err != nil { t.Logf("Could not message GameServer on %s: %v. Will try again...", firstPort, err) @@ -703,7 +703,7 @@ func TestGameServerWithPortsMappedToMultipleContainers(t *testing.T) { } expectedMsg2 := "Ping 2" - errPoll = wait.PollUntilContextTimeout(context.Background(), interval, timeOut, true, func(ctx context.Context) (done bool, err error) { + errPoll = wait.PollUntilContextTimeout(context.Background(), interval, timeOut, true, func(_ context.Context) (done bool, err error) { res, err := framework.SendGameServerUDPToPort(t, readyGs, secondPort, expectedMsg2) if err != nil { t.Logf("Could not message GameServer on %s: %v. Will try again...", secondPort, err) diff --git a/test/e2e/gameserverallocation_test.go b/test/e2e/gameserverallocation_test.go index b7265eccd5..6fa162d529 100644 --- a/test/e2e/gameserverallocation_test.go +++ b/test/e2e/gameserverallocation_test.go @@ -1150,7 +1150,7 @@ func TestCreateFullFleetAndCantGameServerAllocate(t *testing.T) { } } - framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool { + framework.AssertFleetCondition(t, flt, func(_ *logrus.Entry, fleet *agonesv1.Fleet) bool { return fleet.Status.AllocatedReplicas == replicasCount }) @@ -1438,7 +1438,7 @@ func TestGameServerAllocationDuringMultipleAllocationClients(t *testing.T) { // count the number of unique game servers allocated // there should not be any duplicate uniqueAllocatedGSs := 0 - allocatedGS.Range(func(k, v interface{}) bool { + allocatedGS.Range(func(_, _ interface{}) bool { uniqueAllocatedGSs++ return true })