Skip to content

Commit 5c16c6f

Browse files
committed
support k8s host vm vip type
Signed-off-by: zbb88888 <[email protected]>
1 parent d55a933 commit 5c16c6f

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
@@ -368,6 +368,18 @@ func (c *Controller) markAndCleanLSP() error {
368368
// The lsp for vm pod should not be deleted if vm still exists
369369
ipMap.Add(c.getVMLsps()...)
370370

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

pkg/controller/ip.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (c *Controller) acquireIPAddress(subnetName, name, nicName string) (string,
344344
}
345345
}
346346

347-
func (c *Controller) acquireStaticIPAddress(subnetName, name, nicName, ip string) (string, string, string, error) {
347+
func (c *Controller) acquireStaticIPAddress(subnetName, name, nicName, ip string, macPointer *string) (string, string, string, error) {
348348
checkConflict := true
349349
var v4ip, v6ip, mac string
350350
var err error
@@ -354,7 +354,7 @@ func (c *Controller) acquireStaticIPAddress(subnetName, name, nicName, ip string
354354
}
355355
}
356356

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

pkg/controller/ovn_eip.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (c *Controller) handleAddOvnEip(key string) error {
9292
}
9393
portName := cachedEip.Name
9494
if cachedEip.Spec.V4Ip != "" {
95-
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, cachedEip.Name, portName, cachedEip.Spec.V4Ip)
95+
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, cachedEip.Name, portName, cachedEip.Spec.V4Ip, nil)
9696
} else {
9797
// random allocate
9898
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
@@ -1921,7 +1921,7 @@ func (c *Controller) acquireU2OIP(subnet *kubeovnv1.Subnet, u2oInterconnName, u2
19211921
klog.Infof("release underlay to overlay interconnection ip address %s for subnet %s", subnet.Status.U2OInterconnectionIP, subnet.Name)
19221922
c.ipam.ReleaseAddressByPod(u2oInterconnName, subnet.Name)
19231923
}
1924-
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName, subnet.Spec.U2OInterconnectionIP)
1924+
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, u2oInterconnName, u2oInterconnLrpName, subnet.Spec.U2OInterconnectionIP, nil)
19251925
if err != nil {
19261926
klog.Errorf("failed to acquire static underlay to overlay interconnection ip address for subnet %s, %v", subnet.Name, err)
19271927
return "", "", "", err

pkg/controller/vip.go

+26-5
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ func (c *Controller) handleAddVirtualIP(key string) error {
8787
klog.Error(err)
8888
return err
8989
}
90+
var macPointer *string
9091
ipStr := util.GetStringIP(sourceV4Ip, sourceV6Ip)
91-
if ipStr != "" {
92-
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr)
92+
if ipStr != "" && vip.Spec.MacAddress != "" {
93+
macPointer = &vip.Spec.MacAddress
94+
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr, macPointer)
9395
} else {
9496
// Random allocate
9597
v4ip, v6ip, mac, err = c.acquireIPAddress(subnet.Name, vip.Name, portName)
9698
}
97-
9899
if err != nil {
99100
klog.Error(err)
100101
return err
@@ -137,10 +138,25 @@ func (c *Controller) handleAddVirtualIP(key string) error {
137138
parentV6ip = vip.Spec.ParentV6ip
138139
parentMac = vip.Spec.ParentMac
139140
}
141+
if vip.Spec.Type == util.KubeHostVMVip {
142+
// k8s host network pod vm use vip for its nic ip
143+
klog.Infof("create lsp for host network pod vm nic ip %s", vip.Name)
144+
ipStr := util.GetStringIP(v4ip, v6ip)
145+
if err := c.OVNNbClient.CreateLogicalSwitchPort(subnet.Name, portName, ipStr, mac, vip.Name, vip.Spec.Namespace, false, "", "", false, nil, subnet.Spec.Vpc); err != nil {
146+
err = fmt.Errorf("failed to create lsp %s: %w", portName, err)
147+
klog.Error(err)
148+
return err
149+
}
150+
}
140151
if err = c.createOrUpdateVipCR(key, vip.Spec.Namespace, subnet.Name, v4ip, v6ip, mac, parentV4ip, parentV6ip, parentMac); err != nil {
141152
klog.Errorf("failed to create or update vip '%s', %v", vip.Name, err)
142153
return err
143154
}
155+
if vip.Spec.Type == util.KubeHostVMVip {
156+
// vm use the vip as its real ip
157+
klog.Infof("created host network pod vm ip %s", key)
158+
return nil
159+
}
144160
if err := c.handleUpdateVirtualParents(key); err != nil {
145161
err := fmt.Errorf("error syncing virtual parents for vip '%s': %s", key, err.Error())
146162
klog.Error(err)
@@ -214,14 +230,14 @@ func (c *Controller) handleUpdateVirtualIP(key string) error {
214230
func (c *Controller) handleDelVirtualIP(vip *kubeovnv1.Vip) error {
215231
klog.Infof("handle delete vip %s", vip.Name)
216232
// TODO:// clean vip in its parent port aap list
217-
if vip.Spec.Type == util.SwitchLBRuleVip {
233+
if vip.Spec.Type != "" {
218234
subnet, err := c.subnetsLister.Get(vip.Spec.Subnet)
219235
if err != nil {
220236
klog.Errorf("failed to get subnet %s: %v", vip.Spec.Subnet, err)
221237
return err
222238
}
223239
portName := ovs.PodNameToPortName(vip.Name, vip.Spec.Namespace, subnet.Spec.Provider)
224-
klog.Infof("delete vip arp proxy lsp %s", portName)
240+
klog.Infof("delete vip lsp %s", portName)
225241
if err := c.OVNNbClient.DeleteLogicalSwitchPort(portName); err != nil {
226242
err = fmt.Errorf("failed to delete lsp %s: %w", vip.Name, err)
227243
klog.Error(err)
@@ -247,6 +263,11 @@ func (c *Controller) handleUpdateVirtualParents(key string) error {
247263
klog.Error(err)
248264
return err
249265
}
266+
if cachedVip.Spec.Type == util.KubeHostVMVip {
267+
// vm use the vip as its real ip
268+
klog.Infof("created host network pod vm ip %s", key)
269+
return nil
270+
}
250271
// only pods in the same namespace as vip are allowed to use aap
251272
if (cachedVip.Status.V4ip == "" && cachedVip.Status.V6ip == "") || cachedVip.Spec.Namespace == "" {
252273
return nil

pkg/util/const.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444

4545
SwitchLBRuleVipsAnnotation = "ovn.kubernetes.io/switch_lb_vip"
4646
SwitchLBRuleVip = "switch_lb_vip"
47+
KubeHostVMVip = "kube_host_vm_vip"
4748
SwitchLBRuleSubnet = "switch_lb_subnet"
4849

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

0 commit comments

Comments
 (0)