@@ -22,10 +22,12 @@ import (
22
22
sriovutilfs "github.com/k8snetworkplumbingwg/sriovnet/pkg/utils/filesystem"
23
23
"github.com/vishvananda/netlink"
24
24
"golang.org/x/sys/unix"
25
+ corev1 "k8s.io/api/core/v1"
25
26
k8serrors "k8s.io/apimachinery/pkg/api/errors"
26
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
28
"k8s.io/apimachinery/pkg/labels"
28
29
"k8s.io/apimachinery/pkg/types"
30
+ "k8s.io/client-go/kubernetes"
29
31
"k8s.io/klog/v2"
30
32
31
33
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
@@ -591,7 +593,7 @@ func waitNetworkReady(nic, ipAddr, gateway string, underlayGateway, verbose bool
591
593
return nil
592
594
}
593
595
594
- func configureNodeNic (portName , ip , gw , joinCIDR string , macAddr net.HardwareAddr , mtu int ) error {
596
+ func configureNodeNic (cs kubernetes. Interface , nodeName , portName , ip , gw , joinCIDR string , macAddr net.HardwareAddr , mtu int ) error {
595
597
ipStr := util .GetIPWithoutMask (ip )
596
598
raw , err := ovs .Exec (ovs .MayExist , "add-port" , "br-int" , util .NodeNic , "--" ,
597
599
"set" , "interface" , util .NodeNic , "type=internal" , "--" ,
@@ -670,11 +672,20 @@ func configureNodeNic(portName, ip, gw, joinCIDR string, macAddr net.HardwareAdd
670
672
671
673
// ping ovn0 gw to activate the flow
672
674
klog .Infof ("wait ovn0 gw ready" )
673
- if err := waitNetworkReady (util .NodeNic , ip , gw , false , true , gatewayCheckMaxRetry , nil ); err != nil {
675
+ status := corev1 .ConditionFalse
676
+ reason := "JoinSubnetGatewayReachable"
677
+ message := fmt .Sprintf ("ping check to gateway ip %s succeeded" , gw )
678
+ if err = waitNetworkReady (util .NodeNic , ip , gw , false , true , gatewayCheckMaxRetry , nil ); err != nil {
674
679
klog .Errorf ("failed to init ovn0 check: %v" , err )
675
- return err
680
+ status = corev1 .ConditionTrue
681
+ reason = "JoinSubnetGatewayUnreachable"
682
+ message = fmt .Sprintf ("ping check to gateway ip %s failed" , gw )
676
683
}
677
- return nil
684
+ if err := util .SetNodeNetworkUnavailableCondition (cs , nodeName , status , reason , message ); err != nil {
685
+ klog .Errorf ("failed to set node network unavailable condition: %v" , err )
686
+ }
687
+
688
+ return err
678
689
}
679
690
680
691
// If OVS restart, the ovn0 port will down and prevent host to pod network,
@@ -696,7 +707,31 @@ func (c *Controller) loopOvn0Check() {
696
707
}
697
708
ip := node .Annotations [util .IPAddressAnnotation ]
698
709
gw := node .Annotations [util .GatewayAnnotation ]
699
- if err := waitNetworkReady (util .NodeNic , ip , gw , false , false , 5 , nil ); err != nil {
710
+ status := corev1 .ConditionFalse
711
+ reason := "JoinSubnetGatewayReachable"
712
+ message := fmt .Sprintf ("ping check to gateway ip %s succeeded" , gw )
713
+ if err = waitNetworkReady (util .NodeNic , ip , gw , false , false , 5 , nil ); err != nil {
714
+ klog .Errorf ("failed to init ovn0 check: %v" , err )
715
+ status = corev1 .ConditionTrue
716
+ reason = "JoinSubnetGatewayUnreachable"
717
+ message = fmt .Sprintf ("ping check to gateway ip %s failed" , gw )
718
+ }
719
+
720
+ var alreadySet bool
721
+ for _ , condition := range node .Status .Conditions {
722
+ if condition .Type == corev1 .NodeNetworkUnavailable && condition .Status == corev1 .ConditionTrue &&
723
+ condition .Reason == reason && condition .Message == message {
724
+ alreadySet = true
725
+ break
726
+ }
727
+ }
728
+ if ! alreadySet {
729
+ if err := util .SetNodeNetworkUnavailableCondition (c .config .KubeClient , c .config .NodeName , status , reason , message ); err != nil {
730
+ klog .Errorf ("failed to set node network unavailable condition: %v" , err )
731
+ }
732
+ }
733
+
734
+ if err != nil {
700
735
util .LogFatalAndExit (err , "failed to ping ovn0 gateway %s" , gw )
701
736
}
702
737
}
0 commit comments