Skip to content

Commit

Permalink
u2o feature (#2189)
Browse files Browse the repository at this point in the history
* u2o feature

* controller ipam initialize add u2oip

* add crd ips for u2o interconnection ip

* no need enqueue update subnet status, when u2o ip add/del
  • Loading branch information
changluyi committed Dec 30, 2022
1 parent c0d76fd commit 098a821
Show file tree
Hide file tree
Showing 16 changed files with 439 additions and 37 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,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
Original file line number Diff line number Diff line change
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 @@ -1327,6 +1328,9 @@ spec:
- name: ExcludeIPs
type: string
jsonPath: .spec.excludeIps
- name: U2OInterconnectionIP
type: string
jsonPath: .status.u2oInterconnectionIP
schema:
openAPIV3Schema:
type: object
Expand All @@ -1348,6 +1352,8 @@ spec:
type: string
dhcpV6OptionsUUID:
type: string
u2oInterconnectionIP:
type: string
conditions:
type: array
items:
Expand Down Expand Up @@ -1470,6 +1476,8 @@ spec:
- allow
- drop
- reject
u2oInterconnection:
type: boolean
scope: Cluster
names:
plural: subnets
Expand Down Expand Up @@ -2978,6 +2986,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
7 changes: 7 additions & 0 deletions kubeovn-helm/templates/kube-ovn-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,9 @@ spec:
- name: ExcludeIPs
type: string
jsonPath: .spec.excludeIps
- name: U2OInterconnectionIP
type: string
jsonPath: .status.u2oInterconnectionIP
schema:
openAPIV3Schema:
type: object
Expand All @@ -1133,6 +1136,8 @@ spec:
type: string
dhcpV6OptionsUUID:
type: string
u2oInterconnectionIP:
type: string
conditions:
type: array
items:
Expand Down Expand Up @@ -1255,6 +1260,8 @@ spec:
- allow
- drop
- reject
u2oInterconnection:
type: boolean
scope: Cluster
names:
plural: subnets
Expand Down
17 changes: 10 additions & 7 deletions pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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 @@ -179,13 +181,14 @@ type SubnetStatus struct {
// +patchStrategy=merge
Conditions []SubnetCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`

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"`
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,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 @@ -111,6 +112,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 @@ -184,6 +187,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
Original file line number Diff line number Diff line change
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.Gateway, 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
Original file line number Diff line number Diff line change
@@ -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 @@ -10,6 +12,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
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,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
Loading

0 comments on commit 098a821

Please sign in to comment.