Skip to content

Commit 1b42693

Browse files
committed
pod should use mac and ips provider by multus firstly (#4800)
* pod should use mac and ips provider by multus firstly --------- Signed-off-by: clyi <clyi@alauda.io>
1 parent e2ecef1 commit 1b42693

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

pkg/controller/pod.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -1151,11 +1151,21 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) (*v1.Pod
11511151
targetPortNameList := strset.NewWithSize(len(podNets))
11521152
portsNeedToDel := []string{}
11531153
annotationsNeedToDel := []string{}
1154+
annotationsNeedToAdd := make(map[string]string)
11541155
subnetUsedByPort := make(map[string]string)
11551156

11561157
for _, podNet := range podNets {
11571158
portName := ovs.PodNameToPortName(podName, pod.Namespace, podNet.ProviderName)
11581159
targetPortNameList.Add(portName)
1160+
if podNet.IPRequest != "" {
1161+
klog.Infof("pod %s/%s use custom IP %s for provider %s", pod.Namespace, pod.Name, podNet.IPRequest, podNet.ProviderName)
1162+
annotationsNeedToAdd[fmt.Sprintf(util.IPAddressAnnotationTemplate, podNet.ProviderName)] = podNet.IPRequest
1163+
}
1164+
1165+
if podNet.MacRequest != "" {
1166+
klog.Infof("pod %s/%s use custom MAC %s for provider %s", pod.Namespace, pod.Name, podNet.MacRequest, podNet.ProviderName)
1167+
annotationsNeedToAdd[fmt.Sprintf(util.MacAddressAnnotationTemplate, podNet.ProviderName)] = podNet.MacRequest
1168+
}
11591169
}
11601170

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

1180-
if len(portsNeedToDel) == 0 {
1190+
if len(portsNeedToDel) == 0 && len(annotationsNeedToAdd) == 0 {
11811191
return pod, nil
11821192
}
11831193

@@ -1206,6 +1216,11 @@ func (c *Controller) syncKubeOvnNet(pod *v1.Pod, podNets []*kubeovnNet) (*v1.Pod
12061216
}
12071217
}
12081218
}
1219+
1220+
for key, value := range annotationsNeedToAdd {
1221+
patch[key] = value
1222+
}
1223+
12091224
if len(patch) == 0 {
12101225
return pod, nil
12111226
}
@@ -1461,6 +1476,8 @@ type kubeovnNet struct {
14611476
Subnet *kubeovnv1.Subnet
14621477
IsDefault bool
14631478
AllowLiveMigration bool
1479+
IPRequest string
1480+
MacRequest string
14641481
}
14651482

14661483
func (c *Controller) getPodAttachmentNet(pod *v1.Pod) ([]*kubeovnNet, error) {
@@ -1538,13 +1555,21 @@ func (c *Controller) getPodAttachmentNet(pod *v1.Pod) ([]*kubeovnNet, error) {
15381555
return nil, err
15391556
}
15401557
}
1541-
result = append(result, &kubeovnNet{
1558+
1559+
ret := &kubeovnNet{
15421560
Type: providerTypeOriginal,
15431561
ProviderName: providerName,
15441562
Subnet: subnet,
15451563
IsDefault: isDefault,
15461564
AllowLiveMigration: allowLiveMigration,
1547-
})
1565+
}
1566+
1567+
if len(attach.IPRequest) != 0 {
1568+
ret.IPRequest = strings.Join(attach.IPRequest, ",")
1569+
}
1570+
1571+
ret.MacRequest = attach.MacRequest
1572+
result = append(result, ret)
15481573
} else {
15491574
providerName = fmt.Sprintf("%s.%s", attach.Name, attach.Namespace)
15501575
for _, subnet := range subnets {

0 commit comments

Comments
 (0)