Skip to content

Commit

Permalink
feat: suport kubevirt nic hotplug
Browse files Browse the repository at this point in the history
Signed-off-by: wujixin <[email protected]>
  • Loading branch information
wujixin committed Jul 12, 2023
1 parent 269f460 commit 7ac7dc7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) error {
key := fmt.Sprintf("%s/%s", pod.Namespace, podName)
targetPortNameList := strset.NewWithSize(len(podNets))
portsNeedToDel := []string{}
annotationsNeedToDel := []string{}
subnetUsedByPort := make(map[string]string)

for _, podNet := range podNets {
Expand All @@ -1075,6 +1076,12 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) error {
if !targetPortNameList.Has(port.Name) {
portsNeedToDel = append(portsNeedToDel, port.Name)
subnetUsedByPort[port.Name] = port.ExternalIDs["ls"]
portNameSlice := strings.Split(port.Name, ".")
providerName := strings.Join(portNameSlice[2:], ".")
if providerName == util.OvnProvider {
continue
}
annotationsNeedToDel = append(annotationsNeedToDel, providerName)
}
}

Expand All @@ -1100,6 +1107,14 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) error {
}
}

for _, providerName := range annotationsNeedToDel {
for annotationKey := range pod.Annotations {
if strings.HasPrefix(key, providerName) {
delete(pod.Annotations, annotationKey)
}
}
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/daemon/ovs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ func generateNicName(containerID, ifname string) (string, string) {
if ifname == "eth0" {
return fmt.Sprintf("%s_h", containerID[0:12]), fmt.Sprintf("%s_c", containerID[0:12])
}
// The nic name is 14 length and have prefix pod in the Kubevirt v1.0.0
if strings.HasPrefix(ifname, "pod") && len(ifname) == 14 {
ifname = ifname[3 : len(ifname)-4]
return fmt.Sprintf("%s_%s_h", containerID[0:12-len(ifname)], ifname), fmt.Sprintf("%s_%s_c", containerID[0:12-len(ifname)], ifname)
}
return fmt.Sprintf("%s_%s_h", containerID[0:12-len(ifname)], ifname), fmt.Sprintf("%s_%s_c", containerID[0:12-len(ifname)], ifname)
}

Expand Down

0 comments on commit 7ac7dc7

Please sign in to comment.