Skip to content

Commit

Permalink
u2o feature merge to 1.10 (#2227)
Browse files Browse the repository at this point in the history
  • Loading branch information
changluyi committed Jan 5, 2023
1 parent c92af9b commit 4320301
Show file tree
Hide file tree
Showing 15 changed files with 465 additions and 40 deletions.
10 changes: 10 additions & 0 deletions Makefile
Expand Up @@ -329,6 +329,16 @@ kind-install-underlay-ipv4: kind-disable-hairpin kind-load-image kind-untaint-co
ENABLE_VLAN=true VLAN_NIC=eth0 bash
kubectl describe no

.PHONY: kind-install-underlay-u2o-interconnection-dual
kind-install-underlay-u2o-interconnection-dual: kind-disable-hairpin kind-load-image kind-untaint-control-plane
$(call docker_network_info,kind)
@sed -e 's@^[[:space:]]*POD_CIDR=.*@POD_CIDR="$(KIND_IPV4_SUBNET),$(KIND_IPV6_SUBNET)"@' \
-e 's@^[[:space:]]*POD_GATEWAY=.*@POD_GATEWAY="$(KIND_IPV4_GATEWAY),$(KIND_IPV6_GATEWAY)"@' \
-e 's@^[[:space:]]*EXCLUDE_IPS=.*@EXCLUDE_IPS="$(KIND_IPV4_EXCLUDE_IPS),$(KIND_IPV6_EXCLUDE_IPS)"@' \
-e 's@^VLAN_ID=.*@VLAN_ID="0"@' \
dist/images/install.sh | \
ENABLE_SSL=true DUAL_STACK=true ENABLE_VLAN=true VLAN_NIC=eth0 U2O_INTERCONNECTION=true bash

.PHONY: kind-install-underlay-hairpin-ipv4
kind-install-underlay-hairpin-ipv4: kind-enable-hairpin kind-load-image kind-untaint-control-plane
$(call docker_network_info,kind)
Expand Down
9 changes: 9 additions & 0 deletions dist/images/install.sh
Expand Up @@ -7,6 +7,7 @@ ENABLE_SSL=${ENABLE_SSL:-false}
ENABLE_VLAN=${ENABLE_VLAN:-false}
CHECK_GATEWAY=${CHECK_GATEWAY:-true}
LOGICAL_GATEWAY=${LOGICAL_GATEWAY:-false}
U2O_INTERCONNECTION=${U2O_INTERCONNECTION:-false}
ENABLE_MIRROR=${ENABLE_MIRROR:-false}
VLAN_NIC=${VLAN_NIC:-}
HW_OFFLOAD=${HW_OFFLOAD:-false}
Expand Down Expand Up @@ -942,6 +943,9 @@ spec:
- name: ExcludeIPs
type: string
jsonPath: .spec.excludeIps
- name: U2OInterconnectionIP
type: string
jsonPath: .status.u2oInterconnectionIP
schema:
openAPIV3Schema:
type: object
Expand All @@ -963,6 +967,8 @@ spec:
type: string
dhcpV6OptionsUUID:
type: string
u2oInterconnectionIP:
type: string
conditions:
type: array
items:
Expand Down Expand Up @@ -1083,6 +1089,8 @@ spec:
- allow
- drop
- reject
u2oInterconnection:
type: boolean
scope: Cluster
names:
plural: subnets
Expand Down Expand Up @@ -2585,6 +2593,7 @@ spec:
- --default-gateway=$POD_GATEWAY
- --default-gateway-check=$CHECK_GATEWAY
- --default-logical-gateway=$LOGICAL_GATEWAY
- --default-u2o-interconnection=$U2O_INTERCONNECTION
- --default-exclude-ips=$EXCLUDE_IPS
- --node-switch-cidr=$JOIN_CIDR
- --service-cluster-ip-range=$SVC_CIDR
Expand Down
21 changes: 12 additions & 9 deletions pkg/apis/kubeovn/v1/types.go
Expand Up @@ -138,6 +138,8 @@ type SubnetSpec struct {
IPv6RAConfigs string `json:"ipv6RAConfigs,omitempty"`

Acls []Acl `json:"acls,omitempty"`

U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
}

type Acl struct {
Expand Down Expand Up @@ -178,15 +180,16 @@ type SubnetStatus struct {
// +patchStrategy=merge
Conditions []SubnetCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`

AvailableIPs float64 `json:"availableIPs"`
UsingIPs float64 `json:"usingIPs"`
V4AvailableIPs float64 `json:"v4availableIPs"`
V4UsingIPs float64 `json:"v4usingIPs"`
V6AvailableIPs float64 `json:"v6availableIPs"`
V6UsingIPs float64 `json:"v6usingIPs"`
ActivateGateway string `json:"activateGateway"`
DHCPv4OptionsUUID string `json:"dhcpV4OptionsUUID"`
DHCPv6OptionsUUID string `json:"dhcpV6OptionsUUID"`
AvailableIPs float64 `json:"availableIPs"`
UsingIPs float64 `json:"usingIPs"`
V4AvailableIPs float64 `json:"v4availableIPs"`
V4UsingIPs float64 `json:"v4usingIPs"`
V6AvailableIPs float64 `json:"v6availableIPs"`
V6UsingIPs float64 `json:"v6usingIPs"`
ActivateGateway string `json:"activateGateway"`
DHCPv4OptionsUUID string `json:"dhcpV4OptionsUUID"`
DHCPv6OptionsUUID string `json:"dhcpV6OptionsUUID"`
U2OInterconnectionIP string `json:"u2oInterconnectionIP"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
16 changes: 10 additions & 6 deletions pkg/controller/config.go
Expand Up @@ -37,12 +37,13 @@ type Configuration struct {
KubeFactoryClient kubernetes.Interface
KubeOvnFactoryClient clientset.Interface

DefaultLogicalSwitch string
DefaultCIDR string
DefaultGateway string
DefaultExcludeIps string
DefaultGatewayCheck bool
DefaultLogicalGateway bool
DefaultLogicalSwitch string
DefaultCIDR string
DefaultGateway string
DefaultExcludeIps string
DefaultGatewayCheck bool
DefaultLogicalGateway bool
DefaultU2OInterconnection bool

ClusterRouter string
NodeSwitch string
Expand Down Expand Up @@ -102,6 +103,8 @@ func ParseFlags() (*Configuration, error) {
argDefaultLogicalGateway = pflag.Bool("default-logical-gateway", false, "Create a logical gateway for the default subnet instead of using underlay gateway. Take effect only when the default subnet is in underlay mode. (default false)")
argDefaultExcludeIps = pflag.String("default-exclude-ips", "", "Exclude ips in default switch (default gateway address)")

argDefaultU2OInterconnection = pflag.Bool("default-u2o-interconnection", false, "usage for underlay to overlay interconnection")

argClusterRouter = pflag.String("cluster-router", util.DefaultVpc, "The router name for cluster router")
argNodeSwitch = pflag.String("node-switch", "join", "The name of node gateway switch which help node to access pod network")
argNodeSwitchCIDR = pflag.String("node-switch-cidr", "100.64.0.0/16", "The cidr for node switch")
Expand Down Expand Up @@ -168,6 +171,7 @@ func ParseFlags() (*Configuration, error) {
DefaultGateway: *argDefaultGateway,
DefaultGatewayCheck: *argDefaultGatewayCheck,
DefaultLogicalGateway: *argDefaultLogicalGateway,
DefaultU2OInterconnection: *argDefaultU2OInterconnection,
DefaultExcludeIps: *argDefaultExcludeIps,
ClusterRouter: *argClusterRouter,
NodeSwitch: *argNodeSwitch,
Expand Down
14 changes: 14 additions & 0 deletions pkg/controller/init.go
Expand Up @@ -137,7 +137,13 @@ func (c *Controller) initDefaultLogicalSwitch() error {
}
if c.config.NetworkType == util.NetworkTypeVlan {
defaultSubnet.Spec.Vlan = c.config.DefaultVlanName
if c.config.DefaultLogicalGateway && c.config.DefaultU2OInterconnection {
err = fmt.Errorf("logicalGateway and u2oInterconnection can't be opened at the same time")
klog.Error(err)
return err
}
defaultSubnet.Spec.LogicalGateway = c.config.DefaultLogicalGateway
defaultSubnet.Spec.U2OInterconnection = c.config.DefaultU2OInterconnection
}

_, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Create(context.Background(), &defaultSubnet, metav1.CreateOptions{})
Expand Down Expand Up @@ -304,6 +310,14 @@ func (c *Controller) InitIPAM() error {
if err := c.ipam.AddOrUpdateSubnet(subnet.Name, subnet.Spec.CIDRBlock, subnet.Spec.ExcludeIps); err != nil {
klog.Errorf("failed to init subnet %s: %v", subnet.Name, err)
}

u2oInterconnName := fmt.Sprintf(util.U2OInterconnName, subnet.Spec.Vpc, subnet.Name)
u2oInterconnLrpName := fmt.Sprintf("%s-%s", subnet.Spec.Vpc, subnet.Name)
if subnet.Status.U2OInterconnectionIP != "" {
if _, _, _, err = c.ipam.GetStaticAddress(u2oInterconnName, u2oInterconnLrpName, subnet.Status.U2OInterconnectionIP, "", subnet.Name, true); err != nil {
klog.Errorf("failed to init subnet u2o interonnection ip to ipam %v", subnet.Name, err)
}
}
}

result, err := c.ovnLegacyClient.CustomFindEntity("logical_switch_port", []string{"name"}, `external-ids:vendor{<}""`)
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/ip.go
@@ -1,7 +1,9 @@
package controller

import (
"github.com/kubeovn/kube-ovn/pkg/util"
"k8s.io/klog/v2"
"strings"

kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
)
Expand All @@ -12,6 +14,9 @@ func (c *Controller) enqueueAddOrDelIP(obj interface{}) {
}
ipObj := obj.(*kubeovnv1.IP)
klog.V(3).Infof("enqueue update status subnet %s", ipObj.Spec.Subnet)
if strings.HasPrefix(ipObj.Name, util.U2OInterconnName[0:19]) {
return
}
c.updateSubnetStatusQueue.Add(ipObj.Spec.Subnet)
for _, as := range ipObj.Spec.AttachSubnets {
klog.V(3).Infof("enqueue update status subnet %s", as)
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/node.go
Expand Up @@ -602,6 +602,9 @@ func (c *Controller) createOrUpdateCrdIPs(podName, ip, mac, subnetName, ns, node
if subnetName == c.config.NodeSwitch {
key = nodeName
ipName = fmt.Sprintf("node-%s", nodeName)
} else if strings.HasPrefix(podName, util.U2OInterconnName[0:19]) {
key = podName
ipName = podName
} else {
key = podName
ipName = ovs.PodNameToPortName(podName, ns, providerName)
Expand Down

0 comments on commit 4320301

Please sign in to comment.