Skip to content

Commit

Permalink
SQUASH: builder: fix late controller creation race
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
  • Loading branch information
sttts committed Mar 26, 2024
1 parent 0023ef4 commit d023d3e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ var _ = Describe("application", func() {

Context("with cluster provider", func() {
It("should support watching across clusters", func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

adapter := &fakeClusterProvider{
clusterNameList: []string{
"cluster1",
Expand All @@ -570,24 +573,13 @@ var _ = Describe("application", func() {
mgr, err := manager.New(cfg, manager.Options{}.WithExperimentalClusterProvider(adapter))
Expect(err).NotTo(HaveOccurred())

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
By("Starting the manager")
go func() {
defer GinkgoRecover()
Expect(mgr.Start(ctx)).NotTo(HaveOccurred())
}()

cluster1, err := mgr.GetCluster(ctx, "cluster1")
Expect(err).NotTo(HaveOccurred())

By("Creating a custom namespace")
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-multi-cluster-",
},
}
Expect(cluster1.GetClient().Create(ctx, ns)).To(Succeed())
Expect(mgr.GetClient().Create(ctx, ns)).To(Succeed())

ch1 := make(chan reconcile.Request, 1)
ch2 := make(chan reconcile.Request, 1)
Expand All @@ -613,6 +605,15 @@ var _ = Describe("application", func() {
})),
).To(Succeed())

By("Starting the manager")
go func() {
defer GinkgoRecover()
Expect(mgr.Start(ctx)).NotTo(HaveOccurred())
}()

cluster1, err := mgr.GetCluster(ctx, "cluster1")
Expect(err).NotTo(HaveOccurred())

By("Creating a deployment")
dep := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit d023d3e

Please sign in to comment.