Skip to content

Commit

Permalink
fix: configure nic failed when ifname empty
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldin95 committed Apr 17, 2021
1 parent 3ff1772 commit c264bec
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
}

klog.Infof("add port request %v", podRequest)
var macAddr, ip, ipAddr, cidr, gw, subnet, ingress, egress, vlanID string
var macAddr, ip, ipAddr, cidr, gw, subnet, ingress, egress, vlanID, ifName string
var pod *v1.Pod
var err error
for i := 0; i < 15; i++ {
Expand Down Expand Up @@ -82,9 +82,13 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
egress = pod.Annotations[util.EgressRateAnnotation]
vlanID = pod.Annotations[fmt.Sprintf(util.VlanIdAnnotationTemplate, podRequest.Provider)]
ipAddr = util.GetIpAddrWithMask(ip, cidr)
ifName = podRequest.IfName
break
}

if ifName == "" {
ifName = "eth0"
}
if pod.Annotations[fmt.Sprintf(util.AllocatedAnnotationTemplate, podRequest.Provider)] != "true" {
err := fmt.Errorf("no address allocated to pod %s/%s, please see kube-ovn-controller logs to find errors", pod.Namespace, pod.Name)
klog.Error(err)
Expand All @@ -102,8 +106,8 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
}

if strings.Contains(podRequest.Provider, util.OvnProvider) && subnet != "" {
klog.Infof("create container interface %s mac %s, ip %s, cidr %s, gw %s", podRequest.IfName, macAddr, ipAddr, cidr, gw)
err := csh.configureNic(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, podRequest.IfName, macAddr, ipAddr, gw, ingress, egress, vlanID, podRequest.DeviceID)
klog.Infof("create container interface %s mac %s, ip %s, cidr %s, gw %s", ifName, macAddr, ipAddr, cidr, gw)
err := csh.configureNic(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, ifName, macAddr, ipAddr, gw, ingress, egress, vlanID, podRequest.DeviceID)
if err != nil {
errMsg := fmt.Errorf("configure nic failed %v", err)
klog.Error(errMsg)
Expand Down

0 comments on commit c264bec

Please sign in to comment.