Skip to content

Commit 306a852

Browse files
committed
fixup! feat: Add preflight checks framework
Rename Checks to Init
1 parent 7e687a2 commit 306a852

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/webhook/preflight/preflight.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ type CheckResult struct {
2525
type Check = func(ctx context.Context) CheckResult
2626

2727
type Checker interface {
28-
Checks(ctx context.Context, client ctrlclient.Client, cluster *clusterv1.Cluster) ([]Check, error)
28+
// Init decides which of its checks should run for the cluster. It then initializes the checks
29+
// with common dependencies, such as an infrastructure client. Finally, it returns the initialized checks,
30+
// ready to be run.
31+
//
32+
// Init should not store the context `ctx`, because each check will accept its own context.
33+
// Checks may use both the client and the cluster.
34+
Init(ctx context.Context, client ctrlclient.Client, cluster *clusterv1.Cluster) ([]Check, error)
2935
}
3036

3137
type WebhookHandler struct {
@@ -79,7 +85,7 @@ func (h *WebhookHandler) Handle(ctx context.Context, req admission.Request) admi
7985
for _, checker := range h.checkers {
8086
wg.Add(1)
8187
result := ChecksResult{}
82-
result.checks, result.err = checker.Checks(ctx, h.client, cluster)
88+
result.checks, result.err = checker.Init(ctx, h.client, cluster)
8389
checksResultCh <- result
8490
wg.Done()
8591
}

pkg/webhook/preflight/preflight_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type mockChecker struct {
2727
err error
2828
}
2929

30-
func (m *mockChecker) Checks(_ context.Context, _ ctrlclient.Client, _ *clusterv1.Cluster) ([]Check, error) {
30+
func (m *mockChecker) Init(_ context.Context, _ ctrlclient.Client, _ *clusterv1.Cluster) ([]Check, error) {
3131
return m.checks, m.err
3232
}
3333

0 commit comments

Comments
 (0)