Skip to content
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
2 changes: 1 addition & 1 deletion cni/network/multitenancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
32 changes: 15 additions & 17 deletions cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}()
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down