Skip to content

Commit a7af897

Browse files
committed
support recreate a backup pod with full annotation (#3144)
* Support full ready annotation but no ip , pod handle add * cni wait for backup pod ip to be created * no need to make sure node on ip
1 parent 515bdb7 commit a7af897

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

pkg/controller/pod.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ func (c *Controller) enqueueAddPod(obj interface{}) {
215215
return
216216
}
217217

218-
exist, err := c.podNeedSync(p)
218+
need, err := c.podNeedSync(p)
219219
if err != nil {
220220
klog.Errorf("invalid pod net: %v", err)
221221
return
222222
}
223-
if exist {
223+
if need {
224224
klog.Infof("enqueue add pod %s", key)
225225
c.addOrUpdatePodQueue.Add(key)
226226
}
@@ -1266,6 +1266,13 @@ func (c *Controller) podNeedSync(pod *v1.Pod) (bool, error) {
12661266
if pod.Annotations[fmt.Sprintf(util.RoutedAnnotationTemplate, n.ProviderName)] != "true" {
12671267
return true, nil
12681268
}
1269+
ipName := ovs.PodNameToPortName(pod.Name, pod.Namespace, n.ProviderName)
1270+
if _, err = c.ipsLister.Get(ipName); err != nil {
1271+
err = fmt.Errorf("pod has no ip %s: %v", ipName, err)
1272+
// need to sync to create ip
1273+
klog.Error(err)
1274+
return true, nil
1275+
}
12691276
}
12701277
return false, nil
12711278
}

pkg/daemon/handler.go

+28-16
Original file line numberDiff line numberDiff line change
@@ -331,24 +331,36 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
331331

332332
func (csh cniServerHandler) UpdateIPCr(podRequest request.CniRequest, subnet, ip string) error {
333333
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
350361
}
351362
}
363+
// update ip spec node is not that necessary, so we just log the error
352364
return nil
353365
}
354366

0 commit comments

Comments
 (0)