Skip to content

Commit 3d32558

Browse files
committed
Remove routes of ex gw pods in terminating or not ready state
Signed-off-by: arkadeepsen <[email protected]>
1 parent 54d6ce3 commit 3d32558

File tree

6 files changed

+459
-4
lines changed

6 files changed

+459
-4
lines changed

go-controller/pkg/ovn/controller/apbroute/external_controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"k8s.io/client-go/tools/cache"
2323
"k8s.io/client-go/util/workqueue"
2424
"k8s.io/klog/v2"
25+
v1pod "k8s.io/kubernetes/pkg/api/v1/pod"
2526

2627
adminpolicybasedrouteapi "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/adminpolicybasedroute/v1"
2728
adminpolicybasedrouteinformer "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/adminpolicybasedroute/v1/apis/informers/externalversions/adminpolicybasedroute/v1"
@@ -565,10 +566,14 @@ func (m *externalPolicyManager) onPodUpdate(oldObj, newObj interface{}) {
565566
utilruntime.HandleError(errors.New("invalid Pod provided to onPodUpdate()"))
566567
return
567568
}
568-
// if labels AND assigned Pod IPs AND the multus network status annotations are the same, skip processing changes to the pod.
569+
// if labels AND assigned Pod IPs AND the multus network status annotations AND
570+
// pod PodReady condition AND deletion timestamp (PodTerminating) are
571+
// the same, skip processing changes to the pod.
569572
if reflect.DeepEqual(o.Labels, n.Labels) &&
570573
reflect.DeepEqual(o.Status.PodIPs, n.Status.PodIPs) &&
571-
reflect.DeepEqual(o.Annotations[nettypes.NetworkStatusAnnot], n.Annotations[nettypes.NetworkStatusAnnot]) {
574+
reflect.DeepEqual(o.Annotations[nettypes.NetworkStatusAnnot], n.Annotations[nettypes.NetworkStatusAnnot]) &&
575+
reflect.DeepEqual(v1pod.GetPodReadyCondition(o.Status), v1pod.GetPodReadyCondition(n.Status)) &&
576+
reflect.DeepEqual(o.DeletionTimestamp, n.DeletionTimestamp) {
572577
return
573578
}
574579
m.podQueue.Add(n)

go-controller/pkg/ovn/controller/apbroute/external_controller_pod.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import (
1111
"k8s.io/apimachinery/pkg/util/sets"
1212
"k8s.io/client-go/util/workqueue"
1313
"k8s.io/klog/v2"
14+
v1pod "k8s.io/kubernetes/pkg/api/v1/pod"
1415
utilnet "k8s.io/utils/net"
16+
17+
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"
1518
)
1619

1720
func (m *externalPolicyManager) syncPod(pod *corev1.Pod, routeQueue workqueue.TypedRateLimitingInterface[string]) error {
@@ -28,6 +31,13 @@ func (m *externalPolicyManager) syncPod(pod *corev1.Pod, routeQueue workqueue.Ty
2831
}
2932

3033
func getExGwPodIPs(gatewayPod *corev1.Pod, networkName string) (sets.Set[string], error) {
34+
// If an external gateway pod is in terminating or not ready state then don't return the
35+
// IPs for the external gateway pod
36+
if util.PodTerminating(gatewayPod) || !v1pod.IsPodReadyConditionTrue(gatewayPod.Status) {
37+
klog.Warningf("External gateway pod cannot serve traffic; it's in terminating or not ready state: %s/%s", gatewayPod.Namespace, gatewayPod.Name)
38+
return nil, nil
39+
}
40+
3141
if networkName != "" {
3242
return getMultusIPsFromNetworkName(gatewayPod, networkName)
3343
}

go-controller/pkg/ovn/egressgw.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
ktypes "k8s.io/apimachinery/pkg/types"
1616
"k8s.io/apimachinery/pkg/util/sets"
1717
"k8s.io/klog/v2"
18+
v1pod "k8s.io/kubernetes/pkg/api/v1/pod"
1819
utilnet "k8s.io/utils/net"
1920

2021
libovsdbclient "github.com/ovn-kubernetes/libovsdb/client"
@@ -49,6 +50,13 @@ func (oc *DefaultNetworkController) addPodExternalGW(pod *corev1.Pod) error {
4950

5051
klog.Infof("External gateway pod: %s, detected for namespace(s) %s", pod.Name, podRoutingNamespaceAnno)
5152

53+
// If an external gateway pod is in terminating or not ready state then don't add the
54+
// routes for the external gateway pod
55+
if util.PodTerminating(pod) || !v1pod.IsPodReadyConditionTrue(pod.Status) {
56+
klog.Warningf("External gateway pod cannot serve traffic; it's in terminating or not ready state: %s/%s", pod.Namespace, pod.Name)
57+
return nil
58+
}
59+
5260
foundGws, err := getExGwPodIPs(pod)
5361
if err != nil {
5462
klog.Errorf("Error getting exgw IPs for pod: %s, error: %v", pod.Name, err)

go-controller/pkg/ovn/ovn.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
listers "k8s.io/client-go/listers/core/v1"
1717
ref "k8s.io/client-go/tools/reference"
1818
"k8s.io/klog/v2"
19+
v1pod "k8s.io/kubernetes/pkg/api/v1/pod"
1920

2021
libovsdbclient "github.com/ovn-kubernetes/libovsdb/client"
2122

@@ -117,6 +118,10 @@ func networkStatusAnnotationsChanged(oldPod, newPod *corev1.Pod) bool {
117118
return oldPod.Annotations[nettypes.NetworkStatusAnnot] != newPod.Annotations[nettypes.NetworkStatusAnnot]
118119
}
119120

121+
func podBecameReady(oldPod, newPod *corev1.Pod) bool {
122+
return !v1pod.IsPodReadyConditionTrue(oldPod.Status) && v1pod.IsPodReadyConditionTrue(newPod.Status)
123+
}
124+
120125
// ensurePod tries to set up a pod. It returns nil on success and error on failure; failure
121126
// indicates the pod set up should be retried later.
122127
func (oc *DefaultNetworkController) ensurePod(oldPod, pod *corev1.Pod, addPort bool) error {
@@ -131,6 +136,14 @@ func (oc *DefaultNetworkController) ensurePod(oldPod, pod *corev1.Pod, addPort b
131136
return oc.ensureRemotePodIP(oldPod, pod, addPort)
132137
}
133138

139+
// If an external gateway pod is in terminating or not ready state then remove the
140+
// routes for the external gateway pod
141+
if util.PodTerminating(pod) || !v1pod.IsPodReadyConditionTrue(pod.Status) {
142+
if err := oc.deletePodExternalGW(pod); err != nil {
143+
return fmt.Errorf("ensurePod failed %s/%s: %w", pod.Namespace, pod.Name, err)
144+
}
145+
}
146+
134147
if oc.isPodScheduledinLocalZone(pod) {
135148
klog.V(5).Infof("Ensuring zone local for Pod %s/%s in node %s", pod.Namespace, pod.Name, pod.Spec.NodeName)
136149
return oc.ensureLocalZonePod(oldPod, pod, addPort)
@@ -170,7 +183,7 @@ func (oc *DefaultNetworkController) ensureLocalZonePod(oldPod, pod *corev1.Pod,
170183
}
171184
} else {
172185
// either pod is host-networked or its an update for a normal pod (addPort=false case)
173-
if oldPod == nil || exGatewayAnnotationsChanged(oldPod, pod) || networkStatusAnnotationsChanged(oldPod, pod) {
186+
if oldPod == nil || exGatewayAnnotationsChanged(oldPod, pod) || networkStatusAnnotationsChanged(oldPod, pod) || podBecameReady(oldPod, pod) {
174187
if err := oc.addPodExternalGW(pod); err != nil {
175188
return fmt.Errorf("addPodExternalGW failed for %s/%s: %w", pod.Namespace, pod.Name, err)
176189
}
@@ -237,7 +250,7 @@ func (oc *DefaultNetworkController) ensureRemoteZonePod(oldPod, pod *corev1.Pod,
237250
}
238251

239252
// either pod is host-networked or its an update for a normal pod (addPort=false case)
240-
if oldPod == nil || exGatewayAnnotationsChanged(oldPod, pod) || networkStatusAnnotationsChanged(oldPod, pod) {
253+
if oldPod == nil || exGatewayAnnotationsChanged(oldPod, pod) || networkStatusAnnotationsChanged(oldPod, pod) || podBecameReady(oldPod, pod) {
241254
// check if this remote pod is serving as an external GW. If so add the routes in the namespace
242255
// associated with this remote pod
243256
if err := oc.addPodExternalGW(pod); err != nil {

0 commit comments

Comments
 (0)