Skip to content

Commit

Permalink
add multicast snoop for release-1.9 (#3192)
Browse files Browse the repository at this point in the history
  • Loading branch information
changluyi committed Sep 11, 2023
1 parent b2781c6 commit b925c73
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ spec:
type: string
u2oInterconnection:
type: boolean
enableMulticastSnoop:
type: boolean
u2oInterconnectionIP:
type: string
scope: Cluster
Expand Down
2 changes: 2 additions & 0 deletions kubeovn-helm/templates/kube-ovn-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ spec:
type: string
u2oInterconnection:
type: boolean
enableMulticastSnoop:
type: boolean
u2oInterconnectionIP:
type: string
scope: Cluster
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type SubnetSpec struct {
DisableInterConnection bool `json:"disableInterConnection,omitempty"`
U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
U2OInterconnectionIP string `json:"u2oInterconnectionIP,omitempty"`
EnableMulicastSnoop bool `json:"enableMulticastSnoop,omitempty"`
}

// ConditionType encodes information on the condition
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (c *Controller) enqueueUpdateSubnet(old, new interface{}) {
oldSubnet.Spec.Vlan != newSubnet.Spec.Vlan ||
oldSubnet.Spec.U2OInterconnection != newSubnet.Spec.U2OInterconnection ||
(newSubnet.Spec.U2OInterconnection && newSubnet.Spec.U2OInterconnectionIP != "" &&
oldSubnet.Spec.U2OInterconnectionIP != newSubnet.Spec.U2OInterconnectionIP) {
oldSubnet.Spec.U2OInterconnectionIP != newSubnet.Spec.U2OInterconnectionIP) ||
oldSubnet.Spec.EnableMulicastSnoop != newSubnet.Spec.EnableMulicastSnoop {
klog.V(3).Infof("enqueue update subnet %s", key)
c.addOrUpdateSubnetQueue.Add(key)
}
Expand Down Expand Up @@ -602,7 +603,7 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
if !exist {
subnet.Status.EnsureStandardConditions()
// If multiple namespace use same ls name, only first one will success
if err := c.ovnLegacyClient.CreateLogicalSwitch(subnet.Name, vpc.Status.Router, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, needRouter); err != nil {
if err := c.ovnLegacyClient.CreateLogicalSwitch(subnet.Name, vpc.Status.Router, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, needRouter, subnet.Spec.EnableMulicastSnoop); err != nil {
c.patchSubnetStatus(subnet, "CreateLogicalSwitchFailed", err.Error())
return err
}
Expand All @@ -619,7 +620,7 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
if subnet.Status.U2OInterconnectionIP != "" && subnet.Spec.U2OInterconnection {
gateway = subnet.Status.U2OInterconnectionIP
}
if err := c.ovnLegacyClient.SetLogicalSwitchConfig(subnet.Name, vpc.Status.Router, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, gateway, subnet.Spec.ExcludeIps, needRouter); err != nil {
if err := c.ovnLegacyClient.SetLogicalSwitchConfig(subnet.Name, vpc.Status.Router, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, gateway, subnet.Spec.ExcludeIps, needRouter, subnet.Spec.EnableMulicastSnoop); err != nil {
c.patchSubnetStatus(subnet, "SetLogicalSwitchConfigFailed", err.Error())
return err
}
Expand Down
22 changes: 18 additions & 4 deletions pkg/ovs/ovn-nbctl-legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (c LegacyClient) ListPodLogicalSwitchPorts(pod, namespace string) ([]string
return result, nil
}

func (c LegacyClient) SetLogicalSwitchConfig(ls, lr, protocol, subnet, gateway string, excludeIps []string, needRouter bool) error {
func (c LegacyClient) SetLogicalSwitchConfig(ls, lr, protocol, subnet, gateway string, excludeIps []string, needRouter, needMulticastSnoop bool) error {
var err error
cidrBlocks := strings.Split(subnet, ",")
mask := strings.Split(cidrBlocks[0], "/")[1]
Expand Down Expand Up @@ -364,6 +364,15 @@ func (c LegacyClient) SetLogicalSwitchConfig(ls, lr, protocol, subnet, gateway s
}
cmd = append(cmd, []string{"--",
"set", "logical_switch", ls, fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName)}...)

if needMulticastSnoop {
cmd = append(cmd, []string{"--",
"set", "logical_switch", ls, "other_config:mcast_snoop=true", "other_config:mcast_querier=false"}...)
} else {
cmd = append(cmd, []string{"--",
"remove", "logical_switch", ls, "other_config", "mcast_snoop=true", "mcast_querier=false"}...)
}

_, err = c.ovnNbCommand(cmd...)
if err != nil {
klog.Errorf("set switch config for %s failed: %v", ls, err)
Expand All @@ -373,10 +382,15 @@ func (c LegacyClient) SetLogicalSwitchConfig(ls, lr, protocol, subnet, gateway s
}

// CreateLogicalSwitch create logical switch in ovn, connect it to router and apply tcp/udp lb rules
func (c LegacyClient) CreateLogicalSwitch(ls, lr, subnet, gateway string, needRouter bool) error {
_, err := c.ovnNbCommand(MayExist, "ls-add", ls, "--",
"set", "logical_switch", ls, fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName))
func (c LegacyClient) CreateLogicalSwitch(ls, lr, subnet, gateway string, needRouter, needMulticastSnoop bool) error {
cmd := []string{MayExist, "ls-add", ls, "--", "set", "logical_switch", ls, fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName)}

if needMulticastSnoop {
cmd = append(cmd, []string{"--",
"set", "logical_switch", ls, "other_config:mcast_snoop=true", "other_config:mcast_querier=false"}...)
}

_, err := c.ovnNbCommand(cmd...)
if err != nil {
klog.Errorf("create switch %s failed: %v", ls, err)
return err
Expand Down
2 changes: 2 additions & 0 deletions yamls/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ spec:
type: string
u2oInterconnection:
type: boolean
enableMulticastSnoop:
type: boolean
u2oInterconnectionIP:
type: string
scope: Cluster
Expand Down

0 comments on commit b925c73

Please sign in to comment.