@@ -331,24 +331,36 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
331
331
332
332
func (csh cniServerHandler ) UpdateIPCr (podRequest request.CniRequest , subnet , ip string ) error {
333
333
ipCrName := ovs .PodNameToPortName (podRequest .PodName , podRequest .PodNamespace , podRequest .Provider )
334
- oriIpCr , err := csh .KubeOvnClient .KubeovnV1 ().IPs ().Get (context .Background (), ipCrName , metav1.GetOptions {})
335
- if err != nil {
336
- errMsg := fmt .Errorf ("failed to get ip crd for %s, %v" , ip , err )
337
- klog .Error (errMsg )
338
- return errMsg
339
- } else {
340
- ipCr := oriIpCr .DeepCopy ()
341
- ipCr .Spec .NodeName = csh .Config .NodeName
342
- ipCr .Spec .AttachIPs = []string {}
343
- ipCr .Labels [subnet ] = ""
344
- ipCr .Spec .AttachSubnets = []string {}
345
- ipCr .Spec .AttachMacs = []string {}
346
- if _ , err := csh .KubeOvnClient .KubeovnV1 ().IPs ().Update (context .Background (), ipCr , metav1.UpdateOptions {}); err != nil {
347
- errMsg := fmt .Errorf ("failed to update ip crd for %s, %v" , ip , err )
348
- klog .Error (errMsg )
349
- return errMsg
334
+ for i := 0 ; i < 20 ; i ++ {
335
+ oriIpCr , err := csh .KubeOvnClient .KubeovnV1 ().IPs ().Get (context .Background (), ipCrName , metav1.GetOptions {})
336
+ if err != nil {
337
+ err = fmt .Errorf ("failed to get ip crd for %s, %v" , ip , err )
338
+ // maybe create a backup pod with previous annotations
339
+ klog .Error (err )
340
+ } else {
341
+ if oriIpCr .Spec .NodeName != csh .Config .NodeName {
342
+ ipCr := oriIpCr .DeepCopy ()
343
+ ipCr .Spec .NodeName = csh .Config .NodeName
344
+ ipCr .Spec .AttachIPs = []string {}
345
+ ipCr .Labels [subnet ] = ""
346
+ ipCr .Spec .AttachSubnets = []string {}
347
+ ipCr .Spec .AttachMacs = []string {}
348
+ if _ , err := csh .KubeOvnClient .KubeovnV1 ().IPs ().Update (context .Background (), ipCr , metav1.UpdateOptions {}); err != nil {
349
+ err = fmt .Errorf ("failed to update ip crd for %s, %v" , ip , err )
350
+ klog .Error (err )
351
+ } else {
352
+ return nil
353
+ }
354
+ }
355
+ }
356
+ if err != nil {
357
+ klog .Warning ("wait pod ip %s to be ready" , ipCrName )
358
+ time .Sleep (1 * time .Second )
359
+ } else {
360
+ return nil
350
361
}
351
362
}
363
+ // update ip spec node is not that necessary, so we just log the error
352
364
return nil
353
365
}
354
366
0 commit comments