Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions controllers/ovndbcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,10 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
return ctrlResult, nil
}

instance.Status.ReadyCount = sfset.GetStatefulSet().Status.ReadyReplicas
stateful := sfset.GetStatefulSet()
if stateful.Generation == stateful.Status.ObservedGeneration {
instance.Status.ReadyCount = stateful.Status.ReadyReplicas
}

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

if instance.Status.ReadyCount > 0 && len(svcList.Items) > 0 {
if statefulset.IsReady(stateful) && len(svcList.Items) > 0 {
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
instance.Status.Conditions.MarkTrue(condition.ExposeServiceReadyCondition, condition.ExposeServiceReadyMessage)
internalDbAddress := []string{}
Expand Down Expand Up @@ -700,6 +703,15 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
}
}

} else {
Log.Info("Deployment is not ready")
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.DeploymentReadyRunningMessage))
// It is OK to return success as we are watching for StatefulSet changes
return ctrl.Result{}, nil
}
Log.Info("Reconciled Service successfully")
return ctrl.Result{}, nil
Expand Down
28 changes: 15 additions & 13 deletions tests/functional/ovndbcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ var _ = Describe("OVNDBCluster controller", func() {
})

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

//Check that error occurs
Eventually(func(g Gomega) {
conditions := GetOVNDBCluster(dbs[0]).Status.Conditions
cond := conditions.Get(condition.ExposeServiceReadyCondition)
g.Expect(cond.Status).To(Equal(corev1.ConditionFalse))
}).Should(Succeed())
Comment on lines -325 to -329
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error part is not what I got.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that error was added on purpose some months back by @averdagu , let's check that first

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for late response. This test was added due to OSPRH-6798. Where it could happen some panic due to checking Out of Range item on a list. What this test is checking is to not report ready if pods are not created.
Eventho this test scales up the replicas to 3, reconcile loop won't create the new pods (and len(pods) will always be 1), this is like this due to pods are created on function CreateOVNDBClusters more specifically on SimulateStatefulSetReplicaReadyWithPods.
I checked the code with master, tomorrow will check code with your code to see why you're not seeing this error :)

// check that cluster reaches ready
th.ExpectCondition(
dbs[0],
ConditionGetterFunc(OVNDBClusterConditionGetter),
condition.ReadyCondition,
corev1.ConditionTrue,
)

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

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

})

Expand Down