Skip to content

Commit

Permalink
remove direct dependency on github/pkg/errors (#4970)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cailyn committed Jan 13, 2023
1 parent 2b7eb6d commit 8ab4b8d
Show file tree
Hide file tree
Showing 38 changed files with 137 additions and 143 deletions.
8 changes: 4 additions & 4 deletions api/filters/nameref/nameref.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"fmt"
"strings"

"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/filters/fieldspec"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
Expand Down Expand Up @@ -64,7 +64,7 @@ func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
FieldSpec: f.NameFieldToUpdate,
SetValue: f.set,
}); err != nil {
return nil, errors.Wrapf(
return nil, errors.WrapPrefixf(
err, "updating name reference in '%s' field of '%s'",
f.NameFieldToUpdate.Path, f.Referrer.CurId().String())
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func (f Filter) setMapping(node *yaml.RNode) error {
}
nameNode, err := node.Pipe(yaml.FieldMatcher{Name: "name"})
if err != nil {
return errors.Wrap(err, "trying to match 'name' field")
return errors.WrapPrefixf(err, "trying to match 'name' field")
}
if nameNode == nil {
// This is a _configuration_ error; the field path
Expand Down Expand Up @@ -153,7 +153,7 @@ func (f Filter) filterMapCandidatesByNamespace(
node *yaml.RNode) ([]*resource.Resource, error) {
namespaceNode, err := node.Pipe(yaml.FieldMatcher{Name: "namespace"})
if err != nil {
return nil, errors.Wrap(err, "trying to match 'namespace' field")
return nil, errors.WrapPrefixf(err, "trying to match 'namespace' field")
}
if namespaceNode == nil {
return f.ReferralCandidates.Resources(), nil
Expand Down
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/go-errors/errors v1.4.2
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/imdario/mergo v0.3.6
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/kube-openapi v0.0.0-20220401212409-b28bf2818661
Expand All @@ -28,6 +27,7 @@ require (
github.com/kr/pretty v0.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
Expand Down
4 changes: 2 additions & 2 deletions api/internal/accumulator/loadconfigfromcrds.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"encoding/json"
"strings"

"github.com/pkg/errors"
"k8s.io/kube-openapi/pkg/validation/spec"
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -39,7 +39,7 @@ func LoadConfigFromCRDs(
}
m, err := makeNameToApiMap(content)
if err != nil {
return nil, errors.Wrapf(err, "unable to parse open API definition from '%s'", path)
return nil, errors.WrapPrefixf(err, "unable to parse open API definition from '%s'", path)
}
otherTc, err := makeConfigFromApiMap(m)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions api/internal/builtins/HelmChartInflationGenerator.go

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

4 changes: 2 additions & 2 deletions api/internal/builtins/PatchJson6902Transformer.go

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

10 changes: 5 additions & 5 deletions api/internal/builtins/SortOrderTransformer.go

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

6 changes: 3 additions & 3 deletions api/internal/git/gitrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os/exec"
"time"

"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

Expand All @@ -24,7 +24,7 @@ type gitRunner struct {
func newCmdRunner(timeout time.Duration) (*gitRunner, error) {
gitProgram, err := exec.LookPath("git")
if err != nil {
return nil, errors.Wrap(err, "no 'git' program on path")
return nil, errors.WrapPrefixf(err, "no 'git' program on path")
}
dir, err := filesys.NewTmpConfirmedDir()
if err != nil {
Expand All @@ -48,7 +48,7 @@ func (r gitRunner) run(args ...string) error {
func() error {
out, err := cmd.CombinedOutput()
if err != nil {
return errors.Wrapf(err, "failed to run '%s': %s", cmd.String(), string(out))
return errors.WrapPrefixf(err, "failed to run '%s': %s", cmd.String(), string(out))
}
return err
})
Expand Down
4 changes: 2 additions & 2 deletions api/internal/plugins/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"path/filepath"
"strings"

"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
"sigs.k8s.io/kustomize/kyaml/errors"
)

// Compiler creates Go plugin object files.
Expand Down Expand Up @@ -86,7 +86,7 @@ func (b *Compiler) Compile() error {
cmd.Dir = b.workDir
if err := cmd.Run(); err != nil {
b.report()
return errors.Wrapf(
return errors.WrapPrefixf(
err, "cannot compile %s:\nSTDERR\n%s\n",
b.srcPath(), b.stderr.String())
}
Expand Down
10 changes: 5 additions & 5 deletions api/internal/plugins/execplugin/execplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (

"github.com/google/shlex"

"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -151,17 +151,17 @@ func (p *ExecPlugin) Transform(rm resmap.ResMap) error {
func (p *ExecPlugin) invokePlugin(input []byte) ([]byte, error) {
f, err := os.CreateTemp("", tmpConfigFilePrefix)
if err != nil {
return nil, errors.Wrap(
return nil, errors.WrapPrefixf(
err, "creating tmp plugin config file")
}
_, err = f.Write(p.cfg)
if err != nil {
return nil, errors.Wrap(
return nil, errors.WrapPrefixf(
err, "writing plugin config to "+f.Name())
}
err = f.Close()
if err != nil {
return nil, errors.Wrap(
return nil, errors.WrapPrefixf(
err, "closing plugin config file "+f.Name())
}
//nolint:gosec
Expand All @@ -175,7 +175,7 @@ func (p *ExecPlugin) invokePlugin(input []byte) ([]byte, error) {
}
result, err := cmd.Output()
if err != nil {
return nil, errors.Wrapf(
return nil, errors.WrapPrefixf(
err, "failure in plugin configured via %s; %v",
f.Name(), err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions api/internal/plugins/fnplugin/fnplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"fmt"

"github.com/pkg/errors"
"sigs.k8s.io/kustomize/kyaml/errors"

"sigs.k8s.io/kustomize/api/internal/plugins/utils"
"sigs.k8s.io/kustomize/api/resmap"
Expand Down Expand Up @@ -194,7 +194,7 @@ func (p *FnPlugin) invokePlugin(input []byte) ([]byte, error) {

err = p.runFns.Execute()
if err != nil {
return nil, errors.Wrap(
return nil, errors.WrapPrefixf(
err, "couldn't execute function")
}

Expand Down
18 changes: 9 additions & 9 deletions api/internal/plugins/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"reflect"
"strings"

"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
"sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
Expand All @@ -22,6 +21,7 @@ import (
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/resid"
)
Expand Down Expand Up @@ -216,11 +216,11 @@ func (l *Loader) loadAndConfigurePlugin(
}
yaml, err := res.AsYAML()
if err != nil {
return nil, errors.Wrapf(err, "marshalling yaml from res %s", res.OrgId())
return nil, errors.WrapPrefixf(err, "marshalling yaml from res %s", res.OrgId())
}
err = c.Config(resmap.NewPluginHelpers(ldr, v, l.rf, l.pc), yaml)
if err != nil {
return nil, errors.Wrapf(
return nil, errors.WrapPrefixf(
err, "plugin %s fails configuration", res.OrgId())
}
return c, nil
Expand All @@ -246,12 +246,12 @@ func (l *Loader) loadPlugin(res *resource.Resource) (resmap.Configurable, error)
// validation check that function mounts are under the current kustomization directory
for _, mount := range spec.Container.StorageMounts {
if filepath.IsAbs(mount.Src) {
return nil, errors.New(fmt.Sprintf("plugin %s with mount path '%s' is not permitted; "+
"mount paths must be relative to the current kustomization directory", res.OrgId(), mount.Src))
return nil, errors.Errorf("plugin %s with mount path '%s' is not permitted; "+
"mount paths must be relative to the current kustomization directory", res.OrgId(), mount.Src)
}
if strings.HasPrefix(filepath.Clean(mount.Src), "../") {
return nil, errors.New(fmt.Sprintf("plugin %s with mount path '%s' is not permitted; "+
"mount paths must be under the current kustomization directory", res.OrgId(), mount.Src))
return nil, errors.Errorf("plugin %s with mount path '%s' is not permitted; "+
"mount paths must be under the current kustomization directory", res.OrgId(), mount.Src)
}
}
return fnplugin.NewFnPlugin(&l.pc.FnpLoadingOptions), nil
Expand Down Expand Up @@ -307,11 +307,11 @@ func (l *Loader) loadGoPlugin(id resid.ResId, absPath string) (resmap.Configurab
log.Printf("Attempting plugin load from '%s'", absPath)
p, err := plugin.Open(absPath)
if err != nil {
return nil, errors.Wrapf(err, "plugin %s fails to load", absPath)
return nil, errors.WrapPrefixf(err, "plugin %s fails to load", absPath)
}
symbol, err := p.Lookup(konfig.PluginSymbol)
if err != nil {
return nil, errors.Wrapf(
return nil, errors.WrapPrefixf(
err, "plugin %s doesn't have symbol %s",
regId, konfig.PluginSymbol)
}
Expand Down
10 changes: 3 additions & 7 deletions api/internal/target/errmissingkustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"
"strings"

"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/kyaml/errors"
)

type errMissingKustomization struct {
Expand All @@ -23,12 +23,8 @@ func (e *errMissingKustomization) Error() string {
}

func IsMissingKustomizationFileError(err error) bool {
_, ok := err.(*errMissingKustomization)
if ok {
return true
}
_, ok = errors.Cause(err).(*errMissingKustomization)
return ok
e := &errMissingKustomization{}
return errors.As(err, &e)
}

func NewErrMissingKustomization(p string) *errMissingKustomization {
Expand Down

0 comments on commit 8ab4b8d

Please sign in to comment.