Update Windows CNI implementation to free resources in case of HNS failures (#223)
Update Windows CNI implementation to free resources in case of HNS failures
This commit is contained in:
Родитель
95b911c343
Коммит
3ea96edae3
|
@ -1,6 +1,7 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/Azure/azure-container-networking/cni"
|
||||
|
@ -19,7 +20,7 @@ import (
|
|||
* Issue link: https://github.com/kubernetes/kubernetes/issues/57253
|
||||
*/
|
||||
func handleConsecutiveAdd(containerId, endpointId string, nwInfo *network.NetworkInfo, nwCfg *cni.NetworkConfig) (*cniTypesCurr.Result, error) {
|
||||
hnsEndpoint, _ := hcsshim.GetHNSEndpointByName(endpointId)
|
||||
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, containerId)
|
||||
|
@ -55,7 +56,8 @@ func handleConsecutiveAdd(containerId, endpointId string, nwInfo *network.Networ
|
|||
return result, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
err = fmt.Errorf("GetHNSEndpointByName for %v returned nil with err %v", endpointId, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func addDefaultRoute(gwIPString string, epInfo *network.EndpointInfo, result *cniTypesCurr.Result) {
|
||||
|
|
|
@ -47,6 +47,7 @@ func ConstructEndpointID(containerID string, netNsPath string, ifName string) (s
|
|||
// newEndpointImpl creates a new endpoint in the network.
|
||||
func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
|
||||
// Get Infrastructure containerID. Handle ADD calls for workload container.
|
||||
var err error
|
||||
infraEpName, _ := ConstructEndpointID(epInfo.ContainerID, epInfo.NetNsPath, epInfo.IfName)
|
||||
|
||||
hnsEndpoint := &hcsshim.HNSEndpoint{
|
||||
|
@ -79,11 +80,20 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
log.Printf("[net] HNSEndpointRequest DELETE id:%v", hnsResponse.Id)
|
||||
hnsResponse, err := hcsshim.HNSEndpointRequest("DELETE", hnsResponse.Id, "")
|
||||
log.Printf("[net] HNSEndpointRequest DELETE response:%+v err:%v.", hnsResponse, err)
|
||||
}
|
||||
}()
|
||||
|
||||
// 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.
|
||||
|
|
Загрузка…
Ссылка в новой задаче