diff --git a/pkg/config/ovn/ovn.go b/pkg/config/ovn/ovn.go index 897a6554c0..fff4384ffe 100644 --- a/pkg/config/ovn/ovn.go +++ b/pkg/config/ovn/ovn.go @@ -6,6 +6,7 @@ import ( "net" "os" "path/filepath" + "regexp" "k8s.io/klog/v2" "sigs.k8s.io/yaml" @@ -16,6 +17,8 @@ const ( OVNGatewayInterface = "br-ex" OVNExternalGatewayInterface = "br-ex1" defaultMTU = 1500 + OVNKubernetesV4MasqueradeIP = "169.254.169.2" + OVNKubernetesV6MasqueradeIP = "fd69::2" ) type OVNKubernetesConfig struct { @@ -158,3 +161,25 @@ func GetOVNGatewayIP() (string, error) { } return "", fmt.Errorf("failed to get ovn gateway IP address") } + +func ExcludeOVNKubernetesMasqueradeIPs(addrs []net.Addr) []net.Addr { + var netAddrs []net.Addr + for _, a := range addrs { + ipNet, _, _ := net.ParseCIDR(a.String()) + if ipNet.String() != OVNKubernetesV4MasqueradeIP && ipNet.String() != OVNKubernetesV6MasqueradeIP { + netAddrs = append(netAddrs, a) + } + } + return netAddrs +} + +func IsOVNKubernetesInternalInterface(name string) bool { + excludedInterfacesRegexp := regexp.MustCompile( + "^[A-Fa-f0-9]{15}|" + // OVN pod interfaces + "ovn.*|" + // OVN ovn-k8s-mp0 and similar interfaces + "br-int|" + // OVN integration bridge + "veth.*|cni.*|" + // Interfaces used in bridge-cni or flannel + "ovs-system$") // Internal OVS interface + + return excludedInterfacesRegexp.MatchString(name) +} diff --git a/pkg/mdns/controller.go b/pkg/mdns/controller.go index cda42381fc..7ff7e62b9b 100644 --- a/pkg/mdns/controller.go +++ b/pkg/mdns/controller.go @@ -3,11 +3,11 @@ package mdns import ( "context" "net" - "regexp" "strings" "sync" "github.com/openshift/microshift/pkg/config" + "github.com/openshift/microshift/pkg/config/ovn" "github.com/openshift/microshift/pkg/mdns/server" "k8s.io/klog/v2" ) @@ -47,13 +47,6 @@ func (c *MicroShiftmDNSController) Run(ctx context.Context, ready chan<- struct{ ifs, _ := net.Interfaces() - excludedInterfacesRegexp := regexp.MustCompile( - "^[A-Fa-f0-9]{15}|" + // OVN pod interfaces - "ovn.*|" + // OVN ovn-k8s-mp0 and similar interfaces - "br-int|" + // OVN integration bridge - "veth.*|cni.*|" + // Interfaces used in bridge-cni or flannel - "ovs-system$") // Internal OVS interface - // NOTE: this will listen on both br-ex and the physical interface attached to it // i.e. eth0 . We don't believe it's worth going into the complexities (and coupling) // of talking to OpenvSwitch to discover the physical interface(s) on br-ex. And @@ -61,7 +54,7 @@ func (c *MicroShiftmDNSController) Run(ctx context.Context, ready chan<- struct{ // if those were to happend it would be harmless. for n := range ifs { name := ifs[n].Name - if excludedInterfacesRegexp.MatchString(name) { + if ovn.IsOVNKubernetesInternalInterface(name) { continue } klog.Infof("mDNS: Starting server on interface %q, NodeIP %q, NodeName %q", name, c.NodeIP, c.NodeName) @@ -74,6 +67,7 @@ func (c *MicroShiftmDNSController) Run(ctx context.Context, ready chan<- struct{ for n := range ifs { addrs, _ := ifs[n].Addrs() if ipInAddrs(c.NodeIP, addrs) { + addrs = ovn.ExcludeOVNKubernetesMasqueradeIPs(addrs) ips = addrsToStrings(addrs) } }