@@ -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