Skip to content

Commit

Permalink
Finish the %w conversion for go1.13 in the serving part (#5749)
Browse files Browse the repository at this point in the history
* Finish the %w conversion for go1.13 in the serving part

This removes all uses of Wrap(f) in the serving.

/assign @dgerd @yanweiguo

* add missing licence
  • Loading branch information
vagababov authored and knative-prow-robot committed Oct 3, 2019
1 parent e59a7f4 commit e2791cb
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 44 deletions.
5 changes: 2 additions & 3 deletions test/conformance/api/v1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"strings"
"testing"

"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
pkgTest "knative.dev/pkg/test"
"knative.dev/pkg/test/spoof"
Expand Down Expand Up @@ -79,7 +78,7 @@ func validateDomains(
})
}
if err := g.Wait(); err != nil {
return errors.Wrap(err, "error with initial domain probing")
return fmt.Errorf("error with initial domain probing: %w", err)
}

g.Go(func() error {
Expand All @@ -98,7 +97,7 @@ func validateDomains(
})
}
if err := g.Wait(); err != nil {
return errors.Wrap(err, "error checking routing distribution")
return fmt.Errorf("error checking routing distribution: %w", err)
}
return nil
}
Expand Down
5 changes: 2 additions & 3 deletions test/conformance/api/v1alpha1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"strings"
"testing"

"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
pkgTest "knative.dev/pkg/test"
"knative.dev/pkg/test/spoof"
Expand Down Expand Up @@ -79,7 +78,7 @@ func validateDomains(
})
}
if err := g.Wait(); err != nil {
return errors.Wrap(err, "error with initial domain probing")
return fmt.Errorf("error with initial domain probing: %w", err)
}

g.Go(func() error {
Expand All @@ -98,7 +97,7 @@ func validateDomains(
})
}
if err := g.Wait(); err != nil {
return errors.Wrap(err, "error checking routing distribution")
return fmt.Errorf("error checking routing distribution: %w", err)
}
return nil
}
Expand Down
5 changes: 2 additions & 3 deletions test/conformance/api/v1beta1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"strings"
"testing"

"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
pkgTest "knative.dev/pkg/test"
"knative.dev/pkg/test/spoof"
Expand Down Expand Up @@ -79,7 +78,7 @@ func validateDomains(
})
}
if err := g.Wait(); err != nil {
return errors.Wrap(err, "error with initial domain probing")
return fmt.Errorf("error with initial domain probing: %w", err)
}

g.Go(func() error {
Expand All @@ -98,7 +97,7 @@ func validateDomains(
})
}
if err := g.Wait(); err != nil {
return errors.Wrap(err, "error checking routing distribution")
return fmt.Errorf("error checking routing distribution: %w", err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func numberOfPods(ctx *testContext) (float64, error) {
eps, err := ctx.clients.KubeClient.Kube.CoreV1().Endpoints(test.ServingNamespace).Get(
kmeta.ChildName(ctx.resources.Revision.Name, "-private"), metav1.GetOptions{})
if err != nil {
return 0, errors.Wrap(err, "Failed to get endpoints")
return 0, fmt.Errorf("Failed to get endpoints: %w", err)
}
return float64(resources.ReadyAddressCount(eps)), nil
}
Expand Down
20 changes: 18 additions & 2 deletions test/e2e/e2e.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
/*
Copyright 2019 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"fmt"
"testing"
"time"

Expand All @@ -13,7 +30,6 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

"github.com/google/go-cmp/cmp"
perrors "github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
"knative.dev/pkg/system"
pkgTest "knative.dev/pkg/test"
Expand Down Expand Up @@ -66,7 +82,7 @@ func WaitForScaleToZero(t *testing.T, deploymentName string, clients *test.Clien

cfg, err := autoscalerCM(clients)
if err != nil {
return perrors.Wrap(err, "failed to get autoscaler configmap")
return fmt.Errorf("failed to get autoscaler configmap: %w", err)
}

return pkgTest.WaitForDeploymentState(
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"testing"
"time"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
pkgTest "knative.dev/pkg/test"
Expand Down Expand Up @@ -108,7 +107,7 @@ func ScaleToWithin(t *testing.T, scale int, duration time.Duration, latencies La

if err != nil {
t.Errorf("CreateLatestService() = %v", err)
return errors.Wrap(err, "CreateLatestService() failed")
return fmt.Errorf("CreateLatestService() failed: %w", err)
}
// Record the time it took to create the service.
latencies.Add("time-to-create", start)
Expand All @@ -129,7 +128,7 @@ func ScaleToWithin(t *testing.T, scale int, duration time.Duration, latencies La
}, "ServiceUpdatedWithURL")
if err != nil {
t.Errorf("WaitForServiceState(w/ Domain) = %v", err)
return errors.Wrap(err, "WaitForServiceState(w/ Domain) failed")
return fmt.Errorf("WaitForServiceState(w/ Domain) failed: %w", err)
}
// Record the time it took to become ready.
latencies.Add("time-to-ready", start)
Expand All @@ -143,7 +142,7 @@ func ScaleToWithin(t *testing.T, scale int, duration time.Duration, latencies La
test.ServingFlags.ResolvableDomain)
if err != nil {
t.Errorf("WaitForEndpointState(expected text) = %v", err)
return errors.Wrap(err, "WaitForEndpointState(expected text) failed")
return fmt.Errorf("WaitForEndpointState(expected text) failed: %w", err)
}
// Record the time it took to get back a 200 with the expected text.
latencies.Add("time-to-200", start)
Expand Down
5 changes: 2 additions & 3 deletions test/performance/observed_concurency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"testing"
"time"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

Expand Down Expand Up @@ -95,12 +94,12 @@ func parseResponse(body string) (*event, *event, error) {

start, err := strconv.ParseInt(parts[0], 10, 64)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to parse start timestamp, body %q", body)
return nil, nil, fmt.Errorf("failed to parse start timestamp, body %q: %w", body, err)
}

end, err := strconv.ParseInt(parts[1], 10, 64)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to parse end timestamp, body %q", body)
return nil, nil, fmt.Errorf("failed to parse end timestamp, body %q: %w", body, err)
}

startEvent := &event{1, time.Unix(0, int64(start))}
Expand Down
3 changes: 1 addition & 2 deletions test/v1/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"testing"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/test/logging"
v1 "knative.dev/serving/pkg/apis/serving/v1"
Expand Down Expand Up @@ -132,7 +131,7 @@ func WaitForConfigurationState(client *test.ServingClients, name string, inState
})

if waitErr != nil {
return errors.Wrapf(waitErr, "configuration %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("configuration %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions test/v1/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"

"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"knative.dev/pkg/test/logging"
Expand Down Expand Up @@ -48,7 +47,7 @@ func WaitForRevisionState(client *test.ServingClients, name string, inState func
})

if waitErr != nil {
return errors.Wrapf(waitErr, "revision %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("revision %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions test/v1/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"knative.dev/pkg/ptr"
Expand Down Expand Up @@ -83,7 +82,7 @@ func WaitForRouteState(client *test.ServingClients, name string, inState func(r
})

if waitErr != nil {
return errors.Wrapf(waitErr, "route %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("route %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions test/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
"testing"

"github.com/mattbaird/jsonpatch"
"github.com/pkg/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"

ptest "knative.dev/pkg/test"
"knative.dev/pkg/test/logging"
v1 "knative.dev/serving/pkg/apis/serving/v1"
Expand Down Expand Up @@ -215,7 +216,7 @@ func WaitForServiceState(client *test.ServingClients, name string, inState func(
})

if waitErr != nil {
return errors.Wrapf(waitErr, "service %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("service %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions test/v1alpha1/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"testing"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -147,7 +146,7 @@ func WaitForConfigurationState(client *test.ServingAlphaClients, name string, in
})

if waitErr != nil {
return errors.Wrapf(waitErr, "configuration %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("configuration %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions test/v1alpha1/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"

"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"knative.dev/pkg/test/logging"
Expand Down Expand Up @@ -48,7 +47,7 @@ func WaitForRevisionState(client *test.ServingAlphaClients, name string, inState
})

if waitErr != nil {
return errors.Wrapf(waitErr, "revision %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("revision %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions test/v1alpha1/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"knative.dev/pkg/ptr"
Expand Down Expand Up @@ -79,7 +78,7 @@ func WaitForRouteState(client *test.ServingAlphaClients, name string, inState fu
})

if waitErr != nil {
return errors.Wrapf(waitErr, "route %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("route %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions test/v1alpha1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"testing"

"github.com/mattbaird/jsonpatch"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -307,7 +306,7 @@ func WaitForServiceState(client *test.ServingAlphaClients, name string, inState
})

if waitErr != nil {
return errors.Wrapf(waitErr, "service %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("service %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions test/v1beta1/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"testing"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/test/logging"
v1 "knative.dev/serving/pkg/apis/serving/v1"
Expand Down Expand Up @@ -133,7 +132,7 @@ func WaitForConfigurationState(client *test.ServingBetaClients, name string, inS
})

if waitErr != nil {
return errors.Wrapf(waitErr, "configuration %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("configuration %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions test/v1beta1/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"

"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"knative.dev/pkg/test/logging"
Expand Down Expand Up @@ -48,7 +47,7 @@ func WaitForRevisionState(client *test.ServingBetaClients, name string, inState
})

if waitErr != nil {
return errors.Wrapf(waitErr, "revision %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("revision %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions test/v1beta1/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"

"knative.dev/pkg/ptr"
"knative.dev/pkg/test/logging"
"knative.dev/pkg/test/spoof"
v1 "knative.dev/serving/pkg/apis/serving/v1"
"knative.dev/serving/pkg/apis/serving/v1beta1"

rtesting "knative.dev/serving/pkg/testing/v1beta1"
"knative.dev/serving/test"
)
Expand Down Expand Up @@ -84,7 +84,7 @@ func WaitForRouteState(client *test.ServingBetaClients, name string, inState fun
})

if waitErr != nil {
return errors.Wrapf(waitErr, "route %q is not in desired state, got: %+v", name, lastState)
return fmt.Errorf("route %q is not in desired state, got: %+v: %w", name, lastState, waitErr)
}
return nil
}
Expand Down
Loading

0 comments on commit e2791cb

Please sign in to comment.