diff --git a/cni/network/multitenancy.go b/cni/network/multitenancy.go index d36e609a04..ce16c2d5c6 100644 --- a/cni/network/multitenancy.go +++ b/cni/network/multitenancy.go @@ -351,7 +351,7 @@ func (plugin *NetPlugin) GetMultiTenancyCNIResult( result, cnsNetworkConfig, subnetPrefix, err := plugin.multitenancyClient.GetContainerNetworkConfiguration(ctx, nwCfg, k8sPodName, k8sNamespace, ifName) if err != nil { log.Printf("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v", k8sPodName, k8sNamespace, err) - return nil, nil, net.IPNet{}, nil, fmt.Errorf("%w", err) + return nil, nil, net.IPNet{}, nil, fmt.Errorf("GetContainerNetworkConfiguration failed:%w", err) } log.Printf("PrimaryInterfaceIdentifier :%v", subnetPrefix.IP.String()) diff --git a/cni/network/network.go b/cni/network/network.go index 889bc0e4c1..ef24be504f 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -314,7 +314,6 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error { result *cniTypesCurr.Result resultV6 *cniTypesCurr.Result azIpamResult *cniTypesCurr.Result - iface *cniTypesCurr.Interface subnetPrefix net.IPNet cnsNetworkConfig *cns.GetNetworkContainerResponse enableInfraVnet bool @@ -354,7 +353,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error { result = &cniTypesCurr.Result{} } - iface = &cniTypesCurr.Interface{ + iface := &cniTypesCurr.Interface{ Name: args.IfName, } result.Interfaces = append(result.Interfaces, iface) @@ -509,7 +508,9 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error { } defer func() { - err = plugin.cleanupAllocationOnError(err, result, resultV6, nwCfg, args, options) + if err != nil { + plugin.cleanupAllocationOnError(result, resultV6, nwCfg, args, options) + } }() } @@ -539,25 +540,22 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error { return nil } -func (plugin *NetPlugin) cleanupAllocationOnError(err error, +func (plugin *NetPlugin) cleanupAllocationOnError( result, resultV6 *cniTypesCurr.Result, nwCfg *cni.NetworkConfig, args *cniSkel.CmdArgs, - options map[string]interface{}) error { - if err != nil { - if result != nil && len(result.IPs) > 0 { - if er := plugin.ipamInvoker.Delete(&result.IPs[0].Address, nwCfg, args, options); er != nil { - err = plugin.Errorf("Failed to cleanup when NwInfo was nil with error %v, after Add failed with error %w", er, err) - } + options map[string]interface{}) { + + if result != nil && len(result.IPs) > 0 { + if er := plugin.ipamInvoker.Delete(&result.IPs[0].Address, nwCfg, args, options); er != nil { + log.Errorf("Failed to cleanup ip allocation on failure: %v", er) } - if resultV6 != nil && len(resultV6.IPs) > 0 { - if er := plugin.ipamInvoker.Delete(&resultV6.IPs[0].Address, nwCfg, args, options); er != nil { - err = plugin.Errorf("Failed to cleanup when NwInfo was nil with error %v, after Add failed with error %w", er, err) - } + } + if resultV6 != nil && len(resultV6.IPs) > 0 { + if er := plugin.ipamInvoker.Delete(&resultV6.IPs[0].Address, nwCfg, args, options); er != nil { + log.Errorf("Failed to cleanup ipv6 allocation on failure: %v", er) } } - - return err } func (plugin *NetPlugin) createNetworkInternal( @@ -649,7 +647,7 @@ func (plugin *NetPlugin) createNetworkInternal( err = plugin.nm.CreateNetwork(&nwInfo) if err != nil { - err = plugin.Errorf("Failed to create network: %v", err) + err = plugin.Errorf("createNetworkInternal: Failed to create network: %v", err) } return nwInfo, err