Skip to content

Commit 0ea83fc

Browse files
added blocking channel for tests to backfill
Signed-off-by: James Milligan <[email protected]>
1 parent a061556 commit 0ea83fc

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ func main() {
201201
}(errChan)
202202

203203
setupLog.Info("restoring flagd-kubernetes-sync cluster role binding subjects from current cluster state")
204-
podMutator.BackfillPermissions(ctx)
204+
// backfill can be handled asynchronously, so we do not need to block via the channel
205+
go podMutator.BackfillPermissions(ctx, make(chan struct{}, 1))
205206

206207
if err := <-errChan; err != nil {
207208
setupLog.Error(err, "problem running manager")

webhooks/pod_webhook.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ type PodMutator struct {
5353
}
5454

5555
// BackfillPermissions recovers the state of the flagd-kubernetes-sync role binding in the event of upgrade
56-
func (m *PodMutator) BackfillPermissions(ctx context.Context) {
56+
func (m *PodMutator) BackfillPermissions(ctx context.Context, backfillComplete chan struct{}) {
57+
defer func() {
58+
backfillComplete <- struct{}{}
59+
}()
60+
5761
for i := 0; i < 5; i++ {
5862
// fetch all pods with the "openfeature.dev/enabled" annotation set to "true"
5963
podList := &corev1.PodList{}

webhooks/run_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package webhooks
22

33
import (
44
"context"
5-
"log"
65

76
corev1alpha1 "github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
87
corev1alpha2 "github.com/open-feature/open-feature-operator/apis/core/v1alpha2"
@@ -16,7 +15,7 @@ import (
1615
// +kubebuilder:scaffold:imports
1716
)
1817

19-
func run(ctx context.Context, cfg *rest.Config, scheme *runtime.Scheme, opts *envtest.WebhookInstallOptions) error {
18+
func run(ctx context.Context, cfg *rest.Config, scheme *runtime.Scheme, opts *envtest.WebhookInstallOptions, backfillComplete chan struct{}) error {
2019
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
2120

2221
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
@@ -61,11 +60,14 @@ func run(ctx context.Context, cfg *rest.Config, scheme *runtime.Scheme, opts *en
6160
Log: ctrl.Log.WithName("validating-featureflagconfiguration-webhook"),
6261
},
6362
})
64-
go func() {
65-
if err := mgr.Start(ctx); err != nil {
66-
log.Fatal("unable to setup test suite", err)
67-
}
68-
}()
69-
podMutator.BackfillPermissions(ctx)
63+
64+
go func(ctx context.Context, backfillComplete chan struct{}) {
65+
podMutator.BackfillPermissions(ctx, backfillComplete)
66+
}(ctx, backfillComplete)
67+
68+
if err := mgr.Start(ctx); err != nil {
69+
return err
70+
}
71+
7072
return nil
7173
}

webhooks/suite_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,12 @@ var _ = BeforeSuite(func() {
158158
setupPreviouslyExistingPods()
159159

160160
By("running webhook server")
161-
if err := run(testCtx, cfg, scheme, &testEnv.WebhookInstallOptions); err != nil {
162-
logf.Log.Error(err, "run webhook server")
163-
}
161+
backfillComplete := make(chan struct{}, 1)
162+
go func() {
163+
if err := run(testCtx, cfg, scheme, &testEnv.WebhookInstallOptions, backfillComplete); err != nil {
164+
logf.Log.Error(err, "run webhook server")
165+
}
166+
}()
164167
d := &net.Dialer{Timeout: time.Second}
165168
Eventually(func() error {
166169
serverURL := fmt.Sprintf("%s:%d", testEnv.WebhookInstallOptions.LocalServingHost, testEnv.WebhookInstallOptions.LocalServingPort)
@@ -175,7 +178,7 @@ var _ = BeforeSuite(func() {
175178
}
176179
return nil
177180
}).Should(Succeed())
178-
181+
<-backfillComplete
179182
By("setting up resources")
180183
setupMutatePodResources()
181184
setupValidateFeatureFlagConfigurationResources()

0 commit comments

Comments
 (0)