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 25, 2021
1 parent ef9dbc5 commit c57c6db
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 @@ -182,7 +182,8 @@ func (c *Controller) addEgressConfig(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 Down Expand Up @@ -211,7 +212,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 @@ -231,24 +233,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 c57c6db

Please sign in to comment.