Skip to content

Commit a6e73ad

Browse files
committed
🐛 Cluster should be provisoned when cpRef and endpoint is set
We're currently treating the infrastructureRef as almost a requirement, which in fact isn't and it's an optional reference. If the Cluster control plane reference is populated, the endpoint is valid, and the control plane is ready, set the phase to provisioned Signed-off-by: Vince Prignano <[email protected]>
1 parent b962bff commit a6e73ad

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

internal/controllers/cluster/cluster_controller_phases.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ func (r *Reconciler) reconcilePhase(_ context.Context, cluster *clusterv1.Cluste
4848
cluster.Status.SetTypedPhase(clusterv1.ClusterPhasePending)
4949
}
5050

51-
if cluster.Spec.InfrastructureRef != nil {
51+
if cluster.Spec.InfrastructureRef != nil || cluster.Spec.ControlPlaneRef != nil {
5252
cluster.Status.SetTypedPhase(clusterv1.ClusterPhaseProvisioning)
5353
}
5454

55-
if cluster.Status.InfrastructureReady && cluster.Spec.ControlPlaneEndpoint.IsValid() {
55+
if (cluster.Spec.InfrastructureRef == nil || cluster.Status.InfrastructureReady) &&
56+
(cluster.Spec.ControlPlaneRef == nil || cluster.Status.ControlPlaneReady) &&
57+
cluster.Spec.ControlPlaneEndpoint.IsValid() {
5658
cluster.Status.SetTypedPhase(clusterv1.ClusterPhaseProvisioned)
5759
}
5860

@@ -151,6 +153,8 @@ func (r *Reconciler) reconcileInfrastructure(ctx context.Context, cluster *clust
151153
log := ctrl.LoggerFrom(ctx)
152154

153155
if cluster.Spec.InfrastructureRef == nil {
156+
// If the infrastructure ref is not set, marking the infrastructure as ready (no-op).
157+
cluster.Status.InfrastructureReady = true
154158
return ctrl.Result{}, nil
155159
}
156160

internal/controllers/cluster/cluster_controller_phases_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func TestClusterReconcilePhases(t *testing.T) {
8686
name: "returns no error if infrastructure ref is nil",
8787
cluster: &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "test-cluster", Namespace: "test-namespace"}},
8888
expectErr: false,
89+
check: func(g *GomegaWithT, in *clusterv1.Cluster) {
90+
g.Expect(in.Status.InfrastructureReady).To(BeTrue())
91+
},
8992
},
9093
{
9194
name: "returns error if unable to reconcile infrastructure ref",
@@ -563,6 +566,26 @@ func TestClusterReconciler_reconcilePhase(t *testing.T) {
563566

564567
wantPhase: clusterv1.ClusterPhaseProvisioned,
565568
},
569+
{
570+
name: "no cluster infrastructure, control plane ready and ControlPlaneEndpoint is set",
571+
cluster: &clusterv1.Cluster{
572+
ObjectMeta: metav1.ObjectMeta{
573+
Name: "test-cluster",
574+
},
575+
Spec: clusterv1.ClusterSpec{
576+
ControlPlaneEndpoint: clusterv1.APIEndpoint{
577+
Host: "1.2.3.4",
578+
Port: 8443,
579+
},
580+
ControlPlaneRef: &corev1.ObjectReference{},
581+
},
582+
Status: clusterv1.ClusterStatus{
583+
ControlPlaneReady: true,
584+
},
585+
},
586+
587+
wantPhase: clusterv1.ClusterPhaseProvisioned,
588+
},
566589
{
567590
name: "cluster status has FailureReason",
568591
cluster: &clusterv1.Cluster{

0 commit comments

Comments
 (0)