Skip to content

Commit

Permalink
cni wait for backup pod ip to be created
Browse files Browse the repository at this point in the history
  • Loading branch information
bobz965 committed Aug 16, 2023
1 parent 5e6e472 commit f83b7c1
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,25 +331,32 @@ 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)
var errMsg error
for i := 0; i < 20; i++ {
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)
// maybe create a backup pod with previous annotations
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)
} else {
return nil
}
if errMsg != nil {
klog.Warning("wait pod ip %s to be ready", ipCrName)
time.Sleep(1 * time.Second)
}
}
return nil
return errMsg
}

func (csh cniServerHandler) handleDel(req *restful.Request, resp *restful.Response) {

Check failure on line 362 in pkg/daemon/handler.go

View workflow job for this annotation

GitHub Actions / Build arm64

syntax error: unexpected { at end of statement

Check failure on line 362 in pkg/daemon/handler.go

View workflow job for this annotation

GitHub Actions / Build arm64

syntax error: unexpected { at end of statement

Check failure on line 362 in pkg/daemon/handler.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

syntax error: unexpected { at end of statement

Check failure on line 362 in pkg/daemon/handler.go

View workflow job for this annotation

GitHub Actions / Build kube-ovn

syntax error: unexpected { at end of statement
Expand Down

0 comments on commit f83b7c1

Please sign in to comment.