Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ linters:
deny:
- pkg: github.com/hashicorp/go-multierror
desc: "use errors instead"
- pkg: github.com/pkg/errors
desc: "use errors instead"
dupl:
threshold: 400
exclusions:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (
github.com/moby/term v0.5.2
github.com/opencontainers/image-spec v1.1.1
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
github.com/pkg/errors v0.9.1
github.com/rubenv/sql-migrate v1.8.0
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1
github.com/spf13/cobra v1.9.1
Expand Down Expand Up @@ -120,6 +119,7 @@ require (
github.com/onsi/gomega v1.36.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
Expand Down
17 changes: 9 additions & 8 deletions internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package resolver
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
"time"

"github.com/Masterminds/semver/v3"
"github.com/pkg/errors"

chart "helm.sh/helm/v4/pkg/chart/v2"
"helm.sh/helm/v4/pkg/chart/v2/loader"
Expand Down Expand Up @@ -60,7 +61,7 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
for i, d := range reqs {
constraint, err := semver.NewConstraint(d.Version)
if err != nil {
return nil, errors.Wrapf(err, "dependency %q has an invalid version/constraint format", d.Name)
return nil, fmt.Errorf("dependency %q has an invalid version/constraint format: %w", d.Name, err)
}

if d.Repository == "" {
Expand Down Expand Up @@ -124,12 +125,12 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
if !registry.IsOCI(d.Repository) {
repoIndex, err := repo.LoadIndexFile(filepath.Join(r.cachepath, helmpath.CacheIndexFile(repoName)))
if err != nil {
return nil, errors.Wrapf(err, "no cached repository for %s found. (try 'helm repo update')", repoName)
return nil, fmt.Errorf("no cached repository for %s found. (try 'helm repo update'): %w", repoName, err)
}

vs, ok = repoIndex.Entries[d.Name]
if !ok {
return nil, errors.Errorf("%s chart not found in repo %s", d.Name, d.Repository)
return nil, fmt.Errorf("%s chart not found in repo %s", d.Name, d.Repository)
}
found = false
} else {
Expand All @@ -151,7 +152,7 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
ref := fmt.Sprintf("%s/%s", strings.TrimPrefix(d.Repository, fmt.Sprintf("%s://", registry.OCIScheme)), d.Name)
tags, err := r.registryClient.Tags(ref)
if err != nil {
return nil, errors.Wrapf(err, "could not retrieve list of tags for repository %s", d.Repository)
return nil, fmt.Errorf("could not retrieve list of tags for repository %s: %w", d.Repository, err)
}

vs = make(repo.ChartVersions, len(tags))
Expand Down Expand Up @@ -192,7 +193,7 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
}
}
if len(missing) > 0 {
return nil, errors.Errorf("can't get a valid version for %d subchart(s): %s. Make sure a matching chart version exists in the repo, or change the version constraint in Chart.yaml", len(missing), strings.Join(missing, ", "))
return nil, fmt.Errorf("can't get a valid version for %d subchart(s): %s. Make sure a matching chart version exists in the repo, or change the version constraint in Chart.yaml", len(missing), strings.Join(missing, ", "))
}

digest, err := HashReq(reqs, locked)
Expand Down Expand Up @@ -252,8 +253,8 @@ func GetLocalPath(repo, chartpath string) (string, error) {
depPath = filepath.Join(chartpath, p)
}

if _, err = os.Stat(depPath); os.IsNotExist(err) {
return "", errors.Errorf("directory %s not found", depPath)
if _, err = os.Stat(depPath); errors.Is(err, fs.ErrNotExist) {
return "", fmt.Errorf("directory %s not found", depPath)
} else if err != nil {
return "", err
}
Expand Down
5 changes: 2 additions & 3 deletions internal/sympath/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ limitations under the License.
package sympath

import (
"fmt"
"log/slog"
"os"
"path/filepath"
"sort"

"github.com/pkg/errors"
)

// Walk walks the file tree rooted at root, calling walkFn for each file or directory
Expand Down Expand Up @@ -69,7 +68,7 @@ func symwalk(path string, info os.FileInfo, walkFn filepath.WalkFunc) error {
if IsSymlink(info) {
resolved, err := filepath.EvalSymlinks(path)
if err != nil {
return errors.Wrapf(err, "error evaluating symlink %s", path)
return fmt.Errorf("error evaluating symlink %s: %w", path, err)
}
//This log message is to highlight a symlink that is being used within a chart, symlinks can be used for nefarious reasons.
slog.Info("found symbolic link in path. Contents of linked file included and used", "path", path, "resolved", resolved)
Expand Down
7 changes: 3 additions & 4 deletions internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ package test
import (
"bytes"
"flag"
"fmt"
"os"
"path/filepath"

"github.com/pkg/errors"
)

// UpdateGolden writes out the golden files with the latest values, rather than failing the test.
Expand Down Expand Up @@ -75,11 +74,11 @@ func compare(actual []byte, filename string) error {

expected, err := os.ReadFile(filename)
if err != nil {
return errors.Wrapf(err, "unable to read testdata %s", filename)
return fmt.Errorf("unable to read testdata %s: %w", filename, err)
}
expected = normalize(expected)
if !bytes.Equal(expected, actual) {
return errors.Errorf("does not match golden file %s\n\nWANT:\n'%s'\n\nGOT:\n'%s'", filename, expected, actual)
return fmt.Errorf("does not match golden file %s\n\nWANT:\n'%s'\n\nGOT:\n'%s'", filename, expected, actual)
}
return nil
}
Expand Down
33 changes: 19 additions & 14 deletions internal/third_party/dep/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package fs

import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"runtime"
"syscall"

"github.com/pkg/errors"
)

// fs contains a copy of a few functions from dep tool code to avoid a dependency on golang/dep.
Expand All @@ -51,7 +52,7 @@ import (
func RenameWithFallback(src, dst string) error {
_, err := os.Stat(src)
if err != nil {
return errors.Wrapf(err, "cannot stat %s", src)
return fmt.Errorf("cannot stat %s: %w", src, err)
}

err = os.Rename(src, dst)
Expand All @@ -69,20 +70,24 @@ func renameByCopy(src, dst string) error {
if dir, _ := IsDir(src); dir {
cerr = CopyDir(src, dst)
if cerr != nil {
cerr = errors.Wrap(cerr, "copying directory failed")
cerr = fmt.Errorf("copying directory failed: %w", cerr)
}
} else {
cerr = copyFile(src, dst)
if cerr != nil {
cerr = errors.Wrap(cerr, "copying file failed")
cerr = fmt.Errorf("copying file failed: %w", cerr)
}
}

if cerr != nil {
return errors.Wrapf(cerr, "rename fallback failed: cannot rename %s to %s", src, dst)
return fmt.Errorf("rename fallback failed: cannot rename %s to %s: %w", src, dst, cerr)
}

if err := os.RemoveAll(src); err != nil {
return fmt.Errorf("cannot delete %s: %w", src, err)
}

return errors.Wrapf(os.RemoveAll(src), "cannot delete %s", src)
return nil
}

var (
Expand All @@ -107,20 +112,20 @@ func CopyDir(src, dst string) error {
}

_, err = os.Stat(dst)
if err != nil && !os.IsNotExist(err) {
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return err
}
if err == nil {
return errDstExist
}

if err = os.MkdirAll(dst, fi.Mode()); err != nil {
return errors.Wrapf(err, "cannot mkdir %s", dst)
return fmt.Errorf("cannot mkdir %s: %w", dst, err)
}

entries, err := os.ReadDir(src)
if err != nil {
return errors.Wrapf(err, "cannot read directory %s", dst)
return fmt.Errorf("cannot read directory %s: %w", dst, err)
}

for _, entry := range entries {
Expand All @@ -129,13 +134,13 @@ func CopyDir(src, dst string) error {

if entry.IsDir() {
if err = CopyDir(srcPath, dstPath); err != nil {
return errors.Wrap(err, "copying directory failed")
return fmt.Errorf("copying directory failed: %w", err)
}
} else {
// This will include symlinks, which is what we want when
// copying things.
if err = copyFile(srcPath, dstPath); err != nil {
return errors.Wrap(err, "copying file failed")
return fmt.Errorf("copying file failed: %w", err)
}
}
}
Expand All @@ -149,7 +154,7 @@ func CopyDir(src, dst string) error {
// of the source file. The file mode will be copied from the source.
func copyFile(src, dst string) (err error) {
if sym, err := IsSymlink(src); err != nil {
return errors.Wrap(err, "symlink check failed")
return fmt.Errorf("symlink check failed: %w", err)
} else if sym {
if err := cloneSymlink(src, dst); err != nil {
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -226,7 +231,7 @@ func IsDir(name string) (bool, error) {
return false, err
}
if !fi.IsDir() {
return false, errors.Errorf("%q is not a directory", name)
return false, fmt.Errorf("%q is not a directory", name)
}
return true, nil
}
Expand Down
5 changes: 2 additions & 3 deletions internal/third_party/dep/fs/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package fs

import (
"fmt"
"os"
"syscall"

"github.com/pkg/errors"
)

// renameFallback attempts to determine the appropriate fallback to failed rename
Expand All @@ -51,7 +50,7 @@ func renameFallback(err error, src, dst string) error {
if !ok {
return err
} else if terr.Err != syscall.EXDEV {
return errors.Wrapf(terr, "link error: cannot rename %s to %s", src, dst)
return fmt.Errorf("link error: cannot rename %s to %s: %w", src, dst, err)
}

return renameByCopy(src, dst)
Expand Down
3 changes: 1 addition & 2 deletions internal/third_party/dep/fs/rename_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package fs

import (
"errors"
"os"
"syscall"

"github.com/pkg/errors"
)

// renameFallback attempts to determine the appropriate fallback to failed rename
Expand Down
22 changes: 11 additions & 11 deletions pkg/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package action

import (
"bytes"
"errors"
"fmt"
"io"
"log/slog"
Expand All @@ -27,7 +28,6 @@ import (
"strings"
"text/template"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/discovery"
Expand Down Expand Up @@ -105,7 +105,7 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values chartutil.Valu

if ch.Metadata.KubeVersion != "" {
if !chartutil.IsCompatibleRange(ch.Metadata.KubeVersion, caps.KubeVersion.String()) {
return hs, b, "", errors.Errorf("chart requires kubeVersion: %s which is incompatible with Kubernetes %s", ch.Metadata.KubeVersion, caps.KubeVersion.String())
return hs, b, "", fmt.Errorf("chart requires kubeVersion: %s which is incompatible with Kubernetes %s", ch.Metadata.KubeVersion, caps.KubeVersion.String())
}
}

Expand Down Expand Up @@ -220,7 +220,7 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values chartutil.Valu
if pr != nil {
b, err = pr.Run(b)
if err != nil {
return hs, b, notes, errors.Wrap(err, "error while running post render on files")
return hs, b, notes, fmt.Errorf("error while running post render on files: %w", err)
}
}

Expand All @@ -241,13 +241,13 @@ func (cfg *Configuration) getCapabilities() (*chartutil.Capabilities, error) {
}
dc, err := cfg.RESTClientGetter.ToDiscoveryClient()
if err != nil {
return nil, errors.Wrap(err, "could not get Kubernetes discovery client")
return nil, fmt.Errorf("could not get Kubernetes discovery client: %w", err)
}
// force a discovery cache invalidation to always fetch the latest server version/capabilities.
dc.Invalidate()
kubeVersion, err := dc.ServerVersion()
if err != nil {
return nil, errors.Wrap(err, "could not get server version from Kubernetes")
return nil, fmt.Errorf("could not get server version from Kubernetes: %w", err)
}
// Issue #6361:
// Client-Go emits an error when an API service is registered but unimplemented.
Expand All @@ -260,7 +260,7 @@ func (cfg *Configuration) getCapabilities() (*chartutil.Capabilities, error) {
slog.Warn("the kubernetes server has an orphaned API service", slog.Any("error", err))
slog.Warn("to fix this, kubectl delete apiservice <service-name>")
} else {
return nil, errors.Wrap(err, "could not get apiVersions from Kubernetes")
return nil, fmt.Errorf("could not get apiVersions from Kubernetes: %w", err)
}
}

Expand All @@ -280,7 +280,7 @@ func (cfg *Configuration) getCapabilities() (*chartutil.Capabilities, error) {
func (cfg *Configuration) KubernetesClientSet() (kubernetes.Interface, error) {
conf, err := cfg.RESTClientGetter.ToRESTConfig()
if err != nil {
return nil, errors.Wrap(err, "unable to generate config for kubernetes client")
return nil, fmt.Errorf("unable to generate config for kubernetes client: %w", err)
}

return kubernetes.NewForConfig(conf)
Expand All @@ -296,7 +296,7 @@ func (cfg *Configuration) Now() time.Time {

func (cfg *Configuration) releaseContent(name string, version int) (*release.Release, error) {
if err := chartutil.ValidateReleaseName(name); err != nil {
return nil, errors.Errorf("releaseContent: Release name is invalid: %s", name)
return nil, fmt.Errorf("releaseContent: Release name is invalid: %s", name)
}

if version <= 0 {
Expand All @@ -310,7 +310,7 @@ func (cfg *Configuration) releaseContent(name string, version int) (*release.Rel
func GetVersionSet(client discovery.ServerResourcesInterface) (chartutil.VersionSet, error) {
groups, resources, err := client.ServerGroupsAndResources()
if err != nil && !discovery.IsGroupDiscoveryFailedError(err) {
return chartutil.DefaultVersionSet, errors.Wrap(err, "could not get apiVersions from Kubernetes")
return chartutil.DefaultVersionSet, fmt.Errorf("could not get apiVersions from Kubernetes: %w", err)
}

// FIXME: The Kubernetes test fixture for cli appears to always return nil
Expand Down Expand Up @@ -399,11 +399,11 @@ func (cfg *Configuration) Init(getter genericclioptions.RESTClientGetter, namesp
namespace,
)
if err != nil {
return errors.Wrap(err, "unable to instantiate SQL driver")
return fmt.Errorf("unable to instantiate SQL driver: %w", err)
}
store = storage.Init(d)
default:
return errors.Errorf("unknown driver %q", helmDriver)
return fmt.Errorf("unknown driver %q", helmDriver)
}

cfg.RESTClientGetter = getter
Expand Down
Loading