From 4cf6931047dea9583a0db012d916ec4c5fb935d5 Mon Sep 17 00:00:00 2001 From: Kalaiselvi Murugesan Date: Wed, 25 Oct 2023 19:17:39 +0000 Subject: [PATCH 1/3] Replace ErrWaitTimeout with Interrupted() --- pkg/gameserverallocations/allocator.go | 3 +-- test/e2e/framework/framework.go | 3 +-- vendor/k8s.io/client-go/util/retry/util.go | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/gameserverallocations/allocator.go b/pkg/gameserverallocations/allocator.go index 78d831a9e4..fd790df076 100644 --- a/pkg/gameserverallocations/allocator.go +++ b/pkg/gameserverallocations/allocator.go @@ -692,8 +692,7 @@ func Retry(backoff wait.Backoff, fn func() error) error { return false, nil } }) - // nolint:staticcheck - if err == wait.ErrWaitTimeout { + if wait.Interrupted(err) { err = lastConflictErr } return err diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index ef06796298..538024d9b4 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -311,8 +311,7 @@ func (f *Framework) CycleAllocations(ctx context.Context, t *testing.T, flt *ago return false, nil }, ctx.Done()) // Ignore wait timeout error, will always be returned when the context is cancelled at the end of the test. - // nolint:staticcheck - if err != wait.ErrWaitTimeout { + if wait.Interrupted(err) { require.NoError(t, err) } } diff --git a/vendor/k8s.io/client-go/util/retry/util.go b/vendor/k8s.io/client-go/util/retry/util.go index 5cbe7cd466..57d3cd49c1 100644 --- a/vendor/k8s.io/client-go/util/retry/util.go +++ b/vendor/k8s.io/client-go/util/retry/util.go @@ -59,8 +59,7 @@ func OnError(backoff wait.Backoff, retriable func(error) bool, fn func() error) return false, err } }) - // nolint:staticcheck - if err == wait.ErrWaitTimeout { + if wait.Interrupted(err) { err = lastErr } return err From 89306a94aff96815676cb9b7f02d3e6abd5eb195 Mon Sep 17 00:00:00 2001 From: Kalaiselvi Murugesan Date: Wed, 25 Oct 2023 21:02:13 +0000 Subject: [PATCH 2/3] Replaced with PollUntilContextCancel --- pkg/sdkserver/sdkserver.go | 3 +-- test/e2e/framework/framework.go | 12 +++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pkg/sdkserver/sdkserver.go b/pkg/sdkserver/sdkserver.go index 63ef1d32f9..637ef2d61d 100644 --- a/pkg/sdkserver/sdkserver.go +++ b/pkg/sdkserver/sdkserver.go @@ -295,8 +295,7 @@ func (s *SDKServer) WaitForConnection(ctx context.Context) error { } try := 0 - // nolint:staticcheck - return wait.PollImmediateInfiniteWithContext(ctx, 4*time.Second, func(ctx context.Context) (bool, error) { + return wait.PollUntilContextCancel(ctx, 4*time.Second, true, func(ctx context.Context) (bool, error) { ctx, cancel := context.WithTimeout(ctx, 3*time.Second) defer cancel() diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 538024d9b4..6e3e47a88a 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -292,10 +292,9 @@ 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) { - // nolint:staticcheck - err := wait.PollImmediateUntil(period, func() (bool, error) { + err := wait.PollUntilContextCancel(ctx, period, true, func(ctx context.Context) (bool, error) { gsa := GetAllocation(flt) - gsa, err := f.AgonesClient.AllocationV1().GameServerAllocations(flt.Namespace).Create(context.Background(), gsa, metav1.CreateOptions{}) + gsa, err := f.AgonesClient.AllocationV1().GameServerAllocations(flt.Namespace).Create(ctx, gsa, metav1.CreateOptions{}) if err != nil || gsa.Status.State != allocationv1.GameServerAllocationAllocated { // Ignore error. Could be that the buffer was empty, will try again next cycle. return false, nil @@ -304,14 +303,13 @@ func (f *Framework) CycleAllocations(ctx context.Context, t *testing.T, flt *ago // Deallocate after allocDuration. go func(gsa *allocationv1.GameServerAllocation) { time.Sleep(allocDuration) - err := f.AgonesClient.AgonesV1().GameServers(gsa.Namespace).Delete(context.Background(), gsa.Status.GameServerName, metav1.DeleteOptions{}) + err := f.AgonesClient.AgonesV1().GameServers(gsa.Namespace).Delete(ctx, gsa.Status.GameServerName, metav1.DeleteOptions{}) require.NoError(t, err) }(gsa) return false, nil - }, ctx.Done()) - // Ignore wait timeout error, will always be returned when the context is cancelled at the end of the test. - if wait.Interrupted(err) { + }) + if err != nil { require.NoError(t, err) } } From 6cdfa91a7cfbe70e4ae5ce39348ff54e1e9e253c Mon Sep 17 00:00:00 2001 From: Kalaiselvi Murugesan Date: Thu, 26 Oct 2023 01:19:18 +0000 Subject: [PATCH 3/3] ErrorWaitTimeout replaced with Interrupted --- test/e2e/framework/framework.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 6e3e47a88a..c53f84b93d 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -294,7 +294,7 @@ func (f *Framework) WaitForGameServerState(t *testing.T, gs *agonesv1.GameServer 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) { gsa := GetAllocation(flt) - gsa, err := f.AgonesClient.AllocationV1().GameServerAllocations(flt.Namespace).Create(ctx, gsa, metav1.CreateOptions{}) + gsa, err := f.AgonesClient.AllocationV1().GameServerAllocations(flt.Namespace).Create(context.Background(), gsa, metav1.CreateOptions{}) if err != nil || gsa.Status.State != allocationv1.GameServerAllocationAllocated { // Ignore error. Could be that the buffer was empty, will try again next cycle. return false, nil @@ -303,13 +303,14 @@ func (f *Framework) CycleAllocations(ctx context.Context, t *testing.T, flt *ago // Deallocate after allocDuration. go func(gsa *allocationv1.GameServerAllocation) { time.Sleep(allocDuration) - err := f.AgonesClient.AgonesV1().GameServers(gsa.Namespace).Delete(ctx, gsa.Status.GameServerName, metav1.DeleteOptions{}) + err := f.AgonesClient.AgonesV1().GameServers(gsa.Namespace).Delete(context.Background(), gsa.Status.GameServerName, metav1.DeleteOptions{}) require.NoError(t, err) }(gsa) return false, nil }) - if err != nil { + // Ignore wait timeout error, will always be returned when the context is cancelled at the end of the test. + if !wait.Interrupted(err) { require.NoError(t, err) } }