Skip to content

Commit b411963

Browse files
authored
Merge pull request #507 from mjtrangoni/fix-depguard
lint: Update depguard configuration
2 parents 38b0206 + 49c62fc commit b411963

File tree

3 files changed

+57
-27
lines changed

3 files changed

+57
-27
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
go-version-file: 'go.mod'
2222
- uses: golangci/golangci-lint-action@v3
2323
with:
24-
version: v1.51.0
24+
version: v1.55.1

.golangci.yaml

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,44 @@ linters-settings:
138138
min-len: 3
139139
# minimal occurrences count to trigger, 3 by default
140140
min-occurrences: 8
141-
# depguard:
142-
# list-type: blacklist
143-
# include-go-root: false
144-
# packages:
145-
# - github.com/sirupsen/logrus
146-
# packages-with-error-messages:
147-
# # specify an error message to output when a blacklisted package is used
148-
# github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
141+
depguard:
142+
# Rules to apply.
143+
# Default: Only allow $gostd in all files.
144+
rules:
145+
# Name of a rule.
146+
main:
147+
# List of file globs that will match this list of settings to compare against.
148+
# Default: $all
149+
files:
150+
- $all
151+
# List of allowed packages.
152+
allow:
153+
- $gostd
154+
- github.com/Masterminds/semver
155+
- github.com/aryann/difflib
156+
- github.com/databus23/helm-diff/v3
157+
- github.com/evanphx/json-patch
158+
- github.com/gonvenience/ytbx
159+
- github.com/google/go-cmp/cmp
160+
- github.com/homeport/dyff/pkg/dyff
161+
- github.com/json-iterator/go
162+
- github.com/mgutz/ansi
163+
- github.com/spf13/cobra
164+
- github.com/spf13/pflag
165+
- github.com/stretchr/testify/require
166+
- helm.sh/helm/v3
167+
- k8s.io/api/core/v1
168+
- k8s.io/apiextensions-apiserver
169+
- k8s.io/apimachinery
170+
- k8s.io/cli-runtime
171+
- k8s.io/client-go
172+
- sigs.k8s.io/yaml
173+
# Packages that are not allowed where the value is a suggestion.
174+
deny:
175+
- pkg: "github.com/sirupsen/logrus"
176+
desc: not allowed
177+
- pkg: "github.com/pkg/errors"
178+
desc: Should be replaced by standard lib errors package
149179
misspell:
150180
# Correct spellings using locale preferences for US or UK.
151181
# Default is to use a neutral variety of English.
@@ -357,4 +387,4 @@ issues:
357387
# new-from-rev: REV
358388

359389
# Show only new issues created in git patch with set file path.
360-
# new-from-patch: path/to/patch/file
390+
# new-from-patch: path/to/patch/file

cmd/upgrade.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"bytes"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"log"
89
"os"
@@ -11,7 +12,6 @@ import (
1112

1213
jsonpatch "github.com/evanphx/json-patch"
1314
jsoniterator "github.com/json-iterator/go"
14-
"github.com/pkg/errors"
1515
"github.com/spf13/cobra"
1616
"github.com/spf13/pflag"
1717
"helm.sh/helm/v3/pkg/action"
@@ -347,15 +347,15 @@ func (d *diffCmd) runHelm3() error {
347347
}
348348
original, err := actionConfig.KubeClient.Build(bytes.NewBuffer(releaseManifest), false)
349349
if err != nil {
350-
return errors.Wrap(err, "unable to build kubernetes objects from original release manifest")
350+
return fmt.Errorf("unable to build kubernetes objects from original release manifest: %w", err)
351351
}
352352
target, err := actionConfig.KubeClient.Build(bytes.NewBuffer(installManifest), false)
353353
if err != nil {
354-
return errors.Wrap(err, "unable to build kubernetes objects from new release manifest")
354+
return fmt.Errorf("unable to build kubernetes objects from new release manifest: %w", err)
355355
}
356356
releaseManifest, installManifest, err = genManifest(original, target)
357357
if err != nil {
358-
return errors.Wrap(err, "unable to generate manifests")
358+
return fmt.Errorf("unable to generate manifests: %w", err)
359359
}
360360
}
361361

@@ -423,7 +423,7 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
423423

424424
toBeUpdated, err := existingResourceConflict(toBeCreated)
425425
if err != nil {
426-
return nil, nil, errors.Wrap(err, "rendered manifests contain a resource that already exists. Unable to continue with update")
426+
return nil, nil, fmt.Errorf("rendered manifests contain a resource that already exists. Unable to continue with update: %w", err)
427427
}
428428

429429
_ = toBeUpdated.Visit(func(r *resource.Info, err error) error {
@@ -445,7 +445,7 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
445445
currentObj, err := helper.Get(info.Namespace, info.Name)
446446
if err != nil {
447447
if !apierrors.IsNotFound(err) {
448-
return errors.Wrap(err, "could not get information about the resource")
448+
return fmt.Errorf("could not get information about the resource: %w", err)
449449
}
450450
// to be created
451451
out, _ := yaml.Marshal(info.Object)
@@ -457,11 +457,11 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
457457
out, _ := jsoniterator.ConfigCompatibleWithStandardLibrary.Marshal(currentObj)
458458
pruneObj, err := deleteStatusAndTidyMetadata(out)
459459
if err != nil {
460-
return errors.Wrapf(err, "prune current obj %q with kind %s", info.Name, kind)
460+
return fmt.Errorf("prune current obj %q with kind %s: %w", info.Name, kind, err)
461461
}
462462
pruneOut, err := yaml.Marshal(pruneObj)
463463
if err != nil {
464-
return errors.Wrapf(err, "prune current out %q with kind %s", info.Name, kind)
464+
return fmt.Errorf("prune current out %q with kind %s: %w", info.Name, kind, err)
465465
}
466466
releaseManifest = append(releaseManifest, yamlSeperator...)
467467
releaseManifest = append(releaseManifest, pruneOut...)
@@ -479,16 +479,16 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
479479
helper.ServerDryRun = true
480480
targetObj, err := helper.Patch(info.Namespace, info.Name, patchType, patch, nil)
481481
if err != nil {
482-
return errors.Wrapf(err, "cannot patch %q with kind %s", info.Name, kind)
482+
return fmt.Errorf("cannot patch %q with kind %s: %w", info.Name, kind, err)
483483
}
484484
out, _ = jsoniterator.ConfigCompatibleWithStandardLibrary.Marshal(targetObj)
485485
pruneObj, err = deleteStatusAndTidyMetadata(out)
486486
if err != nil {
487-
return errors.Wrapf(err, "prune current obj %q with kind %s", info.Name, kind)
487+
return fmt.Errorf("prune current obj %q with kind %s: %w", info.Name, kind, err)
488488
}
489489
pruneOut, err = yaml.Marshal(pruneObj)
490490
if err != nil {
491-
return errors.Wrapf(err, "prune current out %q with kind %s", info.Name, kind)
491+
return fmt.Errorf("prune current out %q with kind %s: %w", info.Name, kind, err)
492492
}
493493
installManifest = append(installManifest, yamlSeperator...)
494494
installManifest = append(installManifest, pruneOut...)
@@ -501,17 +501,17 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
501501
func createPatch(originalObj, currentObj runtime.Object, target *resource.Info) ([]byte, types.PatchType, error) {
502502
oldData, err := json.Marshal(originalObj)
503503
if err != nil {
504-
return nil, types.StrategicMergePatchType, errors.Wrap(err, "serializing current configuration")
504+
return nil, types.StrategicMergePatchType, fmt.Errorf("serializing current configuration: %w", err)
505505
}
506506
newData, err := json.Marshal(target.Object)
507507
if err != nil {
508-
return nil, types.StrategicMergePatchType, errors.Wrap(err, "serializing target configuration")
508+
return nil, types.StrategicMergePatchType, fmt.Errorf("serializing target configuration: %w", err)
509509
}
510510

511511
// Even if currentObj is nil (because it was not found), it will marshal just fine
512512
currentData, err := json.Marshal(currentObj)
513513
if err != nil {
514-
return nil, types.StrategicMergePatchType, errors.Wrap(err, "serializing live configuration")
514+
return nil, types.StrategicMergePatchType, fmt.Errorf("serializing live configuration: %w", err)
515515
}
516516
// kind := target.Mapping.GroupVersionKind.Kind
517517
// if kind == "Deployment" {
@@ -539,7 +539,7 @@ func createPatch(originalObj, currentObj runtime.Object, target *resource.Info)
539539

540540
patchMeta, err := strategicpatch.NewPatchMetaFromStruct(versionedObject)
541541
if err != nil {
542-
return nil, types.StrategicMergePatchType, errors.Wrap(err, "unable to create patch metadata from object")
542+
return nil, types.StrategicMergePatchType, fmt.Errorf("unable to create patch metadata from object: %w", err)
543543
}
544544

545545
patch, err := strategicpatch.CreateThreeWayMergePatch(oldData, newData, currentData, patchMeta, true)
@@ -565,7 +565,7 @@ func existingResourceConflict(resources kube.ResourceList) (kube.ResourceList, e
565565
if apierrors.IsNotFound(err) {
566566
return nil
567567
}
568-
return errors.Wrap(err, "could not get information about the resource")
568+
return fmt.Errorf("could not get information about the resource: %w", err)
569569
}
570570

571571
requireUpdate.Append(info)
@@ -579,7 +579,7 @@ func deleteStatusAndTidyMetadata(obj []byte) (map[string]interface{}, error) {
579579
var objectMap map[string]interface{}
580580
err := jsoniterator.Unmarshal(obj, &objectMap)
581581
if err != nil {
582-
return nil, errors.Wrap(err, "could not unmarshal byte sequence")
582+
return nil, fmt.Errorf("could not unmarshal byte sequence: %w", err)
583583
}
584584

585585
delete(objectMap, "status")

0 commit comments

Comments
 (0)