Skip to content

Commit

Permalink
pod should use mac and ips provider by multus firstly (#4800) (#4875)
Browse files Browse the repository at this point in the history
* pod should use mac and ips provider by multus firstly

---------

Signed-off-by: clyi <[email protected]>
  • Loading branch information
changluyi authored Dec 27, 2024
1 parent e2ecef1 commit 1f518d9
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,11 +1151,21 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) (*v1.Pod
targetPortNameList := strset.NewWithSize(len(podNets))
portsNeedToDel := []string{}
annotationsNeedToDel := []string{}
annotationsNeedToAdd := make(map[string]string)
subnetUsedByPort := make(map[string]string)

for _, podNet := range podNets {
portName := ovs.PodNameToPortName(podName, pod.Namespace, podNet.ProviderName)
targetPortNameList.Add(portName)
if podNet.IPRequest != "" {
klog.Infof("pod %s/%s use custom IP %s for provider %s", pod.Namespace, pod.Name, podNet.IPRequest, podNet.ProviderName)
annotationsNeedToAdd[fmt.Sprintf(util.IPAddressAnnotationTemplate, podNet.ProviderName)] = podNet.IPRequest
}

if podNet.MacRequest != "" {
klog.Infof("pod %s/%s use custom MAC %s for provider %s", pod.Namespace, pod.Name, podNet.MacRequest, podNet.ProviderName)
annotationsNeedToAdd[fmt.Sprintf(util.MacAddressAnnotationTemplate, podNet.ProviderName)] = podNet.MacRequest
}
}

ports, err := c.OVNNbClient.ListNormalLogicalSwitchPorts(true, map[string]string{"pod": key})
Expand All @@ -1177,7 +1187,7 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) (*v1.Pod
}
}

if len(portsNeedToDel) == 0 {
if len(portsNeedToDel) == 0 && len(annotationsNeedToAdd) == 0 {
return pod, nil
}

Expand Down Expand Up @@ -1206,6 +1216,11 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) (*v1.Pod
}
}
}

for key, value := range annotationsNeedToAdd {
patch[key] = value
}

if len(patch) == 0 {
return pod, nil
}
Expand Down Expand Up @@ -1461,6 +1476,8 @@ type kubeovnNet struct {
Subnet *kubeovnv1.Subnet
IsDefault bool
AllowLiveMigration bool
IPRequest string
MacRequest string
}

func (c *Controller) getPodAttachmentNet(pod *v1.Pod) ([]*kubeovnNet, error) {
Expand Down Expand Up @@ -1538,13 +1555,21 @@ func (c *Controller) getPodAttachmentNet(pod *v1.Pod) ([]*kubeovnNet, error) {
return nil, err
}
}
result = append(result, &kubeovnNet{

ret := &kubeovnNet{
Type: providerTypeOriginal,
ProviderName: providerName,
Subnet: subnet,
IsDefault: isDefault,
AllowLiveMigration: allowLiveMigration,
})
}

if len(attach.IPRequest) != 0 {
ret.IPRequest = strings.Join(attach.IPRequest, ",")
}

ret.MacRequest = attach.MacRequest
result = append(result, ret)
} else {
providerName = fmt.Sprintf("%s.%s", attach.Name, attach.Namespace)
for _, subnet := range subnets {
Expand Down

0 comments on commit 1f518d9

Please sign in to comment.