Remove github.com/pkg/errors with appropriate replacements (#3172)
* errors.Wrap* removal Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * remove errors.Errorf Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * Remove remaining calls Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * Few more errors Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * Fix golint errors Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> --------- Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -20,13 +20,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-retryablehttp"
|
||||
"github.com/pkg/errors"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.uber.org/zap"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -80,18 +80,18 @@ func (c *client) GetServiceForFunction(ctx context.Context, fn *fv1.Function) (s
|
||||
|
||||
body, err := json.Marshal(fn)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could not marshal request body for getting service for function")
|
||||
return "", fmt.Errorf("could not marshal request body for getting service for function: %w", err)
|
||||
}
|
||||
|
||||
req, err := retryablehttp.NewRequestWithContext(ctx, "POST", executorURL, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could not create request for getting service for function")
|
||||
return "", fmt.Errorf("could not create request for getting service for function: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "error posting to getting service for function")
|
||||
return "", fmt.Errorf("error posting to getting service for function: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -101,7 +101,7 @@ func (c *client) GetServiceForFunction(ctx context.Context, fn *fv1.Function) (s
|
||||
|
||||
svcName, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "error reading response body from getting service for function")
|
||||
return "", fmt.Errorf("error reading response body from getting service for function: %w", err)
|
||||
}
|
||||
|
||||
return string(svcName), nil
|
||||
@@ -118,17 +118,17 @@ func (c *client) UnTapService(ctx context.Context, fnMeta metav1.ObjectMeta, exe
|
||||
|
||||
body, err := json.Marshal(tapSvc)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not marshal request body for getting service for function")
|
||||
return fmt.Errorf("could not marshal request body for getting service for function: %w", err)
|
||||
}
|
||||
req, err := retryablehttp.NewRequestWithContext(ctx, "POST", url, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not create request for untap service for function")
|
||||
return fmt.Errorf("could not create request for untap service for function: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error posting to getting service for function")
|
||||
return fmt.Errorf("error posting to getting service for function: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -194,7 +194,7 @@ func (c *client) _tapService(ctx context.Context, tapSvcReqs []TapServiceRequest
|
||||
|
||||
req, err := retryablehttp.NewRequestWithContext(ctx, "POST", executorURL, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not create request for tap service request")
|
||||
return fmt.Errorf("could not create request for tap service request: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ package cms
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
@@ -72,7 +72,7 @@ func refreshPods(ctx context.Context, logger *zap.Logger, funcs []fv1.Function,
|
||||
if exists {
|
||||
err = et.RefreshFuncPods(ctx, logger, f)
|
||||
} else {
|
||||
err = errors.Errorf("Unknown executor type '%s'", f.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType)
|
||||
err = fmt.Errorf("Unknown executor type '%s'", f.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
+11
-12
@@ -26,7 +26,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dchest/uniuri"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
k8sCache "k8s.io/client-go/tools/cache"
|
||||
|
||||
@@ -213,7 +212,7 @@ func (executor *Executor) serveCreateFuncServices(ctx context.Context) {
|
||||
// It normally happened if there are multiple requests are
|
||||
// waiting for the same function and executor failed to cre-
|
||||
// ate service for function.
|
||||
err = errors.Wrapf(err, "error getting service for function %s", fnName)
|
||||
err = fmt.Errorf("error getting service for function %s: %w", fnName, err)
|
||||
req.respChan <- &createFuncServiceResponse{
|
||||
funcSvc: fsvc,
|
||||
err: err,
|
||||
@@ -233,7 +232,7 @@ func (executor *Executor) createServiceForFunction(ctx context.Context, fn *fv1.
|
||||
t := fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType
|
||||
e, ok := executor.executorTypes[t]
|
||||
if !ok {
|
||||
return nil, errors.Errorf("Unknown executor type '%s'", t)
|
||||
return nil, fmt.Errorf("Unknown executor type '%s'", t)
|
||||
}
|
||||
|
||||
fsvc, fsvcErr := e.GetFuncSvc(ctx, fn)
|
||||
@@ -243,7 +242,7 @@ func (executor *Executor) createServiceForFunction(ctx context.Context, fn *fv1.
|
||||
zap.Error(fsvcErr),
|
||||
zap.String("function_name", fn.ObjectMeta.Name),
|
||||
zap.String("function_namespace", fn.ObjectMeta.Namespace))
|
||||
fsvcErr = errors.Wrap(fsvcErr, fmt.Sprintf("[%s] %s", fn.ObjectMeta.Name, e))
|
||||
fsvcErr = fmt.Errorf("[%s] %s: %w", fn.ObjectMeta.Name, e, fsvcErr)
|
||||
}
|
||||
|
||||
return fsvc, fsvcErr
|
||||
@@ -254,7 +253,7 @@ func (executor *Executor) getFunctionServiceFromCache(ctx context.Context, fn *f
|
||||
t := fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType
|
||||
e, ok := executor.executorTypes[t]
|
||||
if !ok {
|
||||
return nil, errors.Errorf("Unknown executor type '%s'", t)
|
||||
return nil, fmt.Errorf("Unknown executor type '%s'", t)
|
||||
}
|
||||
return e.GetFuncSvcFromCache(ctx, fn)
|
||||
}
|
||||
@@ -265,11 +264,11 @@ func StartExecutor(ctx context.Context, clientGen crd.ClientGeneratorInterface,
|
||||
|
||||
fissionClient, err := clientGen.GetFissionClient()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error making the fission client")
|
||||
return fmt.Errorf("error making the fission client: %w", err)
|
||||
}
|
||||
kubernetesClient, err := clientGen.GetKubernetesClient()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error making the kube client")
|
||||
return fmt.Errorf("error making the kube client: %w", err)
|
||||
}
|
||||
metricsClient, err := clientGen.GetMetricsClient()
|
||||
if err != nil {
|
||||
@@ -278,12 +277,12 @@ func StartExecutor(ctx context.Context, clientGen crd.ClientGeneratorInterface,
|
||||
|
||||
err = crd.WaitForFunctionCRDs(ctx, logger, fissionClient)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error waiting for CRDs")
|
||||
return fmt.Errorf("error waiting for CRDs: %w", err)
|
||||
}
|
||||
|
||||
fetcherConfig, err := fetcherConfig.MakeFetcherConfig("/userfunc")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error making fetcher config")
|
||||
return fmt.Errorf("Error making fetcher config: %w", err)
|
||||
}
|
||||
|
||||
executorInstanceID := strings.ToLower(uniuri.NewLen(8))
|
||||
@@ -312,7 +311,7 @@ func StartExecutor(ctx context.Context, clientGen crd.ClientGeneratorInterface,
|
||||
finformerFactory,
|
||||
gpmInformerFactory, podSpecPatch)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "pool manager creation failed")
|
||||
return fmt.Errorf("pool manager creation failed: %w", err)
|
||||
}
|
||||
|
||||
executorLabel, err = utils.GetInformerLabelByExecutor(fv1.ExecutorTypeNewdeploy)
|
||||
@@ -327,7 +326,7 @@ func StartExecutor(ctx context.Context, clientGen crd.ClientGeneratorInterface,
|
||||
finformerFactory,
|
||||
ndmInformerFactory, podSpecPatch)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "new deploy manager creation failed")
|
||||
return fmt.Errorf("new deploy manager creation failed: %w", err)
|
||||
}
|
||||
|
||||
executorLabel, err = utils.GetInformerLabelByExecutor(fv1.ExecutorTypeContainer)
|
||||
@@ -341,7 +340,7 @@ func StartExecutor(ctx context.Context, clientGen crd.ClientGeneratorInterface,
|
||||
executorInstanceID, finformerFactory,
|
||||
cnmInformerFactory)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "container manager creation failed")
|
||||
return fmt.Errorf("container manager creation failed: %w", err)
|
||||
}
|
||||
|
||||
executorTypes := make(map[fv1.ExecutorType]executortype.ExecutorType)
|
||||
|
||||
@@ -19,6 +19,7 @@ package poolmgr
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
@@ -28,7 +29,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dchest/uniuri"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
@@ -320,7 +320,7 @@ func (gp *GenericPool) choosePod(ctx context.Context, newLabels map[string]strin
|
||||
// ending retry loop when the request canceled
|
||||
gp.readyPodQueue.Done(key)
|
||||
gp.readyPodQueue.AddAfter(key, expoDelay)
|
||||
return "", nil, errors.Errorf("failed to relabel pod: %s", err)
|
||||
return "", nil, fmt.Errorf("failed to relabel pod: %s", err)
|
||||
} else if err != nil {
|
||||
logger.Error("failed to relabel pod", zap.Error(err), zap.String("pod", chosenPod.Name), zap.Duration("delay", expoDelay))
|
||||
gp.readyPodQueue.Done(key)
|
||||
@@ -335,13 +335,13 @@ func (gp *GenericPool) choosePod(ctx context.Context, newLabels map[string]strin
|
||||
// So we have to check both of them to ensure the patch success.
|
||||
for k, v := range newLabels {
|
||||
if newPod.Labels[k] != v {
|
||||
return "", nil, errors.Errorf("value of necessary labels '%s' mismatch: want '%s', get '%v'",
|
||||
return "", nil, fmt.Errorf("value of necessary labels '%s' mismatch: want '%s', get '%v'",
|
||||
k, v, newPod.Labels[k])
|
||||
}
|
||||
}
|
||||
for k, v := range annotations {
|
||||
if newPod.Annotations[k] != v {
|
||||
return "", nil, errors.Errorf("value of necessary annotations '%s' mismatch: want '%s', get '%v'",
|
||||
return "", nil, fmt.Errorf("value of necessary annotations '%s' mismatch: want '%s', get '%v'",
|
||||
k, v, newPod.Annotations[k])
|
||||
}
|
||||
}
|
||||
@@ -415,7 +415,7 @@ func (gp *GenericPool) specializePod(ctx context.Context, pod *apiv1.Pod, fn *fv
|
||||
// for fetcher we don't need to create a service, just talk to the pod directly
|
||||
podIP := pod.Status.PodIP
|
||||
if len(podIP) == 0 {
|
||||
return errors.Errorf("Pod %s in namespace %s has no IP", pod.ObjectMeta.Name, pod.ObjectMeta.Namespace)
|
||||
return fmt.Errorf("Pod %s in namespace %s has no IP", pod.ObjectMeta.Name, pod.ObjectMeta.Namespace)
|
||||
}
|
||||
for _, cm := range fn.Spec.ConfigMaps {
|
||||
_, err := gp.kubernetesClient.CoreV1().ConfigMaps(gp.fnNamespace).Get(ctx, cm.Name, metav1.GetOptions{})
|
||||
@@ -571,7 +571,7 @@ func (gp *GenericPool) getFuncSvc(ctx context.Context, fn *fv1.Function) (*fscac
|
||||
}
|
||||
if svc.ObjectMeta.Name != svcName {
|
||||
go gp.scheduleDeletePod(context.Background(), pod.ObjectMeta.Name)
|
||||
return nil, errors.Errorf("sanity check failed for svc %s", svc.ObjectMeta.Name)
|
||||
return nil, fmt.Errorf("sanity check failed for svc %s", svc.ObjectMeta.Name)
|
||||
}
|
||||
|
||||
// the fission router isn't in the same namespace, so return a
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fission/fission/pkg/executor/metrics"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.uber.org/zap"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
@@ -47,6 +46,7 @@ import (
|
||||
"github.com/fission/fission/pkg/crd"
|
||||
"github.com/fission/fission/pkg/executor/executortype"
|
||||
"github.com/fission/fission/pkg/executor/fscache"
|
||||
"github.com/fission/fission/pkg/executor/metrics"
|
||||
"github.com/fission/fission/pkg/executor/reaper"
|
||||
executorUtils "github.com/fission/fission/pkg/executor/util"
|
||||
fetcherConfig "github.com/fission/fission/pkg/fetcher/config"
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.uber.org/zap"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
@@ -292,7 +291,7 @@ func (fsc *FunctionServiceCache) Add(fsvc FuncSvc) (*FuncSvc, error) {
|
||||
if IsNameExistError(err) {
|
||||
err = nil
|
||||
} else {
|
||||
err = errors.Wrap(err, "error caching fsvc")
|
||||
err = fmt.Errorf("error caching fsvc: %w", err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -304,7 +303,7 @@ func (fsc *FunctionServiceCache) Add(fsvc FuncSvc) (*FuncSvc, error) {
|
||||
if IsNameExistError(err) {
|
||||
err = nil
|
||||
} else {
|
||||
err = errors.Wrap(err, "error caching fsvc by function uid")
|
||||
err = fmt.Errorf("error caching fsvc by function uid: %w", err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -383,10 +382,6 @@ func (fsc *FunctionServiceCache) DeleteFunctionSvc(ctx context.Context, fsvc *Fu
|
||||
}
|
||||
}
|
||||
|
||||
func (fsc *FunctionServiceCache) SetCPUUtilization(key crd.CacheKeyURG, svcHost string, cpuUsage resource.Quantity) {
|
||||
fsc.connFunctionCache.SetCPUUtilization(key, svcHost, cpuUsage)
|
||||
}
|
||||
|
||||
// DeleteOld deletes aged function service entries from cache.
|
||||
func (fsc *FunctionServiceCache) DeleteOld(fsvc *FuncSvc, minAge time.Duration) (bool, error) {
|
||||
if time.Since(fsvc.Atime) < minAge {
|
||||
|
||||
@@ -17,8 +17,9 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/fission/fission/pkg/utils/metrics"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/fission/fission/pkg/utils/metrics"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -23,10 +23,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
func TestGetSpecFromConfigMap(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user