diff --git a/cni-plugin/pkg/ipamplugin/ipam_plugin.go b/cni-plugin/pkg/ipamplugin/ipam_plugin.go index 67b5554da17..814d07680a2 100644 --- a/cni-plugin/pkg/ipamplugin/ipam_plugin.go +++ b/cni-plugin/pkg/ipamplugin/ipam_plugin.go @@ -434,9 +434,6 @@ func cmdDel(args *skel.CmdArgs) error { }) logger.Info("Releasing address using handleID") - ctx := context.Background() - ctx, cancel := context.WithTimeout(ctx, 90*time.Second) - defer cancel() // Acquire a best-effort host-wide lock to prevent multiple copies of the CNI plugin trying to assign/delete // concurrently. ReleaseXXX is concurrency safe already but serialising the CNI plugins means that @@ -445,6 +442,10 @@ func cmdDel(args *skel.CmdArgs) error { unlock := acquireIPAMLockBestEffort(conf.IPAMLockFile) defer unlock() + ctx := context.Background() + ctx, cancel := context.WithTimeout(ctx, 90*time.Second) + defer cancel() + if err := calicoClient.IPAM().ReleaseByHandle(ctx, handleID); err != nil { if _, ok := err.(errors.ErrorResourceDoesNotExist); !ok { logger.WithError(err).Error("Failed to release address")