Skip to content

Commit 5574304

Browse files
Merge pull request #31 from metal-stack/fix-race-condition-in-readiness
fix: race condition in readiness #28
2 parents a3253ee + 0db4878 commit 5574304

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

internal/controller/metalstackcluster_controller.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,13 @@ func (r *clusterReconciler) status() error {
732732
})
733733

734734
g.Go(func() error {
735+
if r.infraCluster.Spec.Firewall == nil {
736+
conditionUpdates <- func() {
737+
conditions.MarkTrue(r.infraCluster, v1alpha1.ClusterFirewallDeploymentReady)
738+
}
739+
return nil
740+
}
741+
735742
deploy := &fcmv2.FirewallDeployment{
736743
ObjectMeta: metav1.ObjectMeta{
737744
Name: r.infraCluster.Name,
@@ -748,11 +755,6 @@ func (r *clusterReconciler) status() error {
748755
}
749756

750757
if apierrors.IsNotFound(err) {
751-
if r.infraCluster.Spec.Firewall == nil {
752-
conditions.MarkTrue(r.infraCluster, v1alpha1.ClusterFirewallDeploymentReady)
753-
return
754-
}
755-
756758
conditions.MarkFalse(r.infraCluster, v1alpha1.ClusterFirewallDeploymentReady, "NotCreated", clusterv1.ConditionSeverityError, "firewall deployment was not yet created")
757759
return
758760
}
@@ -781,13 +783,14 @@ func (r *clusterReconciler) status() error {
781783
}()
782784

783785
groupErr := g.Wait()
784-
if groupErr == nil && allConditionsTrue() {
785-
r.infraCluster.Status.Ready = true
786-
}
787786

788787
close(conditionUpdates)
789788
<-ready
790789

790+
if groupErr == nil && allConditionsTrue() {
791+
r.infraCluster.Status.Ready = true
792+
}
793+
791794
err := r.client.Status().Update(r.ctx, r.infraCluster)
792795

793796
return errors.Join(groupErr, err)

internal/controller/metalstackcluster_controller_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ var _ = Describe("MetalStackCluster Controller", func() {
273273
"Type": Equal(v1alpha1.ClusterControlPlaneEndpointEnsured),
274274
"Status": Equal(corev1.ConditionTrue),
275275
})))
276+
Expect(resource.Status.Ready).To(BeTrue())
276277

277278
By("ssh keypair generation")
278279
sshSecret := &corev1.Secret{
@@ -386,6 +387,8 @@ var _ = Describe("MetalStackCluster Controller", func() {
386387
"Status": Equal(corev1.ConditionTrue),
387388
}),
388389
))
390+
391+
Expect(resource.Status.Ready).To(BeTrue())
389392
})
390393
})
391394

@@ -460,6 +463,8 @@ var _ = Describe("MetalStackCluster Controller", func() {
460463
"Reason": Equal("InternalError"),
461464
"Message": ContainSubstring("ip not found"),
462465
})))
466+
467+
Expect(resource.Status.Ready).To(BeFalse())
463468
})
464469
})
465470
})

0 commit comments

Comments
 (0)