Windows: No error for no endpoint found On Del. Ipam clean-up on ADD failure.

We used to return error if no endpoint was found during delete. We now treat this as a success. If we fail during an add call, we now make a delete delegate call to the ipam to clean-up.
This commit is contained in:
Nathan Gieseker
2019-04-17 08:33:10 -07:00
parent b71e8db683
commit 688a87a055
3 changed files with 50 additions and 23 deletions

View File

@ -94,7 +94,7 @@ func GenerateHnsEndpoint(epInfo *EndpointInfo, n *NetConf) (*hcsshim.HNSEndpoint
func GenerateHcnEndpoint(epInfo *EndpointInfo, n *NetConf) (*hcn.HostComputeEndpoint, error) {
// run the IPAM plugin and get back the config to apply
hcnEndpoint, err := hcn.GetEndpointByName(epInfo.EndpointName)
if err != nil && (err != hcn.EndpointNotFoundError{EndpointName: epInfo.EndpointName}) {
if err != nil && !hcn.IsNotFoundError(err) {
return nil, errors.Annotatef(err, "Attempt to get endpoint \"%v\" failed", epInfo.EndpointName)
}
@ -172,7 +172,10 @@ func DeprovisionEndpoint(epName string, netns string, containerID string) error
}
hnsEndpoint, err := hcsshim.GetHNSEndpointByName(epName)
if err != nil {
if hcsshim.IsNotExist(err) {
return nil
} else if err != nil {
return errors.Annotatef(err, "failed to find HNSEndpoint %s", epName)
}
@ -314,7 +317,9 @@ func ConstructResult(hnsNetwork *hcsshim.HNSNetwork, hnsEndpoint *hcsshim.HNSEnd
// This version follows the v2 workflow of removing the endpoint from the namespace and deleting it
func RemoveHcnEndpoint(epName string) error {
hcnEndpoint, err := hcn.GetEndpointByName(epName)
if err != nil {
if hcn.IsNotFoundError(err) {
return nil
} else if err != nil {
_ = fmt.Errorf("[win-cni] Failed to find endpoint %v, err:%v", epName, err)
return err
}