diff --git a/cmd/ci-reporter/cmd/github.go b/cmd/ci-reporter/cmd/github.go index 0c53c6d73cb..387a4076dbe 100644 --- a/cmd/ci-reporter/cmd/github.go +++ b/cmd/ci-reporter/cmd/github.go @@ -19,9 +19,9 @@ package cmd import ( "context" "encoding/json" - "fmt" "os" + "github.com/pkg/errors" "github.com/shurcooL/githubv4" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -89,7 +89,7 @@ func (r GithubReporter) CollectReportData(cfg *Config) ([]*CIReportRecord, error // request github projectboard data githubReportData, err := GetGithubReportData(*cfg, fieldFilter) if err != nil { - return nil, fmt.Errorf("getting GitHub report data: %w", err) + return nil, errors.Wrap(err, "getting GitHub report data") } records := []*CIReportRecord{} diff --git a/cmd/ci-reporter/cmd/root.go b/cmd/ci-reporter/cmd/root.go index 9fd533288b0..96501df057f 100644 --- a/cmd/ci-reporter/cmd/root.go +++ b/cmd/ci-reporter/cmd/root.go @@ -18,13 +18,13 @@ package cmd import ( "encoding/json" - "errors" "fmt" "os" "strings" "time" "github.com/olekukonko/tablewriter" + "github.com/pkg/errors" "github.com/shurcooL/githubv4" "github.com/spf13/cobra" "github.com/tj/go-spin" @@ -85,7 +85,7 @@ func RunReport(cfg *Config, reporters *CIReporters) error { // visualize data if err := PrintReporterData(cfg, reports); err != nil { - return fmt.Errorf("printing report data: %w", err) + return errors.Wrap(err, "printing report data") } return nil @@ -195,7 +195,7 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error { // open output file fileOut, err := os.OpenFile(cfg.Filepath, os.O_WRONLY|os.O_CREATE, 0o666) if err != nil { - return fmt.Errorf("could not open or create a file at %s to write the ci signal report to: %w", cfg.Filepath, err) + return errors.Wrapf(err, "could not open or create a file at %s to write the ci signal report to", cfg.Filepath) } out = fileOut } else { @@ -212,11 +212,11 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error { // print report in json format d, err := reports.Marshal() if err != nil { - return fmt.Errorf("could not marshal report data: %w", err) + return errors.Wrap(err, "could not marshal report data") } _, err = out.WriteString(string(d)) if err != nil { - return fmt.Errorf("could not write to output stream: %w", err) + return errors.Wrap(err, "could not write to output stream") } return nil } @@ -226,7 +226,7 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error { // write header _, err := out.WriteString(fmt.Sprintf("\n%s REPORT\n\n", strings.ToUpper(string(r.Info.Name)))) if err != nil { - return fmt.Errorf("could not write to output stream: %w", err) + return errors.Wrap(err, "could not write to output stream") } table := tablewriter.NewWriter(out) @@ -266,7 +266,7 @@ func PrintReporterData(cfg *Config, reports *CIReportDataFields) error { categoryCounts += fmt.Sprintf("%s:%d ", category, categoryCount) } if _, err := out.WriteString(fmt.Sprintf("\nSUMMARY - Total:%d %s\n", len(data), categoryCounts)); err != nil { - return fmt.Errorf("could not write to output stream: %w", err) + return errors.Wrap(err, "could not write to output stream") } } return nil diff --git a/cmd/krel/cmd/announce_build.go b/cmd/krel/cmd/announce_build.go index 67ac2898249..d5bf47df82e 100644 --- a/cmd/krel/cmd/announce_build.go +++ b/cmd/krel/cmd/announce_build.go @@ -25,6 +25,7 @@ import ( "strings" "text/template" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -176,7 +177,7 @@ func runBuildBranchAnnounce(opts *buildBranchAnnounceOptions, buildOpts *buildAn if err := t.Execute(&annoucement, struct { Branch string }{opts.branch}); err != nil { - return fmt.Errorf("generating the announcement html file: %w", err) + return errors.Wrap(err, "generating the announcement html file") } announcementSubject := fmt.Sprintf("Kubernetes %s branch has been created", opts.branch) @@ -186,7 +187,7 @@ func runBuildBranchAnnounce(opts *buildBranchAnnounceOptions, buildOpts *buildAn // runBuildReleaseAnnounce build the announcement file when creating a new Kubernetes release func runBuildReleaseAnnounce(opts *buildReleaseAnnounceOptions, buildOpts *buildAnnounceOptions, announceOpts *announceOptions) error { if err := announceOpts.Validate(); err != nil { - return fmt.Errorf("validating annoucement send options: %w", err) + return errors.Wrap(err, "validating annoucement send options") } logrus.Info("Building release announcement for new release") @@ -222,7 +223,7 @@ func runBuildReleaseAnnounce(opts *buildReleaseAnnounceOptions, buildOpts *build filepath.Base(opts.changelogFilePath), string(changelogHTML), }); err != nil { - return fmt.Errorf("generating the announcement html file: %w", err) + return errors.Wrap(err, "generating the announcement html file") } announcementSubject := fmt.Sprintf("Kubernetes %s is live!", announceOpts.tag) @@ -237,14 +238,14 @@ func (opts *buildAnnounceOptions) saveAnnouncement(announcementSubject string, a logrus.Infof("Writing HTML file to %s", absOutputPath) err := os.WriteFile(absOutputPath, annoucement.Bytes(), os.FileMode(0o644)) if err != nil { - return fmt.Errorf("saving announcement.html: %w", err) + return errors.Wrap(err, "saving announcement.html") } absOutputPath = filepath.Join(opts.workDir, "announcement-subject.txt") logrus.Infof("Writing announcement subject to %s", absOutputPath) err = os.WriteFile(absOutputPath, []byte(announcementSubject), os.FileMode(0o644)) if err != nil { - return fmt.Errorf("saving announcement-subject.txt: %w", err) + return errors.Wrap(err, "saving announcement-subject.txt") } logrus.Info("Kubernetes Announcement created.") @@ -256,7 +257,7 @@ func getGoVersion() (string, error) { "go", "version"). RunSilentSuccessOutput() if err != nil { - return "", fmt.Errorf("get go version: %w", err) + return "", errors.Wrap(err, "get go version") } versionRegex := regexp.MustCompile(semVerRegex) diff --git a/cmd/krel/cmd/announce_send.go b/cmd/krel/cmd/announce_send.go index fa66e1d2aa7..a766baa95db 100644 --- a/cmd/krel/cmd/announce_send.go +++ b/cmd/krel/cmd/announce_send.go @@ -17,9 +17,9 @@ limitations under the License. package cmd import ( - "errors" "fmt" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -110,7 +110,7 @@ func init() { func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, rootOpts *rootOptions) error { if err := announceRootOpts.Validate(); err != nil { - return fmt.Errorf("validating annoucement send options: %w", err) + return errors.Wrap(err, "validating annoucement send options") } logrus.Info("Retrieving release announcement from Google Cloud Bucket") @@ -123,8 +123,8 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r content, err := http.GetURLResponse(u, false) if err != nil { - return fmt.Errorf( - "unable to retrieve release announcement form url: %s: %w", u, err, + return errors.Wrapf(err, + "unable to retrieve release announcement form url: %s", u, ) } @@ -135,7 +135,7 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r } if opts.sendgridAPIKey == "" { - return fmt.Errorf( + return errors.Errorf( "$%s is not set", sendgridAPIKeyEnvKey, ) } @@ -145,12 +145,12 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r if opts.name != "" && opts.email != "" { if err := m.SetSender(opts.name, opts.email); err != nil { - return fmt.Errorf("unable to set mail sender: %w", err) + return errors.Wrap(err, "unable to set mail sender") } } else { logrus.Info("Retrieving default sender from sendgrid API") if err := m.SetDefaultSender(); err != nil { - return fmt.Errorf("setting default sender: %w", err) + return errors.Wrap(err, "setting default sender") } } @@ -164,7 +164,7 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r logrus.Infof("Using Google Groups as announcement target: %v", groups) if err := m.SetGoogleGroupRecipients(groups...); err != nil { - return fmt.Errorf("unable to set mail recipients: %w", err) + return errors.Wrap(err, "unable to set mail recipients") } logrus.Info("Sending mail") @@ -181,7 +181,7 @@ func runAnnounce(opts *sendAnnounceOptions, announceRootOpts *announceOptions, r if yes { if err := m.Send(content, subject); err != nil { - return fmt.Errorf("unable to send mail: %w", err) + return errors.Wrap(err, "unable to send mail") } } diff --git a/cmd/krel/cmd/ci_build.go b/cmd/krel/cmd/ci_build.go index 069c7d0e772..06bc82ed96a 100644 --- a/cmd/krel/cmd/ci_build.go +++ b/cmd/krel/cmd/ci_build.go @@ -19,6 +19,7 @@ package cmd import ( "fmt" + "github.com/pkg/errors" "github.com/spf13/cobra" "k8s.io/release/pkg/build" @@ -49,7 +50,7 @@ var ciBuildCmd = &cobra.Command{ SilenceErrors: true, RunE: func(cmd *cobra.Command, args []string) error { if err := runCIBuild(ciBuildOpts); err != nil { - return fmt.Errorf("failed to run: %w", err) + return errors.Wrap(err, "failed to run") } return nil diff --git a/cmd/krel/cmd/cve.go b/cmd/krel/cmd/cve.go index b1ed7c2cdd4..fae25749974 100644 --- a/cmd/krel/cmd/cve.go +++ b/cmd/krel/cmd/cve.go @@ -18,11 +18,10 @@ package cmd import ( "bytes" - "errors" - "fmt" "os" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -88,7 +87,7 @@ var argFunc = func(cmd *cobra.Command, args []string) error { } cveOpts.CVE = strings.ToUpper(args[0]) if err := cve.NewClient().CheckID(cveOpts.CVE); err != nil { - return fmt.Errorf("invalid CVE ID. Format must match %s", cve.CVEIDRegExp) + return errors.Errorf("invalid CVE ID. Format must match %s", cve.CVEIDRegExp) } return nil } @@ -114,12 +113,12 @@ func writeNewCVE(opts *cveOptions) (err error) { file, err := client.CreateEmptyMap(opts.CVE) if err != nil { - return fmt.Errorf("creating new cve data map: %w", err) + return errors.Wrap(err, "creating new cve data map") } oldFile, err := os.ReadFile(file.Name()) if err != nil { - return fmt.Errorf("reading local copy of CVE entry: %w", err) + return errors.Wrap(err, "reading local copy of CVE entry") } kubeEditor := editor.NewDefaultEditor([]string{"KUBE_EDITOR", "EDITOR"}) @@ -127,7 +126,7 @@ func writeNewCVE(opts *cveOptions) (err error) { "cve-datamap-", ".yaml", bytes.NewReader(oldFile), ) if err != nil { - return fmt.Errorf("launching editor: %w", err) + return errors.Wrap(err, "launching editor") } if bytes.Equal(changes, oldFile) || len(changes) == 0 { @@ -146,7 +145,7 @@ func writeCVEFiles(opts *cveOptions) error { client := cve.NewClient() for _, mapFile := range opts.mapFiles { if err := client.Write(opts.CVE, mapFile); err != nil { - return fmt.Errorf("writing map file %s: %w", mapFile, err) + return errors.Wrapf(err, "writing map file %s", mapFile) } } return nil @@ -171,7 +170,7 @@ func editCVE(opts *cveOptions) (err error) { // or we should first pull the data from the bucket exists, err := client.EntryExists(opts.CVE) if err != nil { - return fmt.Errorf("checking if cve entry exists: %w", err) + return errors.Wrap(err, "checking if cve entry exists") } if exists { @@ -187,11 +186,11 @@ func editExistingCVE(opts *cveOptions) (err error) { client := cve.NewClient() file, err := client.CopyToTemp(opts.CVE) if err != nil { - return fmt.Errorf("copying CVE entry for edting: %w", err) + return errors.Wrap(err, "copying CVE entry for edting") } oldFile, err := os.ReadFile(file.Name()) if err != nil { - return fmt.Errorf("reading local copy of CVE entry: %w", err) + return errors.Wrap(err, "reading local copy of CVE entry") } kubeEditor := editor.NewDefaultEditor([]string{"KUBE_EDITOR", "EDITOR"}) @@ -199,7 +198,7 @@ func editExistingCVE(opts *cveOptions) (err error) { "cve-datamap-", ".yaml", bytes.NewReader(oldFile), ) if err != nil { - return fmt.Errorf("launching editor: %w", err) + return errors.Wrap(err, "launching editor") } if bytes.Equal(changes, oldFile) || len(changes) == 0 { diff --git a/cmd/krel/cmd/push.go b/cmd/krel/cmd/push.go index 942d261d5f0..0cab0167fe1 100644 --- a/cmd/krel/cmd/push.go +++ b/cmd/krel/cmd/push.go @@ -19,6 +19,7 @@ package cmd import ( "fmt" + "github.com/pkg/errors" "github.com/spf13/cobra" "k8s.io/release/pkg/build" @@ -50,7 +51,7 @@ var pushBuildCmd = &cobra.Command{ SilenceErrors: true, RunE: func(cmd *cobra.Command, args []string) error { if err := runPushBuild(pushBuildOpts); err != nil { - return fmt.Errorf("failed to run: %w", err) + return errors.Wrap(err, "failed to run") } return nil diff --git a/cmd/krel/cmd/release.go b/cmd/krel/cmd/release.go index 2bff1ce1331..4060d8b4d93 100644 --- a/cmd/krel/cmd/release.go +++ b/cmd/krel/cmd/release.go @@ -20,6 +20,7 @@ import ( "fmt" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -137,7 +138,7 @@ func runRelease(options *anago.ReleaseOptions) error { // Perform a local check of the specified options // before launching a Cloud Build job: if err := options.Validate(&anago.State{}); err != nil { - return fmt.Errorf("prechecking release options: %w", err) + return errors.Wrap(err, "prechecking release options") } return rel.Submit(stream) } diff --git a/cmd/krel/cmd/release_notes.go b/cmd/krel/cmd/release_notes.go index ad257702e10..07653cabde1 100644 --- a/cmd/krel/cmd/release_notes.go +++ b/cmd/krel/cmd/release_notes.go @@ -20,7 +20,6 @@ import ( "bufio" "bytes" "encoding/json" - "errors" "fmt" "os" "os/exec" @@ -30,6 +29,7 @@ import ( "time" "github.com/blang/semver" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "gopkg.in/yaml.v2" @@ -227,7 +227,7 @@ func runReleaseNotes() (err error) { if releaseNotesOpts.tag == "" { tag, err = tryToFindLatestMinorTag() if err != nil { - return fmt.Errorf("unable to find latest minor tag: %w", err) + return errors.Wrapf(err, "unable to find latest minor tag") } releaseNotesOpts.tag = tag } else { @@ -237,7 +237,7 @@ func runReleaseNotes() (err error) { if releaseNotesOpts.userFork != "" { org, repo, err := git.ParseRepoSlug(releaseNotesOpts.userFork) if err != nil { - return fmt.Errorf("parsing the user's fork: %w", err) + return errors.Wrap(err, "parsing the user's fork") } releaseNotesOpts.githubOrg = org releaseNotesOpts.websiteRepo, releaseNotesOpts.draftRepo = repo, repo @@ -250,7 +250,7 @@ func runReleaseNotes() (err error) { // First, validate cmdline options if err := releaseNotesOpts.Validate(); err != nil { - return fmt.Errorf("validating command line options: %w", err) + return errors.Wrap(err, "validating command line options") } // before running the generators, verify that the repositories are ready @@ -260,7 +260,7 @@ func runReleaseNotes() (err error) { releaseNotesOpts.githubOrg, releaseNotesOpts.websiteRepo, defaultKubernetesSigsOrg, defaultKubernetesSigsRepo, ); err != nil { - return fmt.Errorf("while checking %s/%s fork: %w", defaultKubernetesSigsOrg, defaultKubernetesSigsRepo, err) + return errors.Wrapf(err, "while checking %s/%s fork", defaultKubernetesSigsOrg, defaultKubernetesSigsRepo) } } @@ -270,7 +270,7 @@ func runReleaseNotes() (err error) { releaseNotesOpts.githubOrg, releaseNotesOpts.draftRepo, git.DefaultGithubOrg, git.DefaultGithubReleaseRepo, ); err != nil { - return fmt.Errorf("while checking %s/%s fork: %w", git.DefaultGithubOrg, git.DefaultGithubReleaseRepo, err) + return errors.Wrapf(err, "while checking %s/%s fork", git.DefaultGithubOrg, git.DefaultGithubReleaseRepo) } } @@ -278,7 +278,7 @@ func runReleaseNotes() (err error) { if releaseNotesOpts.createWebsitePR && confirmWithUser(releaseNotesOpts, "Create website pull request?") { // Run the website PR process if err := createWebsitePR(releaseNotesOpts.repoPath, tag); err != nil { - return fmt.Errorf("creating website PR: %w", err) + return errors.Wrap(err, "creating website PR") } } @@ -286,7 +286,7 @@ func runReleaseNotes() (err error) { if releaseNotesOpts.createDraftPR && confirmWithUser(releaseNotesOpts, "Create draft pull request?") { // Create the Draft PR Process if err := createDraftPR(releaseNotesOpts.repoPath, tag); err != nil { - return fmt.Errorf("creating Draft PR: %w", err) + return errors.Wrap(err, "creating Draft PR") } } @@ -301,7 +301,7 @@ func runReleaseNotes() (err error) { func createDraftPR(repoPath, tag string) (err error) { tagVersion, err := util.TagStringToSemver(tag) if err != nil { - return fmt.Errorf("reading tag: %s: %w", tag, err) + return errors.Wrapf(err, "reading tag: %s", tag) } // From v1.20.0 on we use the previous minor as a starting tag @@ -322,9 +322,9 @@ func createDraftPR(repoPath, tag string) (err error) { git.DefaultGithubOrg, git.DefaultGithubReleaseRepo, ) if err != nil { - return fmt.Errorf( - "while checking if repository is a fork of %s/%s: %w", - git.DefaultGithubOrg, git.DefaultGithubReleaseRepo, err, + return errors.Wrapf( + err, "while checking if repository is a fork of %s/%s", + git.DefaultGithubOrg, git.DefaultGithubReleaseRepo, ) } @@ -341,7 +341,7 @@ func createDraftPR(repoPath, tag string) (err error) { // Generate the notes for the current version releaseNotes, err := gatherNotesFrom(repoPath, start) if err != nil { - return fmt.Errorf("while generating the release notes for tag %s: %w", start, err) + return errors.Wrapf(err, "while generating the release notes for tag %s", start) } branchname := draftBranchPrefix + tag @@ -353,7 +353,7 @@ func createDraftPR(repoPath, tag string) (err error) { releaseNotesOpts.githubOrg, releaseNotesOpts.draftRepo, ) if err != nil { - return fmt.Errorf("preparing local fork of kubernetes/sig-release: %w", err) + return errors.Wrap(err, "preparing local fork of kubernetes/sig-release") } // The release path inside the repository @@ -362,7 +362,7 @@ func createDraftPR(repoPath, tag string) (err error) { // Check if the directory exists releaseDir := filepath.Join(sigReleaseRepo.Dir(), releasePath) if !util.Exists(releaseDir) { - return fmt.Errorf("could not find release directory %s", releaseDir) + return errors.Errorf("could not find release directory %s", releaseDir) } // If we got the --fix flag, start the fix flow @@ -373,28 +373,28 @@ func createDraftPR(repoPath, tag string) (err error) { // createNotesWorkDir is idempotent, we can use it to verify the tree is complete if err := createNotesWorkDir(releaseDir); err != nil { - return fmt.Errorf("creating working directory: %w", err) + return errors.Wrap(err, "creating working directory") } // Run the release notes fix flow err := fixReleaseNotes(filepath.Join(releaseDir, releaseNotesWorkDir), releaseNotes) if err != nil { - return fmt.Errorf("while running release notes fix flow: %w", err) + return errors.Wrap(err, "while running release notes fix flow") } // Create the map provider to read the changes so far rnMapProvider, err := notes.NewProviderFromInitString(filepath.Join(releaseDir, releaseNotesWorkDir, mapsMainDirectory)) if err != nil { - return fmt.Errorf("creating release notes draft: %w", err) + return errors.Wrap(err, "creating release notes draft") } for _, note := range releaseNotes.ByPR() { maps, err := rnMapProvider.GetMapsForPR(note.PrNumber) if err != nil { - return fmt.Errorf("while getting maps for PR #%d: %w", note.PrNumber, err) + return errors.Wrapf(err, "while getting maps for PR #%d", note.PrNumber) } for _, noteMap := range maps { if err := note.ApplyMap(noteMap, true); err != nil { - return fmt.Errorf("applying note maps to PR #%d: %w", note.PrNumber, err) + return errors.Wrapf(err, "applying note maps to PR #%d", note.PrNumber) } } } @@ -403,7 +403,7 @@ func createDraftPR(repoPath, tag string) (err error) { // Generate the results struct result, err := buildNotesResult(start, releaseNotes) if err != nil { - return fmt.Errorf("building release notes results: %w", err) + return errors.Wrap(err, "building release notes results") } // generate the notes files @@ -414,7 +414,7 @@ func createDraftPR(repoPath, tag string) (err error) { // 0600 or less err = os.WriteFile(filepath.Join(releaseDir, releaseNotesWorkDir, draftMarkdownFile), []byte(result.markdown), 0o644) if err != nil { - return fmt.Errorf("writing release notes draft: %w", err) + return errors.Wrapf(err, "writing release notes draft") } logrus.Infof("Release Notes Markdown Draft written to %s", filepath.Join(releaseDir, releaseNotesWorkDir, draftMarkdownFile)) @@ -423,7 +423,7 @@ func createDraftPR(repoPath, tag string) (err error) { // 0600 or less err = os.WriteFile(filepath.Join(releaseDir, releaseNotesWorkDir, draftJSONFile), []byte(result.json), 0o644) if err != nil { - return fmt.Errorf("writing release notes json file: %w", err) + return errors.Wrapf(err, "writing release notes json file") } logrus.Infof("Release Notes JSON version written to %s", filepath.Join(releaseDir, releaseNotesWorkDir, draftJSONFile)) @@ -431,7 +431,7 @@ func createDraftPR(repoPath, tag string) (err error) { if !autoCreatePullRequest { _, autoCreatePullRequest, err = util.Ask("Create pull request with your changes? (y/n)", "y:Y:yes|n:N:no|y", 10) if err != nil { - return fmt.Errorf("while asking to create pull request: %w", err) + return errors.Wrap(err, "while asking to create pull request") } } @@ -450,7 +450,7 @@ func createDraftPR(repoPath, tag string) (err error) { defer func() { if e := sigReleaseRepo.Cleanup(); e != nil { - err = fmt.Errorf("cleaning temporary sig release clone: %w", e) + err = errors.Wrap(e, "cleaning temporary sig release clone") } }() @@ -458,13 +458,13 @@ func createDraftPR(repoPath, tag string) (err error) { if err := createDraftCommit( sigReleaseRepo, releasePath, "Release Notes draft for k/k "+tag, ); err != nil { - return fmt.Errorf("creating release notes commit: %w", err) + return errors.Wrap(err, "creating release notes commit") } // push to the user's remote logrus.Infof("Pushing modified release notes draft to %s/%s", releaseNotesOpts.githubOrg, releaseNotesOpts.draftRepo) if err := sigReleaseRepo.PushToRemote(userForkName, branchname); err != nil { - return fmt.Errorf("pushing %s to remote: %w", userForkName, err) + return errors.Wrapf(err, "pushing %s to remote", userForkName) } // Create a PR against k/sig-release using the github API @@ -493,7 +493,7 @@ func createDraftPR(repoPath, tag string) (err error) { if err != nil { logrus.Warnf("An error has occurred while creating the pull request for %s", tag) logrus.Warn("While the PR failed, the release notes draft was generated and submitted to your fork") - return fmt.Errorf("creating the pull request: %w", err) + return errors.Wrap(err, "creating the pull request") } logrus.Infof( "Successfully created PR: %s%s/%s/pull/%d", @@ -511,12 +511,12 @@ func createDraftPR(repoPath, tag string) (err error) { func createDraftCommit(repo *git.Repo, releasePath, commitMessage string) error { // add the updated draft if err := repo.Add(filepath.Join(releasePath, releaseNotesWorkDir, draftMarkdownFile)); err != nil { - return fmt.Errorf("adding release notes draft to staging area: %w", err) + return errors.Wrap(err, "adding release notes draft to staging area") } // add the json draft if err := repo.Add(filepath.Join(releasePath, releaseNotesWorkDir, draftJSONFile)); err != nil { - return fmt.Errorf("adding release notes json to staging area: %w", err) + return errors.Wrap(err, "adding release notes json to staging area") } // List of directories we'll consider for the PR @@ -547,11 +547,11 @@ func createDraftCommit(repo *git.Repo, releasePath, commitMessage string) error matches, err := filepath.Glob(filepath.Join(repo.Dir(), dirData.Path, "*"+dirData.Ext)) logrus.Debugf("Adding %d %s from %s to commit", len(matches), dirData.Name, dirData.Path) if err != nil { - return fmt.Errorf("checking for %s files in %s: %w", dirData.Ext, dirData.Path, err) + return errors.Wrapf(err, "checking for %s files in %s", dirData.Ext, dirData.Path) } if len(matches) > 0 { if err := repo.Add(filepath.Join(dirData.Path, "*"+dirData.Ext)); err != nil { - return fmt.Errorf("adding %s to staging area: %w", dirData.Name, err) + return errors.Wrapf(err, "adding %s to staging area", dirData.Name) } } } else { @@ -561,7 +561,7 @@ func createDraftCommit(repo *git.Repo, releasePath, commitMessage string) error // add the generated draft if err := repo.UserCommit(commitMessage); err != nil { - return fmt.Errorf("creating commit in %s/%s: %w", releaseNotesOpts.githubOrg, releaseNotesOpts.draftRepo, err) + return errors.Wrapf(err, "creating commit in %s/%s", releaseNotesOpts.githubOrg, releaseNotesOpts.draftRepo) } return nil } @@ -573,7 +573,7 @@ func addReferenceToAssetsFile(repoPath, newJSONFile string) error { file, err := os.Open(assetsFullPath) if err != nil { - return fmt.Errorf("opening assets.ts to check for current version: %w", err) + return errors.Wrap(err, "opening assets.ts to check for current version") } defer file.Close() @@ -612,7 +612,7 @@ func addReferenceToAssetsFile(repoPath, newJSONFile string) error { // write the modified assets.ts file if err := os.WriteFile(assetsFullPath, assetsBuffer.Bytes(), os.FileMode(0o644)); err != nil { - return fmt.Errorf("writing assets.ts file: %w", err) + return errors.Wrap(err, "writing assets.ts file") } return nil @@ -622,19 +622,19 @@ func addReferenceToAssetsFile(repoPath, newJSONFile string) error { func processJSONOutput(repoPath string) error { npmpath, err := exec.LookPath("npm") if err != nil { - return fmt.Errorf("while looking for npm in your path: %w", err) + return errors.Wrap(err, "while looking for npm in your path") } // run npm install logrus.Info("Installing npm modules, this can take a while") if err := command.NewWithWorkDir(repoPath, npmpath, "install").RunSuccess(); err != nil { - return fmt.Errorf("running npm install in kubernetes-sigs/release-notes: %w", err) + return errors.Wrap(err, "running npm install in kubernetes-sigs/release-notes") } // run npm prettier logrus.Info("Running npm prettier...") if err := command.NewWithWorkDir(repoPath, npmpath, "run", "prettier").RunSuccess(); err != nil { - return fmt.Errorf("running npm prettier in kubernetes-sigs/release-notes: %w", err) + return errors.Wrap(err, "running npm prettier in kubernetes-sigs/release-notes") } return nil @@ -644,13 +644,13 @@ func processJSONOutput(repoPath string) error { func createWebsitePR(repoPath, tag string) (err error) { _, err = util.TagStringToSemver(tag) if err != nil { - return fmt.Errorf("reading tag: %s: %w", tag, err) + return errors.Wrapf(err, "reading tag: %s", tag) } // Generate the release notes for ust the current tag jsonStr, err := releaseNotesJSON(repoPath, tag) if err != nil { - return fmt.Errorf("generating release notes in JSON format: %w", err) + return errors.Wrapf(err, "generating release notes in JSON format") } jsonNotesFilename := fmt.Sprintf("release-notes-%s.json", tag[1:]) @@ -662,17 +662,17 @@ func createWebsitePR(repoPath, tag string) (err error) { defaultKubernetesSigsRepo, releaseNotesOpts.githubOrg, releaseNotesOpts.websiteRepo, ) if err != nil { - return fmt.Errorf("preparing local fork branch: %w", err) + return errors.Wrap(err, "preparing local fork branch") } defer func() { if e := k8sSigsRepo.Cleanup(); e != nil { - err = fmt.Errorf("cleaning up k/sigs repo: %w", e) + err = errors.Wrap(e, "cleaning up k/sigs repo") } }() // add a reference to the new json file in assets.ts if err := addReferenceToAssetsFile(k8sSigsRepo.Dir(), jsonNotesFilename); err != nil { - return fmt.Errorf("adding %s to assets file: %w", jsonNotesFilename, err) + return errors.Wrapf(err, "adding %s to assets file", jsonNotesFilename) } // generate the notes @@ -681,31 +681,31 @@ func createWebsitePR(repoPath, tag string) (err error) { if err := os.WriteFile( filepath.Join(k8sSigsRepo.Dir(), jsonNotesPath), []byte(jsonStr), os.FileMode(0o644), ); err != nil { - return fmt.Errorf("writing release notes json file: %w", err) + return errors.Wrapf(err, "writing release notes json file") } // Run NPM prettier if err := processJSONOutput(k8sSigsRepo.Dir()); err != nil { - return fmt.Errorf("while formatting release notes JSON files: %w", err) + return errors.Wrap(err, "while formatting release notes JSON files") } // add the modified files & commit the results if err := k8sSigsRepo.Add(jsonNotesPath); err != nil { - return fmt.Errorf("adding release notes draft to staging area: %w", err) + return errors.Wrap(err, "adding release notes draft to staging area") } if err := k8sSigsRepo.Add(filepath.FromSlash(assetsFilePath)); err != nil { - return fmt.Errorf("adding release notes draft to staging area: %w", err) + return errors.Wrap(err, "adding release notes draft to staging area") } if err := k8sSigsRepo.UserCommit(fmt.Sprintf("Patch relnotes.k8s.io with release %s", tag)); err != nil { - return fmt.Errorf("error creating commit in %s/%s: %w", releaseNotesOpts.githubOrg, releaseNotesOpts.websiteRepo, err) + return errors.Wrapf(err, "Error creating commit in %s/%s", releaseNotesOpts.githubOrg, releaseNotesOpts.websiteRepo) } // push to the user's fork logrus.Infof("Pushing website changes to %s/%s", releaseNotesOpts.githubOrg, releaseNotesOpts.websiteRepo) if err := k8sSigsRepo.PushToRemote(userForkName, branchname); err != nil { - return fmt.Errorf("pushing %s to %s/%s: %w", userForkName, releaseNotesOpts.githubOrg, releaseNotesOpts.websiteRepo, err) + return errors.Wrapf(err, "pushing %s to %s/%s", userForkName, releaseNotesOpts.githubOrg, releaseNotesOpts.websiteRepo) } // Create a PR against k-sigs/release-notes using the github API @@ -726,7 +726,7 @@ func createWebsitePR(repoPath, tag string) (err error) { if err != nil { logrus.Warnf("An error has occurred while creating the pull request for %s", tag) logrus.Warn("While the PR failed, the release notes where generated and submitted to your fork") - return fmt.Errorf("creating the pull request: %w", err) + return errors.Wrap(err, "creating the pull request") } logrus.Infof( @@ -762,7 +762,7 @@ func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) { tagVersion, err := util.TagStringToSemver(tag) if err != nil { - return "", fmt.Errorf("parsing semver from tag string: %w", err) + return "", errors.Wrap(err, "parsing semver from tag string") } logrus.Info("Cloning kubernetes/sig-release to read mapping files") @@ -770,7 +770,7 @@ func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) { git.DefaultGithubOrg, git.DefaultGithubReleaseRepo, false, ) if err != nil { - return "", fmt.Errorf("performing clone of k/sig-release: %w", err) + return "", errors.Wrap(err, "performing clone of k/sig-release") } defer func() { if e := sigReleaseRepo.Cleanup(); e != nil { @@ -783,14 +783,14 @@ func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) { // Ensure we have a valid branch if !git.IsReleaseBranch(branchName) { - return "", errors.New("could not determine a release branch for tag") + return "", errors.New("Could not determine a release branch for tag") } // Preclone the repo to be able to read branches and tags logrus.Infof("Cloning %s/%s", git.DefaultGithubOrg, git.DefaultGithubRepo) repo, err := git.CloneOrOpenGitHubRepo(repoPath, git.DefaultGithubOrg, git.DefaultGithubRepo, false) if err != nil { - return "", fmt.Errorf("cloning default github repo: %w", err) + return "", errors.Wrap(err, "cloning default github repo") } // Chech if release branch already exists @@ -827,7 +827,7 @@ func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) { // All others from the previous existing tag startTag, err = repo.PreviousTag(tag, branchName) if err != nil { - return "", fmt.Errorf("getting previous tag from branch: %w", err) + return "", errors.Wrap(err, "getting previous tag from branch") } tagChoice = "previous tag" } @@ -863,14 +863,14 @@ func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) { // Fetch the notes releaseNotes, err := notes.GatherReleaseNotes(notesOptions) if err != nil { - return "", fmt.Errorf("gathering release notes: %w", err) + return "", errors.Wrapf(err, "gathering release notes") } doc, err := document.New( releaseNotes, notesOptions.StartRev, notesOptions.EndRev, ) if err != nil { - return "", fmt.Errorf("creating release note document: %w", err) + return "", errors.Wrapf(err, "creating release note document") } doc.PreviousRevision = startTag doc.CurrentRevision = tag @@ -878,7 +878,7 @@ func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) { // Create the JSON j, err := json.Marshal(releaseNotes.ByPR()) if err != nil { - return "", fmt.Errorf("generating release notes JSON: %w", err) + return "", errors.Wrapf(err, "generating release notes JSON") } return string(j), err @@ -908,7 +908,7 @@ func gatherNotesFrom(repoPath, startTag string) (*notes.ReleaseNotes, error) { // Fetch the notes releaseNotes, err := notes.GatherReleaseNotes(notesOptions) if err != nil { - return nil, fmt.Errorf("gathering release notes: %w", err) + return nil, errors.Wrapf(err, "gathering release notes") } return releaseNotes, nil @@ -919,7 +919,7 @@ func buildNotesResult(startTag string, releaseNotes *notes.ReleaseNotes) (*relea releaseNotes, startTag, releaseNotesOpts.tag, ) if err != nil { - return nil, fmt.Errorf("creating release note document: %w", err) + return nil, errors.Wrapf(err, "creating release note document") } doc.PreviousRevision = startTag doc.CurrentRevision = releaseNotesOpts.tag @@ -929,15 +929,15 @@ func buildNotesResult(startTag string, releaseNotes *notes.ReleaseNotes) (*relea "", "", "", options.GoTemplateDefault, ) if err != nil { - return nil, fmt.Errorf( - "rendering release notes to markdown: %w", err, + return nil, errors.Wrapf( + err, "rendering release notes to markdown", ) } // Create the JSON j, err := json.MarshalIndent(releaseNotes.ByPR(), "", " ") if err != nil { - return nil, fmt.Errorf("generating release notes JSON: %w", err) + return nil, errors.Wrapf(err, "generating release notes JSON") } return &releaseNotesResult{markdown: markdown, json: string(j)}, nil @@ -948,13 +948,13 @@ func (o *releaseNotesOptions) Validate() error { // Check that we have a GitHub token set token, isset := os.LookupEnv(github.TokenEnvKey) if !isset || token == "" { - return errors.New("cannot generate release notes if GitHub token is not set") + return errors.New("Cannot generate release notes if GitHub token is not set") } // If a tag is defined, see if it is a valid semver tag _, err := util.TagStringToSemver(releaseNotesOpts.tag) if err != nil { - return fmt.Errorf("reading tag: %s: %w", releaseNotesOpts.tag, err) + return errors.Wrapf(err, "reading tag: %s", releaseNotesOpts.tag) } // Options for PR creation @@ -978,13 +978,13 @@ func (sd *sessionData) Save() error { jsonData, err := json.MarshalIndent(sd, "", " ") if err != nil { - return fmt.Errorf("marshaling session data: %w", err) + return errors.Wrap(err, "marshaling session data") } if err := os.WriteFile( filepath.Join(sd.Path, fmt.Sprintf("maps-%d.json", sd.Date)), jsonData, os.FileMode(0o644)); err != nil { - return fmt.Errorf("writing session data to disk: %w", err) + return errors.Wrap(err, "writing session data to disk") } return nil } @@ -993,7 +993,7 @@ func (sd *sessionData) Save() error { func readFixSessions(sessionPath string) (pullRequestChecklist map[int]string, err error) { files, err := os.ReadDir(sessionPath) if err != nil { - return nil, fmt.Errorf("reading working directory: %w", err) + return nil, errors.Wrap(err, "reading working directory") } pullRequestList := make([]struct { Number int `json:"nr"` @@ -1007,10 +1007,10 @@ func readFixSessions(sessionPath string) (pullRequestChecklist map[int]string, e logrus.Debugf("Reading session data from %s", fileData.Name()) jsonData, err := os.ReadFile(filepath.Join(sessionPath, fileData.Name())) if err != nil { - return nil, fmt.Errorf("reading session data from %s: %w", fileData.Name(), err) + return nil, errors.Wrapf(err, "reading session data from %s", fileData.Name()) } if err := json.Unmarshal(jsonData, currentSession); err != nil { - return nil, fmt.Errorf("unmarshalling session data in %s: %w", fileData.Name(), err) + return nil, errors.Wrapf(err, "unmarshalling session data in %s", fileData.Name()) } pullRequestList = append(pullRequestList, currentSession.PullRequests...) } @@ -1030,11 +1030,11 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { // Get data to record the session userEmail, err := git.GetUserEmail() if err != nil { - return fmt.Errorf("getting local user's email: %w", err) + return errors.Wrap(err, "getting local user's email") } userName, err := git.GetUserName() if err != nil { - return fmt.Errorf("getting local user's name: %w", err) + return errors.Wrap(err, "getting local user's name") } // Check the workDir before going further @@ -1053,7 +1053,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { // Read the list of all PRs we've processed so far pullRequestChecklist, err := readFixSessions(filepath.Join(workDir, mapsSessionDirectory)) if err != nil { - return fmt.Errorf("reading previous session data: %w", err) + return errors.Wrapf(err, "reading previous session data") } // Greet the user with basic instructions @@ -1078,13 +1078,13 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { _, _, err = util.Ask("Press enter to start editing", "y:Y:yes|n:N:no|y", 10) } if err != nil { - return fmt.Errorf("asking to retrieve last session: %w", err) + return errors.Wrap(err, "asking to retrieve last session") } // Bring up the provider provider, err := notes.NewProviderFromInitString(workDir) if err != nil { - return fmt.Errorf("while getting map provider for current notes: %w", err) + return errors.Wrap(err, "while getting map provider for current notes") } const ( @@ -1096,7 +1096,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { contentHash, err := note.ContentHash() noteReviewed := false if err != nil { - return fmt.Errorf("getting the content hash for PR#%d: %w", pr, err) + return errors.Wrapf(err, "getting the content hash for PR#%d", pr) } // We'll skip editing if the Releas Note has been reviewed if _, ok := pullRequestChecklist[pr]; ok && @@ -1113,7 +1113,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { fmt.Printf("Pull Request URL: %skubernetes/kubernetes/pull/%d%s", github.GitHubURL, pr, nl) noteMaps, err := provider.GetMapsForPR(pr) if err != nil { - return fmt.Errorf("while getting map for PR #%d: %w", pr, err) + return errors.Wrapf(err, "while getting map for PR #%d", pr) } // Capture the original note values to compare @@ -1133,7 +1133,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { fmt.Println("✨ Note contents was previously modified with a map") for _, noteMap := range noteMaps { if err := note.ApplyMap(noteMap, true); err != nil { - return fmt.Errorf("applying notemap for PR #%d: %w", pr, err) + return errors.Wrapf(err, "applying notemap for PR #%d", pr) } } } @@ -1159,7 +1159,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { logrus.Info("Input cancelled, exiting edit flow") return nil } - return fmt.Errorf("while asking to edit release note: %w", err) + return errors.Wrap(err, "while asking to edit release note") } noteReviewed = true @@ -1177,7 +1177,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { "y:yes|n:no", 10, ) if err != nil { - return fmt.Errorf("while asking to re-edit release note: %w", err) + return errors.Wrap(err, "while asking to re-edit release note") } // If user chooses not to fix the faulty yaml, do not mark as fixed if !retryEditingChoice { @@ -1185,7 +1185,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { break } } else { - return fmt.Errorf("while editing release note: %w", err) + return errors.Wrap(err, "while editing release note") } } } @@ -1200,7 +1200,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { Hash: contentHash, }) if err := session.Save(); err != nil { - return fmt.Errorf("while saving editing session data: %w", err) + return errors.Wrap(err, "while saving editing session data") } } } @@ -1315,7 +1315,7 @@ func editReleaseNote(pr int, workDir string, originalNote, modifiedNote *notes.R // map with the original values yamlCode, err := yaml.Marshal(&unalteredFields) if err != nil { - return false, fmt.Errorf("marshalling release note to map: %w", err) + return false, errors.Wrap(err, "marshalling release note to map") } output += "# " + strings.ReplaceAll(string(yamlCode), "\n", "\n# ") } else { @@ -1323,12 +1323,12 @@ func editReleaseNote(pr int, workDir string, originalNote, modifiedNote *notes.R // values commented out for reference yamlCode, err := yaml.Marshal(&modifiedFields) if err != nil { - return false, fmt.Errorf("marshalling release note to map: %w", err) + return false, errors.Wrap(err, "marshalling release note to map") } unalteredYAML, err := yaml.Marshal(&unalteredFields.ReleaseNote) if err != nil { - return false, fmt.Errorf("marshalling release note to map: %w", err) + return false, errors.Wrap(err, "marshalling release note to map") } output += string(yamlCode) + " # " + strings.ReplaceAll(string(unalteredYAML), "\n", "\n # ") } @@ -1336,7 +1336,7 @@ func editReleaseNote(pr int, workDir string, originalNote, modifiedNote *notes.R kubeEditor := editor.NewDefaultEditor([]string{"KUBE_EDITOR", "EDITOR"}) changes, tempFilePath, err := kubeEditor.LaunchTempFile("release-notes-map-", ".yaml", bytes.NewReader([]byte(output))) if err != nil { - return false, fmt.Errorf("while launching editor: %w", err) + return false, errors.Wrap(err, "while launching editor") } defer func() { @@ -1375,18 +1375,18 @@ func editReleaseNote(pr int, workDir string, originalNote, modifiedNote *notes.R if err != nil { logrus.Error("The YAML code has errors") - return true, fmt.Errorf("while verifying if changes are a valid map: %w", err) + return true, errors.Wrap(err, "while verifying if changes are a valid map") } if testMap.PR == 0 { logrus.Error("The yaml code does not have a PR number") - return true, errors.New("invalid map: the YAML code did not have a PR number") + return true, errors.New("Invalid map: the YAML code did not have a PR number") } // Remarshall the newyaml to save only the new values newYAML, err := yaml.Marshal(testMap) if err != nil { - return true, fmt.Errorf("while re-marshaling new map: %w", err) + return true, errors.Wrap(err, "while re-marshaling new map") } // Write the new map, removing the instructions @@ -1394,7 +1394,7 @@ func editReleaseNote(pr int, workDir string, originalNote, modifiedNote *notes.R err = os.WriteFile(mapPath, newYAML, os.FileMode(0o644)) if err != nil { logrus.Errorf("Error writing map to %s: %s", mapPath, err) - return true, fmt.Errorf("writing modified release note map: %w", err) + return true, errors.Wrap(err, "writing modified release note map") } return false, nil @@ -1412,7 +1412,7 @@ func createNotesWorkDir(releaseDir string) error { } { if !util.Exists(dirPath) { if err := os.Mkdir(dirPath, os.FileMode(0o755)); err != nil { - return fmt.Errorf("creating working directory: %w", err) + return errors.Wrap(err, "creating working directory") } } } diff --git a/cmd/krel/cmd/testgrid.go b/cmd/krel/cmd/testgrid.go index 130bb3e1cf4..af7d5cffc77 100644 --- a/cmd/krel/cmd/testgrid.go +++ b/cmd/krel/cmd/testgrid.go @@ -19,7 +19,6 @@ package cmd import ( "context" "encoding/json" - "errors" "fmt" "net/url" "os" @@ -29,6 +28,7 @@ import ( "github.com/google/uuid" "github.com/mitchellh/mapstructure" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -118,7 +118,7 @@ func runTestGridShot(opts *TestGridOptions) error { logrus.Info("Starting krel testgrishot...") if err := opts.Validate(); err != nil { - return fmt.Errorf("validating testgridshot options: %w", err) + return errors.Wrap(err, "validating testgridshot options") } testgridJobs := []TestGridJob{} @@ -126,13 +126,15 @@ func runTestGridShot(opts *TestGridOptions) error { testGridDashboard := fmt.Sprintf("%s/sig-release-%s-%s/summary", opts.testgridURL, opts.branch, board) content, err := http.NewAgent().WithTimeout(30 * time.Second).Get(testGridDashboard) if err != nil { - return fmt.Errorf("unable to retrieve release announcement form url: %s: %w", testGridDashboard, err) + return errors.Wrapf(err, + "unable to retrieve release announcement form url: %s", testGridDashboard, + ) } var result map[string]interface{} err = json.Unmarshal(content, &result) if err != nil { - return fmt.Errorf("unable unmarshal the testgrid response: %w", err) + return errors.Wrap(err, "unable unmarshal the testgrid response") } testgridJobsTemp := []TestGridJob{} @@ -140,7 +142,7 @@ func runTestGridShot(opts *TestGridOptions) error { result := TestgridJobInfo{} err = mapstructure.Decode(jobData, &result) if err != nil { - return fmt.Errorf("decode testgrid data: %w", err) + return errors.Wrap(err, "decode testgrid data") } for _, state := range opts.states { @@ -158,13 +160,13 @@ func runTestGridShot(opts *TestGridOptions) error { dateNow := fmt.Sprintf("%s-%s", time.Now().UTC().Format(layoutISO), uuid.NewString()) testgridJobs, err = processDashboards(testgridJobs, dateNow, opts) if err != nil { - return fmt.Errorf("processing the dashboards: %w", err) + return errors.Wrap(err, "processing the dashboards") } } err := generateIssueComment(testgridJobs, opts) if err != nil { - return fmt.Errorf("generating the GitHub issue comment: %w", err) + return errors.Wrap(err, "generating the GitHub issue comment") } return nil @@ -178,19 +180,19 @@ func processDashboards(testgridJobs []TestGridJob, date string, opts *TestGridOp content, err := http.NewAgent().WithTimeout(300 * time.Second).Get(rendertronURL) if err != nil { - return testgridJobs, fmt.Errorf("failed to get the testgrid screenshot: %w", err) + return testgridJobs, errors.Wrapf(err, "failed to get the testgrid screenshot") } jobFile := fmt.Sprintf("/tmp/%s-%s-%s.jpg", job.DashboardName, strings.ReplaceAll(job.JobName, " ", "_"), job.Status) f, err := os.Create(jobFile) if err != nil { - return testgridJobs, fmt.Errorf("failed to create the file %s: %w", jobFile, err) + return testgridJobs, errors.Wrapf(err, "failed to create the file %s", jobFile) } _, err = f.Write(content) f.Close() if err != nil { - return testgridJobs, fmt.Errorf("failed to write the content to the file %s: %w", jobFile, err) + return testgridJobs, errors.Wrapf(err, "failed to write the content to the file %s", jobFile) } logrus.Infof("Screenshot saved for %s: %s", job.JobName, jobFile) @@ -198,10 +200,10 @@ func processDashboards(testgridJobs []TestGridJob, date string, opts *TestGridOp gcs := object.NewGCS() if err := gcs.CopyToRemote(jobFile, gcsPath); err != nil { - return testgridJobs, fmt.Errorf("failed to upload the file %s to GCS bucket %s: %w", jobFile, gcsPath, err) + return testgridJobs, errors.Wrapf(err, "failed to upload the file %s to GCS bucket %s", jobFile, gcsPath) } if err := os.Remove(jobFile); err != nil { - return testgridJobs, fmt.Errorf("remove jobfile: %w", err) + return testgridJobs, errors.Wrapf(err, "remove jobfile") } testgridJobs[i].GCSLocation = fmt.Sprintf("https://storage.googleapis.com/%s", gcsPath) logrus.Infof("Screenshot will be available for job %s at %s", job.JobName, testgridJobs[i].GCSLocation) @@ -252,7 +254,7 @@ func generateIssueComment(testgridJobs []TestGridJob, opts *TestGridOptions) err _, _, err := gh.Client().CreateComment(context.Background(), git.DefaultGithubOrg, k8sSigReleaseRepo, opts.gitHubIssue, strings.Join(output, "\n")) if err != nil { - return fmt.Errorf("creating the GitHub comment: %w", err) + return errors.Wrap(err, "creating the GitHub comment") } logrus.Infof("Comment created in the GitHub Issue https://github.com/%s/%s/issues/%d. Thanks for using krel!", git.DefaultGithubOrg, k8sSigReleaseRepo, opts.gitHubIssue) } else { @@ -301,17 +303,17 @@ func (o *TestGridOptions) Validate() error { issue, _, err := gh.Client().GetIssue(context.Background(), git.DefaultGithubOrg, k8sSigReleaseRepo, o.gitHubIssue) if err != nil || issue == nil { - return fmt.Errorf("getting the GitHub Issue %d: %w", o.gitHubIssue, err) + return errors.Wrapf(err, "getting the GitHub Issue %d", o.gitHubIssue) } // The issue needs to be in open state if issue.GetState() != "open" { - return fmt.Errorf("GitHub Issue %d is %s needs to be a open issue", o.gitHubIssue, issue.GetState()) + return errors.Errorf("GitHub Issue %d is %s needs to be a open issue", o.gitHubIssue, issue.GetState()) } // Should be a Issue and not a Pull Request if issue.PullRequestLinks != nil { - return errors.New("this is a Pull Request and not a GitHub Issue") + return errors.New("This is a Pull Request and not a GitHub Issue") } } diff --git a/cmd/krel/cmd/version.go b/cmd/krel/cmd/version.go index baef4633070..50099db0621 100644 --- a/cmd/krel/cmd/version.go +++ b/cmd/krel/cmd/version.go @@ -19,6 +19,7 @@ package cmd import ( "fmt" + "github.com/pkg/errors" "github.com/spf13/cobra" "k8s.io/release/pkg/version" @@ -54,7 +55,7 @@ func runVersion(opts *versionOptions) error { if opts.json { j, err := v.JSONString() if err != nil { - return fmt.Errorf("unable to generate JSON from version info: %w", err) + return errors.Wrap(err, "unable to generate JSON from version info") } res = j } diff --git a/cmd/kubepkg/cmd/root.go b/cmd/kubepkg/cmd/root.go index 3ac7ed2cc62..adcce92c081 100644 --- a/cmd/kubepkg/cmd/root.go +++ b/cmd/kubepkg/cmd/root.go @@ -19,6 +19,7 @@ package cmd import ( "fmt" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -157,7 +158,7 @@ func run(buildType options.BuildType) error { client := kubepkg.New(opts) builds, err := client.ConstructBuilds() if err != nil { - return fmt.Errorf("running kubepkg: %w", err) + return errors.Wrap(err, "running kubepkg") } return client.WalkBuilds(builds) } diff --git a/cmd/publish-release/cmd/github.go b/cmd/publish-release/cmd/github.go index 2fa5c2ae0a0..dc106afd35a 100644 --- a/cmd/publish-release/cmd/github.go +++ b/cmd/publish-release/cmd/github.go @@ -17,11 +17,11 @@ limitations under the License. package cmd import ( - "fmt" "os" "path/filepath" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "k8s.io/release/pkg/announce" @@ -197,7 +197,7 @@ func runGithubPage(opts *githubPageCmdLineOptions) (err error) { Tag: commandLineOpts.tag, }) if err != nil { - return fmt.Errorf("generating sbom: %w", err) + return errors.Wrap(err, "generating sbom") } opts.assets = append(opts.assets, sbom+":SPDX Software Bill of Materials (SBOM)") // Delete the temporary sbom when we're done @@ -219,22 +219,22 @@ func runGithubPage(opts *githubPageCmdLineOptions) (err error) { // Assign the repository data if err := announceOpts.SetRepository(opts.repo); err != nil { - return fmt.Errorf("assigning the repository slug: %w", err) + return errors.Wrap(err, "assigning the repository slug") } // Assign the substitutions if err := announceOpts.ParseSubstitutions(opts.substitutions); err != nil { - return fmt.Errorf("parsing template substitutions: %w", err) + return errors.Wrap(err, "parsing template substitutions") } // Read the csutom template data if err := announceOpts.ReadTemplate(opts.template); err != nil { - return fmt.Errorf("reading the template file: %w", err) + return errors.Wrap(err, "reading the template file") } // Validate the options if err := announceOpts.Validate(); err != nil { - return fmt.Errorf("validating options: %w", err) + return errors.Wrap(err, "validating options") } // Run the update process diff --git a/cmd/release-notes/main.go b/cmd/release-notes/main.go index 51f7470f1cc..80465b7af98 100644 --- a/cmd/release-notes/main.go +++ b/cmd/release-notes/main.go @@ -24,6 +24,7 @@ import ( "path/filepath" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -283,12 +284,12 @@ func WriteReleaseNotes(releaseNotes *notes.ReleaseNotes) (err error) { if releaseNotesOpts.outputFile != "" { output, err = os.OpenFile(releaseNotesOpts.outputFile, os.O_RDWR|os.O_CREATE, os.FileMode(0o644)) if err != nil { - return fmt.Errorf("opening the supplied output file: %w", err) + return errors.Wrapf(err, "opening the supplied output file") } } else { output, err = os.CreateTemp("", "release-notes-") if err != nil { - return fmt.Errorf("creating a temporary file to write the release notes to: %w", err) + return errors.Wrapf(err, "creating a temporary file to write the release notes to") } } @@ -301,7 +302,7 @@ func WriteReleaseNotes(releaseNotes *notes.ReleaseNotes) (err error) { if len(byteValue) > 0 { if err := json.Unmarshal(byteValue, &existingNotes); err != nil { - return fmt.Errorf("unmarshalling existing notes: %w", err) + return errors.Wrapf(err, "unmarshalling existing notes") } } @@ -324,17 +325,17 @@ func WriteReleaseNotes(releaseNotes *notes.ReleaseNotes) (err error) { enc := json.NewEncoder(output) enc.SetIndent("", " ") if err := enc.Encode(releaseNotes.ByPR()); err != nil { - return fmt.Errorf("encoding JSON output: %w", err) + return errors.Wrapf(err, "encoding JSON output") } } else { doc, err := document.New(releaseNotes, opts.StartRev, opts.EndRev) if err != nil { - return fmt.Errorf("creating release note document: %w", err) + return errors.Wrapf(err, "creating release note document") } markdown, err := doc.RenderMarkdownTemplate(opts.ReleaseBucket, opts.ReleaseTars, "", opts.GoTemplate) if err != nil { - return fmt.Errorf("rendering release note document with template: %w", err) + return errors.Wrapf(err, "rendering release note document with template") } const nl = "\n" @@ -347,7 +348,7 @@ func WriteReleaseNotes(releaseNotes *notes.ReleaseNotes) (err error) { url, opts.StartSHA, opts.EndSHA, ) if err != nil { - return fmt.Errorf("generating dependency report: %w", err) + return errors.Wrap(err, "generating dependency report") } markdown += strings.Repeat(nl, 2) + deps } @@ -360,13 +361,13 @@ func WriteReleaseNotes(releaseNotes *notes.ReleaseNotes) (err error) { MaxDepth: mdtoc.MaxHeaderDepth, }) if err != nil { - return fmt.Errorf("generating table of contents: %w", err) + return errors.Wrap(err, "generating table of contents") } markdown = toc + nl + markdown } if _, err := output.WriteString(markdown); err != nil { - return fmt.Errorf("writing output file: %w", err) + return errors.Wrap(err, "writing output file") } } @@ -377,7 +378,7 @@ func WriteReleaseNotes(releaseNotes *notes.ReleaseNotes) (err error) { func run(*cobra.Command, []string) error { releaseNotes, err := notes.GatherReleaseNotes(opts) if err != nil { - return fmt.Errorf("gathering release notes: %w", err) + return errors.Wrapf(err, "gathering release notes") } return WriteReleaseNotes(releaseNotes) diff --git a/cmd/schedule-builder/cmd/root.go b/cmd/schedule-builder/cmd/root.go index deb0bf48b8c..83dcefab45e 100644 --- a/cmd/schedule-builder/cmd/root.go +++ b/cmd/schedule-builder/cmd/root.go @@ -17,10 +17,10 @@ limitations under the License. package cmd import ( - "errors" "fmt" "os" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -111,13 +111,13 @@ func initLogging(*cobra.Command, []string) error { func run(opts *options) error { if err := opts.SetAndValidate(); err != nil { - return fmt.Errorf("validating schedule-path options: %w", err) + return errors.Wrap(err, "validating schedule-path options") } logrus.Infof("Reading the schedule file %s...", opts.configPath) data, err := os.ReadFile(opts.configPath) if err != nil { - return fmt.Errorf("failed to read the file: %w", err) + return errors.Wrap(err, "failed to read the file") } var ( @@ -131,7 +131,7 @@ func run(opts *options) error { switch opts.typeFile { case "patch": if err := yaml.UnmarshalStrict(data, &patchSchedule); err != nil { - return fmt.Errorf("failed to decode the file: %w", err) + return errors.Wrap(err, "failed to decode the file") } logrus.Info("Generating the markdown output...") @@ -139,7 +139,7 @@ func run(opts *options) error { case "release": if err := yaml.UnmarshalStrict(data, &releaseSchedule); err != nil { - return fmt.Errorf("failed to decode the file: %w", err) + return errors.Wrap(err, "failed to decode the file") } logrus.Info("Generating the markdown output...") @@ -155,7 +155,7 @@ func run(opts *options) error { // 0600 or less err := os.WriteFile(opts.outputFile, []byte(scheduleOut), 0o644) if err != nil { - return fmt.Errorf("failed to save schedule to the file: %w", err) + return errors.Wrap(err, "failed to save schedule to the file") } logrus.Info("File saved") } @@ -168,7 +168,7 @@ func (o *options) SetAndValidate() error { logrus.Info("Validating schedule-path options...") if o.configPath == "" { - return fmt.Errorf("need to set the config-path") + return errors.Errorf("need to set the config-path") } return nil diff --git a/go.mod b/go.mod index e9424ce6330..163ea669832 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/mitchellh/mapstructure v1.4.3 github.com/nozzle/throttler v0.0.0-20180817012639-2ea982251481 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/saschagrunert/go-modiff v1.3.0 github.com/sendgrid/rest v2.6.9+incompatible @@ -36,11 +37,11 @@ require ( golang.org/x/text v0.3.7 google.golang.org/api v0.66.0 gopkg.in/yaml.v2 v2.4.0 - sigs.k8s.io/bom v0.1.1-0.20211228172218-5dc67098b61b + sigs.k8s.io/bom v0.2.3-0.20220329054911-dcaf42546717 sigs.k8s.io/mdtoc v1.1.0 sigs.k8s.io/promo-tools/v3 v3.3.0 sigs.k8s.io/release-sdk v0.7.1-0.20220316205410-f3891f4abf58 - sigs.k8s.io/release-utils v0.5.0 + sigs.k8s.io/release-utils v0.6.0 sigs.k8s.io/yaml v1.3.0 sigs.k8s.io/zeitgeist v0.3.0 ) @@ -104,6 +105,7 @@ require ( github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490 // indirect github.com/cockroachdb/apd/v2 v2.0.1 // indirect + github.com/containerd/containerd v1.5.8 // indirect github.com/containerd/stargz-snapshotter/estargz v0.10.1 // indirect github.com/coreos/go-oidc/v3 v3.1.0 // indirect github.com/coreos/go-semver v0.3.0 // indirect @@ -116,6 +118,8 @@ require ( github.com/docker/distribution v2.8.0+incompatible // indirect github.com/docker/docker v20.10.12+incompatible // indirect github.com/docker/docker-credential-helpers v0.6.4 // indirect + github.com/docker/go-connections v0.4.0 // indirect + github.com/docker/go-units v0.4.0 // indirect github.com/dustin/go-humanize v1.0.0 // indirect github.com/emicklei/proto v1.6.15 // indirect github.com/emirpasic/gods v1.12.0 // indirect @@ -221,9 +225,9 @@ require ( github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.0.2 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/package-url/packageurl-go v0.1.1-0.20220203205134-d70459300c8a // indirect github.com/pelletier/go-toml v1.9.4 // indirect github.com/pierrec/lz4 v2.6.1+incompatible // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/prometheus/client_golang v1.11.0 // indirect diff --git a/go.sum b/go.sum index c3028374f6a..126f34d5cf5 100644 --- a/go.sum +++ b/go.sum @@ -31,7 +31,6 @@ cloud.google.com/go v0.83.0/go.mod h1:Z7MJUsANfY0pYPdw0lbnivPx4/vhy/e2FEkSkF7vAV cloud.google.com/go v0.84.0/go.mod h1:RazrYuxIK6Kb7YrzzhPoLmCVzl7Sup4NrbKPg8KHSUM= cloud.google.com/go v0.87.0/go.mod h1:TpDYlFy7vuLzZMMZ+B6iRiELaY7z/gJPaqbMx6mlWcY= cloud.google.com/go v0.90.0/go.mod h1:kRX0mNRHe0e2rC6oNakvwQqzyDmg57xJ+SZU1eT2aDQ= -cloud.google.com/go v0.92.1/go.mod h1:cMc7asehN84LBi1JGTHo4n8wuaGuNAZ7lR7b1YNJBrE= cloud.google.com/go v0.92.2/go.mod h1:8utlLll2EF5XMAV15woO4lSbWQlk8rer9aLOfLh7+YI= cloud.google.com/go v0.92.3/go.mod h1:8utlLll2EF5XMAV15woO4lSbWQlk8rer9aLOfLh7+YI= cloud.google.com/go v0.93.3/go.mod h1:8utlLll2EF5XMAV15woO4lSbWQlk8rer9aLOfLh7+YI= @@ -51,19 +50,15 @@ cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM7 cloud.google.com/go/compute v0.1.0/go.mod h1:GAesmwr110a34z04OlxYkATPBEfVhkymfTBXtfbBFow= cloud.google.com/go/compute v1.1.0 h1:pyPhehLfZ6pVzRgJmXGYvCY4K7WSWRhVw0AwhgVvS84= cloud.google.com/go/compute v1.1.0/go.mod h1:2NIffxgWfORSI7EOYMFatGTfjMLnqrOKBEyYb6NoRgA= -cloud.google.com/go/containeranalysis v0.1.0/go.mod h1:5sRtnKlcFzfRSArzgFEmrMCrAaR4pmjr+Sfn9A+PvoM= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/errorreporting v0.1.0/go.mod h1:cZSiBMvrnl0X13pD9DwKf9sQ8Eqy3EzHqkyKBZxiIrM= cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= cloud.google.com/go/firestore v1.6.1/go.mod h1:asNXNOzBdyVQmEU+ggO8UPodTkEVFW5Qx+rwHnAz+EY= -cloud.google.com/go/grafeas v0.0.0-20210817223811-71387f0142a4/go.mod h1:JIjQPjT5tO2IieDgcDyhc1AvplAIo+FyYSKg3OvITsE= cloud.google.com/go/iam v0.1.1 h1:4CapQyNFjiksks1/x7jsvsygFPhihslYk5GptIrlX68= cloud.google.com/go/iam v0.1.1/go.mod h1:CKqrcnI/suGpybEHxZ7BMehL0oA4LpdyJdUlTl9jVMw= cloud.google.com/go/kms v1.0.0/go.mod h1:nhUehi+w7zht2XrUfvTRNpxrfayBHqP4lu2NSywui/0= cloud.google.com/go/kms v1.1.0 h1:1yc4rLqCkVDS9Zvc7m+3mJ47kw0Uo5Q5+sMjcmUVUeM= cloud.google.com/go/kms v1.1.0/go.mod h1:WdbppnCDMDpOvoYBMn1+gNmOeEoZYqAv+HeuKARGCXI= -cloud.google.com/go/logging v1.4.2/go.mod h1:jco9QZSx8HiVVqLJReq7z7bVdj0P1Jb9PDFs63T+axo= cloud.google.com/go/monitoring v0.1.0/go.mod h1:Hpm3XfzJv+UTiXzCG5Ffp0wijzHTC7Cv4eR7o3x/fEE= cloud.google.com/go/monitoring v1.1.0/go.mod h1:L81pzz7HKn14QCMaCs6NTQkdBnE87TElyanS95vIcl4= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= @@ -213,7 +208,6 @@ github.com/Microsoft/hcsshim v0.8.9/go.mod h1:5692vkUqntj1idxauYlpoINNKeqCiG6Sg3 github.com/Microsoft/hcsshim v0.8.14/go.mod h1:NtVKoYxQuTLx6gEq0L96c9Ju4JbRJ4nY2ow3VK6a9Lg= github.com/Microsoft/hcsshim v0.8.15/go.mod h1:x38A4YbHbdxJtc0sF6oIz+RG0npwSCAvn69iY6URG00= github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+VxGOoXdC600= -github.com/Microsoft/hcsshim v0.8.21/go.mod h1:+w2gRZ5ReXQhFOrvSQeNfhrYB/dg3oDwTOcER2fw4I4= github.com/Microsoft/hcsshim v0.8.23/go.mod h1:4zegtUJth7lAvFyc6cH2gGQ5B3OFQim01nnU2M8jKDg= github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU= github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY= @@ -263,7 +257,6 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:CgnQgUtFrFz9mxFNtED3jI5tLDjKlOM+oUF/sTk6ps0= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= @@ -425,18 +418,15 @@ github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae/go.mod h1:S/7n9cop github.com/caarlos0/ctrlc v1.0.0/go.mod h1:CdXpj4rmq0q/1Eb44M9zi2nKB0QraNKuRGYGrrHhcQw= github.com/campoy/unique v0.0.0-20180121183637-88950e537e7e/go.mod h1:9IOqJGCPMSc6E5ydlp5NIonxObaeu/Iub/X03EKPVYo= github.com/carolynvs/magex v0.5.0/go.mod h1:i4bMWEmwGw2+W/u/0cEs5FTEyLtaN5DEKvVLV+KOEsc= -github.com/carolynvs/magex v0.6.0/go.mod h1:hqaEkr9TAv+kFb/5wgDiTdszF13rpe0Q+bWHmTe6N74= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/cavaliercoder/badio v0.0.0-20160213150051-ce5280129e9e/go.mod h1:V284PjgVwSk4ETmz84rpu9ehpGg7swlIH8npP9k2bGw= github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e/go.mod h1:oDpT4efm8tSYHXV5tHSdRvBet/b/QzxZ+XyyPehvm3A= github.com/cavaliercoder/go-rpm v0.0.0-20200122174316-8cb9fd9c31a8/go.mod h1:AZIh1CCnMrcVm6afFf96PBvE2MRpWFco91z8ObJtgDY= -github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/cenkalti/backoff/v3 v3.2.2 h1:cfUAAO3yvKMYKPrvhDuHSwQnhZNk/RMHKdZqKTxfm6M= github.com/cenkalti/backoff/v3 v3.2.2/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= -github.com/cenkalti/backoff/v4 v4.1.2/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.3.0 h1:t/LhUZLVitR1Ow2YOnduCsavhwFUklBMoGVYUCqmCqk= @@ -493,7 +483,6 @@ github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u9 github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE= github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4= -github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w= github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE= github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU= github.com/containerd/aufs v0.0.0-20210316121734-20793ff83c97/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj3gNv2PU= @@ -526,8 +515,7 @@ github.com/containerd/containerd v1.5.0-beta.1/go.mod h1:5HfvG1V2FsKesEGQ17k5/T7 github.com/containerd/containerd v1.5.0-beta.3/go.mod h1:/wr9AVtEM7x9c+n0+stptlo/uBBoBORwEx6ardVcmKU= github.com/containerd/containerd v1.5.0-beta.4/go.mod h1:GmdgZd2zA2GYIBZ0w09ZvgqEq8EfBp/m3lcVZIvPHhI= github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoTJseu1FGOKuoA4nNb2s= -github.com/containerd/containerd v1.5.1/go.mod h1:0DOxVqwDy2iZvrZp2JUx/E+hS0UNTVn7dJnIOwtYR4g= -github.com/containerd/containerd v1.5.7/go.mod h1:gyvv6+ugqY25TiXxcZC3L5yOeYgEw0QMhscqVp1AR9c= +github.com/containerd/containerd v1.5.8 h1:NmkCC1/QxyZFBny8JogwLpOy2f+VEbO/f6bV2Mqtwuw= github.com/containerd/containerd v1.5.8/go.mod h1:YdFSv5bTFLpG2HIYmfqDpSYYTDX+mc5qtSuYx1YUb/s= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= @@ -556,7 +544,6 @@ github.com/containerd/imgcrypt v1.1.1/go.mod h1:xpLnwiQmEUJPvQoAapeb2SNCxz7Xr6PJ github.com/containerd/nri v0.0.0-20201007170849-eb1350a75164/go.mod h1:+2wGSDGFYfE5+So4M5syatU0N0f0LbWpuqyMi4/BE8c= github.com/containerd/nri v0.0.0-20210316161719-dbaa18c31c14/go.mod h1:lmxnXF6oMkbqs39FiCt1s0R2HSMhcLel9vNL3m4AaeY= github.com/containerd/nri v0.1.0/go.mod h1:lmxnXF6oMkbqs39FiCt1s0R2HSMhcLel9vNL3m4AaeY= -github.com/containerd/stargz-snapshotter/estargz v0.10.0/go.mod h1:aE5PCyhFMwR8sbrErO5eM2GcvkyXTTJremG883D4qF0= github.com/containerd/stargz-snapshotter/estargz v0.10.1 h1:hd1EoVjI2Ax8Cr64tdYqnJ4i4pZU49FkEf5kU8KxQng= github.com/containerd/stargz-snapshotter/estargz v0.10.1/go.mod h1:aE5PCyhFMwR8sbrErO5eM2GcvkyXTTJremG883D4qF0= github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o= @@ -588,7 +575,6 @@ github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-iptables v0.4.5/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU= github.com/coreos/go-iptables v0.5.0/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU= -github.com/coreos/go-oidc v2.1.0+incompatible h1:sdJrfw8akMnCuUlaZU3tE/uYXFgfqom8DBE9so9EBsM= github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= github.com/coreos/go-oidc/v3 v3.1.0 h1:6avEvcdvTa1qYsOZ6I5PRkSYHzpTNWgKYmaJfaYbrRw= github.com/coreos/go-oidc/v3 v3.1.0/go.mod h1:rEJ/idjfUyfkBit1eI1fvyr+64/g9dcKpAm8MJMesvo= @@ -597,7 +583,6 @@ github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmf github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20161114122254-48702e0da86b/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= @@ -605,7 +590,6 @@ github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzA github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -650,7 +634,6 @@ github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQ github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= -github.com/docker/cli v20.10.10+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/cli v20.10.11+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/cli v20.10.12+incompatible h1:lZlz0uzG+GH+c0plStMUdF/qk3ppmgnswpR5EbqzVGA= github.com/docker/cli v20.10.12+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= @@ -659,25 +642,24 @@ github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.8.0+incompatible h1:l9EaZDICImO1ngI+uTifW+ZYvvz7fKISBAKpg+MbWbY= github.com/docker/distribution v2.8.0+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v20.10.10+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v20.10.11+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v20.10.12+incompatible h1:CEeNmFM0QZIsJCZKMkZx0ZcahTiewkrgiwfYD+dfl1U= github.com/docker/docker v20.10.12+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.6.3/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y= github.com/docker/docker-credential-helpers v0.6.4 h1:axCks+yV+2MR3/kZhAmy07yC56WZ2Pwu/fKWtKuZB0o= github.com/docker/docker-credential-helpers v0.6.4/go.mod h1:ofX3UI0Gz1TteYBjtgs07O36Pyasyp66D2uKT7H8W1c= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-events v0.0.0-20170721190031-9461782956ad/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA= github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA= github.com/docker/go-metrics v0.0.0-20180209012529-399ea8c73916/go.mod h1:/u0gXw0Gay3ceNrsHubL3BtdOL2fHf93USgMTe0W5dI= github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw= github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= -github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo= -github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -1097,7 +1079,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= -github.com/google/go-containerregistry v0.7.0/go.mod h1:2zaoelrL0d08gGbpdP3LqyUuBmhWbpD6IOe2s9nLS2k= github.com/google/go-containerregistry v0.7.1-0.20211118220127-abdc633f8305/go.mod h1:6cMIl1RfryEiPzBE67OgtZdEiLWz4myqCQIiBMy3CsM= github.com/google/go-containerregistry v0.8.0/go.mod h1:wW5v71NHGnQyb4k+gSshjxidrC7lN33MdWEn+Mz9TsI= github.com/google/go-containerregistry v0.8.1-0.20220110151055-a61fd0a8e2bb/go.mod h1:wW5v71NHGnQyb4k+gSshjxidrC7lN33MdWEn+Mz9TsI= @@ -1111,7 +1092,6 @@ github.com/google/go-github/v28 v28.1.1/go.mod h1:bsqJWQX05omyWVmc00nEUql9mhQyv3 github.com/google/go-github/v33 v33.0.0 h1:qAf9yP0qc54ufQxzwv+u9H0tiVOnPJxo0lI/JXqw3ZM= github.com/google/go-github/v33 v33.0.0/go.mod h1:GMdDnVZY/2TsWgp/lkYnpSAh6TrzhANBBwm6k6TTEXg= github.com/google/go-github/v39 v39.0.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE= -github.com/google/go-github/v39 v39.1.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE= github.com/google/go-github/v39 v39.2.0 h1:rNNM311XtPOz5rDdsJXAp2o8F67X9FnROXTvto3aSnQ= github.com/google/go-github/v39 v39.2.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE= github.com/google/go-github/v42 v42.0.0 h1:YNT0FwjPrEysRkLIiKuEfSvBPCGKphW5aS5PxwaoLec= @@ -1128,7 +1108,6 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/licenseclassifier v0.0.0-20210325184830-bb04aff29e72 h1:EfzlPF5MRmoWsCGvSkPZ1Nh9uVzHf4FfGnDQ6CXd2NA= github.com/google/licenseclassifier v0.0.0-20210325184830-bb04aff29e72/go.mod h1:qsqn2hxC+vURpyBRygGUuinTO42MFRLcsmQ/P8v94+M= github.com/google/licenseclassifier/v2 v2.0.0-alpha.1 h1:E0HY5OuFS3CQoVFAr1dabMFm4PyjNMbIB1zYulfwnRI= github.com/google/licenseclassifier/v2 v2.0.0-alpha.1/go.mod h1:YAgBGGTeNDMU+WfIgaFvjZe4rudym4f6nIn8ZH5X+VM= @@ -1152,12 +1131,10 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210506205249-923b5ab0fc1a/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210804190019-f964ff605595/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/rpmpack v0.0.0-20191226140753-aa36bfddb3a0/go.mod h1:RaTPr0KUf2K7fnZYLNDrr8rxAamWs3iNywJLtQ2AzBg= github.com/google/rpmpack v0.0.0-20210518075352-dc539ef4f2ea/go.mod h1:+y9lKiqDhR4zkLl+V9h4q0rdyrYVsWWm6LLCQP33DIk= @@ -1176,7 +1153,6 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/wire v0.3.0/go.mod h1:i1DMg/Lu8Sz5yYl25iOdmc5CT5qusaa+zmRWs16741s= github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU= -github.com/googleapis/gax-go v2.0.2+incompatible h1:silFMLAnr330+NRuag/VjIGF7TLp/LBrV2CJKFLWEww= github.com/googleapis/gax-go v2.0.2+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -1197,6 +1173,7 @@ github.com/gorilla/handlers v0.0.0-20150720190736-60c7bfde3e33/go.mod h1:Qkdc/uu github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= @@ -1404,7 +1381,6 @@ github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0 github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.13/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= @@ -1413,7 +1389,6 @@ github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQ github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= -github.com/klauspost/pgzip v1.2.4/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -1453,7 +1428,6 @@ github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc8 github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= -github.com/magefile/mage v1.12.1/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -1513,12 +1487,10 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5 github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0/go.mod h1:fcEyUyXZXoV4Abw8DX0t7wyL8mCDxXyU4iAFZfT3IHw= -github.com/maxbrunsfeld/counterfeiter/v6 v6.4.1/go.mod h1:DK1Cjkc0E49ShgRVs5jy5ASrM15svSnem3K/hiSGD8o= github.com/maxbrunsfeld/counterfeiter/v6 v6.5.0 h1:rBhB9Rls+yb8kA4x5a/cWxOufWfXt24E+kq4YlbGj3g= github.com/maxbrunsfeld/counterfeiter/v6 v6.5.0/go.mod h1:fJ0UAZc1fx3xZhU4eSHQDJ1ApFmTVhp5VTpV9tm2ogg= github.com/mediocregopher/radix/v4 v4.0.0/go.mod h1:ajchozX/6ELmydxWeWM6xCFHVpZ4+67LXHOTOVR0nCE= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= -github.com/mholt/archiver/v3 v3.5.0/go.mod h1:qqTTPUK/HZPFgFQ/TJ3BzvTpF/dPtFVJXdQbCmeMxwc= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.17/go.mod h1:WgzbA6oji13JREwiNsRDNfl7jYdPnmz+VEuLrA+/48M= github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= @@ -1584,6 +1556,7 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk= github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de h1:D5x39vF5KCwKQaw+OC9ZPiLVHXz3UFw2+psEX+gYcto= @@ -1610,7 +1583,6 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso= github.com/nozzle/throttler v0.0.0-20180817012639-2ea982251481 h1:Up6+btDp321ZG5/zdSLo48H9Iaq0UQGthrhWC6pCxzE= github.com/nozzle/throttler v0.0.0-20180817012639-2ea982251481/go.mod h1:yKZQO8QE2bHlgozqWDiRVqTFlLQSj30K/6SAK8EeYFw= -github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -1637,7 +1609,6 @@ github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISq github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -1648,11 +1619,8 @@ github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoT github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= -github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg= github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= -github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= -github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/open-policy-agent/opa v0.35.0 h1:wsXkq/3JJucRUN4h46pn9Zv6cC6fnHWrVxjgoykxM7o= github.com/open-policy-agent/opa v0.35.0/go.mod h1:xEmekKlk6/c+so5HF9wtPnGPXDfBuBsrMGhSHOHEF+U= @@ -1664,7 +1632,6 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8 github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.0/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= -github.com/opencontainers/image-spec v1.0.2-0.20210730191737-8e42a01fb1b7/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= @@ -1700,6 +1667,8 @@ github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJ github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= +github.com/package-url/packageurl-go v0.1.1-0.20220203205134-d70459300c8a h1:tkTSd1nhioPqi5Whu3CQ79UjPtaGOytqyNnSCVOqzHM= +github.com/package-url/packageurl-go v0.1.1-0.20220203205134-d70459300c8a/go.mod h1:uQd4a7Rh3ZsVg5j0lNyAfyxIeGde9yrlhjF78GzeW0c= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= @@ -1722,7 +1691,6 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= -github.com/pierrec/lz4/v4 v4.0.3/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -1819,12 +1787,11 @@ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= +github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.0/go.mod h1:EBwu+T5AvHOcXwvZIkQFjUN6s8Czyqw12GL/Y0tUyRM= github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -1866,7 +1833,6 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shibumi/go-pathspec v1.3.0 h1:QUyMZhFo0Md5B8zV8x2tesohbb5kfbpTi9rBnKh5dkI= github.com/shibumi/go-pathspec v1.3.0/go.mod h1:Xutfslp817l2I1cZvgcfeMQJG5QnU2lh5tVaaMCl3jE= -github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada h1:WokF3GuxBeL+n4Lk4Fa8v9mbdjlrl7bHuneF4N1bk2I= github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc= github.com/shirou/gopsutil/v3 v3.22.2 h1:wCrArWFkHYIdDxx/FSfF5RB4dpJYW6t7rcp3+zL8uks= github.com/shirou/gopsutil/v3 v3.22.2/go.mod h1:WapW1AOOPlHyXr+yOyw3uYx36enocrtSoSBy0L5vUHY= @@ -2114,7 +2080,6 @@ go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= -go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489 h1:1JFLBqwIgdyHN1ZtgjTBwO+blA6gVOmZurpiMEsETKo= go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489/go.mod h1:yVHk9ub3CSBatqGNg7GRmsnfLWtoW60w4eDYfh7vHDg= go.etcd.io/etcd/api/v3 v3.5.0-alpha.0/go.mod h1:mPcW6aZJukV6Aa81LSKpBjQXTWlXB5r74ymPoSWa3Sw= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= @@ -2388,7 +2353,6 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= -golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= @@ -2402,7 +2366,6 @@ golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211111083644-e5c967477495/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211111160137-58aab5ef257a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211208012354-db4efeb81f4b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -2872,7 +2835,6 @@ google.golang.org/genproto v0.0.0-20211018162055-cf77aa76bad2/go.mod h1:5CzLGKJ6 google.golang.org/genproto v0.0.0-20211019152133-63b7e35f4404/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211021150943-2b146023228c/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211028162531-8db9c33dc351/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20211111162719-482062a4217b/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211203200212-54befc351ae9/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= @@ -3063,7 +3025,6 @@ k8s.io/utils v0.0.0-20210305010621-2afb4311ab10/go.mod h1:jPW/WVKK9YHAvNhRxK0md/ k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20211208161948-7d6a63dca704 h1:ZKMMxTvduyf5WUtREOqg5LiXaN1KO/+0oOQPRFrClpo= k8s.io/utils v0.0.0-20211208161948-7d6a63dca704/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= knative.dev/hack v0.0.0-20220118141833-9b2ed8471e30/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI= @@ -3081,19 +3042,17 @@ rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.15/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.22/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg= -sigs.k8s.io/bom v0.1.1-0.20211228172218-5dc67098b61b h1:vkNkvRFjPNf2+L7LqtjJlWyetpkEEvAyQSX7JtpiWMk= -sigs.k8s.io/bom v0.1.1-0.20211228172218-5dc67098b61b/go.mod h1:E1z8SFpPC9+z+Fr1UNMI8ymMUPk//aFX3HKNyBcYZL0= +sigs.k8s.io/bom v0.2.3-0.20220329054911-dcaf42546717 h1:ba9jW4+lVQUgGyDZcsAdJ04PzUJ5pyjtvtOt3IWMk3U= +sigs.k8s.io/bom v0.2.3-0.20220329054911-dcaf42546717/go.mod h1:K6mztJXqrFL7s7u0iCadPNdSpQo7IGYzhUUyuFzwwvs= sigs.k8s.io/mdtoc v1.1.0 h1:q3YtqYzmC2e0hgLXRIOm7/QLuPux1CX3ZHCwlbABxZo= sigs.k8s.io/mdtoc v1.1.0/go.mod h1:QZLVEdHH2iNIR4uHAZyvFRtjloHgVItk8lo/mzCtq3w= sigs.k8s.io/promo-tools/v3 v3.3.0 h1:lpXFhB1+fM1/uOmXehhl72JqoK66o4aowGsOIO5irRQ= sigs.k8s.io/promo-tools/v3 v3.3.0/go.mod h1:hGHcj+AuxenaCG6sI76p9KKUSijlyNjv4X8MULS1yeA= -sigs.k8s.io/release-sdk v0.5.0/go.mod h1:m7EwAKZb9Hua+b8pXnJLMJ/5WY/Fs1CeqxBZYXx0u0A= sigs.k8s.io/release-sdk v0.7.1-0.20220316205410-f3891f4abf58 h1:bcijRfqMJNmPkkcBIqJj5+cZUeZDmc+UhASrWV9xMOw= sigs.k8s.io/release-sdk v0.7.1-0.20220316205410-f3891f4abf58/go.mod h1:W1W+PA1Sxjj8PqkVEklvWaY85VCiUCUcD1/pXuR/YkQ= sigs.k8s.io/release-utils v0.2.0/go.mod h1:9O5livl2h3Q56jUkoZ7UnV22XVRB6MuD4l/51C2vAPg= -sigs.k8s.io/release-utils v0.3.0/go.mod h1:J9xpziRNRI4mAeMZxPRryDodQMoMudMu6yC1aViFHU4= -sigs.k8s.io/release-utils v0.5.0 h1:TVJUoFLjfYYdJ11+mIw6eb44XIOC5BI3QQKiKYCtk/8= -sigs.k8s.io/release-utils v0.5.0/go.mod h1:t9pL38kZkTBVDcjL1y7ajrkNQFLiArVAjOVO0sxzFF0= +sigs.k8s.io/release-utils v0.6.0 h1:wJDuzWJqPH4a5FAxAXE2aBvbB6UMIW7iYMhsKnIMQkA= +sigs.k8s.io/release-utils v0.6.0/go.mod h1:kR1/DuYCJ4covppUasYNcA11OixC9O37B/E0ejRfb+c= sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= sigs.k8s.io/structured-merge-diff/v4 v4.0.3/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4= diff --git a/hack/verify-go-mod.sh b/hack/verify-go-mod.sh index 229f1343f79..b704ad70705 100755 --- a/hack/verify-go-mod.sh +++ b/hack/verify-go-mod.sh @@ -18,5 +18,5 @@ set -o errexit set -o nounset set -o pipefail -go mod tidy +go mod tidy -compat=1.17 git diff --exit-code diff --git a/pkg/anago/anago.go b/pkg/anago/anago.go index 9a16d597dda..f92713b33b3 100644 --- a/pkg/anago/anago.go +++ b/pkg/anago/anago.go @@ -17,11 +17,11 @@ limitations under the License. package anago import ( - "errors" "fmt" "time" "github.com/blang/semver" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/release" @@ -96,17 +96,17 @@ func (o *Options) Validate(state *State) error { o.ReleaseType != release.ReleaseTypeBeta && o.ReleaseType != release.ReleaseTypeRC && o.ReleaseType != release.ReleaseTypeOfficial { - return fmt.Errorf("invalid release type: %s", o.ReleaseType) + return errors.Errorf("invalid release type: %s", o.ReleaseType) } if !git.IsReleaseBranch(o.ReleaseBranch) { - return fmt.Errorf("invalid release branch: %s", o.ReleaseBranch) + return errors.Errorf("invalid release branch: %s", o.ReleaseBranch) } // Verify the build version is correct: correct, err := release.IsValidReleaseBuild(o.BuildVersion) if err != nil { - return fmt.Errorf("checking for a valid build version: %w", err) + return errors.Wrap(err, "checking for a valid build version") } if !correct { return errors.New("invalid BuildVersion specified") @@ -114,7 +114,7 @@ func (o *Options) Validate(state *State) error { semverBuildVersion, err := util.TagStringToSemver(o.BuildVersion) if err != nil { - return fmt.Errorf("invalid build version: %s: %w", o.BuildVersion, err) + return errors.Wrapf(err, "invalid build version: %s", o.BuildVersion) } state.semverBuildVersion = semverBuildVersion @@ -206,7 +206,7 @@ func (s *StageOptions) String() string { // Validate if the options are correctly set. func (s *StageOptions) Validate(state *State) error { if err := s.Options.Validate(state); err != nil { - return fmt.Errorf("validating generic options: %w", err) + return errors.Wrap(err, "validating generic options") } return nil } @@ -230,7 +230,7 @@ func (s *Stage) SetClient(client stageClient) { func (s *Stage) Submit(stream bool) error { logrus.Info("Submitting stage GCB job") if err := s.client.Submit(stream); err != nil { - return fmt.Errorf("submit stage job: %w", err) + return errors.Wrap(err, "submit stage job") } return nil } @@ -241,7 +241,7 @@ func (s *Stage) Run() error { s.client.InitState() if err := s.client.InitLogFile(); err != nil { - return fmt.Errorf("init log file: %w", err) + return errors.Wrap(err, "init log file") } logger := log.NewStepLogger(11) @@ -249,57 +249,57 @@ func (s *Stage) Run() error { logger.WithStep().Info("Validating options") if err := s.client.ValidateOptions(); err != nil { - return fmt.Errorf("validate options: %w", err) + return errors.Wrap(err, "validate options") } logger.WithStep().Info("Checking prerequisites") if err := s.client.CheckPrerequisites(); err != nil { - return fmt.Errorf("check prerequisites: %w", err) + return errors.Wrap(err, "check prerequisites") } logger.WithStep().Info("Checking release branch state") if err := s.client.CheckReleaseBranchState(); err != nil { - return fmt.Errorf("check release branch state: %w", err) + return errors.Wrap(err, "check release branch state") } logger.WithStep().Info("Generating release version") if err := s.client.GenerateReleaseVersion(); err != nil { - return fmt.Errorf("generate release version: %w", err) + return errors.Wrap(err, "generate release version") } logger.WithStep().Info("Preparing workspace") if err := s.client.PrepareWorkspace(); err != nil { - return fmt.Errorf("prepare workspace: %w", err) + return errors.Wrap(err, "prepare workspace") } logger.WithStep().Info("Tagging repository") if err := s.client.TagRepository(); err != nil { - return fmt.Errorf("tag repository: %w", err) + return errors.Wrap(err, "tag repository") } logger.WithStep().Info("Building release") if err := s.client.Build(); err != nil { - return fmt.Errorf("build release: %w", err) + return errors.Wrap(err, "build release") } logger.WithStep().Info("Generating changelog") if err := s.client.GenerateChangelog(); err != nil { - return fmt.Errorf("generate changelog: %w", err) + return errors.Wrap(err, "generate changelog") } logger.WithStep().Info("Verifying artifacts") if err := s.client.VerifyArtifacts(); err != nil { - return fmt.Errorf("verifying artifacts: %w", err) + return errors.Wrap(err, "verifying artifacts") } logger.WithStep().Info("Generating bill of materials") if err := s.client.GenerateBillOfMaterials(); err != nil { - return fmt.Errorf("generating sbom: %w", err) + return errors.Wrap(err, "generating sbom") } logger.WithStep().Info("Staging artifacts") if err := s.client.StageArtifacts(); err != nil { - return fmt.Errorf("stage release artifacts: %w", err) + return errors.Wrap(err, "stage release artifacts") } logger.Info("Stage done") @@ -338,7 +338,7 @@ func (r *ReleaseOptions) String() string { // Validate if the options are correctly set. func (r *ReleaseOptions) Validate(state *State) error { if err := r.Options.Validate(state); err != nil { - return fmt.Errorf("validating generic options: %w", err) + return errors.Wrap(err, "validating generic options") } return nil } @@ -362,7 +362,7 @@ func (r *Release) SetClient(client releaseClient) { func (r *Release) Submit(stream bool) error { logrus.Info("Submitting release GCB job") if err := r.client.Submit(stream); err != nil { - return fmt.Errorf("submit release job: %w", err) + return errors.Wrap(err, "submit release job") } return nil } @@ -372,7 +372,7 @@ func (r *Release) Run() error { r.client.InitState() if err := r.client.InitLogFile(); err != nil { - return fmt.Errorf("init log file: %w", err) + return errors.Wrap(err, "init log file") } logger := log.NewStepLogger(11) @@ -380,59 +380,59 @@ func (r *Release) Run() error { logger.WithStep().Info("Validating options") if err := r.client.ValidateOptions(); err != nil { - return fmt.Errorf("validate options: %w", err) + return errors.Wrap(err, "validate options") } logger.WithStep().Info("Checking prerequisites") if err := r.client.CheckPrerequisites(); err != nil { - return fmt.Errorf("check prerequisites: %w", err) + return errors.Wrap(err, "check prerequisites") } logger.WithStep().Info("Checking release branch state") if err := r.client.CheckReleaseBranchState(); err != nil { - return fmt.Errorf("check release branch state: %w", err) + return errors.Wrap(err, "check release branch state") } logger.WithStep().Info("Generating release version") if err := r.client.GenerateReleaseVersion(); err != nil { - return fmt.Errorf("generate release version: %w", err) + return errors.Wrap(err, "generate release version") } logger.WithStep().Info("Preparing workspace") if err := r.client.PrepareWorkspace(); err != nil { - return fmt.Errorf("prepare workspace: %w", err) + return errors.Wrap(err, "prepare workspace") } logger.WithStep().Info("Checking artifacts provenance") if err := r.client.CheckProvenance(); err != nil { // For now, we ony notify provenance errors as not to treat // them as fatal while we finish testing SLSA compliance. - logrus.Warnf("Checking provenance attestation: %v", err) + logrus.Warn(errors.Wrap(err, "checking provenance attestation")) } logger.WithStep().Info("Pushing artifacts") if err := r.client.PushArtifacts(); err != nil { - return fmt.Errorf("push artifacts: %w", err) + return errors.Wrap(err, "push artifacts") } logger.WithStep().Info("Pushing git objects") if err := r.client.PushGitObjects(); err != nil { - return fmt.Errorf("push git objects: %w", err) + return errors.Wrap(err, "push git objects") } logger.WithStep().Info("Creating announcement") if err := r.client.CreateAnnouncement(); err != nil { - return fmt.Errorf("create announcement: %w", err) + return errors.Wrap(err, "create announcement") } logger.WithStep().Info("Updating GitHub release page") if err := r.client.UpdateGitHubPage(); err != nil { - return fmt.Errorf("updating github page: %w", err) + return errors.Wrap(err, "updating github page") } logger.WithStep().Info("Archiving release") if err := r.client.Archive(); err != nil { - return fmt.Errorf("archive release: %w", err) + return errors.Wrap(err, "archive release") } logger.Info("Release done") diff --git a/pkg/anago/release.go b/pkg/anago/release.go index ef6e0f76447..dc60b9a152c 100644 --- a/pkg/anago/release.go +++ b/pkg/anago/release.go @@ -22,6 +22,7 @@ import ( "path/filepath" "github.com/blang/semver" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/announce" @@ -249,7 +250,7 @@ func (d *DefaultRelease) InitLogFile() error { ) logFile := filepath.Join(os.TempDir(), "release.log") if err := d.impl.ToFile(logFile); err != nil { - return fmt.Errorf("setup log file: %w", err) + return errors.Wrap(err, "setup log file") } d.state.logFile = logFile logrus.Infof("Additionally logging to file %s", d.state.logFile) @@ -284,7 +285,7 @@ func (d *defaultReleaseImpl) PushBranches( func (d *defaultReleaseImpl) PushMainBranch(pusher *release.GitObjectPusher) error { if err := pusher.PushMain(); err != nil { - return fmt.Errorf("pushing changes in main branch: %w", err) + return errors.Wrap(err, "pushing changes in main branch") } return nil } @@ -319,14 +320,14 @@ func (d *defaultReleaseImpl) NewGitPusher( ) (pusher *release.GitObjectPusher, err error) { pusher, err = release.NewGitPusher(opts) if err != nil { - return nil, fmt.Errorf("creating new git object pusher: %w", err) + return nil, errors.Wrap(err, "creating new git object pusher") } return pusher, nil } func (d *DefaultRelease) ValidateOptions() error { if err := d.options.Validate(d.state.State); err != nil { - return fmt.Errorf("validating options: %w", err) + return errors.Wrap(err, "validating options") } return nil } @@ -342,7 +343,7 @@ func (d *DefaultRelease) CheckReleaseBranchState() error { d.state.semverBuildVersion, ) if err != nil { - return fmt.Errorf("check if release branch needs creation: %w", err) + return errors.Wrap(err, "check if release branch needs creation") } d.state.createReleaseBranch = createReleaseBranch return nil @@ -356,7 +357,7 @@ func (d *DefaultRelease) GenerateReleaseVersion() error { d.state.createReleaseBranch, ) if err != nil { - return fmt.Errorf("generating versions for release: %w", err) + return errors.Wrap(err, "generating versions for release") } // Set the versions object in the state d.state.versions = versions @@ -367,7 +368,7 @@ func (d *DefaultRelease) PrepareWorkspace() error { if err := d.impl.PrepareWorkspaceRelease( d.options.BuildVersion, d.options.Bucket(), ); err != nil { - return fmt.Errorf("prepare workspace: %w", err) + return errors.Wrap(err, "prepare workspace") } return nil } @@ -391,13 +392,13 @@ func (d *DefaultRelease) PushArtifacts() error { ValidateRemoteImageDigests: true, } if err := d.impl.CheckReleaseBucket(pushBuildOptions); err != nil { - return fmt.Errorf("check release bucket access: %w", err) + return errors.Wrap(err, "check release bucket access") } if err := d.impl.CopyStagedFromGCS( pushBuildOptions, bucket, d.options.BuildVersion, ); err != nil { - return fmt.Errorf("copy staged from GCS: %w", err) + return errors.Wrap(err, "copy staged from GCS") } // In an official nomock release, we want to ensure that container @@ -413,13 +414,13 @@ func (d *DefaultRelease) PushArtifacts() error { if err := d.impl.ValidateImages( targetRegistry, version, buildDir, ); err != nil { - return fmt.Errorf("validate container images: %w", err) + return errors.Wrap(err, "validate container images") } if err := d.impl.PublishVersion( "release", version, buildDir, bucket, gcsRoot, nil, false, false, ); err != nil { - return fmt.Errorf("publish release: %w", err) + return errors.Wrap(err, "publish release") } } @@ -430,7 +431,7 @@ func (d *DefaultRelease) PushArtifacts() error { objStore, d.options.Bucket(), gcsRoot, ) if err != nil { - return fmt.Errorf("get GCS release root path: %w", err) + return errors.Wrap(err, "get GCS release root path") } gcsReleaseNotesPath := gcsReleaseRootPath + fmt.Sprintf( @@ -442,7 +443,7 @@ func (d *DefaultRelease) PushArtifacts() error { releaseNotesJSONFile, gcsReleaseNotesPath, ); err != nil { - return fmt.Errorf("copy release notes to bucket: %w", err) + return errors.Wrap(err, "copy release notes to bucket") } for _, version := range d.state.versions.Ordered() { @@ -453,7 +454,7 @@ func (d *DefaultRelease) PushArtifacts() error { "/%s/provenance.json", version, ), ); err != nil { - return fmt.Errorf("copying provenance data to release bucket: %w", err) + return errors.Wrap(err, "copying provenance data to release bucket") } } @@ -461,7 +462,7 @@ func (d *DefaultRelease) PushArtifacts() error { if err := d.impl.PublishReleaseNotesIndex( gcsReleaseRootPath, gcsReleaseNotesPath, d.state.versions.Prime(), ); err != nil { - return fmt.Errorf("publish release notes index: %w", err) + return errors.Wrap(err, "publish release notes index") } return nil @@ -479,14 +480,14 @@ func (d *DefaultRelease) PushGitObjects() error { RepoPath: gitRoot, }) if err != nil { - return fmt.Errorf("getting git pusher from the release implementation: %w", err) + return errors.Wrap(err, "getting git pusher from the release implementation") } // The list of tags to be pushed to the remote repository. // These come from the versions object created during // GenerateReleaseVersion() if err := d.impl.PushTags(pusher, d.state.versions.Ordered()); err != nil { - return fmt.Errorf("pushing release tags: %w", err) + return errors.Wrap(err, "pushing release tags") } // Determine which branches have to be pushed, except main @@ -498,13 +499,13 @@ func (d *DefaultRelease) PushGitObjects() error { // Call the release imprementation PushBranches() method if err := d.impl.PushBranches(pusher, branchList); err != nil { - return fmt.Errorf("pushing branches to the remote repository: %w", err) + return errors.Wrap(err, "pushing branches to the remote repository") } // For files created on master with new branches and // for $CHANGELOG_FILEPATH, update the main branch if err := d.impl.PushMainBranch(pusher); err != nil { - return fmt.Errorf("pushing changes in main branch: %w", err) + return errors.Wrap(err, "pushing changes in main branch") } logrus.Infof( @@ -525,7 +526,7 @@ func (d *DefaultRelease) CreateAnnouncement() error { // Get a semver from the prime tag primeSemver, err := util.TagStringToSemver(d.state.versions.Prime()) if err != nil { - return fmt.Errorf("parsing prime version into semver: %w", err) + return errors.Wrap(err, "parsing prime version into semver") } // The main tag we are releasing @@ -541,7 +542,7 @@ func (d *DefaultRelease) CreateAnnouncement() error { // Run the annoucement creation if err := d.impl.CreateAnnouncement(announceOpts); err != nil { - return fmt.Errorf("creating the announcement: %w", err) + return errors.Wrap(err, "creating the announcement") } // Check if we are releasing is the initial minor (eg 1.20.0), @@ -604,7 +605,7 @@ func (d *DefaultRelease) UpdateGitHubPage() error { } // Update the release page (or simply output it during mock) if err := d.impl.UpdateGitHubPage(ghPageOpts); err != nil { - return fmt.Errorf("updating GitHub release page: %w", err) + return errors.Wrap(err, "updating GitHub release page") } return nil } @@ -622,7 +623,7 @@ func (d *DefaultRelease) Archive() error { } if err := d.impl.ArchiveRelease(archiverOptions); err != nil { - return fmt.Errorf("running the release archival process: %w", err) + return errors.Wrap(err, "running the release archival process") } args := "" @@ -651,12 +652,12 @@ func (d *defaultReleaseImpl) CheckStageProvenance(bucket, buildVersion string, v }) if err := checker.CheckStageProvenance(buildVersion); err != nil { - return fmt.Errorf("checking provenance of staged artifacts: %w", err) + return errors.Wrap(err, "checking provenance of staged artifacts") } // Write the final, end-user attestations if err := checker.GenerateFinalAttestation(buildVersion, versions); err != nil { - return fmt.Errorf("generating final SLSA attestations: %w", err) + return errors.Wrap(err, "generating final SLSA attestations") } return nil diff --git a/pkg/anago/stage.go b/pkg/anago/stage.go index fd84667b29f..e57a8fba90c 100644 --- a/pkg/anago/stage.go +++ b/pkg/anago/stage.go @@ -26,6 +26,7 @@ import ( "github.com/blang/semver" intoto "github.com/in-toto/in-toto-golang/in_toto" slsa "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/v0.2" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/build" @@ -330,7 +331,7 @@ func (d *defaultStageImpl) VerifyArtifacts(versions []string) error { // Ensure binaries are of the correct architecture if err := checker.CheckBinaryArchitectures(); err != nil { - return fmt.Errorf("checking binary architectures: %w", err) + return errors.Wrap(err, "checking binary architectures") } return nil @@ -342,7 +343,7 @@ func (d *DefaultStage) InitLogFile() error { ) logFile := filepath.Join(os.TempDir(), "stage.log") if err := d.impl.ToFile(logFile); err != nil { - return fmt.Errorf("setup log file: %w", err) + return errors.Wrap(err, "setup log file") } d.state.logFile = logFile logrus.Infof("Additionally logging to file %s", d.state.logFile) @@ -355,7 +356,7 @@ func (d *DefaultStage) InitState() { func (d *DefaultStage) ValidateOptions() error { if err := d.options.Validate(d.state.State); err != nil { - return fmt.Errorf("validating options: %w", err) + return errors.Wrap(err, "validating options") } return nil } @@ -371,7 +372,7 @@ func (d *DefaultStage) CheckReleaseBranchState() error { d.state.semverBuildVersion, ) if err != nil { - return fmt.Errorf("check if release branch needs creation: %w", err) + return errors.Wrap(err, "check if release branch needs creation") } d.state.createReleaseBranch = createReleaseBranch return nil @@ -385,7 +386,7 @@ func (d *DefaultStage) GenerateReleaseVersion() error { d.state.createReleaseBranch, ) if err != nil { - return fmt.Errorf("generating release versions for stage: %w", err) + return errors.Wrap(err, "generating release versions for stage") } // Set the versions on the state d.state.versions = versions @@ -394,7 +395,7 @@ func (d *DefaultStage) GenerateReleaseVersion() error { func (d *DefaultStage) PrepareWorkspace() error { if err := d.impl.PrepareWorkspaceStage(d.options.NoMock); err != nil { - return fmt.Errorf("prepare workspace: %w", err) + return errors.Wrap(err, "prepare workspace") } return nil } @@ -402,7 +403,7 @@ func (d *DefaultStage) PrepareWorkspace() error { func (d *DefaultStage) TagRepository() error { repo, err := d.impl.OpenRepo(gitRoot) if err != nil { - return fmt.Errorf("open Kubernetes repository: %w", err) + return errors.Wrap(err, "open Kubernetes repository") } for _, version := range d.state.versions.Ordered() { @@ -410,7 +411,7 @@ func (d *DefaultStage) TagRepository() error { // Ensure that the tag not already exists if _, err := d.impl.RevParseTag(repo, version); err == nil { - return fmt.Errorf("tag %s already exists", version) + return errors.Errorf("tag %s already exists", version) } // Usually the build version contains a commit we can reference. If @@ -433,7 +434,7 @@ func (d *DefaultStage) TagRepository() error { if err := d.impl.Checkout( repo, "-b", d.options.ReleaseBranch, commit, ); err != nil { - return fmt.Errorf("create new release branch: %w", err) + return errors.Wrap(err, "create new release branch") } } else { logrus.Infof( @@ -441,13 +442,13 @@ func (d *DefaultStage) TagRepository() error { version, git.DefaultBranch, ) if err := d.impl.Checkout(repo, git.DefaultBranch); err != nil { - return fmt.Errorf("checkout %s branch: %w", git.DefaultBranch, err) + return errors.Wrapf(err, "checkout %s branch", git.DefaultBranch) } } } else { logrus.Infof("Checking out branch %s", d.options.ReleaseBranch) if err := d.impl.Checkout(repo, d.options.ReleaseBranch); err != nil { - return fmt.Errorf("checking out branch %s: %w", d.options.ReleaseBranch, err) + return errors.Wrapf(err, "checking out branch %s", d.options.ReleaseBranch) } } @@ -455,7 +456,7 @@ func (d *DefaultStage) TagRepository() error { // then in detached head state. branch, err := d.impl.CurrentBranch(repo) if err != nil { - return fmt.Errorf("get current branch: %w", err) + return errors.Wrap(err, "get current branch") } if branch != "" { logrus.Infof("Current branch is %s", branch) @@ -494,7 +495,7 @@ func (d *DefaultStage) TagRepository() error { repo, fmt.Sprintf("Release commit for Kubernetes %s", version), ); err != nil { - return fmt.Errorf("create empty release commit: %w", err) + return errors.Wrap(err, "create empty release commit") } } @@ -504,7 +505,7 @@ func (d *DefaultStage) TagRepository() error { if branch != "" && !strings.HasPrefix(branch, "release-") { logrus.Infof("Detaching HEAD at commit %s to create tag %s", commit, version) if err := d.impl.Checkout(repo, commit); err != nil { - return fmt.Errorf("checkout release commit: %w", err) + return errors.Wrap(err, "checkout release commit") } } @@ -514,7 +515,7 @@ func (d *DefaultStage) TagRepository() error { if ref != release.DefaultK8sRef { logrus.Infof("Merging custom ref: %s", ref) if err := d.impl.Merge(repo, git.Remotify(ref)); err != nil { - return fmt.Errorf("merge k8s ref: %w", err) + return errors.Wrap(err, "merge k8s ref") } } @@ -527,7 +528,7 @@ func (d *DefaultStage) TagRepository() error { "Kubernetes %s release %s", d.options.ReleaseType, version, ), ); err != nil { - return fmt.Errorf("tag version: %w", err) + return errors.Wrap(err, "tag version") } // if we are working on master/main at this point, we are in @@ -537,7 +538,7 @@ func (d *DefaultStage) TagRepository() error { if branch != "" && !strings.HasPrefix(branch, "release-") { logrus.Infof("Checking out %s to reattach HEAD", d.options.ReleaseBranch) if err := d.impl.Checkout(repo, d.options.ReleaseBranch); err != nil { - return fmt.Errorf("checking out branch %s: %w", d.options.ReleaseBranch, err) + return errors.Wrapf(err, "checking out branch %s", d.options.ReleaseBranch) } } } @@ -547,13 +548,13 @@ func (d *DefaultStage) TagRepository() error { func (d *DefaultStage) Build() error { // Log in to Docker Hub to avoid getting rate limited if err := d.impl.DockerHubLogin(); err != nil { - return fmt.Errorf("loging into Docker Hub: %w", err) + return errors.Wrap(err, "loging into Docker Hub") } // Call MakeCross for each of the versions we are building for _, version := range d.state.versions.Ordered() { if err := d.impl.MakeCross(version); err != nil { - return fmt.Errorf("build artifacts: %w", err) + return errors.Wrap(err, "build artifacts") } } return nil @@ -591,20 +592,20 @@ func (d *DefaultStage) GenerateChangelog() error { func (d *defaultStageImpl) AddBinariesToSBOM(sbom *spdx.Document, version string) error { binaries, err := d.ListBinaries(version) if err != nil { - return fmt.Errorf("getting binaries list for %s: %w", version, err) + return errors.Wrapf(err, "Getting binaries list for %s", version) } // Add the binaries, taking care of their docs for _, bin := range binaries { file := spdx.NewFile() if err := file.ReadSourceFile(bin.Path); err != nil { - return fmt.Errorf("reading binary sourcefile from %s: %w", bin.Path, err) + return errors.Wrapf(err, "reading binary sourcefile from %s", bin.Path) } file.Name = filepath.Join("bin", bin.Platform, bin.Arch, filepath.Base(bin.Path)) file.FileName = file.Name file.LicenseConcluded = LicenseIdentifier if err := sbom.AddFile(file); err != nil { - return fmt.Errorf("adding file to artifacts sbom: %w", err) + return errors.Wrap(err, "adding file to artifacts sbom") } file.AddRelationship(&spdx.Relationship{ FullRender: false, @@ -621,20 +622,20 @@ func (d *defaultStageImpl) AddBinariesToSBOM(sbom *spdx.Document, version string func (d *defaultStageImpl) AddTarfilesToSBOM(sbom *spdx.Document, version string) error { tarballs, err := d.ListTarballs(version) if err != nil { - return fmt.Errorf("listing release tarballs for %s: %w", version, err) + return errors.Wrapf(err, "listing release tarballs for %s", version) } // Once the initial doc is generated, add the tarfiles for _, tar := range tarballs { file := spdx.NewFile() if err := file.ReadSourceFile(tar); err != nil { - return fmt.Errorf("reading tarball sourcefile from %s: %w", tar, err) + return errors.Wrapf(err, "reading tarball sourcefile from %s", tar) } file.Name = filepath.Base(tar) file.LicenseConcluded = LicenseIdentifier file.FileName = filepath.Base(tar) if err := sbom.AddFile(file); err != nil { - return fmt.Errorf("adding file to artifacts sbom: %w", err) + return errors.Wrap(err, "adding file to artifacts sbom") } file.AddRelationship(&spdx.Relationship{ FullRender: false, @@ -655,7 +656,7 @@ func (d *defaultStageImpl) BuildBaseArtifactsSBOM(options *spdx.DocGenerateOptio func (d *defaultStageImpl) GenerateVersionArtifactsBOM(version string) error { images, err := d.ListImageArchives(version) if err != nil { - return fmt.Errorf("getting artifacts list: %w", err) + return errors.Wrap(err, "getting artifacts list") } // Build the base artifacts sbom. We only pass it the images for @@ -671,15 +672,15 @@ func (d *defaultStageImpl) GenerateVersionArtifactsBOM(version string) error { OutputFile: filepath.Join(), }) if err != nil { - return fmt.Errorf("generating base artifacts sbom for %s: %w", version, err) + return errors.Wrapf(err, "generating base artifacts sbom for %s", version) } // Add the binaries and tarballs if err := d.AddBinariesToSBOM(doc, version); err != nil { - return fmt.Errorf("adding binaries to %s SBOM: %w", version, err) + return errors.Wrapf(err, "adding binaries to %s SBOM", version) } if err := d.AddTarfilesToSBOM(doc, version); err != nil { - return fmt.Errorf("adding tarballs to %s SBOM: %w", version, err) + return errors.Wrapf(err, "adding tarballs to %s SBOM", version) } // Reference the source code SBOM as external document @@ -690,7 +691,7 @@ func (d *defaultStageImpl) GenerateVersionArtifactsBOM(version string) error { if err := extRef.ReadSourceFile( filepath.Join(os.TempDir(), fmt.Sprintf("source-bom-%s.spdx", version)), ); err != nil { - return fmt.Errorf("reading the source file as external reference: %w", err) + return errors.Wrap(err, "reading the source file as external reference") } doc.ExternalDocRefs = append(doc.ExternalDocRefs, extRef) @@ -707,7 +708,7 @@ func (d *defaultStageImpl) GenerateVersionArtifactsBOM(version string) error { // Write the Releas Artifacts SBOM to disk if err := doc.Write(filepath.Join(os.TempDir(), fmt.Sprintf("release-bom-%s.spdx", version))); err != nil { - return fmt.Errorf("writing artifacts SBOM for %s: %w", version, err) + return errors.Wrapf(err, "writing artifacts SBOM for %s", version) } return nil } @@ -717,7 +718,7 @@ func (d *defaultStageImpl) GenerateSourceTreeBOM( ) (*spdx.Document, error) { logrus.Info("Generating Kubernetes source SBOM file") doc, err := spdx.NewDocBuilder().Generate(options) - return doc, fmt.Errorf("generating kubernetes source code SBOM: %w", err) + return doc, errors.Wrap(err, "Generating kubernetes source code SBOM") } // WriteSourceBOM takes a source code SBOM and writes it into a file, updating @@ -727,10 +728,10 @@ func (d *defaultStageImpl) WriteSourceBOM( ) error { spdxDoc.Namespace = fmt.Sprintf("https://sbom.k8s.io/%s/source", version) spdxDoc.Name = fmt.Sprintf("kubernetes-%s", version) - if err := spdxDoc.Write(filepath.Join(os.TempDir(), fmt.Sprintf("source-bom-%s.spdx", version))); err != nil { - return fmt.Errorf("writing the source code SBOM: %w", err) - } - return nil + return errors.Wrap( + spdxDoc.Write(filepath.Join(os.TempDir(), fmt.Sprintf("source-bom-%s.spdx", version))), + "writing the source code SBOM", + ) } func (d *DefaultStage) GenerateBillOfMaterials() error { @@ -747,7 +748,7 @@ func (d *DefaultStage) GenerateBillOfMaterials() error { Directories: []string{gitRoot}, }) if err != nil { - return fmt.Errorf("generating the kubernetes source SBOM: %w", err) + return errors.Wrap(err, "generating the kubernetes source SBOM") } // We generate an artifacts sbom for each of the versions @@ -755,12 +756,12 @@ func (d *DefaultStage) GenerateBillOfMaterials() error { for _, version := range d.state.versions.Ordered() { // Render the common source SBOM for this version if err := d.impl.WriteSourceBOM(spdxDOC, version); err != nil { - return fmt.Errorf("writing SBOM for version %s: %w", version, err) + return errors.Wrapf(err, "writing SBOM for version %s", version) } // Render the artifacts SBOM for version if err := d.impl.GenerateVersionArtifactsBOM(version); err != nil { - return fmt.Errorf("generating SBOM for version %s: %w", version, err) + return errors.Wrapf(err, "generating SBOM for version %s", version) } } @@ -771,7 +772,7 @@ func (d *DefaultStage) StageArtifacts() error { // Generate the intoto attestation, reloaded with the current run data statement, err := d.impl.GenerateAttestation(d.state, d.options) if err != nil { - return fmt.Errorf("generating the provenance attestation: %w", err) + return errors.Wrap(err, "generating the provenance attestation") } // Init push options for provenance document pushBuildOptions := &build.Options{ @@ -781,7 +782,7 @@ func (d *DefaultStage) StageArtifacts() error { ValidateRemoteImageDigests: true, } if err := d.impl.CheckReleaseBucket(pushBuildOptions); err != nil { - return fmt.Errorf("check release bucket access: %w", err) + return errors.Wrap(err, "check release bucket access") } // Stage the local source tree @@ -790,7 +791,7 @@ func (d *DefaultStage) StageArtifacts() error { workspaceDir, d.options.BuildVersion, ); err != nil { - return fmt.Errorf("staging local source tree: %w", err) + return errors.Wrap(err, "staging local source tree") } // Add the sources tarball to the attestation @@ -798,7 +799,7 @@ func (d *DefaultStage) StageArtifacts() error { d.options, filepath.Join(workspaceDir, release.SourcesTar), ) if err != nil { - return fmt.Errorf("adding sources tarball to provenance attestation: %w", err) + return errors.Wrap(err, "adding sources tarball to provenance attestation") } statement.Subject = append(statement.Subject, subjects...) @@ -813,7 +814,7 @@ func (d *DefaultStage) StageArtifacts() error { // Stage local artifacts and write checksums if err := d.impl.StageLocalArtifacts(pushBuildOptions); err != nil { - return fmt.Errorf("staging local artifacts: %w", err) + return errors.Wrap(err, "staging local artifacts") } gcsPath := filepath.Join( d.options.Bucket(), release.StagePath, d.options.BuildVersion, version, @@ -825,7 +826,7 @@ func (d *DefaultStage) StageArtifacts() error { filepath.Join(buildDir, release.GCSStagePath, version), filepath.Join(gcsPath, release.GCSStagePath, version), ); err != nil { - return fmt.Errorf("pushing release artifacts: %w", err) + return errors.Wrap(err, "pushing release artifacts") } // Push container release-images to GCS @@ -834,12 +835,12 @@ func (d *DefaultStage) StageArtifacts() error { filepath.Join(buildDir, release.ImagesPath), filepath.Join(gcsPath, release.ImagesPath), ); err != nil { - return fmt.Errorf("pushing release artifacts: %w", err) + return errors.Wrap(err, "pushing release artifacts") } // Push container images into registry if err := d.impl.PushContainerImages(pushBuildOptions); err != nil { - return fmt.Errorf("pushing container images: %w", err) + return errors.Wrap(err, "pushing container images") } // Add artifacts to the attestation, this should get both release-images @@ -848,19 +849,19 @@ func (d *DefaultStage) StageArtifacts() error { d.options, buildDir, version, ) if err != nil { - return fmt.Errorf("adding provenance of release-images for version %s: %w", version, err) + return errors.Wrapf(err, "adding provenance of release-images for version %s", version) } statement.Subject = append(statement.Subject, subjects...) } // Push the attestation metadata file to the bucket if err := d.impl.PushAttestation(statement, d.options); err != nil { - return fmt.Errorf("writing provenance metadata to disk: %w", err) + return errors.Wrap(err, "writing provenance metadata to disk") } // Delete the local source tarball if err := d.impl.DeleteLocalSourceTarball(pushBuildOptions, workspaceDir); err != nil { - return fmt.Errorf("delete source tarball: %w", err) + return errors.Wrap(err, "delete source tarball") } args := "" @@ -897,13 +898,13 @@ func (d *defaultStageImpl) GenerateAttestation(state *StageState, options *Stage // Fetch the last commit: repo, err := git.OpenRepo(gitRoot) if err != nil { - return nil, fmt.Errorf("opening repository to check commit hash: %w", err) + return nil, errors.Wrap(err, "opening repository to check commit hash") } // Get the k/k commit we are building commitSHA, err := repo.LastCommitSha() if err != nil { - return nil, fmt.Errorf("getting k/k build point: %w", err) + return nil, errors.Wrap(err, "getting k/k build point") } // Create the predicate to populate it with the current @@ -944,11 +945,11 @@ func (d *defaultStageImpl) PushAttestation(attestation *provenance.Statement, op // Create a temporary file: f, err := os.CreateTemp("", "provenance-") if err != nil { - return fmt.Errorf("creating temp file for provenance metadata: %w", err) + return errors.Wrap(err, "creating temp file for provenance metadata") } // Write the provenance statement to disk: if err := attestation.Write(f.Name()); err != nil { - return fmt.Errorf("writing provenance attestation to disk: %w", err) + return errors.Wrap(err, "writing provenance attestation to disk") } // TODO for SLSA2: Sign the attestation @@ -960,14 +961,14 @@ func (d *defaultStageImpl) PushAttestation(attestation *provenance.Statement, op } if err := d.CheckReleaseBucket(pushBuildOptions); err != nil { - return fmt.Errorf("check release bucket access: %w", err) + return errors.Wrap(err, "check release bucket access") } // Push the provenance file to GCS - if err := d.PushReleaseArtifacts(pushBuildOptions, f.Name(), filepath.Join(gcsPath, release.ProvenanceFilename)); err != nil { - return fmt.Errorf("pushing provenance manifest: %w", err) - } - return nil + return errors.Wrap( + d.PushReleaseArtifacts(pushBuildOptions, f.Name(), filepath.Join(gcsPath, release.ProvenanceFilename)), + "pushing provenance manifest", + ) } // GetOutputDirSubjects reads the built artifacts and returns them diff --git a/pkg/announce/announce.go b/pkg/announce/announce.go index df40e7474c8..12e7ffc781f 100644 --- a/pkg/announce/announce.go +++ b/pkg/announce/announce.go @@ -23,6 +23,7 @@ import ( "regexp" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-utils/command" "sigs.k8s.io/release-utils/util" @@ -80,7 +81,7 @@ func CreateForBranch(opts *Options) error { fmt.Sprintf("Kubernetes %s branch has been created", opts.branch), fmt.Sprintf(branchAnnouncement, opts.branch), ); err != nil { - return fmt.Errorf("creating branch announcement: %w", err) + return errors.Wrap(err, "creating branch announcement") } // TODO: When we create a new branch, we notify the publishing-bot folks by @@ -99,7 +100,7 @@ func CreateForRelease(opts *Options) error { if opts.changelogFile != "" { changelogData, err := os.ReadFile(opts.changelogFile) if err != nil { - return fmt.Errorf("reading changelog html file: %w", err) + return errors.Wrap(err, "reading changelog html file") } changelog = string(changelogData) } @@ -125,7 +126,7 @@ func CreateForRelease(opts *Options) error { opts.changelogPath, filepath.Base(opts.changelogPath), opts.tag, ), ); err != nil { - return fmt.Errorf("creating release announcement: %w", err) + return errors.Wrap(err, "creating release announcement") } logrus.Infof("Release announcement created") @@ -139,7 +140,9 @@ func create(workDir, subject, message string) error { if err := os.WriteFile( subjectFile, []byte(subject), 0o755, ); err != nil { - return fmt.Errorf("writing subject to file %s: %w", subjectFile, err) + return errors.Wrapf( + err, "writing subject to file %s", subjectFile, + ) } logrus.Debugf("Wrote file %s", subjectFile) @@ -149,7 +152,9 @@ func create(workDir, subject, message string) error { if err := os.WriteFile( announcementFile, []byte(message), 0o755, ); err != nil { - return fmt.Errorf("writing announcement to file %s: %w", announcementFile, err) + return errors.Wrapf( + err, "writing announcement to file %s", announcementFile, + ) } logrus.Debugf("Wrote file %s", announcementFile) @@ -163,7 +168,7 @@ func create(workDir, subject, message string) error { func getGoVersion(tag string) (string, error) { semver, err := util.TagStringToSemver(tag) if err != nil { - return "", fmt.Errorf("parse version tag: %w", err) + return "", errors.Wrap(err, "parse version tag") } branch := fmt.Sprintf("release-%d.%d", semver.Major, semver.Minor) @@ -172,7 +177,7 @@ func getGoVersion(tag string) (string, error) { if err != nil { kubecrossVer, err = kc.Latest() if err != nil { - return "", fmt.Errorf("get kubecross version: %w", err) + return "", errors.Wrap(err, "get kubecross version") } } @@ -182,7 +187,7 @@ func getGoVersion(tag string) (string, error) { "docker", "run", "--rm", kubecrossImg, "go", "version", ).RunSilentSuccessOutput() if err != nil { - return "", fmt.Errorf("get go version: %w", err) + return "", errors.Wrap(err, "get go version") } versionRegex := regexp.MustCompile(`^?(\d+)(\.\d+)?(\.\d+)`) diff --git a/pkg/announce/github_page.go b/pkg/announce/github_page.go index 4c035272d09..6553b8c6532 100644 --- a/pkg/announce/github_page.go +++ b/pkg/announce/github_page.go @@ -18,14 +18,13 @@ package announce import ( "bytes" - "errors" - "fmt" "html/template" "os" "path/filepath" "strings" "time" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/bom/pkg/spdx" @@ -123,7 +122,7 @@ func GenerateReleaseSBOM(opts *SBOMOptions) (string, error) { // Create a temporary file to write the sbom dir, err := os.MkdirTemp("", "project-sbom-") if err != nil { - return "", fmt.Errorf("creating temporary directory to write sbom: %w", err) + return "", errors.Wrap(err, "creating temporary directory to write sbom") } sbomFile := filepath.Join(dir, sbomFileName) @@ -140,7 +139,7 @@ func GenerateReleaseSBOM(opts *SBOMOptions) (string, error) { doc, err := builder.Generate(builderOpts) if err != nil { - return "", fmt.Errorf("generating initial SBOM: %w", err) + return "", errors.Wrap(err, "generating initial SBOM") } // Add the downlad location and version to the first @@ -157,7 +156,7 @@ func GenerateReleaseSBOM(opts *SBOMOptions) (string, error) { logrus.Infof("Adding file %s to SBOM", f.Path) spdxFile, err := spdxClient.FileFromPath(f.ReadFrom) if err != nil { - return "", fmt.Errorf("adding %s to SBOM: %w", f.ReadFrom, err) + return "", errors.Wrapf(err, "Adding %s to SBOM", f.ReadFrom) } spdxFile.Name = f.Path spdxFile.BuildID() // This is a boog in the spdx pkg, we have to call manually @@ -165,15 +164,11 @@ func GenerateReleaseSBOM(opts *SBOMOptions) (string, error) { opts.Repo, assetDownloadPath, opts.Tag, f.Path, ) if err := doc.AddFile(spdxFile); err != nil { - return "", fmt.Errorf("adding %s as SPDX file to SBOM: %w", f.ReadFrom, err) + return "", errors.Wrapf(err, "adding %s as SPDX file to SBOM", f.ReadFrom) } } - if err := doc.Write(sbomFile); err != nil { - return "", fmt.Errorf("writing sbom to disk: %w", err) - } - - return sbomFile, nil + return sbomFile, errors.Wrap(doc.Write(sbomFile), "writing sbom to disk") } // UpdateGitHubPage updates a github page with data from the release @@ -187,7 +182,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { releaseVerb := "Posting" semver, err := util.TagStringToSemver(opts.Tag) if err != nil { - return fmt.Errorf("parsing semver from tag: %w", err) + return errors.Wrap(err, "parsing semver from tag") } // Determine if this is a prerelase @@ -200,7 +195,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { // Process the specified assets releaseAssets, err := processAssetFiles(opts.AssetFiles) if err != nil { - return fmt.Errorf("processing the asset file list: %w", err) + return errors.Wrap(err, "processing the asset file list") } // Substitution struct for the template @@ -217,7 +212,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { if opts.ReleaseNotesFile != "" { rnData, err := os.ReadFile(opts.ReleaseNotesFile) if err != nil { - return fmt.Errorf("reading release notes file: %w", err) + return errors.Wrap(err, "reading release notes file") } subs.Substitutions["ReleaseNotes"] = string(rnData) } @@ -231,14 +226,14 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { // Parse the template we will use to build the release page tmpl, err := template.New("GitHubPage").Parse(templateText) if err != nil { - return fmt.Errorf("parsing github page template: %w", err) + return errors.Wrap(err, "parsing github page template") } // Run the template to verify the output. output := new(bytes.Buffer) err = tmpl.Execute(output, subs) if err != nil { - return fmt.Errorf("executing page template: %w", err) + return errors.Wrap(err, "executing page template") } // If we are in mock, we write it to stdout and exit. All checks @@ -246,7 +241,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { if !opts.NoMock { logrus.Info("Mock mode, outputting the release page") _, err := os.Stdout.Write(output.Bytes()) - return fmt.Errorf("writing github page to stdout: %w", err) + return errors.Wrap(err, "writing github page to stdout") } // Check to see that a tag exists. @@ -255,7 +250,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { // as a result of the release process. tagFound, err := gh.TagExists(opts.Owner, opts.Repo, opts.Tag) if err != nil { - return fmt.Errorf("checking if the tag already exists in GitHub: %w", err) + return errors.Wrap(err, "checking if the tag already exists in GitHub") } if !tagFound { logrus.Warnf("The %s tag doesn't exist yet on GitHub.", opts.Tag) @@ -267,7 +262,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { // Get the release we are looking for releases, err := gh.Releases(opts.Owner, opts.Repo, true) if err != nil { - return fmt.Errorf("listing the repositories releases: %w", err) + return errors.Wrap(err, "listing the repositories releases") } // Does the release exist yet? @@ -299,7 +294,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { opts.Draft, isPrerelease, ) if err != nil { - return fmt.Errorf("updating the release on GitHub: %w", err) + return errors.Wrap(err, "updating the release on GitHub") } // Releases often take a bit of time to show up in the API @@ -309,7 +304,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { releaseFound := false releases, err = gh.Releases(opts.Owner, opts.Repo, true) if err != nil { - return fmt.Errorf("listing releases in repository: %w", err) + return errors.Wrap(err, "listing releases in repository") } // Check if the page shows up in the API for _, testRelease := range releases { @@ -331,7 +326,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { // Delete any assets reviously uploaded if err := deleteReleaseAssets(gh, opts.Owner, opts.Repo, release.GetID()); err != nil { - return fmt.Errorf("deleting the existing release assets: %w", err) + return errors.Wrap(err, "deleting the existing release assets") } // publish binary @@ -339,7 +334,7 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) { logrus.Infof("Uploading %s as release asset", assetData["realpath"]) asset, err := gh.UploadReleaseAsset(opts.Owner, opts.Repo, release.GetID(), assetData["rawpath"]) if err != nil { - return fmt.Errorf("uploading %s to the release: %w", assetData["realpath"], err) + return errors.Wrapf(err, "uploading %s to the release", assetData["realpath"]) } logrus.Info("Successfully uploaded asset #", asset.GetID()) } @@ -377,7 +372,7 @@ func processAssetFiles(assetFiles []string) (releaseAssets []map[string]string, fileHashes, err := getFileHashes(path) if err != nil { - return nil, fmt.Errorf("getting the hashes: %w", err) + return nil, errors.Wrap(err, "getting the hashes") } assetData["sha512"] = fileHashes["512"] @@ -393,7 +388,7 @@ func deleteReleaseAssets(gh *github.GitHub, owner, repo string, releaseID int64) // the new uploads we are sending currentAssets, err := gh.ListReleaseAssets(owner, repo, releaseID) if err != nil { - return fmt.Errorf("while checking if the release already has assets: %w", err) + return errors.Wrap(err, "while checking if the release already has assets") } if len(currentAssets) == 0 { logrus.Info("No assets found in release") @@ -404,7 +399,7 @@ func deleteReleaseAssets(gh *github.GitHub, owner, repo string, releaseID int64) for _, asset := range currentAssets { logrus.Infof("Deleting %s", asset.GetName()) if err := gh.DeleteReleaseAsset(owner, repo, asset.GetID()); err != nil { - return fmt.Errorf("deleting existing release assets: %w", err) + return errors.Wrap(err, "deleting existing release assets") } } return nil @@ -414,12 +409,12 @@ func deleteReleaseAssets(gh *github.GitHub, owner, repo string, releaseID int64) func getFileHashes(path string) (hashes map[string]string, err error) { sha256, err := hash.SHA256ForFile(path) if err != nil { - return nil, fmt.Errorf("get sha256: %w", err) + return nil, errors.Wrap(err, "get sha256") } sha512, err := hash.SHA512ForFile(path) if err != nil { - return nil, fmt.Errorf("get sha512: %w", err) + return nil, errors.Wrap(err, "get sha512") } return map[string]string{"256": sha256, "512": sha512}, nil @@ -460,7 +455,7 @@ func (o *GitHubPageOptions) ParseSubstitutions(subs []string) error { func (o *GitHubPageOptions) SetRepository(repoSlug string) error { org, repo, err := git.ParseRepoSlug(repoSlug) if err != nil { - return fmt.Errorf("parsing repository slug: %w", err) + return errors.Wrap(err, "parsing repository slug") } o.Owner = org o.Repo = repo @@ -479,7 +474,7 @@ func (o *GitHubPageOptions) ReadTemplate(templatePath string) error { // Otherwise, read a custom template from a file templateData, err := os.ReadFile(templatePath) if err != nil { - return fmt.Errorf("reading page template text: %w", err) + return errors.Wrap(err, "reading page template text") } logrus.Infof("Using custom template from %s", templatePath) o.PageTemplate = string(templateData) diff --git a/pkg/binary/binary.go b/pkg/binary/binary.go index 17b80e6dc70..3a7d70a37f1 100644 --- a/pkg/binary/binary.go +++ b/pkg/binary/binary.go @@ -18,12 +18,11 @@ package binary import ( "bufio" - "errors" - "fmt" "io" "os" "unicode" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -73,7 +72,7 @@ func NewWithOptions(filePath string, opts *Options) (bin *Binary, err error) { // Get the right implementation for the specified file impl, err := getArchImplementation(filePath, opts) if err != nil { - return nil, fmt.Errorf("getting arch implementation: %w", err) + return nil, errors.Wrap(err, "getting arch implementation") } bin.options.Path = filePath bin.SetImplementation(impl) @@ -86,7 +85,7 @@ func getArchImplementation(filePath string, opts *Options) (impl binaryImplement // Check if we're dealing with a Linux binary elf, err := NewELFBinary(filePath, opts) if err != nil { - return nil, fmt.Errorf("checking if file is an ELF binary: %w", err) + return nil, errors.Wrap(err, "checking if file is an ELF binary") } if elf != nil { return elf, nil @@ -95,7 +94,7 @@ func getArchImplementation(filePath string, opts *Options) (impl binaryImplement // Check if its a darwin binary macho, err := NewMachOBinary(filePath, opts) if err != nil { - return nil, fmt.Errorf("checking if file is a Mach-O binary: %w", err) + return nil, errors.Wrap(err, "checking if file is a Mach-O binary") } if macho != nil { return macho, nil @@ -104,7 +103,7 @@ func getArchImplementation(filePath string, opts *Options) (impl binaryImplement // Finally we check to see if it's a windows binary pe, err := NewPEBinary(filePath, opts) if err != nil { - return nil, fmt.Errorf("checking if file is a windows PE binary: %w", err) + return nil, errors.Wrap(err, "checking if file is a windows PE binary") } if pe != nil { return pe, nil @@ -148,7 +147,7 @@ func (b *Binary) ContainsStrings(s ...string) (match bool, err error) { // Open the binary f, err := os.Open(b.options.Path) if err != nil { - return match, fmt.Errorf("opening binary to search: %w", err) + return match, errors.Wrap(err, "opening binary to search") } defer f.Close() terms := map[string]bool{} @@ -164,7 +163,7 @@ func (b *Binary) ContainsStrings(s ...string) (match bool, err error) { r, _, err := in.ReadRune() if err != nil { if err != io.EOF { - return match, fmt.Errorf("while reading binary data: %w", err) + return match, errors.Wrap(err, "while reading binary data") } return false, nil } diff --git a/pkg/binary/elf.go b/pkg/binary/elf.go index 8753e697f90..038f130c943 100644 --- a/pkg/binary/elf.go +++ b/pkg/binary/elf.go @@ -22,6 +22,7 @@ import ( "fmt" "os" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -47,7 +48,7 @@ type ELFHeader struct { func NewELFBinary(filePath string, opts *Options) (*ELFBinary, error) { header, err := GetELFHeader(filePath) if err != nil { - return nil, fmt.Errorf("while trying to get ELF header from file: %w", err) + return nil, errors.Wrap(err, "while trying to get ELF header from file") } if header == nil { logrus.Debug("file is not an ELF binary") @@ -118,7 +119,7 @@ func (eh *ELFHeader) MachineType() string { func GetELFHeader(path string) (*ELFHeader, error) { f, err := os.Open(path) if err != nil { - return nil, fmt.Errorf("opening binary for reading: %w", err) + return nil, errors.Wrap(err, "opening binary for reading") } defer f.Close() @@ -127,7 +128,7 @@ func GetELFHeader(path string) (*ELFHeader, error) { reader := bufio.NewReader(f) hBytes, err := reader.Peek(6) if err != nil { - return nil, fmt.Errorf("reading the binary header: %w", err) + return nil, errors.Wrap(err, "reading the binary header") } logrus.StandardLogger().Debugf("Header bytes: %+v", hBytes) @@ -148,15 +149,15 @@ func GetELFHeader(path string) (*ELFHeader, error) { endianness = binary.BigEndian default: - return nil, fmt.Errorf("invalid endianness specified in elf binary: %w", err) + return nil, errors.Wrap(err, "invalid endianness specified in elf binary") } header := &ELFHeader{} if _, err := f.Seek(4, 0); err != nil { - return nil, fmt.Errorf("seeking past the ELF magic bytes: %w", err) + return nil, errors.Wrap(err, "seeking past the ELF magic bytes") } if err := binary.Read(f, endianness, header); err != nil { - return nil, fmt.Errorf("reading elf header from binary file: %w", err) + return nil, errors.Wrap(err, "reading elf header from binary file") } return header, nil } diff --git a/pkg/binary/mach-o.go b/pkg/binary/mach-o.go index 3f97afcd83c..dc10e55abaf 100644 --- a/pkg/binary/mach-o.go +++ b/pkg/binary/mach-o.go @@ -22,6 +22,7 @@ import ( "fmt" "os" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -50,7 +51,7 @@ type MachOBinary struct { func NewMachOBinary(filePath string, opts *Options) (*MachOBinary, error) { header, err := GetMachOHeader(filePath) if err != nil { - return nil, fmt.Errorf("trying to read a Mach-O header from file: %w", err) + return nil, errors.Wrap(err, "trying to read a Mach-O header from file") } if header == nil { logrus.Debug("File is not a Mach-O binary") @@ -126,14 +127,14 @@ func (machoh *MachOHeader) MachineType() string { func GetMachOHeader(path string) (*MachOHeader, error) { f, err := os.Open(path) if err != nil { - return nil, fmt.Errorf("opening binary for reading: %w", err) + return nil, errors.Wrap(err, "opening binary for reading") } defer f.Close() reader := bufio.NewReader(f) hBytes, err := reader.Peek(4) if err != nil { - return nil, fmt.Errorf("reading the binary header: %w", err) + return nil, errors.Wrap(err, "reading the binary header") } var endianness binary.ByteOrder @@ -161,10 +162,10 @@ func GetMachOHeader(path string) (*MachOHeader, error) { header := &MachOHeader{} if _, err := f.Seek(0, 0); err != nil { - return nil, fmt.Errorf("seeking to the start of the file: %w", err) + return nil, errors.Wrap(err, "seeking to the start of the file") } if err := binary.Read(f, endianness, header); err != nil { - return nil, fmt.Errorf("reading Mach-O header from binary file: %w", err) + return nil, errors.Wrap(err, "reading Mach-O header from binary file") } return header, nil } diff --git a/pkg/binary/windows.go b/pkg/binary/windows.go index b3c7ce43ad7..05dc031b60c 100644 --- a/pkg/binary/windows.go +++ b/pkg/binary/windows.go @@ -18,10 +18,10 @@ package binary import ( "encoding/binary" - "errors" "fmt" "os" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -57,7 +57,7 @@ type PEBinary struct { func NewPEBinary(filePath string, opts *Options) (bin *PEBinary, err error) { header, err := GetPEHeader(filePath) if err != nil { - return nil, fmt.Errorf("reading header from binary: %w", err) + return nil, errors.Wrap(err, "reading header from binary") } if header == nil { logrus.Infof("file is not a PE executable") @@ -133,7 +133,7 @@ func (peh *PEHeader) WordLength() int { func GetPEHeader(path string) (*PEHeader, error) { f, err := os.Open(path) if err != nil { - return nil, fmt.Errorf("opening binary for reading: %w", err) + return nil, errors.Wrap(err, "opening binary for reading") } defer f.Close() @@ -149,10 +149,10 @@ func GetPEHeader(path string) (*PEHeader, error) { signoff := int64(binary.LittleEndian.Uint32(dosheader[0x3c:])) var sign [4]byte if _, err := f.ReadAt(sign[:], signoff); err != nil { - return nil, fmt.Errorf("reading the PE file header location: %w", err) + return nil, errors.Wrap(err, "reading the PE file header location") } if !(sign[0] == 'P' && sign[1] == 'E' && sign[2] == 0 && sign[3] == 0) { - return nil, errors.New("invalid PE COFF file signature") + return nil, errors.New("Invalid PE COFF file signature") } base = signoff + 4 } else { @@ -163,7 +163,7 @@ func GetPEHeader(path string) (*PEHeader, error) { } if _, err := f.Seek(base, 0); err != nil { - return nil, fmt.Errorf("seeking to start of the PE file header location: %w", err) + return nil, errors.Wrap(err, "seeking to start of the PE file header location") } // Read the full header, will be discarded later @@ -174,13 +174,13 @@ func GetPEHeader(path string) (*PEHeader, error) { // Now from the full file header we got, we jump to the "optional" header if _, err = f.Seek(base+int64(binary.Size(header)), 0); err != nil { - return nil, fmt.Errorf("unable to seek to start of PE Optional header: %w", err) + return nil, errors.Wrap(err, "Unable to seek to start of PE Optional header") } // Read the file optional header oheader := &PEOptionalHeader{} if err := binary.Read(f, binary.LittleEndian, oheader); err != nil { - return nil, fmt.Errorf("reading optional PE header from binary: %w", err) + return nil, errors.Wrap(err, "reading optional PE header from binary") } return &PEHeader{ diff --git a/pkg/build/build.go b/pkg/build/build.go index def1df78617..06c8fea0417 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -17,8 +17,7 @@ limitations under the License. package build import ( - "fmt" - + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/release" @@ -138,7 +137,7 @@ func (bi *Instance) getGCSBuildPath(version string) (string, error) { bi.opts.Fast, ) if err != nil { - return "", fmt.Errorf("get GCS release path: %w", err) + return "", errors.Wrap(err, "get GCS release path") } return buildPath, nil diff --git a/pkg/build/ci.go b/pkg/build/ci.go index 5d1d3660dd6..2a44896a8c1 100644 --- a/pkg/build/ci.go +++ b/pkg/build/ci.go @@ -17,10 +17,10 @@ limitations under the License. package build import ( - "fmt" "os" "path/filepath" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/gcp/auth" @@ -36,7 +36,7 @@ func (bi *Instance) Build() error { var dirErr error workingDir, dirErr = os.Getwd() if dirErr != nil { - return fmt.Errorf("getting working directory: %w", dirErr) + return errors.Wrapf(dirErr, "getting working directory") } } logrus.Infof("Current working directory: %s", workingDir) @@ -45,7 +45,7 @@ func (bi *Instance) Build() error { expectedDirRelative := "kubernetes" if workingDirRelative != expectedDirRelative { - return fmt.Errorf( + return errors.Errorf( "build was executed from the %s directory but must be run from the %s directory, exiting", workingDirRelative, expectedDirRelative, @@ -54,7 +54,7 @@ func (bi *Instance) Build() error { buildExists, buildExistsErr := bi.checkBuildExists() if buildExistsErr != nil { - return fmt.Errorf("checking if build exists: %w", buildExistsErr) + return errors.Wrapf(buildExistsErr, "checking if build exists") } if buildExists { @@ -66,14 +66,14 @@ func (bi *Instance) Build() error { // TODO: Should this be configurable? envErr := os.Setenv("KUBE_RELEASE_RUN_TESTS", "n") if envErr != nil { - return fmt.Errorf("setting 'KUBE_RELEASE_RUN_TESTS' to 'n': %w", envErr) + return errors.Wrapf(envErr, "setting 'KUBE_RELEASE_RUN_TESTS' to 'n'") } // Configure docker client for gcr.io authentication to allow communication // with non-public registries. if bi.opts.ConfigureDocker { if configureErr := auth.ConfigureDocker(); configureErr != nil { - return fmt.Errorf("configuring docker auth: %w", configureErr) + return errors.Wrapf(configureErr, "configuring docker auth") } } @@ -81,7 +81,7 @@ func (bi *Instance) Build() error { "make", "clean", ).RunSuccess(); cleanErr != nil { - return fmt.Errorf("running make clean: %w", cleanErr) + return errors.Wrapf(cleanErr, "running make clean") } // Create a Kubernetes build @@ -94,7 +94,7 @@ func (bi *Instance) Build() error { "make", releaseType, ).RunSuccess(); buildErr != nil { - return fmt.Errorf("running make %s: %w", releaseType, buildErr) + return errors.Wrapf(buildErr, "running make %s", releaseType) } // Pushing the build @@ -106,7 +106,7 @@ func (bi *Instance) Build() error { func (bi *Instance) checkBuildExists() (bool, error) { version, getVersionErr := release.GetWorkspaceVersion() if getVersionErr != nil { - return false, fmt.Errorf("getting workspace version: %w", getVersionErr) + return false, errors.Wrap(getVersionErr, "getting workspace version") } bi.opts.Version = version @@ -117,17 +117,17 @@ func (bi *Instance) checkBuildExists() (bool, error) { gcsBuildRoot, gcsBuildRootErr := bi.getGCSBuildPath(bi.opts.Version) if gcsBuildRootErr != nil { - return false, fmt.Errorf("get GCS build root: %w", gcsBuildRootErr) + return false, errors.Wrap(gcsBuildRootErr, "get GCS build root") } kubernetesTar, kubernetesTarErr := bi.objStore.NormalizePath(gcsBuildRoot, release.KubernetesTar) if kubernetesTarErr != nil { - return false, fmt.Errorf("get tarball path: %w", kubernetesTarErr) + return false, errors.Wrap(kubernetesTarErr, "get tarball path") } binPath, binPathErr := bi.objStore.NormalizePath(gcsBuildRoot, "bin") if binPathErr != nil { - return false, fmt.Errorf("get binary path: %w", binPathErr) + return false, errors.Wrap(binPathErr, "get binary path") } gcsBuildPaths := []string{ diff --git a/pkg/build/make.go b/pkg/build/make.go index 2e999596056..a101ac7c83b 100644 --- a/pkg/build/make.go +++ b/pkg/build/make.go @@ -20,6 +20,7 @@ import ( "fmt" "os" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/release" "sigs.k8s.io/release-sdk/git" @@ -74,12 +75,12 @@ func (d *defaultMakeImpl) Rename(from, to string) error { func (m *Make) MakeCross(version string) error { repo, err := m.impl.OpenRepo(".") if err != nil { - return fmt.Errorf("open Kubernetes repository: %w", err) + return errors.Wrap(err, "open Kubernetes repository") } logrus.Infof("Checking out version %s", version) if err := m.impl.Checkout(repo, version); err != nil { - return fmt.Errorf("checking out version %s: %w", version, err) + return errors.Wrapf(err, "checking out version %s", version) } // Unset the build memory requirement for parallel builds @@ -94,13 +95,13 @@ func (m *Make) MakeCross(version string) error { "cross-in-a-container", fmt.Sprintf("KUBE_DOCKER_IMAGE_TAG=%s", version), ); err != nil { - return fmt.Errorf("build version %s: %w", version, err) + return errors.Wrapf(err, "build version %s", version) } newBuildDir := fmt.Sprintf("%s-%s", release.BuildDir, version) logrus.Infof("Moving build output to %s", newBuildDir) if err := m.impl.Rename(release.BuildDir, newBuildDir); err != nil { - return fmt.Errorf("move build output: %w", err) + return errors.Wrap(err, "move build output") } logrus.Info("Building package tarballs") @@ -110,7 +111,7 @@ func (m *Make) MakeCross(version string) error { fmt.Sprintf("KUBE_DOCKER_IMAGE_TAG=%s", version), fmt.Sprintf("OUT_DIR=%s", newBuildDir), ); err != nil { - return fmt.Errorf("build package tarballs: %w", err) + return errors.Wrap(err, "build package tarballs") } return nil diff --git a/pkg/build/push.go b/pkg/build/push.go index 434715e6c13..0e24a839208 100644 --- a/pkg/build/push.go +++ b/pkg/build/push.go @@ -18,7 +18,6 @@ package build import ( "context" - "errors" "fmt" "os" "path/filepath" @@ -26,6 +25,7 @@ import ( "strings" "cloud.google.com/go/storage" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/release" @@ -105,7 +105,7 @@ var ExtraWindowsStageFiles = []stageFile{ func (bi *Instance) Push() error { version, err := bi.findLatestVersion() if err != nil { - return fmt.Errorf("find latest version: %w", err) + return errors.Wrap(err, "find latest version") } if version == "" { @@ -115,27 +115,27 @@ func (bi *Instance) Push() error { logrus.Infof("Latest version is %s", version) if err := bi.CheckReleaseBucket(); err != nil { - return fmt.Errorf("check release bucket access: %w", err) + return errors.Wrap(err, "check release bucket access") } if err := bi.StageLocalArtifacts(); err != nil { - return fmt.Errorf("staging local artifacts: %w", err) + return errors.Wrap(err, "staging local artifacts") } if err := bi.PushContainerImages(); err != nil { - return fmt.Errorf("push container images: %w", err) + return errors.Wrap(err, "push container images") } gcsDest, gcsDestErr := bi.getGCSBuildPath(version) if gcsDestErr != nil { - return fmt.Errorf("get GCS destination: %w", gcsDestErr) + return errors.Wrap(gcsDestErr, "get GCS destination") } if err := bi.PushReleaseArtifacts( filepath.Join(bi.opts.BuildDir, release.GCSStagePath, version), gcsDest, ); err != nil { - return fmt.Errorf("push release artifacts: %w", err) + return errors.Wrap(err, "push release artifacts") } if !bi.opts.CI { @@ -160,7 +160,7 @@ func (bi *Instance) Push() error { bi.opts.PrivateBucket, bi.opts.Fast, ); err != nil { - return fmt.Errorf("publish release: %w", err) + return errors.Wrap(err, "publish release") } return nil @@ -171,13 +171,13 @@ func (bi *Instance) findLatestVersion() (latestVersion string, err error) { if bi.opts.RepoRoot == "" { bi.opts.RepoRoot, err = os.Getwd() if err != nil { - return "", fmt.Errorf("get working directory: %w", err) + return "", errors.Wrap(err, "get working directory") } } isBazel, err := release.BuiltWithBazel(bi.opts.RepoRoot) if err != nil { - return "", fmt.Errorf("identify if release built with Bazel: %w", err) + return "", errors.Wrap(err, "identify if release built with Bazel") } latestVersion = bi.opts.Version @@ -186,14 +186,14 @@ func (bi *Instance) findLatestVersion() (latestVersion string, err error) { logrus.Info("Using Bazel build version") version, err := release.ReadBazelVersion(bi.opts.RepoRoot) if err != nil { - return "", fmt.Errorf("read Bazel build version: %w", err) + return "", errors.Wrap(err, "read Bazel build version") } latestVersion = version } else { logrus.Info("Using Dockerized build version") version, err := release.ReadDockerizedVersion(bi.opts.RepoRoot) if err != nil { - return "", fmt.Errorf("read Dockerized build version: %w", err) + return "", errors.Wrap(err, "read Dockerized build version") } latestVersion = version } @@ -203,18 +203,18 @@ func (bi *Instance) findLatestVersion() (latestVersion string, err error) { valid, err := release.IsValidReleaseBuild(latestVersion) if err != nil { - return "", fmt.Errorf( - "determine if release build version is valid: %w", err, + return "", errors.Wrap( + err, "determine if release build version is valid", ) } if !valid { - return "", fmt.Errorf( + return "", errors.Errorf( "build version %s is not valid for release", latestVersion, ) } if bi.opts.CI && release.IsDirtyBuild(latestVersion) { - return "", fmt.Errorf( + return "", errors.Errorf( "refusing to push dirty build %s with --ci flag given", latestVersion, ) @@ -261,15 +261,15 @@ func (bi *Instance) CheckReleaseBucket() error { client, err := storage.NewClient(context.Background()) if err != nil { - return fmt.Errorf( + return errors.Wrap(err, "fetching gcloud credentials, try running "+ - `"gcloud auth application-default login": %w`, err, + `"gcloud auth application-default login"`, ) } bucket := client.Bucket(bi.opts.Bucket) if bucket == nil { - return fmt.Errorf( + return errors.Errorf( "identify specified bucket for artifacts: %s", bi.opts.Bucket, ) } @@ -280,10 +280,10 @@ func (bi *Instance) CheckReleaseBucket() error { context.Background(), requiredGCSPerms, ) if err != nil { - return fmt.Errorf("find release artifact bucket, try running `gcloud auth application-default login`: %w", err) + return errors.Wrap(err, "find release artifact bucket, try running `gcloud auth application-default login`") } if len(perms) != 1 { - return fmt.Errorf( + return errors.Errorf( "GCP user must have at least %s permissions on bucket %s", requiredGCSPerms, bi.opts.Bucket, ) @@ -299,7 +299,7 @@ func (bi *Instance) StageLocalArtifacts() error { logrus.Infof("Cleaning staging dir %s", stageDir) if err := util.RemoveAndReplaceDir(stageDir); err != nil { - return fmt.Errorf("remove and replace GCS staging directory: %w", err) + return errors.Wrap(err, "remove and replace GCS staging directory") } // Copy release tarballs to local GCS staging directory for push @@ -307,20 +307,20 @@ func (bi *Instance) StageLocalArtifacts() error { if err := util.CopyDirContentsLocal( filepath.Join(bi.opts.BuildDir, release.ReleaseTarsPath), stageDir, ); err != nil { - return fmt.Errorf("copy source directory into destination: %w", err) + return errors.Wrap(err, "copy source directory into destination") } if bi.opts.StageExtraFiles { // Copy helpful GCP scripts to local GCS staging directory for push logrus.Info("Copying extra GCP stage files") if err := bi.copyStageFiles(stageDir, ExtraGcpStageFiles); err != nil { - return fmt.Errorf("copy GCP stage files: %w", err) + return errors.Wrapf(err, "copy GCP stage files") } // Copy helpful Windows scripts to local GCS staging directory for push logrus.Info("Copying extra Windows stage files") if err := bi.copyStageFiles(stageDir, ExtraWindowsStageFiles); err != nil { - return fmt.Errorf("copy Windows stage files: %w", err) + return errors.Wrapf(err, "copy Windows stage files") } } @@ -333,7 +333,7 @@ func (bi *Instance) StageLocalArtifacts() error { filepath.Join(bi.opts.BuildDir, release.ReleaseStagePath), stageDir, ); err != nil { - return fmt.Errorf("stage binaries: %w", err) + return errors.Wrap(err, "stage binaries") } } else { logrus.Infof( @@ -349,14 +349,14 @@ func (bi *Instance) StageLocalArtifacts() error { if err := util.CopyFileLocal( sbom, filepath.Join(stageDir, filename), false, ); err != nil { - return fmt.Errorf("copying SBOM manifests: %w", err) + return errors.Wrapf(err, "copying SBOM manifests") } } // Write the release checksums logrus.Info("Writing checksums") if err := release.WriteChecksums(stageDir); err != nil { - return fmt.Errorf("write checksums: %w", err) + return errors.Wrap(err, "write checksums") } return nil } @@ -372,7 +372,9 @@ func (bi *Instance) copyStageFiles(stageDir string, files []stageFile) error { if err := os.MkdirAll( filepath.Dir(dstPath), os.FileMode(0o755), ); err != nil { - return fmt.Errorf("create destination path %s: %w", file.dstPath, err) + return errors.Wrapf( + err, "create destination path %s", file.dstPath, + ) } } @@ -380,7 +382,7 @@ func (bi *Instance) copyStageFiles(stageDir string, files []stageFile) error { filepath.Join(bi.opts.BuildDir, file.srcPath), dstPath, file.required, ); err != nil { - return fmt.Errorf("copy stage file: %w", err) + return errors.Wrapf(err, "copy stage file") } } @@ -392,28 +394,26 @@ func (bi *Instance) copyStageFiles(stageDir string, files []stageFile) error { func (bi *Instance) PushReleaseArtifacts(srcPath, gcsPath string) error { dstPath, dstPathErr := bi.objStore.NormalizePath(gcsPath) if dstPathErr != nil { - return fmt.Errorf("normalize GCS destination: %w", dstPathErr) + return errors.Wrap(dstPathErr, "normalize GCS destination") } logrus.Infof("Pushing release artifacts from %s to %s", srcPath, dstPath) finfo, err := os.Stat(srcPath) if err != nil { - return fmt.Errorf("checking if source path is a directory: %w", err) + return errors.Wrap(err, "checking if source path is a directory") } // If we are handling a single file copy instead of rsync if !finfo.IsDir() { - if err := bi.objStore.CopyToRemote(srcPath, dstPath); err != nil { - return fmt.Errorf("copying file to GCS: %w", err) - } - return nil + return errors.Wrap( + bi.objStore.CopyToRemote(srcPath, dstPath), "copying file to GCS", + ) } - if err := bi.objStore.RsyncRecursive(srcPath, dstPath); err != nil { - return fmt.Errorf("rsync artifacts to GCS: %w", err) - } - return nil + return errors.Wrap( + bi.objStore.RsyncRecursive(srcPath, dstPath), "rsync artifacts to GCS", + ) } // PushContainerImages will publish container images into the set @@ -431,7 +431,7 @@ func (bi *Instance) PushContainerImages() error { if err := images.Publish( bi.opts.Registry, bi.opts.Version, bi.opts.BuildDir, ); err != nil { - return fmt.Errorf("publish container images: %w", err) + return errors.Wrap(err, "publish container images") } if !bi.opts.ValidateRemoteImageDigests { @@ -442,7 +442,7 @@ func (bi *Instance) PushContainerImages() error { if err := images.Validate( bi.opts.Registry, bi.opts.Version, bi.opts.BuildDir, ); err != nil { - return fmt.Errorf("validate container images: %w", err) + return errors.Wrap(err, "validate container images") } return nil @@ -464,33 +464,33 @@ func (bi *Instance) CopyStagedFromGCS(stagedBucket, buildVersion string) error { gcsSrc, gcsSrcErr := bi.objStore.NormalizePath(src) if gcsSrcErr != nil { - return fmt.Errorf("normalize GCS source: %w", gcsSrcErr) + return errors.Wrap(gcsSrcErr, "normalize GCS source") } dst, dstErr := bi.objStore.NormalizePath(bi.opts.Bucket, "release", bi.opts.Version) if dstErr != nil { - return fmt.Errorf("normalize GCS destination: %w", dstErr) + return errors.Wrap(dstErr, "normalize GCS destination") } logrus.Infof("Bucket to bucket rsync from %s to %s", gcsSrc, dst) if err := bi.objStore.RsyncRecursive(gcsSrc, dst); err != nil { - return fmt.Errorf("copy stage to release bucket: %w", err) + return errors.Wrap(err, "copy stage to release bucket") } src = filepath.Join(src, release.KubernetesTar) dst = filepath.Join(bi.opts.BuildDir, release.GCSStagePath, bi.opts.Version, release.KubernetesTar) logrus.Infof("Copy kubernetes tarball %s to %s", src, dst) if err := bi.objStore.CopyToLocal(src, dst); err != nil { - return fmt.Errorf("copy to local: %w", err) + return errors.Wrapf(err, "copy to local") } src = filepath.Join(gcsStageRoot, release.ImagesPath) if err := os.MkdirAll(bi.opts.BuildDir, os.FileMode(0o755)); err != nil { - return fmt.Errorf("create dst dir: %w", err) + return errors.Wrap(err, "create dst dir") } logrus.Infof("Copy container images %s to %s", src, bi.opts.BuildDir) if err := bi.objStore.CopyToLocal(src, bi.opts.BuildDir); err != nil { - return fmt.Errorf("copy to local: %w", err) + return errors.Wrapf(err, "copy to local") } return nil @@ -504,13 +504,13 @@ func (bi *Instance) StageLocalSourceTree(workDir, buildVersion string) error { exclude, err := regexp.Compile(fmt.Sprintf(`.*/%s-.*`, release.BuildDir)) if err != nil { - return fmt.Errorf("compile tarball exclude regex: %w", err) + return errors.Wrap(err, "compile tarball exclude regex") } if err := tar.Compress( tarballPath, filepath.Join(workDir, "src"), exclude, ); err != nil { - return fmt.Errorf("create tarball: %w", err) + return errors.Wrap(err, "create tarball") } logrus.Infof("Uploading source tree tarball to GCS") @@ -522,7 +522,7 @@ func (bi *Instance) StageLocalSourceTree(workDir, buildVersion string) error { tarballPath, filepath.Join(bi.opts.Bucket, release.StagePath, buildVersion, release.SourcesTar), ); err != nil { - return fmt.Errorf("copy tarball to GCS: %w", err) + return errors.Wrap(err, "copy tarball to GCS") } return nil @@ -533,8 +533,5 @@ func (bi *Instance) StageLocalSourceTree(workDir, buildVersion string) error { func (bi *Instance) DeleteLocalSourceTarball(workDir string) error { tarballPath := filepath.Join(workDir, release.SourcesTar) logrus.Infof("Removing local source tree tarball " + tarballPath) - if err := os.RemoveAll(tarballPath); err != nil { - return fmt.Errorf("remove local source tarball: %w", err) - } - return nil + return errors.Wrap(os.RemoveAll(tarballPath), "remove local source tarball") } diff --git a/pkg/changelog/changelog.go b/pkg/changelog/changelog.go index f882c476b5a..f73af318be5 100644 --- a/pkg/changelog/changelog.go +++ b/pkg/changelog/changelog.go @@ -26,6 +26,7 @@ import ( "strings" "github.com/blang/semver" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/notes/options" @@ -73,7 +74,7 @@ func (c *Changelog) SetImpl(impl impl) { func (c *Changelog) Run() error { tag, err := c.impl.TagStringToSemver(c.options.Tag) if err != nil { - return fmt.Errorf("parse tag %s: %w", c.options.Tag, err) + return errors.Wrapf(err, "parse tag %s", c.options.Tag) } // Automatically set the branch to a release branch if not provided @@ -86,7 +87,9 @@ func (c *Changelog) Run() error { logrus.Infof("Using local repository path %s", c.options.RepoPath) repo, err := c.impl.OpenRepo(c.options.RepoPath) if err != nil { - return fmt.Errorf("open expected k/k repository %q: %w", c.options.RepoPath, err) + return errors.Wrapf(err, + "open expected k/k repository %q", c.options.RepoPath, + ) } if currentBranch, err := c.impl.CurrentBranch(repo); err == nil { logrus.Infof("We're currently on branch: %s", currentBranch) @@ -95,7 +98,7 @@ func (c *Changelog) Run() error { remoteBranch := git.Remotify(branch) head, err := c.impl.RevParseTag(repo, remoteBranch) if err != nil { - return fmt.Errorf("get latest branch commit: %w", err) + return errors.Wrap(err, "get latest branch commit") } logrus.Infof("Found latest %s commit %s", remoteBranch, head) @@ -115,7 +118,7 @@ func (c *Changelog) Run() error { downloadsTable, c.options.Bucket, c.options.Tars, c.options.Images, startRev, c.options.Tag, ); err != nil { - return fmt.Errorf("create downloads table: %w", err) + return errors.Wrapf(err, "create downloads table") } // New final minor versions should have remote release notes @@ -139,7 +142,7 @@ func (c *Changelog) Run() error { // New minor alpha, beta and rc releases get generated notes latestTags, tErr := c.impl.LatestGitHubTagsPerBranch() if tErr != nil { - return fmt.Errorf("get latest GitHub tags: %w", tErr) + return errors.Wrap(tErr, "get latest GitHub tags") } if startTag, ok := latestTags[branch]; ok { @@ -152,7 +155,7 @@ func (c *Changelog) Run() error { markdown, jsonStr, err = c.generateReleaseNotes(branch, startRev, endRev) } else { - return fmt.Errorf( + return errors.Errorf( "no latest tag available for branch %s", branch, ) } @@ -161,7 +164,7 @@ func (c *Changelog) Run() error { if c.options.CloneCVEMaps { cveDir, err := c.impl.CloneCVEData() if err != nil { - return fmt.Errorf("getting cve data maps: %w", err) + return errors.Wrap(err, "getting cve data maps") } c.options.CVEDataDir = cveDir } @@ -177,14 +180,14 @@ func (c *Changelog) Run() error { markdown, jsonStr, err = c.generateReleaseNotes(branch, startTag, endRev) } if err != nil { - return fmt.Errorf("generate release notes: %w", err) + return errors.Wrap(err, "generate release notes") } if c.options.Dependencies { logrus.Info("Generating dependency changes") deps, err := c.impl.DependencyChanges(startRev, endRev) if err != nil { - return fmt.Errorf("generate dependency changes: %w", err) + return errors.Wrap(err, "generate dependency changes") } markdown += strings.Repeat(nl, 2) + deps } @@ -192,13 +195,13 @@ func (c *Changelog) Run() error { logrus.Info("Generating TOC") toc, err := c.impl.GenerateTOC(markdown) if err != nil { - return fmt.Errorf("generate table of contents: %w", err) + return errors.Wrap(err, "generate table of contents") } // Restore the currently checked out branch currentBranch, err := c.impl.CurrentBranch(repo) if err != nil { - return fmt.Errorf("get current branch: %w", err) + return errors.Wrap(err, "get current branch") } if currentBranch != "" { defer func() { @@ -210,29 +213,29 @@ func (c *Changelog) Run() error { logrus.Infof("Checking out %s branch", git.DefaultBranch) if err := c.impl.Checkout(repo, git.DefaultBranch); err != nil { - return fmt.Errorf("checkout %s branch: %w", git.DefaultBranch, err) + return errors.Wrapf(err, "checkout %s branch", git.DefaultBranch) } logrus.Info("Writing markdown") if err := c.writeMarkdown(repo, toc, markdown, tag); err != nil { - return fmt.Errorf("write markdown: %w", err) + return errors.Wrap(err, "write markdown") } logrus.Info("Writing HTML") if err := c.writeHTML(tag, markdown); err != nil { - return fmt.Errorf("write HTML: %w", err) + return errors.Wrap(err, "write HTML") } logrus.Info("Writing JSON") if err := c.writeJSON(tag, jsonStr); err != nil { - return fmt.Errorf("write JSON: %w", err) + return errors.Wrap(err, "write JSON") } logrus.Info("Committing changes") - if err := c.commitChanges(repo, branch, tag); err != nil { - return fmt.Errorf("commit changes: %w", err) - } - return nil + return errors.Wrap( + c.commitChanges(repo, branch, tag), + "commit changes", + ) } func (c *Changelog) generateReleaseNotes( @@ -260,22 +263,22 @@ func (c *Changelog) generateReleaseNotes( } if err := c.impl.ValidateAndFinish(notesOptions); err != nil { - return "", "", fmt.Errorf("validating notes options: %w", err) + return "", "", errors.Wrap(err, "validating notes options") } releaseNotes, err := c.impl.GatherReleaseNotes(notesOptions) if err != nil { - return "", "", fmt.Errorf("gather release notes: %w", err) + return "", "", errors.Wrapf(err, "gather release notes") } doc, err := c.impl.NewDocument(releaseNotes, startRev, c.options.Tag) if err != nil { - return "", "", fmt.Errorf("create release note document: %w", err) + return "", "", errors.Wrapf(err, "create release note document") } releaseNotesJSON, err := json.MarshalIndent(releaseNotes.ByPR(), "", " ") if err != nil { - return "", "", fmt.Errorf("build release notes JSON: %w", err) + return "", "", errors.Wrapf(err, "build release notes JSON") } markdown, err = c.impl.RenderMarkdownTemplate( @@ -283,7 +286,7 @@ func (c *Changelog) generateReleaseNotes( options.GoTemplateInline+releaseNotesTemplate, ) if err != nil { - return "", "", fmt.Errorf("render release notes to markdown: %w", err) + return "", "", errors.Wrapf(err, "render release notes to markdown") } return markdown, string(releaseNotesJSON), nil @@ -308,7 +311,7 @@ func (c *Changelog) writeMarkdown( if _, err := c.impl.Stat(changelogPath); os.IsNotExist(err) { logrus.Infof("Changelog %q does not exist, creating it", changelogPath) if err := c.adaptChangelogReadmeFile(repo, tag); err != nil { - return fmt.Errorf("adapt changelog readme: %w", err) + return errors.Wrap(err, "adapt changelog readme") } return writeFile(toc, markdown) } @@ -317,12 +320,12 @@ func (c *Changelog) writeMarkdown( logrus.Infof("Adding new content to changelog file %s ", changelogPath) content, err := c.impl.ReadFile(changelogPath) if err != nil { - return fmt.Errorf("read changelog file: %w", err) + return errors.Wrap(err, "read changelog file") } tocEndIndex := bytes.Index(content, []byte(TocEnd)) if tocEndIndex < 0 { - return fmt.Errorf( + return errors.Errorf( "find table of contents end marker `%s` in %q", TocEnd, changelogPath, ) @@ -333,12 +336,12 @@ func (c *Changelog) writeMarkdown( ) mergedTOC, err := c.impl.GenerateTOC(mergedMarkdown) if err != nil { - return fmt.Errorf("generate table of contents: %w", err) + return errors.Wrap(err, "generate table of contents") } - if err := writeFile(mergedTOC, mergedMarkdown); err != nil { - return fmt.Errorf("write merged markdown: %w", err) - } - return nil + return errors.Wrap( + writeFile(mergedTOC, mergedMarkdown), + "write merged markdown", + ) } func (c *Changelog) htmlChangelogFilename(tag semver.Version) string { @@ -374,42 +377,42 @@ func addTocMarkers(toc string) string { func (c *Changelog) writeHTML(tag semver.Version, markdown string) error { content := &bytes.Buffer{} if err := c.impl.MarkdownToHTML(markdown, content); err != nil { - return fmt.Errorf("render HTML from markdown: %w", err) + return errors.Wrap(err, "render HTML from markdown") } t, err := c.impl.ParseHTMLTemplate(htmlTemplate) if err != nil { - return fmt.Errorf("parse HTML template: %w", err) + return errors.Wrap(err, "parse HTML template") } output := bytes.Buffer{} if err := c.impl.TemplateExecute(t, &output, struct { Title, Content string }{util.SemverToTagString(tag), content.String()}); err != nil { - return fmt.Errorf("execute HTML template: %w", err) + return errors.Wrap(err, "execute HTML template") } absOutputPath, err := c.impl.Abs(c.htmlChangelogFilename(tag)) if err != nil { - return fmt.Errorf("get absolute file path: %w", err) + return errors.Wrap(err, "get absolute file path") } logrus.Infof("Writing HTML file to %s", absOutputPath) - if err := c.impl.WriteFile(absOutputPath, output.Bytes(), os.FileMode(0o644)); err != nil { - return fmt.Errorf("write template: %w", err) - } - return nil + return errors.Wrap( + c.impl.WriteFile(absOutputPath, output.Bytes(), os.FileMode(0o644)), + "write template", + ) } func (c *Changelog) writeJSON(tag semver.Version, jsonStr string) error { absOutputPath, err := c.impl.Abs(c.jsonChangelogFilename(tag)) if err != nil { - return fmt.Errorf("get absolute file path: %w", err) + return errors.Wrap(err, "get absolute file path") } logrus.Infof("Writing JSON file to %s", absOutputPath) - if err := c.impl.WriteFile(absOutputPath, []byte(jsonStr), os.FileMode(0o644)); err != nil { - return fmt.Errorf("write JSON: %w", err) - } - return nil + return errors.Wrap( + c.impl.WriteFile(absOutputPath, []byte(jsonStr), os.FileMode(0o644)), + "write JSON", + ) } func (c *Changelog) lookupRemoteReleaseNotes( @@ -426,7 +429,9 @@ func (c *Changelog) lookupRemoteReleaseNotes( remoteMarkdown := remoteBase + "release-notes-draft.md" markdownStr, err = c.impl.GetURLResponse(remoteMarkdown) if err != nil { - return "", "", fmt.Errorf("fetch release notes markdown from remote: %s: %w", remoteMarkdown, err) + return "", "", errors.Wrapf(err, + "fetch release notes markdown from remote: %s", remoteMarkdown, + ) } logrus.Infof("Found remote release notes markdown on: %s", remoteMarkdown) @@ -461,7 +466,7 @@ func (c *Changelog) commitChanges( for _, filename := range changelogFiles { logrus.Infof("Adding %s to repository", filename) if err := c.impl.Add(repo, filename); err != nil { - return fmt.Errorf("add file %s to repository: %w", filename, err) + return errors.Wrapf(err, "add file %s to repository", filename) } } @@ -469,14 +474,14 @@ func (c *Changelog) commitChanges( if err := c.impl.Commit(repo, fmt.Sprintf( "CHANGELOG: Update directory for %s release", util.SemverToTagString(tag), )); err != nil { - return fmt.Errorf("committing changes into repository: %w", err) + return errors.Wrap(err, "committing changes into repository") } if branch != git.DefaultBranch { logrus.Infof("Checking out %s branch", branch) // Release branch modifications if err := c.impl.Checkout(repo, branch); err != nil { - return fmt.Errorf("checking out release branch %s: %w", branch, err) + return errors.Wrapf(err, "checking out release branch %s", branch) } // Remove all other changelog files if we’re on the the first official release @@ -484,7 +489,7 @@ func (c *Changelog) commitChanges( pattern := filepath.Join(RepoChangelogDir, "CHANGELOG-*.md") logrus.Infof("Removing unnecessary %s files", pattern) if err := c.impl.Rm(repo, true, pattern); err != nil { - return fmt.Errorf("removing %s files: %w", pattern, err) + return errors.Wrapf(err, "removing %s files", pattern) } } @@ -492,14 +497,14 @@ func (c *Changelog) commitChanges( if err := c.impl.Checkout( repo, git.DefaultBranch, releaseChangelog, ); err != nil { - return fmt.Errorf("check out main branch changelog: %w", err) + return errors.Wrap(err, "check out main branch changelog") } logrus.Info("Committing changes to release branch in repository") if err := c.impl.Commit(repo, fmt.Sprintf( "Update %s for %s", releaseChangelog, util.SemverToTagString(tag), )); err != nil { - return fmt.Errorf("committing changes into repository: %w", err) + return errors.Wrap(err, "committing changes into repository") } } @@ -512,7 +517,7 @@ func (c *Changelog) adaptChangelogReadmeFile( targetFile := filepath.Join(repo.Dir(), RepoChangelogDir, "README.md") readme, err := c.impl.ReadFile(targetFile) if err != nil { - return fmt.Errorf("read changelog README.md: %w", err) + return errors.Wrap(err, "read changelog README.md") } cf := filepath.Base(markdownChangelogFilename(tag)) @@ -535,7 +540,7 @@ func (c *Changelog) adaptChangelogReadmeFile( if err := c.impl.WriteFile( targetFile, []byte(strings.Join(res, nl)+nl), os.FileMode(0o644)); err != nil { - return fmt.Errorf("write changelog README.md: %w", err) + return errors.Wrap(err, "write changelog README.md") } return nil } diff --git a/pkg/changelog/impl.go b/pkg/changelog/impl.go index 554ef74fe6c..e9be4247232 100644 --- a/pkg/changelog/impl.go +++ b/pkg/changelog/impl.go @@ -17,13 +17,13 @@ limitations under the License. package changelog import ( - "fmt" "io" "os" "path/filepath" "text/template" "github.com/blang/semver" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/yuin/goldmark" "github.com/yuin/goldmark/extension" @@ -229,19 +229,19 @@ func (*defaultImpl) Rm(repo *git.Repo, force bool, files ...string) error { func (*defaultImpl) CloneCVEData() (cveDir string, err error) { tmpdir, err := os.MkdirTemp(os.TempDir(), "cve-maps-") if err != nil { - return "", fmt.Errorf("creating temporary dir for CVE data: %w", err) + return "", errors.Wrap(err, "creating temporary dir for CVE data") } // Create a new GCS client gcs := object.NewGCS() remoteSrc, err := gcs.NormalizePath(object.GcsPrefix + filepath.Join(cve.Bucket, cve.Directory)) if err != nil { - return "", fmt.Errorf("normalizing cve bucket path: %w", err) + return "", errors.Wrap(err, "normalizing cve bucket path") } bucketExists, err := gcs.PathExists(remoteSrc) if err != nil { - return "", fmt.Errorf("checking if CVE directory exists: %w", err) + return "", errors.Wrap(err, "checking if CVE directory exists") } if !bucketExists { logrus.Warnf("CVE data maps not found in bucket location: %s", remoteSrc) @@ -250,7 +250,7 @@ func (*defaultImpl) CloneCVEData() (cveDir string, err error) { // Rsync the CVE files to the temp dir if err := gcs.RsyncRecursive(remoteSrc, tmpdir); err != nil { - return "", fmt.Errorf("copying release directory to bucket: %w", err) + return "", errors.Wrap(err, "copying release directory to bucket") } logrus.Infof("Successfully synchronized CVE data maps from %s", remoteSrc) return tmpdir, nil diff --git a/pkg/cve/client.go b/pkg/cve/client.go index 3af1a80983e..29e00941c7b 100644 --- a/pkg/cve/client.go +++ b/pkg/cve/client.go @@ -17,10 +17,11 @@ limitations under the License. package cve import ( - "fmt" "os" "path/filepath" + "github.com/pkg/errors" + "k8s.io/release/pkg/release" "sigs.k8s.io/release-sdk/object" ) @@ -63,12 +64,12 @@ func NewClient() *Client { // Write writes a map to the bucket func (c *Client) Write(cve, mapPath string) error { if err := c.impl.CheckID(cve); err != nil { - return fmt.Errorf("checking CVE identifier: %w", err) + return errors.Wrap(err, "checking CVE identifier") } // Validate the information in the data maps if err := c.impl.ValidateCVEMap(cve, mapPath, &c.options); err != nil { - return fmt.Errorf("validating CVE data in map file: %w", err) + return errors.Wrap(err, "validating CVE data in map file") } destPath := object.GcsPrefix + filepath.Join( @@ -79,7 +80,7 @@ func (c *Client) Write(cve, mapPath string) error { if err := c.impl.CopyFile( mapPath, destPath, &c.options, ); err != nil { - return fmt.Errorf("writing %s map file to CVE bucket: %w", cve, err) + return errors.Wrapf(err, "writing %s map file to CVE bucket", cve) } return nil @@ -93,7 +94,7 @@ func (c *Client) CheckID(cve string) error { // Delete removes a CVE entry from the security bucket location func (c *Client) Delete(cve string) error { if err := c.impl.CheckID(cve); err != nil { - return fmt.Errorf("checking CVE identifier: %w", err) + return errors.Wrap(err, "checking CVE identifier") } return c.impl.DeleteFile( diff --git a/pkg/cve/cve.go b/pkg/cve/cve.go index 9b374ab82e0..8997bffa02e 100644 --- a/pkg/cve/cve.go +++ b/pkg/cve/cve.go @@ -17,10 +17,10 @@ limitations under the License. package cve import ( - "errors" "fmt" "regexp" + "github.com/pkg/errors" cvss "github.com/spiegel-im-spiegel/go-cvss/v3/metric" ) @@ -83,7 +83,7 @@ func (cve *CVE) Validate() error { if _, ok := map[string]bool{ "None": true, "Low": true, "Medium": true, "High": true, "Critical": true, }[cve.CVSSRating]; !ok { - return errors.New("invalid CVSS rating") + return errors.New("Invalid CVSS rating") } // Check vector string is not empty @@ -94,7 +94,7 @@ func (cve *CVE) Validate() error { // Parse the vector string to make sure it is well formed bm, err := cvss.NewBase().Decode(cve.CVSSVector) if err != nil { - return fmt.Errorf("parsing CVSS vector string: %w", err) + return errors.Wrap(err, "parsing CVSS vector string") } cve.CalcLink = fmt.Sprintf( "https://www.first.org/cvss/calculator/%s#%s", bm.Ver.String(), cve.CVSSVector, @@ -108,12 +108,12 @@ func (cve *CVE) Validate() error { } if err := ValidateID(cve.ID); err != nil { - return fmt.Errorf("checking CVE ID: %w", err) + return errors.Wrap(err, "checking CVE ID") } // Title and description must not be empty if cve.Title == "" { - return errors.New("title missing from CVE data") + return errors.New("Title missing from CVE data") } if cve.Description == "" { diff --git a/pkg/cve/impl.go b/pkg/cve/impl.go index bd07e648000..963b2031f82 100644 --- a/pkg/cve/impl.go +++ b/pkg/cve/impl.go @@ -18,7 +18,6 @@ package cve import ( "context" - "errors" "fmt" "os" "path/filepath" @@ -26,6 +25,7 @@ import ( "strings" "cloud.google.com/go/storage" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" @@ -56,15 +56,15 @@ func (impl *defaultClientImplementation) CheckBucketWriteAccess(opts *ClientOpti client, err := storage.NewClient(context.Background()) if err != nil { - return fmt.Errorf( + return errors.Wrap(err, "fetching gcloud credentials, try running "+ - `"gcloud auth application-default login": %w`, err, + `"gcloud auth application-default login"`, ) } bucket := client.Bucket(opts.Bucket) if bucket == nil { - return fmt.Errorf( + return errors.Errorf( "unable to open CVE bucket: %s", opts.Bucket, ) } @@ -75,10 +75,10 @@ func (impl *defaultClientImplementation) CheckBucketWriteAccess(opts *ClientOpti context.Background(), requiredGCSPerms, ) if err != nil { - return fmt.Errorf("getting bucket permissions: %w", err) + return errors.Wrap(err, "getting bucket permissions") } if len(perms) != 1 { - return fmt.Errorf( + return errors.Errorf( "GCP user must have at least %s permissions on bucket %s", requiredGCSPerms, opts.Bucket, ) @@ -92,22 +92,22 @@ func (impl *defaultClientImplementation) DeleteFile( path string, opts *ClientOptions, ) error { if err := impl.CheckBucketWriteAccess(opts); err != nil { - return fmt.Errorf("checking bucket permissions to delete data: %w", err) + return errors.Wrap(err, "checking bucket permissions to delete data") } gcs := object.NewGCS() path, err := gcs.NormalizePath(path) if err != nil { - return fmt.Errorf("normalizing bucket path: %w", err) + return errors.Wrap(err, "normalizing bucket path") } if err := impl.CheckBucketPath(path, opts); err != nil { - return fmt.Errorf("checking path to delete file: %w", err) + return errors.Wrap(err, "checking path to delete file") } if !strings.HasSuffix(path, ".yaml") { return errors.New("only yaml files can be deleted") } exists, err := gcs.PathExists(path) if err != nil { - return fmt.Errorf("checking if cve entry exists: %w", err) + return errors.Wrap(err, "checking if cve entry exists") } if !exists { return errors.New("specified CVE entry not found") @@ -121,7 +121,7 @@ func (impl *defaultClientImplementation) CopyToTemp( ) (*os.File, error) { dir, err := os.MkdirTemp(os.TempDir(), "cve-maps-") if err != nil { - return nil, fmt.Errorf("creating temp dir: %w", err) + return nil, errors.Wrap(err, "creating temp dir") } gcs := object.NewGCS() if err := gcs.CopyToLocal( @@ -129,7 +129,7 @@ func (impl *defaultClientImplementation) CopyToTemp( opts.Bucket, opts.Directory, cve+mapExt, ), dir, ); err != nil { - return nil, fmt.Errorf("copying CVE %s to tempfile: %w", cve, err) + return nil, errors.Wrapf(err, "copying CVE %s to tempfile", cve) } return os.Open(filepath.Join(dir, cve+mapExt)) } @@ -139,7 +139,7 @@ func (impl *defaultClientImplementation) CopyFile( src, dest string, opts *ClientOptions, ) error { if err := impl.CheckBucketWriteAccess(opts); err != nil { - return fmt.Errorf("checking bucket permissions to copy data: %w", err) + return errors.Wrap(err, "checking bucket permissions to copy data") } gcs := object.NewGCS() gcs.SetOptions( @@ -147,14 +147,14 @@ func (impl *defaultClientImplementation) CopyFile( ) path, err := gcs.NormalizePath(dest) if err != nil { - return fmt.Errorf("normalizing bucket path: %w", err) + return errors.Wrap(err, "normalizing bucket path") } if err := impl.CheckBucketPath(path, opts); err != nil { - return fmt.Errorf("checking path to copy file: %w", err) + return errors.Wrap(err, "checking path to copy file") } if err := gcs.CopyToRemote(src, path); err != nil { - return fmt.Errorf("copying %s to bucket: %w", path, err) + return errors.Wrapf(err, "copying %s to bucket", path) } // Copy the file to the bucket @@ -168,7 +168,7 @@ func (impl *defaultClientImplementation) CheckBucketPath( g := object.NewGCS() path, err := g.NormalizePath(path) if err != nil { - return fmt.Errorf("normalizing CVE bucket path: %w", err) + return errors.Wrap(err, "normalizing CVE bucket path") } path = strings.TrimPrefix(path, object.GcsPrefix) @@ -193,7 +193,7 @@ func (impl *defaultClientImplementation) ValidateCVEMap( // Parse the data map maps, err := notes.ParseReleaseNotesMap(path) if err != nil { - return fmt.Errorf("parsing CVE data map: %w", err) + return errors.Wrap(err, "parsing CVE data map") } // Cycle all data maps in file @@ -205,10 +205,10 @@ func (impl *defaultClientImplementation) ValidateCVEMap( // Cast the datafield as CVE data cvedata := CVE{} if err := cvedata.ReadRawInterface(dataMap.DataFields["cve"]); err != nil { - return fmt.Errorf("reading CVE data from YAML file: %w", err) + return errors.Wrap(err, "reading CVE data from YAML file") } if err := cvedata.Validate(); err != nil { - return fmt.Errorf("validating map #%d in file %s: %w", i, path, err) + return errors.Wrapf(err, "validating map #%d in file %s", i, path) } if cvedata.ID != cveID { @@ -228,7 +228,7 @@ func (impl *defaultClientImplementation) CreateEmptyFile(cve string, opts *Clien file *os.File, err error, ) { if err := impl.CheckID(cve); err != nil { - return nil, fmt.Errorf("checking new CVE ID: %w", err) + return nil, errors.Wrap(err, "checking new CVE ID") } // Add a relnote-compatible struct with only the CVE data @@ -247,18 +247,18 @@ func (impl *defaultClientImplementation) CreateEmptyFile(cve string, opts *Clien // Marshall the data struct into yaml yamlCode, err := yaml.Marshal(noteMap) if err != nil { - return nil, fmt.Errorf("marshalling CVE data map: %w", err) + return nil, errors.Wrap(err, "marshalling CVE data map") } file, err = os.CreateTemp(os.TempDir(), "cve-data-*.yaml") if err != nil { - return nil, fmt.Errorf("creating new map file: %w", err) + return nil, errors.Wrap(err, "creating new map file") } if _, err := file.WriteString(newMapHeader); err != nil { - return nil, fmt.Errorf("writing empty CVE header: %w", err) + return nil, errors.Wrap(err, "writing empty CVE header") } if _, err := file.Write(yamlCode); err != nil { - return nil, fmt.Errorf("writing yaml code to file: %w", err) + return nil, errors.Wrap(err, "writing yaml code to file") } return file, nil @@ -270,7 +270,7 @@ func (impl *defaultClientImplementation) EntryExists( ) (exists bool, err error) { // Check the ID string to be valid if err := ValidateID(cveID); err != nil { - return exists, fmt.Errorf("checking CVE ID string: %w", err) + return exists, errors.Wrap(err, "checking CVE ID string") } // Verify the expected file exists in the bucket @@ -282,7 +282,7 @@ func (impl *defaultClientImplementation) EntryExists( ), ) if err != nil { - return exists, fmt.Errorf("checking if CVE entry already exists: %w", err) + return exists, errors.Wrap(err, "checking if CVE entry already exists") } return gcs.PathExists(path) } diff --git a/pkg/fastforward/fastforward.go b/pkg/fastforward/fastforward.go index 2403712b93d..bf5e071e8bd 100644 --- a/pkg/fastforward/fastforward.go +++ b/pkg/fastforward/fastforward.go @@ -17,12 +17,12 @@ limitations under the License. package fastforward import ( - "errors" "fmt" "net/url" "path/filepath" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/gcp/gcb" "k8s.io/release/pkg/release" @@ -78,7 +78,7 @@ Please only answer after you have validated the changes.` func (f *FastForward) Run() (err error) { if f.options.Submit { if err := f.prepareToolRepo(); err != nil { - return fmt.Errorf("prepare tool repo: %w", err) + return errors.Wrap(err, "prepare tool repo") } logrus.Info("Submitting GCB job") options := gcb.NewDefaultOptions() @@ -92,7 +92,7 @@ func (f *FastForward) Run() (err error) { repo, err := f.prepareKubernetesRepo() if err != nil { - return fmt.Errorf("prepare repository: %w", err) + return errors.Wrap(err, "prepare repository") } if !f.options.NoMock { @@ -105,13 +105,13 @@ func (f *FastForward) Run() (err error) { logrus.Info("No release branch specified, finding the latest") branch, err = f.RepoLatestReleaseBranch(repo) if err != nil { - return fmt.Errorf("finding latest release branch: %w", err) + return errors.Wrap(err, "finding latest release branch") } logrus.Infof("Found latest release branch: %s", branch) notRequired, err := f.noFastForwardRequired(repo, branch) if err != nil { - return fmt.Errorf("check if fast forward is required: %w", err) + return errors.Wrap(err, "check if fast forward is required") } if notRequired { logrus.Infof( @@ -123,13 +123,13 @@ func (f *FastForward) Run() (err error) { } else { logrus.Infof("Checking if %q is a release branch", branch) if isReleaseBranch := f.IsReleaseBranch(branch); !isReleaseBranch { - return fmt.Errorf("%s is not a release branch", branch) + return errors.Errorf("%s is not a release branch", branch) } logrus.Info("Checking if branch is available on the default remote") branchExists, err := f.RepoHasRemoteBranch(repo, branch) if err != nil { - return fmt.Errorf("checking if branch exists on the default remote: %w", err) + return errors.Wrap(err, "checking if branch exists on the default remote") } if !branchExists { return errors.New("branch does not exist on the default remote") @@ -146,7 +146,7 @@ func (f *FastForward) Run() (err error) { // Restore the currently checked out branch afterwards currentBranch, err := f.RepoCurrentBranch(repo) if err != nil { - return fmt.Errorf("unable to retrieve current branch: %w", err) + return errors.Wrap(err, "unable to retrieve current branch") } defer func() { if err := f.RepoCheckout(repo, currentBranch); err != nil { @@ -157,13 +157,13 @@ func (f *FastForward) Run() (err error) { logrus.Info("Checking out release branch") if err := f.RepoCheckout(repo, branch); err != nil { - return fmt.Errorf("checking out branch %s: %w", branch, err) + return errors.Wrapf(err, "checking out branch %s", branch) } logrus.Infof("Finding merge base between %q and %q", git.DefaultBranch, branch) mergeBase, err := f.RepoMergeBase(repo, git.DefaultBranch, branch) if err != nil { - return fmt.Errorf("find merge base: %w", err) + return errors.Wrap(err, "find merge base") } // Verify the tags @@ -175,7 +175,7 @@ func (f *FastForward) Run() (err error) { WithTags(), ) if err != nil { - return fmt.Errorf("describe latest main tag: %w", err) + return errors.Wrap(err, "describe latest main tag") } mergeBaseTag, err := f.RepoDescribe( repo, @@ -185,12 +185,12 @@ func (f *FastForward) Run() (err error) { WithTags(), ) if err != nil { - return fmt.Errorf("describe latest merge base tag: %w", err) + return errors.Wrap(err, "describe latest merge base tag") } logrus.Infof("Merge base tag is: %s", mergeBaseTag) if mainTag != mergeBaseTag { - return fmt.Errorf( + return errors.Errorf( "unable to fast forward: tag %q does not match %q", mainTag, mergeBaseTag, ) @@ -199,18 +199,18 @@ func (f *FastForward) Run() (err error) { releaseRev, err := f.RepoHead(repo) if err != nil { - return fmt.Errorf("get release rev: %w", err) + return errors.Wrap(err, "get release rev") } logrus.Infof("Latest release branch revision is %s", releaseRev) logrus.Info("Merging main branch changes into release branch") if err := f.RepoMerge(repo, f.options.MainRef); err != nil { - return fmt.Errorf("merge main ref: %w", err) + return errors.Wrap(err, "merge main ref") } headRev, err := f.RepoHead(repo) if err != nil { - return fmt.Errorf("get HEAD rev: %w", err) + return errors.Wrap(err, "get HEAD rev") } prepushMessage(f.RepoDir(repo), branch, f.options.MainRef, releaseRev, headRev) @@ -221,14 +221,14 @@ func (f *FastForward) Run() (err error) { } else { _, pushUpstream, err = f.Ask(pushUpstreamQuestion, "yes", 3) if err != nil { - return fmt.Errorf("ask upstream question: %w", err) + return errors.Wrap(err, "ask upstream question") } } if pushUpstream { logrus.Infof("Pushing %s branch", branch) if err := f.RepoPush(repo, branch); err != nil { - return fmt.Errorf("push to repo: %w", err) + return errors.Wrap(err, "push to repo") } } @@ -270,7 +270,7 @@ func (f *FastForward) noFastForwardRequired(repo *git.Repo, branch string) (bool tagExists, err := f.RepoHasRemoteTag(repo, version) if err != nil { - return false, fmt.Errorf("finding remote tag %s: %w", version, err) + return false, errors.Wrapf(err, "finding remote tag %s", version) } return tagExists, nil @@ -288,7 +288,7 @@ func (f *FastForward) prepareKubernetesRepo() (*git.Repo, error) { logrus.Info("Cloning repository by using HTTPs") repo, err := f.CloneOrOpenGitHubRepo(f.options.RepoPath, k8sOrg, k8sRepo, false) if err != nil { - return nil, fmt.Errorf("clone or open k/k GitHub repository: %w", err) + return nil, errors.Wrap(err, "clone or open k/k GitHub repository") } if f.IsDefaultK8sUpstream() { @@ -298,7 +298,7 @@ func (f *FastForward) prepareKubernetesRepo() (*git.Repo, error) { Host: "github.com", Path: filepath.Join(git.DefaultGithubOrg, git.DefaultGithubRepo), }).String()); err != nil { - return nil, fmt.Errorf("changing git remote of repository: %w", err) + return nil, errors.Wrap(err, "changing git remote of repository") } } else { logrus.Info("Using non-default k8s upstream, doing no git modifications") @@ -310,7 +310,7 @@ func (f *FastForward) prepareKubernetesRepo() (*git.Repo, error) { logrus.Info("Cloning repository by using SSH") repo, err := f.CloneOrOpenDefaultGitHubRepoSSH(f.options.RepoPath) if err != nil { - return nil, fmt.Errorf("clone or open k/k GitHub repository: %w", err) + return nil, errors.Wrap(err, "clone or open k/k GitHub repository") } return repo, nil @@ -325,10 +325,10 @@ func (f *FastForward) prepareToolRepo() error { tmpPath, err := f.MkdirTemp("", "k-release-") if err != nil { - return fmt.Errorf("create temp directory: %w", err) + return errors.Wrap(err, "create temp directory") } if err := f.RemoveAll(tmpPath); err != nil { - return fmt.Errorf("remove temp directory: %w", err) + return errors.Wrap(err, "remove temp directory") } if _, err := f.CloneOrOpenGitHubRepo( tmpPath, @@ -336,10 +336,10 @@ func (f *FastForward) prepareToolRepo() error { release.DefaultToolRepo, false, ); err != nil { - return fmt.Errorf("clone tool repository: %w", err) + return errors.Wrap(err, "clone tool repository") } if err := f.Chdir(tmpPath); err != nil { - return fmt.Errorf("change directory: %w", err) + return errors.Wrap(err, "change directory") } return nil } diff --git a/pkg/fastforward/fastforward_test.go b/pkg/fastforward/fastforward_test.go index 80dc3f37ad7..44d27e16207 100644 --- a/pkg/fastforward/fastforward_test.go +++ b/pkg/fastforward/fastforward_test.go @@ -17,9 +17,9 @@ limitations under the License. package fastforward import ( - "errors" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/require" "k8s.io/release/pkg/fastforward/fastforwardfakes" ) diff --git a/pkg/gcp/auth/auth.go b/pkg/gcp/auth/auth.go index b09a21dcbfa..908ecaa599e 100644 --- a/pkg/gcp/auth/auth.go +++ b/pkg/gcp/auth/auth.go @@ -17,10 +17,9 @@ limitations under the License. package auth import ( - "errors" - "fmt" "strings" + "github.com/pkg/errors" "sigs.k8s.io/release-sdk/gcli" ) @@ -51,7 +50,7 @@ func ConfigureDocker() error { "configure-docker", ) if err != nil { - return fmt.Errorf("running 'gcloud auth configure-docker': %w", err) + return errors.Wrapf(err, "running 'gcloud auth configure-docker'") } return nil diff --git a/pkg/gcp/build/build.go b/pkg/gcp/build/build.go index 3df21b62627..81448a111bd 100644 --- a/pkg/gcp/build/build.go +++ b/pkg/gcp/build/build.go @@ -17,7 +17,6 @@ limitations under the License. package build import ( - "errors" "fmt" "os" "path" @@ -29,6 +28,7 @@ import ( "github.com/google/uuid" "github.com/olekukonko/tablewriter" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/net/context" "google.golang.org/api/cloudbuild/v1" @@ -82,7 +82,7 @@ func PrepareBuilds(o *Options) error { if bazelWorkspace := os.Getenv("BUILD_WORKSPACE_DIRECTORY"); bazelWorkspace != "" { if err := os.Chdir(bazelWorkspace); err != nil { - return fmt.Errorf("failed to chdir to bazel workspace (%s): %w", bazelWorkspace, err) + return errors.Wrapf(err, "failed to chdir to bazel workspace (%s)", bazelWorkspace) } } @@ -97,7 +97,7 @@ func PrepareBuilds(o *Options) error { // when the config directory is not the same as the build directory. absConfigDir, absErr := filepath.Abs(o.ConfigDir) if absErr != nil { - return fmt.Errorf("could not resolve absolute path for config directory: %w", absErr) + return errors.Wrapf(absErr, "could not resolve absolute path for config directory") } o.ConfigDir = absConfigDir @@ -105,14 +105,14 @@ func PrepareBuilds(o *Options) error { configDirErr := o.ValidateConfigDir() if configDirErr != nil { - return fmt.Errorf("could not validate config directory: %w", configDirErr) + return errors.Wrapf(configDirErr, "could not validate config directory") } logrus.Infof("Config directory: %s", o.ConfigDir) logrus.Infof("Changing to build directory: %s", o.BuildDir) if err := os.Chdir(o.BuildDir); err != nil { - return fmt.Errorf("failed to chdir to build directory (%s): %w", o.BuildDir, err) + return errors.Wrapf(err, "failed to chdir to build directory (%s)", o.BuildDir) } return nil @@ -143,7 +143,7 @@ func (o *Options) ValidateConfigDir() error { func (o *Options) uploadBuildDir(targetBucket string) (string, error) { f, err := os.CreateTemp("", "") if err != nil { - return "", fmt.Errorf("failed to create temp file: %w", err) + return "", errors.Wrapf(err, "failed to create temp file") } name := f.Name() _ = f.Close() @@ -151,7 +151,7 @@ func (o *Options) uploadBuildDir(targetBucket string) (string, error) { logrus.Infof("Creating source tarball at %s...", name) if err := tar.Compress(name, ".", regexp.MustCompile(".git")); err != nil { - return "", fmt.Errorf("create tarball: %w", err) + return "", errors.Wrap(err, "create tarball") } u := uuid.New() @@ -161,7 +161,7 @@ func (o *Options) uploadBuildDir(targetBucket string) (string, error) { name, uploaded, ); err != nil { - return "", fmt.Errorf("upload files to GCS: %w", err) + return "", errors.Wrap(err, "upload files to GCS") } return uploaded, nil @@ -228,9 +228,9 @@ func RunSingleJob(o *Options, jobName, uploaded, version string, subs map[string } if diskSizeInt > 1000 { - return errors.New("selected disk size must be no greater than 1000 GB") + return errors.New("Selected disk size must be no greater than 1000 GB") } else if diskSizeInt <= 0 { - return errors.New("selected disk size must be greater than 0 GB") + return errors.New("Selected disk size must be greater than 0 GB") } diskSizeArg := fmt.Sprintf("--disk-size=%s", o.DiskSize) @@ -243,7 +243,7 @@ func RunSingleJob(o *Options, jobName, uploaded, version string, subs map[string p := path.Join(o.LogDir, strings.ReplaceAll(jobName, "/", "-")+".log") f, err := os.Create(p) if err != nil { - return fmt.Errorf("couldn't create %s: %w", p, err) + return errors.Wrapf(err, "couldn't create %s", p) } defer f.Close() @@ -252,7 +252,7 @@ func RunSingleJob(o *Options, jobName, uploaded, version string, subs map[string logrus.Infof("cloudbuild command to send to gcp: %s", cmd.String()) if err := cmd.RunSuccess(); err != nil { - return fmt.Errorf("error running %s: %w", cmd.String(), err) + return errors.Wrapf(err, "error running %s", cmd.String()) } return nil @@ -264,10 +264,10 @@ func getVariants(o *Options) (variants, error) { content, err := os.ReadFile(path.Join(o.ConfigDir, "variants.yaml")) if err != nil { if !os.IsNotExist(err) { - return nil, fmt.Errorf("failed to load variants.yaml: %w", err) + return nil, errors.Wrapf(err, "failed to load variants.yaml") } if o.Variant != "" { - return nil, fmt.Errorf("no variants.yaml found, but a build variant (%q) was specified", o.Variant) + return nil, errors.Errorf("no variants.yaml found, but a build variant (%q) was specified", o.Variant) } return nil, nil } @@ -275,12 +275,12 @@ func getVariants(o *Options) (variants, error) { Variants variants `json:"variants"` }{} if err := yaml.UnmarshalStrict(content, &v); err != nil { - return nil, fmt.Errorf("failed to read variants.yaml: %w", err) + return nil, errors.Wrapf(err, "failed to read variants.yaml") } if o.Variant != "" { va, ok := v.Variants[o.Variant] if !ok { - return nil, fmt.Errorf("requested variant %q, which is not present in variants.yaml", o.Variant) + return nil, errors.Errorf("requested variant %q, which is not present in variants.yaml", o.Variant) } return variants{o.Variant: va}, nil } @@ -294,7 +294,7 @@ func RunBuildJobs(o *Options) []error { var err error uploaded, err = o.uploadBuildDir(o.ScratchBucket + gcsSourceDir) if err != nil { - return []error{fmt.Errorf("failed to upload source: %w", err)} + return []error{errors.Wrapf(err, "failed to upload source")} } } } else { @@ -341,7 +341,7 @@ func RunBuildJobs(o *Options) []error { logrus.Infof("Starting job %q...", job) if err := RunSingleJob(o, job, uploaded, tag, mergeMaps(extraSubs, vc)); err != nil { logrus.Infof("Job %q failed: %v", job, err) - jobErrors = append(jobErrors, fmt.Errorf("job %q failed: %w", job, err)) + jobErrors = append(jobErrors, errors.Wrapf(err, "job %q failed", job)) } else { logrus.Infof("Job %q completed", job) } @@ -367,12 +367,12 @@ func ListJobs(project string, lastJobs int64) error { service, err := cloudbuild.NewService(ctx, opts) if err != nil { - return fmt.Errorf("failed to fetching gcloud credentials... try running \"gcloud auth application-default login\": %w", err) + return errors.Wrap(err, "failed to fetching gcloud credentials... try running \"gcloud auth application-default login\"") } req, err := service.Projects.Builds.List(project).PageSize(lastJobs).Do() if err != nil { - return fmt.Errorf("failed to listing the builds: %w", err) + return errors.Wrap(err, "failed to listing the builds") } table := tablewriter.NewWriter(os.Stdout) @@ -392,12 +392,12 @@ func GetJobsByTag(project, tagsFilter string) ([]*cloudbuild.Build, error) { service, err := cloudbuild.NewService(ctx, opts) if err != nil { - return nil, fmt.Errorf("failed to fetching gcloud credentials... try running \"gcloud auth application-default login\": %w", err) + return nil, errors.Wrap(err, "failed to fetching gcloud credentials... try running \"gcloud auth application-default login\"") } req, err := service.Projects.Builds.List(project).Filter(tagsFilter).PageSize(50).Do() if err != nil { - return nil, fmt.Errorf("failed to listing the builds: %w", err) + return nil, errors.Wrap(err, "failed to listing the builds") } return req.Builds, nil diff --git a/pkg/gcp/gcb/gcb.go b/pkg/gcp/gcb/gcb.go index 0d5c2e705ad..f7c9f5b3a75 100644 --- a/pkg/gcp/gcb/gcb.go +++ b/pkg/gcp/gcb/gcb.go @@ -19,7 +19,6 @@ package gcb //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate import ( - "errors" "fmt" "os" "path/filepath" @@ -27,6 +26,7 @@ import ( "strings" "github.com/blang/semver" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/gcp/auth" @@ -161,7 +161,7 @@ func (o *Options) Validate() error { if o.Branch == git.DefaultBranch { if o.ReleaseType == release.ReleaseTypeRC || o.ReleaseType == release.ReleaseTypeOfficial { - return fmt.Errorf("cannot cut a release candidate or an official release from %s", git.DefaultBranch) + return errors.Errorf("cannot cut a release candidate or an official release from %s", git.DefaultBranch) } } else { if o.ReleaseType == release.ReleaseTypeAlpha || o.ReleaseType == release.ReleaseTypeBeta { @@ -183,7 +183,7 @@ func (o *Options) Validate() error { // Submit is the main method responsible for submitting release jobs to GCB. func (g *GCB) Submit() error { if err := g.options.Validate(); err != nil { - return fmt.Errorf("validating GCB options: %w", err) + return errors.Wrap(err, "validating GCB options") } toolOrg := release.GetToolOrg() @@ -191,15 +191,15 @@ func (g *GCB) Submit() error { toolRef := release.GetToolRef() if err := gcli.PreCheck(); err != nil { - return fmt.Errorf("pre-checking for GCP package usage: %w", err) + return errors.Wrap(err, "pre-checking for GCP package usage") } if err := g.repoClient.Open(); err != nil { - return fmt.Errorf("open release repo: %w", err) + return errors.Wrap(err, "open release repo") } if err := g.repoClient.CheckState(toolOrg, toolRepo, toolRef, g.options.NoMock); err != nil { - return fmt.Errorf("verifying repository state: %w", err) + return errors.Wrap(err, "verifying repository state") } logrus.Infof("Running GCB with the following options: %+v", g.options) @@ -286,14 +286,13 @@ func (g *GCB) Submit() error { version, err := g.repoClient.GetTag() if err != nil { - return fmt.Errorf("getting current tag: %w", err) + return errors.Wrap(err, "getting current tag") } - if err := build.RunSingleJob(&g.options.Options, "", "", version, gcbSubs); err != nil { - return fmt.Errorf("run GCB job: %w", err) - } - - return nil + return errors.Wrap( + build.RunSingleJob(&g.options.Options, "", "", version, gcbSubs), + "run GCB job", + ) } // SetGCBSubstitutions takes a set of `Options` and returns a map of GCB @@ -334,7 +333,7 @@ func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef string) (map[string // If the kubecross version is not set, we will get a 404 from GitHub. // In that case, we do not err but use the latest version (unless we're on main branch) if g.options.Branch == git.DefaultBranch || !strings.Contains(err.Error(), "404") { - return gcbSubs, fmt.Errorf("retrieve kube-cross version: %w", err) + return gcbSubs, errors.Wrap(err, "retrieve kube-cross version") } logrus.Infof("KubeCross version not set for %s, falling back to latest", g.options.Branch) } @@ -343,7 +342,7 @@ func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef string) (map[string if g.options.Branch != git.DefaultBranch { kcVersionLatest, err = kc.Latest() if err != nil { - return gcbSubs, fmt.Errorf("retrieve latest kube-cross version: %w", err) + return gcbSubs, errors.Wrap(err, "retrieve latest kube-cross version") } // if kcVersionBranch is empty, the branch does not exist yet, we use @@ -362,20 +361,20 @@ func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef string) (map[string buildVersion := g.options.BuildVersion if g.options.Release && buildVersion == "" { - return gcbSubs, errors.New("build version must be specified when sending a release GCB run") + return gcbSubs, errors.New("Build version must be specified when sending a release GCB run") } if g.options.Stage && g.options.BuildAtHead { hash, err := git.LSRemoteExec(git.GetDefaultKubernetesRepoURL(), "rev-parse", g.options.Branch) if err != nil { - return gcbSubs, fmt.Errorf( - "execute rev-parse for branch %s: %w", g.options.Branch, err, + return gcbSubs, errors.Wrapf( + err, "execute rev-parse for branch %s", g.options.Branch, ) } fields := strings.Fields(hash) if len(fields) < 1 { - return gcbSubs, fmt.Errorf("unexpected output: %s", hash) + return gcbSubs, errors.Errorf("unexpected output: %s", hash) } buildVersion = fields[0] @@ -395,25 +394,25 @@ func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef string) (map[string buildVersionSemver, err := util.TagStringToSemver(buildVersion) if err != nil { - return gcbSubs, fmt.Errorf("parse build version: %w", err) + return gcbSubs, errors.Wrap(err, "parse build version") } createBranch, err := g.releaseClient.NeedsCreation( g.options.Branch, g.options.ReleaseType, buildVersionSemver, ) if err != nil { - return nil, fmt.Errorf("check if branch needs to be created: %w", err) + return nil, errors.Wrap(err, "check if branch needs to be created") } versions, err := g.releaseClient.GenerateReleaseVersion( g.options.ReleaseType, buildVersion, g.options.Branch, createBranch, ) if err != nil { - return nil, fmt.Errorf("generate release version: %w", err) + return nil, errors.Wrap(err, "generate release version") } primeSemver, err := util.TagStringToSemver(versions.Prime()) if err != nil { - return gcbSubs, fmt.Errorf("parse prime version: %w", err) + return gcbSubs, errors.Wrap(err, "parse prime version") } gcbSubs["MAJOR_VERSION_TAG"] = strconv.FormatUint(primeSemver.Major, 10) diff --git a/pkg/gcp/gcb/history.go b/pkg/gcp/gcb/history.go index 34cff6e9448..34a42002b6a 100644 --- a/pkg/gcp/gcb/history.go +++ b/pkg/gcp/gcb/history.go @@ -17,12 +17,12 @@ limitations under the License. package gcb import ( - "errors" "fmt" "strings" "time" "github.com/olekukonko/tablewriter" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/api/cloudbuild/v1" @@ -105,7 +105,7 @@ var status = map[string]string{ func (h *History) Run() error { from, to, err := h.parseDateRange() if err != nil { - return fmt.Errorf("parse from and to dates: %w", err) + return errors.Wrap(err, "parse from and to dates") } logrus.Infof("Running history with the following options: %+v", h.opts) @@ -115,7 +115,7 @@ func (h *History) Run() error { ) jobs, err := h.impl.GetJobsByTag(h.opts.Project, tagFilter) if err != nil { - return fmt.Errorf("get GCP build jobs by tag: %w", err) + return errors.Wrap(err, "get GCP build jobs by tag") } tableString := &strings.Builder{} @@ -158,11 +158,11 @@ func (h *History) Run() error { const layout = "2006-01-02T15:04:05.99Z" tStart, err := h.impl.ParseTime(layout, start) if err != nil { - return fmt.Errorf("parsing the start job time: %w", err) + return errors.Wrap(err, "parsing the start job time") } tEnd, err := h.impl.ParseTime(layout, end) if err != nil { - return fmt.Errorf("parsing the end job time: %w", err) + return errors.Wrap(err, "parsing the end job time") } diff := tEnd.Sub(tStart) out := time.Time{}.Add(diff) @@ -195,7 +195,7 @@ func (h *History) parseDateRange() (from, to string, err error) { ) timeStampFrom, err := h.impl.ParseTime(parseLayout, h.opts.DateFrom) if err != nil { - return "", "", fmt.Errorf("convert date from: %w", err) + return "", "", errors.Wrapf(err, "convert date from") } from = timeStampFrom.Format(resultLayout) @@ -209,7 +209,7 @@ func (h *History) parseDateRange() (from, to string, err error) { } else { timeStampTo, err := h.impl.ParseTime(parseLayout, h.opts.DateTo) if err != nil { - return "", "", fmt.Errorf("convert date to: %w", err) + return "", "", errors.Wrapf(err, "convert date to") } // Set the ending date to midnight of the next day dateTo := time.Date( diff --git a/pkg/kubecross/kubecross.go b/pkg/kubecross/kubecross.go index 3c3643e1e48..7616c15ad45 100644 --- a/pkg/kubecross/kubecross.go +++ b/pkg/kubecross/kubecross.go @@ -19,6 +19,7 @@ package kubecross import ( "fmt" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/git" @@ -51,7 +52,7 @@ func (k *KubeCross) ForBranch(branch string) (string, error) { url := fmt.Sprintf("%s/%s/%s", baseURL, branch, versionPath) version, err := k.impl.GetURLResponse(url, true) if err != nil { - return "", fmt.Errorf("get URL response: %w", err) + return "", errors.Wrap(err, "get URL response") } logrus.Infof("Retrieved kube-cross version: %s", version) diff --git a/pkg/kubecross/kubecross_test.go b/pkg/kubecross/kubecross_test.go index e1f85b191d1..27bc079991f 100644 --- a/pkg/kubecross/kubecross_test.go +++ b/pkg/kubecross/kubecross_test.go @@ -17,9 +17,9 @@ limitations under the License. package kubecross import ( - "errors" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/require" "k8s.io/release/pkg/kubecross/kubecrossfakes" diff --git a/pkg/kubepkg/kubepkg.go b/pkg/kubepkg/kubepkg.go index 1fcedea2bec..1ebd28be014 100644 --- a/pkg/kubepkg/kubepkg.go +++ b/pkg/kubepkg/kubepkg.go @@ -17,7 +17,6 @@ limitations under the License. package kubepkg import ( - "errors" "fmt" "os" "path/filepath" @@ -27,6 +26,7 @@ import ( "github.com/blang/semver" gogithub "github.com/google/go-github/v39/github" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/kubepkg/options" @@ -176,7 +176,7 @@ func (c *Client) ConstructBuilds() ([]Build, error) { // TODO: Get package directory for any version once package definitions are broken out packageTemplateDir := filepath.Join(c.options.TemplateDir(), string(c.options.BuildType()), pkg) if _, err := os.Stat(packageTemplateDir); err != nil { - return nil, fmt.Errorf("finding package template dir: %w", err) + return nil, errors.Wrap(err, "finding package template dir") } b := &Build{ @@ -265,7 +265,7 @@ func (c *Client) buildPackage(build Build, packageDef *PackageDefinition, arch, logrus.Infof("Checking if user-supplied Kubernetes version (%s) is valid semver...", bc.KubernetesVersion) kubeSemver, err := util.TagStringToSemver(bc.KubernetesVersion) if err != nil { - return fmt.Errorf("user-supplied Kubernetes version is not valid semver: %w", err) + return errors.Wrap(err, "user-supplied Kubernetes version is not valid semver") } kubeVersionString := kubeSemver.String() @@ -289,12 +289,12 @@ func (c *Client) buildPackage(build Build, packageDef *PackageDefinition, arch, bc.KubernetesVersion, err = c.GetKubernetesVersion(pd) if err != nil { - return fmt.Errorf("getting Kubernetes version: %w", err) + return errors.Wrap(err, "getting Kubernetes version") } bc.DownloadLinkBase, err = c.GetDownloadLinkBase(pd) if err != nil { - return fmt.Errorf("getting Kubernetes download link base: %w", err) + return errors.Wrap(err, "getting Kubernetes download link base") } logrus.Infof("Kubernetes download link base: %s", bc.DownloadLinkBase) @@ -305,14 +305,14 @@ func (c *Client) buildPackage(build Build, packageDef *PackageDefinition, arch, bc.Version, err = c.GetPackageVersion(pd) if err != nil { - return fmt.Errorf("getting package version: %w", err) + return errors.Wrap(err, "getting package version") } logrus.Infof("%s package version: %s", bc.Name, bc.Version) bc.Dependencies, err = GetDependencies(pd) if err != nil { - return fmt.Errorf("getting dependencies: %w", err) + return errors.Wrap(err, "getting dependencies") } bc.KubeadmKubeletConfigFile = kubeadmConf @@ -321,12 +321,12 @@ func (c *Client) buildPackage(build Build, packageDef *PackageDefinition, arch, bc.CNIVersion, err = GetCNIVersion(pd) if err != nil { - return fmt.Errorf("getting CNI version: %w", err) + return errors.Wrap(err, "getting CNI version") } bc.CNIDownloadLink, err = GetCNIDownloadLink(pd.Version, bc.GoArch) if err != nil { - return fmt.Errorf("getting CNI download link: %w", err) + return errors.Wrap(err, "getting CNI download link") } logrus.Infof("Building %s package for %s/%s architecture...", bc.Package, bc.GoArch, bc.BuildArch) @@ -374,7 +374,7 @@ func (c *Client) run(bc *buildConfig) error { "--host-arch", bc.BuildArch, ); err != nil { - return fmt.Errorf("running debian package build: %w", err) + return errors.Wrap(err, "running debian package build") } fileName := fmt.Sprintf( @@ -389,18 +389,18 @@ func (c *Client) run(bc *buildConfig) error { logrus.Infof("Using package destination path %s", dstPath) if err := os.MkdirAll(filepath.Dir(dstPath), os.FileMode(0o777)); err != nil { - return fmt.Errorf("creating %s: %w", filepath.Dir(dstPath), err) + return errors.Wrapf(err, "creating %s", filepath.Dir(dstPath)) } srcPath := filepath.Join(specDir, fileName) input, err := c.impl.ReadFile(srcPath) if err != nil { - return fmt.Errorf("reading %s: %w", srcPath, err) + return errors.Wrapf(err, "reading %s", srcPath) } err = c.impl.WriteFile(dstPath, input, os.FileMode(0o644)) if err != nil { - return fmt.Errorf("writing file to %s: %w", dstPath, err) + return errors.Wrapf(err, "writing file to %s", dstPath) } logrus.Infof("Successfully built %s", dstPath) @@ -460,15 +460,15 @@ func GetCNIVersion(packageDef *PackageDefinition) (string, error) { if packageDef.CNIVersion != "" { cniSemVer, err := util.TagStringToSemver(packageDef.CNIVersion) if err != nil { - return "", fmt.Errorf("parsing CNI version: %w", err) + return "", errors.Wrap(err, "parsing CNI version") } minCNISemVer, err := util.TagStringToSemver(MinimumCNIVersion) if err != nil { - return "", fmt.Errorf("parsing CNI version: %w", err) + return "", errors.Wrap(err, "parsing CNI version") } if cniSemVer.LT(minCNISemVer) { - return "", fmt.Errorf("specified CNI version (%s) cannot be lower than %s", packageDef.CNIVersion, MinimumCNIVersion) + return "", errors.Errorf("specified CNI version (%s) cannot be lower than %s", packageDef.CNIVersion, MinimumCNIVersion) } logrus.Infof("Setting CNI version to %s", packageDef.CNIVersion) @@ -539,12 +539,12 @@ func (c *Client) GetCRIToolsVersion(packageDef *PackageDefinition) (string, erro for _, tag := range tags { tagSemver, err := semver.Parse(tag) if err != nil { - return "", fmt.Errorf("could not parse tag semver: %w", err) + return "", errors.Wrap(err, "could not parse tag semver") } criToolsSemver, err := semver.Parse(criToolsVersion) if err != nil { - return "", fmt.Errorf("could not parse CRI tools semver: %w", err) + return "", errors.Wrap(err, "could not parse CRI tools semver") } if tagSemver.GTE(criToolsSemver) { @@ -623,7 +623,7 @@ func getBuildArch(goArch string, buildType options.BuildType) string { func GetCNIDownloadLink(version, arch string) (string, error) { if _, err := util.TagStringToSemver(version); err != nil { - return "", fmt.Errorf("parsing CNI version: %w", err) + return "", errors.Wrap(err, "parsing CNI version") } return fmt.Sprintf("https://storage.googleapis.com/k8s-artifacts-cni/release/v%s/cni-plugins-linux-%s-v%s.tgz", version, arch, version), nil diff --git a/pkg/kubepkg/kubepkg_test.go b/pkg/kubepkg/kubepkg_test.go index d77b908af55..06e9486f7a4 100644 --- a/pkg/kubepkg/kubepkg_test.go +++ b/pkg/kubepkg/kubepkg_test.go @@ -17,11 +17,11 @@ limitations under the License. package kubepkg_test import ( - "errors" "os" "path/filepath" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/require" "k8s.io/release/pkg/kubepkg" diff --git a/pkg/kubepkg/options/options.go b/pkg/kubepkg/options/options.go index 155f820f25b..bceb998a9ac 100644 --- a/pkg/kubepkg/options/options.go +++ b/pkg/kubepkg/options/options.go @@ -17,10 +17,10 @@ limitations under the License. package options import ( - "errors" "path/filepath" "reflect" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-utils/util" diff --git a/pkg/kubepkg/template.go b/pkg/kubepkg/template.go index dd252e47f5e..5ac955c7f5b 100644 --- a/pkg/kubepkg/template.go +++ b/pkg/kubepkg/template.go @@ -18,11 +18,11 @@ package kubepkg import ( "bytes" - "fmt" "os" "path/filepath" "text/template" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -68,13 +68,13 @@ func buildSpecs(bc *buildConfig, specDir string) (workItems []work, err error) { for _, item := range workItems { buf := bytes.Buffer{} if err := item.t.Execute(&buf, bc); err != nil { - return nil, fmt.Errorf("executing template for %s: %w", item.src, err) + return nil, errors.Wrapf(err, "executing template for %s", item.src) } if err := os.WriteFile( item.dst, buf.Bytes(), item.info.Mode(), ); err != nil { - return nil, fmt.Errorf("writing file %s: %w", item.dst, err) + return nil, errors.Wrapf(err, "writing file %s", item.dst) } } diff --git a/pkg/mail/mail.go b/pkg/mail/mail.go index 6f966b94503..cd24e2d28fa 100644 --- a/pkg/mail/mail.go +++ b/pkg/mail/mail.go @@ -21,6 +21,7 @@ import ( "fmt" "net/http" + "github.com/pkg/errors" "github.com/sendgrid/rest" "github.com/sendgrid/sendgrid-go" "github.com/sendgrid/sendgrid-go/helpers/mail" @@ -123,17 +124,17 @@ func (s *Sender) SetDefaultSender() error { request := sendgrid.GetRequest(s.apiKey, "/v3/user/email", "") response, err := s.apiClient.API(request) if err != nil { - return fmt.Errorf("getting user email: %w", err) + return errors.Wrap(err, "getting user email") } if response.StatusCode != http.StatusOK { - return fmt.Errorf("unable to get users email: %s", response.Body) + return errors.Errorf("unable to get users email: %s", response.Body) } type email struct { Email string `json:"email"` } emailResponse := &email{} if err := json.Unmarshal([]byte(response.Body), emailResponse); err != nil { - return fmt.Errorf("decoding JSON response: %w", err) + return errors.Wrap(err, "decoding JSON response") } logrus.Infof("Using sender address: %s", emailResponse.Email) @@ -141,10 +142,10 @@ func (s *Sender) SetDefaultSender() error { request = sendgrid.GetRequest(s.apiKey, "/v3/user/profile", "") response, err = s.apiClient.API(request) if err != nil { - return fmt.Errorf("getting user profile: %w", err) + return errors.Wrap(err, "getting user profile") } if response.StatusCode != http.StatusOK { - return fmt.Errorf("unable to get users profile: %s", response.Body) + return errors.Errorf("unable to get users profile: %s", response.Body) } type profile struct { FirstName string `json:"first_name"` @@ -152,7 +153,7 @@ func (s *Sender) SetDefaultSender() error { } pr := profile{} if err := json.Unmarshal([]byte(response.Body), &pr); err != nil { - return fmt.Errorf("decoding JSON response: %w", err) + return errors.Wrap(err, "decoding JSON response") } name := fmt.Sprintf("%s %s", pr.FirstName, pr.LastName) diff --git a/pkg/notes/dependencies.go b/pkg/notes/dependencies.go index 89c20ba6a73..e8b2c12fb05 100644 --- a/pkg/notes/dependencies.go +++ b/pkg/notes/dependencies.go @@ -17,9 +17,9 @@ limitations under the License. package notes import ( - "fmt" "strings" + "github.com/pkg/errors" "github.com/saschagrunert/go-modiff/pkg/modiff" "sigs.k8s.io/release-sdk/git" @@ -66,7 +66,7 @@ func (d *Dependencies) ChangesForURL(url, from, to string) (string, error) { res, err := d.moDiff.Run(config) if err != nil { - return "", fmt.Errorf("getting dependency changes: %w", err) + return "", errors.Wrap(err, "getting dependency changes") } return res, nil diff --git a/pkg/notes/document/document.go b/pkg/notes/document/document.go index 851bc48cb30..17dd1ff8b14 100644 --- a/pkg/notes/document/document.go +++ b/pkg/notes/document/document.go @@ -17,7 +17,6 @@ limitations under the License. package document import ( - "errors" "fmt" "io" "os" @@ -27,6 +26,7 @@ import ( "strings" "text/template" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -91,7 +91,7 @@ func fetchFileMetadata(dir, urlPrefix, tag string) (*FileMetadata, error) { for fileType, patterns := range m { fInfo, err := fileInfo(dir, patterns, urlPrefix, tag) if err != nil { - return nil, fmt.Errorf("fetching file info: %w", err) + return nil, errors.Wrap(err, "fetching file info") } *fileType = append(*fileType, fInfo...) fileCount += len(fInfo) @@ -115,7 +115,7 @@ func fetchImageMetadata(dir, tag string) (*ImageMetadata, error) { image.ProdRegistry, tag, dir, nil, ) if err != nil { - return nil, fmt.Errorf("get manifest images: %w", err) + return nil, errors.Wrap(err, "get manifest images") } if len(manifests) == 0 { @@ -171,7 +171,7 @@ func fileInfo(dir string, patterns []string, urlPrefix, tag string) ([]File, err for _, filePath := range matches { sha512, err := hash.SHA512ForFile(filePath) if err != nil { - return nil, fmt.Errorf("get sha512: %w", err) + return nil, errors.Wrap(err, "get sha512") } fileName := filepath.Base(filePath) @@ -253,12 +253,12 @@ func GatherReleaseNotesDocument( ) (*Document, error) { releaseNotes, err := notes.GatherReleaseNotes(opts) if err != nil { - return nil, fmt.Errorf("gathering release notes: %w", err) + return nil, errors.Wrapf(err, "gathering release notes") } doc, err := New(releaseNotes, previousRev, currentRev) if err != nil { - return nil, fmt.Errorf("creating release note document: %w", err) + return nil, errors.Wrapf(err, "creating release note document") } return doc, nil @@ -295,12 +295,12 @@ func New( // Populate the struct from the raw interface if err := newcve.ReadRawInterface(note.DataFields["cve"]); err != nil { - return nil, fmt.Errorf("reading CVE data embedded in map file: %w", err) + return nil, errors.Wrap(err, "reading CVE data embedded in map file") } // Verify that CVE data has the minimum fields defined if err := newcve.Validate(); err != nil { - return nil, fmt.Errorf("checking CVE map file for PR #%d: %w", pr, err) + return nil, errors.Wrapf(err, "checking CVE map file for PR #%d", pr) } doc.CVEList = append(doc.CVEList, newcve) } @@ -361,30 +361,30 @@ func (d *Document) RenderMarkdownTemplate(bucket, tars, images, templateSpec str fileMetadata, err := fetchFileMetadata(tars, urlPrefix, d.CurrentRevision) if err != nil { - return "", fmt.Errorf("fetching file downloads metadata: %w", err) + return "", errors.Wrap(err, "fetching file downloads metadata") } d.FileDownloads = fileMetadata imageMetadata, err := fetchImageMetadata(images, d.CurrentRevision) if err != nil { - return "", fmt.Errorf("fetching image downloads metadata: %w", err) + return "", errors.Wrap(err, "fetching image downloads metadata") } d.ImageDownloads = imageMetadata goTemplate, err := d.template(templateSpec) if err != nil { - return "", fmt.Errorf("fetching template: %w", err) + return "", errors.Wrap(err, "fetching template") } tmpl, err := template.New("markdown"). Funcs(template.FuncMap{"prettyKind": prettyKind}). Parse(goTemplate) if err != nil { - return "", fmt.Errorf("parsing template: %w", err) + return "", errors.Wrap(err, "parsing template") } var s strings.Builder if err := tmpl.Execute(&s, d); err != nil { - return "", fmt.Errorf("rendering with template: %w", err) + return "", errors.Wrapf(err, "rendering with template") } return strings.TrimSpace(s.String()), nil } @@ -399,7 +399,7 @@ func (d *Document) template(templateSpec string) (string, error) { } if !strings.HasPrefix(templateSpec, options.GoTemplatePrefix) { - return "", fmt.Errorf( + return "", errors.Errorf( "bad template format: expected %q, %q or %q. Got: %q", options.GoTemplateDefault, options.GoTemplatePrefix+"", @@ -417,10 +417,10 @@ func (d *Document) template(templateSpec string) (string, error) { // Assume file-based template b, err := os.ReadFile(templatePathOrOnline) if err != nil { - return "", fmt.Errorf("reading template: %w", err) + return "", errors.Wrap(err, "reading template") } if len(b) == 0 { - return "", fmt.Errorf("template %q must be non-empty", templatePathOrOnline) + return "", errors.Errorf("template %q must be non-empty", templatePathOrOnline) } return string(b), nil @@ -440,12 +440,12 @@ func CreateDownloadsTable(w io.Writer, bucket, tars, images, prevTag, newTag str urlPrefix := release.URLPrefixForBucket(bucket) fileMetadata, err := fetchFileMetadata(tars, urlPrefix, newTag) if err != nil { - return fmt.Errorf("fetching file downloads metadata: %w", err) + return errors.Wrap(err, "fetching file downloads metadata") } imageMetadata, err := fetchImageMetadata(images, newTag) if err != nil { - return fmt.Errorf("fetching image downloads metadata: %w", err) + return errors.Wrap(err, "fetching image downloads metadata") } if fileMetadata == nil && imageMetadata == nil { diff --git a/pkg/notes/notes.go b/pkg/notes/notes.go index bcfcb24b8b9..60a65b14d84 100644 --- a/pkg/notes/notes.go +++ b/pkg/notes/notes.go @@ -21,7 +21,6 @@ import ( "context" "crypto/rand" "crypto/sha1" //nolint:gosec // used for file integrity checks, NOT security - "errors" "fmt" "math/big" "net/http" @@ -36,6 +35,7 @@ import ( gogithub "github.com/google/go-github/v39/github" "github.com/nozzle/throttler" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -215,7 +215,7 @@ type Gatherer struct { func NewGatherer(ctx context.Context, opts *options.Options) (*Gatherer, error) { client, err := opts.Client() if err != nil { - return nil, fmt.Errorf("unable to create notes client: %w", err) + return nil, errors.Wrap(err, "unable to create notes client") } return &Gatherer{ client: client, @@ -239,7 +239,7 @@ func GatherReleaseNotes(opts *options.Options) (*ReleaseNotes, error) { logrus.Info("Gathering release notes") gatherer, err := NewGatherer(context.Background(), opts) if err != nil { - return nil, fmt.Errorf("retrieving notes gatherer: %w", err) + return nil, errors.Wrapf(err, "retrieving notes gatherer") } var releaseNotes *ReleaseNotes @@ -251,7 +251,7 @@ func GatherReleaseNotes(opts *options.Options) (*ReleaseNotes, error) { releaseNotes, err = gatherer.ListReleaseNotes() } if err != nil { - return nil, fmt.Errorf("listing release notes: %w", err) + return nil, errors.Wrapf(err, "listing release notes") } logrus.Infof("finished gathering release notes in %v", time.Since(startTime)) @@ -266,20 +266,20 @@ func (g *Gatherer) ListReleaseNotes() (*ReleaseNotes, error) { for _, initString := range g.options.MapProviderStrings { provider, err := NewProviderFromInitString(initString) if err != nil { - return nil, fmt.Errorf("while getting release notes map providers: %w", err) + return nil, errors.Wrap(err, "while getting release notes map providers") } mapProviders = append(mapProviders, provider) } commits, err := g.listCommits(g.options.Branch, g.options.StartSHA, g.options.EndSHA) if err != nil { - return nil, fmt.Errorf("listing commits: %w", err) + return nil, errors.Wrap(err, "listing commits") } // Get the PRs into a temporary results set resultsTemp, err := g.gatherNotes(commits) if err != nil { - return nil, fmt.Errorf("gathering notes: %w", err) + return nil, errors.Wrap(err, "gathering notes") } // Cycle the results and add the complete notes, as well as those that @@ -292,7 +292,9 @@ func (g *Gatherer) ListReleaseNotes() (*ReleaseNotes, error) { for _, provider := range mapProviders { noteMaps, err := provider.GetMapsForPR(res.pullRequest.GetNumber()) if err != nil { - return nil, fmt.Errorf("checking if a map exists for PR %d: %w", res.pullRequest.GetNumber(), err) + return nil, errors.Wrapf( + err, "checking if a map exists for PR %d", res.pullRequest.GetNumber(), + ) } if len(noteMaps) != 0 { logrus.Infof( @@ -340,12 +342,12 @@ func (g *Gatherer) ListReleaseNotes() (*ReleaseNotes, error) { for _, provider := range mapProviders { noteMaps, err := provider.GetMapsForPR(result.pullRequest.GetNumber()) if err != nil { - return nil, fmt.Errorf("looking up note map: %w", err) + return nil, errors.Wrap(err, "Error while looking up note map") } for _, noteMap := range noteMaps { if err := note.ApplyMap(noteMap, g.options.AddMarkdownLinks); err != nil { - return nil, fmt.Errorf("applying notemap for PR #%d: %w", result.pullRequest.GetNumber(), err) + return nil, errors.Wrapf(err, "applying notemap for PR #%d", result.pullRequest.GetNumber()) } } } @@ -520,12 +522,12 @@ func (g *Gatherer) ReleaseNoteFromCommit(result *Result) (*ReleaseNote, error) { func (g *Gatherer) listCommits(branch, start, end string) ([]*gogithub.RepositoryCommit, error) { startCommit, _, err := g.client.GetCommit(g.context, g.options.GithubOrg, g.options.GithubRepo, start) if err != nil { - return nil, fmt.Errorf("retrieve start commit: %w", err) + return nil, errors.Wrap(err, "retrieve start commit") } endCommit, _, err := g.client.GetCommit(g.context, g.options.GithubOrg, g.options.GithubRepo, end) if err != nil { - return nil, fmt.Errorf("retrieve end commit: %w", err) + return nil, errors.Wrap(err, "retrieve end commit") } allCommits := &commitList{} @@ -1150,7 +1152,7 @@ func (rn *ReleaseNote) ToNoteMap() (string, error) { yamlCode, err := yaml.Marshal(¬eMap) if err != nil { - return "", fmt.Errorf("marshalling release note to map: %w", err) + return "", errors.Wrap(err, "marshalling release note to map") } return string(yamlCode), nil @@ -1161,7 +1163,7 @@ func (rn *ReleaseNote) ContentHash() (string, error) { // Convert the note to a map noteMap, err := rn.ToNoteMap() if err != nil { - return "", fmt.Errorf("serializing note's content: %w", err) + return "", errors.Wrap(err, "serializing note's content") } //nolint:gosec // used for file integrity checks, NOT security @@ -1169,7 +1171,7 @@ func (rn *ReleaseNote) ContentHash() (string, error) { h := sha1.New() _, err = h.Write([]byte(noteMap)) if err != nil { - return "", fmt.Errorf("calculating content hash from map: %w", err) + return "", errors.Wrap(err, "calculating content hash from map") } return fmt.Sprintf("%x", h.Sum(nil)), nil } diff --git a/pkg/notes/notes_map.go b/pkg/notes/notes_map.go index 8b1a744f8e4..8d7bd64bd67 100644 --- a/pkg/notes/notes_map.go +++ b/pkg/notes/notes_map.go @@ -17,12 +17,11 @@ limitations under the License. package notes import ( - "errors" - "fmt" "io" "os" "path/filepath" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" @@ -60,7 +59,7 @@ func ParseReleaseNotesMap(mapPath string) (*[]ReleaseNotesMap, error) { notemaps := []ReleaseNotesMap{} yamlReader, err := os.Open(mapPath) if err != nil { - return nil, fmt.Errorf("opening maps: %w", err) + return nil, errors.Wrap(err, "opening maps") } defer yamlReader.Close() @@ -71,7 +70,7 @@ func ParseReleaseNotesMap(mapPath string) (*[]ReleaseNotesMap, error) { if err := decoder.Decode(¬eMap); err == io.EOF { break } else if err != nil { - return nil, fmt.Errorf("decoding note map: %w", err) + return nil, errors.Wrap(err, "decoding note map") } notemaps = append(notemaps, noteMap) } @@ -143,7 +142,7 @@ func (mp *DirectoryMapProvider) readMaps() error { for _, fileName := range fileList { notemaps, err := ParseReleaseNotesMap(fileName) if err != nil { - return fmt.Errorf("while parsing note map in %s: %w", fileName, err) + return errors.Wrapf(err, "while parsing note map in %s", fileName) } for i, notemap := range *notemaps { if _, ok := mp.Maps[notemap.PR]; !ok { @@ -161,7 +160,7 @@ func (mp *DirectoryMapProvider) GetMapsForPR(pr int) (notesMap []*ReleaseNotesMa if mp.Maps == nil { err := mp.readMaps() if err != nil { - return nil, fmt.Errorf("while reading release notes maps: %w", err) + return nil, errors.Wrap(err, "while reading release notes maps") } } if notesMap, ok := mp.Maps[pr]; ok { diff --git a/pkg/notes/notes_v2.go b/pkg/notes/notes_v2.go index 3b51f2b7d8d..1ea7b4dd67d 100644 --- a/pkg/notes/notes_v2.go +++ b/pkg/notes/notes_v2.go @@ -23,6 +23,8 @@ import ( "sync" "time" + "github.com/pkg/errors" + "k8s.io/release/pkg/notes/options" "github.com/cheggaaa/pb/v3" @@ -48,7 +50,7 @@ func (g *Gatherer) ListReleaseNotesV2() (*ReleaseNotes, error) { // left parent of Git commits is always the main branch parent pairs, err := g.listLeftParentCommits(g.options) if err != nil { - return nil, fmt.Errorf("listing offline commits: %w", err) + return nil, errors.Wrap(err, "listing offline commits") } // load map providers specified in options @@ -56,7 +58,7 @@ func (g *Gatherer) ListReleaseNotesV2() (*ReleaseNotes, error) { for _, initString := range g.options.MapProviderStrings { provider, err := NewProviderFromInitString(initString) if err != nil { - return nil, fmt.Errorf("while getting release notes map providers: %w", err) + return nil, errors.Wrap(err, "while getting release notes map providers") } mapProviders = append(mapProviders, provider) } @@ -242,19 +244,19 @@ func (g *Gatherer) listLeftParentCommits(opts *options.Options) ([]*commitPrPair endCommit, err := localRepository.CommitObject(plumbing.NewHash(opts.EndSHA)) if err != nil { - return nil, fmt.Errorf("finding commit of EndSHA: %w", err) + return nil, errors.Wrap(err, "finding commit of EndSHA") } startCommit, err := localRepository.CommitObject(plumbing.NewHash(opts.StartSHA)) if err != nil { - return nil, fmt.Errorf("finding commit of StartSHA: %w", err) + return nil, errors.Wrap(err, "finding commit of StartSHA") } logrus.Debugf("finding merge base (last shared commit) between the two SHAs") startTime := time.Now() lastSharedCommits, err := endCommit.MergeBase(startCommit) if err != nil { - return nil, fmt.Errorf("finding shared commits: %w", err) + return nil, errors.Wrap(err, "finding shared commits") } if len(lastSharedCommits) == 0 { return nil, fmt.Errorf("no shared commits between the provided SHAs") @@ -274,7 +276,7 @@ func (g *Gatherer) listLeftParentCommits(opts *options.Options) ([]*commitPrPair // Find and collect commit objects commitPointer, err := localRepository.CommitObject(hashPointer) if err != nil { - return nil, fmt.Errorf("finding CommitObject: %w", err) + return nil, errors.Wrap(err, "finding CommitObject") } // Find and collect PR number from commit message diff --git a/pkg/notes/options/options.go b/pkg/notes/options/options.go index 3163493df50..4fdbb4c874e 100644 --- a/pkg/notes/options/options.go +++ b/pkg/notes/options/options.go @@ -17,11 +17,10 @@ limitations under the License. package options import ( - "errors" - "fmt" "os" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/git" @@ -188,7 +187,7 @@ func (o *Options) ValidateAndFinish() (err error) { if ok { o.githubToken = token } else if o.ReplayDir == "" { - return fmt.Errorf( + return errors.Errorf( "neither environment variable `%s` nor `replay` option is set", github.TokenEnvKey, ) @@ -220,7 +219,7 @@ func (o *Options) ValidateAndFinish() (err error) { if o.StartRev != "" && o.StartSHA == "" { sha, err := repo.RevParseTag(o.StartRev) if err != nil { - return fmt.Errorf("resolving %s: %w", o.StartRev, err) + return errors.Wrapf(err, "resolving %s", o.StartRev) } logrus.Infof("Using found start SHA: %s", sha) o.StartSHA = sha @@ -228,7 +227,7 @@ func (o *Options) ValidateAndFinish() (err error) { if o.EndRev != "" && o.EndSHA == "" { sha, err := repo.RevParseTag(o.EndRev) if err != nil { - return fmt.Errorf("resolving %s: %w", o.EndRev, err) + return errors.Wrapf(err, "resolving %s", o.EndRev) } logrus.Infof("Using found end SHA: %s", sha) o.EndSHA = sha @@ -249,7 +248,7 @@ func (o *Options) ValidateAndFinish() (err error) { } if err := o.checkFormatOptions(); err != nil { - return fmt.Errorf("while checking format flags: %w", err) + return errors.Wrap(err, "while checking format flags") } return nil } @@ -260,7 +259,7 @@ func (o *Options) checkFormatOptions() error { logrus.Infof("Using output format: %s", o.Format) if o.Format == FormatMarkdown && o.GoTemplate != GoTemplateDefault { if !strings.HasPrefix(o.GoTemplate, GoTemplatePrefix) { - return fmt.Errorf("go template has to be prefixed with %q", GoTemplatePrefix) + return errors.Errorf("go template has to be prefixed with %q", GoTemplatePrefix) } templatePathOrOnline := strings.TrimPrefix(o.GoTemplate, GoTemplatePrefix) @@ -268,10 +267,10 @@ func (o *Options) checkFormatOptions() error { if !strings.HasPrefix(templatePathOrOnline, GoTemplatePrefixInline) { fileStats, err := os.Stat(templatePathOrOnline) if os.IsNotExist(err) { - return fmt.Errorf("could not find template file (%s)", templatePathOrOnline) + return errors.Errorf("could not find template file (%s)", templatePathOrOnline) } if fileStats.Size() == 0 { - return fmt.Errorf("template file %s is empty", templatePathOrOnline) + return errors.Errorf("template file %s is empty", templatePathOrOnline) } } } @@ -279,7 +278,7 @@ func (o *Options) checkFormatOptions() error { return errors.New("go-template cannot be defined when in JSON mode") } if o.Format != FormatJSON && o.Format != FormatMarkdown { - return fmt.Errorf("invalid format: %s", o.Format) + return errors.Errorf("invalid format: %s", o.Format) } return nil } @@ -361,7 +360,7 @@ func (o *Options) Client() (github.Client, error) { gh, err = github.NewWithToken(o.githubToken) } if err != nil { - return nil, fmt.Errorf("unable to create GitHub client: %w", err) + return nil, errors.Wrap(err, "unable to create GitHub client") } if o.RecordDir != "" { diff --git a/pkg/release/archive.go b/pkg/release/archive.go index 87263c99573..1013a5945cc 100644 --- a/pkg/release/archive.go +++ b/pkg/release/archive.go @@ -17,12 +17,12 @@ limitations under the License. package release import ( - "errors" "fmt" "os" "path/filepath" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/gcli" @@ -106,12 +106,12 @@ func (o *ArchiverOptions) Validate() error { // Check if the build version is well formed (used for cleaning old staged build) if _, err := util.TagStringToSemver(o.BuildVersion); err != nil { - return fmt.Errorf("verifying build version tag: %w", err) + return errors.Wrap(err, "verifying build version tag") } // Check if the prime version is well formed if _, err := util.TagStringToSemver(o.PrimeVersion); err != nil { - return fmt.Errorf("verifying prime version tag: %w", err) + return errors.Wrap(err, "verifying prime version tag") } return nil @@ -134,7 +134,7 @@ type defaultArchiverImpl struct{} func (archiver *Archiver) ArchiveRelease() error { // Verify options are complete if err := archiver.impl.ValidateOptions(archiver.opts); err != nil { - return fmt.Errorf("validating archive options: %w", err) + return errors.Wrap(err, "validating archive options") } // TODO: Is this still relevant? @@ -153,7 +153,7 @@ func (archiver *Archiver) ArchiveRelease() error { if err := archiver.impl.DeleteStalePasswordFiles( archiver.opts.ReleaseBuildDir, ); err != nil { - return fmt.Errorf("looking for stale password files: %w", err) + return errors.Wrap(err, "looking for stale password files") } // Clean previous staged builds @@ -161,7 +161,7 @@ func (archiver *Archiver) ArchiveRelease() error { object.GcsPrefix+filepath.Join(archiver.opts.Bucket, StagePath), archiver.opts.BuildVersion, ); err != nil { - return fmt.Errorf("deleting previous staged builds: %w", err) + return errors.Wrap(err, "deleting previous staged builds") } // Copy the release to the bucket @@ -169,7 +169,7 @@ func (archiver *Archiver) ArchiveRelease() error { archiver.opts.ReleaseBuildDir, archiver.opts.ArchiveBucketPath(), ); err != nil { - return fmt.Errorf("while copying the release directory: %w", err) + return errors.Wrap(err, "while copying the release directory") } // copy_logs_to_workdir @@ -178,14 +178,14 @@ func (archiver *Archiver) ArchiveRelease() error { filepath.Join(archiver.opts.ReleaseBuildDir, logsArchiveSubPath), filepath.Join(archiver.opts.ArchiveBucketPath(), logsArchiveSubPath), ); err != nil { - return fmt.Errorf("copying release logs to archive: %w", err) + return errors.Wrap(err, "copying release logs to archive") } // Make the logs private (remove AllUsers from the GCS ACL) if err := archiver.impl.MakeFilesPrivate( filepath.Join(archiver.opts.ArchiveBucketPath(), logsArchiveSubPath), ); err != nil { - return fmt.Errorf("setting private ACL on logs: %w", err) + return errors.Wrapf(err, "setting private ACL on logs") } logrus.Info("Release archive complete") @@ -194,10 +194,7 @@ func (archiver *Archiver) ArchiveRelease() error { // validateOptions runs the options validation func (a *defaultArchiverImpl) ValidateOptions(o *ArchiverOptions) error { - if err := o.Validate(); err != nil { - return fmt.Errorf("validating options: %w", err) - } - return nil + return errors.Wrap(o.Validate(), "validating options") } // makeFilesPrivate updates the ACL on all files in a directory @@ -206,11 +203,11 @@ func (a *defaultArchiverImpl) MakeFilesPrivate(archiveBucketPath string) error { gcs := object.NewGCS() logsPath, err := gcs.NormalizePath(archiveBucketPath + "/*") if err != nil { - return fmt.Errorf("normalizing gcs path to modify ACL: %w", err) + return errors.Wrap(err, "normalizing gcs path to modify ACL") } // logrun -s $GSUTIL acl ch -d AllUsers "$archive_bucket/$build_dir/${LOGFILE##*/}*" || true if err := gcli.GSUtil("acl", "ch", "-d", "AllUsers", logsPath); err != nil { - return fmt.Errorf("removing public access from files in %s: %w", archiveBucketPath, err) + return errors.Wrapf(err, "removing public access from files in %s", archiveBucketPath) } return nil } @@ -220,14 +217,14 @@ func (a *defaultArchiverImpl) DeleteStalePasswordFiles(releaseBuildDir string) e if err := command.NewWithWorkDir( releaseBuildDir, "find", "-type", "f", "-name", "rsyncd.password", "-delete", ).RunSuccess(); err != nil { - return fmt.Errorf("deleting temporary password files: %w", err) + return errors.Wrap(err, "deleting temporary password files") } // Delete the git remote config to avoid it ending in the stage bucket gitConf := filepath.Join(releaseBuildDir, "k8s.io", "kubernetes", ".git", "config") if util.Exists(gitConf) { if err := os.Remove(gitConf); err != nil { - return fmt.Errorf("deleting git remote config: %w", err) + return errors.Wrap(err, "deleting git remote config") } } else { logrus.Warn("git configuration file not found, nothing to remove") @@ -247,26 +244,26 @@ func (a *defaultArchiverImpl) CopyReleaseLogs( if archiveBucketLogsPath != "" { archiveBucketLogsPath, err = gcs.NormalizePath(archiveBucketLogsPath) if err != nil { - return fmt.Errorf("normalizing remote logfile destination: %w", err) + return errors.Wrap(err, "normalizing remote logfile destination") } } // Check the destination directory exists if !util.Exists(targetDir) { if err := os.Mkdir(targetDir, os.FileMode(0o755)); err != nil { - return fmt.Errorf("creating logs archive directory: %w", err) + return errors.Wrap(err, "creating logs archive directory") } } for _, fileName := range logFiles { // Strip the logfiles from control chars and sensitive data if err := util.CleanLogFile(fileName); err != nil { - return fmt.Errorf("sanitizing logfile: %w", err) + return errors.Wrap(err, "sanitizing logfile") } logrus.Infof("Copying %s to %s", fileName, targetDir) if err := util.CopyFileLocal( fileName, filepath.Join(targetDir, filepath.Base(fileName)), true, ); err != nil { - return fmt.Errorf("copying logfile %s to %s: %w", fileName, targetDir, err) + return errors.Wrapf(err, "Copying logfile %s to %s", fileName, targetDir) } } // TODO: Grab previous log files from stage and copy them to logs dir @@ -275,7 +272,7 @@ func (a *defaultArchiverImpl) CopyReleaseLogs( if archiveBucketLogsPath != "" { logrus.Infof("Rsyncing logs to remote bucket %s", archiveBucketLogsPath) if err := gcs.RsyncRecursive(targetDir, archiveBucketLogsPath); err != nil { - return fmt.Errorf("while synching log files to remote bucket addr: %w", err) + return errors.Wrap(err, "while synching log files to remote bucket addr") } } return nil @@ -289,24 +286,24 @@ func (a *defaultArchiverImpl) CopyReleaseToBucket(releaseBuildDir, archiveBucket gcs := object.NewGCS() remoteDest, err := gcs.NormalizePath(archiveBucketPath) if err != nil { - return fmt.Errorf("normalizing destination path: %w", err) + return errors.Wrap(err, "normalizing destination path") } srcPath := filepath.Join(releaseBuildDir, "k8s.io") tarball := srcPath + ".tar.gz" logrus.Infof("Compressing %s to %s", srcPath, tarball) if err := tar.Compress(tarball, srcPath); err != nil { - return fmt.Errorf("create source tarball: %w", err) + return errors.Wrap(err, "create source tarball") } logrus.Infof("Removing source path %s before syncing", srcPath) if err := os.RemoveAll(srcPath); err != nil { - return fmt.Errorf("remove source path: %w", err) + return errors.Wrap(err, "remove source path") } logrus.Infof("Rsync %s to %s", releaseBuildDir, remoteDest) if err := gcs.RsyncRecursive(releaseBuildDir, remoteDest); err != nil { - return fmt.Errorf("copying release directory to bucket: %w", err) + return errors.Wrap(err, "copying release directory to bucket") } return nil } @@ -316,7 +313,7 @@ func (a *defaultArchiverImpl) GetLogFiles(logsDir string) ([]string, error) { logFiles := []string{} tmpContents, err := os.ReadDir(logsDir) if err != nil { - return nil, fmt.Errorf("searching for logfiles in %s: %w", logsDir, err) + return nil, errors.Wrapf(err, "searching for logfiles in %s", logsDir) } for _, finfo := range tmpContents { if strings.HasPrefix(finfo.Name(), "anago") && @@ -333,7 +330,7 @@ func (a *defaultArchiverImpl) CleanStagedBuilds(bucketPath, buildVersion string) // Build the prefix we will be looking for semver, err := util.TagStringToSemver(buildVersion) if err != nil { - return fmt.Errorf("parsing semver from tag: %w", err) + return errors.Wrap(err, "parsing semver from tag") } dirPrefix := fmt.Sprintf("%s%d.%d", util.TagPrefix, semver.Major, semver.Minor) @@ -348,20 +345,20 @@ func (a *defaultArchiverImpl) CleanStagedBuilds(bucketPath, buildVersion string) // Normalize the bucket path path, err := gcs.NormalizePath(bucketPath, dirPrefix+"*") if err != nil { - return fmt.Errorf("normalizing stage path: %w", err) + return errors.Wrap(err, "normalizing stage path") } // Get all staged build that match the pattern output, err := gcli.GSUtilOutput("ls", "-d", path) if err != nil { - return fmt.Errorf("listing bucket contents: %w", err) + return errors.Wrap(err, "listing bucket contents") } for _, line := range strings.Fields(output) { if strings.Contains(line, dirPrefix) && !strings.Contains(line, buildVersion) { logrus.Infof("Deleting previous staged build: %s", line) if err := gcs.DeletePath(line); err != nil { - return fmt.Errorf("calling gsutil to delete build: %w", err) + return errors.Wrap(err, "calling gsutil to delete build") } } } diff --git a/pkg/release/binaries.go b/pkg/release/binaries.go index 5ffdae3789e..f31d979428c 100644 --- a/pkg/release/binaries.go +++ b/pkg/release/binaries.go @@ -17,9 +17,9 @@ limitations under the License. package release import ( - "fmt" "path/filepath" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/release/pkg/binary" ) @@ -54,7 +54,7 @@ func (ac *ArtifactChecker) Options() *ArtifactCheckerOptions { func (ac *ArtifactChecker) CheckBinaryTags() error { for _, tag := range ac.opts.Versions { if err := ac.impl.CheckVersionTags(ac.opts, tag); err != nil { - return fmt.Errorf("checking tags in %s binaries: %w", tag, err) + return errors.Wrapf(err, "checking tags in %s binaries", tag) } } return nil @@ -65,7 +65,7 @@ func (ac *ArtifactChecker) CheckBinaryTags() error { func (ac *ArtifactChecker) CheckBinaryArchitectures() error { for _, tag := range ac.opts.Versions { if err := ac.impl.CheckVersionArch(ac.opts, tag); err != nil { - return fmt.Errorf("checking tags in %s binaries: %w", tag, err) + return errors.Wrapf(err, "checking tags in %s binaries", tag) } } return nil @@ -95,13 +95,13 @@ func (impl *defaultArtifactCheckerImpl) CheckVersionTags( ) error { binaries, err := impl.ListReleaseBinaries(opts, version) if err != nil { - return fmt.Errorf("listing binaries for release %s: %w", version, err) + return errors.Wrapf(err, "listing binaries for release %s", version) } logrus.Infof("Checking %d binaries for tag %s", len(binaries), version) for _, binData := range binaries { bin, err := binary.New(binData.Path) if err != nil { - return fmt.Errorf("creating binary from %s: %w", binData.Path, err) + return errors.Wrapf(err, "creating binary from %s", binData.Path) } // The mounter binary is not tagged @@ -112,10 +112,10 @@ func (impl *defaultArtifactCheckerImpl) CheckVersionTags( // TODO: Ensure binary contains the correct commit message contains, err := bin.ContainsStrings(version) if err != nil { - return fmt.Errorf("scanning binary %s: %w", binData.Path, err) + return errors.Wrapf(err, "scanning binary %s", binData.Path) } if !contains { - return fmt.Errorf( + return errors.Errorf( "tag %s not found in produced binary: %s ", version, binData.Path, ) } @@ -130,17 +130,17 @@ func (impl *defaultArtifactCheckerImpl) CheckVersionArch( ) error { binaries, err := impl.ListReleaseBinaries(opts, version) if err != nil { - return fmt.Errorf("listing binaries for release %s: %w", version, err) + return errors.Wrapf(err, "listing binaries for release %s", version) } logrus.Infof("Ensuring architecture of %d binaries for version %s", len(binaries), version) for _, binData := range binaries { bin, err := binary.New(binData.Path) if err != nil { - return fmt.Errorf("creating binary object from %s: %w", binData.Path, err) + return errors.Wrapf(err, "creating binary object from %s", binData.Path) } if bin.Arch() != binData.Arch || bin.OS() != binData.Platform { - return fmt.Errorf( + return errors.Errorf( "binary %s has incorrect architecture: expected %s/%s got %s/%s", binData.Path, binData.Arch, binData.Platform, bin.Arch(), bin.OS(), ) diff --git a/pkg/release/branch_checker.go b/pkg/release/branch_checker.go index 265e4810945..bca876a069b 100644 --- a/pkg/release/branch_checker.go +++ b/pkg/release/branch_checker.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/blang/semver" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/git" @@ -64,7 +65,9 @@ func (r *BranchChecker) NeedsCreation( fmt.Sprintf("refs/heads/%s", branch), ) if err != nil { - return false, fmt.Errorf("get remote commit for %s branch: %w", branch, err) + return false, errors.Wrapf( + err, "get remote commit for %s branch", branch, + ) } if output != "" { @@ -72,8 +75,8 @@ func (r *BranchChecker) NeedsCreation( } else { logrus.Infof("Branch %s does not yet exist on remote location", branch) if releaseType == ReleaseTypeOfficial { - return false, fmt.Errorf( - "can't do officials relases when creating a new branch", + return false, errors.Errorf( + "Can't do officials relases when creating a new branch", ) } createReleaseBranch = true @@ -89,7 +92,7 @@ func (r *BranchChecker) NeedsCreation( "release-%d.%d", buildVersion.Major, buildVersion.Minor, ) if branch != requiredReleaseBranch { - return false, fmt.Errorf( + return false, errors.Errorf( "branch and build version does not match, got: %v, required: %v", branch, requiredReleaseBranch, ) diff --git a/pkg/release/images.go b/pkg/release/images.go index daa1344ac47..f323097d8f2 100644 --- a/pkg/release/images.go +++ b/pkg/release/images.go @@ -24,6 +24,7 @@ import ( "strings" "github.com/google/go-containerregistry/pkg/crane" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/sign" @@ -112,13 +113,13 @@ func (i *Images) Publish(registry, version, buildPath string) error { if err := i.Execute( "docker", "load", "-qi", path, ); err != nil { - return fmt.Errorf("load container image: %w", err) + return errors.Wrap(err, "load container image") } if err := i.Execute( "docker", "tag", origTag, newTagWithArch, ); err != nil { - return fmt.Errorf("tag container image: %w", err) + return errors.Wrap(err, "tag container image") } logrus.Infof("Pushing %s", newTagWithArch) @@ -126,28 +127,28 @@ func (i *Images) Publish(registry, version, buildPath string) error { if err := i.Execute( "gcloud", "docker", "--", "push", newTagWithArch, ); err != nil { - return fmt.Errorf("push container image: %w", err) + return errors.Wrap(err, "push container image") } if err := i.SignImage(i.signer, newTagWithArch); err != nil { - return fmt.Errorf("sign container image: %w", err) + return errors.Wrap(err, "sign container image") } if err := i.Execute( "docker", "rmi", origTag, newTagWithArch, ); err != nil { - return fmt.Errorf("remove local container image: %w", err) + return errors.Wrap(err, "remove local container image") } return nil }, ) if err != nil { - return fmt.Errorf("get manifest images: %w", err) + return errors.Wrap(err, "get manifest images") } if err := os.Setenv("DOCKER_CLI_EXPERIMENTAL", "enabled"); err != nil { - return fmt.Errorf("enable docker experimental CLI: %w", err) + return errors.Wrap(err, "enable docker experimental CLI") } for image, arches := range manifestImages { @@ -164,7 +165,7 @@ func (i *Images) Publish(registry, version, buildPath string) error { []string{"manifest", "create", "--amend", imageVersion}, manifests..., )...); err != nil { - return fmt.Errorf("create manifest: %w", err) + return errors.Wrap(err, "create manifest") } for _, arch := range arches { @@ -176,7 +177,7 @@ func (i *Images) Publish(registry, version, buildPath string) error { "docker", "manifest", "annotate", "--arch", arch, imageVersion, fmt.Sprintf("%s-%s:%s", image, arch, version), ); err != nil { - return fmt.Errorf("annotate manifest with arch: %w", err) + return errors.Wrap(err, "annotate manifest with arch") } } @@ -184,11 +185,11 @@ func (i *Images) Publish(registry, version, buildPath string) error { if err := i.Execute( "docker", "manifest", "push", imageVersion, "--purge", ); err != nil { - return fmt.Errorf("push manifest: %w", err) + return errors.Wrap(err, "push manifest") } if err := i.SignImage(i.signer, imageVersion); err != nil { - return fmt.Errorf("sign manifest list: %w", err) + return errors.Wrap(err, "sign manifest list") } } @@ -205,14 +206,14 @@ func (i *Images) Validate(registry, version, buildPath string) error { registry, version, buildPath, func(_, _, image string) error { logrus.Infof("Verifying that image is signed: %s", image) - if err := i.VerifyImage(i.signer, image); err != nil { - return fmt.Errorf("verify signed image: %w", err) - } - return nil + return errors.Wrap( + i.VerifyImage(i.signer, image), + "verify signed image", + ) }, ) if err != nil { - return fmt.Errorf("get manifest images: %w", err) + return errors.Wrap(err, "get manifest images") } logrus.Infof("Got manifest images %+v", manifestImages) @@ -221,21 +222,25 @@ func (i *Images) Validate(registry, version, buildPath string) error { manifestBytes, err := crane.Manifest(imageVersion) if err != nil { - return fmt.Errorf("get remote manifest from %s: %w", imageVersion, err) + return errors.Wrapf( + err, "get remote manifest from %s", imageVersion, + ) } logrus.Info("Verifying that image manifest list is signed") if err := i.VerifyImage(i.signer, imageVersion); err != nil { - return fmt.Errorf("verify signed manifest list: %w", err) + return errors.Wrap(err, "verify signed manifest list") } manifest := string(manifestBytes) manifestFile, err := os.CreateTemp("", "manifest-") if err != nil { - return fmt.Errorf("create temp file for manifest: %w", err) + return errors.Wrap(err, "create temp file for manifest") } if _, err := manifestFile.WriteString(manifest); err != nil { - return fmt.Errorf("write manifest to %s: %w", manifestFile.Name(), err) + return errors.Wrapf( + err, "write manifest to %s", manifestFile.Name(), + ) } for _, arch := range arches { @@ -249,11 +254,14 @@ func (i *Images) Validate(registry, version, buildPath string) error { manifestFile.Name(), ) if err != nil { - return fmt.Errorf("get digest from manifest file %s for arch %s: %w", manifestFile.Name(), arch, err) + return errors.Wrapf( + err, "get digest from manifest file %s for arch %s", + manifestFile.Name(), arch, + ) } if digest == "" { - return fmt.Errorf( + return errors.Errorf( "could not find the image digest for %s on %s", imageVersion, arch, ) @@ -263,7 +271,7 @@ func (i *Images) Validate(registry, version, buildPath string) error { } if err := os.RemoveAll(manifestFile.Name()); err != nil { - return fmt.Errorf("remove manifest file: %w", err) + return errors.Wrap(err, "remove manifest file") } } @@ -290,16 +298,20 @@ func (i *Images) Exists(registry, version string, fast bool) (bool, error) { manifestBytes, err := crane.Manifest(imageVersion) if err != nil { - return false, fmt.Errorf("get remote manifest from %s: %w", imageVersion, err) + return false, errors.Wrapf( + err, "get remote manifest from %s", imageVersion, + ) } manifest := string(manifestBytes) manifestFile, err := os.CreateTemp("", "manifest-") if err != nil { - return false, fmt.Errorf("create temp file for manifest: %w", err) + return false, errors.Wrap(err, "create temp file for manifest") } if _, err := manifestFile.WriteString(manifest); err != nil { - return false, fmt.Errorf("write manifest to %s: %w", manifestFile.Name(), err) + return false, errors.Wrapf( + err, "write manifest to %s", manifestFile.Name(), + ) } for _, arch := range arches { @@ -313,11 +325,14 @@ func (i *Images) Exists(registry, version string, fast bool) (bool, error) { manifestFile.Name(), ) if err != nil { - return false, fmt.Errorf("get digest from manifest file %s for arch %s: %w", manifestFile.Name(), arch, err) + return false, errors.Wrapf( + err, "get digest from manifest file %s for arch %s", + manifestFile.Name(), arch, + ) } if digest == "" { - return false, fmt.Errorf( + return false, errors.Errorf( "could not find the image digest for %s on %s", imageVersion, arch, ) @@ -327,7 +342,7 @@ func (i *Images) Exists(registry, version string, fast bool) (bool, error) { } if err := os.RemoveAll(manifestFile.Name()); err != nil { - return false, fmt.Errorf("remove manifest file: %w", err) + return false, errors.Wrap(err, "remove manifest file") } } @@ -347,7 +362,7 @@ func (i *Images) GetManifestImages( archPaths, err := os.ReadDir(releaseImagesPath) if err != nil { - return nil, fmt.Errorf("read images path %s: %w", releaseImagesPath, err) + return nil, errors.Wrapf(err, "read images path %s", releaseImagesPath) } for _, archPath := range archPaths { @@ -375,12 +390,12 @@ func (i *Images) GetManifestImages( origTag, err := i.RepoTagFromTarball(path) if err != nil { - return fmt.Errorf("getting repo tags for tarball: %w", err) + return errors.Wrap(err, "getting repo tags for tarball") } tagMatches := tagRegex.FindStringSubmatch(origTag) if len(tagMatches) != 2 { - return fmt.Errorf( + return errors.Errorf( "malformed tag %s in %s", origTag, path, ) } @@ -397,13 +412,13 @@ func (i *Images) GetManifestImages( if err := forTarballFn( path, origTag, newTagWithArch, ); err != nil { - return fmt.Errorf("executing tarball callback: %w", err) + return errors.Wrap(err, "executing tarball callback") } } return nil }, ); err != nil { - return nil, fmt.Errorf("traversing path: %w", err) + return nil, errors.Wrap(err, "traversing path") } } return manifestImages, nil diff --git a/pkg/release/images_test.go b/pkg/release/images_test.go index 304dd9e15de..314b4116b04 100644 --- a/pkg/release/images_test.go +++ b/pkg/release/images_test.go @@ -17,13 +17,13 @@ limitations under the License. package release_test import ( - "errors" "fmt" "os" "path/filepath" "strings" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/require" "k8s.io/release/pkg/release" "k8s.io/release/pkg/release/releasefakes" diff --git a/pkg/release/prerequisites.go b/pkg/release/prerequisites.go index 7a9a655f0e1..05e5a216943 100644 --- a/pkg/release/prerequisites.go +++ b/pkg/release/prerequisites.go @@ -17,9 +17,9 @@ limitations under the License. package release import ( - "fmt" "strings" + "github.com/pkg/errors" "github.com/shirou/gopsutil/v3/disk" "github.com/sirupsen/logrus" @@ -121,7 +121,7 @@ func (p *PrerequisitesChecker) Run(workdir string) error { ) if !p.impl.CommandAvailable(commands...) { - return fmt.Errorf("not all commands available") + return errors.Errorf("not all commands available") } // Docker version checks @@ -129,10 +129,10 @@ func (p *PrerequisitesChecker) Run(workdir string) error { logrus.Infof("Verifying minimum Docker version %s", minVersion) versionOutput, err := p.impl.DockerVersion() if err != nil { - return fmt.Errorf("validate docker version: %w", err) + return errors.Wrap(err, "validate docker version") } if versionOutput < minVersion { - return fmt.Errorf( + return errors.Errorf( "minimum docker version %s required, got %s", minVersion, versionOutput, ) @@ -143,7 +143,7 @@ func (p *PrerequisitesChecker) Run(workdir string) error { if _, err := p.impl.GCloudOutput( "config", "get-value", "project", ); err != nil { - return fmt.Errorf("no account authorized through gcloud: %w", err) + return errors.Wrap(err, "no account authorized through gcloud") } // GitHub checks @@ -152,7 +152,7 @@ func (p *PrerequisitesChecker) Run(workdir string) error { "Verifying that %s environemt variable is set", github.TokenEnvKey, ) if !p.impl.IsEnvSet(github.TokenEnvKey) { - return fmt.Errorf("no %s env variable set", github.TokenEnvKey) + return errors.Errorf("no %s env variable set", github.TokenEnvKey) } } @@ -163,11 +163,11 @@ func (p *PrerequisitesChecker) Run(workdir string) error { ) res, err := p.impl.Usage(workdir) if err != nil { - return fmt.Errorf("check available disk space: %w", err) + return errors.Wrap(err, "check available disk space") } diskSpaceGiB := res.Free / 1024 / 1024 / 1024 if diskSpaceGiB < minDiskSpaceGiB { - return fmt.Errorf( + return errors.Errorf( "not enough disk space available. Got %dGiB, need at least %dGiB", diskSpaceGiB, minDiskSpaceGiB, ) @@ -176,7 +176,7 @@ func (p *PrerequisitesChecker) Run(workdir string) error { // Git setup check logrus.Info("Configuring git user and email") if err := p.impl.ConfigureGlobalDefaultUserAndEmail(); err != nil { - return fmt.Errorf("configure git user and email: %w", err) + return errors.Wrap(err, "configure git user and email") } return nil diff --git a/pkg/release/provenance.go b/pkg/release/provenance.go index d610586a799..ad11e9904dd 100644 --- a/pkg/release/provenance.go +++ b/pkg/release/provenance.go @@ -24,6 +24,7 @@ import ( "strings" intoto "github.com/in-toto/in-toto-golang/in_toto" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/bom/pkg/provenance" @@ -56,7 +57,7 @@ func (pc *ProvenanceChecker) CheckStageProvenance(buildVersion string) error { // Init the local dir h := sha1.New() if _, err := h.Write([]byte(buildVersion)); err != nil { - return fmt.Errorf("creating dir: %w", err) + return errors.Wrap(err, "creating dir") } pc.options.StageDirectory = filepath.Join(pc.options.ScratchDirectory, fmt.Sprintf("%x", h.Sum(nil))) @@ -66,23 +67,23 @@ func (pc *ProvenanceChecker) CheckStageProvenance(buildVersion string) error { ) + string(filepath.Separator), ) if err != nil { - return fmt.Errorf("normalizing GCS stage path: %w", err) + return errors.Wrap(err, "normalizing GCS stage path") } // Download all the artifacts from the bucket if err := pc.impl.downloadStagedArtifacts(pc.options, pc.objStore, gcsPath); err != nil { - return fmt.Errorf("downloading staged artifacts: %w", err) + return errors.Wrap(err, "downloading staged artifacts") } // Preprocess the attestation file. We have to rewrite the paths // to strip the GCS prefix statement, err := pc.impl.processAttestation(pc.options, buildVersion) if err != nil { - return fmt.Errorf("processing provenance attestation: %w", err) + return errors.Wrap(err, "processing provenance attestation") } // Run the check of the artifacts if err := pc.impl.checkProvenance(pc.options, statement); err != nil { - return fmt.Errorf("verifying provenance of staged artifacts: %w", err) + return errors.Wrap(err, "verifying provenance of staged artifacts") } logrus.Infof( "Successfully verified provenance information of %d staged artifacts", @@ -103,7 +104,7 @@ func (pc *ProvenanceChecker) GenerateFinalAttestation(buildVersion string, versi ), statementPath, version, ); err != nil { - return fmt.Errorf("generating provenance data for %s: %w", version, err) + return errors.Wrapf(err, "generating provenance data for %s", version) } } return nil @@ -131,13 +132,13 @@ func (di *defaultProvenanceCheckerImpl) downloadStagedArtifacts( logrus.Infof("Synching stage from %s to %s", path, opts.StageDirectory) if !util.Exists(opts.StageDirectory) { if err := os.MkdirAll(opts.StageDirectory, os.FileMode(0o755)); err != nil { - return fmt.Errorf("creating local working directory: %w", err) + return errors.Wrap(err, "creating local working directory") } } - if err := objStore.CopyToLocal(path, opts.StageDirectory); err != nil { - return fmt.Errorf("synching staged sources: %w", err) - } - return nil + return errors.Wrap( + objStore.CopyToLocal(path, opts.StageDirectory), + "synching staged sources", + ) } // processAttestation @@ -147,7 +148,7 @@ func (di *defaultProvenanceCheckerImpl) processAttestation( // Load the downloaded statement s, err = provenance.LoadStatement(filepath.Join(opts.StageDirectory, buildVersion, ProvenanceFilename)) if err != nil { - return nil, fmt.Errorf("loading staging provenance file: %w", err) + return nil, errors.Wrap(err, "loading staging provenance file") } // We've downloaded all artifacts, so to check we need to strip @@ -170,10 +171,7 @@ func (di *defaultProvenanceCheckerImpl) processAttestation( func (di *defaultProvenanceCheckerImpl) checkProvenance( opts *ProvenanceCheckerOptions, s *provenance.Statement, ) error { - if err := s.VerifySubjects(opts.StageDirectory); err != nil { - return fmt.Errorf("checking subjects in attestation: %w", err) - } - return nil + return errors.Wrap(s.VerifySubjects(opts.StageDirectory), "checking subjects in attestation") } func (di *defaultProvenanceCheckerImpl) generateFinalAttestation( @@ -181,7 +179,7 @@ func (di *defaultProvenanceCheckerImpl) generateFinalAttestation( ) error { doc, err := spdx.OpenDoc(sbom) if err != nil { - return fmt.Errorf("parsing sbom for version %s from %s: %w", version, sbom, err) + return errors.Wrapf(err, "parsing sbom for version %s from %s", version, sbom) } slsaStatement := doc.ToProvenanceStatement(spdx.DefaultProvenanceOptions) @@ -193,12 +191,14 @@ func (di *defaultProvenanceCheckerImpl) generateFinalAttestation( ) } if err := slsaStatement.ClonePredicate(stageProvenance); err != nil { - return fmt.Errorf("cloning SLSA predicate from staging provenance: %s: %w", stageProvenance, err) + return errors.Wrapf( + err, "cloning SLSA predicate from staging provenance: %s", stageProvenance, + ) } if err := slsaStatement.Write( filepath.Join(os.TempDir(), fmt.Sprintf("provenance-%s.json", version)), ); err != nil { - return fmt.Errorf("writing final provenance attestation for %s: %w", version, err) + return errors.Wrapf(err, "writing final provenance attestation for %s", version) } return nil @@ -253,16 +253,16 @@ func (di *defaultProvenanceReaderImpl) GetStagingSubjects( info, err := os.Stat(path) if err != nil { - return nil, fmt.Errorf("checking artifact path to generate provenance subjects: %w", err) + return nil, errors.Wrap(err, "checking artifact path to generate provenance subjects") } if info.IsDir() { if err := dummy.ReadSubjectsFromDir(path); err != nil { - return nil, fmt.Errorf("generating provenance subject from file %s: %w", path, err) + return nil, errors.Wrapf(err, "generating provenance subject from file %s", path) } } else { if err := dummy.AddSubjectFromFile(path); err != nil { - return nil, fmt.Errorf("generating provenance subject from file %s: %w", path, err) + return nil, errors.Wrapf(err, "generating provenance subject from file %s", path) } } @@ -291,7 +291,7 @@ func (di *defaultProvenanceReaderImpl) GetBuildSubjects( // translated. dummy := provenance.NewSLSAStatement() if err := dummy.ReadSubjectsFromDir(path); err != nil { - return nil, fmt.Errorf("reading output directory provenance subjects: %w", err) + return nil, errors.Wrap(err, "reading output directory provenance subjects") } // Cycle the subjects, translate the paths and copy them to the diff --git a/pkg/release/publish.go b/pkg/release/publish.go index ff4aaf59ff3..a22c6d594fc 100644 --- a/pkg/release/publish.go +++ b/pkg/release/publish.go @@ -23,6 +23,7 @@ import ( "path/filepath" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/gcli" @@ -170,7 +171,7 @@ func (p *Publisher) PublishVersion( sv, err := util.TagStringToSemver(version) if err != nil { - return fmt.Errorf("invalid version %s", version) + return errors.Errorf("invalid version %s", version) } markerPath, markerPathErr := p.client.GetMarkerPath( @@ -178,7 +179,7 @@ func (p *Publisher) PublishVersion( gcsRoot, ) if markerPathErr != nil { - return fmt.Errorf("get version marker path: %w", markerPathErr) + return errors.Wrap(markerPathErr, "get version marker path") } releasePath, releasePathErr := p.client.GetReleasePath( @@ -188,13 +189,13 @@ func (p *Publisher) PublishVersion( fast, ) if releasePathErr != nil { - return fmt.Errorf("get release path: %w", releasePathErr) + return errors.Wrap(releasePathErr, "get release path") } // TODO: This should probably be a more thorough check of explicit files // TODO: This should explicitly do a `gsutil ls` via gcs.PathExists if err := p.client.GSUtil("ls", releasePath); err != nil { - return fmt.Errorf("release files don't exist at %s: %w", releasePath, err) + return errors.Wrapf(err, "release files don't exist at %s", releasePath) } var versionMarkers []string @@ -225,7 +226,7 @@ func (p *Publisher) PublishVersion( versionMarker, markerPath, version, ) if err != nil { - return fmt.Errorf("verify latest update for %s: %w", versionMarker, err) + return errors.Wrapf(err, "verify latest update for %s", versionMarker) } // If there's a version that's above the one we're trying to release, @@ -241,7 +242,7 @@ func (p *Publisher) PublishVersion( if err := p.PublishToGcs( versionMarker, buildDir, markerPath, version, privateBucket, ); err != nil { - return fmt.Errorf("publish release to GCS: %w", err) + return errors.Wrap(err, "publish release to GCS") } } @@ -261,7 +262,7 @@ func (p *Publisher) VerifyLatestUpdate( publishFileDst, publishFileDstErr := p.client.NormalizePath(markerPath, publishFile) if publishFileDstErr != nil { - return false, fmt.Errorf("get marker file destination: %w", publishFileDstErr) + return false, errors.Wrap(publishFileDstErr, "get marker file destination") } // TODO: Should we add a object.`GCS` method for `gsutil cat`? @@ -273,12 +274,12 @@ func (p *Publisher) VerifyLatestUpdate( sv, err := util.TagStringToSemver(version) if err != nil { - return false, fmt.Errorf("invalid version format %s", version) + return false, errors.Errorf("invalid version format %s", version) } gcsSemverVersion, err := util.TagStringToSemver(gcsVersion) if err != nil { - return false, fmt.Errorf("invalid GCS version format %s", gcsVersion) + return false, errors.Errorf("invalid GCS version format %s", gcsVersion) } if sv.LTE(gcsSemverVersion) { @@ -304,7 +305,7 @@ func (p *Publisher) PublishToGcs( releaseStage := filepath.Join(buildDir, ReleaseStagePath) publishFileDst, publishFileDstErr := p.client.NormalizePath(markerPath, publishFile) if publishFileDstErr != nil { - return fmt.Errorf("get marker file destination: %w", publishFileDstErr) + return errors.Wrap(publishFileDstErr, "get marker file destination") } publicLink := fmt.Sprintf("%s/%s", URLPrefixForBucket(markerPath), publishFile) @@ -314,14 +315,14 @@ func (p *Publisher) PublishToGcs( uploadDir := filepath.Join(releaseStage, "upload") if err := os.MkdirAll(uploadDir, os.FileMode(0o755)); err != nil { - return fmt.Errorf("create upload dir %s: %w", uploadDir, err) + return errors.Wrapf(err, "create upload dir %s", uploadDir) } latestFile := filepath.Join(uploadDir, "latest") if err := os.WriteFile( latestFile, []byte(version), os.FileMode(0o644), ); err != nil { - return fmt.Errorf("write latest version file: %w", err) + return errors.Wrap(err, "write latest version file") } if err := p.client.GSUtil( @@ -332,7 +333,7 @@ func (p *Publisher) PublishToGcs( latestFile, publishFileDst, ); err != nil { - return fmt.Errorf("copy %s to %s: %w", latestFile, publishFileDst, err) + return errors.Wrapf(err, "copy %s to %s", latestFile, publishFileDst) } var content string @@ -351,7 +352,7 @@ func (p *Publisher) PublishToGcs( "acl", "ch", "-R", "-g", "all:R", publishFileDst, ) if err != nil { - return fmt.Errorf("change %s permissions: %w", publishFileDst, err) + return errors.Wrapf(err, "change %s permissions", publishFileDst) } logrus.Infof("Making uploaded version file public: %s", aclOutput) } @@ -359,20 +360,20 @@ func (p *Publisher) PublishToGcs( // If public, validate public link response, err := p.client.GetURLResponse(publicLink) if err != nil { - return fmt.Errorf("get content of %s: %w", publicLink, err) + return errors.Wrapf(err, "get content of %s", publicLink) } content = response } else { response, err := p.client.GSUtilOutput("cat", publicLink) if err != nil { - return fmt.Errorf("get content of %s: %w", publicLink, err) + return errors.Wrapf(err, "get content of %s", publicLink) } content = response } logrus.Infof("Validating uploaded version file at %s", publicLink) if version != content { - return fmt.Errorf( + return errors.Errorf( "version %s it not equal response %s", version, content, ) @@ -393,18 +394,18 @@ func (p *Publisher) PublishReleaseNotesIndex( gcsIndexRootPath, releaseNotesIndex, ) if err != nil { - return fmt.Errorf("normalize index file: %w", err) + return errors.Wrap(err, "normalize index file") } logrus.Infof("Publishing release notes index %s", indexFilePath) releaseNotesFilePath, err := p.client.NormalizePath(gcsReleaseNotesPath) if err != nil { - return fmt.Errorf("normalize release notes file: %w", err) + return errors.Wrap(err, "normalize release notes file") } success, err := p.client.GSUtilStatus("-q", "stat", indexFilePath) if err != nil { - return fmt.Errorf("run gcsutil stat: %w", err) + return errors.Wrap(err, "run gcsutil stat") } logrus.Info("Building release notes index") @@ -414,7 +415,7 @@ func (p *Publisher) PublishReleaseNotesIndex( tempDir, err := p.client.TempDir("", "release-notes-index-") if err != nil { - return fmt.Errorf("create temp dir: %w", err) + return errors.Wrap(err, "create temp dir") } defer os.RemoveAll(tempDir) tempIndexFile := filepath.Join(tempDir, releaseNotesIndex) @@ -422,16 +423,16 @@ func (p *Publisher) PublishReleaseNotesIndex( if err := p.client.CopyToLocal( indexFilePath, tempIndexFile, ); err != nil { - return fmt.Errorf("copy index file to local: %w", err) + return errors.Wrap(err, "copy index file to local") } indexBytes, err := p.client.ReadFile(tempIndexFile) if err != nil { - return fmt.Errorf("read local index file: %w", err) + return errors.Wrap(err, "read local index file") } if err := p.client.Unmarshal(indexBytes, &versions); err != nil { - return fmt.Errorf("unmarshal versions: %w", err) + return errors.Wrap(err, "unmarshal versions") } } else { logrus.Info("Creating non existing release notes index file") @@ -440,24 +441,24 @@ func (p *Publisher) PublishReleaseNotesIndex( versionJSON, err := p.client.Marshal(versions) if err != nil { - return fmt.Errorf("marshal version JSON: %w", err) + return errors.Wrap(err, "marshal version JSON") } logrus.Infof("Writing new release notes index: %s", string(versionJSON)) tempFile, err := p.client.TempFile("", "release-notes-index-") if err != nil { - return fmt.Errorf("create temp file: %w", err) + return errors.Wrap(err, "create temp file") } defer os.Remove(tempFile.Name()) if _, err := tempFile.Write(versionJSON); err != nil { - return fmt.Errorf("write temp index: %w", err) + return errors.Wrap(err, "write temp index") } logrus.Info("Uploading release notes index") if err := p.client.CopyToRemote( tempFile.Name(), indexFilePath, ); err != nil { - return fmt.Errorf("upload index file: %w", err) + return errors.Wrap(err, "upload index file") } return nil diff --git a/pkg/release/publish_test.go b/pkg/release/publish_test.go index f76d1709cbd..8a76e518d1f 100644 --- a/pkg/release/publish_test.go +++ b/pkg/release/publish_test.go @@ -17,10 +17,10 @@ limitations under the License. package release_test import ( - "errors" "os" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/require" "k8s.io/release/pkg/release" "k8s.io/release/pkg/release/releasefakes" diff --git a/pkg/release/push_git_objects.go b/pkg/release/push_git_objects.go index a664435be95..28b82ceea45 100644 --- a/pkg/release/push_git_objects.go +++ b/pkg/release/push_git_objects.go @@ -17,11 +17,11 @@ limitations under the License. package release import ( - "errors" "fmt" "strings" "github.com/blang/semver" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/git" "sigs.k8s.io/release-utils/util" @@ -51,12 +51,12 @@ type GitObjectPusherOptions struct { func NewGitPusher(opts *GitObjectPusherOptions) (*GitObjectPusher, error) { repo, err := git.OpenRepo(opts.RepoPath) if err != nil { - return nil, fmt.Errorf("while opening repository: %w", err) + return nil, errors.Wrap(err, "while opening repository") } logrus.Infof("Checkout %s branch to push objects", git.DefaultBranch) if err := repo.Checkout(git.DefaultBranch); err != nil { - return nil, fmt.Errorf("checking out %s branch: %w", git.DefaultBranch, err) + return nil, errors.Wrapf(err, "checking out %s branch", git.DefaultBranch) } // Pass the dry-run flag to the repo @@ -78,7 +78,7 @@ func NewGitPusher(opts *GitObjectPusherOptions) (*GitObjectPusher, error) { func (gp *GitObjectPusher) PushBranches(branchList []string) error { for _, branchName := range branchList { if err := gp.PushBranch(branchName); err != nil { - return fmt.Errorf("pushing %s branch: %w", branchName, err) + return errors.Wrapf(err, "pushing %s branch", branchName) } } logrus.Infof("Successfully pushed %d branches", len(branchList)) @@ -90,31 +90,31 @@ func (gp *GitObjectPusher) PushBranches(branchList []string) error { func (gp *GitObjectPusher) PushBranch(branchName string) error { // Check if the branch name is correct if err := gp.checkBranchName(branchName); err != nil { - return fmt.Errorf("checking branch name: %w", err) + return errors.Wrap(err, "checking branch name") } // To be able to push a branch the ref has to exist in the local repo: branchExists, err := gp.repo.HasBranch(branchName) if err != nil { - return fmt.Errorf("checking if branch already exists locally: %w", err) + return errors.Wrap(err, "checking if branch already exists locally") } if !branchExists { - return fmt.Errorf("unable to push branch %s, it does not exist in the local repo", branchName) + return errors.Errorf("unable to push branch %s, it does not exist in the local repo", branchName) } // Checkout the branch before merging logrus.Infof("Checking out branch %s to merge upstream changes", branchName) if err := gp.repo.Checkout(branchName); err != nil { - return fmt.Errorf("checking out branch %s: %w", git.Remotify(branchName), err) + return errors.Wrapf(err, "checking out branch %s", git.Remotify(branchName)) } if err := gp.mergeRemoteIfRequired(branchName); err != nil { - return fmt.Errorf("merge remote if required: %w", err) + return errors.Wrap(err, "merge remote if required") } logrus.Infof("Pushing%s %s branch:", dryRunLabel[gp.opts.DryRun], branchName) if err := gp.repo.Push(branchName); err != nil { - return fmt.Errorf("pushing branch %s: %w", branchName, err) + return errors.Wrapf(err, "pushing branch %s", branchName) } logrus.Infof("Branch %s pushed successfully", branchName) return nil @@ -124,7 +124,7 @@ func (gp *GitObjectPusher) PushBranch(branchName string) error { func (gp *GitObjectPusher) PushTags(tagList []string) (err error) { for _, tag := range tagList { if err := gp.PushTag(tag); err != nil { - return fmt.Errorf("while pushing %s tag: %w", tag, err) + return errors.Wrapf(err, "while pushing %s tag", tag) } } logrus.Infof("Pushed %d tags to the remote repo", len(tagList)) @@ -135,13 +135,13 @@ func (gp *GitObjectPusher) PushTags(tagList []string) (err error) { func (gp *GitObjectPusher) PushTag(newTag string) (err error) { // Verify that the tag is a valid tag if err := gp.checkTagName(newTag); err != nil { - return fmt.Errorf("parsing version tag: %w", err) + return errors.Wrap(err, "parsing version tag") } // Check if tag already exists currentTags, err := gp.repo.Tags() if err != nil { - return fmt.Errorf("checking if tag exists: %w", err) + return errors.Wrap(err, "checking if tag exists") } // verify that the tag exists locally before trying to push @@ -153,13 +153,13 @@ func (gp *GitObjectPusher) PushTag(newTag string) (err error) { } } if !tagExists { - return fmt.Errorf("unable to push tag %s, it does not exist in the repo yet", newTag) + return errors.Errorf("unable to push tag %s, it does not exist in the repo yet", newTag) } // CHeck if tag already exists in the remote repo tagExists, err = gp.repo.HasRemoteTag(newTag) if err != nil { - return fmt.Errorf("checking of tag %s exists: %w", newTag, err) + return errors.Wrapf(err, "checking of tag %s exists", newTag) } // If the tag already exists in the remote, we return success @@ -172,7 +172,7 @@ func (gp *GitObjectPusher) PushTag(newTag string) (err error) { // Push the new tag, retrying up to opts.MaxRetries times if err := gp.repo.Push(newTag); err != nil { - return fmt.Errorf("pushing tag %s: %w", newTag, err) + return errors.Wrapf(err, "pushing tag %s", newTag) } logrus.Infof("Successfully pushed tag %s", newTag) @@ -183,7 +183,7 @@ func (gp *GitObjectPusher) PushTag(newTag string) (err error) { func (gp *GitObjectPusher) checkTagName(tagName string) error { _, err := util.TagStringToSemver(tagName) if err != nil { - return fmt.Errorf("tranforming tag into semver: %w", err) + return errors.Wrap(err, "tranforming tag into semver") } return nil } @@ -191,13 +191,13 @@ func (gp *GitObjectPusher) checkTagName(tagName string) error { // checkBranchName verifies that the branch name is valid func (gp *GitObjectPusher) checkBranchName(branchName string) error { if !strings.HasPrefix(branchName, "release-") { - return errors.New("branch name has to start with release-") + return errors.New("Branch name has to start with release-") } versionTag := strings.TrimPrefix(branchName, "release-") // Add .0 and check is we get a valid semver _, err := semver.Parse(versionTag + ".0") if err != nil { - return fmt.Errorf("parsing semantic version in branchname: %w", err) + return errors.Wrap(err, "parsing semantic version in branchname") } return nil } @@ -206,13 +206,13 @@ func (gp *GitObjectPusher) checkBranchName(branchName string) error { func (gp *GitObjectPusher) PushMain() error { logrus.Infof("Checkout %s branch to push objects", git.DefaultBranch) if err := gp.repo.Checkout(git.DefaultBranch); err != nil { - return fmt.Errorf("checking out %s branch: %w", git.DefaultBranch, err) + return errors.Wrapf(err, "checking out %s branch", git.DefaultBranch) } // logrun -v git status -s || return 1 status, err := gp.repo.Status() if err != nil { - return fmt.Errorf("while reading the repository status: %w", err) + return errors.Wrap(err, "while reading the repository status") } if status.String() == "" { logrus.Info("Repository status: no modified paths") @@ -223,7 +223,7 @@ func (gp *GitObjectPusher) PushMain() error { // logrun -v git show || return 1 lastLog, err := gp.repo.ShowLastCommit() if err != nil { - return fmt.Errorf("getting last commit data from log: %w", err) + return errors.Wrap(err, "getting last commit data from log") } logrus.Info(lastLog) @@ -231,18 +231,18 @@ func (gp *GitObjectPusher) PushMain() error { _, err = gp.repo.FetchRemote(git.DefaultRemote) if err != nil { - return fmt.Errorf("while fetching origin repository: %w", err) + return errors.Wrap(err, "while fetching origin repository") } if err := gp.repo.Rebase(fmt.Sprintf("%s/%s", git.DefaultRemote, git.DefaultBranch)); err != nil { - return fmt.Errorf("rebasing repository: %w", err) + return errors.Wrap(err, "rebasing repository") } logrus.Infof("Pushing%s %s branch", dryRunLabel[gp.opts.DryRun], git.DefaultBranch) // logrun -s git push$dryrun_flag origin master || return 1 if err := gp.repo.Push(git.DefaultBranch); err != nil { - return fmt.Errorf("pushing %s branch: %w", git.DefaultBranch, err) + return errors.Wrapf(err, "pushing %s branch", git.DefaultBranch) } return nil } @@ -254,12 +254,14 @@ func (gp *GitObjectPusher) mergeRemoteIfRequired(branch string) error { logrus.Infof("Fetching from %s", git.DefaultRemote) if _, err := gp.repo.FetchRemote(git.DefaultRemote); err != nil { - return fmt.Errorf("fetch remote: %w", err) + return errors.Wrap(err, "fetch remote") } branchExists, err := gp.repo.HasRemoteBranch(branchParts[1]) if err != nil { - return fmt.Errorf("checking if branch %s exists in repo remote: %w", branch, err) + return errors.Wrapf( + err, "checking if branch %s exists in repo remote", branch, + ) } if !branchExists { logrus.Infof( @@ -270,7 +272,9 @@ func (gp *GitObjectPusher) mergeRemoteIfRequired(branch string) error { logrus.Infof("Merging %s branch", branch) if err := gp.repo.Merge(branch); err != nil { - return fmt.Errorf("merging remote branch %s to local repo: %w", branch, err) + return errors.Wrapf( + err, "merging remote branch %s to local repo", branch, + ) } logrus.Info("Local branch is now up to date") diff --git a/pkg/release/push_git_objects_test.go b/pkg/release/push_git_objects_test.go index a07964cd4ab..35e6049d401 100644 --- a/pkg/release/push_git_objects_test.go +++ b/pkg/release/push_git_objects_test.go @@ -17,11 +17,11 @@ limitations under the License. package release import ( - "fmt" "os" "strings" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/require" "sigs.k8s.io/release-sdk/git" "sigs.k8s.io/release-utils/command" @@ -31,13 +31,13 @@ func getTestGitObjectPusher() (pusher *GitObjectPusher, repoPath string, err err // Initialize a test repository for the test pusher repoPath, err = os.MkdirTemp("", "sigrelease-test-repo-*") if err != nil { - return nil, "", fmt.Errorf("creating a directory for test repository: %w", err) + return nil, "", errors.Wrap(err, "creating a directory for test repository") } if err := command.NewWithWorkDir( repoPath, "git", "init").RunSilentSuccess(); err != nil { os.RemoveAll(repoPath) - return nil, repoPath, fmt.Errorf("initializing test repository: %w", err) + return nil, repoPath, errors.Wrapf(err, "initializing test repository") } // Create root commit @@ -45,25 +45,25 @@ func getTestGitObjectPusher() (pusher *GitObjectPusher, repoPath string, err err repoPath, "git", "commit", "--allow-empty", "-m", "Root commit", ).RunSilentSuccess(); err != nil { os.RemoveAll(repoPath) - return nil, repoPath, fmt.Errorf("creating first commit: %w", err) + return nil, repoPath, errors.Wrapf(err, "creating first commit") } // Check if branch exists (in case initial branch is 'main' and we expect 'master') out, err := command.NewWithWorkDir(repoPath, "git", "branch").RunSuccessOutput() if err != nil { - return nil, repoPath, fmt.Errorf("listing branches in test repo: %w", err) + return nil, repoPath, errors.Wrap(err, "listing branches in test repo") } if !strings.Contains(out.Output(), git.DefaultBranch) { if err := command.NewWithWorkDir( repoPath, "git", "branch", git.DefaultBranch, ).RunSilentSuccess(); err != nil { - return nil, repoPath, fmt.Errorf("creating main branch: %w", err) + return nil, repoPath, errors.Wrap(err, "creating main branch") } } pusher, err = NewGitPusher(&GitObjectPusherOptions{RepoPath: repoPath}) if err != nil { - return nil, repoPath, fmt.Errorf("creating test git pusher: %w", err) + return nil, repoPath, errors.Wrap(err, "creating test git pusher") } return pusher, repoPath, nil diff --git a/pkg/release/release.go b/pkg/release/release.go index 0478331acd3..dfeaf978bda 100644 --- a/pkg/release/release.go +++ b/pkg/release/release.go @@ -19,7 +19,6 @@ package release import ( "crypto/sha256" "crypto/sha512" - "errors" "fmt" "hash" "io" @@ -28,6 +27,7 @@ import ( "regexp" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/promo-tools/v3/image" @@ -255,13 +255,15 @@ func GetWorkspaceVersion() (string, error) { workspaceStatusScript := "hack/print-workspace-status.sh" _, workspaceStatusScriptStatErr := os.Stat(workspaceStatusScript) if os.IsNotExist(workspaceStatusScriptStatErr) { - return "", fmt.Errorf("checking for workspace status script: %w", workspaceStatusScriptStatErr) + return "", errors.Wrapf(workspaceStatusScriptStatErr, + "checking for workspace status script", + ) } logrus.Info("Getting workspace status") workspaceStatusStream, getWorkspaceStatusErr := command.New(workspaceStatusScript).RunSuccessOutput() if getWorkspaceStatusErr != nil { - return "", fmt.Errorf("getting workspace status: %w", getWorkspaceStatusErr) + return "", errors.Wrapf(getWorkspaceStatusErr, "getting workspace status") } workspaceStatus := workspaceStatusStream.Output() @@ -291,7 +293,7 @@ func CopyBinaries(rootPath, targetPath string) error { platformsPath := filepath.Join(rootPath, "client") platformsAndArches, err := os.ReadDir(platformsPath) if err != nil { - return fmt.Errorf("retrieve platforms from %s: %w", platformsPath, err) + return errors.Wrapf(err, "retrieve platforms from %s", platformsPath) } for _, platformArch := range platformsAndArches { @@ -305,7 +307,7 @@ func CopyBinaries(rootPath, targetPath string) error { split := strings.Split(platformArch.Name(), "-") if len(split) != 2 { - return fmt.Errorf( + return errors.Errorf( "expected `platform-arch` format for %s", platformArch.Name(), ) } @@ -331,7 +333,9 @@ func CopyBinaries(rootPath, targetPath string) error { dst := filepath.Join(targetPath, "bin", platform, arch) logrus.Infof("Copying server binaries from %s to %s", src, dst) if err := util.CopyDirContentsLocal(src, dst); err != nil { - return fmt.Errorf("copy server binaries from %s to %s: %w", src, dst, err) + return errors.Wrapf(err, + "copy server binaries from %s to %s", src, dst, + ) } // Copy node binaries if they exist and this isn't a 'server' platform @@ -341,7 +345,9 @@ func CopyBinaries(rootPath, targetPath string) error { logrus.Infof("Copying node binaries from %s to %s", src, dst) if err := util.CopyDirContentsLocal(src, dst); err != nil { - return fmt.Errorf("copy node binaries from %s to %s: %w", src, dst, err) + return errors.Wrapf(err, + "copy node binaries from %s to %s", src, dst, + ) } } } @@ -369,22 +375,22 @@ func WriteChecksums(rootPath string) error { sha, err := rhash.ForFile(path, hasher) if err != nil { - return fmt.Errorf("get hash from file: %w", err) + return errors.Wrap(err, "get hash from file") } files = append(files, fmt.Sprintf("%s %s", sha, path)) return nil }, ); err != nil { - return "", fmt.Errorf("traversing root path %s: %w", rootPath, err) + return "", errors.Wrapf(err, "traversing root path %s", rootPath) } file, err := os.Create(fileName) if err != nil { - return "", fmt.Errorf("create file %s: %w", fileName, err) + return "", errors.Wrapf(err, "create file %s", fileName) } if _, err := file.WriteString(strings.Join(files, "\n")); err != nil { - return "", fmt.Errorf("write to file %s: %w", fileName, err) + return "", errors.Wrapf(err, "write to file %s", fileName) } return file.Name(), nil @@ -394,11 +400,11 @@ func WriteChecksums(rootPath string) error { // We checksum everything except our checksum files, which we do next. sha256SumsFile, err := createSHASums(sha256.New()) if err != nil { - return fmt.Errorf("create SHA256 sums: %w", err) + return errors.Wrap(err, "create SHA256 sums") } sha512SumsFile, err := createSHASums(sha512.New()) if err != nil { - return fmt.Errorf("create SHA512 sums: %w", err) + return errors.Wrap(err, "create SHA512 sums") } // After all the checksum files are generated, move them into the bucket @@ -407,18 +413,18 @@ func WriteChecksums(rootPath string) error { if err := util.CopyFileLocal( file, filepath.Join(rootPath, file), true, ); err != nil { - return fmt.Errorf("move %s sums file to %s: %w", file, rootPath, err) + return errors.Wrapf(err, "move %s sums file to %s", file, rootPath) } if err := os.RemoveAll(file); err != nil { - return fmt.Errorf("remove file %s: %w", file, err) + return errors.Wrapf(err, "remove file %s", file) } return nil } if err := moveFile(sha256SumsFile); err != nil { - return fmt.Errorf("move SHA256 sums: %w", err) + return errors.Wrap(err, "move SHA256 sums") } if err := moveFile(sha512SumsFile); err != nil { - return fmt.Errorf("move SHA512 sums: %w", err) + return errors.Wrap(err, "move SHA512 sums") } logrus.Infof("Hashing files in %s", rootPath) @@ -426,14 +432,14 @@ func WriteChecksums(rootPath string) error { writeSHAFile := func(fileName string, hasher hash.Hash) error { sha, err := rhash.ForFile(fileName, hasher) if err != nil { - return fmt.Errorf("get hash from file: %w", err) + return errors.Wrap(err, "get hash from file") } shaFileName := fmt.Sprintf("%s.sha%d", fileName, hasher.Size()*8) - if err := os.WriteFile(shaFileName, []byte(sha), os.FileMode(0o644)); err != nil { - return fmt.Errorf("write SHA to file %s: %w", shaFileName, err) - } - return nil + return errors.Wrapf( + os.WriteFile(shaFileName, []byte(sha), os.FileMode(0o644)), + "write SHA to file %s", shaFileName, + ) } if err := filepath.Walk(rootPath, @@ -446,16 +452,16 @@ func WriteChecksums(rootPath string) error { } if err := writeSHAFile(path, sha256.New()); err != nil { - return fmt.Errorf("write %s.sha256: %w", file.Name(), err) + return errors.Wrapf(err, "write %s.sha256", file.Name()) } if err := writeSHAFile(path, sha512.New()); err != nil { - return fmt.Errorf("write %s.sha512: %w", file.Name(), err) + return errors.Wrapf(err, "write %s.sha512", file.Name()) } return nil }, ); err != nil { - return fmt.Errorf("traversing root path %s: %w", rootPath, err) + return errors.Wrapf(err, "traversing root path %s", rootPath) } return nil @@ -485,7 +491,7 @@ func CreatePubBotBranchIssue(branchName string) error { &github.NewIssueOptions{}, ) if err != nil { - return fmt.Errorf("creating publishing bot issue: %w", err) + return errors.Wrap(err, "creating publishing bot issue") } logrus.Infof("Publishing bot issue created #%d!", issue.GetNumber()) return nil @@ -495,7 +501,7 @@ func CreatePubBotBranchIssue(branchName string) error { func DockerHubLogin() error { // Check the environment variable is set if os.Getenv(DockerHubEnvKey) == "" { - return errors.New("unable to find docker token in the environment") + return errors.New("Unable to find docker token in the environment") } // Pipe the token into docker login cmd := command.New( @@ -505,7 +511,7 @@ func DockerHubLogin() error { // Run docker login: if err := cmd.RunSuccess(); err != nil { errStr := strings.ReplaceAll(err.Error(), os.Getenv(DockerHubEnvKey), "**********") - return fmt.Errorf("%s: logging into Docker Hub", errStr) + return errors.Wrap(errors.New(errStr), "logging into Docker Hub") } logrus.Infof("User %s successfully logged into Docker Hub", DockerHubUserName) return nil diff --git a/pkg/release/release_version.go b/pkg/release/release_version.go index 787a3919884..465fa4c60d0 100644 --- a/pkg/release/release_version.go +++ b/pkg/release/release_version.go @@ -22,6 +22,7 @@ import ( "strconv" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/regex" @@ -130,7 +131,7 @@ func GenerateReleaseVersion( // if branch == release+1, version is an alpha v, err := util.TagStringToSemver(version) if err != nil { - return nil, fmt.Errorf("invalid formatted version %s", version) + return nil, errors.Errorf("invalid formatted version %s", version) } var label string @@ -153,15 +154,19 @@ func GenerateReleaseVersion( if branchFromMaster { // nolint:gocritic // a switch case would not make it better branchMatch := regex.BranchRegex.FindStringSubmatch(branch) if len(branchMatch) < 3 { - return nil, fmt.Errorf("invalid formatted branch %s", branch) + return nil, errors.Errorf("invalid formatted branch %s", branch) } branchMajor, err := strconv.Atoi(branchMatch[1]) if err != nil { - return nil, fmt.Errorf("parsing branch major version %q to int: %w", branchMatch[1], err) + return nil, errors.Wrapf( + err, "parsing branch major version %q to int", branchMatch[1], + ) } branchMinor, err := strconv.Atoi(branchMatch[2]) if err != nil { - return nil, fmt.Errorf("parsing branch minor version %q to int: %w", branchMatch[2], err) + return nil, errors.Wrapf( + err, "parsing branch minor version %q to int", branchMatch[2], + ) } releaseBranch := struct{ major, minor int }{ major: branchMajor, minor: branchMinor, @@ -232,7 +237,7 @@ func GenerateReleaseVersion( // Concretely: // We should not be able to cut x.y.z-alpha.N after x.y.z-beta.M if label != ReleaseTypeAlpha { - return nil, fmt.Errorf( + return nil, errors.Errorf( "cannot cut an alpha tag after a non-alpha release %s. %s", version, "please specify an allowed release type ('beta')", diff --git a/pkg/release/repository.go b/pkg/release/repository.go index 20c17b010b4..80b3079aa71 100644 --- a/pkg/release/repository.go +++ b/pkg/release/repository.go @@ -17,13 +17,13 @@ limitations under the License. package release import ( - "errors" "fmt" "os" "path/filepath" "strings" "time" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/git" @@ -56,11 +56,11 @@ type Repository interface { func (r *Repo) Open() error { dir, err := os.Getwd() if err != nil { - return fmt.Errorf("getting current working directory: %w", err) + return errors.Wrap(err, "getting current working directory") } repo, err := git.OpenRepo(dir) if err != nil { - return fmt.Errorf("opening release repository: %w", err) + return errors.Wrap(err, "opening release repository") } r.repo = repo return nil @@ -80,7 +80,7 @@ func (r *Repo) GetTag() (string, error) { WithTags(), ) if err != nil { - return "", fmt.Errorf("running git describe: %w", err) + return "", errors.Wrap(err, "running git describe") } t := time.Now().Format("20060102") return fmt.Sprintf("%s-%s", describeOutput, t), nil @@ -92,7 +92,7 @@ func (r *Repo) CheckState(expOrg, expRepo, expRev string, nomock bool) error { dirty, err := r.repo.IsDirty() if err != nil { - return fmt.Errorf("checking if repository is dirty: %w", err) + return errors.Wrap(err, "checking if repository is dirty") } if dirty { return errors.New( @@ -103,23 +103,23 @@ func (r *Repo) CheckState(expOrg, expRepo, expRev string, nomock bool) error { branch, err := r.repo.CurrentBranch() if err != nil { - return fmt.Errorf("retrieving current branch: %w", err) + return errors.Wrap(err, "retrieving current branch") } head, err := r.repo.Head() if err != nil { - return fmt.Errorf("retrieving repository HEAD: %w", err) + return errors.Wrap(err, "retrieving repository HEAD") } logrus.Infof("Repo head is: %s", head) rev, err := r.repo.RevParse(expRev) if err != nil { - return fmt.Errorf("retrieving rev-parse for %s: %w", expRev, err) + return errors.Wrapf(err, "retrieving rev-parse for %s", expRev) } if rev != head { - return fmt.Errorf("revision %q expected but got %q", head, rev) + return errors.Errorf("revision %q expected but got %q", head, rev) } if nomock && !(expOrg == DefaultToolOrg && expRepo == DefaultToolRepo && expRev == DefaultToolRef) { @@ -131,7 +131,7 @@ func (r *Repo) CheckState(expOrg, expRepo, expRev string, nomock bool) error { // Verify the remote remotes, err := r.repo.Remotes() if err != nil { - return fmt.Errorf("retrieving repository remotes: %w", err) + return errors.Wrap(err, "retrieving repository remotes") } var foundRemote *git.Remote for _, remote := range remotes { @@ -146,7 +146,7 @@ func (r *Repo) CheckState(expOrg, expRepo, expRev string, nomock bool) error { } } if foundRemote == nil { - return fmt.Errorf( + return errors.Errorf( "unable to find remote matching organization %q and repository %q", expOrg, expRepo, ) @@ -175,19 +175,19 @@ func (r *Repo) CheckState(expOrg, expRepo, expRev string, nomock bool) error { } lsRemoteOut, err := r.repo.LsRemote(args...) if err != nil { - return fmt.Errorf("getting remote HEAD: %w", err) + return errors.Wrap(err, "getting remote HEAD") } fields := strings.Fields(lsRemoteOut) if len(fields) < 1 { - return fmt.Errorf("unexpected output: %s", lsRemoteOut) + return errors.Errorf("unexpected output: %s", lsRemoteOut) } commit := fields[0] logrus.Infof("Got remote commit: %s", commit) logrus.Info("Verifying that remote commit is equal to the local one") if head != commit { - return fmt.Errorf( - "local HEAD (%s) is not equal to latest remote commit (%s)", + return errors.Errorf( + "Local HEAD (%s) is not equal to latest remote commit (%s)", head, commit, ) } diff --git a/pkg/release/version.go b/pkg/release/version.go index 7a5aaf066d0..a190bbf88d8 100644 --- a/pkg/release/version.go +++ b/pkg/release/version.go @@ -17,9 +17,9 @@ limitations under the License. package release import ( - "fmt" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/git" @@ -107,7 +107,7 @@ func (v *Version) GetKubeVersionForBranch(versionType VersionType, branch string version := "" if branch != git.DefaultBranch { if !git.IsReleaseBranch(branch) { - return "", fmt.Errorf("%s is not a valid release branch", branch) + return "", errors.Errorf("%s is not a valid release branch", branch) } version = strings.TrimPrefix(branch, "release-") } @@ -122,7 +122,7 @@ func (v *Version) kubeVersionFromURL(url string) (string, error) { logrus.Infof("Retrieving Kubernetes build version from %s...", url) version, httpErr := v.client.GetURLResponse(url) if httpErr != nil { - return "", fmt.Errorf("retrieving kube version: %w", httpErr) + return "", errors.Wrap(httpErr, "retrieving kube version") } logrus.Infof("Retrieved Kubernetes version: %s", version) diff --git a/pkg/release/workspace.go b/pkg/release/workspace.go index feb9925d83d..a82decc6884 100644 --- a/pkg/release/workspace.go +++ b/pkg/release/workspace.go @@ -17,13 +17,13 @@ limitations under the License. package release import ( - "errors" "fmt" "net/url" "os" "path/filepath" "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/bom/pkg/license" @@ -48,11 +48,11 @@ func PrepareWorkspaceStage(directory string, noMock bool) error { // the artifacts into non-default locations. This needs further // investigation and goes beyond the currently implemented testing // approach. - return errors.New( + return errors.Errorf( "staging non default upstream Kubernetes is forbidden. " + "Verify that the $K8S_ORG, $K8S_REPO and $K8S_REF " + "environment variables point to their defaults when " + - "doing using nomock releases", + "doing using nomock releases.", ) } @@ -60,7 +60,7 @@ func PrepareWorkspaceStage(directory string, noMock bool) error { repo, err := git.CloneOrOpenGitHubRepo(directory, k8sOrg, k8sRepo, false) if err != nil { - return fmt.Errorf("clone k/k repository: %w", err) + return errors.Wrap(err, "clone k/k repository") } // Prewarm the SPDX licenses cache. As it is one of the main @@ -72,17 +72,17 @@ func PrepareWorkspaceStage(directory string, noMock bool) error { doptions.CacheDir = s.Options().LicenseCacheDir downloader, err := license.NewDownloaderWithOptions(doptions) if err != nil { - return fmt.Errorf("creating license downloader: %w", err) + return errors.Wrap(err, "creating license downloader") } // Fetch the SPDX licenses if _, err := downloader.GetLicenses(); err != nil { - return fmt.Errorf("retrieving SPDX licenses: %w", err) + return errors.Wrap(err, "retrieving SPDX licenses") } if isDefaultK8sUpstream { token, ok := os.LookupEnv(github.TokenEnvKey) if !ok { - return fmt.Errorf("%s env variable is not set", github.TokenEnvKey) + return errors.Errorf("%s env variable is not set", github.TokenEnvKey) } if err := repo.SetURL(git.DefaultRemote, (&url.URL{ @@ -91,7 +91,7 @@ func PrepareWorkspaceStage(directory string, noMock bool) error { Host: "github.com", Path: filepath.Join(git.DefaultGithubOrg, git.DefaultGithubRepo), }).String()); err != nil { - return fmt.Errorf("changing git remote of repository: %w", err) + return errors.Wrap(err, "changing git remote of repository") } } else { logrus.Info("Using non-default k8s upstream, doing no git modifications") @@ -107,7 +107,7 @@ func PrepareWorkspaceRelease(directory, buildVersion, bucket string) error { logrus.Infof("Searching for staged %s on %s", SourcesTar, bucket) tempDir, err := os.MkdirTemp("", "staged-") if err != nil { - return fmt.Errorf("create staged sources temp dir: %w", err) + return errors.Wrap(err, "create staged sources temp dir") } defer os.RemoveAll(tempDir) @@ -118,25 +118,25 @@ func PrepareWorkspaceRelease(directory, buildVersion, bucket string) error { gcs := object.NewGCS() gcs.WithAllowMissing(false) if err := gcs.CopyToLocal(src, dst); err != nil { - return fmt.Errorf("copying staged sources from GCS: %w", err) + return errors.Wrap(err, "copying staged sources from GCS") } logrus.Info("Got staged sources, extracting archive") if err := tar.Extract( dst, strings.TrimSuffix(directory, "/src/k8s.io/kubernetes"), ); err != nil { - return fmt.Errorf("extracting %s: %w", dst, err) + return errors.Wrapf(err, "extracting %s", dst) } // Reset the github token in the staged k/k clone token, ok := os.LookupEnv(github.TokenEnvKey) if !ok { - return fmt.Errorf("%s env variable is not set", github.TokenEnvKey) + return errors.Errorf("%s env variable is not set", github.TokenEnvKey) } repo, err := git.OpenRepo(directory) if err != nil { - return fmt.Errorf("opening staged clone of k/k: %w", err) + return errors.Wrap(err, "opening staged clone of k/k") } if err := repo.SetURL(git.DefaultRemote, (&url.URL{ @@ -145,7 +145,7 @@ func PrepareWorkspaceRelease(directory, buildVersion, bucket string) error { Host: "github.com", Path: filepath.Join(git.DefaultGithubOrg, git.DefaultGithubRepo), }).String()); err != nil { - return fmt.Errorf("changing git remote of repository: %w", err) + return errors.Wrap(err, "changing git remote of repository") } return nil @@ -170,7 +170,7 @@ func ListBuildBinaries(gitroot, version string) (list []struct{ Path, Platform, } platformsAndArches, err := os.ReadDir(platformsPath) if err != nil { - return nil, fmt.Errorf("retrieve platforms from %s: %w", platformsPath, err) + return nil, errors.Wrapf(err, "retrieve platforms from %s", platformsPath) } for _, platformArch := range platformsAndArches { @@ -184,7 +184,7 @@ func ListBuildBinaries(gitroot, version string) (list []struct{ Path, Platform, split := strings.Split(platformArch.Name(), "-") if len(split) != 2 { - return nil, fmt.Errorf( + return nil, errors.Errorf( "expected `platform-arch` format for %s", platformArch.Name(), ) } @@ -226,7 +226,7 @@ func ListBuildBinaries(gitroot, version string) (list []struct{ Path, Platform, return nil }, ); err != nil { - return nil, fmt.Errorf("gathering binaries from %s: %w", src, err) + return nil, errors.Wrapf(err, "gathering binaries from %s", src) } // Copy node binaries if they exist and this isn't a 'server' platform @@ -250,7 +250,7 @@ func ListBuildBinaries(gitroot, version string) (list []struct{ Path, Platform, return nil }, ); err != nil { - return nil, fmt.Errorf("gathering node binaries from %s: %w", src, err) + return nil, errors.Wrapf(err, "gathering node binaries from %s", src) } } } @@ -279,7 +279,7 @@ func ListBuildTarballs(gitroot, version string) (tarList []string, err error) { return nil }, ); err != nil { - return nil, fmt.Errorf("gathering tarfiles binaries from %s: %w", tarsPath, err) + return nil, errors.Wrapf(err, "gathering tarfiles binaries from %s", tarsPath) } return tarList, nil } @@ -293,7 +293,7 @@ func ListBuildImages(gitroot, version string) (imageList []string, err error) { arches, err := os.ReadDir(filepath.Join(buildDir, ImagesPath)) if err != nil { - return nil, fmt.Errorf("opening images directory: %w", err) + return nil, errors.Wrap(err, "opening images directory") } for _, arch := range arches { if !arch.IsDir() { @@ -301,7 +301,7 @@ func ListBuildImages(gitroot, version string) (imageList []string, err error) { } images, err := os.ReadDir(filepath.Join(buildDir, ImagesPath, arch.Name())) if err != nil { - return nil, fmt.Errorf("opening %s images directory: %w", arch.Name(), err) + return nil, errors.Wrapf(err, "opening %s images directory", arch.Name()) } for _, tarball := range images { imageList = append( diff --git a/pkg/testgrid/testgrid-scraper.go b/pkg/testgrid/testgrid-scraper.go index 4abaac097dd..92c3c66fcaf 100644 --- a/pkg/testgrid/testgrid-scraper.go +++ b/pkg/testgrid/testgrid-scraper.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/hashicorp/go-multierror" + "github.com/pkg/errors" ) // SummaryLookup this type is used if multiple testgrid summaries are getting requested concurrently @@ -66,7 +67,7 @@ func ReqTestgridDashboardSummaries(dashboardNames []DashboardName) (DashboardDat // Collect data from buffered channel for lookups := range requestData(done, dashboardNames...) { if lookups.Error != nil { - err = multierror.Append(err, fmt.Errorf("error requesting summary for dashboard %s: %w", lookups.Dashboard, lookups.Error)) + err = multierror.Append(err, errors.Wrapf(lookups.Error, "error requesting summary for dashboard %s", lookups.Dashboard)) } else { dashboardData[lookups.Dashboard] = lookups.Summary } @@ -78,16 +79,16 @@ func ReqTestgridDashboardSummaries(dashboardNames []DashboardName) (DashboardDat func ReqTestgridDashboardSummary(dashboardName DashboardName) (JobData, error) { resp, err := http.Get(fmt.Sprintf("https://testgrid.k8s.io/%s/summary", dashboardName)) if err != nil { - return nil, fmt.Errorf("request remote content: %w", err) + return nil, errors.Wrap(err, "request remote content") } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - return nil, fmt.Errorf("read response body: %w", err) + return nil, errors.Wrap(err, "read response body") } summary, err := UnmarshalTestgridSummary(body) if err != nil { - return nil, fmt.Errorf("unmarshal response body: %w", err) + return nil, errors.Wrap(err, "unmarshal response body") } return summary, nil } diff --git a/pkg/testgrid/testgrid.go b/pkg/testgrid/testgrid.go index 208276669f6..39efd7f092c 100644 --- a/pkg/testgrid/testgrid.go +++ b/pkg/testgrid/testgrid.go @@ -17,11 +17,11 @@ limitations under the License. package testgrid import ( - "fmt" "os" "github.com/GoogleCloudPlatform/testgrid/config" pb "github.com/GoogleCloudPlatform/testgrid/pb/config" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "sigs.k8s.io/release-utils/http" @@ -63,13 +63,13 @@ func (t *TestGrid) SetClient(client Client) { func (t *TestGrid) BlockingTests(branch string) (tests []string, err error) { conf, err := t.configFromURL(testgridConfigURL) if err != nil { - return nil, fmt.Errorf("cannot get config: %w", err) + return nil, errors.Wrap(err, "cannot get config") } dashboardName := "sig-" + branch + "-blocking" dashboard := config.FindDashboard(dashboardName, conf) if dashboard == nil { - return nil, fmt.Errorf("dashboard %s not found", dashboardName) + return nil, errors.Errorf("dashboard %s not found", dashboardName) } for _, tab := range dashboard.DashboardTab { @@ -94,11 +94,11 @@ func (t *TestGrid) configFromURL(url string) (cfg *pb.Configuration, err error) response, err := t.client.GetURLResponse(url, false) if err != nil { - return nil, fmt.Errorf("retrieving remote content: %w", err) + return nil, errors.Wrap(err, "retrieving remote content") } if _, err := tmpFile.WriteString(response); err != nil { - return nil, fmt.Errorf("writing response to file: %w", err) + return nil, errors.Wrap(err, "writing response to file") } return config.ReadPath(tmpFile.Name())