Skip to content

Commit 38e89de

Browse files
authored
Merge pull request kubernetes-sigs#10909 from vincepri/fix-condition-infraready2
🐛 When infrastructureRef is nil, set InfrastructureReadyCondition to true
2 parents 95e8d4b + 4a0900c commit 38e89de

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

internal/controllers/cluster/cluster_controller_phases.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (r *Reconciler) reconcileInfrastructure(ctx context.Context, cluster *clust
153153
if cluster.Spec.InfrastructureRef == nil {
154154
// If the infrastructure ref is not set, marking the infrastructure as ready (no-op).
155155
cluster.Status.InfrastructureReady = true
156+
conditions.MarkTrue(cluster, clusterv1.InfrastructureReadyCondition)
156157
return ctrl.Result{}, nil
157158
}
158159

internal/controllers/cluster/cluster_controller_phases_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func TestClusterReconcilePhases(t *testing.T) {
8888
expectErr: false,
8989
check: func(g *GomegaWithT, in *clusterv1.Cluster) {
9090
g.Expect(in.Status.InfrastructureReady).To(BeTrue())
91+
g.Expect(conditions.IsTrue(in, clusterv1.InfrastructureReadyCondition)).To(BeTrue())
9192
},
9293
},
9394
{

internal/controllers/cluster/cluster_controller_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,50 @@ func TestClusterReconciler(t *testing.T) {
172172
}, timeout).Should(BeTrue())
173173
})
174174

175+
t.Run("Should successfully patch a cluster object if the spec diff is empty but the status conditions diff is not", func(t *testing.T) {
176+
g := NewWithT(t)
177+
178+
// Setup
179+
cluster := &clusterv1.Cluster{
180+
ObjectMeta: metav1.ObjectMeta{
181+
GenerateName: "test3-",
182+
Namespace: ns.Name,
183+
},
184+
}
185+
g.Expect(env.Create(ctx, cluster)).To(Succeed())
186+
key := client.ObjectKey{Name: cluster.Name, Namespace: cluster.Namespace}
187+
defer func() {
188+
err := env.Delete(ctx, cluster)
189+
g.Expect(err).ToNot(HaveOccurred())
190+
}()
191+
192+
// Wait for reconciliation to happen.
193+
g.Eventually(func() bool {
194+
if err := env.Get(ctx, key, cluster); err != nil {
195+
return false
196+
}
197+
return len(cluster.Finalizers) > 0
198+
}, timeout).Should(BeTrue())
199+
200+
// Patch
201+
g.Eventually(func() bool {
202+
ph, err := patch.NewHelper(cluster, env)
203+
g.Expect(err).ToNot(HaveOccurred())
204+
conditions.MarkTrue(cluster, clusterv1.InfrastructureReadyCondition)
205+
g.Expect(ph.Patch(ctx, cluster, patch.WithStatusObservedGeneration{})).To(Succeed())
206+
return true
207+
}, timeout).Should(BeTrue())
208+
209+
// Assertions
210+
g.Eventually(func() bool {
211+
instance := &clusterv1.Cluster{}
212+
if err := env.Get(ctx, key, instance); err != nil {
213+
return false
214+
}
215+
return conditions.IsTrue(cluster, clusterv1.InfrastructureReadyCondition)
216+
}, timeout).Should(BeTrue())
217+
})
218+
175219
t.Run("Should successfully patch a cluster object if both the spec diff and status diff are non empty", func(t *testing.T) {
176220
g := NewWithT(t)
177221

0 commit comments

Comments
 (0)