diff --git a/api/approval.go b/api/approval.go index 41502ed9c79..d7c84594ae4 100644 --- a/api/approval.go +++ b/api/approval.go @@ -19,10 +19,10 @@ package api import ( "bufio" "bytes" + "fmt" "io" "github.com/go-playground/validator/v10" - "github.com/pkg/errors" "k8s.io/enhancements/pkg/yaml" ) @@ -51,7 +51,7 @@ type PRRApproval struct { func (prr *PRRApproval) Validate() error { v := validator.New() if err := v.Struct(prr); err != nil { - return errors.Wrap(err, "running validation") + return fmt.Errorf("running validation: %w", err) } return nil @@ -128,17 +128,17 @@ func (p *PRRHandler) Parse(in io.Reader) (*PRRApproval, error) { approval := &PRRApproval{} if err := scanner.Err(); err != nil { - return approval, errors.Wrap(err, "reading file") + return approval, fmt.Errorf("reading file: %w", err) } if err := yaml.UnmarshalStrict(body.Bytes(), &approval); err != nil { - p.Errors = append(p.Errors, errors.Wrap(err, "error unmarshalling YAML")) - return approval, errors.Wrap(err, "unmarshalling YAML") + p.Errors = append(p.Errors, fmt.Errorf("error unmarshalling YAML: %w", err)) + return approval, fmt.Errorf("unmarshalling YAML: %w", err) } if valErr := approval.Validate(); valErr != nil { - p.Errors = append(p.Errors, errors.Wrap(valErr, "validating PRR")) - return approval, errors.Wrap(valErr, "validating PRR") + p.Errors = append(p.Errors, fmt.Errorf("validating PRR: %w", valErr)) + return approval, fmt.Errorf("validating PRR: %w", valErr) } return approval, nil diff --git a/api/error.go b/api/error.go index 25eeafdbd9d..b1578e08f7e 100644 --- a/api/error.go +++ b/api/error.go @@ -17,7 +17,7 @@ limitations under the License. package api import ( - "github.com/pkg/errors" + "errors" ) var ( diff --git a/api/groups.go b/api/groups.go index b006f6bcbaa..87b32c2d569 100644 --- a/api/groups.go +++ b/api/groups.go @@ -18,14 +18,13 @@ package api import ( "bufio" + "errors" "fmt" "io/ioutil" "net/http" "regexp" "sort" - "github.com/pkg/errors" - "k8s.io/enhancements/pkg/yaml" ) @@ -92,18 +91,13 @@ var _ GroupFetcher = &RemoteGroupFetcher{} func (f *RemoteGroupFetcher) FetchGroups() ([]string, error) { resp, err := http.Get(f.GroupsListURL) if err != nil { - return nil, errors.Wrap(err, "fetching SIG list") + return nil, fmt.Errorf("fetching SIG list: %w", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, errors.New( - fmt.Sprintf( - "invalid status code when fetching SIG list: %d", - resp.StatusCode, - ), - ) + return nil, fmt.Errorf("invalid status code when fetching SIG list: %d", resp.StatusCode) } re := regexp.MustCompile(`- dir: (.*)$`) @@ -118,7 +112,7 @@ func (f *RemoteGroupFetcher) FetchGroups() ([]string, error) { } if err := scanner.Err(); err != nil { - return nil, errors.Wrap(err, "scanning SIG list") + return nil, fmt.Errorf("scanning SIG list: %w", err) } sort.Strings(result) @@ -130,23 +124,18 @@ func (f *RemoteGroupFetcher) FetchGroups() ([]string, error) { func (f *RemoteGroupFetcher) FetchPRRApprovers() ([]string, error) { resp, err := http.Get(f.OwnersAliasesURL) if err != nil { - return nil, errors.Wrap(err, "fetching owners aliases") + return nil, fmt.Errorf("fetching owners aliases: %w", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, errors.New( - fmt.Sprintf( - "invalid status code when fetching owners aliases: %d", - resp.StatusCode, - ), - ) + return nil, fmt.Errorf("invalid status code when fetching owners aliases: %d", resp.StatusCode) } body, err := ioutil.ReadAll(resp.Body) if err != nil { - return nil, errors.Wrap(err, "reading owners aliases") + return nil, fmt.Errorf("reading owners aliases: %w", err) } config := &struct { @@ -154,7 +143,7 @@ func (f *RemoteGroupFetcher) FetchPRRApprovers() ([]string, error) { }{} if err := yaml.UnmarshalStrict(body, config); err != nil { - return nil, errors.Wrap(err, "unmarshalling owners aliases") + return nil, fmt.Errorf("unmarshalling owners aliases: %w", err) } var result []string diff --git a/api/proposal.go b/api/proposal.go index b81837d5a85..d39e3dba7be 100644 --- a/api/proposal.go +++ b/api/proposal.go @@ -25,7 +25,6 @@ import ( "strings" "github.com/go-playground/validator/v10" - "github.com/pkg/errors" "k8s.io/enhancements/pkg/yaml" ) @@ -177,7 +176,7 @@ func (k *KEPHandler) Parse(in io.Reader) (*Proposal, error) { } if err := scanner.Err(); err != nil { - return kep, errors.Wrap(err, "reading file") + return kep, fmt.Errorf("reading file: %w", err) } // this file is just the KEP metadata @@ -187,8 +186,8 @@ func (k *KEPHandler) Parse(in io.Reader) (*Proposal, error) { } if err := yaml.UnmarshalStrict(metadata, &kep); err != nil { - k.Errors = append(k.Errors, errors.Wrap(err, "error unmarshalling YAML")) - return kep, errors.Wrap(err, "unmarshalling YAML") + k.Errors = append(k.Errors, fmt.Errorf("error unmarshalling YAML: %w", err)) + return kep, fmt.Errorf("unmarshalling YAML: %w", err) } if err := k.validateStruct(kep); err != nil { diff --git a/go.mod b/go.mod index e755d859bdf..a13a7738d6b 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/google/go-github/v33 v33.0.0 github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0 github.com/olekukonko/tablewriter v0.0.5 - github.com/pkg/errors v0.9.1 github.com/psampaz/go-mod-outdated v0.8.0 github.com/sirupsen/logrus v1.7.0 github.com/spf13/cobra v1.1.1 @@ -44,6 +43,7 @@ require ( github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.6.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect diff --git a/keps/sig-scheduling/624-scheduling-framework/README.md b/keps/sig-scheduling/624-scheduling-framework/README.md index d655a6f29dc..8d7656e6125 100644 --- a/keps/sig-scheduling/624-scheduling-framework/README.md +++ b/keps/sig-scheduling/624-scheduling-framework/README.md @@ -588,7 +588,7 @@ func NewServiceAffinity(args *runtime.Unknown, h FrameworkHandle) (Plugin, error LabelName, LabelValue string } if err := json.Unmarshal(args.Raw, &config); err != nil { - return nil, errors.Wrap(err, "could not parse args") + return nil, fmt.Errorf("could not parse args: %w", err) } //... } diff --git a/pkg/kepctl/commands/create.go b/pkg/kepctl/commands/create.go index cbc3793665e..2cf6dd4c27e 100644 --- a/pkg/kepctl/commands/create.go +++ b/pkg/kepctl/commands/create.go @@ -17,7 +17,8 @@ limitations under the License. package commands import ( - "github.com/pkg/errors" + "fmt" + "github.com/spf13/cobra" "k8s.io/enhancements/api" @@ -128,7 +129,7 @@ func addCreate(topLevel *cobra.Command) { func runCreate(opts *proposal.CreateOpts) error { rc, err := repo.New(rootOpts.RepoPath) if err != nil { - return errors.Wrap(err, "creating repo client") + return fmt.Errorf("creating repo client: %w", err) } opts.Repo = rc diff --git a/pkg/kepctl/commands/promote.go b/pkg/kepctl/commands/promote.go index 6dda4e418c6..ca4bfeeb768 100644 --- a/pkg/kepctl/commands/promote.go +++ b/pkg/kepctl/commands/promote.go @@ -17,7 +17,8 @@ limitations under the License. package commands import ( - "github.com/pkg/errors" + "fmt" + "github.com/spf13/cobra" "k8s.io/enhancements/pkg/proposal" @@ -65,7 +66,7 @@ func addPromote(topLevel *cobra.Command) { func runPromote(opts *proposal.PromoteOpts) error { rc, err := repo.New(rootOpts.RepoPath) if err != nil { - return errors.Wrap(err, "creating repo client") + return fmt.Errorf("creating repo client: %w", err) } opts.Repo = rc diff --git a/pkg/kepctl/commands/query.go b/pkg/kepctl/commands/query.go index 86b3cb3d1d8..1f3e98c9210 100644 --- a/pkg/kepctl/commands/query.go +++ b/pkg/kepctl/commands/query.go @@ -20,7 +20,6 @@ import ( "fmt" "os" - "github.com/pkg/errors" "github.com/spf13/cobra" "k8s.io/enhancements/pkg/output" @@ -115,7 +114,7 @@ func addQuery(topLevel *cobra.Command) { func runQuery(opts *repo.QueryOpts) error { rc, err := repo.New(rootOpts.RepoPath) if err != nil { - return errors.Wrap(err, "creating repo client") + return fmt.Errorf("creating repo client: %w", err) } rc.TokenPath = rootOpts.TokenPath diff --git a/pkg/kepval/approval.go b/pkg/kepval/approval.go index 12009ff165d..84d45730419 100644 --- a/pkg/kepval/approval.go +++ b/pkg/kepval/approval.go @@ -17,13 +17,13 @@ limitations under the License. package kepval import ( + "errors" "fmt" "os" "path/filepath" "strings" "github.com/blang/semver/v4" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/enhancements/api" @@ -32,7 +32,7 @@ import ( func ValidatePRR(kep *api.Proposal, h *api.PRRHandler, prrDir string) error { requiredPRRApproval, err := isPRRRequired(kep) if err != nil { - return errors.Wrap(err, "checking if PRR is required") + return fmt.Errorf("checking if PRR is required: %w", err) } if !requiredPRRApproval { @@ -55,24 +55,24 @@ func ValidatePRR(kep *api.Proposal, h *api.PRRHandler, prrDir string) error { } if err != nil { - return errors.Wrapf(err, "could not open file %s", prrFilepath) + return fmt.Errorf("could not open file %s: %w", prrFilepath, err) } // TODO: Create a context to hold the parsers prr, prrParseErr := h.Parse(prrFile) if prrParseErr != nil { - return errors.Wrap(prrParseErr, "parsing PRR approval file") + return fmt.Errorf("parsing PRR approval file: %w", prrParseErr) } // TODO: This shouldn't be required once we push the errors into the // parser struct if prr.Error != nil { - return errors.Wrapf(prr.Error, "%v has an error", prrFilepath) + return fmt.Errorf("%v has an error: %w", prrFilepath, prr.Error) } stagePRRApprover, err := prr.ApproverForStage(kep.Stage) if err != nil { - return errors.Wrapf(err, "getting PRR approver for %s stage", kep.Stage) + return fmt.Errorf("getting PRR approver for %s stage: %w", kep.Stage, err) } if stagePRRApprover == "" { @@ -85,13 +85,7 @@ func ValidatePRR(kep *api.Proposal, h *api.PRRHandler, prrDir string) error { validApprover := api.IsOneOf(stagePRRApprover, h.PRRApprovers) if !validApprover { - return errors.New( - fmt.Sprintf( - "this contributor (%s) is not a PRR approver (%v)", - stagePRRApprover, - h.PRRApprovers, - ), - ) + return fmt.Errorf("this contributor (%s) is not a PRR approver (%v)", stagePRRApprover, h.PRRApprovers) } return nil @@ -116,12 +110,12 @@ func isPRRRequired(kep *api.Proposal) (required bool, err error) { // TODO: Consider making this a function prrRequiredAtSemVer, err := semver.ParseTolerant("v1.21") if err != nil { - return required, errors.Wrap(err, "creating a SemVer object for PRRs") + return required, fmt.Errorf("creating a SemVer object for PRRs: %w", err) } latestSemVer, err := semver.ParseTolerant(kep.LatestMilestone) if err != nil { - return required, errors.Wrap(err, "creating a SemVer object for latest milestone") + return required, fmt.Errorf("creating a SemVer object for latest milestone: %w", err) } if latestSemVer.LT(prrRequiredAtSemVer) { diff --git a/pkg/proposal/create.go b/pkg/proposal/create.go index 537d0335295..47d78b1390d 100644 --- a/pkg/proposal/create.go +++ b/pkg/proposal/create.go @@ -24,7 +24,6 @@ import ( "strings" "time" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/enhancements/api" @@ -115,7 +114,7 @@ func createKEP(kep *api.Proposal, opts *CreateOpts) error { ) if writeErr := ioutil.WriteFile(newPath, template, os.ModePerm); writeErr != nil { - return errors.Wrapf(writeErr, "writing KEP data to file") + return fmt.Errorf("writing KEP data to file: %w", writeErr) } return nil diff --git a/pkg/proposal/options.go b/pkg/proposal/options.go index 1b4a817157a..b48c35e3726 100644 --- a/pkg/proposal/options.go +++ b/pkg/proposal/options.go @@ -17,10 +17,9 @@ limitations under the License. package proposal import ( + "errors" "fmt" "regexp" - - "github.com/pkg/errors" ) type Options struct { diff --git a/pkg/repo/query.go b/pkg/repo/query.go index a55177bb5c9..0cf8a965a39 100644 --- a/pkg/repo/query.go +++ b/pkg/repo/query.go @@ -17,10 +17,10 @@ limitations under the License. package repo import ( + "errors" "fmt" "regexp" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/enhancements/api" @@ -95,7 +95,7 @@ func (r *Repo) Query(opts *QueryOpts) ([]*api.Proposal, error) { if r.TokenPath != "" { logrus.Infof("Setting GitHub token: %v", r.TokenPath) if tokenErr := r.SetGitHubToken(r.TokenPath); tokenErr != nil { - return nil, errors.Wrapf(tokenErr, "setting GitHub token") + return nil, fmt.Errorf("setting GitHub token: %w", tokenErr) } } @@ -105,7 +105,7 @@ func (r *Repo) Query(opts *QueryOpts) ([]*api.Proposal, error) { // KEPs in the local filesystem localKEPs, err := r.LoadLocalKEPs(sig) if err != nil { - return nil, errors.Wrap(err, "loading local KEPs") + return nil, fmt.Errorf("loading local KEPs: %w", err) } allKEPs = append(allKEPs, localKEPs...) diff --git a/pkg/repo/repo.go b/pkg/repo/repo.go index 2b6808d819a..82e77408952 100644 --- a/pkg/repo/repo.go +++ b/pkg/repo/repo.go @@ -27,7 +27,6 @@ import ( "strings" "github.com/google/go-github/v33/github" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/oauth2" @@ -96,52 +95,31 @@ func NewRepo(repoPath string, fetcher api.GroupFetcher) (*Repo, error) { proposalPath := filepath.Join(repoPath, ProposalPathStub) fi, err := os.Stat(proposalPath) if err != nil { - return nil, errors.Wrapf( - err, - "getting file info for proposal path %s", - proposalPath, - ) + return nil, fmt.Errorf("getting file info for proposal path %s: %w", proposalPath, err) } if !fi.IsDir() { - return nil, errors.Wrap( - err, - "checking if proposal path is a directory", - ) + return nil, fmt.Errorf("checking if proposal path is a directory: %w", err) } prrApprovalPath := filepath.Join(proposalPath, PRRApprovalPathStub) fi, err = os.Stat(prrApprovalPath) if err != nil { - return nil, errors.Wrapf( - err, - "getting file info for PRR approval path %s", - prrApprovalPath, - ) + return nil, fmt.Errorf("getting file info for PRR approval path %s: %w", prrApprovalPath, err) } if !fi.IsDir() { - return nil, errors.Wrap( - err, - "checking if PRR approval path is a directory", - ) + return nil, fmt.Errorf("checking if PRR approval path is a directory: %w", err) } proposalReadme := filepath.Join(proposalPath, "README.md") fi, err = os.Stat(proposalReadme) if err != nil { - return nil, errors.Wrapf( - err, - "getting file info for proposal README path %s", - proposalPath, - ) + return nil, fmt.Errorf("getting file info for proposal README path %s: %w", proposalPath, err) } if !fi.Mode().IsRegular() { - return nil, errors.Wrap( - err, - "checking if proposal README is a file", - ) + return nil, fmt.Errorf("checking if proposal README is a file: %w", err) } groups, err := fetcher.FetchGroups() @@ -169,7 +147,7 @@ func NewRepo(repoPath string, fetcher api.GroupFetcher) (*Repo, error) { proposalTemplate, err := repo.getProposalTemplate() if err != nil { - return nil, errors.Wrap(err, "getting proposal template") + return nil, fmt.Errorf("getting proposal template: %w", err) } repo.ProposalTemplate = proposalTemplate @@ -258,11 +236,7 @@ func (r *Repo) LoadLocalKEPs(sig string) ([]*api.Proposal, error) { // KEPs in the local filesystem files, err := r.findLocalKEPMeta(sig) if err != nil { - return nil, errors.Wrapf( - err, - "searching for local KEPs from %s", - sig, - ) + return nil, fmt.Errorf("searching for local KEPs from %s: %w", sig, err) } logrus.Debugf("loading the following local KEPs: %v", files) @@ -271,11 +245,7 @@ func (r *Repo) LoadLocalKEPs(sig string) ([]*api.Proposal, error) { for i, kepYamlPath := range files { kep, err := r.loadKEPFromYaml(r.BasePath, kepYamlPath) if err != nil { - return nil, errors.Wrapf( - err, - "reading KEP %s from yaml", - kepYamlPath, - ) + return nil, fmt.Errorf("reading KEP %s from yaml: %w", kepYamlPath, err) } allKEPs[i] = kep @@ -296,7 +266,7 @@ func (r *Repo) LoadLocalKEP(sig, name string) (*api.Proposal, error) { _, err := os.Stat(kepPath) if err != nil { - return nil, errors.Wrapf(err, "getting file info for %s", kepPath) + return nil, fmt.Errorf("getting file info for %s: %w", kepPath, err) } return r.loadKEPFromYaml(r.BasePath, kepPath) @@ -481,7 +451,7 @@ func (r *Repo) loadKEPFromYaml(repoPath, kepPath string) (*api.Proposal, error) if err != nil { logrus.Errorf( "%v", - errors.Wrapf(err, "validating PRR for %s", p.Name), + fmt.Errorf("validating PRR for %s: %w", p.Name, err), ) } diff --git a/pkg/repo/validate.go b/pkg/repo/validate.go index f152cd4505e..07d88ab6b6e 100644 --- a/pkg/repo/validate.go +++ b/pkg/repo/validate.go @@ -17,11 +17,11 @@ limitations under the License. package repo import ( + "errors" "fmt" "os" "path/filepath" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/enhancements/pkg/kepval" @@ -87,7 +87,7 @@ func (r *Repo) Validate() ( // This indicates a problem walking the filepath, not a validation error. if err != nil { - return warnings, valErrMap, errors.Wrap(err, "walking repository") + return warnings, valErrMap, fmt.Errorf("walking repository: %w", err) } if len(files) == 0 { @@ -130,7 +130,7 @@ func (e fatalValidationError) Unwrap() error { return e.Err } func validateFile(r *Repo, prrDir, filename string) error { kepFile, err := os.Open(filename) if err != nil { - return &fatalValidationError{Err: errors.Wrapf(err, "could not open file %s", filename)} + return &fatalValidationError{Err: fmt.Errorf("could not open file %s: %w", filename, err)} } defer kepFile.Close() @@ -138,14 +138,14 @@ func validateFile(r *Repo, prrDir, filename string) error { kepHandler, prrHandler := r.KEPHandler, r.PRRHandler kep, kepParseErr := kepHandler.Parse(kepFile) if kepParseErr != nil { - return errors.Wrap(kepParseErr, "parsing KEP file") + return fmt.Errorf("parsing KEP file: %w", kepParseErr) } kep.Filename = filename // TODO: This shouldn't be required once we push the errors into the // parser struct if kep.Error != nil { - return &fatalValidationError{Err: errors.Wrapf(kep.Error, "%v has an error", filename)} + return &fatalValidationError{Err: fmt.Errorf("%v has an error: %w", filename, kep.Error)} } return kepval.ValidatePRR(kep, prrHandler, prrDir)