From 5cac10651f5272332c8fec20f6943ccd38b65368 Mon Sep 17 00:00:00 2001 From: Shufang Date: Fri, 21 Feb 2020 10:58:23 -0800 Subject: [PATCH 1/4] Fix unnecessary consecutiveAdd for windows(#367). --- cni/network/network_windows.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cni/network/network_windows.go b/cni/network/network_windows.go index d839fa0175..88c651881a 100644 --- a/cni/network/network_windows.go +++ b/cni/network/network_windows.go @@ -39,6 +39,16 @@ func handleConsecutiveAdd(args *cniSkel.CmdArgs, endpointId string, nwInfo *netw return nil, err } + /* + * Return in case of endpoint is already attached and consecutive add call doesn't need to be handled + */ + endpoint, err := GetHNSEndpointByID(endpointId) + isAttached, err := endpoint.IsAttached(args.ContainerID) + if isAttached { + log.Printf("No consecutive Add needed since endpoint is already attatched") + return nil, err + } + hnsEndpoint, err := hcsshim.GetHNSEndpointByName(endpointId) if hnsEndpoint != nil { log.Printf("[net] Found existing endpoint through hcsshim: %+v", hnsEndpoint) From af15864cc7e4c362f8f9a420e6d4fa5c39d77c34 Mon Sep 17 00:00:00 2001 From: Shufang Date: Fri, 21 Feb 2020 10:58:23 -0800 Subject: [PATCH 2/4] Fix unnecessary consecutiveAdd for windows(#367). --- cni/network/network_windows.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cni/network/network_windows.go b/cni/network/network_windows.go index d839fa0175..4c76bacead 100644 --- a/cni/network/network_windows.go +++ b/cni/network/network_windows.go @@ -39,6 +39,15 @@ func handleConsecutiveAdd(args *cniSkel.CmdArgs, endpointId string, nwInfo *netw return nil, err } + /* + * Return in case of endpoint is already attached and consecutive add call doesn't need to be handled + */ + endpoint, _ := GetHNSEndpointByID(endpointId) + isAttached, err := endpoint.IsAttached(args.ContainerID) + if isAttached { + return nil, err + } + hnsEndpoint, err := hcsshim.GetHNSEndpointByName(endpointId) if hnsEndpoint != nil { log.Printf("[net] Found existing endpoint through hcsshim: %+v", hnsEndpoint) From 16210f31024d0090fb80a880ceeea1f818b1f854 Mon Sep 17 00:00:00 2001 From: Shufang Date: Fri, 21 Feb 2020 10:58:23 -0800 Subject: [PATCH 3/4] Fix unnecessary consecutiveAdd for windows(#367). --- cni/network/network_windows.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/cni/network/network_windows.go b/cni/network/network_windows.go index 88c651881a..a2d392034f 100644 --- a/cni/network/network_windows.go +++ b/cni/network/network_windows.go @@ -39,25 +39,20 @@ func handleConsecutiveAdd(args *cniSkel.CmdArgs, endpointId string, nwInfo *netw return nil, err } - /* - * Return in case of endpoint is already attached and consecutive add call doesn't need to be handled - */ - endpoint, err := GetHNSEndpointByID(endpointId) - isAttached, err := endpoint.IsAttached(args.ContainerID) - if isAttached { - log.Printf("No consecutive Add needed since endpoint is already attatched") - return nil, err - } - hnsEndpoint, err := hcsshim.GetHNSEndpointByName(endpointId) if hnsEndpoint != nil { log.Printf("[net] Found existing endpoint through hcsshim: %+v", hnsEndpoint) log.Printf("[net] Attaching ep %v to container %v", hnsEndpoint.Id, args.ContainerID) - err := hcsshim.HotAttachEndpoint(args.ContainerID, hnsEndpoint.Id) - if err != nil { - log.Printf("[cni-net] Failed to hot attach shared endpoint[%v] to container [%v], err:%v.", hnsEndpoint.Id, args.ContainerID, err) - return nil, err + endpoint, _ := hcsshim.GetHNSEndpointByID(hnsEndpoint.Id) + isAttached, _ := endpoint.IsAttached(args.ContainerID) + // Attach endpoint if it's not attached yet. If attached, populate result directly should be good enough. + if !isAttached { + err := hcsshim.HotAttachEndpoint(args.ContainerID, hnsEndpoint.Id) + if err != nil { + log.Printf("[cni-net] Failed to hot attach shared endpoint[%v] to container [%v], err:%v.", hnsEndpoint.Id, args.ContainerID, err) + return nil, err + } } // Populate result. From 2f60266e25a160bdd4150ea2f2576544d9259acf Mon Sep 17 00:00:00 2001 From: Shufang Date: Mon, 24 Feb 2020 14:56:13 -0800 Subject: [PATCH 4/4] Fix unnecessary consecutiveAdd for windows(#367). --- cni/network/network_windows.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cni/network/network_windows.go b/cni/network/network_windows.go index a2d392034f..615c871496 100644 --- a/cni/network/network_windows.go +++ b/cni/network/network_windows.go @@ -42,12 +42,11 @@ func handleConsecutiveAdd(args *cniSkel.CmdArgs, endpointId string, nwInfo *netw hnsEndpoint, err := hcsshim.GetHNSEndpointByName(endpointId) if hnsEndpoint != nil { log.Printf("[net] Found existing endpoint through hcsshim: %+v", hnsEndpoint) - log.Printf("[net] Attaching ep %v to container %v", hnsEndpoint.Id, args.ContainerID) - endpoint, _ := hcsshim.GetHNSEndpointByID(hnsEndpoint.Id) isAttached, _ := endpoint.IsAttached(args.ContainerID) - // Attach endpoint if it's not attached yet. If attached, populate result directly should be good enough. + // Attach endpoint if it's not attached yet. if !isAttached { + log.Printf("[net] Attaching ep %v to container %v", hnsEndpoint.Id, args.ContainerID) err := hcsshim.HotAttachEndpoint(args.ContainerID, hnsEndpoint.Id) if err != nil { log.Printf("[cni-net] Failed to hot attach shared endpoint[%v] to container [%v], err:%v.", hnsEndpoint.Id, args.ContainerID, err)