Merge branch 'master' into make-mock-provider-async2

This commit is contained in:
Brian Goff
2019-06-05 14:42:11 -07:00
committed by GitHub
60 changed files with 1144 additions and 1427 deletions

View File

@@ -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()

View File

@@ -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
}

View File

@@ -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

View File

@@ -12,12 +12,17 @@ var (
// FargateRegions are AWS regions where Fargate is available.
FargateRegions = Regions{
"ap-northeast-1", // Asia Pacific (Tokyo)
"ap-northeast-2", // Asia Pacific (Seoul)
"ap-southeast-1", // Asia Pacific (Singapore)
"ap-southeast-2", // Asia Pacific (Sydney)
"ap-south-1", // Asia Pacific (Mumbai)
"ca-central-1", // Canada (Central)
"eu-central-1", // EU (Frankfurt)
"eu-west-1", // EU (Ireland)
"eu-west-2", // EU (London)
"us-east-1", // US East (N. Virginia)
"us-east-2", // US East (Ohio)
"us-west-1", // US West (N. California)
"us-west-2", // US West (Oregon)
}
)

View File

@@ -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

View File

@@ -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
}

View File

@@ -5,7 +5,6 @@ import (
"strings"
"time"
"github.com/cpuguy83/strongerrors/status/ocstatus"
"github.com/pkg/errors"
"github.com/virtual-kubelet/azure-aci/client/aci"
"github.com/virtual-kubelet/virtual-kubelet/log"
@@ -97,7 +96,7 @@ func (p *ACIProvider) GetStatsSummary(ctx context.Context) (summary *stats.Summa
Types: []aci.MetricType{aci.MetricTypeCPUUsage, aci.MetricTypeMemoryUsage},
})
if err != nil {
span.SetStatus(ocstatus.FromError(err))
span.SetStatus(err)
return errors.Wrapf(err, "error fetching cpu/mem stats for container group %s", cgName)
}
logger.Debug("Got system stats")
@@ -109,7 +108,7 @@ func (p *ACIProvider) GetStatsSummary(ctx context.Context) (summary *stats.Summa
Types: []aci.MetricType{aci.MetricTyperNetworkBytesRecievedPerSecond, aci.MetricTyperNetworkBytesTransmittedPerSecond},
})
if err != nil {
span.SetStatus(ocstatus.FromError(err))
span.SetStatus(err)
return errors.Wrapf(err, "error fetching network stats for container group %s", cgName)
}
logger.Debug("Got network stats")
@@ -120,7 +119,7 @@ func (p *ACIProvider) GetStatsSummary(ctx context.Context) (summary *stats.Summa
}
if err := errGroup.Wait(); err != nil {
span.SetStatus(ocstatus.FromError(err))
span.SetStatus(err)
return nil, errors.Wrap(err, "error in request to fetch container group metrics")
}
close(chResult)

View File

@@ -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
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -7,7 +7,7 @@ import (
"net/http/httptest"
"github.com/gorilla/mux"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
)
// CCIMock implements a CCI service mock server.

View File

@@ -10,8 +10,7 @@ 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"
@@ -252,7 +251,7 @@ func (p *MockLegacyProvider) DeletePod(ctx context.Context, pod *v1.Pod) (err er
}
if _, exists := p.pods[key]; !exists {
return strongerrors.NotFound(fmt.Errorf("pod not found"))
return errdefs.NotFound("pod not found")
}
now := metav1.Now()
@@ -281,7 +280,7 @@ func (p *MockLegacyProvider) DeletePod(ctx context.Context, pod *v1.Pod) (err er
func (p *MockLegacyProvider) GetPod(ctx context.Context, namespace, name string) (pod *v1.Pod, err error) {
ctx, span := trace.StartSpan(ctx, "GetPod")
defer func() {
span.SetStatus(ocstatus.FromError(err))
span.SetStatus(err)
span.End()
}()
@@ -298,7 +297,7 @@ func (p *MockLegacyProvider) GetPod(ctx context.Context, namespace, name string)
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.

View File

@@ -11,6 +11,10 @@ import (
)
// Provider contains the methods required to implement a virtual-kubelet provider.
//
// Errors produced by these methods should implement an interface from
// github.com/virtual-kubelet/virtual-kubelet/errdefs package in order for the
// core logic to be able to understand the type of failure.
type Provider interface {
vkubelet.PodLifecycleHandler

View File

@@ -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)
}

View File

@@ -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)
}