From d45b7f79287cb3f6551b2755f57e02c1141629aa Mon Sep 17 00:00:00 2001 From: Ashvin Deodhar Date: Fri, 12 Apr 2019 12:10:03 -0700 Subject: [PATCH 1/2] Skip HotAttachEp from CNM create endpoint --- cni/network/network.go | 1 + cnm/network/network.go | 5 +++-- network/endpoint.go | 1 + network/endpoint_windows.go | 14 ++++++++------ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cni/network/network.go b/cni/network/network.go index 8e36bc0f6d..8a9cbb74c7 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -452,6 +452,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error { EnableInfraVnet: enableInfraVnet, PODName: k8sPodName, PODNameSpace: k8sNamespace, + SkipHotAttachEp: false, } epPolicies := getPoliciesFromRuntimeCfg(nwCfg) diff --git a/cnm/network/network.go b/cnm/network/network.go index 860551c1ad..599db6e4e7 100644 --- a/cnm/network/network.go +++ b/cnm/network/network.go @@ -229,8 +229,9 @@ func (plugin *netPlugin) createEndpoint(w http.ResponseWriter, r *http.Request) } epInfo := network.EndpointInfo{ - Id: req.EndpointID, - IPAddresses: []net.IPNet{*ipv4Address}, + Id: req.EndpointID, + IPAddresses: []net.IPNet{*ipv4Address}, + SkipHotAttachEp: true, // Skip hot attach endpoint as it's done in Join } epInfo.Data = make(map[string]interface{}) diff --git a/network/endpoint.go b/network/endpoint.go index cbff7cbeab..75dd3bcbe4 100644 --- a/network/endpoint.go +++ b/network/endpoint.go @@ -61,6 +61,7 @@ type EndpointInfo struct { PODNameSpace string Data map[string]interface{} InfraVnetAddressSpace string + SkipHotAttachEp bool } // RouteInfo contains information about an IP route. diff --git a/network/endpoint_windows.go b/network/endpoint_windows.go index 742d338c21..d13f26d258 100644 --- a/network/endpoint_windows.go +++ b/network/endpoint_windows.go @@ -94,12 +94,14 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) { } }() - // Attach the endpoint. - log.Printf("[net] Attaching endpoint %v to container %v.", hnsResponse.Id, epInfo.ContainerID) - err = hcsshim.HotAttachEndpoint(epInfo.ContainerID, hnsResponse.Id) - if err != nil { - log.Printf("[net] Failed to attach endpoint: %v.", err) - return nil, err + if !epInfo.SkipHotAttachEp { + // Attach the endpoint. + log.Printf("[net] Attaching endpoint %v to container %v.", hnsResponse.Id, epInfo.ContainerID) + err = hcsshim.HotAttachEndpoint(epInfo.ContainerID, hnsResponse.Id) + if err != nil { + log.Printf("[net] Failed to attach endpoint: %v.", err) + return nil, err + } } // Create the endpoint object. From 9ca5652f49bc58f266591b0f0bb14880fdc966b1 Mon Sep 17 00:00:00 2001 From: Ashvin Deodhar Date: Fri, 12 Apr 2019 16:12:07 -0700 Subject: [PATCH 2/2] Address review comments --- cni/network/network.go | 2 +- network/endpoint_windows.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cni/network/network.go b/cni/network/network.go index 8a9cbb74c7..27d75adfdb 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -452,7 +452,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error { EnableInfraVnet: enableInfraVnet, PODName: k8sPodName, PODNameSpace: k8sNamespace, - SkipHotAttachEp: false, + SkipHotAttachEp: false, // Hot attach at the time of endpoint creation } epPolicies := getPoliciesFromRuntimeCfg(nwCfg) diff --git a/network/endpoint_windows.go b/network/endpoint_windows.go index d13f26d258..699277cda4 100644 --- a/network/endpoint_windows.go +++ b/network/endpoint_windows.go @@ -94,7 +94,10 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) { } }() - if !epInfo.SkipHotAttachEp { + if epInfo.SkipHotAttachEp { + log.Printf("[net] Skipping attaching the endpoint %v to container %v.", + hnsResponse.Id, epInfo.ContainerID) + } else { // Attach the endpoint. log.Printf("[net] Attaching endpoint %v to container %v.", hnsResponse.Id, epInfo.ContainerID) err = hcsshim.HotAttachEndpoint(epInfo.ContainerID, hnsResponse.Id)