From 2f1f1189fa1607e935326a840b53ca1182f11821 Mon Sep 17 00:00:00 2001 From: John Sanda Date: Mon, 18 Oct 2021 12:56:38 -0400 Subject: [PATCH] fix api server timeouts during shutdown Need to cancel the context. It is discussed in https://github.com/kubernetes-sigs/controller-runtime/issues/1571#issuecomment-945535598. --- apis/config/v1beta1/zz_generated.deepcopy.go | 1 - apis/k8ssandra/v1alpha1/zz_generated.deepcopy.go | 1 - apis/replication/v1alpha1/zz_generated.deepcopy.go | 1 - apis/stargate/v1alpha1/zz_generated.deepcopy.go | 1 - controllers/k8ssandra/k8ssandracluster_controller_test.go | 2 ++ controllers/replication/secret_controller_test.go | 4 ++-- controllers/stargate/stargate_controller_test.go | 2 ++ 7 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apis/config/v1beta1/zz_generated.deepcopy.go b/apis/config/v1beta1/zz_generated.deepcopy.go index f0bc5e668..40a35a450 100644 --- a/apis/config/v1beta1/zz_generated.deepcopy.go +++ b/apis/config/v1beta1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/apis/k8ssandra/v1alpha1/zz_generated.deepcopy.go b/apis/k8ssandra/v1alpha1/zz_generated.deepcopy.go index 8d837c2ca..37ea6453a 100644 --- a/apis/k8ssandra/v1alpha1/zz_generated.deepcopy.go +++ b/apis/k8ssandra/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/apis/replication/v1alpha1/zz_generated.deepcopy.go b/apis/replication/v1alpha1/zz_generated.deepcopy.go index 710fceada..a397bc196 100644 --- a/apis/replication/v1alpha1/zz_generated.deepcopy.go +++ b/apis/replication/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/apis/stargate/v1alpha1/zz_generated.deepcopy.go b/apis/stargate/v1alpha1/zz_generated.deepcopy.go index f2394704d..b3fcacac0 100644 --- a/apis/stargate/v1alpha1/zz_generated.deepcopy.go +++ b/apis/stargate/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/controllers/k8ssandra/k8ssandracluster_controller_test.go b/controllers/k8ssandra/k8ssandracluster_controller_test.go index 666e7fa8b..6a5a5fb0a 100644 --- a/controllers/k8ssandra/k8ssandracluster_controller_test.go +++ b/controllers/k8ssandra/k8ssandracluster_controller_test.go @@ -51,6 +51,7 @@ var ( func TestK8ssandraCluster(t *testing.T) { ctx := testutils.TestSetup(t) + ctx, cancel := context.WithCancel(ctx) testEnv = &testutils.MultiClusterTestEnv{} seedsResolver.callback = func(dc *cassdcapi.CassandraDatacenter) ([]string, error) { return []string{}, nil @@ -82,6 +83,7 @@ func TestK8ssandraCluster(t *testing.T) { } defer testEnv.Stop(t) + defer cancel() t.Run("CreateSingleDcCluster", testEnv.ControllerTest(ctx, createSingleDcCluster)) t.Run("CreateMultiDcCluster", testEnv.ControllerTest(ctx, createMultiDcCluster)) diff --git a/controllers/replication/secret_controller_test.go b/controllers/replication/secret_controller_test.go index 706f320e0..4e6a935fa 100644 --- a/controllers/replication/secret_controller_test.go +++ b/controllers/replication/secret_controller_test.go @@ -38,7 +38,7 @@ var ( func TestSecretController(t *testing.T) { ctx := testutils.TestSetup(t) - // ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(ctx) testEnv = &testutils.MultiClusterTestEnv{} err := testEnv.Start(ctx, t, func(mgr manager.Manager, clientCache *clientcache.ClientCache, clusters []cluster.Cluster) error { return (&SecretSyncController{ @@ -51,7 +51,7 @@ func TestSecretController(t *testing.T) { } defer testEnv.Stop(t) - // defer cancel() + defer cancel() // Secret controller tests t.Run("SingleClusterDoNothingToSecretsTest", testEnv.ControllerTest(ctx, wrongClusterIgnoreCopy)) diff --git a/controllers/stargate/stargate_controller_test.go b/controllers/stargate/stargate_controller_test.go index 24cfd45b7..5374fadd5 100644 --- a/controllers/stargate/stargate_controller_test.go +++ b/controllers/stargate/stargate_controller_test.go @@ -29,6 +29,7 @@ const ( func TestStargate(t *testing.T) { ctx := testutils.TestSetup(t) + ctx, cancel := context.WithCancel(ctx) testEnv := &testutils.TestEnv{} err := testEnv.Start(ctx, t, func(mgr manager.Manager) error { err := (&StargateReconciler{ @@ -43,6 +44,7 @@ func TestStargate(t *testing.T) { } defer testEnv.Stop(t) + defer cancel() t.Run("CreateStargateSingleRack", func(t *testing.T) { testCreateStargateSingleRack(t, testEnv.TestClient)