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:
@@ -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
|
||||
|
||||
@@ -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
26
providers/azure/errors.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user