From 70fbbecc43aa9db9d015eef4a8fbacd60d47de68 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Fri, 20 Aug 2021 18:09:42 +0800 Subject: [PATCH] remove subnet's `spec.underlayGateway` field --- dist/images/install-pre-1.16.sh | 7 +------ dist/images/install.sh | 7 +------ dist/images/kubectl-ko | 5 +---- docs/OpenstackOnKubernetes.md | 6 ------ docs/multi-nic.md | 2 +- docs/subnet.md | 1 - docs/vlan.md | 4 ---- docs/vpc.md | 15 ++------------- pkg/apis/kubeovn/v1/types.go | 3 +-- pkg/controller/init.go | 1 - pkg/controller/node.go | 2 +- pkg/controller/pod.go | 2 +- pkg/controller/subnet.go | 11 +++++------ pkg/daemon/controller.go | 2 +- pkg/daemon/gateway.go | 2 +- pkg/ovs/ovn-nbctl.go | 8 ++++---- test/e2e/e2e_suite_test.go | 11 +++++------ test/e2e/subnet/normal.go | 1 - yamls/crd-pre-1.16.yaml | 2 -- yamls/crd.yaml | 2 -- 20 files changed, 25 insertions(+), 69 deletions(-) diff --git a/dist/images/install-pre-1.16.sh b/dist/images/install-pre-1.16.sh index 6a3d41dd75e..e2b9c64ce38 100644 --- a/dist/images/install-pre-1.16.sh +++ b/dist/images/install-pre-1.16.sh @@ -505,8 +505,6 @@ spec: type: boolean vlan: type: string - underlayGateway: - type: boolean disableGatewayCheck: type: boolean disableInterConnection: @@ -2342,11 +2340,8 @@ trace(){ exit 1 fi - vlan=$(kubectl get subnet "$ls" -o jsonpath={.spec.vlan}) - underlayGateway=$(kubectl get subnet "$ls" -o jsonpath={.spec.underlayGateway}) - gwMac="" - if [ ! -z "$vlan" -a "$underlayGateway" = "true" ]; then + if [ ! -z "$(kubectl get subnet $ls -o jsonpath={.spec.vlan})" ]; then ovnCni=$(kubectl get pod -n $KUBE_OVN_NS -o wide | grep -w kube-ovn-cni | grep " $nodeName " | awk '{print $1}') if [ -z "$ovnCni" ]; then echo "No kube-ovn-cni Pod running on node $nodeName" diff --git a/dist/images/install.sh b/dist/images/install.sh index 0c3066f232f..cb17428f2fa 100755 --- a/dist/images/install.sh +++ b/dist/images/install.sh @@ -532,8 +532,6 @@ spec: type: boolean vlan: type: string - underlayGateway: - type: boolean disableGatewayCheck: type: boolean disableInterConnection: @@ -2386,11 +2384,8 @@ trace(){ exit 1 fi - vlan=$(kubectl get subnet "$ls" -o jsonpath={.spec.vlan}) - underlayGateway=$(kubectl get subnet "$ls" -o jsonpath={.spec.underlayGateway}) - gwMac="" - if [ ! -z "$vlan" -a "$underlayGateway" = "true" ]; then + if [ ! -z "$(kubectl get subnet $ls -o jsonpath={.spec.vlan})" ]; then ovnCni=$(kubectl get pod -n $KUBE_OVN_NS -o wide | grep -w kube-ovn-cni | grep " $nodeName " | awk '{print $1}') if [ -z "$ovnCni" ]; then echo "No kube-ovn-cni Pod running on node $nodeName" diff --git a/dist/images/kubectl-ko b/dist/images/kubectl-ko index 1957a0ae3d6..b63e148669a 100644 --- a/dist/images/kubectl-ko +++ b/dist/images/kubectl-ko @@ -86,11 +86,8 @@ trace(){ exit 1 fi - vlan=$(kubectl get subnet "$ls" -o jsonpath={.spec.vlan}) - underlayGateway=$(kubectl get subnet "$ls" -o jsonpath={.spec.underlayGateway}) - gwMac="" - if [ ! -z "$vlan" -a "$underlayGateway" = "true" ]; then + if [ ! -z "$(kubectl get subnet $ls -o jsonpath={.spec.vlan})" ]; then ovnCni=$(kubectl get pod -n $KUBE_OVN_NS -o wide | grep -w kube-ovn-cni | grep " $nodeName " | awk '{print $1}') if [ -z "$ovnCni" ]; then echo "No kube-ovn-cni Pod running on node $nodeName" diff --git a/docs/OpenstackOnKubernetes.md b/docs/OpenstackOnKubernetes.md index 09b7a645fed..6b9819dd30b 100644 --- a/docs/OpenstackOnKubernetes.md +++ b/docs/OpenstackOnKubernetes.md @@ -138,13 +138,7 @@ spec: namespaces: - net2 cidrBlock: 12.0.1.0/24 - default: false - gatewayType: distributed natOutgoing: false - private: false - protocol: IPv4 - provider: ovn - underlayGateway: false ``` 4. Add pod and test. diff --git a/docs/multi-nic.md b/docs/multi-nic.md index 197ab3d6c82..a10fc1e86f4 100644 --- a/docs/multi-nic.md +++ b/docs/multi-nic.md @@ -77,7 +77,7 @@ spec: - 172.17.0.1..172.17.0.10 ``` -Other options like gatewayType, gatewayNode, private, allowSubnets, vlan, underlayGateway, natOutgoing are not available for attachment network. +Other options like gatewayType, gatewayNode, private, allowSubnets, vlan, natOutgoing are not available for attachment network. ### Create Pod with multi network diff --git a/docs/subnet.md b/docs/subnet.md index ebad1fe0ee2..e4f03536a26 100644 --- a/docs/subnet.md +++ b/docs/subnet.md @@ -66,7 +66,6 @@ Since kube-ovn v1.8.0, kube-ovn support using designative egress ip on node, the ## Advance Options - `vlan`: if enable vlan network, use this field to specific which vlan the subnet should bind to. -- `underlayGateway`: if enable vlan network, use this field to use underlay network gateway directly, instead of ovs virtual gateway - `externalEgressGateway`: External egress gateway address. When set, egress traffic is redirected to the external gateway through gateway node(s) by policy-based routing. Conflict with `natOutgoing`. - `policyRoutingPriority`/`policyRoutingTableID`: Priority & table ID used in policy-based routing. Required when `externalEgressGateway` is set. NOTICE: `policyRoutingTableID` MUST be unique. - `disableGatewayCheck`: By default Kube-OVN checks Pod's network by sending ICMP request to the subnet's gateway. Set it to `true` if the subnet is in underlay mode and the physical gateway does not respond to ICMP requests. diff --git a/docs/vlan.md b/docs/vlan.md index b9227ea2335..f190ca34a1a 100644 --- a/docs/vlan.md +++ b/docs/vlan.md @@ -92,10 +92,8 @@ metadata: name: product spec: cidrBlock: 10.100.0.0/16 - default: false gateway: 10.100.0.1 vlan: product - underlayGateway: true ``` ### Dynamical Management @@ -150,10 +148,8 @@ metadata: name: subnet1 spec: cidrBlock: 10.100.0.0/16 - default: false gateway: 10.100.0.1 vlan: vlan1 - underlayGateway: true ``` ### Install Hybrid mode diff --git a/docs/vpc.md b/docs/vpc.md index e4003e1b7f5..e88ff7fe297 100644 --- a/docs/vpc.md +++ b/docs/vpc.md @@ -36,12 +36,7 @@ spec: - ns1 cidrBlock: 10.0.1.0/24 default: true - gatewayType: distributed natOutgoing: false - private: false - protocol: IPv4 - provider: ovn - underlayGateway: false --- kind: Subnet apiVersion: kubeovn.io/v1 @@ -50,13 +45,7 @@ metadata: spec: vpc: test-vpc-2 cidrBlock: 10.0.1.0/24 - default: false - gatewayType: distributed natOutgoing: false - private: false - protocol: IPv4 - provider: ovn - underlayGateway: false ``` In the examples above, two subnet in different VPCs can use same IP space @@ -70,7 +59,7 @@ apiVersion: v1 kind: Pod metadata: annotations: - ovn.kubernetes.io/logical_switch: ne1 + ovn.kubernetes.io/logical_switch: net1 namespace: default name: vpc1-pod --- @@ -78,7 +67,7 @@ apiVersion: v1 kind: Pod metadata: annotations: - ovn.kubernetes.io/logical_switch: ne2 + ovn.kubernetes.io/logical_switch: net2 namespace: default name: vpc2-pod ``` diff --git a/pkg/apis/kubeovn/v1/types.go b/pkg/apis/kubeovn/v1/types.go index 1ef114a8ae9..8ed7757bb83 100644 --- a/pkg/apis/kubeovn/v1/types.go +++ b/pkg/apis/kubeovn/v1/types.go @@ -118,8 +118,7 @@ type SubnetSpec struct { Private bool `json:"private"` AllowSubnets []string `json:"allowSubnets,omitempty"` - Vlan string `json:"vlan,omitempty"` - UnderlayGateway bool `json:"underlayGateway"` + Vlan string `json:"vlan,omitempty"` DisableGatewayCheck bool `json:"disableGatewayCheck"` DisableInterConnection bool `json:"disableInterConnection"` diff --git a/pkg/controller/init.go b/pkg/controller/init.go index e9374196c88..0b9511fb923 100644 --- a/pkg/controller/init.go +++ b/pkg/controller/init.go @@ -119,7 +119,6 @@ func (c *Controller) initDefaultLogicalSwitch() error { } if c.config.NetworkType == util.NetworkTypeVlan { defaultSubnet.Spec.Vlan = c.config.DefaultVlanName - defaultSubnet.Spec.UnderlayGateway = true } _, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Create(context.Background(), &defaultSubnet, metav1.CreateOptions{}) diff --git a/pkg/controller/node.go b/pkg/controller/node.go index 0922eb30b0b..27da9ea6be9 100644 --- a/pkg/controller/node.go +++ b/pkg/controller/node.go @@ -514,7 +514,7 @@ func (c *Controller) checkGatewayReady() error { } for _, subnet := range subnetList { - if subnet.Spec.UnderlayGateway || subnet.Spec.GatewayType != kubeovnv1.GWCentralizedType || subnet.Spec.GatewayNode == "" { + if subnet.Spec.Vlan != "" || subnet.Spec.GatewayType != kubeovnv1.GWCentralizedType || subnet.Spec.GatewayNode == "" { continue } diff --git a/pkg/controller/pod.go b/pkg/controller/pod.go index cd9daf9a7dd..9cd127536c8 100644 --- a/pkg/controller/pod.go +++ b/pkg/controller/pod.go @@ -679,7 +679,7 @@ func (c *Controller) handleUpdatePod(key string) error { break } - if podIP != "" && subnet.Spec.Vpc == util.DefaultVpc && !subnet.Spec.UnderlayGateway { + if podIP != "" && subnet.Spec.Vlan == "" && subnet.Spec.Vpc == util.DefaultVpc { if pod.Annotations[util.EipAnnotation] != "" || pod.Annotations[util.SnatAnnotation] != "" { cm, err := c.configMapsLister.ConfigMaps("kube-system").Get(util.ExternalGatewayConfig) if err != nil { diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index a888b8407c6..65e9caced31 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -88,7 +88,6 @@ func (c *Controller) enqueueUpdateSubnet(old, new interface{}) { !reflect.DeepEqual(oldSubnet.Spec.Namespaces, newSubnet.Spec.Namespaces) || oldSubnet.Spec.GatewayType != newSubnet.Spec.GatewayType || oldSubnet.Spec.GatewayNode != newSubnet.Spec.GatewayNode || - oldSubnet.Spec.UnderlayGateway != newSubnet.Spec.UnderlayGateway || oldSubnet.Spec.Gateway != newSubnet.Spec.Gateway || !reflect.DeepEqual(oldSubnet.Spec.ExcludeIps, newSubnet.Spec.ExcludeIps) || oldSubnet.Spec.Vlan != newSubnet.Spec.Vlan { @@ -551,7 +550,7 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error { klog.Errorf("failed to list nodes %v", err) return err } - if subnet.Spec.Vpc != util.DefaultVpc && subnet.Spec.Vlan != "" && !subnet.Spec.UnderlayGateway { + if subnet.Spec.Vlan != "" && subnet.Spec.Vpc != util.DefaultVpc { for _, node := range nodes { for _, addr := range node.Status.Addresses { if addr.Type == v1.NodeInternalIP && util.CIDRContainIP(subnet.Spec.CIDRBlock, addr.Address) { @@ -574,17 +573,17 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error { if !exist { subnet.Status.EnsureStandardConditions() // If multiple namespace use same ls name, only first one will success - if err := c.ovnClient.CreateLogicalSwitch(subnet.Name, vpc.Status.Router, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps, subnet.Spec.UnderlayGateway, vpc.Status.Default); err != nil { + if err := c.ovnClient.CreateLogicalSwitch(subnet.Name, vpc.Status.Router, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps, subnet.Spec.Vlan != "", vpc.Status.Default); err != nil { c.patchSubnetStatus(subnet, "CreateLogicalSwitchFailed", err.Error()) return err } } else { // logical switch exists, only update other_config - if err := c.ovnClient.SetLogicalSwitchConfig(subnet.Name, subnet.Spec.UnderlayGateway, vpc.Status.Router, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps); err != nil { + if err := c.ovnClient.SetLogicalSwitchConfig(subnet.Name, subnet.Spec.Vlan != "", vpc.Status.Router, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps); err != nil { c.patchSubnetStatus(subnet, "SetLogicalSwitchConfigFailed", err.Error()) return err } - if subnet.Spec.UnderlayGateway { + if subnet.Spec.Vlan != "" { if err := c.ovnClient.RemoveRouterPort(subnet.Name, vpc.Status.Router); err != nil { klog.Errorf("failed to remove router port from %s, %v", subnet.Name, err) return err @@ -869,7 +868,7 @@ func (c *Controller) reconcileGateway(subnet *kubeovnv1.Subnet) error { return err } - if subnet.Spec.UnderlayGateway { + if subnet.Spec.Vlan != "" { for _, pod := range pods { if pod.Annotations[util.LogicalSwitchAnnotation] == subnet.Name && pod.Annotations[util.IpAddressAnnotation] != "" { if err := c.deleteStaticRoute(pod.Annotations[util.IpAddressAnnotation], c.config.ClusterRouter, subnet); err != nil { diff --git a/pkg/daemon/controller.go b/pkg/daemon/controller.go index 72cc3c15fb3..9a32af3a43d 100644 --- a/pkg/daemon/controller.go +++ b/pkg/daemon/controller.go @@ -630,7 +630,7 @@ func (c *Controller) reconcileRouters(event subnetEvent) error { cidrs := make([]string, 0, len(subnets)*2) for _, subnet := range subnets { - if subnet.Spec.Vpc != util.DefaultVpc || !subnet.Status.IsReady() || subnet.Spec.UnderlayGateway { + if subnet.Spec.Vlan != "" || subnet.Spec.Vpc != util.DefaultVpc || !subnet.Status.IsReady() { continue } diff --git a/pkg/daemon/gateway.go b/pkg/daemon/gateway.go index 7b8f24006f6..ffd38e7fd7a 100644 --- a/pkg/daemon/gateway.go +++ b/pkg/daemon/gateway.go @@ -921,7 +921,7 @@ func (c *Controller) getEgressNatIpByNode(nodeName string) (map[string]string, e } for _, subnet := range subnetList { - if subnet.Spec.UnderlayGateway || subnet.Spec.GatewayType != kubeovnv1.GWCentralizedType || subnet.Spec.GatewayNode == "" || !util.GatewayContains(subnet.Spec.GatewayNode, nodeName) { + if subnet.Spec.Vlan != "" || subnet.Spec.GatewayType != kubeovnv1.GWCentralizedType || subnet.Spec.GatewayNode == "" || !util.GatewayContains(subnet.Spec.GatewayNode, nodeName) { continue } diff --git a/pkg/ovs/ovn-nbctl.go b/pkg/ovs/ovn-nbctl.go index 338e78cc475..fffe766761d 100644 --- a/pkg/ovs/ovn-nbctl.go +++ b/pkg/ovs/ovn-nbctl.go @@ -206,7 +206,7 @@ func (c Client) ListPodLogicalSwitchPorts(pod, namespace string) ([]string, erro return result, nil } -func (c Client) SetLogicalSwitchConfig(ls string, isUnderlayGW bool, lr, protocol, subnet, gateway string, excludeIps []string) error { +func (c Client) SetLogicalSwitchConfig(ls string, underlay bool, lr, protocol, subnet, gateway string, excludeIps []string) error { var err error cidrBlocks := strings.Split(subnet, ",") mask := strings.Split(cidrBlocks[0], "/")[1] @@ -239,7 +239,7 @@ func (c Client) SetLogicalSwitchConfig(ls string, isUnderlayGW bool, lr, protoco "set", "logical_switch", ls, fmt.Sprintf("other_config:ipv6_prefix=%s", strings.Split(cidrBlocks[1], "/")[0]), "--", "set", "logical_switch", ls, fmt.Sprintf("other_config:exclude_ips=%s", strings.Join(excludeIps, " "))} } - if !isUnderlayGW { + if !underlay { cmd = append(cmd, []string{"--", "set", "logical_router_port", fmt.Sprintf("%s-%s", lr, ls), fmt.Sprintf("networks=%s", networks)}...) } @@ -254,7 +254,7 @@ func (c Client) SetLogicalSwitchConfig(ls string, isUnderlayGW bool, lr, protoco } // CreateLogicalSwitch create logical switch in ovn, connect it to router and apply tcp/udp lb rules -func (c Client) CreateLogicalSwitch(ls, lr, protocol, subnet, gateway string, excludeIps []string, underlayGateway, defaultVpc bool) error { +func (c Client) CreateLogicalSwitch(ls, lr, protocol, subnet, gateway string, excludeIps []string, underlay, defaultVpc bool) error { var err error switch protocol { case kubeovnv1.ProtocolIPv4: @@ -287,7 +287,7 @@ func (c Client) CreateLogicalSwitch(ls, lr, protocol, subnet, gateway string, ex ip := util.GetIpAddrWithMask(gateway, subnet) mac := util.GenerateMac() - if !underlayGateway { + if !underlay { if err := c.createRouterPort(ls, lr, ip, mac); err != nil { klog.Errorf("failed to connect switch %s to router, %v", ls, err) return err diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index aec9ee27aab..65987c6790b 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -235,12 +235,11 @@ var _ = SynchronizedBeforeSuite(func() []byte { Labels: map[string]string{"e2e": "true"}, }, Spec: kubeovn.SubnetSpec{ - CIDRBlock: underlayCIDR, - Gateway: underlayGateway, - ExcludeIps: underlayNodeIPs, - Vlan: vlan.Name, - UnderlayGateway: true, - Namespaces: []string{underlay.Namespace}, + CIDRBlock: underlayCIDR, + Gateway: underlayGateway, + ExcludeIps: underlayNodeIPs, + Vlan: vlan.Name, + Namespaces: []string{underlay.Namespace}, }, } if _, err = f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), &subnet, metav1.CreateOptions{}); err != nil { diff --git a/test/e2e/subnet/normal.go b/test/e2e/subnet/normal.go index f5a8fb35d46..3607cf79630 100644 --- a/test/e2e/subnet/normal.go +++ b/test/e2e/subnet/normal.go @@ -623,7 +623,6 @@ var _ = Describe("[Subnet]", func() { Spec: kubeovn.SubnetSpec{ CIDRBlock: "11.17.0.0/16", Namespaces: []string{namespace.Name}, - UnderlayGateway: true, DisableGatewayCheck: true, }, } diff --git a/yamls/crd-pre-1.16.yaml b/yamls/crd-pre-1.16.yaml index 66cebda9cc0..da8882cc4d9 100644 --- a/yamls/crd-pre-1.16.yaml +++ b/yamls/crd-pre-1.16.yaml @@ -187,8 +187,6 @@ spec: type: boolean vlan: type: string - underlayGateway: - type: boolean disableGatewayCheck: type: boolean disableInterConnection: diff --git a/yamls/crd.yaml b/yamls/crd.yaml index 60c47b344f6..563cebf7387 100644 --- a/yamls/crd.yaml +++ b/yamls/crd.yaml @@ -205,8 +205,6 @@ spec: type: boolean vlan: type: string - underlayGateway: - type: boolean disableGatewayCheck: type: boolean disableInterConnection: