Skip to content

Commit 3ef2504

Browse files
committed
Move runtime config reconcilation post service setup
We need to wait for ovn cluster to be ready and that relies on pods to be in ready state. And for multi replica ovn cluster the pods needs to communicate with each other using dns addresses and those are provided by the headless service. So moving the runtime config task post setting up the services so cluster can be formed and pods move to the ready state. This issue was catched in the backup/restore exercise [2]. Also adapted getPodIPInNetwork to set networkattachment condition and accordingly the envtest. [1] #540 [2] https://github.com/openstack-k8s-operators/dev-docs/blob/main/backup-restore/user-guide.md Related-Issue: #OSPRH-27985 Signed-off-by: Yatin Karel <ykarel@redhat.com>
1 parent a430f15 commit 3ef2504

2 files changed

Lines changed: 48 additions & 40 deletions

File tree

internal/controller/ovndbcluster_controller.go

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -659,26 +659,31 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
659659
return ctrlResult, nil
660660
}
661661

662+
// create Statefulset - end
663+
// Handle service init
664+
ctrlResult, err = r.reconcileServices(ctx, instance, helper, serviceLabels, serviceName)
665+
if err != nil {
666+
instance.Status.Conditions.Set(condition.FalseCondition(
667+
condition.ExposeServiceReadyCondition,
668+
condition.ErrorReason,
669+
condition.SeverityWarning,
670+
condition.ExposeServiceReadyErrorMessage,
671+
err.Error()))
672+
return ctrlResult, err
673+
} else if (ctrlResult != ctrl.Result{}) {
674+
instance.Status.Conditions.Set(condition.FalseCondition(
675+
condition.ExposeServiceReadyCondition,
676+
condition.RequestedReason,
677+
condition.SeverityInfo,
678+
condition.ExposeServiceReadyRunningMessage))
679+
return ctrlResult, err
680+
}
681+
662682
stateful := sfset.GetStatefulSet()
663683
if stateful.Generation == stateful.Status.ObservedGeneration {
664684
instance.Status.ReadyCount = stateful.Status.ReadyReplicas
665685
}
666686

667-
// Only run runtime config when all pods are ready and no rolling update in progress
668-
if instance.Status.ReadyCount == *instance.Spec.Replicas &&
669-
stateful.Status.UpdatedReplicas == *instance.Spec.Replicas {
670-
err = r.reconcileRuntimeConfig(ctx, helper, instance, serviceLabels, serviceName)
671-
if err != nil {
672-
instance.Status.Conditions.Set(condition.FalseCondition(
673-
condition.ServiceConfigReadyCondition,
674-
condition.ErrorReason,
675-
condition.SeverityWarning,
676-
condition.ServiceConfigReadyErrorMessage,
677-
err.Error()))
678-
return ctrl.Result{}, err
679-
}
680-
}
681-
682687
// verify if network attachment matches expectations
683688
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, networkAttachments, serviceLabels, instance.Status.ReadyCount)
684689
if err != nil {
@@ -700,26 +705,6 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
700705
return ctrlResult, nil
701706
}
702707

703-
// create Statefulset - end
704-
// Handle service init
705-
ctrlResult, err = r.reconcileServices(ctx, instance, helper, serviceLabels, serviceName)
706-
if err != nil {
707-
instance.Status.Conditions.Set(condition.FalseCondition(
708-
condition.ExposeServiceReadyCondition,
709-
condition.ErrorReason,
710-
condition.SeverityWarning,
711-
condition.ExposeServiceReadyErrorMessage,
712-
err.Error()))
713-
return ctrlResult, err
714-
} else if (ctrlResult != ctrl.Result{}) {
715-
instance.Status.Conditions.Set(condition.FalseCondition(
716-
condition.ExposeServiceReadyCondition,
717-
condition.RequestedReason,
718-
condition.SeverityInfo,
719-
condition.ExposeServiceReadyRunningMessage))
720-
return ctrlResult, err
721-
}
722-
723708
svcList, err := service.GetServicesListWithLabel(
724709
ctx,
725710
helper,
@@ -736,6 +721,21 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
736721
return ctrl.Result{}, err
737722
}
738723

724+
// Only run runtime config when all pods are ready and no rolling update in progress
725+
if instance.Status.ReadyCount == *instance.Spec.Replicas &&
726+
stateful.Status.UpdatedReplicas == *instance.Spec.Replicas {
727+
err = r.reconcileRuntimeConfig(ctx, helper, instance, serviceLabels, serviceName)
728+
if err != nil {
729+
instance.Status.Conditions.Set(condition.FalseCondition(
730+
condition.ServiceConfigReadyCondition,
731+
condition.ErrorReason,
732+
condition.SeverityWarning,
733+
condition.ServiceConfigReadyErrorMessage,
734+
err.Error()))
735+
return ctrl.Result{}, err
736+
}
737+
}
738+
739739
if statefulset.IsReady(stateful) && len(svcList.Items) > 0 {
740740
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
741741
instance.Status.Conditions.MarkTrue(condition.ExposeServiceReadyCondition, condition.ExposeServiceReadyMessage)
@@ -797,7 +797,9 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
797797
return ctrl.Result{}, nil
798798
}
799799

800-
func getPodIPInNetwork(ovnPod corev1.Pod, namespace string, networkAttachment string) (string, error) {
800+
func getPodIPInNetwork(ovnPod corev1.Pod, instance *ovnv1.OVNDBCluster) (string, error) {
801+
namespace := instance.Namespace
802+
networkAttachment := instance.Spec.NetworkAttachment
801803
netStat, err := nad.GetNetworkStatusFromAnnotation(ovnPod.Annotations)
802804
if err != nil {
803805
err = fmt.Errorf("error while getting the Network Status for pod %s: %w", ovnPod.Name, err)
@@ -812,6 +814,12 @@ func getPodIPInNetwork(ovnPod corev1.Pod, namespace string, networkAttachment st
812814
}
813815
// If this is reached it means that no IP was found, construct error and return
814816
err = fmt.Errorf("%w IP address from pod %s in network %s, IP is empty", util.ErrInvalidStatus, ovnPod.Name, networkAttachment)
817+
instance.Status.Conditions.Set(condition.FalseCondition(
818+
condition.NetworkAttachmentsReadyCondition,
819+
condition.ErrorReason,
820+
condition.SeverityWarning,
821+
condition.NetworkAttachmentsReadyErrorMessage,
822+
err.Error()))
815823
return "", err
816824
}
817825

@@ -1005,11 +1013,11 @@ func (r *OVNDBClusterReconciler) reconcileServices(
10051013
return ctrl.Result{}, err
10061014
}
10071015

1008-
dnsIP, err := getPodIPInNetwork(ovnPod, instance.Namespace, instance.Spec.NetworkAttachment)
1009-
dnsIPsList = append(dnsIPsList, dnsIP)
1016+
dnsIP, err := getPodIPInNetwork(ovnPod, instance)
10101017
if err != nil {
10111018
return ctrl.Result{}, err
10121019
}
1020+
dnsIPsList = append(dnsIPsList, dnsIP)
10131021
}
10141022
// DNSData info is called every reconcile loop to ensure that even if a pod gets
10151023
// restarted and it's IP has changed, the DNSData CR will have the correct info.

test/functional/ovndbcluster_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ var _ = Describe("OVNDBCluster controller", func() {
837837
corev1.ConditionFalse,
838838
condition.ErrorReason,
839839
"NetworkAttachments error occurred "+
840-
"not all pods have interfaces with ips as configured in NetworkAttachments: internalapi",
840+
"invalid status IP address from pod ovsdbserver-sb-0 in network internalapi, IP is empty",
841841
)
842842
})
843843
It("reports that an IP is missing", func() {
@@ -877,7 +877,7 @@ var _ = Describe("OVNDBCluster controller", func() {
877877
corev1.ConditionFalse,
878878
condition.ErrorReason,
879879
"NetworkAttachments error occurred "+
880-
"not all pods have interfaces with ips as configured in NetworkAttachments: internalapi",
880+
"invalid status IP address from pod ovsdbserver-sb-0 in network internalapi, IP is empty",
881881
)
882882
})
883883
It("reports NetworkAttachmentsReady if the Pods got the proper annotations", func() {

0 commit comments

Comments
 (0)