Skip to content

Commit

Permalink
u2o feature merge to 1.9 (#2226)
Browse files Browse the repository at this point in the history
  • Loading branch information
changluyi committed Jan 5, 2023
1 parent 2788d8e commit d48dd36
Show file tree
Hide file tree
Showing 15 changed files with 464 additions and 34 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,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 @@ -507,6 +508,9 @@ spec:
- name: ExcludeIPs
type: string
jsonPath: .spec.excludeIps
- name: U2OInterconnectionIP
type: string
jsonPath: .status.u2oInterconnectionIP
schema:
openAPIV3Schema:
type: object
Expand All @@ -524,6 +528,8 @@ spec:
type: number
activateGateway:
type: string
u2oInterconnectionIP:
type: string
conditions:
type: array
items:
Expand Down Expand Up @@ -602,6 +608,8 @@ spec:
type: boolean
htbqos:
type: string
u2oInterconnection:
type: boolean
scope: Cluster
names:
plural: subnets
Expand Down Expand Up @@ -1915,6 +1923,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 @@ -334,6 +334,9 @@ spec:
- name: ExcludeIPs
type: string
jsonPath: .spec.excludeIps
- name: U2OInterconnectionIP
type: string
jsonPath: .status.u2oInterconnectionIP
schema:
openAPIV3Schema:
type: object
Expand All @@ -351,6 +354,8 @@ spec:
type: number
activateGateway:
type: string
u2oInterconnectionIP:
type: string
conditions:
type: array
items:
Expand Down Expand Up @@ -429,6 +434,8 @@ spec:
type: boolean
htbqos:
type: string
u2oInterconnection:
type: boolean
scope: Cluster
names:
plural: subnets
Expand Down
16 changes: 9 additions & 7 deletions pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ type SubnetSpec struct {
LogicalGateway bool `json:"logicalGateway,omitempty"`
DisableGatewayCheck bool `json:"disableGatewayCheck,omitempty"`
DisableInterConnection bool `json:"disableInterConnection,omitempty"`
U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
}

// ConditionType encodes information on the condition
Expand Down Expand Up @@ -160,13 +161,14 @@ 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"`
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"`
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 @@ -36,12 +36,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 @@ -99,6 +100,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 @@ -163,6 +166,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 @@ -300,6 +306,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
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 @@ -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
Original file line number Diff line number Diff line change
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 d48dd36

Please sign in to comment.