diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 58391032..f1b9bd7a 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -21,4 +21,4 @@ jobs: go-version-file: 'go.mod' - uses: golangci/golangci-lint-action@v3 with: - version: v1.51.0 + version: v1.55.1 diff --git a/.golangci.yaml b/.golangci.yaml index ed5ebd34..a6b9400f 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -138,14 +138,44 @@ linters-settings: min-len: 3 # minimal occurrences count to trigger, 3 by default min-occurrences: 8 - # depguard: - # list-type: blacklist - # include-go-root: false - # packages: - # - github.com/sirupsen/logrus - # packages-with-error-messages: - # # specify an error message to output when a blacklisted package is used - # github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" + depguard: + # Rules to apply. + # Default: Only allow $gostd in all files. + rules: + # Name of a rule. + main: + # List of file globs that will match this list of settings to compare against. + # Default: $all + files: + - $all + # List of allowed packages. + allow: + - $gostd + - github.com/Masterminds/semver + - github.com/aryann/difflib + - github.com/databus23/helm-diff/v3 + - github.com/evanphx/json-patch + - github.com/gonvenience/ytbx + - github.com/google/go-cmp/cmp + - github.com/homeport/dyff/pkg/dyff + - github.com/json-iterator/go + - github.com/mgutz/ansi + - github.com/spf13/cobra + - github.com/spf13/pflag + - github.com/stretchr/testify/require + - helm.sh/helm/v3 + - k8s.io/api/core/v1 + - k8s.io/apiextensions-apiserver + - k8s.io/apimachinery + - k8s.io/cli-runtime + - k8s.io/client-go + - sigs.k8s.io/yaml + # Packages that are not allowed where the value is a suggestion. + deny: + - pkg: "github.com/sirupsen/logrus" + desc: not allowed + - pkg: "github.com/pkg/errors" + desc: Should be replaced by standard lib errors package misspell: # Correct spellings using locale preferences for US or UK. # Default is to use a neutral variety of English. @@ -357,4 +387,4 @@ issues: # new-from-rev: REV # Show only new issues created in git patch with set file path. - # new-from-patch: path/to/patch/file \ No newline at end of file + # new-from-patch: path/to/patch/file diff --git a/cmd/upgrade.go b/cmd/upgrade.go index da7b5ac6..082d2a30 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -3,6 +3,7 @@ package cmd import ( "bytes" "encoding/json" + "errors" "fmt" "log" "os" @@ -11,7 +12,6 @@ import ( jsonpatch "github.com/evanphx/json-patch" jsoniterator "github.com/json-iterator/go" - "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" "helm.sh/helm/v3/pkg/action" @@ -347,15 +347,15 @@ func (d *diffCmd) runHelm3() error { } original, err := actionConfig.KubeClient.Build(bytes.NewBuffer(releaseManifest), false) if err != nil { - return errors.Wrap(err, "unable to build kubernetes objects from original release manifest") + return fmt.Errorf("unable to build kubernetes objects from original release manifest: %w", err) } target, err := actionConfig.KubeClient.Build(bytes.NewBuffer(installManifest), false) if err != nil { - return errors.Wrap(err, "unable to build kubernetes objects from new release manifest") + return fmt.Errorf("unable to build kubernetes objects from new release manifest: %w", err) } releaseManifest, installManifest, err = genManifest(original, target) if err != nil { - return errors.Wrap(err, "unable to generate manifests") + return fmt.Errorf("unable to generate manifests: %w", err) } } @@ -423,7 +423,7 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) { toBeUpdated, err := existingResourceConflict(toBeCreated) if err != nil { - return nil, nil, errors.Wrap(err, "rendered manifests contain a resource that already exists. Unable to continue with update") + return nil, nil, fmt.Errorf("rendered manifests contain a resource that already exists. Unable to continue with update: %w", err) } _ = toBeUpdated.Visit(func(r *resource.Info, err error) error { @@ -445,7 +445,7 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) { currentObj, err := helper.Get(info.Namespace, info.Name) if err != nil { if !apierrors.IsNotFound(err) { - return errors.Wrap(err, "could not get information about the resource") + return fmt.Errorf("could not get information about the resource: %w", err) } // to be created out, _ := yaml.Marshal(info.Object) @@ -457,11 +457,11 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) { out, _ := jsoniterator.ConfigCompatibleWithStandardLibrary.Marshal(currentObj) pruneObj, err := deleteStatusAndTidyMetadata(out) if err != nil { - return errors.Wrapf(err, "prune current obj %q with kind %s", info.Name, kind) + return fmt.Errorf("prune current obj %q with kind %s: %w", info.Name, kind, err) } pruneOut, err := yaml.Marshal(pruneObj) if err != nil { - return errors.Wrapf(err, "prune current out %q with kind %s", info.Name, kind) + return fmt.Errorf("prune current out %q with kind %s: %w", info.Name, kind, err) } releaseManifest = append(releaseManifest, yamlSeperator...) releaseManifest = append(releaseManifest, pruneOut...) @@ -479,16 +479,16 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) { helper.ServerDryRun = true targetObj, err := helper.Patch(info.Namespace, info.Name, patchType, patch, nil) if err != nil { - return errors.Wrapf(err, "cannot patch %q with kind %s", info.Name, kind) + return fmt.Errorf("cannot patch %q with kind %s: %w", info.Name, kind, err) } out, _ = jsoniterator.ConfigCompatibleWithStandardLibrary.Marshal(targetObj) pruneObj, err = deleteStatusAndTidyMetadata(out) if err != nil { - return errors.Wrapf(err, "prune current obj %q with kind %s", info.Name, kind) + return fmt.Errorf("prune current obj %q with kind %s: %w", info.Name, kind, err) } pruneOut, err = yaml.Marshal(pruneObj) if err != nil { - return errors.Wrapf(err, "prune current out %q with kind %s", info.Name, kind) + return fmt.Errorf("prune current out %q with kind %s: %w", info.Name, kind, err) } installManifest = append(installManifest, yamlSeperator...) installManifest = append(installManifest, pruneOut...) @@ -501,17 +501,17 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) { func createPatch(originalObj, currentObj runtime.Object, target *resource.Info) ([]byte, types.PatchType, error) { oldData, err := json.Marshal(originalObj) if err != nil { - return nil, types.StrategicMergePatchType, errors.Wrap(err, "serializing current configuration") + return nil, types.StrategicMergePatchType, fmt.Errorf("serializing current configuration: %w", err) } newData, err := json.Marshal(target.Object) if err != nil { - return nil, types.StrategicMergePatchType, errors.Wrap(err, "serializing target configuration") + return nil, types.StrategicMergePatchType, fmt.Errorf("serializing target configuration: %w", err) } // 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, fmt.Errorf("serializing live configuration: %w", err) } // kind := target.Mapping.GroupVersionKind.Kind // if kind == "Deployment" { @@ -539,7 +539,7 @@ func createPatch(originalObj, currentObj runtime.Object, target *resource.Info) 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, fmt.Errorf("unable to create patch metadata from object: %w", err) } patch, err := strategicpatch.CreateThreeWayMergePatch(oldData, newData, currentData, patchMeta, true) @@ -565,7 +565,7 @@ func existingResourceConflict(resources kube.ResourceList) (kube.ResourceList, e if apierrors.IsNotFound(err) { return nil } - return errors.Wrap(err, "could not get information about the resource") + return fmt.Errorf("could not get information about the resource: %w", err) } requireUpdate.Append(info) @@ -579,7 +579,7 @@ func deleteStatusAndTidyMetadata(obj []byte) (map[string]interface{}, error) { var objectMap map[string]interface{} err := jsoniterator.Unmarshal(obj, &objectMap) if err != nil { - return nil, errors.Wrap(err, "could not unmarshal byte sequence") + return nil, fmt.Errorf("could not unmarshal byte sequence: %w", err) } delete(objectMap, "status")