Skip to content

Commit

Permalink
CNI async delete after ReleaseIPAddress (#2232)
Browse files Browse the repository at this point in the history
add second check for releaseIP failure

Co-authored-by: Quang Nguyen <[email protected]>
  • Loading branch information
camrynl and nddq authored Sep 21, 2023
1 parent 028e162 commit 1b22180
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions cni/network/invoker_cns.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func setHostOptions(ncSubnetPrefix *net.IPNet, options map[string]interface{}, i

// Delete calls into the releaseipconfiguration API in CNS
func (invoker *CNSIPAMInvoker) Delete(address *net.IPNet, nwCfg *cni.NetworkConfig, args *cniSkel.CmdArgs, _ map[string]interface{}) error { //nolint
var connectionErr *cnscli.ConnectionFailureErr
// Parse Pod arguments.
podInfo := cns.KubernetesPodInfo{
PodName: invoker.podName,
Expand Down Expand Up @@ -319,16 +320,21 @@ func (invoker *CNSIPAMInvoker) Delete(address *net.IPNet, nwCfg *cni.NetworkConf
}

if err = invoker.cnsClient.ReleaseIPAddress(context.TODO(), ipConfig); err != nil {
// if the old API fails as well then we just return the error

logger.Error("Failed to release IP address from CNS using ReleaseIPAddress ",
zap.String("infracontainerid", ipConfigs.InfraContainerID),
zap.Error(err))

return errors.Wrap(err, fmt.Sprintf("failed to release IP %v using ReleaseIPAddress with err ", ipConfig.DesiredIPAddress)+"%w")
if errors.As(err, &connectionErr) {
addErr := fsnotify.AddFile(ipConfigs.PodInterfaceID, args.ContainerID, watcherPath)
if addErr != nil {
logger.Error("Failed to add file to watcher", zap.String("podInterfaceID", ipConfigs.PodInterfaceID), zap.String("containerID", args.ContainerID), zap.Error(addErr))
return errors.Wrap(addErr, fmt.Sprintf("failed to add file to watcher with containerID %s and podInterfaceID %s", args.ContainerID, ipConfigs.PodInterfaceID))
}
} else {
logger.Error("Failed to release IP address from CNS using ReleaseIPAddress ",
zap.String("infracontainerid", ipConfigs.InfraContainerID),
zap.Error(err))

return errors.Wrap(err, fmt.Sprintf("failed to release IP %v using ReleaseIPAddress with err ", ipConfig.DesiredIPAddress)+"%w")
}
}
} else {
var connectionErr *cnscli.ConnectionFailureErr
if errors.As(err, &connectionErr) {
addErr := fsnotify.AddFile(ipConfigs.PodInterfaceID, args.ContainerID, watcherPath)
if addErr != nil {
Expand Down

0 comments on commit 1b22180

Please sign in to comment.