diff --git a/dist/images/install.sh b/dist/images/install.sh index 348fcf68896..6c8c89c6bdf 100755 --- a/dist/images/install.sh +++ b/dist/images/install.sh @@ -613,6 +613,8 @@ spec: type: string u2oInterconnection: type: boolean + enableMulticastSnoop: + type: boolean u2oInterconnectionIP: type: string scope: Cluster diff --git a/kubeovn-helm/templates/kube-ovn-crd.yaml b/kubeovn-helm/templates/kube-ovn-crd.yaml index c0962068f59..f2f1b230a9b 100644 --- a/kubeovn-helm/templates/kube-ovn-crd.yaml +++ b/kubeovn-helm/templates/kube-ovn-crd.yaml @@ -436,6 +436,8 @@ spec: type: string u2oInterconnection: type: boolean + enableMulticastSnoop: + type: boolean u2oInterconnectionIP: type: string scope: Cluster diff --git a/pkg/apis/kubeovn/v1/types.go b/pkg/apis/kubeovn/v1/types.go index 3c5e2f2af89..ca5638333a4 100644 --- a/pkg/apis/kubeovn/v1/types.go +++ b/pkg/apis/kubeovn/v1/types.go @@ -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 diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index d628aa674e8..8b7a052376b 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -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) } @@ -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 } @@ -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 } diff --git a/pkg/ovs/ovn-nbctl-legacy.go b/pkg/ovs/ovn-nbctl-legacy.go index 518bea5a8b2..ac73eec463c 100644 --- a/pkg/ovs/ovn-nbctl-legacy.go +++ b/pkg/ovs/ovn-nbctl-legacy.go @@ -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] @@ -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) @@ -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 diff --git a/yamls/crd.yaml b/yamls/crd.yaml index d2cf3848030..77682fb28ec 100644 --- a/yamls/crd.yaml +++ b/yamls/crd.yaml @@ -225,6 +225,8 @@ spec: type: string u2oInterconnection: type: boolean + enableMulticastSnoop: + type: boolean u2oInterconnectionIP: type: string scope: Cluster