Skip to content

Commit 0ccf58e

Browse files
vinceprik8s-infra-cherrypick-robot
authored and
k8s-infra-cherrypick-robot
committed
bug: 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 a4293c8 commit 0ccf58e

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",
@@ -566,6 +569,26 @@ func TestClusterReconciler_reconcilePhase(t *testing.T) {
566569

567570
wantPhase: clusterv1.ClusterPhaseProvisioned,
568571
},
572+
{
573+
name: "no cluster infrastructure, control plane ready and ControlPlaneEndpoint is set",
574+
cluster: &clusterv1.Cluster{
575+
ObjectMeta: metav1.ObjectMeta{
576+
Name: "test-cluster",
577+
},
578+
Spec: clusterv1.ClusterSpec{
579+
ControlPlaneEndpoint: clusterv1.APIEndpoint{
580+
Host: "1.2.3.4",
581+
Port: 8443,
582+
},
583+
ControlPlaneRef: &corev1.ObjectReference{},
584+
},
585+
Status: clusterv1.ClusterStatus{
586+
ControlPlaneReady: true,
587+
},
588+
},
589+
590+
wantPhase: clusterv1.ClusterPhaseProvisioned,
591+
},
569592
{
570593
name: "cluster status has FailureReason",
571594
cluster: &clusterv1.Cluster{

0 commit comments

Comments
 (0)