aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorKuralamudhan Ramakrishnan <kuralamudhan.ramakrishnan@intel.com>2020-08-09 21:38:57 -0700
committerKuralamudhan Ramakrishnan <kuralamudhan.ramakrishnan@intel.com>2020-09-17 17:10:02 -0700
commit69b6bceec76caea07f95ba5cc372205c16e0e11b (patch)
tree06cbf79c6b62e934e68ddd62b07c727313ed4c39 /cmd
parentc99d1522d6a52765cb8bb664149c705e33911f7d (diff)
adding gwipaddress features in network annotation
- check defautgateway is true only for one network - first network with defautgateway is only configured, rest is ignored - add node network and ovn4nfv0-* route info for eth0 interface Signed-off-by: Kuralamudhan Ramakrishnan <kuralamudhan.ramakrishnan@intel.com> Change-Id: I078dee22627b2fa92e34b6cc4fa2ec7c8cd58220
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ovn4nfvk8s-cni/app/helper_linux.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/cmd/ovn4nfvk8s-cni/app/helper_linux.go b/cmd/ovn4nfvk8s-cni/app/helper_linux.go
index cfcd4e9..21db529 100644
--- a/cmd/ovn4nfvk8s-cni/app/helper_linux.go
+++ b/cmd/ovn4nfvk8s-cni/app/helper_linux.go
@@ -8,12 +8,14 @@ import (
"os/exec"
"ovn4nfv-k8s-plugin/internal/pkg/config"
"ovn4nfv-k8s-plugin/internal/pkg/network"
+ "ovn4nfv-k8s-plugin/internal/pkg/ovn"
"strconv"
"strings"
"github.com/containernetworking/cni/pkg/types/current"
"github.com/containernetworking/plugins/pkg/ip"
"github.com/containernetworking/plugins/pkg/ns"
+ "github.com/prometheus/common/log"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
)
@@ -96,9 +98,19 @@ func CreateNodeOVSInternalPort(nodeintfipaddr, nodeintfmacaddr, node string) err
return nil
}
-func setupInterface(netns ns.NetNS, containerID, ifName, macAddress, ipAddress, gatewayIP, defaultGateway string, idx, mtu int) (*current.Interface, *current.Interface, error) {
+func setupInterface(netns ns.NetNS, containerID, ifName, macAddress, ipAddress, gatewayIP, defaultGateway string, idx, mtu int, isDefaultGW bool) (*current.Interface, *current.Interface, error) {
hostIface := &current.Interface{}
contIface := &current.Interface{}
+ var hostNet string
+
+ if defaultGateway == "false" && isDefaultGW == true && ifName == "eth0" {
+ var err error
+ hostNet, err = network.GetHostNetwork()
+ if err != nil {
+ log.Error(err, "Failed to get host network")
+ return nil, nil, fmt.Errorf("failed to get host network: %v", err)
+ }
+ }
var oldHostVethName string
err := netns.Do(func(hostNS ns.NetNS) error {
@@ -147,6 +159,15 @@ func setupInterface(netns ns.NetNS, containerID, ifName, macAddress, ipAddress,
return err
}
}
+
+ if defaultGateway == "false" && isDefaultGW == true && ifName == "eth0" {
+ stdout, stderr, err := ovn.RunIP("route", "add", hostNet, "via", gatewayIP)
+ if err != nil && !strings.Contains(stderr, "RTNETLINK answers: File exists") {
+ logrus.Errorf("Failed to ip route add stout %s, stderr %s, err %v", stdout, stderr, err)
+ return fmt.Errorf("Failed to ip route add stout %s, stderr %s, err %v", stdout, stderr, err)
+ }
+ }
+
oldHostVethName = hostVeth.Name
return nil
@@ -165,7 +186,7 @@ func setupInterface(netns ns.NetNS, containerID, ifName, macAddress, ipAddress,
}
// ConfigureInterface sets up the container interface
-var ConfigureInterface = func(containerNetns, containerID, ifName, namespace, podName, macAddress, ipAddress, gatewayIP, interfaceName, defaultGateway string, idx, mtu int) ([]*current.Interface, error) {
+var ConfigureInterface = func(containerNetns, containerID, ifName, namespace, podName, macAddress, ipAddress, gatewayIP, interfaceName, defaultGateway string, idx, mtu int, isDefaultGW bool) ([]*current.Interface, error) {
netns, err := ns.GetNS(containerNetns)
if err != nil {
return nil, fmt.Errorf("failed to open netns %q: %v", containerNetns, err)
@@ -178,9 +199,8 @@ var ConfigureInterface = func(containerNetns, containerID, ifName, namespace, po
} else {
ifaceID = fmt.Sprintf("%s_%s", namespace, podName)
interfaceName = ifName
- defaultGateway = "true"
}
- hostIface, contIface, err := setupInterface(netns, containerID, interfaceName, macAddress, ipAddress, gatewayIP, defaultGateway, idx, mtu)
+ hostIface, contIface, err := setupInterface(netns, containerID, interfaceName, macAddress, ipAddress, gatewayIP, defaultGateway, idx, mtu, isDefaultGW)
if err != nil {
return nil, err
}