Skip to content

Commit 1b22180

Browse files
camrynlnddq
andauthored
CNI async delete after ReleaseIPAddress (#2232)
add second check for releaseIP failure Co-authored-by: Quang Nguyen <[email protected]>
1 parent 028e162 commit 1b22180

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

cni/network/invoker_cns.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ func setHostOptions(ncSubnetPrefix *net.IPNet, options map[string]interface{}, i
279279

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

321322
if err = invoker.cnsClient.ReleaseIPAddress(context.TODO(), ipConfig); err != nil {
322-
// if the old API fails as well then we just return the error
323-
324-
logger.Error("Failed to release IP address from CNS using ReleaseIPAddress ",
325-
zap.String("infracontainerid", ipConfigs.InfraContainerID),
326-
zap.Error(err))
327-
328-
return errors.Wrap(err, fmt.Sprintf("failed to release IP %v using ReleaseIPAddress with err ", ipConfig.DesiredIPAddress)+"%w")
323+
if errors.As(err, &connectionErr) {
324+
addErr := fsnotify.AddFile(ipConfigs.PodInterfaceID, args.ContainerID, watcherPath)
325+
if addErr != nil {
326+
logger.Error("Failed to add file to watcher", zap.String("podInterfaceID", ipConfigs.PodInterfaceID), zap.String("containerID", args.ContainerID), zap.Error(addErr))
327+
return errors.Wrap(addErr, fmt.Sprintf("failed to add file to watcher with containerID %s and podInterfaceID %s", args.ContainerID, ipConfigs.PodInterfaceID))
328+
}
329+
} else {
330+
logger.Error("Failed to release IP address from CNS using ReleaseIPAddress ",
331+
zap.String("infracontainerid", ipConfigs.InfraContainerID),
332+
zap.Error(err))
333+
334+
return errors.Wrap(err, fmt.Sprintf("failed to release IP %v using ReleaseIPAddress with err ", ipConfig.DesiredIPAddress)+"%w")
335+
}
329336
}
330337
} else {
331-
var connectionErr *cnscli.ConnectionFailureErr
332338
if errors.As(err, &connectionErr) {
333339
addErr := fsnotify.AddFile(ipConfigs.PodInterfaceID, args.ContainerID, watcherPath)
334340
if addErr != nil {

0 commit comments

Comments
 (0)