@@ -1163,10 +1163,12 @@ func (c *Controller) syncKubeOvnNet(cachedPod, pod *v1.Pod, podNets []*kubeovnNe
1163
1163
portName := ovs .PodNameToPortName (podName , pod .Namespace , podNet .ProviderName )
1164
1164
targetPortNameList .Add (portName )
1165
1165
if podNet .IPRequest != "" {
1166
+ klog .Infof ("pod %s/%s use custom IP %s for provider %s" , pod .Namespace , pod .Name , podNet .IPRequest , podNet .ProviderName )
1166
1167
annotationsNeedToAdd [fmt .Sprintf (util .IPAddressAnnotationTemplate , podNet .ProviderName )] = podNet .IPRequest
1167
1168
}
1168
1169
1169
1170
if podNet .MacRequest != "" {
1171
+ klog .Infof ("pod %s/%s use custom MAC %s for provider %s" , pod .Namespace , pod .Name , podNet .MacRequest , podNet .ProviderName )
1170
1172
annotationsNeedToAdd [fmt .Sprintf (util .MacAddressAnnotationTemplate , podNet .ProviderName )] = podNet .MacRequest
1171
1173
}
1172
1174
}
@@ -1194,42 +1196,39 @@ func (c *Controller) syncKubeOvnNet(cachedPod, pod *v1.Pod, podNets []*kubeovnNe
1194
1196
return pod , nil
1195
1197
}
1196
1198
1197
- if len (portsNeedToDel ) > 0 {
1198
- for _ , portNeedDel := range portsNeedToDel {
1199
- klog .Infof ("release port %s for pod %s" , portNeedDel , podName )
1200
- if subnet , ok := c .ipam .Subnets [subnetUsedByPort [portNeedDel ]]; ok {
1201
- subnet .ReleaseAddressWithNicName (podName , portNeedDel )
1202
- }
1203
- if err := c .OVNNbClient .DeleteLogicalSwitchPort (portNeedDel ); err != nil {
1204
- klog .Errorf ("failed to delete lsp %s, %v" , portNeedDel , err )
1199
+ for _ , portNeedDel := range portsNeedToDel {
1200
+ klog .Infof ("release port %s for pod %s" , portNeedDel , podName )
1201
+ if subnet , ok := c .ipam .Subnets [subnetUsedByPort [portNeedDel ]]; ok {
1202
+ subnet .ReleaseAddressWithNicName (podName , portNeedDel )
1203
+ }
1204
+ if err := c .OVNNbClient .DeleteLogicalSwitchPort (portNeedDel ); err != nil {
1205
+ klog .Errorf ("failed to delete lsp %s, %v" , portNeedDel , err )
1206
+ return nil , err
1207
+ }
1208
+ if err := c .config .KubeOvnClient .KubeovnV1 ().IPs ().Delete (context .Background (), portNeedDel , metav1.DeleteOptions {}); err != nil {
1209
+ if ! k8serrors .IsNotFound (err ) {
1210
+ klog .Errorf ("failed to delete ip %s, %v" , portNeedDel , err )
1205
1211
return nil , err
1206
1212
}
1207
- if err := c .config .KubeOvnClient .KubeovnV1 ().IPs ().Delete (context .Background (), portNeedDel , metav1.DeleteOptions {}); err != nil {
1208
- if ! k8serrors .IsNotFound (err ) {
1209
- klog .Errorf ("failed to delete ip %s, %v" , portNeedDel , err )
1210
- return nil , err
1211
- }
1212
- }
1213
1213
}
1214
+ }
1214
1215
1215
- for _ , providerName := range annotationsNeedToDel {
1216
- for annotationKey := range pod .Annotations {
1217
- if strings .HasPrefix (annotationKey , providerName ) {
1218
- delete (pod .Annotations , annotationKey )
1219
- }
1216
+ for _ , providerName := range annotationsNeedToDel {
1217
+ for annotationKey := range pod .Annotations {
1218
+ if strings .HasPrefix (annotationKey , providerName ) {
1219
+ delete (pod .Annotations , annotationKey )
1220
1220
}
1221
1221
}
1222
1222
}
1223
1223
1224
- if len (annotationsNeedToAdd ) > 0 {
1225
- for annotationKey , annotationValue := range annotationsNeedToAdd {
1226
- pod .Annotations [annotationKey ] = annotationValue
1227
- }
1224
+ for annotationKey , annotationValue := range annotationsNeedToAdd {
1225
+ pod .Annotations [annotationKey ] = annotationValue
1228
1226
}
1229
1227
1230
1228
if len (cachedPod .Annotations ) == len (pod .Annotations ) {
1231
1229
return pod , nil
1232
1230
}
1231
+
1233
1232
patch , err := util .GenerateMergePatchPayload (cachedPod , pod )
1234
1233
if err != nil {
1235
1234
klog .Errorf ("failed to generate patch payload for pod '%s', %v" , pod .Name , err )
@@ -1572,10 +1571,7 @@ func (c *Controller) getPodAttachmentNet(pod *v1.Pod) ([]*kubeovnNet, error) {
1572
1571
ret .IPRequest = attach .IPRequest [0 ]
1573
1572
}
1574
1573
1575
- if attach .MacRequest != "" {
1576
- ret .MacRequest = attach .MacRequest
1577
- }
1578
-
1574
+ ret .MacRequest = attach .MacRequest
1579
1575
result = append (result , ret )
1580
1576
} else {
1581
1577
providerName = fmt .Sprintf ("%s.%s" , attach .Name , attach .Namespace )
0 commit comments