Skip to content

Commit

Permalink
Merge pull request #10921 from k8s-infra-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-10909-to-release-1.7

[release-1.7] 🐛 When infrastructureRef is nil, set InfrastructureReadyCondition to true
  • Loading branch information
k8s-ci-robot authored Jul 22, 2024
2 parents 6dd78a5 + a8f1d8e commit bd3fd3d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/controllers/cluster/cluster_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (r *Reconciler) reconcileInfrastructure(ctx context.Context, cluster *clust
if cluster.Spec.InfrastructureRef == nil {
// If the infrastructure ref is not set, marking the infrastructure as ready (no-op).
cluster.Status.InfrastructureReady = true
conditions.MarkTrue(cluster, clusterv1.InfrastructureReadyCondition)
return ctrl.Result{}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestClusterReconcilePhases(t *testing.T) {
expectErr: false,
check: func(g *GomegaWithT, in *clusterv1.Cluster) {
g.Expect(in.Status.InfrastructureReady).To(BeTrue())
g.Expect(conditions.IsTrue(in, clusterv1.InfrastructureReadyCondition)).To(BeTrue())
},
},
{
Expand Down
44 changes: 44 additions & 0 deletions internal/controllers/cluster/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,50 @@ func TestClusterReconciler(t *testing.T) {
}, timeout).Should(BeTrue())
})

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) {
g := NewWithT(t)

// Setup
cluster := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test3-",
Namespace: ns.Name,
},
}
g.Expect(env.Create(ctx, cluster)).To(Succeed())
key := client.ObjectKey{Name: cluster.Name, Namespace: cluster.Namespace}
defer func() {
err := env.Delete(ctx, cluster)
g.Expect(err).ToNot(HaveOccurred())
}()

// Wait for reconciliation to happen.
g.Eventually(func() bool {
if err := env.Get(ctx, key, cluster); err != nil {
return false
}
return len(cluster.Finalizers) > 0
}, timeout).Should(BeTrue())

// Patch
g.Eventually(func() bool {
ph, err := patch.NewHelper(cluster, env)
g.Expect(err).ToNot(HaveOccurred())
conditions.MarkTrue(cluster, clusterv1.InfrastructureReadyCondition)
g.Expect(ph.Patch(ctx, cluster, patch.WithStatusObservedGeneration{})).To(Succeed())
return true
}, timeout).Should(BeTrue())

// Assertions
g.Eventually(func() bool {
instance := &clusterv1.Cluster{}
if err := env.Get(ctx, key, instance); err != nil {
return false
}
return conditions.IsTrue(cluster, clusterv1.InfrastructureReadyCondition)
}, timeout).Should(BeTrue())
})

t.Run("Should successfully patch a cluster object if both the spec diff and status diff are non empty", func(t *testing.T) {
g := NewWithT(t)

Expand Down

0 comments on commit bd3fd3d

Please sign in to comment.