Skip to content

Commit 3bcd694

Browse files
committed
Use statefulset.IsReady() to validate status
Changes to use the common IsReady() func to validate a deployment is fully up as requested and e.g. no update rollout in progress. During a minor update this has seen to already report/mark the condition ready, even the deployment is still in progress, or the replacement pod failed. Jira: OSPRH-14472 Depends-On: openstack-k8s-operators/lib-common#616 Signed-off-by: Martin Schuppert <[email protected]>
1 parent def3136 commit 3bcd694

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

controllers/ovndbcluster_controller.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,10 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
603603
return ctrlResult, nil
604604
}
605605

606-
instance.Status.ReadyCount = sfset.GetStatefulSet().Status.ReadyReplicas
606+
deploy := sfset.GetStatefulSet()
607+
if deploy.Generation == deploy.Status.ObservedGeneration {
608+
instance.Status.ReadyCount = deploy.Status.ReadyReplicas
609+
}
607610

608611
// verify if network attachment matches expectations
609612
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, networkAttachments, serviceLabels, instance.Status.ReadyCount)
@@ -662,7 +665,7 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
662665
return ctrl.Result{}, err
663666
}
664667

665-
if instance.Status.ReadyCount > 0 && len(svcList.Items) > 0 {
668+
if statefulset.IsReady(deploy) && len(svcList.Items) > 0 {
666669
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
667670
instance.Status.Conditions.MarkTrue(condition.ExposeServiceReadyCondition, condition.ExposeServiceReadyMessage)
668671
internalDbAddress := []string{}
@@ -700,6 +703,15 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
700703
}
701704
}
702705

706+
} else {
707+
Log.Info("Deployment is not ready")
708+
instance.Status.Conditions.Set(condition.FalseCondition(
709+
condition.DeploymentReadyCondition,
710+
condition.RequestedReason,
711+
condition.SeverityInfo,
712+
condition.DeploymentReadyRunningMessage))
713+
// It is OK to return success as we are watching for StatefulSet changes
714+
return ctrl.Result{}, nil
703715
}
704716
Log.Info("Reconciled Service successfully")
705717
return ctrl.Result{}, nil

tests/functional/ovndbcluster_controller_test.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ var _ = Describe("OVNDBCluster controller", func() {
305305
})
306306

307307
When("OVNDBClusters are created with networkAttachments", func() {
308-
It("does not break if pods are not created yet", func() {
308+
It("does not break if pods get scaled", func() {
309309
// Create OVNDBCluster with 1 replica
310310
spec := GetDefaultOVNDBClusterSpec()
311311
spec.NetworkAttachment = "internalapi"
@@ -321,12 +321,13 @@ var _ = Describe("OVNDBCluster controller", func() {
321321
g.Expect(k8sClient.Update(ctx, c)).Should(Succeed())
322322
}).Should(Succeed())
323323

324-
//Check that error occurs
325-
Eventually(func(g Gomega) {
326-
conditions := GetOVNDBCluster(dbs[0]).Status.Conditions
327-
cond := conditions.Get(condition.ExposeServiceReadyCondition)
328-
g.Expect(cond.Status).To(Equal(corev1.ConditionFalse))
329-
}).Should(Succeed())
324+
// check that cluster reaches ready
325+
th.ExpectCondition(
326+
dbs[0],
327+
ConditionGetterFunc(OVNDBClusterConditionGetter),
328+
condition.ReadyCondition,
329+
corev1.ConditionTrue,
330+
)
330331

331332
// Decrease replicas back to 1
332333
Eventually(func(g Gomega) {
@@ -335,12 +336,13 @@ var _ = Describe("OVNDBCluster controller", func() {
335336
g.Expect(k8sClient.Update(ctx, c)).Should(Succeed())
336337
}).Should(Succeed())
337338

338-
//Check that error doesn't happen and instance is ready
339-
Eventually(func(g Gomega) {
340-
conditions := GetOVNDBCluster(dbs[0]).Status.Conditions
341-
cond := conditions.Get(condition.DeploymentReadyCondition)
342-
g.Expect(cond.Status).To(Equal(corev1.ConditionTrue))
343-
}).Should(Succeed())
339+
// check that cluster reaches ready
340+
th.ExpectCondition(
341+
dbs[0],
342+
ConditionGetterFunc(OVNDBClusterConditionGetter),
343+
condition.ReadyCondition,
344+
corev1.ConditionTrue,
345+
)
344346

345347
})
346348

0 commit comments

Comments
 (0)