Use errdefs package
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/log"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers/alibabacloud/eci"
|
||||
@@ -254,7 +254,7 @@ func (p *ECIProvider) DeletePod(ctx context.Context, pod *v1.Pod) error {
|
||||
}
|
||||
}
|
||||
if eciId == "" {
|
||||
return strongerrors.NotFound(fmt.Errorf("DeletePod can't find Pod %s-%s", pod.Namespace, pod.Name))
|
||||
return errdefs.NotFoundf("DeletePod can't find Pod %s-%s", pod.Namespace, pod.Name)
|
||||
}
|
||||
|
||||
request := eci.CreateDeleteContainerGroupRequest()
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors"
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
)
|
||||
|
||||
func wrapError(err error) error {
|
||||
@@ -19,7 +19,7 @@ func wrapError(err error) error {
|
||||
|
||||
switch se.HttpStatus() {
|
||||
case http.StatusNotFound:
|
||||
return strongerrors.NotFound(err)
|
||||
return errdefs.AsNotFound(err)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
"github.com/aws/aws-sdk-go/service/ecs"
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/vkubelet/api"
|
||||
k8sTypes "k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
@@ -276,7 +276,7 @@ func (c *Cluster) GetPod(namespace string, name string) (*Pod, error) {
|
||||
tag := buildTaskDefinitionTag(c.name, namespace, name)
|
||||
pod, ok := c.pods[tag]
|
||||
if !ok {
|
||||
return nil, strongerrors.NotFound(fmt.Errorf("pod %s/%s is not found", namespace, name))
|
||||
return nil, errdefs.NotFoundf("pod %s/%s is not found", namespace, name)
|
||||
}
|
||||
|
||||
return pod, nil
|
||||
|
||||
@@ -19,11 +19,11 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/gorilla/websocket"
|
||||
client "github.com/virtual-kubelet/azure-aci/client"
|
||||
"github.com/virtual-kubelet/azure-aci/client/aci"
|
||||
"github.com/virtual-kubelet/azure-aci/client/network"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/log"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/trace"
|
||||
@@ -777,7 +777,7 @@ func (p *ACIProvider) GetContainerLogs(ctx context.Context, namespace, podName,
|
||||
}
|
||||
|
||||
if cg.Tags["NodeName"] != p.nodeName {
|
||||
return nil, strongerrors.NotFound(errors.New("got unexpected pod node name"))
|
||||
return nil, errdefs.NotFound("got unexpected pod node name")
|
||||
}
|
||||
|
||||
// get logs from cg
|
||||
|
||||
@@ -3,8 +3,8 @@ package azure
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/virtual-kubelet/azure-aci/client/api"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
)
|
||||
|
||||
func wrapError(err error) error {
|
||||
@@ -19,7 +19,7 @@ func wrapError(err error) error {
|
||||
|
||||
switch e.StatusCode {
|
||||
case http.StatusNotFound:
|
||||
return strongerrors.NotFound(err)
|
||||
return errdefs.AsNotFound(err)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/Azure/go-autorest/autorest"
|
||||
"github.com/Azure/go-autorest/autorest/azure"
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
)
|
||||
|
||||
func wrapError(err error) error {
|
||||
@@ -14,7 +14,7 @@ func wrapError(err error) error {
|
||||
}
|
||||
switch {
|
||||
case isStatus(err, http.StatusNotFound):
|
||||
return strongerrors.NotFound(err)
|
||||
return errdefs.AsNotFound(err)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/vkubelet/api"
|
||||
@@ -569,7 +569,7 @@ func (p *CRIProvider) DeletePod(ctx context.Context, pod *v1.Pod) error {
|
||||
|
||||
ps, ok := p.podStatus[pod.UID]
|
||||
if !ok {
|
||||
return strongerrors.NotFound(fmt.Errorf("Pod %s not found", pod.UID))
|
||||
return errdefs.NotFoundf("Pod %s not found", pod.UID)
|
||||
}
|
||||
|
||||
// TODO: Check pod status for running state
|
||||
@@ -601,7 +601,7 @@ func (p *CRIProvider) GetPod(ctx context.Context, namespace, name string) (*v1.P
|
||||
|
||||
pod := p.findPodByName(namespace, name)
|
||||
if pod == nil {
|
||||
return nil, strongerrors.NotFound(fmt.Errorf("Pod %s in namespace %s could not be found on the node", name, namespace))
|
||||
return nil, errdefs.NotFoundf("Pod %s in namespace %s could not be found on the node", name, namespace)
|
||||
}
|
||||
|
||||
return createPodSpecFromCRI(pod, p.nodeName), nil
|
||||
@@ -638,11 +638,11 @@ func (p *CRIProvider) GetContainerLogs(ctx context.Context, namespace, podName,
|
||||
|
||||
pod := p.findPodByName(namespace, podName)
|
||||
if pod == nil {
|
||||
return nil, strongerrors.NotFound(fmt.Errorf("Pod %s in namespace %s not found", podName, namespace))
|
||||
return nil, errdefs.NotFoundf("Pod %s in namespace %s not found", podName, namespace)
|
||||
}
|
||||
container := pod.containers[containerName]
|
||||
if container == nil {
|
||||
return nil, strongerrors.NotFound(fmt.Errorf("Cannot find container %s in pod %s namespace %s", containerName, podName, namespace))
|
||||
return nil, errdefs.NotFoundf("Cannot find container %s in pod %s namespace %s", containerName, podName, namespace)
|
||||
}
|
||||
|
||||
return readLogFile(container.LogPath, opts)
|
||||
@@ -686,7 +686,7 @@ func (p *CRIProvider) GetPodStatus(ctx context.Context, namespace, name string)
|
||||
|
||||
pod := p.findPodByName(namespace, name)
|
||||
if pod == nil {
|
||||
return nil, strongerrors.NotFound(fmt.Errorf("Pod %s in namespace %s could not be found on the node", name, namespace))
|
||||
return nil, errdefs.NotFoundf("Pod %s in namespace %s could not be found on the node", name, namespace)
|
||||
}
|
||||
|
||||
return createPodStatusFromCRI(pod), nil
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers/huawei/auth"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/vkubelet/api"
|
||||
@@ -257,7 +257,7 @@ func errorFromResponse(resp *http.Response) error {
|
||||
|
||||
switch resp.StatusCode {
|
||||
case http.StatusNotFound:
|
||||
return strongerrors.NotFound(err)
|
||||
return errdefs.AsNotFound(err)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/cpuguy83/strongerrors/status/ocstatus"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/log"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/trace"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/vkubelet/api"
|
||||
@@ -189,7 +189,7 @@ func (p *MockProvider) DeletePod(ctx context.Context, pod *v1.Pod) (err error) {
|
||||
}
|
||||
|
||||
if _, exists := p.pods[key]; !exists {
|
||||
return strongerrors.NotFound(fmt.Errorf("pod not found"))
|
||||
return errdefs.NotFound("pod not found")
|
||||
}
|
||||
|
||||
delete(p.pods, key)
|
||||
@@ -218,7 +218,7 @@ func (p *MockProvider) GetPod(ctx context.Context, namespace, name string) (pod
|
||||
if pod, ok := p.pods[key]; ok {
|
||||
return pod, nil
|
||||
}
|
||||
return nil, strongerrors.NotFound(fmt.Errorf("pod \"%s/%s\" is not known to the provider", namespace, name))
|
||||
return nil, errdefs.NotFoundf("pod \"%s/%s\" is not known to the provider", namespace, name)
|
||||
}
|
||||
|
||||
// GetContainerLogs retrieves the logs of a container by name from the provider.
|
||||
|
||||
@@ -3,8 +3,7 @@ package register
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||
)
|
||||
@@ -27,7 +26,7 @@ type initFunc func(InitConfig) (providers.Provider, error)
|
||||
func GetProvider(name string, cfg InitConfig) (providers.Provider, error) {
|
||||
f, ok := providerInits[name]
|
||||
if !ok {
|
||||
return nil, strongerrors.NotFound(errors.Errorf("provider not found: %s", name))
|
||||
return nil, errdefs.NotFoundf("provider not found: %s", name)
|
||||
}
|
||||
return f(cfg)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff"
|
||||
"github.com/cpuguy83/strongerrors"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/vkubelet/api"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
)
|
||||
@@ -292,7 +292,7 @@ func checkResponseStatus(r *http.Response, err error) error {
|
||||
if r.StatusCode < 200 || r.StatusCode > 299 {
|
||||
switch r.StatusCode {
|
||||
case http.StatusNotFound:
|
||||
return strongerrors.NotFound(errors.New(r.Status))
|
||||
return errdefs.NotFound(r.Status)
|
||||
default:
|
||||
return errors.New(r.Status)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user