Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove imports of golang.org/x/xerrors #1711

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/entrypoint/waiter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"fmt"
"os"
"time"

"github.com/tektoncd/pipeline/pkg/entrypoint"
"golang.org/x/xerrors"
)

// realWaiter actually waits for files, by polling.
Expand All @@ -32,7 +32,7 @@ func (*realWaiter) Wait(file string, expectContent bool) error {
return nil
}
} else if !os.IsNotExist(err) {
return xerrors.Errorf("Waiting for %q: %w", file, err)
return fmt.Errorf("Waiting for %q: %w", file, err)
}
if _, err := os.Stat(file + ".err"); err == nil {
return skipError("error file present, bail and skip the step")
Expand Down
13 changes: 6 additions & 7 deletions pkg/apis/pipeline/v1alpha1/build_gcs_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/names"
"golang.org/x/xerrors"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -72,10 +71,10 @@ type BuildGCSResource struct {
// NewBuildGCSResource creates a new BuildGCS resource to pass to a Task.
func NewBuildGCSResource(images pipeline.Images, r *PipelineResource) (*BuildGCSResource, error) {
if r.Spec.Type != PipelineResourceTypeStorage {
return nil, xerrors.Errorf("BuildGCSResource: Cannot create a BuildGCS resource from a %s Pipeline Resource", r.Spec.Type)
return nil, fmt.Errorf("BuildGCSResource: Cannot create a BuildGCS resource from a %s Pipeline Resource", r.Spec.Type)
}
if r.Spec.SecretParams != nil {
return nil, xerrors.Errorf("BuildGCSResource: %s cannot support artifacts on private bucket", r.Name)
return nil, fmt.Errorf("BuildGCSResource: %s cannot support artifacts on private bucket", r.Name)
}
var location string
var aType GCSArtifactType
Expand All @@ -87,15 +86,15 @@ func NewBuildGCSResource(images pipeline.Images, r *PipelineResource) (*BuildGCS
var err error
aType, err = getArtifactType(param.Value)
if err != nil {
return nil, xerrors.Errorf("BuildGCSResource %s : %w", r.Name, err)
return nil, fmt.Errorf("BuildGCSResource %s : %w", r.Name, err)
}
}
}
if location == "" {
return nil, xerrors.Errorf("BuildGCSResource: Need Location to be specified in order to create BuildGCS resource %s", r.Name)
return nil, fmt.Errorf("BuildGCSResource: Need Location to be specified in order to create BuildGCS resource %s", r.Name)
}
if aType == GCSArtifactType("") {
return nil, xerrors.Errorf("BuildGCSResource: Need ArtifactType to be specified to create BuildGCS resource %s", r.Name)
return nil, fmt.Errorf("BuildGCSResource: Need ArtifactType to be specified to create BuildGCS resource %s", r.Name)
}
return &BuildGCSResource{
Name: r.Name,
Expand Down Expand Up @@ -162,5 +161,5 @@ func getArtifactType(val string) (GCSArtifactType, error) {
return a, nil
}
}
return "", xerrors.Errorf("Invalid ArtifactType %s. Should be one of %s", val, validArtifactTypes)
return "", fmt.Errorf("Invalid ArtifactType %s. Should be one of %s", val, validArtifactTypes)
}
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package v1alpha1
import (
b64 "encoding/base64"
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/tektoncd/pipeline/pkg/names"
"golang.org/x/xerrors"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ type ClusterResource struct {
// NewClusterResource create a new k8s cluster resource to pass to a pipeline task
func NewClusterResource(kubeconfigWriterImage string, r *PipelineResource) (*ClusterResource, error) {
if r.Spec.Type != PipelineResourceTypeCluster {
return nil, xerrors.Errorf("ClusterResource: Cannot create a Cluster resource from a %s Pipeline Resource", r.Spec.Type)
return nil, fmt.Errorf("ClusterResource: Cannot create a Cluster resource from a %s Pipeline Resource", r.Spec.Type)
}
clusterResource := ClusterResource{
Type: r.Spec.Type,
Expand Down
7 changes: 3 additions & 4 deletions pkg/apis/pipeline/v1alpha1/gcs_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/names"
"golang.org/x/xerrors"
corev1 "k8s.io/api/core/v1"
)

Expand All @@ -48,7 +47,7 @@ type GCSResource struct {
// NewGCSResource creates a new GCS resource to pass to a Task
func NewGCSResource(images pipeline.Images, r *PipelineResource) (*GCSResource, error) {
if r.Spec.Type != PipelineResourceTypeStorage {
return nil, xerrors.Errorf("GCSResource: Cannot create a GCS resource from a %s Pipeline Resource", r.Spec.Type)
return nil, fmt.Errorf("GCSResource: Cannot create a GCS resource from a %s Pipeline Resource", r.Spec.Type)
}
var location string
var locationSpecified, dir bool
Expand All @@ -66,7 +65,7 @@ func NewGCSResource(images pipeline.Images, r *PipelineResource) (*GCSResource,
}

if !locationSpecified {
return nil, xerrors.Errorf("GCSResource: Need Location to be specified in order to create GCS resource %s", r.Name)
return nil, fmt.Errorf("GCSResource: Need Location to be specified in order to create GCS resource %s", r.Name)
}
return &GCSResource{
Name: r.Name,
Expand Down Expand Up @@ -132,7 +131,7 @@ func (s *GCSResource) GetOutputTaskModifier(ts *TaskSpec, path string) (TaskModi
// GetInputTaskModifier returns the TaskModifier to be used when this resource is an input.
func (s *GCSResource) GetInputTaskModifier(ts *TaskSpec, path string) (TaskModifier, error) {
if path == "" {
return nil, xerrors.Errorf("GCSResource: Expect Destination Directory param to be set %s", s.Name)
return nil, fmt.Errorf("GCSResource: Expect Destination Directory param to be set %s", s.Name)
}
var args []string
if s.TypeDir {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/git_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License.
package v1alpha1

import (
"fmt"
"strings"

"github.com/tektoncd/pipeline/pkg/names"
"golang.org/x/xerrors"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -48,7 +48,7 @@ type GitResource struct {
// NewGitResource creates a new git resource to pass to a Task
func NewGitResource(gitImage string, r *PipelineResource) (*GitResource, error) {
if r.Spec.Type != PipelineResourceTypeGit {
return nil, xerrors.Errorf("GitResource: Cannot create a Git resource from a %s Pipeline Resource", r.Spec.Type)
return nil, fmt.Errorf("GitResource: Cannot create a Git resource from a %s Pipeline Resource", r.Spec.Type)
}
gitResource := GitResource{
Name: r.Name,
Expand Down
5 changes: 2 additions & 3 deletions pkg/apis/pipeline/v1alpha1/image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ package v1alpha1

import (
"encoding/json"
"fmt"
"strings"

"golang.org/x/xerrors"
)

// NewImageResource creates a new ImageResource from a PipelineResource.
func NewImageResource(r *PipelineResource) (*ImageResource, error) {
if r.Spec.Type != PipelineResourceTypeImage {
return nil, xerrors.Errorf("ImageResource: Cannot create an Image resource from a %s Pipeline Resource", r.Spec.Type)
return nil, fmt.Errorf("ImageResource: Cannot create an Image resource from a %s Pipeline Resource", r.Spec.Type)
}
ir := &ImageResource{
Name: r.Name,
Expand Down
7 changes: 3 additions & 4 deletions pkg/apis/pipeline/v1alpha1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/tektoncd/pipeline/pkg/list"
"github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag"
"github.com/tektoncd/pipeline/pkg/substitution"
"golang.org/x/xerrors"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/validation"
"knative.dev/pkg/apis"
Expand Down Expand Up @@ -67,7 +66,7 @@ func validateDeclaredResources(ps *PipelineSpec) error {
}
missing := list.DiffLeft(required, provided)
if len(missing) > 0 {
return xerrors.Errorf("Pipeline declared resources didn't match usage in Tasks: Didn't provide required values: %s", missing)
return fmt.Errorf("Pipeline declared resources didn't match usage in Tasks: Didn't provide required values: %s", missing)
}
return nil
}
Expand Down Expand Up @@ -99,10 +98,10 @@ func validateFrom(tasks []PipelineTask) error {
for _, pb := range rd.From {
outputs, found := taskOutputs[pb]
if !found {
return xerrors.Errorf("expected resource %s to be from task %s, but task %s doesn't exist", rd.Resource, pb, pb)
return fmt.Errorf("expected resource %s to be from task %s, but task %s doesn't exist", rd.Resource, pb, pb)
}
if !isOutput(outputs, rd.Resource) {
return xerrors.Errorf("the resource %s from %s must be an output but is an input", rd.Resource, pb)
return fmt.Errorf("the resource %s from %s must be an output but is an input", rd.Resource, pb)
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/apis/pipeline/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ limitations under the License.
package v1alpha1

import (
"fmt"

"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha2"
"golang.org/x/xerrors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -82,7 +83,7 @@ type InternalTaskModifier = v1alpha2.InternalTaskModifier
func checkStepNotAlreadyAdded(s Step, steps []Step) error {
for _, step := range steps {
if s.Name == step.Name {
return xerrors.Errorf("Step %s cannot be added again", step.Name)
return fmt.Errorf("Step %s cannot be added again", step.Name)
}
}
return nil
Expand Down Expand Up @@ -117,7 +118,7 @@ func ApplyTaskModifier(ts *TaskSpec, tm TaskModifier) error {
if volume.Name == v.Name {
// If a Volume with the same name but different contents has already been added, we can't add both
if d := cmp.Diff(volume, v); d != "" {
return xerrors.Errorf("Tried to add volume %s already added but with different contents", volume.Name)
return fmt.Errorf("Tried to add volume %s already added but with different contents", volume.Name)
}
// If an identical Volume has already been added, don't add it again
alreadyAdded = true
Expand Down Expand Up @@ -225,5 +226,5 @@ func ResourceFromType(r *PipelineResource, images pipeline.Images) (PipelineReso
case PipelineResourceTypeCloudEvent:
return NewCloudEventResource(r)
}
return nil, xerrors.Errorf("%s is an invalid or unimplemented PipelineResource", r.Spec.Type)
return nil, fmt.Errorf("%s is an invalid or unimplemented PipelineResource", r.Spec.Type)
}
7 changes: 3 additions & 4 deletions pkg/apis/pipeline/v1alpha1/storage_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strings"

"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"golang.org/x/xerrors"
corev1 "k8s.io/api/core/v1"
)

Expand All @@ -48,7 +47,7 @@ type PipelineStorageResourceInterface interface {
// to add input and output steps and volumes to an executing pod.
func NewStorageResource(images pipeline.Images, r *PipelineResource) (PipelineStorageResourceInterface, error) {
if r.Spec.Type != PipelineResourceTypeStorage {
return nil, xerrors.Errorf("StoreResource: Cannot create a storage resource from a %s Pipeline Resource", r.Spec.Type)
return nil, fmt.Errorf("StoreResource: Cannot create a storage resource from a %s Pipeline Resource", r.Spec.Type)
}

for _, param := range r.Spec.Params {
Expand All @@ -59,11 +58,11 @@ func NewStorageResource(images pipeline.Images, r *PipelineResource) (PipelineSt
case strings.EqualFold(param.Value, string(PipelineResourceTypeBuildGCS)):
return NewBuildGCSResource(images, r)
default:
return nil, xerrors.Errorf("%s is an invalid or unimplemented PipelineStorageResource", param.Value)
return nil, fmt.Errorf("%s is an invalid or unimplemented PipelineStorageResource", param.Value)
}
}
}
return nil, xerrors.Errorf("StoreResource: Cannot create a storage resource without type %s in spec", r.Name)
return nil, fmt.Errorf("StoreResource: Cannot create a storage resource without type %s in spec", r.Name)
}

func getStorageVolumeSpec(s PipelineStorageResourceInterface, spec TaskSpec) []corev1.Volume {
Expand Down
7 changes: 4 additions & 3 deletions pkg/apis/pipeline/v1alpha2/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
package v1alpha2

import (
"fmt"

"github.com/google/go-cmp/cmp"
"golang.org/x/xerrors"
v1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -152,7 +153,7 @@ func ApplyTaskModifier(ts *TaskSpec, tm TaskModifier) error {
if volume.Name == v.Name {
// If a Volume with the same name but different contents has already been added, we can't add both
if d := cmp.Diff(volume, v); d != "" {
return xerrors.Errorf("Tried to add volume %s already added but with different contents", volume.Name)
return fmt.Errorf("Tried to add volume %s already added but with different contents", volume.Name)
}
// If an identical Volume has already been added, don't add it again
alreadyAdded = true
Expand All @@ -169,7 +170,7 @@ func ApplyTaskModifier(ts *TaskSpec, tm TaskModifier) error {
func checkStepNotAlreadyAdded(s Step, steps []Step) error {
for _, step := range steps {
if s.Name == step.Name {
return xerrors.Errorf("Step %s cannot be added again", step.Name)
return fmt.Errorf("Step %s cannot be added again", step.Name)
}
}
return nil
Expand Down
17 changes: 8 additions & 9 deletions pkg/artifacts/artifacts_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/system"
"go.uber.org/zap"
"golang.org/x/xerrors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -180,7 +179,7 @@ func ConfigMapNeedsPVC(configMap *corev1.ConfigMap, err error, logger *zap.Sugar
if errors.IsNotFound(err) {
return true, nil
}
return false, xerrors.Errorf("couldn't determine if PVC was needed from config map: %w", err)
return false, fmt.Errorf("couldn't determine if PVC was needed from config map: %w", err)
}
if configMap == nil {
return true, nil
Expand All @@ -206,7 +205,7 @@ func GetArtifactStorage(images pipeline.Images, prName string, c kubernetes.Inte
configMap, err := c.CoreV1().ConfigMaps(system.GetNamespace()).Get(BucketConfigName, metav1.GetOptions{})
pvc, err := ConfigMapNeedsPVC(configMap, err, logger)
if err != nil {
return nil, xerrors.Errorf("couldn't determine if PVC was needed from config map: %w", err)
return nil, fmt.Errorf("couldn't determine if PVC was needed from config map: %w", err)
}
if pvc {
return &v1alpha1.ArtifactPVC{Name: prName, ShellImage: images.ShellImage}, nil
Expand Down Expand Up @@ -252,7 +251,7 @@ func createPVC(pr *v1alpha1.PipelineRun, c kubernetes.Interface) (*corev1.Persis

configMap, err := c.CoreV1().ConfigMaps(system.GetNamespace()).Get(PvcConfigName, metav1.GetOptions{})
if err != nil && !errors.IsNotFound(err) {
return nil, xerrors.Errorf("failed to get PVC ConfigMap %s for %q due to error: %w", PvcConfigName, pr.Name, err)
return nil, fmt.Errorf("failed to get PVC ConfigMap %s for %q due to error: %w", PvcConfigName, pr.Name, err)
}
var pvcSizeStr string
var pvcStorageClassNameStr string
Expand All @@ -265,7 +264,7 @@ func createPVC(pr *v1alpha1.PipelineRun, c kubernetes.Interface) (*corev1.Persis
}
pvcSize, err := resource.ParseQuantity(pvcSizeStr)
if err != nil {
return nil, xerrors.Errorf("failed to create Persistent Volume spec for %q due to error: %w", pr.Name, err)
return nil, fmt.Errorf("failed to create Persistent Volume spec for %q due to error: %w", pr.Name, err)
}
var pvcStorageClassName *string
if pvcStorageClassNameStr == "" {
Expand All @@ -277,22 +276,22 @@ func createPVC(pr *v1alpha1.PipelineRun, c kubernetes.Interface) (*corev1.Persis
pvcSpec := GetPVCSpec(pr, pvcSize, pvcStorageClassName)
pvc, err := c.CoreV1().PersistentVolumeClaims(pr.Namespace).Create(pvcSpec)
if err != nil {
return nil, xerrors.Errorf("failed to claim Persistent Volume %q due to error: %w", pr.Name, err)
return nil, fmt.Errorf("failed to claim Persistent Volume %q due to error: %w", pr.Name, err)
}
return pvc, nil
}
return nil, xerrors.Errorf("failed to get claim Persistent Volume %q due to error: %w", pr.Name, err)
return nil, fmt.Errorf("failed to get claim Persistent Volume %q due to error: %w", pr.Name, err)
}
return nil, nil
}

func deletePVC(pr *v1alpha1.PipelineRun, c kubernetes.Interface) error {
if _, err := c.CoreV1().PersistentVolumeClaims(pr.Namespace).Get(GetPVCName(pr), metav1.GetOptions{}); err != nil {
if !errors.IsNotFound(err) {
return xerrors.Errorf("failed to get Persistent Volume %q due to error: %w", GetPVCName(pr), err)
return fmt.Errorf("failed to get Persistent Volume %q due to error: %w", GetPVCName(pr), err)
}
} else if err := c.CoreV1().PersistentVolumeClaims(pr.Namespace).Delete(GetPVCName(pr), &metav1.DeleteOptions{}); err != nil {
return xerrors.Errorf("failed to delete Persistent Volume %q due to error: %w", pr.Name, err)
return fmt.Errorf("failed to delete Persistent Volume %q due to error: %w", pr.Name, err)
}
return nil
}
Expand Down
Loading