Skip to content

Commit 110440f

Browse files
authored
u2o support specify u2o ip on release-1.9 (#2935)
* u2o support specify u2o ip on release-1.9 * fix merge err
1 parent 5c855cd commit 110440f

File tree

6 files changed

+67
-9
lines changed

6 files changed

+67
-9
lines changed

dist/images/install.sh

+2
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,8 @@ spec:
613613
type: string
614614
u2oInterconnection:
615615
type: boolean
616+
u2oInterconnectionIP:
617+
type: string
616618
scope: Cluster
617619
names:
618620
plural: subnets

kubeovn-helm/templates/kube-ovn-crd.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ spec:
436436
type: string
437437
u2oInterconnection:
438438
type: boolean
439+
u2oInterconnectionIP:
440+
type: string
439441
scope: Cluster
440442
names:
441443
plural: subnets

pkg/apis/kubeovn/v1/types.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ type SubnetSpec struct {
124124
Vlan string `json:"vlan,omitempty"`
125125
HtbQos string `json:"htbqos,omitempty"`
126126

127-
LogicalGateway bool `json:"logicalGateway,omitempty"`
128-
DisableGatewayCheck bool `json:"disableGatewayCheck,omitempty"`
129-
DisableInterConnection bool `json:"disableInterConnection,omitempty"`
130-
U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
127+
LogicalGateway bool `json:"logicalGateway,omitempty"`
128+
DisableGatewayCheck bool `json:"disableGatewayCheck,omitempty"`
129+
DisableInterConnection bool `json:"disableInterConnection,omitempty"`
130+
U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
131+
U2OInterconnectionIP string `json:"u2oInterconnectionIP,omitempty"`
131132
}
132133

133134
// ConditionType encodes information on the condition

pkg/controller/subnet.go

+44-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ func (c *Controller) enqueueUpdateSubnet(old, new interface{}) {
9292
oldSubnet.Spec.Gateway != newSubnet.Spec.Gateway ||
9393
!reflect.DeepEqual(oldSubnet.Spec.ExcludeIps, newSubnet.Spec.ExcludeIps) ||
9494
oldSubnet.Spec.Vlan != newSubnet.Spec.Vlan ||
95-
oldSubnet.Spec.U2OInterconnection != newSubnet.Spec.U2OInterconnection {
95+
oldSubnet.Spec.U2OInterconnection != newSubnet.Spec.U2OInterconnection ||
96+
(newSubnet.Spec.U2OInterconnection && newSubnet.Spec.U2OInterconnectionIP != "" &&
97+
oldSubnet.Spec.U2OInterconnectionIP != newSubnet.Spec.U2OInterconnectionIP) {
9698
klog.V(3).Infof("enqueue update subnet %s", key)
9799
c.addOrUpdateSubnetQueue.Add(key)
98100
}
@@ -274,6 +276,11 @@ func formatSubnet(subnet *kubeovnv1.Subnet, c *Controller) error {
274276
}
275277
}
276278
}
279+
if subnet.Spec.U2OInterconnectionIP != "" && !subnet.Spec.U2OInterconnection {
280+
subnet.Spec.U2OInterconnectionIP = ""
281+
changed = true
282+
}
283+
277284
klog.Infof("format subnet %v, changed %v", subnet.Name, changed)
278285
if changed {
279286
_, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Update(context.Background(), subnet, metav1.UpdateOptions{})
@@ -1219,14 +1226,29 @@ func (c *Controller) reconcileU2OInterconnectionIP(subnet *kubeovnv1.Subnet) err
12191226
klog.Infof("reconcile underlay subnet %s to overlay interconnection with U2OInterconnection %v U2OInterconnectionIP %s ",
12201227
subnet.Name, subnet.Spec.U2OInterconnection, subnet.Status.U2OInterconnectionIP)
12211228
if subnet.Spec.U2OInterconnection {
1222-
if subnet.Status.U2OInterconnectionIP == "" {
1223-
u2oInterconnName := fmt.Sprintf(util.U2OInterconnName, subnet.Spec.Vpc, subnet.Name)
1224-
u2oInterconnLrpName := fmt.Sprintf("%s-%s", subnet.Spec.Vpc, subnet.Name)
1225-
v4ip, v6ip, _, err := c.acquireIpAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName)
1229+
u2oInterconnName := fmt.Sprintf(util.U2OInterconnName, subnet.Spec.Vpc, subnet.Name)
1230+
u2oInterconnLrpName := fmt.Sprintf("%s-%s", subnet.Spec.Vpc, subnet.Name)
1231+
var v4ip, v6ip string
1232+
var err error
1233+
if subnet.Spec.U2OInterconnectionIP == "" && subnet.Status.U2OInterconnectionIP == "" {
1234+
v4ip, v6ip, _, err = c.acquireIpAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName)
12261235
if err != nil {
12271236
klog.Errorf("failed to acquire underlay to overlay interconnection ip address for subnet %s, %v", subnet.Name, err)
12281237
return err
12291238
}
1239+
} else if subnet.Spec.U2OInterconnectionIP != "" && subnet.Status.U2OInterconnectionIP != subnet.Spec.U2OInterconnectionIP {
1240+
if subnet.Status.U2OInterconnectionIP != "" {
1241+
c.ipam.ReleaseAddressByPod(u2oInterconnName)
1242+
}
1243+
1244+
v4ip, v6ip, _, err = c.acquireStaticIpAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName, subnet.Spec.U2OInterconnectionIP)
1245+
if err != nil {
1246+
klog.Errorf("failed to acquire static underlay to overlay interconnection ip address for subnet %s, %v", subnet.Name, err)
1247+
return err
1248+
}
1249+
}
1250+
1251+
if v4ip != "" || v6ip != "" {
12301252
switch subnet.Spec.Protocol {
12311253
case kubeovnv1.ProtocolIPv4:
12321254
subnet.Status.U2OInterconnectionIP = v4ip
@@ -1943,3 +1965,20 @@ func (c *Controller) acquireIpAddress(subnetName, name, nicName string) (string,
19431965
}
19441966
}
19451967
}
1968+
1969+
func (c *Controller) acquireStaticIpAddress(subnetName, name, nicName, ip string) (string, string, string, error) {
1970+
checkConflict := true
1971+
var v4ip, v6ip, mac string
1972+
var err error
1973+
for _, ipStr := range strings.Split(ip, ",") {
1974+
if net.ParseIP(ipStr) == nil {
1975+
return "", "", "", fmt.Errorf("failed to parse vip ip %s", ipStr)
1976+
}
1977+
}
1978+
1979+
if v4ip, v6ip, mac, err = c.ipam.GetStaticAddress(name, nicName, ip, "", subnetName, checkConflict); err != nil {
1980+
klog.Errorf("failed to get static virtual ip '%s', mac '%s', subnet '%s', %v", ip, mac, subnetName, err)
1981+
return "", "", "", err
1982+
}
1983+
return v4ip, v6ip, mac, nil
1984+
}

pkg/util/validator.go

+12
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ func ValidateSubnet(subnet kubeovnv1.Subnet) error {
111111
}
112112
}
113113

114+
if subnet.Spec.LogicalGateway && subnet.Spec.U2OInterconnection {
115+
return fmt.Errorf("logicalGateway and u2oInterconnection can't be opened at the same time")
116+
}
117+
118+
if subnet.Spec.U2OInterconnectionIP != "" {
119+
if !CIDRContainIP(subnet.Spec.CIDRBlock, subnet.Spec.U2OInterconnectionIP) {
120+
return fmt.Errorf("u2oInterconnectionIP %s is not in subnet %s cidr %s",
121+
subnet.Spec.U2OInterconnectionIP,
122+
subnet.Name, subnet.Spec.CIDRBlock)
123+
}
124+
}
125+
114126
return nil
115127
}
116128

yamls/crd.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ spec:
225225
type: string
226226
u2oInterconnection:
227227
type: boolean
228+
u2oInterconnectionIP:
229+
type: string
228230
scope: Cluster
229231
names:
230232
plural: subnets

0 commit comments

Comments
 (0)