Skip to content

Commit

Permalink
Fix the local k8s instance shutdown
Browse files Browse the repository at this point in the history
issue: kubernetes-sigs/controller-runtime#1571
Signed-off-by: Sebastian Sch <sebassch@gmail.com>
  • Loading branch information
SchSeba authored and Sebastian Scheinkman committed Jul 28, 2022
1 parent 856384c commit 483aa04
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ import (
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.

var k8sClient client.Client
var testEnv *envtest.Environment
var (
k8sClient client.Client
testEnv *envtest.Environment

ctx context.Context
cancel context.CancelFunc
)

// Define utility constants for object names and testing timeouts/durations and intervals.
const (
Expand Down Expand Up @@ -130,9 +135,11 @@ var _ = BeforeSuite(func(done Done) {
os.Setenv("RELEASE_VERSION", "4.7.0")
os.Setenv("OPERATOR_NAME", "sriov-network-operator")

ctx, cancel = context.WithCancel(ctrl.SetupSignalHandler())

go func() {
defer GinkgoRecover()
err = k8sManager.Start(ctrl.SetupSignalHandler())
err = k8sManager.Start(ctx)
Expect(err).ToNot(HaveOccurred())
}()

Expand Down Expand Up @@ -168,8 +175,10 @@ var _ = BeforeSuite(func(done Done) {

var _ = AfterSuite(func() {
By("tearing down the test environment")
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
cancel()
Eventually(func() error {
return testEnv.Stop()
}, timeout, time.Second).ShouldNot(HaveOccurred())
})

func TestAPIs(t *testing.T) {
Expand Down

0 comments on commit 483aa04

Please sign in to comment.