Skip to content

Commit f3833f9

Browse files
watermelon-brotherwujixin
and
wujixin
authored
feat: suport kubevirt nic hotplug (#3013)
Signed-off-by: wujixin <wujix@yealink.com> Co-authored-by: wujixin <wujix@yealink.com>
1 parent 62f3328 commit f3833f9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/controller/pod.go

+15
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) error {
10691069
key := fmt.Sprintf("%s/%s", pod.Namespace, podName)
10701070
targetPortNameList := strset.NewWithSize(len(podNets))
10711071
portsNeedToDel := []string{}
1072+
annotationsNeedToDel := []string{}
10721073
subnetUsedByPort := make(map[string]string)
10731074

10741075
for _, podNet := range podNets {
@@ -1086,6 +1087,12 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) error {
10861087
if !targetPortNameList.Has(port.Name) {
10871088
portsNeedToDel = append(portsNeedToDel, port.Name)
10881089
subnetUsedByPort[port.Name] = port.ExternalIDs["ls"]
1090+
portNameSlice := strings.Split(port.Name, ".")
1091+
providerName := strings.Join(portNameSlice[2:], ".")
1092+
if providerName == util.OvnProvider {
1093+
continue
1094+
}
1095+
annotationsNeedToDel = append(annotationsNeedToDel, providerName)
10891096
}
10901097
}
10911098

@@ -1111,6 +1118,14 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) error {
11111118
}
11121119
}
11131120

1121+
for _, providerName := range annotationsNeedToDel {
1122+
for annotationKey := range pod.Annotations {
1123+
if strings.HasPrefix(key, providerName) {
1124+
delete(pod.Annotations, annotationKey)
1125+
}
1126+
}
1127+
}
1128+
11141129
return nil
11151130
}
11161131

pkg/daemon/ovs_linux.go

+5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ func generateNicName(containerID, ifname string) (string, string) {
191191
if ifname == "eth0" {
192192
return fmt.Sprintf("%s_h", containerID[0:12]), fmt.Sprintf("%s_c", containerID[0:12])
193193
}
194+
// The nic name is 14 length and have prefix pod in the Kubevirt v1.0.0
195+
if strings.HasPrefix(ifname, "pod") && len(ifname) == 14 {
196+
ifname = ifname[3 : len(ifname)-4]
197+
return fmt.Sprintf("%s_%s_h", containerID[0:12-len(ifname)], ifname), fmt.Sprintf("%s_%s_c", containerID[0:12-len(ifname)], ifname)
198+
}
194199
return fmt.Sprintf("%s_%s_h", containerID[0:12-len(ifname)], ifname), fmt.Sprintf("%s_%s_c", containerID[0:12-len(ifname)], ifname)
195200
}
196201

0 commit comments

Comments
 (0)