Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pkg/config/ovn/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"os"
"path/filepath"
"regexp"

"k8s.io/klog/v2"
"sigs.k8s.io/yaml"
Expand All @@ -16,6 +17,8 @@ const (
OVNGatewayInterface = "br-ex"
OVNExternalGatewayInterface = "br-ex1"
defaultMTU = 1500
OVNKubernetesV4MasqueradeIP = "169.254.169.2"
OVNKubernetesV6MasqueradeIP = "fd69::2"
)

type OVNKubernetesConfig struct {
Expand Down Expand Up @@ -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)
}
12 changes: 3 additions & 9 deletions pkg/mdns/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a dependency between the MDNS and OVN components, which is going to make it harder to make OVN pluggable. We can do this for now, but we need a plan to decouple these again in the future. What can we do to keep them loosely coupled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually doing some code preparation work in this PR to move ovnk related code in its own files under pkg/config/ovn. Before this PR, the ovnk interfaces and special IP address are hardcoded in mdns controller. For fully decoupling ovnk from mdns controller (assuming mdns will stay in microshift main), we would need an interface between microshift and plugins to exchange the mdns related information (this is where the binary/script method in pluggable enhancement would help).

"github.com/openshift/microshift/pkg/mdns/server"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -47,21 +47,14 @@ 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
// we have also verified that no duplicate mDNS answers will happen because of this,
// 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)
Expand All @@ -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)
}
}
Expand Down