@@ -3,12 +3,12 @@ package cmd
33import (
44 "context"
55 "encoding/base64"
6+ "errors"
67 "fmt"
78 "io"
89 "strings"
910
1011 "github.com/dtan4/k8sec/pkg/client"
11- "github.com/pkg/errors"
1212 "github.com/spf13/cobra"
1313 v1 "k8s.io/api/core/v1"
1414)
@@ -46,14 +46,14 @@ rails Opaque foo "dtan4"
4646` ,
4747 RunE : func (cmd * cobra.Command , args []string ) error {
4848 if len (args ) < 2 {
49- return errors . New ( "Too few arguments. " )
49+ return fmt . Errorf ( "too few arguments" )
5050 }
5151
5252 ctx := context .Background ()
5353
5454 k8sclient , err := client .New (rootOpts .kubeconfig , rootOpts .context )
5555 if err != nil {
56- return errors . Wrap ( err , "Failed to initialize Kubernetes API client." )
56+ return fmt . Errorf ( " initialize Kubernetes API client: %w" , err )
5757 }
5858
5959 var namespace string
@@ -82,15 +82,15 @@ func runSet(ctx context.Context, k8sclient client.Client, namespace string, args
8282 ary := strings .SplitN (kv , "=" , 2 )
8383
8484 if len (ary ) != 2 {
85- return errors .Errorf ( "Argument should be in key=value format. argument=%q" , kv )
85+ return errors .New ( "argument should be in key=value format argument" )
8686 }
8787
8888 k , v := ary [0 ], ary [1 ]
8989
9090 if opts .base64encoded {
9191 _v , err := base64 .StdEncoding .DecodeString (v )
9292 if err != nil {
93- return errors . Wrapf ( err , "Failed to decode value as base64-encoded string. value=%q " , v )
93+ return fmt . Errorf ( " decode value as base64-encoded string: %w " , err )
9494 }
9595
9696 data [k ] = _v
@@ -101,7 +101,7 @@ func runSet(ctx context.Context, k8sclient client.Client, namespace string, args
101101
102102 ss , err := k8sclient .ListSecrets (ctx , namespace )
103103 if err != nil {
104- return errors . Wrapf ( err , "Failed to get current secret. name=%s " , name )
104+ return fmt . Errorf ( " get current secret %q: %w " , name , err )
105105 }
106106
107107 exists := false
@@ -118,7 +118,7 @@ func runSet(ctx context.Context, k8sclient client.Client, namespace string, args
118118 if exists {
119119 s , err = k8sclient .GetSecret (ctx , namespace , name )
120120 if err != nil {
121- return errors . Wrapf ( err , "Failed to get current secret. name=%s " , name )
121+ return fmt . Errorf ( " get current secret %q: %w " , name , err )
122122 }
123123
124124 if s .Data == nil {
@@ -131,7 +131,7 @@ func runSet(ctx context.Context, k8sclient client.Client, namespace string, args
131131
132132 _ , err = k8sclient .UpdateSecret (ctx , namespace , s )
133133 if err != nil {
134- return errors . Wrapf ( err , "Failed to update secret. name=%s " , name )
134+ return fmt . Errorf ( " update secret %q: %w " , name , err )
135135 }
136136 } else {
137137 s = & v1.Secret {
@@ -141,7 +141,7 @@ func runSet(ctx context.Context, k8sclient client.Client, namespace string, args
141141
142142 _ , err = k8sclient .CreateSecret (ctx , namespace , s )
143143 if err != nil {
144- return errors . Wrapf ( err , "Failed to create secret. name=%s " , name )
144+ return fmt . Errorf ( " create secret %q: %w " , name , err )
145145 }
146146 }
147147
0 commit comments