replace as many github error deps as possible from pkg/

Signed-off-by: James Sheppard <jgsheppa@protonmail.com>
pull/12063/head
James Sheppard 2 years ago
parent 49cb4c41bd
commit dae0017d2b

@ -18,13 +18,14 @@ package loader
import (
"bytes"
"errors"
"fmt"
"log"
"os"
"path/filepath"
"strings"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
"sigs.k8s.io/yaml"
"helm.sh/helm/v3/pkg/chart"
@ -83,7 +84,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
c.Metadata = new(chart.Metadata)
}
if err := yaml.Unmarshal(f.Data, c.Metadata); err != nil {
return c, errors.Wrap(err, "cannot load Chart.yaml")
return c, githubErrors.Wrap(err, "cannot load Chart.yaml")
}
// NOTE(bacongobbler): while the chart specification says that APIVersion must be set,
// Helm 2 accepted charts that did not provide an APIVersion in their chart metadata.
@ -101,12 +102,12 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
case f.Name == "Chart.lock":
c.Lock = new(chart.Lock)
if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil {
return c, errors.Wrap(err, "cannot load Chart.lock")
return c, githubErrors.Wrap(err, "cannot load Chart.lock")
}
case f.Name == "values.yaml":
c.Values = make(map[string]interface{})
if err := yaml.Unmarshal(f.Data, &c.Values); err != nil {
return c, errors.Wrap(err, "cannot load values.yaml")
return c, githubErrors.Wrap(err, "cannot load values.yaml")
}
case f.Name == "values.schema.json":
c.Schema = f.Data
@ -121,7 +122,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
log.Printf("Warning: Dependencies are handled in Chart.yaml since apiVersion \"v2\". We recommend migrating dependencies to Chart.yaml.")
}
if err := yaml.Unmarshal(f.Data, c.Metadata); err != nil {
return c, errors.Wrap(err, "cannot load requirements.yaml")
return c, githubErrors.Wrap(err, "cannot load requirements.yaml")
}
if c.Metadata.APIVersion == chart.APIVersionV1 {
c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data})
@ -130,7 +131,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
case f.Name == "requirements.lock":
c.Lock = new(chart.Lock)
if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil {
return c, errors.Wrap(err, "cannot load requirements.lock")
return c, githubErrors.Wrap(err, "cannot load requirements.lock")
}
if c.Metadata == nil {
c.Metadata = new(chart.Metadata)
@ -192,7 +193,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
}
if err != nil {
return c, errors.Wrapf(err, "error unpacking %s in %s", n, c.Name())
return c, githubErrors.Wrapf(err, "error unpacking %s in %s", n, c.Name())
}
c.AddDependency(sc)
}

@ -17,12 +17,13 @@ limitations under the License.
package chartutil
import (
"errors"
"io"
"os"
"path/filepath"
securejoin "github.com/cyphar/filepath-securejoin"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
"sigs.k8s.io/yaml"
"helm.sh/helm/v3/pkg/chart"
@ -42,7 +43,7 @@ func Expand(dir string, r io.Reader) error {
if file.Name == "Chart.yaml" {
ch := &chart.Metadata{}
if err := yaml.Unmarshal(file.Data, ch); err != nil {
return errors.Wrap(err, "cannot load Chart.yaml")
return githubErrors.Wrap(err, "cannot load Chart.yaml")
}
chartName = ch.Name
}

@ -20,12 +20,13 @@ import (
"archive/tar"
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"time"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
"sigs.k8s.io/yaml"
"helm.sh/helm/v3/pkg/chart"
@ -85,7 +86,7 @@ func SaveDir(c *chart.Chart, dest string) error {
for _, dep := range c.Dependencies() {
// Here, we write each dependency as a tar file.
if _, err := Save(dep, base); err != nil {
return errors.Wrapf(err, "saving %s", dep.ChartFullPath())
return githubErrors.Wrapf(err, "saving %s", dep.ChartFullPath())
}
}
return nil
@ -101,7 +102,7 @@ func SaveDir(c *chart.Chart, dest string) error {
// This returns the absolute path to the chart archive file.
func Save(c *chart.Chart, outDir string) (string, error) {
if err := c.Validate(); err != nil {
return "", errors.Wrap(err, "chart validation")
return "", githubErrors.Wrap(err, "chart validation")
}
filename := fmt.Sprintf("%s-%s.tgz", c.Name(), c.Metadata.Version)
@ -113,7 +114,7 @@ func Save(c *chart.Chart, outDir string) (string, error) {
return "", err2
}
} else {
return "", errors.Wrapf(err, "stat %s", dir)
return "", githubErrors.Wrapf(err, "stat %s", dir)
}
} else if !stat.IsDir() {
return "", fmt.Errorf("is not a directory: %s", dir)

@ -25,8 +25,9 @@ import (
"sort"
"strings"
"text/template"
"errors"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
"k8s.io/client-go/rest"
"helm.sh/helm/v3/pkg/chart"
@ -122,7 +123,7 @@ func (e Engine) initFunMap(t *template.Template, referenceTpls map[string]render
var buf strings.Builder
if v, ok := includedNames[name]; ok {
if v > recursionMaxNums {
return "", errors.Wrapf(fmt.Errorf("unable to execute template"), "rendering template has a nested reference name: %s", name)
return "", githubErrors.Wrapf(fmt.Errorf("unable to execute template"), "rendering template has a nested reference name: %s", name)
}
includedNames[name]++
} else {
@ -137,12 +138,12 @@ func (e Engine) initFunMap(t *template.Template, referenceTpls map[string]render
funcMap["tpl"] = func(tpl string, vals chartutil.Values) (string, error) {
basePath, err := vals.PathValue("Template.BasePath")
if err != nil {
return "", errors.Wrapf(err, "cannot retrieve Template.Basepath from values inside tpl function: %s", tpl)
return "", githubErrors.Wrapf(err, "cannot retrieve Template.Basepath from values inside tpl function: %s", tpl)
}
templateName, err := vals.PathValue("Template.Name")
if err != nil {
return "", errors.Wrapf(err, "cannot retrieve Template.Name from values inside tpl function: %s", tpl)
return "", githubErrors.Wrapf(err, "cannot retrieve Template.Name from values inside tpl function: %s", tpl)
}
templates := map[string]renderable{
@ -155,7 +156,7 @@ func (e Engine) initFunMap(t *template.Template, referenceTpls map[string]render
result, err := e.renderWithReferences(templates, referenceTpls)
if err != nil {
return "", errors.Wrapf(err, "error during tpl function execution for %q", tpl)
return "", githubErrors.Wrapf(err, "error during tpl function execution for %q", tpl)
}
return result[templateName.(string)], nil
}

@ -28,9 +28,10 @@ import (
"strings"
"sync"
"time"
"errors"
jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
batch "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@ -121,10 +122,10 @@ func (c *Client) IsReachable() error {
return errors.New("Kubernetes cluster unreachable")
}
if err != nil {
return errors.Wrap(err, "Kubernetes cluster unreachable")
return githubErrors.Wrap(err, "Kubernetes cluster unreachable")
}
if _, err := client.ServerVersion(); err != nil {
return errors.Wrap(err, "Kubernetes cluster unreachable")
return githubErrors.Wrap(err, "Kubernetes cluster unreachable")
}
return nil
}
@ -391,7 +392,7 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
helper := resource.NewHelper(info.Client, info.Mapping).WithFieldManager(getManagedFieldsManager())
if _, err := helper.Get(info.Namespace, info.Name); err != nil {
if !apierrors.IsNotFound(err) {
return errors.Wrap(err, "could not get information about the resource")
return githubErrors.Wrap(err, "could not get information about the resource")
}
// Append the created resource to the results, even if something fails
@ -399,7 +400,7 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
// Since the resource does not exist, create it.
if err := createResource(info); err != nil {
return errors.Wrap(err, "failed to create resource")
return githubErrors.Wrap(err, "failed to create resource")
}
kind := info.Mapping.GroupVersionKind.Kind
@ -606,24 +607,24 @@ func deleteResource(info *resource.Info, policy metav1.DeletionPropagation) erro
func createPatch(target *resource.Info, current runtime.Object) ([]byte, types.PatchType, error) {
oldData, err := json.Marshal(current)
if err != nil {
return nil, types.StrategicMergePatchType, errors.Wrap(err, "serializing current configuration")
return nil, types.StrategicMergePatchType, githubErrors.Wrap(err, "serializing current configuration")
}
newData, err := json.Marshal(target.Object)
if err != nil {
return nil, types.StrategicMergePatchType, errors.Wrap(err, "serializing target configuration")
return nil, types.StrategicMergePatchType, githubErrors.Wrap(err, "serializing target configuration")
}
// Fetch the current object for the three way merge
helper := resource.NewHelper(target.Client, target.Mapping).WithFieldManager(getManagedFieldsManager())
currentObj, err := helper.Get(target.Namespace, target.Name)
if err != nil && !apierrors.IsNotFound(err) {
return nil, types.StrategicMergePatchType, errors.Wrapf(err, "unable to get data for current object %s/%s", target.Namespace, target.Name)
return nil, types.StrategicMergePatchType, githubErrors.Wrapf(err, "unable to get data for current object %s/%s", target.Namespace, target.Name)
}
// Even if currentObj is nil (because it was not found), it will marshal just fine
currentData, err := json.Marshal(currentObj)
if err != nil {
return nil, types.StrategicMergePatchType, errors.Wrap(err, "serializing live configuration")
return nil, types.StrategicMergePatchType, githubErrors.Wrap(err, "serializing live configuration")
}
// Get a versioned object
@ -646,7 +647,7 @@ func createPatch(target *resource.Info, current runtime.Object) ([]byte, types.P
patchMeta, err := strategicpatch.NewPatchMetaFromStruct(versionedObject)
if err != nil {
return nil, types.StrategicMergePatchType, errors.Wrap(err, "unable to create patch metadata from object")
return nil, types.StrategicMergePatchType, githubErrors.Wrap(err, "unable to create patch metadata from object")
}
patch, err := strategicpatch.CreateThreeWayMergePatch(oldData, newData, currentData, patchMeta, true)
@ -665,13 +666,13 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
var err error
obj, err = helper.Replace(target.Namespace, target.Name, true, target.Object)
if err != nil {
return errors.Wrap(err, "failed to replace object")
return githubErrors.Wrap(err, "failed to replace object")
}
c.Log("Replaced %q with kind %s for kind %s", target.Name, currentObj.GetObjectKind().GroupVersionKind().Kind, kind)
} else {
patch, patchType, err := createPatch(target, currentObj)
if err != nil {
return errors.Wrap(err, "failed to create patch")
return githubErrors.Wrap(err, "failed to create patch")
}
if patch == nil || string(patch) == "{}" {
@ -679,7 +680,7 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
// This needs to happen to make sure that Helm has the latest info from the API
// Otherwise there will be no labels and other functions that use labels will panic
if err := target.Get(); err != nil {
return errors.Wrap(err, "failed to refresh resource information")
return githubErrors.Wrap(err, "failed to refresh resource information")
}
return nil
}
@ -687,7 +688,7 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
c.Log("Patch %s %q in namespace %s", kind, target.Name, target.Namespace)
obj, err = helper.Patch(target.Namespace, target.Name, patchType, patch, nil)
if err != nil {
return errors.Wrapf(err, "cannot patch %q with kind %s", target.Name, kind)
return githubErrors.Wrapf(err, "cannot patch %q with kind %s", target.Name, kind)
}
}

@ -26,8 +26,9 @@ import (
"path/filepath"
"regexp"
"strings"
"errors"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/validation"
apipath "k8s.io/apimachinery/pkg/api/validation/path"
"k8s.io/apimachinery/pkg/util/validation/field"
@ -209,7 +210,7 @@ func validateAllowedExtension(fileName string) error {
}
func validateYamlContent(err error) error {
return errors.Wrap(err, "unable to parse YAML")
return githubErrors.Wrap(err, "unable to parse YAML")
}
// validateMetadataName uses the correct validation function for the object
@ -222,7 +223,7 @@ func validateMetadataName(obj *K8sYamlStruct) error {
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), obj.Metadata.Name, msg))
}
if len(allErrs) > 0 {
return errors.Wrapf(allErrs.ToAggregate(), "object name does not conform to Kubernetes naming requirements: %q", obj.Metadata.Name)
return githubErrors.Wrapf(allErrs.ToAggregate(), "object name does not conform to Kubernetes naming requirements: %q", obj.Metadata.Name)
}
return nil
}

@ -19,13 +19,14 @@ import (
"bytes"
"crypto"
"encoding/hex"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
"golang.org/x/crypto/openpgp" //nolint
"golang.org/x/crypto/openpgp/clearsign" //nolint
"golang.org/x/crypto/openpgp/packet" //nolint
@ -237,12 +238,12 @@ func (s *Signatory) ClearSign(chartpath string) (string, error) {
// In other words, if we call Close here, there's a risk that there's an attempt to use the
// private key to sign garbage data (since we know that io.Copy failed, `w` won't contain
// anything useful).
return "", errors.Wrap(err, "failed to write to clearsign encoder")
return "", githubErrors.Wrap(err, "failed to write to clearsign encoder")
}
err = w.Close()
if err != nil {
return "", errors.Wrap(err, "failed to either sign or armor message block")
return "", githubErrors.Wrap(err, "failed to either sign or armor message block")
}
return out.String(), nil
@ -262,7 +263,7 @@ func (s *Signatory) Verify(chartpath, sigpath string) (*Verification, error) {
// First verify the signature
sig, err := s.decodeSignature(sigpath)
if err != nil {
return ver, errors.Wrap(err, "failed to decode signature")
return ver, githubErrors.Wrap(err, "failed to decode signature")
}
by, err := s.verifySignature(sig)

@ -23,8 +23,9 @@ import (
"path"
"strings"
"time"
"errors"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
"helm.sh/helm/v3/internal/tlsutil"
"helm.sh/helm/v3/pkg/chart/loader"
@ -108,7 +109,7 @@ func (pusher *OCIPusher) newRegistryClient() (*registry.Client, error) {
if (pusher.opts.certFile != "" && pusher.opts.keyFile != "") || pusher.opts.caFile != "" || pusher.opts.insecureSkipTLSverify {
tlsConf, err := tlsutil.NewClientTLS(pusher.opts.certFile, pusher.opts.keyFile, pusher.opts.caFile, pusher.opts.insecureSkipTLSverify)
if err != nil {
return nil, errors.Wrap(err, "can't create TLS config for client")
return nil, githubErrors.Wrap(err, "can't create TLS config for client")
}
registryClient, err := registry.NewClient(

@ -26,7 +26,6 @@ import (
"github.com/Masterminds/semver/v3"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
orascontext "oras.land/oras-go/pkg/context"
"oras.land/oras-go/pkg/registry"
@ -90,7 +89,7 @@ func GetTagMatchingVersionOrConstraint(tags []string, versionString string) (str
}
}
return "", errors.Errorf("Could not locate a version matching provided version string %s", versionString)
return "", fmt.Errorf("Could not locate a version matching provided version string %s", versionString)
}
// extractChartMeta is used to extract a chart metadata from a byte array

@ -26,9 +26,10 @@ import (
"sort"
"strings"
"time"
"errors"
"github.com/Masterminds/semver/v3"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
"sigs.k8s.io/yaml"
"helm.sh/helm/v3/internal/fileutil"
@ -110,7 +111,7 @@ func LoadIndexFile(path string) (*IndexFile, error) {
}
i, err := loadIndex(b, path)
if err != nil {
return nil, errors.Wrapf(err, "error loading %s", path)
return nil, githubErrors.Wrapf(err, "error loading %s", path)
}
return i, nil
}
@ -126,7 +127,7 @@ func (i IndexFile) MustAdd(md *chart.Metadata, filename, baseURL, digest string)
md.APIVersion = chart.APIVersionV1
}
if err := md.Validate(); err != nil {
return errors.Wrapf(err, "validate failed for %s", filename)
return githubErrors.Wrapf(err, "validate failed for %s", filename)
}
u := filename
@ -320,7 +321,7 @@ func IndexDirectory(dir, baseURL string) (*IndexFile, error) {
return index, err
}
if err := index.MustAdd(c.Metadata, fname, parentURL, hash); err != nil {
return index, errors.Wrapf(err, "failed adding to %s to index", fname)
return index, githubErrors.Wrapf(err, "failed adding to %s to index", fname)
}
}
return index, nil

@ -17,11 +17,10 @@ limitations under the License.
package storage // import "helm.sh/helm/v3/pkg/storage"
import (
"errors"
"fmt"
"strings"
"github.com/pkg/errors"
rspb "helm.sh/helm/v3/pkg/release"
relutil "helm.sh/helm/v3/pkg/releaseutil"
"helm.sh/helm/v3/pkg/storage/driver"
@ -213,7 +212,7 @@ func (s *Storage) removeLeastRecent(name string, max int) error {
case 1:
return errs[0]
default:
return errors.Errorf("encountered %d deletion errors. First is: %s", c, errs[0])
return fmt.Errorf("encountered %d deletion errors. First is: %s", c, errs[0])
}
}
@ -235,7 +234,7 @@ func (s *Storage) Last(name string) (*rspb.Release, error) {
return nil, err
}
if len(h) == 0 {
return nil, errors.Errorf("no revision for release %q", name)
return nil, fmt.Errorf("no revision for release %q", name)
}
relutil.Reverse(h, relutil.SortByRevision)

@ -18,13 +18,14 @@ package strvals
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"strconv"
"strings"
"unicode"
"github.com/pkg/errors"
githubErrors "github.com/pkg/errors"
"sigs.k8s.io/yaml"
)
@ -196,7 +197,7 @@ func (t *parser) key(data map[string]interface{}, nestedNameLevel int) (reterr e
// We are in a list index context, so we need to set an index.
i, err := t.keyIndex()
if err != nil {
return errors.Wrap(err, "error parsing index")
return githubErrors.Wrap(err, "error parsing index")
}
kk := string(k)
// Find or create target list
@ -394,7 +395,7 @@ func (t *parser) listItem(list []interface{}, i, nestedNameLevel int) ([]interfa
// now we have a nested list. Read the index and handle.
nextI, err := t.keyIndex()
if err != nil {
return list, errors.Wrap(err, "error parsing index")
return list, githubErrors.Wrap(err, "error parsing index")
}
var crtList []interface{}
if len(list) > i {

Loading…
Cancel
Save