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

@@ -9,7 +9,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/virtual-kubelet/virtual-kubelet/log"
"io"
"os"
"strconv"
@@ -17,6 +16,8 @@ import (
"time"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
"github.com/cpuguy83/strongerrors"
"github.com/virtual-kubelet/virtual-kubelet/log"
"github.com/virtual-kubelet/virtual-kubelet/manager"
"github.com/virtual-kubelet/virtual-kubelet/providers/alicloud/eci"
"k8s.io/api/core/v1"
@@ -246,13 +247,13 @@ func (p *ECIProvider) DeletePod(ctx context.Context, pod *v1.Pod) error {
}
}
if eciId == "" {
return fmt.Errorf("DeletePod cann't find Pod %s-%s", pod.Namespace, pod.Name)
return strongerrors.NotFound(fmt.Errorf("DeletePod can't find Pod %s-%s", pod.Namespace, pod.Name))
}
request := eci.CreateDeleteContainerGroupRequest()
request.ContainerGroupId = eciId
_, err := p.eciClient.DeleteContainerGroup(request)
return err
return wrapError(err)
}
// GetPod returns a pod by name that is running inside ECI
@@ -280,7 +281,7 @@ func (p *ECIProvider) GetContainerLogs(ctx context.Context, namespace, podName,
}
}
if eciId == "" {
return "", errors.New(fmt.Sprintf("GetContainerLogs cann't find Pod %s-%s", namespace, podName))
return "", errors.New(fmt.Sprintf("GetContainerLogs can't find Pod %s-%s", namespace, podName))
}
request := eci.CreateDescribeContainerLogRequest()

View File

@@ -0,0 +1,26 @@
package alicloud
import (
"net/http"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors"
"github.com/cpuguy83/strongerrors"
)
func wrapError(err error) error {
if err == nil {
return nil
}
se, ok := err.(*errors.ServerError)
if !ok {
return err
}
switch se.HttpStatus() {
case http.StatusNotFound:
return strongerrors.NotFound(err)
default:
return err
}
}