diff --git a/Makefile b/Makefile index a81cd7ed769..4587016219d 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ export GOPROXY export GO111MODULE=on # Kubebuilder. -export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.20.2 +export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.27 export KUBEBUILDER_CONTROLPLANE_START_TIMEOUT ?= 60s export KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT ?= 60s diff --git a/controllers/suite_test.go b/controllers/suite_test.go index df6d57f5cd4..8b7629a06e3 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -32,7 +32,8 @@ import ( // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. var ( - testEnv *env.TestEnvironment + testEnv *env.TestEnvironment + testEnvCancel func() ) func TestAPIs(t *testing.T) { @@ -64,10 +65,13 @@ var _ = BeforeSuite(func() { // +kubebuilder:scaffold:scheme + ctx, cancel := context.WithCancel(context.Background()) + testEnvCancel = cancel + By("starting the manager") go func() { defer GinkgoRecover() - Expect(testEnv.StartManager()).To(Succeed()) + Expect(testEnv.StartManager(ctx)).To(Succeed()) }() Eventually(func() bool { @@ -80,6 +84,7 @@ var _ = BeforeSuite(func() { }) var _ = AfterSuite(func() { + testEnvCancel() if testEnv != nil { By("tearing down the test environment") Expect(testEnv.Stop()).To(Succeed()) diff --git a/exp/controllers/suite_test.go b/exp/controllers/suite_test.go index 912e580fd2a..0752b1e2e09 100644 --- a/exp/controllers/suite_test.go +++ b/exp/controllers/suite_test.go @@ -35,7 +35,8 @@ import ( // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. var ( - testEnv *env.TestEnvironment + testEnv *env.TestEnvironment + testEnvCancel func() ) func TestAPIs(t *testing.T) { @@ -60,10 +61,13 @@ var _ = BeforeSuite(func() { // +kubebuilder:scaffold:scheme + mgrCtx, mgrCancel := context.WithCancel(context.Background()) + testEnvCancel = mgrCancel + By("starting the manager") go func() { defer GinkgoRecover() - Expect(testEnv.StartManager()).To(Succeed()) + Expect(testEnv.StartManager(mgrCtx)).To(Succeed()) }() Eventually(func() bool { @@ -76,6 +80,7 @@ var _ = BeforeSuite(func() { }) var _ = AfterSuite(func() { + testEnvCancel() if testEnv != nil { By("tearing down the test environment") Expect(testEnv.Stop()).To(Succeed()) diff --git a/internal/test/env/env.go b/internal/test/env/env.go index b70ab948bfb..5f74c56f072 100644 --- a/internal/test/env/env.go +++ b/internal/test/env/env.go @@ -119,8 +119,8 @@ func NewTestEnvironment() *TestEnvironment { } // StartManager starts the test environment manager and blocks until the context is canceled. -func (t *TestEnvironment) StartManager() error { - return t.Manager.Start(context.Background()) +func (t *TestEnvironment) StartManager(ctx context.Context) error { + return t.Manager.Start(ctx) } // Stop stops the test environment.