Skip to content

Commit

Permalink
Merge pull request #2558 from Priyankasaggu11929/psaggu-pkg-build
Browse files Browse the repository at this point in the history
pkg/build: replace github.com/pkg/errors dependency with native error wrapping
  • Loading branch information
k8s-ci-robot authored Jun 13, 2022
2 parents 55f8570 + 60d3e63 commit 9093576
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 71 deletions.
5 changes: 3 additions & 2 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ limitations under the License.
package build

import (
"github.com/pkg/errors"
"fmt"

"github.com/sirupsen/logrus"

"k8s.io/release/pkg/release"
Expand Down Expand Up @@ -137,7 +138,7 @@ func (bi *Instance) getGCSBuildPath(version string) (string, error) {
bi.opts.Fast,
)
if err != nil {
return "", errors.Wrap(err, "get GCS release path")
return "", fmt.Errorf("get GCS release path: %w", err)
}

return buildPath, nil
Expand Down
24 changes: 12 additions & 12 deletions pkg/build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -36,7 +36,7 @@ func (bi *Instance) Build() error {
var dirErr error
workingDir, dirErr = os.Getwd()
if dirErr != nil {
return errors.Wrapf(dirErr, "getting working directory")
return fmt.Errorf("getting working directory: %w", dirErr)
}
}
logrus.Infof("Current working directory: %s", workingDir)
Expand All @@ -45,7 +45,7 @@ func (bi *Instance) Build() error {
expectedDirRelative := "kubernetes"

if workingDirRelative != expectedDirRelative {
return errors.Errorf(
return fmt.Errorf(
"build was executed from the %s directory but must be run from the %s directory, exiting",
workingDirRelative,
expectedDirRelative,
Expand All @@ -54,7 +54,7 @@ func (bi *Instance) Build() error {

buildExists, buildExistsErr := bi.checkBuildExists()
if buildExistsErr != nil {
return errors.Wrapf(buildExistsErr, "checking if build exists")
return fmt.Errorf("checking if build exists: %w", buildExistsErr)
}

if buildExists {
Expand All @@ -66,22 +66,22 @@ func (bi *Instance) Build() error {
// TODO: Should this be configurable?
envErr := os.Setenv("KUBE_RELEASE_RUN_TESTS", "n")
if envErr != nil {
return errors.Wrapf(envErr, "setting 'KUBE_RELEASE_RUN_TESTS' to 'n'")
return fmt.Errorf("setting 'KUBE_RELEASE_RUN_TESTS' to 'n': %w", envErr)
}

// 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 errors.Wrapf(configureErr, "configuring docker auth")
return fmt.Errorf("configuring docker auth: %w", configureErr)
}
}

if cleanErr := command.New(
"make",
"clean",
).RunSuccess(); cleanErr != nil {
return errors.Wrapf(cleanErr, "running make clean")
return fmt.Errorf("running make clean: %w", cleanErr)
}

// Create a Kubernetes build
Expand All @@ -94,7 +94,7 @@ func (bi *Instance) Build() error {
"make",
releaseType,
).RunSuccess(); buildErr != nil {
return errors.Wrapf(buildErr, "running make %s", releaseType)
return fmt.Errorf("running make %s: %w", releaseType, buildErr)
}

// Pushing the build
Expand All @@ -106,7 +106,7 @@ func (bi *Instance) Build() error {
func (bi *Instance) checkBuildExists() (bool, error) {
version, getVersionErr := release.GetWorkspaceVersion()
if getVersionErr != nil {
return false, errors.Wrap(getVersionErr, "getting workspace version")
return false, fmt.Errorf("getting workspace version: %w", getVersionErr)
}

bi.opts.Version = version
Expand All @@ -117,17 +117,17 @@ func (bi *Instance) checkBuildExists() (bool, error) {

gcsBuildRoot, gcsBuildRootErr := bi.getGCSBuildPath(bi.opts.Version)
if gcsBuildRootErr != nil {
return false, errors.Wrap(gcsBuildRootErr, "get GCS build root")
return false, fmt.Errorf("get GCS build root: %w", gcsBuildRootErr)
}

kubernetesTar, kubernetesTarErr := bi.objStore.NormalizePath(gcsBuildRoot, release.KubernetesTar)
if kubernetesTarErr != nil {
return false, errors.Wrap(kubernetesTarErr, "get tarball path")
return false, fmt.Errorf("get tarball path: %w", kubernetesTarErr)
}

binPath, binPathErr := bi.objStore.NormalizePath(gcsBuildRoot, "bin")
if binPathErr != nil {
return false, errors.Wrap(binPathErr, "get binary path")
return false, fmt.Errorf("get binary path: %w", binPathErr)
}

gcsBuildPaths := []string{
Expand Down
11 changes: 5 additions & 6 deletions pkg/build/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/release/pkg/release"
"sigs.k8s.io/release-sdk/git"
Expand Down Expand Up @@ -75,12 +74,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 errors.Wrap(err, "open Kubernetes repository")
return fmt.Errorf("open Kubernetes repository: %w", err)
}

logrus.Infof("Checking out version %s", version)
if err := m.impl.Checkout(repo, version); err != nil {
return errors.Wrapf(err, "checking out version %s", version)
return fmt.Errorf("checking out version %s: %w", version, err)
}

// Unset the build memory requirement for parallel builds
Expand All @@ -95,13 +94,13 @@ func (m *Make) MakeCross(version string) error {
"cross-in-a-container",
fmt.Sprintf("KUBE_DOCKER_IMAGE_TAG=%s", version),
); err != nil {
return errors.Wrapf(err, "build version %s", version)
return fmt.Errorf("build version %s: %w", version, err)
}

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 errors.Wrap(err, "move build output")
return fmt.Errorf("move build output: %w", err)
}

logrus.Info("Building package tarballs")
Expand All @@ -111,7 +110,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 errors.Wrap(err, "build package tarballs")
return fmt.Errorf("build package tarballs: %w", err)
}

return nil
Expand Down
Loading

0 comments on commit 9093576

Please sign in to comment.