in network/manager.go [142:186]
func (nm *networkManager) DeleteEndpoint(endpointID string) error {
nm.Lock()
defer nm.Unlock()
hcnEndpoint, err := hcn.GetEndpointByID(endpointID)
if err != nil {
return err
}
// Remove this endpoint from the namespace
epNamespace, err := hcn.GetNamespaceByID(hcnEndpoint.HostComputeNamespace)
// If namespace was not found, that's ok, we'll just delete the endpoint and clear the error.
if hcn.IsNotFoundError(err) || hcnEndpoint.HostComputeNamespace == "" {
logrus.Debugf("[cni-net] Namespace [%v] was not found error or non-existent, err:%v", hcnEndpoint.HostComputeNamespace, err)
} else if err != nil {
return fmt.Errorf("error while attempting to get namespace, err:%v", err)
}
// In this case the namespace was found, so we want to properly remove it before deleting the endpoint.
if epNamespace != nil {
err = hcn.RemoveNamespaceEndpoint(hcnEndpoint.HostComputeNamespace, hcnEndpoint.Id)
if err != nil {
if hcn.IsNotFoundError(err) {
logrus.Debugf("[cni-net] Endpoint or Namespace was not found, err: %v", err)
} else {
return fmt.Errorf("error removing endpoint from namespace %v : endpoint %v", err, hcnEndpoint)
}
}
}
err = hcnEndpoint.Delete()
if err != nil {
// We retry this if the delete fails incase the endpoint was deleted between now
// and when the endpoint was originally queried
hcnEndpoint, nestedErr := hcn.GetEndpointByName(hcnEndpoint.Name)
if nestedErr != nil {
return nestedErr
} else {
logrus.Debugf("[cni-net] error deleting endpoint %v : endpoint %v", err, hcnEndpoint)
return err
}
}
return nil
}