@@ -3,6 +3,7 @@ package cmd
3
3
import (
4
4
"bytes"
5
5
"encoding/json"
6
+ "errors"
6
7
"fmt"
7
8
"log"
8
9
"os"
@@ -11,7 +12,6 @@ import (
11
12
12
13
jsonpatch "github.com/evanphx/json-patch"
13
14
jsoniterator "github.com/json-iterator/go"
14
- "github.com/pkg/errors"
15
15
"github.com/spf13/cobra"
16
16
"github.com/spf13/pflag"
17
17
"helm.sh/helm/v3/pkg/action"
@@ -347,15 +347,15 @@ func (d *diffCmd) runHelm3() error {
347
347
}
348
348
original , err := actionConfig .KubeClient .Build (bytes .NewBuffer (releaseManifest ), false )
349
349
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 )
351
351
}
352
352
target , err := actionConfig .KubeClient .Build (bytes .NewBuffer (installManifest ), false )
353
353
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 )
355
355
}
356
356
releaseManifest , installManifest , err = genManifest (original , target )
357
357
if err != nil {
358
- return errors . Wrap ( err , "unable to generate manifests" )
358
+ return fmt . Errorf ( "unable to generate manifests: %w" , err )
359
359
}
360
360
}
361
361
@@ -423,7 +423,7 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
423
423
424
424
toBeUpdated , err := existingResourceConflict (toBeCreated )
425
425
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 )
427
427
}
428
428
429
429
_ = toBeUpdated .Visit (func (r * resource.Info , err error ) error {
@@ -445,7 +445,7 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
445
445
currentObj , err := helper .Get (info .Namespace , info .Name )
446
446
if err != nil {
447
447
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 )
449
449
}
450
450
// to be created
451
451
out , _ := yaml .Marshal (info .Object )
@@ -457,11 +457,11 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
457
457
out , _ := jsoniterator .ConfigCompatibleWithStandardLibrary .Marshal (currentObj )
458
458
pruneObj , err := deleteStatusAndTidyMetadata (out )
459
459
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 )
461
461
}
462
462
pruneOut , err := yaml .Marshal (pruneObj )
463
463
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 )
465
465
}
466
466
releaseManifest = append (releaseManifest , yamlSeperator ... )
467
467
releaseManifest = append (releaseManifest , pruneOut ... )
@@ -479,16 +479,16 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
479
479
helper .ServerDryRun = true
480
480
targetObj , err := helper .Patch (info .Namespace , info .Name , patchType , patch , nil )
481
481
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 )
483
483
}
484
484
out , _ = jsoniterator .ConfigCompatibleWithStandardLibrary .Marshal (targetObj )
485
485
pruneObj , err = deleteStatusAndTidyMetadata (out )
486
486
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 )
488
488
}
489
489
pruneOut , err = yaml .Marshal (pruneObj )
490
490
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 )
492
492
}
493
493
installManifest = append (installManifest , yamlSeperator ... )
494
494
installManifest = append (installManifest , pruneOut ... )
@@ -501,17 +501,17 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
501
501
func createPatch (originalObj , currentObj runtime.Object , target * resource.Info ) ([]byte , types.PatchType , error ) {
502
502
oldData , err := json .Marshal (originalObj )
503
503
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 )
505
505
}
506
506
newData , err := json .Marshal (target .Object )
507
507
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 )
509
509
}
510
510
511
511
// Even if currentObj is nil (because it was not found), it will marshal just fine
512
512
currentData , err := json .Marshal (currentObj )
513
513
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 )
515
515
}
516
516
// kind := target.Mapping.GroupVersionKind.Kind
517
517
// if kind == "Deployment" {
@@ -539,7 +539,7 @@ func createPatch(originalObj, currentObj runtime.Object, target *resource.Info)
539
539
540
540
patchMeta , err := strategicpatch .NewPatchMetaFromStruct (versionedObject )
541
541
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 )
543
543
}
544
544
545
545
patch , err := strategicpatch .CreateThreeWayMergePatch (oldData , newData , currentData , patchMeta , true )
@@ -565,7 +565,7 @@ func existingResourceConflict(resources kube.ResourceList) (kube.ResourceList, e
565
565
if apierrors .IsNotFound (err ) {
566
566
return nil
567
567
}
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 )
569
569
}
570
570
571
571
requireUpdate .Append (info )
@@ -579,7 +579,7 @@ func deleteStatusAndTidyMetadata(obj []byte) (map[string]interface{}, error) {
579
579
var objectMap map [string ]interface {}
580
580
err := jsoniterator .Unmarshal (obj , & objectMap )
581
581
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 )
583
583
}
584
584
585
585
delete (objectMap , "status" )
0 commit comments