Skip to content

Commit c53e562

Browse files
zbb88888zhangzujian
authored and
zhangbingbing2
committed
support k8s host vm vip type (#5148)
--------- Signed-off-by: zbb88888 <[email protected]> Co-authored-by: 张祖建 <[email protected]> Signed-off-by: zhangbingbing2 <[email protected]>
1 parent 76cb5bb commit c53e562

File tree

6 files changed

+45
-12
lines changed

6 files changed

+45
-12
lines changed

pkg/controller/gc.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@ func (c *Controller) markAndCleanLSP() error {
367367
// The lsp for vm pod should not be deleted if vm still exists
368368
ipMap.Add(c.getVMLsps()...)
369369

370+
vips, err := c.virtualIpsLister.List(labels.Everything())
371+
if err != nil {
372+
klog.Errorf("failed to list virtual ip, %v", err)
373+
return err
374+
}
375+
vipsMap := strset.NewWithSize(len(vips))
376+
for _, vip := range vips {
377+
if vip.Spec.Type != "" {
378+
portName := ovs.PodNameToPortName(vip.Name, vip.Spec.Namespace, util.OvnProvider)
379+
vipsMap.Add(portName)
380+
}
381+
}
370382
lsps, err := c.OVNNbClient.ListNormalLogicalSwitchPorts(c.config.EnableExternalVpc, nil)
371383
if err != nil {
372384
klog.Errorf("failed to list logical switch port, %v", err)
@@ -380,9 +392,8 @@ func (c *Controller) markAndCleanLSP() error {
380392
if ipMap.Has(lsp.Name) {
381393
continue
382394
}
383-
384-
if lsp.Options != nil && lsp.Options["arp_proxy"] == "true" {
385-
// arp_proxy lsp is a type of vip crd which should not gc
395+
if vipsMap.Has(lsp.Name) {
396+
// skip gc lsp for k8s host network vm pod or switch lb rule
386397
continue
387398
}
388399
if !lastNoPodLSP.Has(lsp.Name) {

pkg/controller/ip.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func (c *Controller) acquireIPAddress(subnetName, name, nicName string) (string,
462462
}
463463
}
464464

465-
func (c *Controller) acquireStaticIPAddress(subnetName, name, nicName, ip string) (string, string, string, error) {
465+
func (c *Controller) acquireStaticIPAddress(subnetName, name, nicName, ip string, macPointer *string) (string, string, string, error) {
466466
checkConflict := true
467467
var v4ip, v6ip, mac string
468468
var err error
@@ -472,7 +472,7 @@ func (c *Controller) acquireStaticIPAddress(subnetName, name, nicName, ip string
472472
}
473473
}
474474

475-
if v4ip, v6ip, mac, err = c.ipam.GetStaticAddress(name, nicName, ip, nil, subnetName, checkConflict); err != nil {
475+
if v4ip, v6ip, mac, err = c.ipam.GetStaticAddress(name, nicName, ip, macPointer, subnetName, checkConflict); err != nil {
476476
klog.Errorf("failed to get static virtual ip '%s', mac '%s', subnet '%s', %v", ip, mac, subnetName, err)
477477
return "", "", "", err
478478
}

pkg/controller/ovn_eip.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (c *Controller) handleAddOvnEip(key string) error {
240240
}
241241
portName := cachedEip.Name
242242
if cachedEip.Spec.V4Ip != "" {
243-
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, cachedEip.Name, portName, cachedEip.Spec.V4Ip)
243+
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, cachedEip.Name, portName, cachedEip.Spec.V4Ip, nil)
244244
} else {
245245
// random allocate
246246
v4ip, v6ip, mac, err = c.acquireIPAddress(subnet.Name, cachedEip.Name, portName)

pkg/controller/subnet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ func (c *Controller) reconcileU2OInterconnectionIP(subnet *kubeovnv1.Subnet) err
20312031
c.ipam.ReleaseAddressByPod(u2oInterconnName, subnet.Name)
20322032
}
20332033

2034-
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName, subnet.Spec.U2OInterconnectionIP)
2034+
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName, subnet.Spec.U2OInterconnectionIP, nil)
20352035
if err != nil {
20362036
klog.Errorf("failed to acquire static underlay to overlay interconnection ip address for subnet %s, %v", subnet.Name, err)
20372037
return err

pkg/controller/vip.go

+26-5
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,15 @@ func (c *Controller) handleAddVirtualIP(key string) error {
238238
klog.Error(err)
239239
return err
240240
}
241+
var macPointer *string
241242
ipStr := util.GetStringIP(sourceV4Ip, sourceV6Ip)
242-
if ipStr != "" {
243-
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr)
243+
if ipStr != "" || vip.Spec.MacAddress != "" {
244+
macPointer = &vip.Spec.MacAddress
245+
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr, macPointer)
244246
} else {
245247
// Random allocate
246248
v4ip, v6ip, mac, err = c.acquireIPAddress(subnet.Name, vip.Name, portName)
247249
}
248-
249250
if err != nil {
250251
klog.Error(err)
251252
return err
@@ -288,10 +289,25 @@ func (c *Controller) handleAddVirtualIP(key string) error {
288289
parentV6ip = vip.Spec.ParentV6ip
289290
parentMac = vip.Spec.ParentMac
290291
}
292+
if vip.Spec.Type == util.KubeHostVMVip {
293+
// k8s host network pod vm use vip for its nic ip
294+
klog.Infof("create lsp for host network pod vm nic ip %s", vip.Name)
295+
ipStr := util.GetStringIP(v4ip, v6ip)
296+
if err := c.OVNNbClient.CreateLogicalSwitchPort(subnet.Name, portName, ipStr, mac, vip.Name, vip.Spec.Namespace, false, "", "", false, nil, subnet.Spec.Vpc); err != nil {
297+
err = fmt.Errorf("failed to create lsp %s: %w", portName, err)
298+
klog.Error(err)
299+
return err
300+
}
301+
}
291302
if err = c.createOrUpdateVipCR(key, vip.Spec.Namespace, subnet.Name, v4ip, v6ip, mac, parentV4ip, parentV6ip, parentMac); err != nil {
292303
klog.Errorf("failed to create or update vip '%s', %v", vip.Name, err)
293304
return err
294305
}
306+
if vip.Spec.Type == util.KubeHostVMVip {
307+
// vm use the vip as its real ip
308+
klog.Infof("created host network pod vm ip %s", key)
309+
return nil
310+
}
295311
if err := c.handleUpdateVirtualParents(key); err != nil {
296312
err := fmt.Errorf("error syncing virtual parents for vip '%s': %s", key, err.Error())
297313
klog.Error(err)
@@ -365,14 +381,14 @@ func (c *Controller) handleUpdateVirtualIP(key string) error {
365381
func (c *Controller) handleDelVirtualIP(vip *kubeovnv1.Vip) error {
366382
klog.Infof("handle delete vip %s", vip.Name)
367383
// TODO:// clean vip in its parent port aap list
368-
if vip.Spec.Type == util.SwitchLBRuleVip {
384+
if vip.Spec.Type != "" {
369385
subnet, err := c.subnetsLister.Get(vip.Spec.Subnet)
370386
if err != nil {
371387
klog.Errorf("failed to get subnet %s: %v", vip.Spec.Subnet, err)
372388
return err
373389
}
374390
portName := ovs.PodNameToPortName(vip.Name, vip.Spec.Namespace, subnet.Spec.Provider)
375-
klog.Infof("delete vip arp proxy lsp %s", portName)
391+
klog.Infof("delete vip lsp %s", portName)
376392
if err := c.OVNNbClient.DeleteLogicalSwitchPort(portName); err != nil {
377393
err = fmt.Errorf("failed to delete lsp %s: %w", vip.Name, err)
378394
klog.Error(err)
@@ -398,6 +414,11 @@ func (c *Controller) handleUpdateVirtualParents(key string) error {
398414
klog.Error(err)
399415
return err
400416
}
417+
if cachedVip.Spec.Type == util.KubeHostVMVip {
418+
// vm use the vip as its real ip
419+
klog.Infof("created host network pod vm ip %s", key)
420+
return nil
421+
}
401422
// only pods in the same namespace as vip are allowed to use aap
402423
if (cachedVip.Status.V4ip == "" && cachedVip.Status.V6ip == "") || cachedVip.Spec.Namespace == "" {
403424
return nil

pkg/util/const.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const (
4141

4242
SwitchLBRuleVipsAnnotation = "ovn.kubernetes.io/switch_lb_vip"
4343
SwitchLBRuleVip = "switch_lb_vip"
44+
KubeHostVMVip = "kube_host_vm_vip"
4445
SwitchLBRuleSubnet = "switch_lb_subnet"
4546

4647
LogicalRouterAnnotation = "ovn.kubernetes.io/logical_router"

0 commit comments

Comments
 (0)