Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support recreate a backup pod with full annotation #3144

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ func (c *Controller) enqueueAddPod(obj interface{}) {
return
}

exist, err := c.podNeedSync(p)
need, err := c.podNeedSync(p)
if err != nil {
klog.Errorf("invalid pod net: %v", err)
return
}
if exist {
if need {
klog.Infof("enqueue add pod %s", key)
c.addOrUpdatePodQueue.Add(key)
}
Expand Down Expand Up @@ -1266,6 +1266,13 @@ func (c *Controller) podNeedSync(pod *v1.Pod) (bool, error) {
if pod.Annotations[fmt.Sprintf(util.RoutedAnnotationTemplate, n.ProviderName)] != "true" {
return true, nil
}
ipName := ovs.PodNameToPortName(pod.Name, pod.Namespace, n.ProviderName)
if _, err = c.ipsLister.Get(ipName); err != nil {
err = fmt.Errorf("pod has no ip %s: %v", ipName, err)
// need to sync to create ip
klog.Error(err)
return true, nil
}
}
return false, nil
}
Expand Down
44 changes: 28 additions & 16 deletions pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,24 +331,36 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon

func (csh cniServerHandler) UpdateIPCr(podRequest request.CniRequest, subnet, ip string) error {
ipCrName := ovs.PodNameToPortName(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider)
oriIpCr, err := csh.KubeOvnClient.KubeovnV1().IPs().Get(context.Background(), ipCrName, metav1.GetOptions{})
if err != nil {
errMsg := fmt.Errorf("failed to get ip crd for %s, %v", ip, err)
klog.Error(errMsg)
return errMsg
} else {
ipCr := oriIpCr.DeepCopy()
ipCr.Spec.NodeName = csh.Config.NodeName
ipCr.Spec.AttachIPs = []string{}
ipCr.Labels[subnet] = ""
ipCr.Spec.AttachSubnets = []string{}
ipCr.Spec.AttachMacs = []string{}
if _, err := csh.KubeOvnClient.KubeovnV1().IPs().Update(context.Background(), ipCr, metav1.UpdateOptions{}); err != nil {
errMsg := fmt.Errorf("failed to update ip crd for %s, %v", ip, err)
klog.Error(errMsg)
return errMsg
for i := 0; i < 20; i++ {
oriIpCr, err := csh.KubeOvnClient.KubeovnV1().IPs().Get(context.Background(), ipCrName, metav1.GetOptions{})
if err != nil {
err = fmt.Errorf("failed to get ip crd for %s, %v", ip, err)
// maybe create a backup pod with previous annotations
klog.Error(err)
} else {
if oriIpCr.Spec.NodeName != csh.Config.NodeName {
ipCr := oriIpCr.DeepCopy()
ipCr.Spec.NodeName = csh.Config.NodeName
ipCr.Spec.AttachIPs = []string{}
ipCr.Labels[subnet] = ""
ipCr.Spec.AttachSubnets = []string{}
ipCr.Spec.AttachMacs = []string{}
if _, err := csh.KubeOvnClient.KubeovnV1().IPs().Update(context.Background(), ipCr, metav1.UpdateOptions{}); err != nil {
err = fmt.Errorf("failed to update ip crd for %s, %v", ip, err)
klog.Error(err)
} else {
return nil
}
}
}
if err != nil {
klog.Warning("wait pod ip %s to be ready", ipCrName)
time.Sleep(1 * time.Second)
} else {
return nil
}
}
// update ip spec node is not that necessary, so we just log the error
return nil
}

Expand Down