From 0d3f441cbd415560500ceeab6e26f6e28696515a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A5=96=E5=BB=BA?= Date: Sat, 8 Jul 2023 11:12:05 +0800 Subject: [PATCH] replace ovn legacy client with libovsdb --- cmd/controller/controller.go | 24 - .../controller_health_check.go | 13 - dist/images/Dockerfile.base | 8 - dist/images/start-controller.sh | 23 - dist/images/start-webhook.sh | 4 +- mocks/pkg/ovs/interface.go | 74 ++- pkg/controller/controller.go | 2 +- pkg/controller/external-gw.go | 1 - pkg/controller/gc.go | 18 +- pkg/controller/ovn_fip.go | 21 +- pkg/controller/ovn_snat.go | 9 +- pkg/controller/pod.go | 27 +- pkg/controller/subnet.go | 4 +- pkg/controller/vpc.go | 6 +- pkg/ovs/interface.go | 4 +- pkg/ovs/ovn-nb-dhcp_options.go | 8 +- pkg/ovs/ovn-nb-dhcp_options_test.go | 12 +- pkg/ovs/ovn-nb-nat.go | 34 +- pkg/ovs/ovn-nb-nat_test.go | 20 +- pkg/ovs/ovn-nbctl-legacy.go | 593 ------------------ pkg/ovs/ovn-sbctl.go | 15 + pkg/ovs/ovn.go | 7 +- 22 files changed, 187 insertions(+), 740 deletions(-) delete mode 100644 pkg/ovs/ovn-nbctl-legacy.go diff --git a/cmd/controller/controller.go b/cmd/controller/controller.go index 1c81323f1812..0c98312addfa 100644 --- a/cmd/controller/controller.go +++ b/cmd/controller/controller.go @@ -22,7 +22,6 @@ import ( kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" "github.com/kubeovn/kube-ovn/pkg/controller" - "github.com/kubeovn/kube-ovn/pkg/ovs" "github.com/kubeovn/kube-ovn/pkg/util" "github.com/kubeovn/kube-ovn/versions" ) @@ -54,7 +53,6 @@ func CmdMain() { util.LogFatalAndExit(err, "failed to check permission") } - go loopOvnNbctlDaemon(config) go func() { mux := http.NewServeMux() if config.EnableMetrics { @@ -135,28 +133,6 @@ func CmdMain() { }) } -func loopOvnNbctlDaemon(config *controller.Configuration) { - for { - daemonSocket := os.Getenv("OVN_NB_DAEMON") - time.Sleep(5 * time.Second) - - if _, err := os.Stat(daemonSocket); os.IsNotExist(err) || daemonSocket == "" { - if err := ovs.StartOvnNbctlDaemon(config.OvnNbAddr); err != nil { - klog.Errorf("failed to start ovn-nbctl daemon %v", err) - } - } - - // ovn-nbctl daemon may hang and cannot process further request. - // In case of that, we need to start a new daemon. - if err := ovs.CheckAlive(); err != nil { - klog.Warningf("ovn-nbctl daemon doesn't return, start a new daemon") - if err := ovs.StartOvnNbctlDaemon(config.OvnNbAddr); err != nil { - klog.Errorf("failed to start ovn-nbctl daemon %v", err) - } - } - } -} - func checkPermission(config *controller.Configuration) error { resources := []string{"vpcs", "subnets", "ips", "vlans", "vpc-nat-gateways"} for _, res := range resources { diff --git a/cmd/controller_health_check/controller_health_check.go b/cmd/controller_health_check/controller_health_check.go index a477c01fadcb..0c38a82d4896 100644 --- a/cmd/controller_health_check/controller_health_check.go +++ b/cmd/controller_health_check/controller_health_check.go @@ -8,23 +8,10 @@ import ( "time" kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" - "github.com/kubeovn/kube-ovn/pkg/ovs" "github.com/kubeovn/kube-ovn/pkg/util" ) func CmdMain() { - content, err := os.ReadFile("/var/run/ovn/ovn-nbctl.pid") - if err != nil { - util.LogFatalAndExit(err, "failed to get ovn-nbctl daemon pid") - } - daemonPid := strings.TrimSuffix(string(content), "\n") - if err := os.Setenv("OVN_NB_DAEMON", fmt.Sprintf("/var/run/ovn/ovn-nbctl.%s.ctl", daemonPid)); err != nil { - util.LogFatalAndExit(err, "failed to set env OVN_NB_DAEMON") - } - if err := ovs.CheckAlive(); err != nil { - os.Exit(1) - } - addr := "127.0.0.1:10660" if os.Getenv("ENABLE_BIND_LOCAL_IP") == "true" { podIpsEnv := os.Getenv("POD_IPS") diff --git a/dist/images/Dockerfile.base b/dist/images/Dockerfile.base index 0aa9a8daf6d7..39593151ded7 100644 --- a/dist/images/Dockerfile.base +++ b/dist/images/Dockerfile.base @@ -101,12 +101,6 @@ RUN curl -sSf -L --retry 3 -o /usr/local/bin/bfdd-control https://github.com/bob curl -sSf -L --retry 3 -o /usr/local/bin/bfdd-beacon https://github.com/bobz965/bfd-binary-for-kube-ovn-cni/releases/download/${BFDD_VERSION}/bfdd-beacon && \ chmod +x /usr/local/bin/bfdd-control /usr/local/bin/bfdd-beacon -ENV DUMB_INIT_VERSION="1.2.5" -RUN dumb_init_arch="x86_64"; \ - if [ "$ARCH" = "arm64" ]; then dumb_init_arch="aarch64"; fi; \ - curl -sSf -L --retry 5 -o /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_${dumb_init_arch} && \ - chmod +x /usr/bin/dumb-init - RUN --mount=type=bind,target=/packages,from=ovs-builder,source=/packages \ dpkg -i /packages/openvswitch-*.deb /packages/python3-openvswitch*.deb && \ dpkg -i --ignore-depends=openvswitch-switch,openvswitch-common /packages/ovn-*.deb && \ @@ -119,5 +113,3 @@ RUN --mount=type=bind,target=/packages,from=ovs-builder,source=/packages \ rm -rf /var/lib/apt/lists/* && \ dpkg -i --ignore-depends=openvswitch-switch,openvswitch-common /packages/*.ddeb; \ fi - -ENTRYPOINT ["/usr/bin/dumb-init", "--"] diff --git a/dist/images/start-controller.sh b/dist/images/start-controller.sh index 808f07edf96e..6457059f55d8 100755 --- a/dist/images/start-controller.sh +++ b/dist/images/start-controller.sh @@ -32,29 +32,6 @@ function gen_conn_str { nb_addr="$(gen_conn_str 6641)" sb_addr="$(gen_conn_str 6642)" -for ((i=0; i<3; i++)); do - if [[ "$ENABLE_SSL" == "false" ]]; then - OVN_NB_DAEMON=$(ovn-nbctl --db="$nb_addr" --pidfile --detach --overwrite-pidfile) - else - OVN_NB_DAEMON=$(ovn-nbctl -p /var/run/tls/key -c /var/run/tls/cert -C /var/run/tls/cacert --db="$nb_addr" --pidfile --detach --overwrite-pidfile) - fi - if echo -n "${OVN_NB_DAEMON}" | grep -qE '^/var/run/ovn/ovn-nbctl\.[0-9]+\.ctl$'; then - export OVN_NB_DAEMON - break - fi - if [ $(echo ${OVN_NB_DAEMON} | wc -c) -gt 64 ]; then - OVN_NB_DAEMON="$(echo ${OVN_NB_DAEMON} | cut -c1-64)..." - fi - echo "invalid ovn-nbctl daemon socket: \"${OVN_NB_DAEMON}\"" - unset OVN_NB_DAEMON - pkill -f ovn-nbctl -done - -if [ -z "${OVN_NB_DAEMON}" ]; then - echo "failed to start ovn-nbctl daemon" - exit 1 -fi - exec ./kube-ovn-controller --ovn-nb-addr="$nb_addr" \ --ovn-sb-addr="$sb_addr" \ $@ diff --git a/dist/images/start-webhook.sh b/dist/images/start-webhook.sh index fad6e86e2fc1..4257e654089f 100755 --- a/dist/images/start-webhook.sh +++ b/dist/images/start-webhook.sh @@ -1,4 +1,2 @@ #!/usr/bin/env bash -set -euo pipefail -export OVN_NB_DAEMON=$(ovn-nbctl --db=tcp:${OVN_NB_SERVICE_HOST}:${OVN_NB_SERVICE_PORT} --pidfile --detach) -exec ./kube-ovn-webhook --ovn-nb-host=${OVN_NB_SERVICE_HOST} --ovn-nb-port=${OVN_NB_SERVICE_PORT} $@ \ No newline at end of file +exec ./kube-ovn-webhook diff --git a/mocks/pkg/ovs/interface.go b/mocks/pkg/ovs/interface.go index 3eb9448326e3..775fd9c46359 100644 --- a/mocks/pkg/ovs/interface.go +++ b/mocks/pkg/ovs/interface.go @@ -1726,6 +1726,20 @@ func (m *MockNAT) EXPECT() *MockNATMockRecorder { return m.recorder } +// AddNat mocks base method. +func (m *MockNAT) AddNat(lrName, natType, externalIP, logicalIP, logicalMac, port string, options map[string]string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddNat", lrName, natType, externalIP, logicalIP, logicalMac, port, options) + ret0, _ := ret[0].(error) + return ret0 +} + +// AddNat indicates an expected call of AddNat. +func (mr *MockNATMockRecorder) AddNat(lrName, natType, externalIP, logicalIP, logicalMac, port, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNat", reflect.TypeOf((*MockNAT)(nil).AddNat), lrName, natType, externalIP, logicalIP, logicalMac, port, options) +} + // DeleteNat mocks base method. func (m *MockNAT) DeleteNat(lrName, natType, externalIP, logicalIP string) error { m.ctrl.T.Helper() @@ -1754,6 +1768,21 @@ func (mr *MockNATMockRecorder) DeleteNats(lrName, natType, logicalIP interface{} return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteNats", reflect.TypeOf((*MockNAT)(nil).DeleteNats), lrName, natType, logicalIP) } +// GetNATByUUID mocks base method. +func (m *MockNAT) GetNATByUUID(uuid string) (*ovnnb.NAT, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetNATByUUID", uuid) + ret0, _ := ret[0].(*ovnnb.NAT) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetNATByUUID indicates an expected call of GetNATByUUID. +func (mr *MockNATMockRecorder) GetNATByUUID(uuid interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNATByUUID", reflect.TypeOf((*MockNAT)(nil).GetNATByUUID), uuid) +} + // ListNats mocks base method. func (m *MockNAT) ListNats(lrName, natType, logicalIP string, externalIDs map[string]string) ([]*ovnnb.NAT, error) { m.ctrl.T.Helper() @@ -1883,18 +1912,18 @@ func (mr *MockDHCPOptionsMockRecorder) ListDHCPOptions(needVendorFilter, externa } // UpdateDHCPOptions mocks base method. -func (m *MockDHCPOptions) UpdateDHCPOptions(subnet *v1.Subnet) (*ovs.DHCPOptionsUUIDs, error) { +func (m *MockDHCPOptions) UpdateDHCPOptions(subnet *v1.Subnet, mtu int) (*ovs.DHCPOptionsUUIDs, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateDHCPOptions", subnet) + ret := m.ctrl.Call(m, "UpdateDHCPOptions", subnet, mtu) ret0, _ := ret[0].(*ovs.DHCPOptionsUUIDs) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateDHCPOptions indicates an expected call of UpdateDHCPOptions. -func (mr *MockDHCPOptionsMockRecorder) UpdateDHCPOptions(subnet interface{}) *gomock.Call { +func (mr *MockDHCPOptionsMockRecorder) UpdateDHCPOptions(subnet, mtu interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDHCPOptions", reflect.TypeOf((*MockDHCPOptions)(nil).UpdateDHCPOptions), subnet) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDHCPOptions", reflect.TypeOf((*MockDHCPOptions)(nil).UpdateDHCPOptions), subnet, mtu) } // MockOvnClient is a mock of OvnClient interface. @@ -1953,6 +1982,20 @@ func (mr *MockOvnClientMockRecorder) AddLogicalRouterStaticRoute(lrName, routeTa return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddLogicalRouterStaticRoute", reflect.TypeOf((*MockOvnClient)(nil).AddLogicalRouterStaticRoute), varargs...) } +// AddNat mocks base method. +func (m *MockOvnClient) AddNat(lrName, natType, externalIP, logicalIP, logicalMac, port string, options map[string]string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddNat", lrName, natType, externalIP, logicalIP, logicalMac, port, options) + ret0, _ := ret[0].(error) + return ret0 +} + +// AddNat indicates an expected call of AddNat. +func (mr *MockOvnClientMockRecorder) AddNat(lrName, natType, externalIP, logicalIP, logicalMac, port, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNat", reflect.TypeOf((*MockOvnClient)(nil).AddNat), lrName, natType, externalIP, logicalIP, logicalMac, port, options) +} + // AddressSetUpdateAddress mocks base method. func (m *MockOvnClient) AddressSetUpdateAddress(asName string, addresses ...string) error { m.ctrl.T.Helper() @@ -2727,6 +2770,21 @@ func (mr *MockOvnClientMockRecorder) GetLogicalSwitchPort(lspName, ignoreNotFoun return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLogicalSwitchPort", reflect.TypeOf((*MockOvnClient)(nil).GetLogicalSwitchPort), lspName, ignoreNotFound) } +// GetNATByUUID mocks base method. +func (m *MockOvnClient) GetNATByUUID(uuid string) (*ovnnb.NAT, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetNATByUUID", uuid) + ret0, _ := ret[0].(*ovnnb.NAT) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetNATByUUID indicates an expected call of GetNATByUUID. +func (mr *MockOvnClientMockRecorder) GetNATByUUID(uuid interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNATByUUID", reflect.TypeOf((*MockOvnClient)(nil).GetNATByUUID), uuid) +} + // GetNbGlobal mocks base method. func (m *MockOvnClient) GetNbGlobal() (*ovnnb.NBGlobal, error) { m.ctrl.T.Helper() @@ -3440,18 +3498,18 @@ func (mr *MockOvnClientMockRecorder) Transact(method, operations interface{}) *g } // UpdateDHCPOptions mocks base method. -func (m *MockOvnClient) UpdateDHCPOptions(subnet *v1.Subnet) (*ovs.DHCPOptionsUUIDs, error) { +func (m *MockOvnClient) UpdateDHCPOptions(subnet *v1.Subnet, mtu int) (*ovs.DHCPOptionsUUIDs, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateDHCPOptions", subnet) + ret := m.ctrl.Call(m, "UpdateDHCPOptions", subnet, mtu) ret0, _ := ret[0].(*ovs.DHCPOptionsUUIDs) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateDHCPOptions indicates an expected call of UpdateDHCPOptions. -func (mr *MockOvnClientMockRecorder) UpdateDHCPOptions(subnet interface{}) *gomock.Call { +func (mr *MockOvnClientMockRecorder) UpdateDHCPOptions(subnet, mtu interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDHCPOptions", reflect.TypeOf((*MockOvnClient)(nil).UpdateDHCPOptions), subnet) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDHCPOptions", reflect.TypeOf((*MockOvnClient)(nil).UpdateDHCPOptions), subnet, mtu) } // UpdateDnatAndSnat mocks base method. diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 5b4b18f5bc50..10ecac280033 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -310,7 +310,7 @@ func Run(ctx context.Context, config *Configuration) { vpcs: &sync.Map{}, podSubnetMap: &sync.Map{}, deletingPodObjMap: &sync.Map{}, - ovnLegacyClient: ovs.NewLegacyClient(config.OvnNbAddr, config.OvnTimeout, config.OvnSbAddr, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.ClusterTcpSessionLoadBalancer, config.ClusterUdpSessionLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR), + ovnLegacyClient: ovs.NewLegacyClient(config.OvnTimeout, config.OvnSbAddr, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.ClusterTcpSessionLoadBalancer, config.ClusterUdpSessionLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR), ipam: ovnipam.NewIPAM(), namedPort: NewNamedPort(), diff --git a/pkg/controller/external-gw.go b/pkg/controller/external-gw.go index fc6afe3da875..4656240e35f7 100644 --- a/pkg/controller/external-gw.go +++ b/pkg/controller/external-gw.go @@ -65,7 +65,6 @@ func (c *Controller) resyncExternalGateway() { } exGwEnabled = "true" lastExGwCM = cm.Data - c.ovnLegacyClient.ExternalGatewayType = cm.Data["type"] c.ExternalGatewayType = cm.Data["type"] if err := c.updateDefaultVpcExternal(true); err != nil { klog.Error("failed to update default vpc, %v", err) diff --git a/pkg/controller/gc.go b/pkg/controller/gc.go index 9eb3d1db0bc2..327eb82c1c56 100644 --- a/pkg/controller/gc.go +++ b/pkg/controller/gc.go @@ -119,11 +119,11 @@ func (c *Controller) gcLogicalSwitch() error { klog.Errorf("failed to list subnet, %v", err) return err } - subnetNames := make([]string, 0, len(subnets)) + subnetNames := strset.NewWithSize(len(subnets)) subnetMap := make(map[string]*kubeovnv1.Subnet, len(subnets)) for _, s := range subnets { subnetMap[s.Name] = s - subnetNames = append(subnetNames, s.Name) + subnetNames.Add(s.Name) } lss, err := c.ovnClient.ListLogicalSwitch(c.config.EnableExternalVpc, nil) @@ -152,21 +152,20 @@ func (c *Controller) gcLogicalSwitch() error { } klog.Infof("start to gc dhcp options") - dhcpOptions, err := c.ovnLegacyClient.ListDHCPOptions(c.config.EnableExternalVpc, "", "") + dhcpOptions, err := c.ovnClient.ListDHCPOptions(c.config.EnableExternalVpc, nil) if err != nil { klog.Errorf("failed to list dhcp options, %v", err) return err } var uuidToDeleteList = []string{} for _, item := range dhcpOptions { - ls := item.ExternalIds["ls"] - if !util.IsStringIn(ls, subnetNames) { + if len(item.ExternalIDs) == 0 || !subnetNames.Has(item.ExternalIDs["ls"]) { uuidToDeleteList = append(uuidToDeleteList, item.UUID) } } klog.Infof("gc dhcp options %v", uuidToDeleteList) if len(uuidToDeleteList) > 0 { - if err = c.ovnLegacyClient.DeleteDHCPOptionsByUUIDs(uuidToDeleteList); err != nil { + if err = c.ovnClient.DeleteDHCPOptionsByUUIDs(uuidToDeleteList...); err != nil { klog.Errorf("failed to delete dhcp options by uuids, %v", err) return err } @@ -641,11 +640,14 @@ func (c *Controller) gcStaticRoute() error { continue } if route.IPPrefix != "0.0.0.0/0" && route.IPPrefix != "::/0" && c.ipam.ContainAddress(route.IPPrefix) { - exist, err := c.ovnLegacyClient.NatRuleExists(route.IPPrefix) - if exist || err != nil { + exist, err := c.ovnClient.NatExists(c.config.ClusterRouter, "", "", route.IPPrefix) + if err != nil { klog.Errorf("failed to get NatRule by LogicalIP %s, %v", route.IPPrefix, err) continue } + if exist { + continue + } klog.Infof("gc static route %s %v %s %s", route.RouteTable, route.Policy, route.IPPrefix, route.Nexthop) if err = c.ovnClient.DeleteLogicalRouterStaticRoute(c.config.ClusterRouter, &route.RouteTable, route.Policy, route.IPPrefix, route.Nexthop); err != nil { klog.Errorf("failed to delete stale route %s %v %s %s: %v", route.RouteTable, route.Policy, route.IPPrefix, route.Nexthop, err) diff --git a/pkg/controller/ovn_fip.go b/pkg/controller/ovn_fip.go index ee7e1fefddda..b27cd053667e 100644 --- a/pkg/controller/ovn_fip.go +++ b/pkg/controller/ovn_fip.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "strconv" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -14,6 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" + "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb" "github.com/kubeovn/kube-ovn/pkg/util" ) @@ -251,8 +253,9 @@ func (c *Controller) handleAddOvnFip(key string) error { return err } // ovn add fip - if err = c.ovnLegacyClient.AddFipRule(vpcName, cachedEip.Status.V4Ip, - internalV4Ip, mac, cachedFip.Spec.IpName); err != nil { + if err = c.ovnClient.AddNat(vpcName, ovnnb.NATTypeDNATAndSNAT, cachedEip.Status.V4Ip, + internalV4Ip, mac, cachedFip.Spec.IpName, + map[string]string{"staleless": strconv.FormatBool(c.ExternalGatewayType == kubeovnv1.GWDistributedType)}); err != nil { klog.Errorf("failed to create v4 fip, %v", err) return err } @@ -327,8 +330,9 @@ func (c *Controller) handleUpdateOvnFip(key string) error { return err } vpcName := subnet.Spec.Vpc - if err = c.ovnLegacyClient.AddFipRule(vpcName, cachedEip.Status.V4Ip, - internalV4Ip, mac, cachedFip.Spec.IpName); err != nil { + if err = c.ovnClient.AddNat(vpcName, ovnnb.NATTypeDNATAndSNAT, cachedEip.Status.V4Ip, + internalV4Ip, mac, cachedFip.Spec.IpName, + map[string]string{"staleless": strconv.FormatBool(c.ExternalGatewayType == kubeovnv1.GWDistributedType)}); err != nil { klog.Errorf("failed to create v4 fip, %v", err) return err } @@ -347,13 +351,14 @@ func (c *Controller) handleUpdateOvnFip(key string) error { // fip change eip if c.ovnFipChangeEip(fip, cachedEip) { klog.V(3).Infof("fip change ip, old ip '%s', new ip %s", fip.Status.V4Ip, cachedEip.Status.V4Ip) - if err = c.ovnLegacyClient.DeleteFipRule(vpcName, fip.Status.V4Ip, internalV4Ip); err != nil { + if err = c.ovnClient.DeleteNat(vpcName, ovnnb.NATTypeDNATAndSNAT, fip.Status.V4Ip, internalV4Ip); err != nil { klog.Errorf("failed to create fip, %v", err) return err } // ovn add fip - if err = c.ovnLegacyClient.AddFipRule(vpcName, cachedEip.Status.V4Ip, - internalV4Ip, mac, cachedFip.Spec.IpName); err != nil { + if err = c.ovnClient.AddNat(vpcName, ovnnb.NATTypeDNATAndSNAT, cachedEip.Status.V4Ip, + internalV4Ip, mac, cachedFip.Spec.IpName, + map[string]string{"staleless": strconv.FormatBool(c.ExternalGatewayType == kubeovnv1.GWDistributedType)}); err != nil { klog.Errorf("failed to create fip, %v", err) return err } @@ -395,7 +400,7 @@ func (c *Controller) handleDelOvnFip(key string) error { } // ovn delete fip if cachedFip.Status.Vpc != "" && cachedFip.Status.V4Eip != "" && cachedFip.Status.V4Ip != "" { - if err = c.ovnLegacyClient.DeleteFipRule(cachedFip.Status.Vpc, cachedFip.Status.V4Eip, cachedFip.Status.V4Ip); err != nil { + if err = c.ovnClient.DeleteNat(cachedFip.Status.Vpc, ovnnb.NATTypeDNATAndSNAT, cachedFip.Status.V4Eip, cachedFip.Status.V4Ip); err != nil { klog.Errorf("failed to delete fip, %v", err) return err } diff --git a/pkg/controller/ovn_snat.go b/pkg/controller/ovn_snat.go index cdefaf620536..f8c87c559332 100644 --- a/pkg/controller/ovn_snat.go +++ b/pkg/controller/ovn_snat.go @@ -14,6 +14,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" + "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb" "github.com/kubeovn/kube-ovn/pkg/util" ) @@ -241,7 +242,7 @@ func (c *Controller) handleAddOvnSnatRule(key string) error { return err } // ovn add snat - if err = c.ovnLegacyClient.AddSnatRule(vpcName, cachedEip.Spec.V4Ip, v4IpCidr); err != nil { + if err = c.ovnClient.AddNat(vpcName, ovnnb.NATTypeSNAT, cachedEip.Spec.V4Ip, v4IpCidr, "", "", nil); err != nil { klog.Errorf("failed to create snat, %v", err) return err } @@ -287,7 +288,7 @@ func (c *Controller) handleUpdateOvnSnatRule(key string) error { klog.V(3).Infof("ovn delete snat %s", key) // ovn delete snat if cachedSnat.Status.Vpc != "" && cachedSnat.Status.V4Eip != "" && cachedSnat.Status.V4IpCidr != "" { - if err = c.ovnLegacyClient.DeleteSnatRule(cachedSnat.Status.Vpc, cachedSnat.Status.V4Eip, cachedSnat.Status.V4IpCidr); err != nil { + if err = c.ovnClient.DeleteNat(cachedSnat.Status.Vpc, ovnnb.NATTypeSNAT, cachedSnat.Status.V4Eip, cachedSnat.Status.V4IpCidr); err != nil { klog.Errorf("failed to delete snat, %v", err) return err } @@ -343,12 +344,12 @@ func (c *Controller) handleUpdateOvnSnatRule(key string) error { // snat change eip if c.ovnSnatChangeEip(cachedSnat, cachedEip) { klog.V(3).Infof("snat change ip, old ip %s, new ip %s", cachedEip.Status.V4Ip, cachedEip.Spec.V4Ip) - if err = c.ovnLegacyClient.DeleteSnatRule(vpcName, cachedEip.Status.V4Ip, v4IpCidr); err != nil { + if err = c.ovnClient.DeleteNat(vpcName, ovnnb.NATTypeSNAT, cachedEip.Status.V4Ip, v4IpCidr); err != nil { klog.Errorf("failed to delte snat, %v", err) return err } // ovn add snat with new eip - if err = c.ovnLegacyClient.AddSnatRule(vpcName, cachedEip.Spec.V4Ip, v4IpCidr); err != nil { + if err = c.ovnClient.AddNat(vpcName, ovnnb.NATTypeSNAT, cachedEip.Spec.V4Ip, v4IpCidr, "", "", nil); err != nil { klog.Errorf("failed to create snat, %v", err) return err } diff --git a/pkg/controller/pod.go b/pkg/controller/pod.go index d917052a34e5..04c39e002fb8 100644 --- a/pkg/controller/pod.go +++ b/pkg/controller/pod.go @@ -846,14 +846,25 @@ func (c *Controller) reconcileRouteSubnets(cachedPod, pod *v1.Pod, needRoutePodN if c.config.EnableEipSnat { for _, ipStr := range strings.Split(podIP, ",") { - if err := c.ovnLegacyClient.UpdateNatRule("dnat_and_snat", ipStr, pod.Annotations[util.EipAnnotation], c.config.ClusterRouter, pod.Annotations[util.MacAddressAnnotation], fmt.Sprintf("%s.%s", podName, pod.Namespace)); err != nil { - klog.Errorf("failed to add nat rules, %v", err) - return err + if eip := pod.Annotations[util.EipAnnotation]; eip == "" { + if err = c.ovnClient.DeleteNats(c.config.ClusterRouter, ovnnb.NATTypeDNATAndSNAT, ipStr); err != nil { + klog.Errorf("failed to delete nat rules: %v", err) + } + } else if util.CheckProtocol(eip) == util.CheckProtocol(ipStr) { + if err = c.ovnClient.UpdateDnatAndSnat(c.config.ClusterRouter, eip, ipStr, fmt.Sprintf("%s.%s", podName, pod.Namespace), pod.Annotations[util.MacAddressAnnotation], c.ExternalGatewayType); err != nil { + klog.Errorf("failed to add nat rules, %v", err) + return err + } } - - if err := c.ovnLegacyClient.UpdateNatRule("snat", ipStr, pod.Annotations[util.SnatAnnotation], c.config.ClusterRouter, "", ""); err != nil { - klog.Errorf("failed to add nat rules, %v", err) - return err + if eip := pod.Annotations[util.SnatAnnotation]; eip == "" { + if err = c.ovnClient.DeleteNats(c.config.ClusterRouter, ovnnb.NATTypeSNAT, ipStr); err != nil { + klog.Errorf("failed to delete nat rules: %v", err) + } + } else if util.CheckProtocol(eip) == util.CheckProtocol(ipStr) { + if err = c.ovnClient.UpdateSnat(c.config.ClusterRouter, eip, ipStr); err != nil { + klog.Errorf("failed to add nat rules, %v", err) + return err + } } } } @@ -930,7 +941,7 @@ func (c *Controller) handleDeletePod(key string) error { } } if exGwEnabled == "true" { - if err := c.ovnLegacyClient.DeleteNatRule(address.Ip, vpc.Name); err != nil { + if err := c.ovnClient.DeleteNat(vpc.Name, "", "", address.Ip); err != nil { return err } } diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index c6456c22c401..a4af5df8f251 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -613,7 +613,7 @@ func (c *Controller) updateSubnetDHCPOption(subnet *kubeovnv1.Subnet, needRouter } } - dhcpOptionsUUIDs, err := c.ovnLegacyClient.UpdateDHCPOptions(subnet.Name, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.DHCPv4Options, subnet.Spec.DHCPv6Options, subnet.Spec.EnableDHCP, mtu) + dhcpOptionsUUIDs, err := c.ovnClient.UpdateDHCPOptions(subnet, mtu) if err != nil { klog.Errorf("failed to update dhcp options for switch %s, %v", subnet.Name, err) return err @@ -885,7 +885,7 @@ func (c *Controller) handleDeleteLogicalSwitch(key string) (err error) { return err } - if err = c.ovnLegacyClient.DeleteDHCPOptions(key, kubeovnv1.ProtocolDual); err != nil { + if err = c.ovnClient.DeleteDHCPOptions(key, kubeovnv1.ProtocolDual); err != nil { klog.Errorf("failed to delete dhcp options of logical switch %s %v", key, err) return err } diff --git a/pkg/controller/vpc.go b/pkg/controller/vpc.go index f6155aa6ffc1..3c7268b81828 100644 --- a/pkg/controller/vpc.go +++ b/pkg/controller/vpc.go @@ -345,16 +345,16 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error { } for _, nat := range lr.Nat { - logicalIP, err := c.ovnLegacyClient.GetNatIPInfo(nat) + info, err := c.ovnClient.GetNATByUUID(nat) if err != nil { klog.Errorf("failed to get nat ip info for vpc %s, %v", vpc.Name, err) return err } - if logicalIP != "" { + if info.LogicalIP != "" { for rtb := range rtbs { targetRoutes = append(targetRoutes, &kubeovnv1.StaticRoute{ Policy: kubeovnv1.PolicySrc, - CIDR: logicalIP, + CIDR: info.LogicalIP, NextHopIP: nextHop, RouteTable: rtb, }) diff --git a/pkg/ovs/interface.go b/pkg/ovs/interface.go index b0e66ecd5cc5..9ffc12f3b188 100644 --- a/pkg/ovs/interface.go +++ b/pkg/ovs/interface.go @@ -142,6 +142,8 @@ type LogicalRouterPolicy interface { } type NAT interface { + GetNATByUUID(uuid string) (*ovnnb.NAT, error) + AddNat(lrName, natType, externalIP, logicalIP, logicalMac, port string, options map[string]string) error UpdateSnat(lrName, externalIP, logicalIP string) error UpdateDnatAndSnat(lrName, externalIP, logicalIP, lspName, externalMac, gatewayType string) error DeleteNats(lrName, natType, logicalIP string) error @@ -151,7 +153,7 @@ type NAT interface { } type DHCPOptions interface { - UpdateDHCPOptions(subnet *kubeovnv1.Subnet) (*DHCPOptionsUUIDs, error) + UpdateDHCPOptions(subnet *kubeovnv1.Subnet, mtu int) (*DHCPOptionsUUIDs, error) DeleteDHCPOptions(lsName string, protocol string) error DeleteDHCPOptionsByUUIDs(uuidList ...string) error ListDHCPOptions(needVendorFilter bool, externalIDs map[string]string) ([]ovnnb.DHCPOptions, error) diff --git a/pkg/ovs/ovn-nb-dhcp_options.go b/pkg/ovs/ovn-nb-dhcp_options.go index feda547f375d..e0e93b197894 100644 --- a/pkg/ovs/ovn-nb-dhcp_options.go +++ b/pkg/ovs/ovn-nb-dhcp_options.go @@ -35,7 +35,7 @@ func (c *ovnClient) CreateDHCPOptions(lsName, cidr, options string) error { return nil } -func (c *ovnClient) UpdateDHCPOptions(subnet *kubeovnv1.Subnet) (*DHCPOptionsUUIDs, error) { +func (c *ovnClient) UpdateDHCPOptions(subnet *kubeovnv1.Subnet, mtu int) (*DHCPOptionsUUIDs, error) { lsName := subnet.Name cidrBlock := subnet.Spec.CIDRBlock gateway := subnet.Spec.Gateway @@ -65,7 +65,7 @@ func (c *ovnClient) UpdateDHCPOptions(subnet *kubeovnv1.Subnet) (*DHCPOptionsUUI v4Gateway = gateways[0] } - dhcpV4OptUUID, err := c.updateDHCPv4Options(lsName, v4CIDR, v4Gateway, subnet.Spec.DHCPv4Options) + dhcpV4OptUUID, err := c.updateDHCPv4Options(lsName, v4CIDR, v4Gateway, subnet.Spec.DHCPv4Options, mtu) if err != nil { return nil, fmt.Errorf("update IPv4 dhcp options for logical switch %s: %v", lsName, err) } @@ -81,7 +81,7 @@ func (c *ovnClient) UpdateDHCPOptions(subnet *kubeovnv1.Subnet) (*DHCPOptionsUUI }, nil } -func (c *ovnClient) updateDHCPv4Options(lsName, cidr, gateway, options string) (uuid string, err error) { +func (c *ovnClient) updateDHCPv4Options(lsName, cidr, gateway, options string, mtu int) (uuid string, err error) { protocol := util.CheckProtocol(cidr) if protocol != kubeovnv1.ProtocolIPv4 { return "", fmt.Errorf("cidr %s must be a valid ipv4 address", cidr) @@ -98,7 +98,7 @@ func (c *ovnClient) updateDHCPv4Options(lsName, cidr, gateway, options string) ( mac = dhcpOpt.Options["server_mac"] } - options = fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s", 3600, gateway, "169.254.0.254", mac) + options = fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s,mtu=%d", 3600, gateway, "169.254.0.254", mac, mtu) } /* update */ diff --git a/pkg/ovs/ovn-nb-dhcp_options_test.go b/pkg/ovs/ovn-nb-dhcp_options_test.go index 1315c14a9678..a0d7ff4c5515 100644 --- a/pkg/ovs/ovn-nb-dhcp_options_test.go +++ b/pkg/ovs/ovn-nb-dhcp_options_test.go @@ -35,7 +35,7 @@ func (suite *OvnClientTestSuite) testUpdateDHCPOptions() { subnet := mockSubnet(lsName, true) t.Run("update dhcp options", func(t *testing.T) { - uuid, err := ovnClient.UpdateDHCPOptions(subnet) + uuid, err := ovnClient.UpdateDHCPOptions(subnet, 1500) require.NoError(t, err) v4DHCPOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) @@ -51,7 +51,7 @@ func (suite *OvnClientTestSuite) testUpdateDHCPOptions() { t.Run("delete dhcp options", func(t *testing.T) { subnet.Spec.EnableDHCP = false - uuid, err := ovnClient.UpdateDHCPOptions(subnet) + uuid, err := ovnClient.UpdateDHCPOptions(subnet, 1500) require.NoError(t, err) require.Empty(t, uuid.DHCPv4OptionsUUID) require.Empty(t, uuid.DHCPv6OptionsUUID) @@ -76,7 +76,7 @@ func (suite *OvnClientTestSuite) test_updateDHCPv4Options() { t.Run("create dhcp options", func(t *testing.T) { t.Run("without options", func(t *testing.T) { - uuid, err := ovnClient.updateDHCPv4Options(lsName, cidr, gateway, "") + uuid, err := ovnClient.updateDHCPv4Options(lsName, cidr, gateway, "", 1500) require.NoError(t, err) dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) @@ -91,13 +91,14 @@ func (suite *OvnClientTestSuite) test_updateDHCPv4Options() { "router": "192.168.30.1", "server_id": "169.254.0.254", "server_mac": serverMac, + "mtu": "1500", }, dhcpOpt.Options) }) t.Run("with options", func(t *testing.T) { lsName := "test-update-v4-dhcp-opt-ls-with-opt" options := fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s", 7200, gateway, "169.254.0.1", "00:00:00:11:22:33") - uuid, err := ovnClient.updateDHCPv4Options(lsName, cidr, gateway, options) + uuid, err := ovnClient.updateDHCPv4Options(lsName, cidr, gateway, options, 1500) require.NoError(t, err) dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) @@ -115,7 +116,7 @@ func (suite *OvnClientTestSuite) test_updateDHCPv4Options() { }) t.Run("update dhcp options", func(t *testing.T) { - uuid, err := ovnClient.updateDHCPv4Options(lsName, cidr, gateway, "") + uuid, err := ovnClient.updateDHCPv4Options(lsName, cidr, gateway, "", 1500) require.NoError(t, err) dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) @@ -128,6 +129,7 @@ func (suite *OvnClientTestSuite) test_updateDHCPv4Options() { "router": "192.168.30.1", "server_id": "169.254.0.254", "server_mac": serverMac, + "mtu": "1500", }, dhcpOpt.Options) }) } diff --git a/pkg/ovs/ovn-nb-nat.go b/pkg/ovs/ovn-nb-nat.go index 6f5c0840e41a..ff7b317836fc 100644 --- a/pkg/ovs/ovn-nb-nat.go +++ b/pkg/ovs/ovn-nb-nat.go @@ -14,8 +14,18 @@ import ( "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb" ) -func (c *ovnClient) AddNat(lrName, natType, externalIP, logicalIP string) error { - nat, err := c.newNat(lrName, natType, externalIP, logicalIP) +func (c *ovnClient) AddNat(lrName, natType, externalIP, logicalIP, logicalMac, port string, options map[string]string) error { + nat, err := c.newNat(lrName, natType, externalIP, logicalIP, logicalMac, port, func(nat *ovnnb.NAT) { + if len(options) == 0 { + return + } + if len(nat.Options) == 0 { + nat.Options = make(map[string]string, len(options)) + } + for k, v := range options { + nat.Options[k] = v + } + }) if err != nil { return err } @@ -75,7 +85,7 @@ func (c *ovnClient) UpdateSnat(lrName, externalIP, logicalIP string) error { } /* create nat */ - if nat, err = c.newNat(lrName, natType, externalIP, logicalIP); err != nil { + if nat, err = c.newNat(lrName, natType, externalIP, logicalIP, "", ""); err != nil { return fmt.Errorf("new logical router %s nat 'type %s external ip %s logical ip %s': %v", lrName, natType, externalIP, logicalIP, err) } @@ -111,16 +121,15 @@ func (c *ovnClient) UpdateDnatAndSnat(lrName, externalIP, logicalIP, lspName, ex nat.LogicalPort = &lspName nat.ExternalMAC = &externalMac - if nil == nat.Options { - nat.Options = make(map[string]string) + if nat.Options == nil { + nat.Options = make(map[string]string, 1) } - nat.Options["stateless"] = "true" } } /* create nat */ - if nat, err = c.newNat(lrName, natType, externalIP, logicalIP, options); err != nil { + if nat, err = c.newNat(lrName, natType, externalIP, logicalIP, "", "", options); err != nil { return fmt.Errorf("new logical router %s nat 'type %s external ip %s logical ip %s logical port %s external mac %s': %v", lrName, natType, externalIP, logicalIP, lspName, externalMac, err) } @@ -219,6 +228,9 @@ func (c *ovnClient) GetNat(lrName, natType, externalIP, logicalIP string, ignore } fnFilter := func(nat *ovnnb.NAT) bool { + if natType == "" { + return nat.LogicalIP == logicalIP + } if natType == ovnnb.NATTypeSNAT { return nat.Type == natType && nat.LogicalIP == logicalIP } @@ -255,7 +267,7 @@ func (c *ovnClient) NatExists(lrName, natType, externalIP, logicalIP string) (bo } // newNat return net with basic information -func (c *ovnClient) newNat(lrName, natType, externalIP, logicalIP string, options ...func(nat *ovnnb.NAT)) (*ovnnb.NAT, error) { +func (c *ovnClient) newNat(lrName, natType, externalIP, logicalIP, logicalMac, port string, options ...func(nat *ovnnb.NAT)) (*ovnnb.NAT, error) { if len(lrName) == 0 { return nil, fmt.Errorf("the logical router name is required") } @@ -284,6 +296,12 @@ func (c *ovnClient) newNat(lrName, natType, externalIP, logicalIP string, option ExternalIP: externalIP, LogicalIP: logicalIP, } + if logicalMac != "" { + nat.ExternalMAC = &logicalMac + } + if port != "" { + nat.LogicalPort = &port + } for _, option := range options { option(nat) diff --git a/pkg/ovs/ovn-nb-nat_test.go b/pkg/ovs/ovn-nb-nat_test.go index 0a0cd0b11e9e..e4562e80759d 100644 --- a/pkg/ovs/ovn-nb-nat_test.go +++ b/pkg/ovs/ovn-nb-nat_test.go @@ -40,7 +40,7 @@ func (suite *OvnClientTestSuite) testCreateNats() { // snat for _, logicalIP := range logicalIPs { - nat, err := ovnClient.newNat(lrName, "snat", externalIPs[0], logicalIP) + nat, err := ovnClient.newNat(lrName, "snat", externalIPs[0], logicalIP, "", "") require.NoError(t, err) nats = append(nats, nat) @@ -48,7 +48,7 @@ func (suite *OvnClientTestSuite) testCreateNats() { // dnat_and_snat for _, externalIP := range externalIPs { - nat, err := ovnClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0]) + nat, err := ovnClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0], "", "") require.NoError(t, err) nats = append(nats, nat) @@ -201,12 +201,12 @@ func (suite *OvnClientTestSuite) testDeleteNat() { nats := make([]*ovnnb.NAT, 0) // create snat rule - nat, err := ovnClient.newNat(lrName, "snat", externalIP, logicalIP) + nat, err := ovnClient.newNat(lrName, "snat", externalIP, logicalIP, "", "") require.NoError(t, err) nats = append(nats, nat) // create dnat_and_snat rule - nat, err = ovnClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIP) + nat, err = ovnClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIP, "", "") require.NoError(t, err) nats = append(nats, nat) @@ -256,14 +256,14 @@ func (suite *OvnClientTestSuite) testDeleteNats() { nats := make([]*ovnnb.NAT, 0) // create two snat rule for _, logicalIP := range logicalIPs { - nat, err := ovnClient.newNat(lrName, "snat", externalIPs[0], logicalIP) + nat, err := ovnClient.newNat(lrName, "snat", externalIPs[0], logicalIP, "", "") require.NoError(t, err) nats = append(nats, nat) } // create two dnat_and_snat rule for _, externalIP := range externalIPs { - nat, err := ovnClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0]) + nat, err := ovnClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0], "", "") require.NoError(t, err) nats = append(nats, nat) } @@ -387,7 +387,7 @@ func (suite *OvnClientTestSuite) testGetNat() { externalIP := "192.168.30.254" logicalIP := "10.250.0.4" - err := ovnClient.AddNat(lrName, natType, externalIP, logicalIP) + err := ovnClient.AddNat(lrName, natType, externalIP, logicalIP, "", "", nil) require.NoError(t, err) t.Run("found nat", func(t *testing.T) { @@ -412,7 +412,7 @@ func (suite *OvnClientTestSuite) testGetNat() { externalIP := "192.168.30.254" logicalIP := "10.250.0.4" - err := ovnClient.AddNat(lrName, natType, externalIP, logicalIP) + err := ovnClient.AddNat(lrName, natType, externalIP, logicalIP, "", "", nil) require.NoError(t, err) t.Run("found nat", func(t *testing.T) { @@ -449,7 +449,7 @@ func (suite *OvnClientTestSuite) test_newNat() { LogicalIP: logicalIP, } - nat, err := ovnClient.newNat(lrName, natType, externalIP, logicalIP) + nat, err := ovnClient.newNat(lrName, natType, externalIP, logicalIP, "", "") require.NoError(t, err) expect.UUID = nat.UUID require.Equal(t, expect, nat) @@ -475,7 +475,7 @@ func (suite *OvnClientTestSuite) test_newNat() { nat.ExternalMAC = &externalMac } - nat, err := ovnClient.newNat(lrName, natType, externalIP, logicalIP, options) + nat, err := ovnClient.newNat(lrName, natType, externalIP, logicalIP, "", "", options) require.NoError(t, err) expect.UUID = nat.UUID require.Equal(t, expect, nat) diff --git a/pkg/ovs/ovn-nbctl-legacy.go b/pkg/ovs/ovn-nbctl-legacy.go deleted file mode 100644 index e310314fb5bd..000000000000 --- a/pkg/ovs/ovn-nbctl-legacy.go +++ /dev/null @@ -1,593 +0,0 @@ -package ovs - -import ( - "bytes" - "fmt" - "os" - "os/exec" - "regexp" - "strings" - "time" - - "k8s.io/klog/v2" - - kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" - "github.com/kubeovn/kube-ovn/pkg/util" -) - -var nbctlDaemonSocketRegexp = regexp.MustCompile(`^/var/run/ovn/ovn-nbctl\.[0-9]+\.ctl$`) - -func (c LegacyClient) ovnNbCommand(cmdArgs ...string) (string, error) { - start := time.Now() - cmdArgs = append([]string{fmt.Sprintf("--timeout=%d", c.OvnTimeout), "--no-wait"}, cmdArgs...) - raw, err := exec.Command(OvnNbCtl, cmdArgs...).CombinedOutput() - elapsed := float64((time.Since(start)) / time.Millisecond) - klog.V(4).Infof("command %s %s in %vms, output %q", OvnNbCtl, strings.Join(cmdArgs, " "), elapsed, raw) - method := "" - for _, arg := range cmdArgs { - if !strings.HasPrefix(arg, "--") { - method = arg - break - } - } - code := "0" - defer func() { - ovsClientRequestLatency.WithLabelValues("ovn-nb", method, code).Observe(elapsed) - }() - - if err != nil { - code = "1" - klog.Warningf("ovn-nbctl command error: %s %s in %vms", OvnNbCtl, strings.Join(cmdArgs, " "), elapsed) - return "", fmt.Errorf("%s, %q", raw, err) - } else if elapsed > 500 { - klog.Warningf("ovn-nbctl command took too long: %s %s in %vms", OvnNbCtl, strings.Join(cmdArgs, " "), elapsed) - } - return trimCommandOutput(raw), nil -} - -func (c LegacyClient) GetVersion() (string, error) { - if c.Version != "" { - return c.Version, nil - } - output, err := c.ovnNbCommand("--version") - if err != nil { - return "", fmt.Errorf("failed to get version,%v", err) - } - lines := strings.Split(output, "\n") - if len(lines) > 0 { - c.Version = strings.Split(lines[0], " ")[1] - } - return c.Version, nil -} - -func (c LegacyClient) CustomFindEntity(entity string, attris []string, args ...string) (result []map[string][]string, err error) { - result = []map[string][]string{} - var attrStr strings.Builder - for _, e := range attris { - attrStr.WriteString(e) - attrStr.WriteString(",") - } - // Assuming that the order of the elements in attris does not change - cmd := []string{"--format=csv", "--data=bare", "--no-heading", fmt.Sprintf("--columns=%s", attrStr.String()), "find", entity} - cmd = append(cmd, args...) - output, err := c.ovnNbCommand(cmd...) - if err != nil { - klog.Errorf("failed to customized list logical %s: %v", entity, err) - return nil, err - } - if output == "" { - return result, nil - } - lines := strings.Split(output, "\n") - for _, l := range lines { - aResult := make(map[string][]string) - parts := strings.Split(strings.TrimSpace(l), ",") - for i, e := range attris { - if aResult[e] = strings.Fields(parts[i]); aResult[e] == nil { - aResult[e] = []string{} - } - } - result = append(result, aResult) - } - return result, nil -} - -func (c LegacyClient) UpdateNatRule(policy, logicalIP, externalIP, router, logicalMac, port string) error { - // when dual protocol pod has eip or snat, will add nat for all dual addresses. - // will fail when logicalIP externalIP is different protocol. - if externalIP != "" && util.CheckProtocol(logicalIP) != util.CheckProtocol(externalIP) { - return nil - } - - if policy == "snat" { - if externalIP == "" { - _, err := c.ovnNbCommand(IfExists, "lr-nat-del", router, "snat", logicalIP) - return err - } - if _, err := c.ovnNbCommand(IfExists, "lr-nat-del", router, "snat", logicalIP); err != nil { - return err - } - _, err := c.ovnNbCommand(MayExist, "lr-nat-add", router, policy, externalIP, logicalIP) - return err - } else { - output, err := c.ovnNbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=external_ip", "find", "NAT", fmt.Sprintf("logical_ip=%s", strings.ReplaceAll(logicalIP, ":", "\\:")), "type=dnat_and_snat") - if err != nil { - klog.Errorf("failed to list nat rules, %v", err) - return err - } - eips := strings.Split(output, "\n") - for _, eip := range eips { - eip = strings.TrimSpace(eip) - if eip == "" || eip == externalIP { - continue - } - if _, err := c.ovnNbCommand(IfExists, "lr-nat-del", router, "dnat_and_snat", eip); err != nil { - klog.Errorf("failed to delete nat rule, %v", err) - return err - } - } - if externalIP != "" { - if c.ExternalGatewayType == "distributed" { - _, err = c.ovnNbCommand(MayExist, "--stateless", "lr-nat-add", router, policy, externalIP, logicalIP, port, logicalMac) - } else { - _, err = c.ovnNbCommand(MayExist, "lr-nat-add", router, policy, externalIP, logicalIP) - } - return err - } - } - return nil -} - -func (c LegacyClient) DeleteNatRule(logicalIP, router string) error { - output, err := c.ovnNbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=type,external_ip", "find", "NAT", fmt.Sprintf("logical_ip=%s", strings.ReplaceAll(logicalIP, ":", "\\:"))) - if err != nil { - klog.Errorf("failed to list nat rules, %v", err) - return err - } - rules := strings.Split(output, "\n") - for _, rule := range rules { - if len(strings.Split(rule, ",")) != 2 { - continue - } - policy, externalIP := strings.Split(rule, ",")[0], strings.Split(rule, ",")[1] - if policy == "snat" { - if _, err := c.ovnNbCommand(IfExists, "lr-nat-del", router, "snat", logicalIP); err != nil { - klog.Errorf("failed to delete nat rule, %v", err) - return err - } - } else if policy == "dnat_and_snat" { - if _, err := c.ovnNbCommand(IfExists, "lr-nat-del", router, "dnat_and_snat", externalIP); err != nil { - klog.Errorf("failed to delete nat rule, %v", err) - return err - } - } - } - - return err -} - -func (c *LegacyClient) NatRuleExists(logicalIP string) (bool, error) { - results, err := c.CustomFindEntity("NAT", []string{"external_ip"}, fmt.Sprintf("logical_ip=%s", strings.ReplaceAll(logicalIP, ":", "\\:"))) - if err != nil { - klog.Errorf("customFindEntity failed, %v", err) - return false, err - } - if len(results) == 0 { - return false, nil - } - return true, nil -} - -func (c LegacyClient) AddFipRule(router, eip, logicalIP, logicalMac, port string) error { - // failed if logicalIP externalIP(eip) is different protocol. - if util.CheckProtocol(logicalIP) != util.CheckProtocol(eip) { - return nil - } - var err error - fip := "dnat_and_snat" - if eip != "" && logicalIP != "" && logicalMac != "" { - if c.ExternalGatewayType == "distributed" { - _, err = c.ovnNbCommand(MayExist, "--stateless", "lr-nat-add", router, fip, eip, logicalIP, port, logicalMac) - } else { - _, err = c.ovnNbCommand(MayExist, "lr-nat-add", router, fip, eip, logicalIP) - } - return err - } else { - return fmt.Errorf("logical ip, external ip and logical mac must be provided to add fip rule") - } -} - -func (c LegacyClient) DeleteFipRule(router, eip, logicalIP string) error { - fip := "dnat_and_snat" - output, err := c.ovnNbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=type,external_ip", "find", "NAT", fmt.Sprintf("logical_ip=%s", logicalIP)) - if err != nil { - klog.Errorf("failed to list nat rules, %v", err) - return err - } - rules := strings.Split(output, "\n") - for _, rule := range rules { - if len(strings.Split(rule, ",")) != 2 { - continue - } - policy, externalIP := strings.Split(rule, ",")[0], strings.Split(rule, ",")[1] - if externalIP == eip && policy == fip { - if _, err := c.ovnNbCommand(IfExists, "lr-nat-del", router, fip, externalIP); err != nil { - klog.Errorf("failed to delete fip rule, %v", err) - return err - } - } - } - return err -} - -func (c *LegacyClient) FipRuleExists(eip, logicalIP string) (bool, error) { - fip := "dnat_and_snat" - output, err := c.ovnNbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=type,external_ip", "find", "NAT", fmt.Sprintf("logical_ip=%s", logicalIP)) - if err != nil { - klog.Errorf("failed to list nat rules, %v", err) - return false, err - } - rules := strings.Split(output, "\n") - for _, rule := range rules { - if len(strings.Split(rule, ",")) != 2 { - continue - } - policy, externalIP := strings.Split(rule, ",")[0], strings.Split(rule, ",")[1] - if externalIP == eip && policy == fip { - return true, nil - } - } - return false, fmt.Errorf("fip rule not exist") -} - -func (c LegacyClient) AddSnatRule(router, eip, ipCidr string) error { - // failed if logicalIP externalIP(eip) is different protocol. - if util.CheckProtocol(ipCidr) != util.CheckProtocol(eip) { - return nil - } - snat := "snat" - if eip != "" && ipCidr != "" { - _, err := c.ovnNbCommand(MayExist, "lr-nat-add", router, snat, eip, ipCidr) - return err - } else { - return fmt.Errorf("logical ip, external ip and logical mac must be provided to add snat rule") - } -} - -func (c LegacyClient) DeleteSnatRule(router, eip, ipCidr string) error { - snat := "snat" - output, err := c.ovnNbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=type,external_ip", "find", "NAT", fmt.Sprintf("logical_ip=%s", ipCidr)) - if err != nil { - klog.Errorf("failed to list nat rules, %v", err) - return err - } - rules := strings.Split(output, "\n") - for _, rule := range rules { - if len(strings.Split(rule, ",")) != 2 { - continue - } - policy, externalIP := strings.Split(rule, ",")[0], strings.Split(rule, ",")[1] - if externalIP == eip && policy == snat { - if _, err := c.ovnNbCommand(IfExists, "lr-nat-del", router, snat, ipCidr); err != nil { - klog.Errorf("failed to delete snat rule, %v", err) - return err - } - } - } - return err -} - -// StartOvnNbctlDaemon start a daemon and set OVN_NB_DAEMON env -func StartOvnNbctlDaemon(ovnNbAddr string) error { - klog.Infof("start ovn-nbctl daemon") - output, err := exec.Command( - "pkill", - "-f", - "ovn-nbctl", - ).CombinedOutput() - if err != nil { - klog.Errorf("failed to kill old ovn-nbctl daemon: %q", output) - return err - } - command := []string{ - fmt.Sprintf("--db=%s", ovnNbAddr), - "--pidfile", - "--detach", - "--overwrite-pidfile", - } - if os.Getenv("ENABLE_SSL") == "true" { - command = []string{ - "-p", "/var/run/tls/key", - "-c", "/var/run/tls/cert", - "-C", "/var/run/tls/cacert", - fmt.Sprintf("--db=%s", ovnNbAddr), - "--pidfile", - "--detach", - "--overwrite-pidfile", - } - } - - var stdout, stderr bytes.Buffer - cmd := exec.Command("ovn-nbctl", command...) - cmd.Stdout, cmd.Stderr = &stdout, &stderr - if err = cmd.Run(); err != nil { - klog.Errorf("failed to start ovn-nbctl daemon: %v, %s, %s", err, stdout.String(), stderr.String()) - return err - } - - daemonSocket := strings.TrimSpace(stdout.String()) - if !nbctlDaemonSocketRegexp.MatchString(daemonSocket) { - err = fmt.Errorf("invalid nbctl daemon socket: %q", daemonSocket) - klog.Error(err) - return err - } - - _ = os.Unsetenv("OVN_NB_DAEMON") - if err := os.Setenv("OVN_NB_DAEMON", daemonSocket); err != nil { - klog.Errorf("failed to set env OVN_NB_DAEMON, %v", err) - return err - } - return nil -} - -// CheckAlive check if kube-ovn-controller can access ovn-nb from nbctl-daemon -func CheckAlive() error { - var stderr bytes.Buffer - cmd := exec.Command("ovn-nbctl", "--timeout=60", "show") - cmd.Stderr = &stderr - - if err := cmd.Run(); err != nil { - klog.Errorf("failed to access ovn-nb from daemon: %v, %s", err, stderr.String()) - return err - } - return nil -} - -type dhcpOptions struct { - UUID string - CIDR string - ExternalIds map[string]string - options map[string]string -} - -func (c LegacyClient) ListDHCPOptions(needVendorFilter bool, ls string, protocol string) ([]dhcpOptions, error) { - cmds := []string{"--format=csv", "--no-heading", "--data=bare", "--columns=_uuid,cidr,external_ids,options", "find", "dhcp_options"} - if needVendorFilter { - cmds = append(cmds, fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName)) - } - if len(ls) != 0 { - cmds = append(cmds, fmt.Sprintf("external_ids:ls=%s", ls)) - } - if len(protocol) != 0 && protocol != kubeovnv1.ProtocolDual { - cmds = append(cmds, fmt.Sprintf("external_ids:protocol=%s", protocol)) - } - - output, err := c.ovnNbCommand(cmds...) - if err != nil { - klog.Errorf("failed to find dhcp options, %v", err) - return nil, err - } - entries := strings.Split(output, "\n") - dhcpOptionsList := make([]dhcpOptions, 0, len(entries)) - for _, entry := range strings.Split(output, "\n") { - if len(strings.Split(entry, ",")) == 4 { - t := strings.Split(entry, ",") - - externalIdsMap := map[string]string{} - for _, ex := range strings.Split(t[2], " ") { - ids := strings.Split(strings.TrimSpace(ex), "=") - if len(ids) == 2 { - externalIdsMap[ids[0]] = ids[1] - } - } - - optionsMap := map[string]string{} - for _, op := range strings.Split(t[3], " ") { - kv := strings.Split(strings.TrimSpace(op), "=") - if len(kv) == 2 { - optionsMap[kv[0]] = kv[1] - } - } - - dhcpOptionsList = append(dhcpOptionsList, - dhcpOptions{UUID: strings.TrimSpace(t[0]), CIDR: strings.TrimSpace(t[1]), ExternalIds: externalIdsMap, options: optionsMap}) - } - } - return dhcpOptionsList, nil -} - -func (c *LegacyClient) createDHCPOptions(ls, cidr, optionsStr string) (dhcpOptionsUuid string, err error) { - klog.Infof("create dhcp options ls:%s, cidr:%s, optionStr:[%s]", ls, cidr, optionsStr) - - protocol := util.CheckProtocol(cidr) - output, err := c.ovnNbCommand("create", "dhcp_options", - fmt.Sprintf("cidr=%s", strings.ReplaceAll(cidr, ":", "\\:")), - fmt.Sprintf("options=%s", strings.ReplaceAll(optionsStr, ":", "\\:")), - fmt.Sprintf("external_ids=ls=%s,protocol=%s,vendor=%s", ls, protocol, util.CniTypeName)) - if err != nil { - klog.Errorf("create dhcp options %s for switch %s failed: %v", cidr, ls, err) - return "", err - } - dhcpOptionsUuid = strings.Split(output, "\n")[0] - - return dhcpOptionsUuid, nil -} - -func (c *LegacyClient) updateDHCPv4Options(ls, v4CIDR, v4Gateway, dhcpV4OptionsStr string, mtu int) (dhcpV4OptionsUuid string, err error) { - dhcpV4OptionsStr = strings.ReplaceAll(dhcpV4OptionsStr, " ", "") - dhcpV4Options, err := c.ListDHCPOptions(true, ls, kubeovnv1.ProtocolIPv4) - if err != nil { - klog.Errorf("list dhcp options for switch %s protocol %s failed: %v", ls, kubeovnv1.ProtocolIPv4, err) - return "", err - } - - if len(v4CIDR) > 0 { - if len(dhcpV4Options) == 0 { - // create - mac := util.GenerateMac() - if len(dhcpV4OptionsStr) == 0 { - // default dhcp v4 options - dhcpV4OptionsStr = fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s,mtu=%d", 3600, v4Gateway, "169.254.0.254", mac, mtu) - } - dhcpV4OptionsUuid, err = c.createDHCPOptions(ls, v4CIDR, dhcpV4OptionsStr) - if err != nil { - klog.Errorf("create dhcp options for switch %s failed: %v", ls, err) - return "", err - } - } else { - // update - v4Options := dhcpV4Options[0] - if len(dhcpV4OptionsStr) == 0 { - mac := v4Options.options["server_mac"] - if len(mac) == 0 { - mac = util.GenerateMac() - } - dhcpV4OptionsStr = fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s,mtu=%d", 3600, v4Gateway, "169.254.0.254", mac, mtu) - } - _, err = c.ovnNbCommand("set", "dhcp_options", v4Options.UUID, fmt.Sprintf("cidr=%s", v4CIDR), - fmt.Sprintf("options=%s", strings.ReplaceAll(dhcpV4OptionsStr, ":", "\\:"))) - if err != nil { - klog.Errorf("set cidr and options for dhcp v4 options %s failed: %v", v4Options.UUID, err) - return "", err - } - dhcpV4OptionsUuid = v4Options.UUID - } - } else if len(dhcpV4Options) > 0 { - // delete - if err = c.DeleteDHCPOptions(ls, kubeovnv1.ProtocolIPv4); err != nil { - klog.Errorf("delete dhcp options for switch %s protocol %s failed: %v", ls, kubeovnv1.ProtocolIPv4, err) - return "", err - } - } - - return -} - -func (c *LegacyClient) updateDHCPv6Options(ls, v6CIDR, dhcpV6OptionsStr string) (dhcpV6OptionsUuid string, err error) { - dhcpV6OptionsStr = strings.ReplaceAll(dhcpV6OptionsStr, " ", "") - dhcpV6Options, err := c.ListDHCPOptions(true, ls, kubeovnv1.ProtocolIPv6) - if err != nil { - klog.Errorf("list dhcp options for switch %s protocol %s failed: %v", ls, kubeovnv1.ProtocolIPv6, err) - return "", err - } - - if len(v6CIDR) > 0 { - if len(dhcpV6Options) == 0 { - // create - if len(dhcpV6OptionsStr) == 0 { - mac := util.GenerateMac() - dhcpV6OptionsStr = fmt.Sprintf("server_id=%s", mac) - } - dhcpV6OptionsUuid, err = c.createDHCPOptions(ls, v6CIDR, dhcpV6OptionsStr) - if err != nil { - klog.Errorf("create dhcp options for switch %s failed: %v", ls, err) - return "", err - } - } else { - // update - v6Options := dhcpV6Options[0] - if len(dhcpV6OptionsStr) == 0 { - mac := v6Options.options["server_id"] - if len(mac) == 0 { - mac = util.GenerateMac() - } - dhcpV6OptionsStr = fmt.Sprintf("server_id=%s", mac) - } - _, err = c.ovnNbCommand("set", "dhcp_options", v6Options.UUID, fmt.Sprintf("cidr=%s", strings.ReplaceAll(v6CIDR, ":", "\\:")), - fmt.Sprintf("options=%s", strings.ReplaceAll(dhcpV6OptionsStr, ":", "\\:"))) - if err != nil { - klog.Errorf("set cidr and options for dhcp v6 options %s failed: %v", v6Options.UUID, err) - return "", err - } - dhcpV6OptionsUuid = v6Options.UUID - } - } else if len(dhcpV6Options) > 0 { - // delete - if err = c.DeleteDHCPOptions(ls, kubeovnv1.ProtocolIPv6); err != nil { - klog.Errorf("delete dhcp options for switch %s protocol %s failed: %v", ls, kubeovnv1.ProtocolIPv6, err) - return "", err - } - } - - return -} - -func (c *LegacyClient) UpdateDHCPOptions(ls, cidrBlock, gateway, dhcpV4OptionsStr, dhcpV6OptionsStr string, enableDHCP bool, mtu int) (dhcpOptionsUUIDs *DHCPOptionsUUIDs, err error) { - dhcpOptionsUUIDs = &DHCPOptionsUUIDs{} - if enableDHCP { - var v4CIDR, v6CIDR string - var v4Gateway string - switch util.CheckProtocol(cidrBlock) { - case kubeovnv1.ProtocolIPv4: - v4CIDR = cidrBlock - v4Gateway = gateway - case kubeovnv1.ProtocolIPv6: - v6CIDR = cidrBlock - case kubeovnv1.ProtocolDual: - cidrBlocks := strings.Split(cidrBlock, ",") - gateways := strings.Split(gateway, ",") - v4CIDR, v6CIDR = cidrBlocks[0], cidrBlocks[1] - v4Gateway = gateways[0] - } - - dhcpOptionsUUIDs.DHCPv4OptionsUUID, err = c.updateDHCPv4Options(ls, v4CIDR, v4Gateway, dhcpV4OptionsStr, mtu) - if err != nil { - klog.Errorf("update dhcp options for switch %s failed: %v", ls, err) - return nil, err - } - dhcpOptionsUUIDs.DHCPv6OptionsUUID, err = c.updateDHCPv6Options(ls, v6CIDR, dhcpV6OptionsStr) - if err != nil { - klog.Errorf("update dhcp options for switch %s failed: %v", ls, err) - return nil, err - } - - } else { - if err = c.DeleteDHCPOptions(ls, kubeovnv1.ProtocolDual); err != nil { - klog.Errorf("delete dhcp options for switch %s failed: %v", ls, err) - return nil, err - } - } - return dhcpOptionsUUIDs, nil -} - -func (c *LegacyClient) DeleteDHCPOptionsByUUIDs(uuidList []string) (err error) { - for _, uuid := range uuidList { - _, err = c.ovnNbCommand("dhcp-options-del", uuid) - if err != nil { - klog.Errorf("delete dhcp options %s failed: %v", uuid, err) - return err - } - } - return nil -} - -func (c *LegacyClient) DeleteDHCPOptions(ls string, protocol string) error { - klog.V(4).Infof("delete dhcp options for switch %s protocol %s", ls, protocol) - dhcpOptionsList, err := c.ListDHCPOptions(true, ls, protocol) - if err != nil { - klog.Errorf("find dhcp options failed, %v", err) - return err - } - uuidToDeleteList := []string{} - for _, item := range dhcpOptionsList { - uuidToDeleteList = append(uuidToDeleteList, item.UUID) - } - - return c.DeleteDHCPOptionsByUUIDs(uuidToDeleteList) -} - -func (c *LegacyClient) GetNatIPInfo(uuid string) (string, error) { - var logical_ip string - - output, err := c.ovnNbCommand("--data=bare", "--format=csv", "--no-heading", "--columns=logical_ip", "list", "nat", uuid) - if err != nil { - klog.Errorf("failed to list nat, %v", err) - return logical_ip, err - } - lines := strings.Split(output, "\n") - - if len(lines) > 0 { - logical_ip = strings.TrimSpace(lines[0]) - } - return logical_ip, nil -} diff --git a/pkg/ovs/ovn-sbctl.go b/pkg/ovs/ovn-sbctl.go index 8a09326cd0a6..9b7fca27c559 100644 --- a/pkg/ovs/ovn-sbctl.go +++ b/pkg/ovs/ovn-sbctl.go @@ -51,6 +51,21 @@ func (c LegacyClient) ovnSbCommand(cmdArgs ...string) (string, error) { return trimCommandOutput(raw), nil } +func (c LegacyClient) GetVersion() (string, error) { + if c.Version != "" { + return c.Version, nil + } + output, err := c.ovnSbCommand("--version") + if err != nil { + return "", fmt.Errorf("failed to get version,%v", err) + } + lines := strings.Split(output, "\n") + if len(lines) > 0 { + c.Version = strings.Fields(lines[0])[1] + } + return c.Version, nil +} + func (c LegacyClient) DeleteChassisByNode(node string) error { chassis, err := c.GetChassis(node) if err != nil { diff --git a/pkg/ovs/ovn.go b/pkg/ovs/ovn.go index 8133015d6961..22c820a6d6e8 100644 --- a/pkg/ovs/ovn.go +++ b/pkg/ovs/ovn.go @@ -19,7 +19,6 @@ var ( // LegacyClient is the legacy ovn client type LegacyClient struct { - OvnNbAddress string OvnTimeout int OvnSbAddress string OvnICNbAddress string @@ -31,7 +30,6 @@ type LegacyClient struct { ClusterUdpSessionLoadBalancer string NodeSwitch string NodeSwitchCIDR string - ExternalGatewayType string Version string } @@ -59,11 +57,10 @@ const ( ) // NewLegacyClient init a legacy ovn client -func NewLegacyClient(ovnNbAddr string, ovnNbTimeout int, ovnSbAddr, clusterRouter, clusterTcpLoadBalancer, clusterUdpLoadBalancer, clusterTcpSessionLoadBalancer, clusterUdpSessionLoadBalancer, nodeSwitch, nodeSwitchCIDR string) *LegacyClient { +func NewLegacyClient(timeout int, ovnSbAddr, clusterRouter, clusterTcpLoadBalancer, clusterUdpLoadBalancer, clusterTcpSessionLoadBalancer, clusterUdpSessionLoadBalancer, nodeSwitch, nodeSwitchCIDR string) *LegacyClient { return &LegacyClient{ - OvnNbAddress: ovnNbAddr, OvnSbAddress: ovnSbAddr, - OvnTimeout: ovnNbTimeout, + OvnTimeout: timeout, ClusterRouter: clusterRouter, ClusterTcpLoadBalancer: clusterTcpLoadBalancer, ClusterUdpLoadBalancer: clusterUdpLoadBalancer,