errors: use cpuguy83/strongerrors

Signed-off-by: Paulo Pires <pjpires@gmail.com>
This commit is contained in:
Paulo Pires
2018-11-29 22:18:15 +00:00
parent 058c683c66
commit f031fc6d6b
3 changed files with 133 additions and 11 deletions

View File

@@ -20,7 +20,6 @@ import (
"sync"
"time"
pkgerrors "github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/runtime"
@@ -33,6 +32,7 @@ import (
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
vkerrors "github.com/virtual-kubelet/virtual-kubelet/errors"
"github.com/virtual-kubelet/virtual-kubelet/log"
)
@@ -112,7 +112,7 @@ func (pc *PodController) Run(ctx context.Context, threadiness int) error {
// Wait for the caches to be synced before starting workers.
if ok := cache.WaitForCacheSync(ctx.Done(), pc.podsInformer.Informer().HasSynced); !ok {
return pkgerrors.New("failed to wait for caches to sync")
return vkerrors.DeadlineWithMessage("failed to wait for caches to sync")
}
// Perform a reconciliation step that deletes any dangling pods from the provider.
@@ -162,7 +162,7 @@ func (pc *PodController) processNextWorkItem() bool {
if key, ok = obj.(string); !ok {
// As the item in the work queue is actually invalid, we call Forget here else we'd go into a loop of attempting to process a work item that is invalid.
pc.workqueue.Forget(obj)
runtime.HandleError(pkgerrors.Errorf("expected string in work queue but got %#v", obj))
runtime.HandleError(vkerrors.InvalidArgumentWithMessage("expected string in work queue but got %#v", obj))
return nil
}
// Run the syncHandler, passing it the namespace/name string of the Pod resource to be synced.
@@ -175,7 +175,7 @@ func (pc *PodController) processNextWorkItem() bool {
}
// We've exceeded the maximum retries, so we must forget the key.
pc.workqueue.Forget(key)
return pkgerrors.Wrapf(err, "forgetting %q due to maximum retries reached", key)
return vkerrors.Exhausted(err)
}
// Finally, if no error occurs we Forget this item so it does not get queued again until another change happens.
pc.workqueue.Forget(obj)
@@ -196,7 +196,7 @@ func (pc *PodController) syncHandler(key string) error {
namespace, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
// Log the error but do not requeue the key as it is invalid.
runtime.HandleError(pkgerrors.Wrapf(err, "invalid resource key: %q", key))
runtime.HandleError(vkerrors.InvalidArgument(err))
return nil
}
@@ -209,7 +209,7 @@ func (pc *PodController) syncHandler(key string) error {
if !errors.IsNotFound(err) {
// We've failed to fetch the pod from the lister, but the error is not a 404.
// Hence, we add the key back to the work queue so we can retry processing it later.
return pkgerrors.Wrapf(err, "failed to fetch pod with key %q from lister", key)
return vkerrors.Unknown(err, "failed to fetch pod with key %q from lister", key)
}
// At this point we know the Pod resource doesn't exist, which most probably means it was deleted.
// Hence, we must delete it from the provider if it still exists there.
@@ -229,7 +229,7 @@ func (pc *PodController) syncPodInProvider(ctx context.Context, pod *corev1.Pod)
if pod.DeletionTimestamp != nil {
// Delete the pod.
if err := pc.server.deletePod(ctx, pod); err != nil {
return pkgerrors.Wrapf(err, "failed to delete pod %q in the provider", key)
return vkerrors.Unknown(err, "failed to delete pod %q in the provider", key)
}
return nil
}
@@ -250,7 +250,7 @@ func (pc *PodController) syncPodInProvider(ctx context.Context, pod *corev1.Pod)
}
// Create the pod in the provider.
if err := pc.server.createPod(ctx, pod); err != nil {
return pkgerrors.Wrapf(err, "failed to create pod %q in the provider", key)
return vkerrors.Unknown(err, "failed to create pod %q in the provider", key)
}
return nil
}
@@ -273,7 +273,7 @@ func (pc *PodController) deletePodInProvider(ctx context.Context, namespace, nam
// Delete the pod.
if err := pc.server.deletePod(ctx, pod); err != nil {
return pkgerrors.Wrapf(err, "failed to delete pod %q in the provider", key)
return vkerrors.Unknown(err, "failed to delete pod %q in the provider", key)
}
return nil
}
@@ -283,7 +283,7 @@ func (pc *PodController) deleteDanglingPods(ctx context.Context) error {
// Grab the list of pods known to the provider.
pps, err := pc.server.provider.GetPods(ctx)
if err != nil {
return pkgerrors.Wrap(err, "failed to fetch the list of pods from the provider")
return vkerrors.Unknown(err, "failed to fetch the list of pods from the provider")
}
// Create a slice to hold the pods we will be deleting from the provider.
@@ -299,7 +299,7 @@ func (pc *PodController) deleteDanglingPods(ctx context.Context) error {
continue
}
// For some reason we couldn't fetch the pod from the lister, so we propagate the error.
return pkgerrors.Wrap(err, "failed to fetch pod from the lister")
return vkerrors.Unknown(err, "failed to fetch pod from the lister")
}
}