@@ -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
"helm.sh/helm/v3/pkg/action"
17
17
"helm.sh/helm/v3/pkg/cli"
@@ -249,15 +249,15 @@ func (d *diffCmd) runHelm3() error {
249
249
}
250
250
original , err := actionConfig .KubeClient .Build (bytes .NewBuffer (releaseManifest ), false )
251
251
if err != nil {
252
- return errors . Wrap ( err , "unable to build kubernetes objects from original release manifest" )
252
+ return fmt . Errorf ( "unable to build kubernetes objects from original release manifest: %w" , err )
253
253
}
254
254
target , err := actionConfig .KubeClient .Build (bytes .NewBuffer (installManifest ), false )
255
255
if err != nil {
256
- return errors . Wrap ( err , "unable to build kubernetes objects from new release manifest" )
256
+ return fmt . Errorf ( "unable to build kubernetes objects from new release manifest: %w" , err )
257
257
}
258
258
releaseManifest , installManifest , err = genManifest (original , target )
259
259
if err != nil {
260
- return errors . Wrap ( err , "unable to generate manifests" )
260
+ return fmt . Errorf ( "unable to generate manifests: %w" , err )
261
261
}
262
262
}
263
263
@@ -325,7 +325,7 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
325
325
326
326
toBeUpdated , err := existingResourceConflict (toBeCreated )
327
327
if err != nil {
328
- return nil , nil , errors . Wrap ( err , "rendered manifests contain a resource that already exists. Unable to continue with update" )
328
+ return nil , nil , fmt . Errorf ( "rendered manifests contain a resource that already exists. Unable to continue with update: %w" , err )
329
329
}
330
330
331
331
_ = toBeUpdated .Visit (func (r * resource.Info , err error ) error {
@@ -347,7 +347,7 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
347
347
currentObj , err := helper .Get (info .Namespace , info .Name )
348
348
if err != nil {
349
349
if ! apierrors .IsNotFound (err ) {
350
- return errors . Wrap ( err , "could not get information about the resource" )
350
+ return fmt . Errorf ( "could not get information about the resource: %w" , err )
351
351
}
352
352
// to be created
353
353
out , _ := yaml .Marshal (info .Object )
@@ -359,11 +359,11 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
359
359
out , _ := jsoniterator .ConfigCompatibleWithStandardLibrary .Marshal (currentObj )
360
360
pruneObj , err := deleteStatusAndTidyMetadata (out )
361
361
if err != nil {
362
- return errors . Wrapf ( err , "prune current obj %q with kind %s" , info .Name , kind )
362
+ return fmt . Errorf ( "prune current obj %q with kind %s: %w " , info .Name , kind , err )
363
363
}
364
364
pruneOut , err := yaml .Marshal (pruneObj )
365
365
if err != nil {
366
- return errors . Wrapf ( err , "prune current out %q with kind %s" , info .Name , kind )
366
+ return fmt . Errorf ( "prune current out %q with kind %s: %w " , info .Name , kind , err )
367
367
}
368
368
releaseManifest = append (releaseManifest , yamlSeperator ... )
369
369
releaseManifest = append (releaseManifest , pruneOut ... )
@@ -381,16 +381,16 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
381
381
helper .ServerDryRun = true
382
382
targetObj , err := helper .Patch (info .Namespace , info .Name , patchType , patch , nil )
383
383
if err != nil {
384
- return errors . Wrapf ( err , "cannot patch %q with kind %s" , info .Name , kind )
384
+ return fmt . Errorf ( "cannot patch %q with kind %s: %w " , info .Name , kind , err )
385
385
}
386
386
out , _ = jsoniterator .ConfigCompatibleWithStandardLibrary .Marshal (targetObj )
387
387
pruneObj , err = deleteStatusAndTidyMetadata (out )
388
388
if err != nil {
389
- return errors . Wrapf ( err , "prune current obj %q with kind %s" , info .Name , kind )
389
+ return fmt . Errorf ( "prune current obj %q with kind %s: %w " , info .Name , kind , err )
390
390
}
391
391
pruneOut , err = yaml .Marshal (pruneObj )
392
392
if err != nil {
393
- return errors . Wrapf ( err , "prune current out %q with kind %s" , info .Name , kind )
393
+ return fmt . Errorf ( "prune current out %q with kind %s: %w " , info .Name , kind , err )
394
394
}
395
395
installManifest = append (installManifest , yamlSeperator ... )
396
396
installManifest = append (installManifest , pruneOut ... )
@@ -403,17 +403,17 @@ func genManifest(original, target kube.ResourceList) ([]byte, []byte, error) {
403
403
func createPatch (originalObj , currentObj runtime.Object , target * resource.Info ) ([]byte , types.PatchType , error ) {
404
404
oldData , err := json .Marshal (originalObj )
405
405
if err != nil {
406
- return nil , types .StrategicMergePatchType , errors . Wrap ( err , "serializing current configuration" )
406
+ return nil , types .StrategicMergePatchType , fmt . Errorf ( "serializing current configuration: %w" , err )
407
407
}
408
408
newData , err := json .Marshal (target .Object )
409
409
if err != nil {
410
- return nil , types .StrategicMergePatchType , errors . Wrap ( err , "serializing target configuration" )
410
+ return nil , types .StrategicMergePatchType , fmt . Errorf ( "serializing target configuration: %w" , err )
411
411
}
412
412
413
413
// Even if currentObj is nil (because it was not found), it will marshal just fine
414
414
currentData , err := json .Marshal (currentObj )
415
415
if err != nil {
416
- return nil , types .StrategicMergePatchType , errors . Wrap ( err , "serializing live configuration" )
416
+ return nil , types .StrategicMergePatchType , fmt . Errorf ( "serializing live configuration: %w" , err )
417
417
}
418
418
// kind := target.Mapping.GroupVersionKind.Kind
419
419
// if kind == "Deployment" {
@@ -441,7 +441,7 @@ func createPatch(originalObj, currentObj runtime.Object, target *resource.Info)
441
441
442
442
patchMeta , err := strategicpatch .NewPatchMetaFromStruct (versionedObject )
443
443
if err != nil {
444
- return nil , types .StrategicMergePatchType , errors . Wrap ( err , "unable to create patch metadata from object" )
444
+ return nil , types .StrategicMergePatchType , fmt . Errorf ( "unable to create patch metadata from object: %w" , err )
445
445
}
446
446
447
447
patch , err := strategicpatch .CreateThreeWayMergePatch (oldData , newData , currentData , patchMeta , true )
@@ -467,7 +467,7 @@ func existingResourceConflict(resources kube.ResourceList) (kube.ResourceList, e
467
467
if apierrors .IsNotFound (err ) {
468
468
return nil
469
469
}
470
- return errors . Wrap ( err , "could not get information about the resource" )
470
+ return fmt . Errorf ( "could not get information about the resource: %w" , err )
471
471
}
472
472
473
473
requireUpdate .Append (info )
@@ -481,7 +481,7 @@ func deleteStatusAndTidyMetadata(obj []byte) (map[string]interface{}, error) {
481
481
var objectMap map [string ]interface {}
482
482
err := jsoniterator .Unmarshal (obj , & objectMap )
483
483
if err != nil {
484
- return nil , errors . Wrap ( err , "could not unmarshal byte sequence" )
484
+ return nil , fmt . Errorf ( "could not unmarshal byte sequence: %w" , err )
485
485
}
486
486
487
487
delete (objectMap , "status" )
0 commit comments