Skip to content

Commit 73edfd8

Browse files
authored
fix: Do not run preflight checks if Cluster is paused (#1181)
**What problem does this PR solve?**: When clusterctl moves the Cluster, clusterctl first creates a paused Cluster object, then the referenced Secrets. That order might be a bug. However, to allow move to work, we want to skip preflight checks. **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 022b848 commit 73edfd8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

pkg/webhook/preflight/preflight.go

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

98+
if cluster.Spec.Paused {
99+
// If the cluster is paused, skip all checks.
100+
// This allows the cluster to be moved to another API server without running checks.
101+
return admission.Allowed("")
102+
}
103+
98104
skipEvaluator := skip.New(cluster)
99105

100106
if skipEvaluator.ForAll() {

pkg/webhook/preflight/preflight_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,3 +998,39 @@ func TestRun_ZeroChecksFromChecker(t *testing.T) {
998998

999999
assert.Equal(t, "check1", normalResults[0].Name, "expected result name to be 'check1'")
10001000
}
1001+
1002+
func TestHandle_ClusterPaused(t *testing.T) {
1003+
scheme := runtime.NewScheme()
1004+
err := clusterv1.AddToScheme(scheme)
1005+
require.NoError(t, err)
1006+
1007+
decoder := admission.NewDecoder(scheme)
1008+
1009+
// Create a paused cluster
1010+
cluster := topologyCluster()
1011+
cluster.Spec.Paused = true
1012+
1013+
handler := New(fake.NewClientBuilder().Build(), decoder)
1014+
1015+
ctx := context.Background()
1016+
1017+
// Create admission request
1018+
jsonCluster, err := json.Marshal(cluster)
1019+
require.NoError(t, err)
1020+
1021+
admissionReq := admission.Request{
1022+
AdmissionRequest: admissionv1.AdmissionRequest{
1023+
Operation: admissionv1.Create,
1024+
Object: runtime.RawExtension{
1025+
Raw: jsonCluster,
1026+
},
1027+
},
1028+
}
1029+
1030+
// Handle the request
1031+
got := handler.Handle(ctx, admissionReq)
1032+
1033+
// Check response - should be allowed without warnings for paused cluster
1034+
assert.True(t, got.Allowed, "expected response to be allowed for paused cluster")
1035+
assert.Empty(t, got.Warnings, "expected no warnings for paused cluster")
1036+
}

0 commit comments

Comments
 (0)