Skip to content

Commit

Permalink
do not check static route conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Aug 16, 2022
1 parent 7103aae commit 2f44599
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 85 deletions.
79 changes: 22 additions & 57 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,72 +558,37 @@ func (c *Controller) handleDeletePod(pod *v1.Pod) error {

p, _ := c.podsLister.Pods(pod.Namespace).Get(pod.Name)
if p != nil && p.UID != pod.UID {
// The existing OVN static route with a different nexthop will block creation of the new Pod,
// so we need to check the node names
if pod.Spec.NodeName == "" || pod.Spec.NodeName == p.Spec.NodeName {
// the old Pod has not been scheduled,
// or the new Pod and the old one are scheduled to the same node
return nil
// Pod with same name exists, just return here
return nil
}

addresses := c.ipam.GetPodAddress(key)
for _, address := range addresses {
if strings.TrimSpace(address.Ip) == "" {
continue
}
if pod.DeletionTimestamp == nil {
// triggered by add/update events, ignore
return nil
subnet, err := c.subnetsLister.Get(address.Subnet.Name)
if err != nil {
return err
}
vpc, err := c.vpcsLister.Get(subnet.Spec.Vpc)
if err != nil {
return err
}
if err := c.ovnClient.DeleteStaticRoute(address.Ip, vpc.Status.Router); err != nil {
return err
}
if err := c.ovnClient.DeleteNatRule(address.Ip, vpc.Status.Router); err != nil {
return err
}
}

ports, err := c.ovnClient.ListPodLogicalSwitchPorts(podName, pod.Namespace)
ports, err := c.ovnClient.ListPodLogicalSwitchPorts(pod.Name, pod.Namespace)
if err != nil {
klog.Errorf("failed to list lsps of pod '%s', %v", pod.Name, err)
return err
}

if len(ports) != 0 {
addresses := c.ipam.GetPodAddress(key)
for _, address := range addresses {
if strings.TrimSpace(address.Ip) == "" {
continue
}
subnet, err := c.subnetsLister.Get(address.Subnet.Name)
if k8serrors.IsNotFound(err) {
continue
} else if err != nil {
return err
}
vpc, err := c.vpcsLister.Get(subnet.Spec.Vpc)
if k8serrors.IsNotFound(err) {
continue
} else if err != nil {
return err
}
if err := c.ovnClient.DeleteStaticRoute(address.Ip, vpc.Status.Router); err != nil {
return err
}
if err := c.ovnClient.DeleteNatRule(address.Ip, vpc.Status.Router); err != nil {
return err
}
}

// there's some case which can not delete static route by ipam for sts pod when upgrading from lower version
for _, lsp := range ports {
addrs, err := c.ovnClient.GetLogicalSwitchPortAddress(lsp)
if err != nil {
if err != ovs.ErrNoAddr {
klog.Errorf("failed to get addr for lsp %s, %v", lsp, err)
}
continue
}
for _, addr := range addrs {
if net.ParseIP(addr) == nil {
continue
}
if err := c.ovnClient.DeleteStaticRoute(addr, util.DefaultVpc); err != nil {
klog.Errorf("failed to delete static route for lsp %s, err %v", lsp, err)
return err
}
}
}
}

var keepIpCR bool
if ok, sts := isStatefulSetPod(pod); ok {
toDel := isStatefulSetPodToDel(c.config.KubeClient, pod, sts)
Expand Down
28 changes: 0 additions & 28 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,20 +680,6 @@ func (c Client) AddStaticRoute(policy, cidr, nextHop, router string, routeType s
policy = PolicyDstIP
}

var existingRoutes []string
if routeType != util.EcmpRouteType {
result, err := c.CustomFindEntity("Logical_Router", []string{"static_routes"}, fmt.Sprintf("name=%s", router))
if err != nil {
return err
}
if len(result) > 1 {
return fmt.Errorf("unexpected error: found %d logical router with name %s", len(result), router)
}
if len(result) != 0 {
existingRoutes = result[0]["static_routes"]
}
}

for _, cidrBlock := range strings.Split(cidr, ",") {
for _, gw := range strings.Split(nextHop, ",") {
if util.CheckProtocol(cidrBlock) != util.CheckProtocol(gw) {
Expand All @@ -704,20 +690,6 @@ func (c Client) AddStaticRoute(policy, cidr, nextHop, router string, routeType s
return err
}
} else {
if !strings.ContainsRune(cidrBlock, '/') {
filter := []string{fmt.Sprintf("policy=%s", policy), fmt.Sprintf(`ip_prefix="%s"`, cidrBlock), fmt.Sprintf(`nexthop!="%s"`, gw)}
result, err := c.CustomFindEntity("Logical_Router_Static_Route", []string{"_uuid"}, filter...)
if err != nil {
return err
}

for _, route := range result {
if util.ContainsString(existingRoutes, route["_uuid"][0]) {
return fmt.Errorf(`static route "policy=%s ip_prefix=%s" with different nexthop already exists on logical router %s`, policy, cidrBlock, router)
}
}
}

if _, err := c.ovnNbCommand(MayExist, fmt.Sprintf("%s=%s", Policy, policy), "lr-route-add", router, cidrBlock, gw); err != nil {
return err
}
Expand Down

0 comments on commit 2f44599

Please sign in to comment.