Use strongerrors in provider implementations. (#403)

This ensures that we can catch certain types of errors from providers
and handle accordingly in the core. There is still more to do here to
improve that but this resolves an immediate need to know why a Delete
failed.

vic provider was not updated since I could not figure out where to get
this information.
This commit is contained in:
Brian Goff
2018-11-07 16:02:48 -08:00
committed by Robbie Zhang
parent 1d76b1341e
commit cd42fdd7b8
15 changed files with 210 additions and 20 deletions

View File

@@ -342,8 +342,8 @@ func (p *ACIProvider) setupNetworkProfile(auth *client.Authentication) error {
return fmt.Errorf("unable to delegate subnet '%s' to Azure Container Instance since it references the network security group '%s'.", p.subnetName, *subnet.SubnetPropertiesFormat.NetworkSecurityGroup.ID)
}
if subnet.SubnetPropertiesFormat.RouteTable != nil {
return fmt.Errorf("unable to delegate subnet '%s' to Azure Container Instance since it references the route table '%s'.", p.subnetName, *subnet.SubnetPropertiesFormat.RouteTable.ID)
}
return fmt.Errorf("unable to delegate subnet '%s' to Azure Container Instance since it references the route table '%s'.", p.subnetName, *subnet.SubnetPropertiesFormat.RouteTable.ID)
}
if subnet.SubnetPropertiesFormat.ServiceAssociationLinks != nil {
for _, l := range *subnet.SubnetPropertiesFormat.ServiceAssociationLinks {
if l.ServiceAssociationLinkPropertiesFormat != nil && *l.ServiceAssociationLinkPropertiesFormat.LinkedResourceType == subnetDelegationService {
@@ -427,7 +427,7 @@ func getKubeProxyExtension(secretPath, masterURI, clusterCIDR string) (*aci.Exte
clientcmdv1.NamedCluster{
Name: name,
Cluster: clientcmdv1.Cluster{
Server: masterURI,
Server: masterURI,
CertificateAuthorityData: ca,
},
},
@@ -691,7 +691,8 @@ func (p *ACIProvider) DeletePod(ctx context.Context, pod *v1.Pod) error {
defer span.End()
addAzureAttributes(span, p)
return p.aciClient.DeleteContainerGroup(ctx, p.resourceGroup, fmt.Sprintf("%s-%s", pod.Namespace, pod.Name))
err := p.aciClient.DeleteContainerGroup(ctx, p.resourceGroup, fmt.Sprintf("%s-%s", pod.Namespace, pod.Name))
return wrapError(err)
}
// GetPod returns a pod by name that is running inside ACI

View File

@@ -46,6 +46,7 @@ func CheckResponse(res *http.Response) error {
if res.StatusCode >= 200 && res.StatusCode <= 299 {
return nil
}
slurp, err := ioutil.ReadAll(res.Body)
if err == nil {
jerr := new(errorReply)
@@ -59,9 +60,10 @@ func CheckResponse(res *http.Response) error {
return jerr.Error
}
}
return &Error{
StatusCode: res.StatusCode,
Body: string(slurp),
Body: res.Status,
Header: res.Header,
}
}

26
providers/azure/errors.go Normal file
View File

@@ -0,0 +1,26 @@
package azure
import (
"net/http"
"github.com/cpuguy83/strongerrors"
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/api"
)
func wrapError(err error) error {
if err == nil {
return nil
}
e, ok := err.(*api.Error)
if !ok {
return err
}
switch e.StatusCode {
case http.StatusNotFound:
return strongerrors.NotFound(err)
default:
return err
}
}