Skip to content

Commit 9db3e90

Browse files
authored
fix: misc fixes to the preflight framework (#1188)
**What problem does this PR solve?**: - Skip preflight on Cluster update. This is defensive programming. The webhook is already configured to only run on create. When we support for update, we will remove this, and reconfigure the webhook. - Use preflight check name as cause type. Previously, the "FailedPreflight" prefix was present, but it makes it more difficult to identify the name of the check that failed, and the prefix is not necessary, because the top-level Message explains that preflight checks failed. - Debug log message when preflight check runs. **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent 2007a42 commit 9db3e90

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

pkg/webhook/preflight/preflight.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ func (h *WebhookHandler) Handle(ctx context.Context, req admission.Request) admi
8484
return admission.Allowed("")
8585
}
8686

87+
if req.Operation == admissionv1.Update {
88+
return admission.Allowed("")
89+
}
90+
8791
cluster := &clusterv1.Cluster{}
8892
err := h.decoder.Decode(req, cluster)
8993
if err != nil {
@@ -131,11 +135,13 @@ func (h *WebhookHandler) Handle(ctx context.Context, req admission.Request) admi
131135
resp.Allowed = false
132136
}
133137
for _, cause := range result.Causes {
134-
resp.Result.Details.Causes = append(resp.Result.Details.Causes, metav1.StatusCause{
135-
Type: metav1.CauseType(fmt.Sprintf("FailedPreflight%s", result.Name)),
136-
Message: cause.Message,
137-
Field: cause.Field,
138-
})
138+
resp.Result.Details.Causes = append(resp.Result.Details.Causes,
139+
metav1.StatusCause{
140+
Type: metav1.CauseType(result.Name),
141+
Message: cause.Message,
142+
Field: cause.Field,
143+
},
144+
)
139145
}
140146
resp.Warnings = append(resp.Warnings, result.Warnings...)
141147
}
@@ -185,6 +191,12 @@ func run(ctx context.Context,
185191

186192
checksWG := sync.WaitGroup{}
187193
for j, check := range checks {
194+
ctrl.LoggerFrom(ctx).V(5).Info(
195+
"running preflight check",
196+
"checkName", check.Name(),
197+
"clusterName", cluster.Name,
198+
"clusterNamespace", cluster.Namespace,
199+
)
188200
if skipEvaluator.For(check.Name()) {
189201
resultsOrderedByCheck[j] = namedResult{
190202
Name: check.Name(),

pkg/webhook/preflight/preflight_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func TestHandle(t *testing.T) {
248248
Details: &metav1.StatusDetails{
249249
Causes: []metav1.StatusCause{
250250
{
251-
Type: "FailedPreflightTest1",
251+
Type: "Test1",
252252
Field: "spec.test",
253253
Message: "test failed",
254254
},
@@ -342,11 +342,11 @@ func TestHandle(t *testing.T) {
342342
Details: &metav1.StatusDetails{
343343
Causes: []metav1.StatusCause{
344344
{
345-
Type: "FailedPreflightTest2",
345+
Type: "Test2",
346346
Message: "check failed",
347347
},
348348
{
349-
Type: "FailedPreflightTest1",
349+
Type: "Test1",
350350
Message: "internal error",
351351
},
352352
},
@@ -475,11 +475,11 @@ func TestHandleCancelledContext(t *testing.T) {
475475
Details: &metav1.StatusDetails{
476476
Causes: []metav1.StatusCause{
477477
{
478-
Type: "FailedPreflightTest1",
478+
Type: "Test1",
479479
Message: "context cancelled",
480480
},
481481
{
482-
Type: "FailedPreflightTest2",
482+
Type: "Test2",
483483
Message: "context cancelled",
484484
},
485485
},

0 commit comments

Comments
 (0)