Skip to content

Commit ca94914

Browse files
authored
fix: check northd endpoint by pod IP protocol in ovn leader checker (#6523)
Instead of skipping IPv6 addresses, now the checkNorthdEpAlive function determines the expected AddressType based on the pod's own IP protocol (IPv4 or IPv6) and only checks endpoint slices matching that protocol. This ensures proper endpoint availability checking for both IPv4 and IPv6 deployments. Signed-off-by: clyi <clyi@alauda.io>
1 parent 1954678 commit ca94914

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

pkg/ovn_leader_checker/ovn.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,34 @@ func checkNorthdEpAvailable(ip string) bool {
282282
return true
283283
}
284284

285-
func checkNorthdEpAlive(cfg *Configuration, namespace, service string) bool {
285+
func checkNorthdEpAlive(cfg *Configuration, namespace, service string, expectedAddrType discoveryv1.AddressType) bool {
286286
epsList, err := cfg.KubeClient.DiscoveryV1().EndpointSlices(namespace).List(context.Background(), metav1.ListOptions{LabelSelector: labelSelector})
287287
if err != nil {
288288
klog.Errorf("failed to list endpoint slices for service %s/%s: %v", namespace, service, err)
289289
return false
290290
}
291291

292292
for _, eps := range epsList.Items {
293+
// Only check endpoint slices matching the pod IP protocol
294+
if eps.AddressType != expectedAddrType {
295+
continue
296+
}
297+
293298
for _, ep := range eps.Endpoints {
294299
if (ep.Conditions.Ready != nil && !*ep.Conditions.Ready) || len(ep.Addresses) == 0 {
295300
continue
296301
}
297302

298-
// Found an address, check its availability. We only need one.
299-
klog.V(5).Infof("found address %s in endpoint slice %s/%s for service %s, checking availability", ep.Addresses[0], eps.Namespace, eps.Name, service)
300-
return checkNorthdEpAvailable(ep.Addresses[0])
303+
for _, address := range ep.Addresses {
304+
klog.V(5).Infof("found address %s in endpoint slice %s/%s for service %s, checking availability", address, eps.Namespace, eps.Name, service)
305+
if checkNorthdEpAvailable(address) {
306+
return true
307+
}
308+
}
301309
}
302310
}
303311

304-
klog.V(5).Infof("no address found in any endpoint slices for service %s/%s", namespace, service)
312+
klog.V(5).Infof("no address found in any endpoint slices for service %s/%s with AddressType %s", namespace, service, expectedAddrType)
305313
return false
306314
}
307315

@@ -422,6 +430,15 @@ func doOvnLeaderCheck(cfg *Configuration, podName, podNamespace string) {
422430
util.LogFatalAndExit(nil, "preValidChkCfg: invalid cfg")
423431
}
424432

433+
// Determine the expected AddressType based on pod IP protocol
434+
podIP := os.Getenv(util.EnvPodIP)
435+
var expectedAddrType discoveryv1.AddressType
436+
if util.CheckProtocol(podIP) == kubeovnv1.ProtocolIPv6 {
437+
expectedAddrType = discoveryv1.AddressTypeIPv6
438+
} else {
439+
expectedAddrType = discoveryv1.AddressTypeIPv4
440+
}
441+
425442
if !cfg.IsICDBServer && !checkOvnIsAlive() {
426443
klog.Errorf("ovn is not alive")
427444
return
@@ -441,7 +458,7 @@ func doOvnLeaderCheck(cfg *Configuration, podName, podNamespace string) {
441458
return
442459
}
443460
if sbLeader && checkNorthdSvcExist(cfg, podNamespace, "ovn-northd") {
444-
if !checkNorthdEpAlive(cfg, podNamespace, "ovn-northd") {
461+
if !checkNorthdEpAlive(cfg, podNamespace, "ovn-northd", expectedAddrType) {
445462
klog.Warning("no available northd leader, try to release the lock")
446463
stealLock()
447464
}

0 commit comments

Comments
 (0)