diff options
Diffstat (limited to 'internal/pkg/ovn/pods.go')
-rw-r--r-- | internal/pkg/ovn/pods.go | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/internal/pkg/ovn/pods.go b/internal/pkg/ovn/pods.go index cc3d459..fcd258e 100644 --- a/internal/pkg/ovn/pods.go +++ b/internal/pkg/ovn/pods.go @@ -80,7 +80,7 @@ func (oc *Controller) deleteLogicalPort(pod *kapi.Pod) { return } -func (oc *Controller) addLogicalPortWithSwitch(pod *kapi.Pod, logicalSwitch, ipAddress, macAddress, interfaceName string) (annotation string) { +func (oc *Controller) addLogicalPortWithSwitch(pod *kapi.Pod, logicalSwitch, ipAddress, macAddress, interfaceName, netType string) (annotation string) { var out, stderr string var err error var isStaticIP bool @@ -112,7 +112,11 @@ func (oc *Controller) addLogicalPortWithSwitch(pod *kapi.Pod, logicalSwitch, ipA out, stderr, err = util.RunOVNNbctlUnix("--may-exist", "lsp-add", logicalSwitch, portName, "--", "lsp-set-addresses", portName, fmt.Sprintf("%s %s", macAddress, ipAddress), "--", "--if-exists", - "clear", "logical_switch_port", portName, "dynamic_addresses") + "clear", "logical_switch_port", portName, "dynamic_addresses", "--", "set", + "logical_switch_port", portName, + "external-ids:namespace="+pod.Namespace, + "external-ids:logical_switch="+logicalSwitch, + "external-ids:pod=true") if err != nil { logrus.Errorf("Failed to add logical port to switch "+ "stdout: %q, stderr: %q (%v)", @@ -136,11 +140,6 @@ func (oc *Controller) addLogicalPortWithSwitch(pod *kapi.Pod, logicalSwitch, ipA } } oc.logicalPortCache[portName] = logicalSwitch - gatewayIP, mask, err := oc.getGatewayFromSwitch(logicalSwitch) - if err != nil { - logrus.Errorf("Error obtaining gateway address for switch %s: %s", logicalSwitch, err) - return - } count := 30 for count > 0 { @@ -178,7 +177,18 @@ func (oc *Controller) addLogicalPortWithSwitch(pod *kapi.Pod, logicalSwitch, ipA logrus.Errorf("Error while obtaining addresses for %s", portName) return } - annotation = fmt.Sprintf(`{\"ip_address\":\"%s/%s\", \"mac_address\":\"%s\", \"gateway_ip\": \"%s\"}`, addresses[1], mask, addresses[0], gatewayIP) + + if netType == "virtual" { + gatewayIP, mask, err := oc.getGatewayFromSwitch(logicalSwitch) + if err != nil { + logrus.Errorf("Error obtaining gateway address for switch %s: %s", logicalSwitch, err) + return + } + annotation = fmt.Sprintf(`{\"ip_address\":\"%s/%s\", \"mac_address\":\"%s\", \"gateway_ip\": \"%s\"}`, addresses[1], mask, addresses[0], gatewayIP) + } else { + annotation = fmt.Sprintf(`{\"ip_address\":\"%s\", \"mac_address\":\"%s\", \"gateway_ip\": \"%s\"}`, addresses[1], addresses[0], "") + } + return annotation } @@ -203,7 +213,7 @@ func findLogicalSwitch(name string) bool { func (oc *Controller) addLogicalPort(pod *kapi.Pod) { var logicalSwitch string - var ipAddress, macAddress, interfaceName, defaultGateway string + var ipAddress, macAddress, interfaceName, defaultGateway, netType string annotation := pod.Annotations["ovnNetwork"] @@ -217,10 +227,15 @@ func (oc *Controller) addLogicalPort(pod *kapi.Pod) { ovnString = "[" for _, net := range ovnNetObjs { logicalSwitch = net["name"].(string) + if !findLogicalSwitch(logicalSwitch) { + logrus.Errorf("Logical Switch not found") + return + } if _, ok := net["interface"]; ok { interfaceName = net["interface"].(string) } else { - interfaceName = "" + logrus.Errorf("Interface name must be provided") + return } if _, ok := net["ipAddress"]; ok { ipAddress = net["ipAddress"].(string) @@ -237,14 +252,24 @@ func (oc *Controller) addLogicalPort(pod *kapi.Pod) { } else { defaultGateway = "false" } - if !findLogicalSwitch(logicalSwitch) { + if _, ok := net["netType"]; ok { + netType = net["netType"].(string) + } else { + netType = "virtual" + } + if netType != "provider" && netType != "virtual" { + logrus.Errorf("netType is not supported") return } - if interfaceName == "" { - logrus.Errorf("Interface name must be provided") + if netType == "provider" && ipAddress == "" { + logrus.Errorf("ipAddress must be provided for netType Provider") + return + } + if netType == "provider" && defaultGateway == "true" { + logrus.Errorf("defaultGateway not supported for provider network - Use ovnNetworkRoutes to add routes") return } - outStr = oc.addLogicalPortWithSwitch(pod, logicalSwitch, ipAddress, macAddress, interfaceName) + outStr = oc.addLogicalPortWithSwitch(pod, logicalSwitch, ipAddress, macAddress, interfaceName, netType) if outStr == "" { return } |