diff --git a/cni/network/network.go b/cni/network/network.go index 8e36bc0f6..27d75adfd 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, // Hot attach at the time of endpoint creation } epPolicies := getPoliciesFromRuntimeCfg(nwCfg) diff --git a/cnm/network/network.go b/cnm/network/network.go index 860551c1a..599db6e4e 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 cbff7cbea..75dd3bcbe 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 742d338c2..699277cda 100644 --- a/network/endpoint_windows.go +++ b/network/endpoint_windows.go @@ -94,12 +94,17 @@ 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 { + 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) + if err != nil { + log.Printf("[net] Failed to attach endpoint: %v.", err) + return nil, err + } } // Create the endpoint object.