Skip to content

Commit 0e36260

Browse files
committed
fixup! feat: Preflight check opt-out
Handler skips individual checks, and returns warning when checks are skipped
1 parent c9da77e commit 0e36260

File tree

2 files changed

+119
-126
lines changed

2 files changed

+119
-126
lines changed

pkg/webhook/preflight/preflight.go

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ func (h *WebhookHandler) Handle(ctx context.Context, req admission.Request) admi
9595
return admission.Allowed("")
9696
}
9797

98-
if optout.New(cluster).ForAll() {
98+
optoutEvaluator := optout.New(cluster)
99+
100+
if optoutEvaluator.ForAll() {
99101
// If the cluster has opted out of all checks, return allowed.
100-
return admission.Allowed("Cluster has opted out of all preflight checks")
102+
return admission.Allowed("").WithWarnings(
103+
"Cluster has opted out of all preflight checks",
104+
)
101105
}
102106

103-
resultsOrderedByCheckerAndCheck := run(ctx, h.client, cluster, h.checkers)
107+
resultsOrderedByCheckerAndCheck := run(ctx, h.client, cluster, optoutEvaluator, h.checkers)
104108

105109
// Summarize the results.
106110
resp := admission.Response{
@@ -152,23 +156,50 @@ func (h *WebhookHandler) Handle(ctx context.Context, req admission.Request) admi
152156
func run(ctx context.Context,
153157
client ctrlclient.Client,
154158
cluster *clusterv1.Cluster,
159+
optoutEvaluator *optout.Evaluator,
155160
checkers []Checker,
156161
) [][]namedResult {
157162
resultsOrderedByCheckerAndCheck := make([][]namedResult, len(checkers))
158163

159164
checkersWG := sync.WaitGroup{}
160165
for i, checker := range checkers {
161166
checkersWG.Add(1)
162-
go func(ctx context.Context, client ctrlclient.Client, cluster *clusterv1.Cluster, checker Checker, i int) {
167+
go func(
168+
ctx context.Context,
169+
client ctrlclient.Client,
170+
cluster *clusterv1.Cluster,
171+
optoutEvaluator *optout.Evaluator,
172+
checker Checker,
173+
i int,
174+
) {
163175
defer checkersWG.Done()
164176

165177
checks := checker.Init(ctx, client, cluster)
166178
resultsOrderedByCheck := make([]namedResult, len(checks))
167179

168180
checksWG := sync.WaitGroup{}
169181
for j, check := range checks {
182+
if optoutEvaluator.For(check.Name()) {
183+
// If the cluster has opted out of this check, skip it.
184+
resultsOrderedByCheck[j] = namedResult{
185+
Name: check.Name(),
186+
CheckResult: CheckResult{
187+
Allowed: true,
188+
Error: false,
189+
Causes: nil,
190+
Warnings: []string{
191+
fmt.Sprintf("Cluster has opted out of preflight check %q", check.Name()),
192+
},
193+
},
194+
}
195+
continue
196+
}
170197
checksWG.Add(1)
171-
go func(ctx context.Context, check Check, j int) {
198+
go func(
199+
ctx context.Context,
200+
check Check,
201+
j int,
202+
) {
172203
defer checksWG.Done()
173204
defer func() {
174205
if r := recover(); r != nil {
@@ -207,6 +238,7 @@ func run(ctx context.Context,
207238
ctx,
208239
client,
209240
cluster,
241+
optoutEvaluator,
210242
checker,
211243
i,
212244
)

0 commit comments

Comments
 (0)