@@ -32,9 +32,10 @@ import (
3232 "k8s.io/apimachinery/pkg/types"
3333 "k8s.io/apimachinery/pkg/util/yaml"
3434 "k8s.io/client-go/kubernetes/scheme"
35+ "k8s.io/utils/ptr"
3536 ctrl "sigs.k8s.io/controller-runtime"
3637 "sigs.k8s.io/controller-runtime/pkg/client"
37- "sigs.k8s.io/controller-runtime/pkg/log/zap "
38+ "sigs.k8s.io/controller-runtime/pkg/config "
3839 metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3940
4041 ocpconfigv1 "github.com/openshift/api/config/v1"
@@ -44,8 +45,6 @@ import (
4445 "github.com/backube/volsync/internal/controller/utils"
4546)
4647
47- var logger = zap .New (zap .UseDevMode (true ), zap .WriteTo (GinkgoWriter ))
48-
4948var _ = Describe ("A cluster w/o StorageContextConstraints" , func () {
5049 BeforeEach (func () {
5150 // Make sure we're not caching properties
@@ -361,11 +360,21 @@ var _ = Describe("A cluster w/ StorageContextConstraints", func() {
361360 cancelFuncCalled := false
362361
363362 var testManagerCancel context.CancelFunc
363+ var testManagerDone chan struct {}
364364
365365 BeforeEach (func () {
366+ cancelFuncCalled = false
367+
366368 testManager , err := ctrl .NewManager (cfg , ctrl.Options {
367369 Scheme : scheme .Scheme ,
368370 Metrics : metricsserver.Options {BindAddress : "0" },
371+ // Set global controller options - allow dup controller names as these don't get unregistered
372+ // when tearing down the manager - so our TLSSecurityProfileWatcher will fail the dup name
373+ // validation (we don't have the option of setting the name ourself) when this runs multiple
374+ // times for separate tests
375+ Controller : config.Controller {
376+ SkipNameValidation : ptr .To (true ),
377+ },
369378 })
370379 Expect (err ).ToNot (HaveOccurred ())
371380
@@ -384,15 +393,20 @@ var _ = Describe("A cluster w/ StorageContextConstraints", func() {
384393
385394 var testManagerCtx context.Context
386395 testManagerCtx , testManagerCancel = context .WithCancel (ctx )
387- // Start the manager
396+ testManagerDone = make (chan struct {})
397+ // Start the manager; wait for Start to return in AfterEach so the next test
398+ // does not register another controller (with same name) while this mgr is running
388399 go func () {
389400 defer GinkgoRecover ()
390- err = testManager .Start (testManagerCtx )
401+ defer close (testManagerDone )
402+ err := testManager .Start (testManagerCtx )
391403 Expect (err ).NotTo (HaveOccurred ())
404+ logger .Info ("test manager stopped" )
392405 }()
393406 })
394407 AfterEach (func () {
395408 testManagerCancel ()
409+ Eventually (testManagerDone , maxWait , interval ).Should (BeClosed ())
396410 })
397411
398412 It ("Should not call cancel function if no TLS profile change" , func () {
0 commit comments