From cf53cb55c5c0b0512cd10c29191fddc25c8b4f6a Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Sat, 13 Apr 2024 04:18:31 +0000 Subject: [PATCH] fix subnet provider validation Signed-off-by: zhangzujian --- pkg/controller/external_gw.go | 5 +- pkg/controller/gc.go | 6 +- pkg/controller/pod.go | 2 +- pkg/controller/subnet.go | 4 +- pkg/daemon/controller.go | 2 +- pkg/daemon/controller_linux.go | 2 +- pkg/daemon/controller_windows.go | 2 +- pkg/daemon/handler.go | 8 +- pkg/ovs/util.go | 3 +- pkg/util/subnet.go | 13 +++ pkg/util/validator_test.go | 148 ++++++++++++++-------------- pkg/webhook/static_ip.go | 2 +- test/e2e/framework/subnet.go | 2 +- test/e2e/ovn-vpc-nat-gw/e2e_test.go | 2 +- 14 files changed, 107 insertions(+), 94 deletions(-) create mode 100644 pkg/util/subnet.go diff --git a/pkg/controller/external_gw.go b/pkg/controller/external_gw.go index e797580cb26..123feeb33b9 100644 --- a/pkg/controller/external_gw.go +++ b/pkg/controller/external_gw.go @@ -13,6 +13,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" + kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" "github.com/kubeovn/kube-ovn/pkg/util" ) @@ -51,7 +52,7 @@ func (c *Controller) resyncExternalGateway() { return } klog.Infof("last external gw configmap: %v", lastExGwCM) - if (lastExGwCM["type"] == "distributed" && cm.Data["type"] == "centralized") || + if (lastExGwCM["type"] == kubeovnv1.GWDistributedType && cm.Data["type"] == kubeovnv1.GWCentralizedType) || lastExGwCM != nil && !reflect.DeepEqual(lastExGwCM["external-gw-nodes"], cm.Data["external-gw-nodes"]) { klog.Info("external gw nodes list changed, start to remove ovn external gw") if err := c.removeExternalGateway(); err != nil { @@ -228,7 +229,7 @@ func (c *Controller) getGatewayChassis(config map[string]string) ([]string, erro for _, node := range nodes { gwNodes = append(gwNodes, node.Name) } - if config["type"] != "distributed" { + if config["type"] != kubeovnv1.GWDistributedType { nodeNames := strings.Split(config["external-gw-nodes"], ",") for _, name := range nodeNames { name = strings.TrimSpace(name) diff --git a/pkg/controller/gc.go b/pkg/controller/gc.go index b32ad3f03dd..0f74cc28295 100644 --- a/pkg/controller/gc.go +++ b/pkg/controller/gc.go @@ -779,7 +779,7 @@ func (c *Controller) isOVNProvided(providerName string, pod *corev1.Pod) (bool, klog.Errorf("parse annotation logical switch %s error %v", ls, err) return false, err } - if !strings.HasSuffix(subnet.Spec.Provider, util.OvnProvider) { + if !isOvnSubnet(subnet) { return false, nil } return true, nil @@ -818,7 +818,7 @@ func (c *Controller) getVMLsps() []string { continue } for _, multiNet := range attachNets { - provider := fmt.Sprintf("%s.%s.ovn", multiNet.Name, multiNet.Namespace) + provider := fmt.Sprintf("%s.%s.%s", multiNet.Name, multiNet.Namespace, util.OvnProvider) vmLsp := ovs.PodNameToPortName(vm.Name, ns.Name, provider) vmLsps = append(vmLsps, vmLsp) } @@ -829,7 +829,7 @@ func (c *Controller) getVMLsps() []string { if len(items) != 2 { items = []string{vm.GetNamespace(), items[0]} } - provider := fmt.Sprintf("%s.%s.ovn", items[1], items[0]) + provider := fmt.Sprintf("%s.%s.%s", items[1], items[0], util.OvnProvider) vmLsp := ovs.PodNameToPortName(vm.Name, ns.Name, provider) vmLsps = append(vmLsps, vmLsp) } diff --git a/pkg/controller/pod.go b/pkg/controller/pod.go index 48589c9295e..dfd325804da 100644 --- a/pkg/controller/pod.go +++ b/pkg/controller/pod.go @@ -1607,7 +1607,7 @@ func (c *Controller) getPodAttachmentNet(pod *v1.Pod) ([]*kubeovnNet, error) { allowLiveMigration := false isDefault := util.IsDefaultNet(pod.Annotations[util.DefaultNetworkAnnotation], attach) - providerName = fmt.Sprintf("%s.%s.ovn", attach.Name, attach.Namespace) + providerName = fmt.Sprintf("%s.%s.%s", attach.Name, attach.Namespace, util.OvnProvider) if pod.Annotations[fmt.Sprintf(util.LiveMigrationAnnotationTemplate, providerName)] == "true" { allowLiveMigration = true } diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index 65799988466..fe5097bf53d 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -298,7 +298,7 @@ func (c *Controller) formatSubnet(subnet *kubeovnv1.Subnet) (*kubeovnv1.Subnet, changed = true } if subnet.Spec.Vpc == "" { - if subnet.Spec.Provider != "" && !strings.HasSuffix(subnet.Spec.Provider, util.OvnProvider) { + if !isOvnSubnet(subnet) { klog.Infof("subnet %s is not ovn subnet, no vpc", subnet.Name) } else { changed = true @@ -2220,7 +2220,7 @@ func (c *Controller) calcSubnetStatusIP(subnet *kubeovnv1.Subnet) (*kubeovnv1.Su } func isOvnSubnet(subnet *kubeovnv1.Subnet) bool { - return subnet.Spec.Provider == "" || subnet.Spec.Provider == util.OvnProvider || strings.HasSuffix(subnet.Spec.Provider, "ovn") + return util.IsOvnProvider(subnet.Spec.Provider) } func checkAndFormatsExcludeIPs(subnet *kubeovnv1.Subnet) bool { diff --git a/pkg/daemon/controller.go b/pkg/daemon/controller.go index 4bbb65bfd01..7404d6dc218 100644 --- a/pkg/daemon/controller.go +++ b/pkg/daemon/controller.go @@ -501,7 +501,7 @@ func (c *Controller) enqueuePod(oldObj, newObj interface{}) { return } for _, multiNet := range attachNets { - provider := fmt.Sprintf("%s.%s.ovn", multiNet.Name, multiNet.Namespace) + provider := fmt.Sprintf("%s.%s.%s", multiNet.Name, multiNet.Namespace, util.OvnProvider) if newPod.Annotations[fmt.Sprintf(util.AllocatedAnnotationTemplate, provider)] == "true" { if oldPod.Annotations[fmt.Sprintf(util.IngressRateAnnotationTemplate, provider)] != newPod.Annotations[fmt.Sprintf(util.IngressRateAnnotationTemplate, provider)] || oldPod.Annotations[fmt.Sprintf(util.EgressRateAnnotationTemplate, provider)] != newPod.Annotations[fmt.Sprintf(util.EgressRateAnnotationTemplate, provider)] || diff --git a/pkg/daemon/controller_linux.go b/pkg/daemon/controller_linux.go index 3e1462faedf..06315805fc0 100644 --- a/pkg/daemon/controller_linux.go +++ b/pkg/daemon/controller_linux.go @@ -560,7 +560,7 @@ func (c *Controller) handlePod(key string) error { return err } for _, multiNet := range attachNets { - provider := fmt.Sprintf("%s.%s.ovn", multiNet.Name, multiNet.Namespace) + provider := fmt.Sprintf("%s.%s.%s", multiNet.Name, multiNet.Namespace, util.OvnProvider) if pod.Annotations[fmt.Sprintf(util.VMTemplate, provider)] != "" { podName = pod.Annotations[fmt.Sprintf(util.VMTemplate, provider)] } diff --git a/pkg/daemon/controller_windows.go b/pkg/daemon/controller_windows.go index 6442c311743..7e245529b0b 100644 --- a/pkg/daemon/controller_windows.go +++ b/pkg/daemon/controller_windows.go @@ -183,7 +183,7 @@ func (c *Controller) handlePod(key string) error { return err } for _, multiNet := range attachNets { - provider := fmt.Sprintf("%s.%s.ovn", multiNet.Name, multiNet.Namespace) + provider := fmt.Sprintf("%s.%s.%s", multiNet.Name, multiNet.Namespace, util.OvnProvider) if pod.Annotations[fmt.Sprintf(util.VMTemplate, provider)] != "" { podName = pod.Annotations[fmt.Sprintf(util.VMTemplate, provider)] } diff --git a/pkg/daemon/handler.go b/pkg/daemon/handler.go index af042a11743..dd80a70fc97 100644 --- a/pkg/daemon/handler.go +++ b/pkg/daemon/handler.go @@ -46,7 +46,7 @@ func createCniServerHandler(config *Configuration, controller *Controller) *cniS } func (csh cniServerHandler) providerExists(provider string) (*kubeovnv1.Subnet, bool) { - if provider == "" || strings.HasSuffix(provider, util.OvnProvider) { + if util.IsOvnProvider(provider) { return nil, true } subnets, _ := csh.Controller.subnetsLister.List(labels.Everything()) @@ -184,7 +184,7 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon isDefaultRoute = ifName == "eth0" } - if isDefaultRoute && pod.Annotations[fmt.Sprintf(util.RoutedAnnotationTemplate, podRequest.Provider)] != "true" && strings.HasSuffix(podRequest.Provider, util.OvnProvider) { + if isDefaultRoute && pod.Annotations[fmt.Sprintf(util.RoutedAnnotationTemplate, podRequest.Provider)] != "true" && util.IsOvnProvider(podRequest.Provider) { klog.Infof("wait route ready for pod %s/%s provider %s", podRequest.PodNamespace, podRequest.PodName, podRequest.Provider) cniWaitRouteResult.WithLabelValues(nodeName).Inc() time.Sleep(1 * time.Second) @@ -217,7 +217,7 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon return } - if isDefaultRoute && pod.Annotations[fmt.Sprintf(util.RoutedAnnotationTemplate, podRequest.Provider)] != "true" && strings.HasSuffix(podRequest.Provider, util.OvnProvider) { + if isDefaultRoute && pod.Annotations[fmt.Sprintf(util.RoutedAnnotationTemplate, podRequest.Provider)] != "true" && util.IsOvnProvider(podRequest.Provider) { err := fmt.Errorf("route is not ready for pod %s/%s provider %s, please see kube-ovn-controller logs to find errors", pod.Namespace, pod.Name, podRequest.Provider) klog.Error(err) if err := resp.WriteHeaderAndEntity(http.StatusInternalServerError, request.CniResponse{Err: err.Error()}); err != nil { @@ -451,7 +451,7 @@ func (csh cniServerHandler) handleDel(req *restful.Request, resp *restful.Respon return } - if pod.Annotations != nil && (podRequest.Provider == util.OvnProvider || podRequest.CniType == util.CniTypeName) { + if pod.Annotations != nil && (util.IsOvnProvider(podRequest.Provider) || podRequest.CniType == util.CniTypeName) { subnet := pod.Annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, podRequest.Provider)] if subnet != "" { ip := pod.Annotations[fmt.Sprintf(util.IPAddressAnnotationTemplate, podRequest.Provider)] diff --git a/pkg/ovs/util.go b/pkg/ovs/util.go index e16daf3fca2..bcb821c6416 100644 --- a/pkg/ovs/util.go +++ b/pkg/ovs/util.go @@ -27,8 +27,7 @@ func GetLocalnetName(subnet string) string { } func trimCommandOutput(raw []byte) string { - output := strings.TrimSpace(string(raw)) - return strings.Trim(output, "\"") + return strings.Trim(strings.TrimSpace(string(raw)), `"`) } func LogicalRouterPortName(lr, ls string) string { diff --git a/pkg/util/subnet.go b/pkg/util/subnet.go new file mode 100644 index 00000000000..137ef36c109 --- /dev/null +++ b/pkg/util/subnet.go @@ -0,0 +1,13 @@ +package util + +import "strings" + +func IsOvnProvider(provider string) bool { + if provider == "" || provider == OvnProvider { + return true + } + if fields := strings.Split(provider, "."); len(fields) == 3 && fields[2] == OvnProvider { + return true + } + return false +} diff --git a/pkg/util/validator_test.go b/pkg/util/validator_test.go index 164dc7131f9..600b784c575 100644 --- a/pkg/util/validator_test.go +++ b/pkg/util/validator_test.go @@ -40,13 +40,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, GatewayNode: "", NatOutgoing: false, ExternalEgressGateway: "", @@ -80,13 +80,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.17.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -102,13 +102,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "127.0.0.1/8", Gateway: "127.0.0.1", ExcludeIps: []string{"127.0.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -124,13 +124,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "127.0.1/8", Gateway: "127.0.0.1", ExcludeIps: []string{"127.0.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -146,13 +146,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "127.0.1/8", Gateway: "127.0.0.1", ExcludeIps: []string{"127.0.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -168,13 +168,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1..10.16.0.10..10.16.0.12"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -190,13 +190,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1.."}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -212,13 +212,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.1..10.16.10"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -234,13 +234,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.2..10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -256,13 +256,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1..10.16.0.10"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, Private: true, AllowSubnets: []string{"10.18.0/16"}, }, @@ -280,12 +280,12 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1..10.16.0.10"}, - Provider: "ovn", + Provider: OvnProvider, GatewayType: "damn", }, Status: kubeovnv1.SubnetStatus{}, @@ -302,13 +302,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.20.0.0/16", Gateway: "10.20.0.1", ExcludeIps: []string{"10.20.0.1..10.20.0.10"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -324,13 +324,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1..10.16.0.10"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, ExternalEgressGateway: "192.178.2.1", NatOutgoing: true, }, @@ -348,13 +348,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.2..10.16.0.10"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, ExternalEgressGateway: "192.178.2.1,192.178.2.2,192.178.2.3", NatOutgoing: false, }, @@ -372,13 +372,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.2..10.16.0.10"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, ExternalEgressGateway: "192.178.2.1,192.178..2", NatOutgoing: false, }, @@ -396,13 +396,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, ExternalEgressGateway: "192.178.2.1,fd00:10:16::1", }, Status: kubeovnv1.SubnetStatus{}, @@ -419,13 +419,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1..10.16.0.10"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, Vips: []string{"10.17.2.1"}, }, Status: kubeovnv1.SubnetStatus{}, @@ -442,13 +442,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -464,13 +464,13 @@ func TestValidateSubnet(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, }, Status: kubeovnv1.SubnetStatus{}, }, @@ -681,13 +681,13 @@ func TestValidateCidrConflict(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.17.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, Vlan: "123", }, Status: kubeovnv1.SubnetStatus{}, @@ -701,13 +701,13 @@ func TestValidateCidrConflict(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster11", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.17.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, Vlan: "1234", }, Status: kubeovnv1.SubnetStatus{}, @@ -725,13 +725,13 @@ func TestValidateCidrConflict(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.17.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, Vlan: "123", }, Status: kubeovnv1.SubnetStatus{}, @@ -745,13 +745,13 @@ func TestValidateCidrConflict(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.17.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, Vlan: "123", }, Status: kubeovnv1.SubnetStatus{}, @@ -769,13 +769,13 @@ func TestValidateCidrConflict(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.16.0.0/16", Gateway: "10.16.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, Vlan: "123", ExternalEgressGateway: "12.12.123.12", PolicyRoutingTableID: 111, @@ -791,13 +791,13 @@ func TestValidateCidrConflict(t *testing.T) { Spec: kubeovnv1.SubnetSpec{ Default: true, Vpc: "ovn-cluster", - Protocol: "IPv4", + Protocol: kubeovnv1.ProtocolIPv4, Namespaces: nil, CIDRBlock: "10.17.0.0/16", Gateway: "10.17.0.1", ExcludeIps: []string{"10.16.0.1"}, - Provider: "ovn", - GatewayType: "distributed", + Provider: OvnProvider, + GatewayType: kubeovnv1.GWDistributedType, Vlan: "123", ExternalEgressGateway: "12.12.123.12", PolicyRoutingTableID: 111, diff --git a/pkg/webhook/static_ip.go b/pkg/webhook/static_ip.go index 21c286813af..7083897996f 100644 --- a/pkg/webhook/static_ip.go +++ b/pkg/webhook/static_ip.go @@ -145,7 +145,7 @@ func (v *ValidatingHook) allowLiveMigration(_ context.Context, annotations map[s for _, attach := range multusNets { // allocate kubeovn network - providerName := fmt.Sprintf("%s.%s.ovn", attach.Name, attach.Namespace) + providerName := fmt.Sprintf("%s.%s.%s", attach.Name, attach.Namespace, util.OvnProvider) if annotations[fmt.Sprintf(util.LiveMigrationAnnotationTemplate, providerName)] == "true" { return true } diff --git a/test/e2e/framework/subnet.go b/test/e2e/framework/subnet.go index ff3b4b2be65..08feb13bab5 100644 --- a/test/e2e/framework/subnet.go +++ b/test/e2e/framework/subnet.go @@ -260,7 +260,7 @@ func MakeSubnet(name, vlan, cidr, gateway, vpc, provider string, excludeIPs, gat Namespaces: namespaces, }, } - if provider == "" || strings.HasSuffix(provider, util.OvnProvider) { + if util.IsOvnProvider(provider) { if len(gatewayNodes) != 0 { subnet.Spec.GatewayType = apiv1.GWCentralizedType } else { diff --git a/test/e2e/ovn-vpc-nat-gw/e2e_test.go b/test/e2e/ovn-vpc-nat-gw/e2e_test.go index 63de5016b93..45d58e09bcf 100644 --- a/test/e2e/ovn-vpc-nat-gw/e2e_test.go +++ b/test/e2e/ovn-vpc-nat-gw/e2e_test.go @@ -935,7 +935,7 @@ var _ = framework.Describe("[group:ovn-vpc-nat-gw]", func() { cmData = map[string]string{ "enable-external-gw": "true", "external-gw-nodes": externalGwNodes, - "type": "distributed", + "type": kubeovnv1.GWDistributedType, "external-gw-nic": "eth1", "external-gw-addr": strings.Join(cidr, ","), }