Skip to content

Commit

Permalink
fix lr policy for default subnet with logical gateway enabled (#2177)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Dec 27, 2022
1 parent b9085d5 commit ea0b77c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func (c *Controller) gcPortGroup() error {
return err
}
for _, subnet := range subnets {
if subnet.Spec.Vpc != util.DefaultVpc || subnet.Spec.Vlan != "" || subnet.Name == c.config.NodeSwitch || subnet.Spec.GatewayType != kubeovnv1.GWDistributedType {
if subnet.Spec.Vpc != util.DefaultVpc || (subnet.Spec.Vlan != "" && !subnet.Spec.LogicalGateway) || subnet.Name == c.config.NodeSwitch || subnet.Spec.GatewayType != kubeovnv1.GWDistributedType {
continue
}
for _, node := range nodes {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (c *Controller) handleAddNode(key string) error {
}

for _, subnet := range subnets {
if subnet.Spec.Vlan != "" || subnet.Spec.Vpc != util.DefaultVpc || subnet.Name == c.config.NodeSwitch || subnet.Spec.GatewayType != kubeovnv1.GWDistributedType {
if (subnet.Spec.Vlan != "" && !subnet.Spec.LogicalGateway) || subnet.Spec.Vpc != util.DefaultVpc || subnet.Name == c.config.NodeSwitch || subnet.Spec.GatewayType != kubeovnv1.GWDistributedType {
continue
}
if err = c.createPortGroupForDistributedSubnet(node, subnet); err != nil {
Expand Down Expand Up @@ -1114,7 +1114,7 @@ func (c *Controller) deletePolicyRouteForNode(nodeName string) error {
}

for _, subnet := range subnets {
if subnet.Spec.Vlan != "" || subnet.Spec.Vpc != util.DefaultVpc || subnet.Name == c.config.NodeSwitch {
if (subnet.Spec.Vlan != "" && !subnet.Spec.LogicalGateway) || subnet.Spec.Vpc != util.DefaultVpc || subnet.Name == c.config.NodeSwitch {
continue
}

Expand Down Expand Up @@ -1181,7 +1181,7 @@ func (c *Controller) addPolicyRouteForCentralizedSubnetOnNode(nodeName, nodeIP s
}

for _, subnet := range subnets {
if subnet.Spec.Vlan != "" || subnet.Spec.Vpc != util.DefaultVpc || subnet.Name == c.config.NodeSwitch || subnet.Spec.GatewayType != kubeovnv1.GWCentralizedType {
if (subnet.Spec.Vlan != "" && !subnet.Spec.LogicalGateway) || subnet.Spec.Vpc != util.DefaultVpc || subnet.Name == c.config.NodeSwitch || subnet.Spec.GatewayType != kubeovnv1.GWCentralizedType {
continue
}

Expand Down
20 changes: 14 additions & 6 deletions pkg/daemon/controller_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,34 @@ func (c *Controller) reconcileRouters(event subnetEvent) error {
}
}

node, err := c.nodesLister.Get(c.config.NodeName)
if err != nil {
klog.Errorf("failed to get node %s %v", c.config.NodeName, err)
return err
}
nodeIPv4, nodeIPv6 := util.GetNodeInternalIP(*node)

cidrs := make([]string, 0, len(subnets)*2)
for _, subnet := range subnets {
if subnet.Spec.Vlan != "" || subnet.Spec.Vpc != util.DefaultVpc || !subnet.Status.IsReady() {
if (subnet.Spec.Vlan != "" && !subnet.Spec.LogicalGateway) || subnet.Spec.Vpc != util.DefaultVpc || !subnet.Status.IsReady() {
continue
}

for _, cidrBlock := range strings.Split(subnet.Spec.CIDRBlock, ",") {
if _, ipNet, err := net.ParseCIDR(cidrBlock); err != nil {
klog.Errorf("%s is not a valid cidr block", cidrBlock)
} else {
if nodeIPv4 != "" && util.CIDRContainIP(cidrBlock, nodeIPv4) {
continue
}
if nodeIPv6 != "" && util.CIDRContainIP(cidrBlock, nodeIPv6) {
continue
}
cidrs = append(cidrs, ipNet.String())
}
}
}

node, err := c.nodesLister.Get(c.config.NodeName)
if err != nil {
klog.Errorf("failed to get node %s %v", c.config.NodeName, err)
return err
}
gateway, ok := node.Annotations[util.GatewayAnnotation]
if !ok {
klog.Errorf("annotation for node %s ovn.kubernetes.io/gateway not exists", node.Name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *Controller) getSubnetsDistributedGateway(protocol string) ([]string, er
var result []string
for _, subnet := range subnets {
if subnet.DeletionTimestamp == nil &&
subnet.Spec.Vlan == "" &&
(subnet.Spec.Vlan == "" || subnet.Spec.LogicalGateway) &&
subnet.Spec.Vpc == util.DefaultVpc &&
subnet.Spec.CIDRBlock != "" &&
subnet.Spec.GatewayType == kubeovnv1.GWDistributedType &&
Expand Down

0 comments on commit ea0b77c

Please sign in to comment.