Skip to content

Commit e28f583

Browse files
Skip HotAttachEp from CNM createEndpoint (#332)
* Skip HotAttachEp from CNM create endpoint * Address review comments
1 parent a1f804a commit e28f583

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

cni/network/network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
452452
EnableInfraVnet: enableInfraVnet,
453453
PODName: k8sPodName,
454454
PODNameSpace: k8sNamespace,
455+
SkipHotAttachEp: false, // Hot attach at the time of endpoint creation
455456
}
456457

457458
epPolicies := getPoliciesFromRuntimeCfg(nwCfg)

cnm/network/network.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ func (plugin *netPlugin) createEndpoint(w http.ResponseWriter, r *http.Request)
229229
}
230230

231231
epInfo := network.EndpointInfo{
232-
Id: req.EndpointID,
233-
IPAddresses: []net.IPNet{*ipv4Address},
232+
Id: req.EndpointID,
233+
IPAddresses: []net.IPNet{*ipv4Address},
234+
SkipHotAttachEp: true, // Skip hot attach endpoint as it's done in Join
234235
}
235236

236237
epInfo.Data = make(map[string]interface{})

network/endpoint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type EndpointInfo struct {
6161
PODNameSpace string
6262
Data map[string]interface{}
6363
InfraVnetAddressSpace string
64+
SkipHotAttachEp bool
6465
}
6566

6667
// RouteInfo contains information about an IP route.

network/endpoint_windows.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
9494
}
9595
}()
9696

97-
// Attach the endpoint.
98-
log.Printf("[net] Attaching endpoint %v to container %v.", hnsResponse.Id, epInfo.ContainerID)
99-
err = hcsshim.HotAttachEndpoint(epInfo.ContainerID, hnsResponse.Id)
100-
if err != nil {
101-
log.Printf("[net] Failed to attach endpoint: %v.", err)
102-
return nil, err
97+
if epInfo.SkipHotAttachEp {
98+
log.Printf("[net] Skipping attaching the endpoint %v to container %v.",
99+
hnsResponse.Id, epInfo.ContainerID)
100+
} else {
101+
// Attach the endpoint.
102+
log.Printf("[net] Attaching endpoint %v to container %v.", hnsResponse.Id, epInfo.ContainerID)
103+
err = hcsshim.HotAttachEndpoint(epInfo.ContainerID, hnsResponse.Id)
104+
if err != nil {
105+
log.Printf("[net] Failed to attach endpoint: %v.", err)
106+
return nil, err
107+
}
103108
}
104109

105110
// Create the endpoint object.

0 commit comments

Comments
 (0)