From c39b2ca5d73299e85783d7e7479f3f6761e3f7a3 Mon Sep 17 00:00:00 2001 From: Aswin Suryanarayanan Date: Mon, 21 Aug 2023 19:47:08 -0400 Subject: [PATCH] Support discovery of OVN-IC in OCP deployments Signed-off-by: Aswin Suryanarayanan --- .../submariner/route_agent_resources.go | 14 ++++++++++-- pkg/discovery/network/openshift4.go | 22 ++++++++++++++++++- pkg/discovery/network/ovnkubernetes.go | 3 ++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/controllers/submariner/route_agent_resources.go b/controllers/submariner/route_agent_resources.go index a6aeb1e06..23e589340 100644 --- a/controllers/submariner/route_agent_resources.go +++ b/controllers/submariner/route_agent_resources.go @@ -21,6 +21,7 @@ package submariner import ( "context" "strconv" + "strings" "github.com/go-logr/logr" "github.com/submariner-io/admiral/pkg/names" @@ -49,6 +50,15 @@ func newRouteAgentDaemonSet(cr *v1alpha1.Submariner, clusterNetwork *network.Clu "app": name, "component": "routeagent", } + ovnNBDBPath := network.DefaultOvnNBDB + + configurePath, ok := clusterNetwork.PluginSettings[network.OvnNBDB] + if ok { + parts := strings.Split(configurePath, ":") + if len(parts) == 2 && parts[0] == "unix" { + ovnNBDBPath = parts[1] + } + } maxUnavailable := intstr.FromString("100%") @@ -87,7 +97,7 @@ func newRouteAgentDaemonSet(cr *v1alpha1.Submariner, clusterNetwork *network.Clu Path: "/sys", }}}, {Name: "host-var-run-openvswitch-nbdb-sock", VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{ - Path: "/var/run/openvswitch/ovnnb_db.sock", + Path: ovnNBDBPath, }}}, }, Containers: []corev1.Container{ @@ -108,7 +118,7 @@ func newRouteAgentDaemonSet(cr *v1alpha1.Submariner, clusterNetwork *network.Clu {Name: "host-sys", MountPath: "/sys", ReadOnly: true}, {Name: "host-run-xtables-lock", MountPath: "/run/xtables.lock"}, {Name: "host-run-openvswitch-db-sock", MountPath: "/run/openvswitch/db.sock"}, - {Name: "host-var-run-openvswitch-nbdb-sock", MountPath: "/var/run/openvswitch/ovnnb_db.sock"}, + {Name: "host-var-run-openvswitch-nbdb-sock", MountPath: ovnNBDBPath}, }, Env: []corev1.EnvVar{ {Name: "SUBMARINER_NAMESPACE", Value: cr.Spec.Namespace}, diff --git a/pkg/discovery/network/openshift4.go b/pkg/discovery/network/openshift4.go index c2546b592..150b25a95 100644 --- a/pkg/discovery/network/openshift4.go +++ b/pkg/discovery/network/openshift4.go @@ -49,7 +49,27 @@ func discoverOpenShift4Network(ctx context.Context, client controllerClient.Clie return nil, errors.WithMessage(err, "error obtaining the default 'cluster' OpenShift4 Network config resource") } - return parseOS4Network(network) + clusterNetwork, err := parseOS4Network(network) + if err != nil { + return nil, err + } + + if clusterNetwork.NetworkPlugin == cni.OVNKubernetes { + ovnDBPod, err := FindPod(ctx, client, "name=ovnkube-db") + if err != nil { + return nil, err + } + + if ovnDBPod == nil { + // IC is enabled and Openshift uses zone per node and to connect to OVN DB using + // socket connection we need to use this path. + clusterNetwork.PluginSettings = map[string]string{ + OvnNBDB: "unix:/var/run/ovn-ic/ovnnb_db.sock", + } + } + } + + return clusterNetwork, err } func parseOS4Network(cr *unstructured.Unstructured) (*ClusterNetwork, error) { diff --git a/pkg/discovery/network/ovnkubernetes.go b/pkg/discovery/network/ovnkubernetes.go index dce5693f4..67ccf7826 100644 --- a/pkg/discovery/network/ovnkubernetes.go +++ b/pkg/discovery/network/ovnkubernetes.go @@ -34,6 +34,7 @@ const ( ovnKubeService = "ovnkube-db" OvnNBDB = "OVN_NBDB" OvnSBDB = "OVN_SBDB" + DefaultOvnNBDB = "/var/run/openvswitch/ovnnb_db.sock" OvnNBDBDefaultPort = 6641 OvnSBDBDefaultPort = 6642 ) @@ -109,7 +110,7 @@ func discoverOvnNodeClusterNetwork(ctx context.Context, client controllerClient. func createLocalClusterNetwork() *ClusterNetwork { return &ClusterNetwork{ PluginSettings: map[string]string{ - OvnNBDB: "unix:/var/run/openvswitch/ovnnb_db.sock", + OvnNBDB: "unix:" + DefaultOvnNBDB, }, } }