Skip to content

Commit

Permalink
u2o support specify u2o ip on release-1.11 (#2937)
Browse files Browse the repository at this point in the history
  • Loading branch information
changluyi committed Jun 13, 2023
1 parent 9485980 commit effc111
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
2 changes: 2 additions & 0 deletions dist/images/install.sh
Expand Up @@ -1495,6 +1495,8 @@ spec:
- reject
u2oInterconnection:
type: boolean
u2oInterconnectionIP:
type: string
scope: Cluster
names:
plural: subnets
Expand Down
2 changes: 2 additions & 0 deletions kubeovn-helm/templates/kube-ovn-crd.yaml
Expand Up @@ -1266,6 +1266,8 @@ spec:
- reject
u2oInterconnection:
type: boolean
u2oInterconnectionIP:
type: string
scope: Cluster
names:
plural: subnets
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/kubeovn/v1/types.go
Expand Up @@ -138,7 +138,8 @@ type SubnetSpec struct {

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

U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
U2OInterconnectionIP string `json:"u2oInterconnectionIP,omitempty"`
}

type Acl struct {
Expand Down
32 changes: 27 additions & 5 deletions pkg/controller/subnet.go
Expand Up @@ -94,7 +94,9 @@ func (c *Controller) enqueueUpdateSubnet(old, new interface{}) {
oldSubnet.Spec.IPv6RAConfigs != newSubnet.Spec.IPv6RAConfigs ||
oldSubnet.Spec.Protocol != newSubnet.Spec.Protocol ||
!reflect.DeepEqual(oldSubnet.Spec.Acls, newSubnet.Spec.Acls) ||
oldSubnet.Spec.U2OInterconnection != newSubnet.Spec.U2OInterconnection {
oldSubnet.Spec.U2OInterconnection != newSubnet.Spec.U2OInterconnection ||
(newSubnet.Spec.U2OInterconnection && newSubnet.Spec.U2OInterconnectionIP != "" &&
oldSubnet.Spec.U2OInterconnectionIP != newSubnet.Spec.U2OInterconnectionIP) {
klog.V(3).Infof("enqueue update subnet %s", key)
c.addOrUpdateSubnetQueue.Add(key)
}
Expand Down Expand Up @@ -312,6 +314,11 @@ func formatSubnet(subnet *kubeovnv1.Subnet, c *Controller) error {
}
}
}
if subnet.Spec.U2OInterconnectionIP != "" && !subnet.Spec.U2OInterconnection {
subnet.Spec.U2OInterconnectionIP = ""
changed = true
}

klog.Infof("format subnet %v, changed %v", subnet.Name, changed)
if changed {
_, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Update(context.Background(), subnet, metav1.UpdateOptions{})
Expand Down Expand Up @@ -1530,14 +1537,29 @@ func (c *Controller) reconcileU2OInterconnectionIP(subnet *kubeovnv1.Subnet) err
klog.Infof("reconcile underlay subnet %s to overlay interconnection with U2OInterconnection %v U2OInterconnectionIP %s ",
subnet.Name, subnet.Spec.U2OInterconnection, subnet.Status.U2OInterconnectionIP)
if subnet.Spec.U2OInterconnection {
if subnet.Status.U2OInterconnectionIP == "" {
u2oInterconnName := fmt.Sprintf(util.U2OInterconnName, subnet.Spec.Vpc, subnet.Name)
u2oInterconnLrpName := fmt.Sprintf("%s-%s", subnet.Spec.Vpc, subnet.Name)
v4ip, v6ip, _, err := c.acquireIpAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName)
u2oInterconnName := fmt.Sprintf(util.U2OInterconnName, subnet.Spec.Vpc, subnet.Name)
u2oInterconnLrpName := fmt.Sprintf("%s-%s", subnet.Spec.Vpc, subnet.Name)
var v4ip, v6ip string
var err error
if subnet.Spec.U2OInterconnectionIP == "" && subnet.Status.U2OInterconnectionIP == "" {
v4ip, v6ip, _, err = c.acquireIpAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName)
if err != nil {
klog.Errorf("failed to acquire underlay to overlay interconnection ip address for subnet %s, %v", subnet.Name, err)
return err
}
} else if subnet.Spec.U2OInterconnectionIP != "" && subnet.Status.U2OInterconnectionIP != subnet.Spec.U2OInterconnectionIP {
if subnet.Status.U2OInterconnectionIP != "" {
c.ipam.ReleaseAddressByPod(u2oInterconnName)
}

v4ip, v6ip, _, err = c.acquireStaticIpAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName, subnet.Spec.U2OInterconnectionIP)
if err != nil {
klog.Errorf("failed to acquire static underlay to overlay interconnection ip address for subnet %s, %v", subnet.Name, err)
return err
}
}

if v4ip != "" || v6ip != "" {
switch subnet.Spec.Protocol {
case kubeovnv1.ProtocolIPv4:
subnet.Status.U2OInterconnectionIP = v4ip
Expand Down
12 changes: 12 additions & 0 deletions pkg/util/validator.go
Expand Up @@ -105,6 +105,18 @@ func ValidateSubnet(subnet kubeovnv1.Subnet) error {
}
}
}

if subnet.Spec.LogicalGateway && subnet.Spec.U2OInterconnection {
return fmt.Errorf("logicalGateway and u2oInterconnection can't be opened at the same time")
}

if subnet.Spec.U2OInterconnectionIP != "" {
if !CIDRContainIP(subnet.Spec.CIDRBlock, subnet.Spec.U2OInterconnectionIP) {
return fmt.Errorf("u2oInterconnectionIP %s is not in subnet %s cidr %s",
subnet.Spec.U2OInterconnectionIP,
subnet.Name, subnet.Spec.CIDRBlock)
}
}
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions yamls/crd.yaml
Expand Up @@ -1274,6 +1274,8 @@ spec:
- reject
u2oInterconnection:
type: boolean
u2oInterconnectionIP:
type: string
scope: Cluster
names:
plural: subnets
Expand Down

0 comments on commit effc111

Please sign in to comment.