Skip to content

Commit

Permalink
fix ipset on pod creation/deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Aug 23, 2021
1 parent b2081ed commit 13b2080
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions pkg/daemon/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ func (c *Controller) setPolicyRouting() error {
}

func (c *Controller) addEgressConfig(subnet *kubeovnv1.Subnet, ip string) error {
if subnet.Spec.GatewayType != kubeovnv1.GWDistributedType ||
if subnet.Spec.Vlan != "" ||
subnet.Spec.GatewayType != kubeovnv1.GWDistributedType ||
subnet.Spec.Vpc != util.DefaultVpc {
return nil
}
Expand Down Expand Up @@ -205,7 +206,8 @@ func (c *Controller) removeEgressConfig(subnet, ip string) error {
return err
}

if podSubnet.Spec.GatewayType != kubeovnv1.GWDistributedType ||
if podSubnet.Spec.Vlan != "" ||
podSubnet.Spec.GatewayType != kubeovnv1.GWDistributedType ||
podSubnet.Spec.Vpc != util.DefaultVpc {
return nil
}
Expand All @@ -225,24 +227,32 @@ func (c *Controller) removeEgressConfig(subnet, ip string) error {

func (c *Controller) addIPSetMembers(setID, protocol string, ips []string) {
if protocol == kubeovnv1.ProtocolDual {
c.ipset[kubeovnv1.ProtocolIPv4].AddMembers(setID, []string{ips[0]})
c.ipset[kubeovnv1.ProtocolIPv6].AddMembers(setID, []string{ips[1]})
c.ipset[kubeovnv1.ProtocolIPv4].ApplyUpdates()
c.ipset[kubeovnv1.ProtocolIPv6].ApplyUpdates()
} else {
c.ipset[protocol].AddMembers(setID, []string{ips[0]})
if c.ipset[kubeovnv1.ProtocolIPv4] != nil {
c.ipset[kubeovnv1.ProtocolIPv4].AddMembers(setID, ips[:1])
c.ipset[kubeovnv1.ProtocolIPv4].ApplyUpdates()
}
if c.ipset[kubeovnv1.ProtocolIPv6] != nil {
c.ipset[kubeovnv1.ProtocolIPv6].AddMembers(setID, ips[1:])
c.ipset[kubeovnv1.ProtocolIPv6].ApplyUpdates()
}
} else if c.ipset[protocol] != nil {
c.ipset[protocol].AddMembers(setID, ips[:1])
c.ipset[protocol].ApplyUpdates()
}
}

func (c *Controller) removeIPSetMembers(setID, protocol string, ips []string) {
if protocol == kubeovnv1.ProtocolDual {
c.ipset[kubeovnv1.ProtocolIPv4].RemoveMembers(setID, []string{ips[0]})
c.ipset[kubeovnv1.ProtocolIPv6].RemoveMembers(setID, []string{ips[1]})
c.ipset[kubeovnv1.ProtocolIPv4].ApplyUpdates()
c.ipset[kubeovnv1.ProtocolIPv6].ApplyUpdates()
} else {
c.ipset[protocol].RemoveMembers(setID, []string{ips[0]})
if c.ipset[kubeovnv1.ProtocolIPv4] != nil {
c.ipset[kubeovnv1.ProtocolIPv4].RemoveMembers(setID, ips[:1])
c.ipset[kubeovnv1.ProtocolIPv4].ApplyUpdates()
}
if c.ipset[kubeovnv1.ProtocolIPv6] != nil {
c.ipset[kubeovnv1.ProtocolIPv6].RemoveMembers(setID, ips[1:])
c.ipset[kubeovnv1.ProtocolIPv6].ApplyUpdates()
}
} else if c.ipset[protocol] != nil {
c.ipset[protocol].RemoveMembers(setID, ips[:1])
c.ipset[protocol].ApplyUpdates()
}
}
Expand Down

0 comments on commit 13b2080

Please sign in to comment.