Skip to content

Commit

Permalink
Merge pull request #31 from metal-stack/fix-race-condition-in-readiness
Browse files Browse the repository at this point in the history
fix: race condition in readiness #28
  • Loading branch information
robertvolkmann authored Jan 21, 2025
2 parents a3253ee + 0db4878 commit 5574304
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 11 additions & 8 deletions internal/controller/metalstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,13 @@ func (r *clusterReconciler) status() error {
})

g.Go(func() error {
if r.infraCluster.Spec.Firewall == nil {
conditionUpdates <- func() {
conditions.MarkTrue(r.infraCluster, v1alpha1.ClusterFirewallDeploymentReady)
}
return nil
}

deploy := &fcmv2.FirewallDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: r.infraCluster.Name,
Expand All @@ -748,11 +755,6 @@ func (r *clusterReconciler) status() error {
}

if apierrors.IsNotFound(err) {
if r.infraCluster.Spec.Firewall == nil {
conditions.MarkTrue(r.infraCluster, v1alpha1.ClusterFirewallDeploymentReady)
return
}

conditions.MarkFalse(r.infraCluster, v1alpha1.ClusterFirewallDeploymentReady, "NotCreated", clusterv1.ConditionSeverityError, "firewall deployment was not yet created")
return
}
Expand Down Expand Up @@ -781,13 +783,14 @@ func (r *clusterReconciler) status() error {
}()

groupErr := g.Wait()
if groupErr == nil && allConditionsTrue() {
r.infraCluster.Status.Ready = true
}

close(conditionUpdates)
<-ready

if groupErr == nil && allConditionsTrue() {
r.infraCluster.Status.Ready = true
}

err := r.client.Status().Update(r.ctx, r.infraCluster)

return errors.Join(groupErr, err)
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/metalstackcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ var _ = Describe("MetalStackCluster Controller", func() {
"Type": Equal(v1alpha1.ClusterControlPlaneEndpointEnsured),
"Status": Equal(corev1.ConditionTrue),
})))
Expect(resource.Status.Ready).To(BeTrue())

By("ssh keypair generation")
sshSecret := &corev1.Secret{
Expand Down Expand Up @@ -386,6 +387,8 @@ var _ = Describe("MetalStackCluster Controller", func() {
"Status": Equal(corev1.ConditionTrue),
}),
))

Expect(resource.Status.Ready).To(BeTrue())
})
})

Expand Down Expand Up @@ -460,6 +463,8 @@ var _ = Describe("MetalStackCluster Controller", func() {
"Reason": Equal("InternalError"),
"Message": ContainSubstring("ip not found"),
})))

Expect(resource.Status.Ready).To(BeFalse())
})
})
})
Expand Down

0 comments on commit 5574304

Please sign in to comment.