44 "bytes"
55 "context"
66 "encoding/json"
7+ "errors"
78 "fmt"
89 "io"
910 "io/ioutil"
@@ -15,7 +16,6 @@ import (
1516
1617 "github.com/google/uuid"
1718 "github.com/pivotal-cf/brokerapi/v7/domain"
18- "github.com/pkg/errors"
1919 "github.com/thanhpk/randstr"
2020 "golang.org/x/oauth2/clientcredentials"
2121 "k8s.io/apimachinery/pkg/util/wait"
@@ -111,7 +111,7 @@ func (c *Client) ProvisionRuntime(kymaVersion string) (string, error) {
111111 c .log .Info (fmt .Sprintf ("Provisioning Runtime [instanceID: %s, NAME: %s]" , c .InstanceID (), c .ClusterName ()))
112112 requestByte , err := c .prepareProvisionDetails (kymaVersion )
113113 if err != nil {
114- return "" , errors . Wrap ( err , "while preparing provision details" )
114+ return "" , fmt . Errorf ( "while preparing provision details: %w" , err )
115115 }
116116 c .log .Info (fmt .Sprintf ("Provisioning parameters: %v" , string (requestByte )))
117117
@@ -120,7 +120,7 @@ func (c *Client) ProvisionRuntime(kymaVersion string) (string, error) {
120120 err = wait .PollUntilContextTimeout (context .Background (), time .Second , time .Second * 5 , false , func (ctx context.Context ) (bool , error ) {
121121 err := c .executeRequest (http .MethodPut , provisionURL , http .StatusAccepted , bytes .NewReader (requestByte ), & response )
122122 if err != nil {
123- c .log .Warn (errors . Wrap ( err , "while executing request" ).Error ())
123+ c .log .Warn (fmt . Errorf ( "while executing request: %w" , err ).Error ())
124124 return false , nil
125125 }
126126 if response .Operation == "" {
@@ -130,7 +130,7 @@ func (c *Client) ProvisionRuntime(kymaVersion string) (string, error) {
130130 return true , nil
131131 })
132132 if err != nil {
133- return "" , errors . Wrap ( err , "while waiting for successful provision call" )
133+ return "" , fmt . Errorf ( "while waiting for successful provision call: %w" , err )
134134 }
135135 c .log .Info (fmt .Sprintf ("Successfully send provision request, got operation ID %s" , response .Operation ))
136136
@@ -146,13 +146,13 @@ func (c *Client) DeprovisionRuntime() (string, error) {
146146 err := wait .PollUntilContextTimeout (context .Background (), time .Second , time .Second * 5 , false , func (ctx context.Context ) (bool , error ) {
147147 err := c .executeRequest (http .MethodDelete , deprovisionURL , http .StatusAccepted , nil , & response )
148148 if err != nil {
149- c .log .Warn (errors . Wrap ( err , "while executing request" ).Error ())
149+ c .log .Warn (fmt . Errorf ( "while executing request: %w" , err ).Error ())
150150 return false , nil
151151 }
152152 return true , nil
153153 })
154154 if err != nil {
155- return "" , errors . Wrap ( err , "while waiting for successful deprovision call" )
155+ return "" , fmt . Errorf ( "while waiting for successful deprovision call: %w" , err )
156156 }
157157 c .log .Info (fmt .Sprintf ("Successfully send deprovision request, got operation ID %s" , response .Operation ))
158158 return response .Operation , nil
@@ -162,7 +162,7 @@ func (c *Client) SuspendRuntime() error {
162162 c .log .Info (fmt .Sprintf ("Suspending Runtime [instanceID: %s, NAME: %s]" , c .instanceID , c .clusterName ))
163163 requestByte , err := c .prepareUpdateDetails (BoolPtr (false ))
164164 if err != nil {
165- return errors . Wrap ( err , "while preparing update details" )
165+ return fmt . Errorf ( "while preparing update details: %w" , err )
166166 }
167167 c .log .Info (fmt .Sprintf ("Suspension parameters: %v" , string (requestByte )))
168168
@@ -173,13 +173,13 @@ func (c *Client) SuspendRuntime() error {
173173 err = wait .PollUntilContextTimeout (context .Background (), time .Second , time .Second * 5 , false , func (ctx context.Context ) (bool , error ) {
174174 err := c .executeRequest (http .MethodPatch , suspensionURL , http .StatusOK , bytes .NewReader (requestByte ), & suspensionResponse )
175175 if err != nil {
176- c .log .Warn (errors . Wrap ( err , "while executing request" ).Error ())
176+ c .log .Warn (fmt . Errorf ( "while executing request: %w" , err ).Error ())
177177 return false , nil
178178 }
179179 return true , nil
180180 })
181181 if err != nil {
182- return errors . Wrap ( err , "while waiting for successful suspension call" )
182+ return fmt . Errorf ( "while waiting for successful suspension call: %w" , err )
183183 }
184184 c .log .Info (fmt .Sprintf ("Successfully send suspension request for %s" , suspensionResponse ))
185185 return nil
@@ -189,7 +189,7 @@ func (c *Client) UnsuspendRuntime() error {
189189 c .log .Info (fmt .Sprintf ("Unsuspending Runtime [instanceID: %s, NAME: %s]" , c .InstanceID (), c .ClusterName ()))
190190 requestByte , err := c .prepareUpdateDetails (BoolPtr (true ))
191191 if err != nil {
192- return errors . Wrap ( err , "while preparing update details" )
192+ return fmt . Errorf ( "while preparing update details: %w" , err )
193193 }
194194 c .log .Info (fmt .Sprintf ("Unsuspension parameters: %v" , string (requestByte )))
195195
@@ -200,13 +200,13 @@ func (c *Client) UnsuspendRuntime() error {
200200 err = wait .PollUntilContextTimeout (context .Background (), time .Second , time .Second * 5 , false , func (ctx context.Context ) (bool , error ) {
201201 err := c .executeRequest (http .MethodPatch , suspensionURL , http .StatusOK , bytes .NewReader (requestByte ), & unsuspensionResponse )
202202 if err != nil {
203- c .log .Warn (errors . Wrap ( err , "while executing request" ).Error ())
203+ c .log .Warn (fmt . Errorf ( "while executing request: %w" , err ).Error ())
204204 return false , nil
205205 }
206206 return true , nil
207207 })
208208 if err != nil {
209- return errors . Wrap ( err , "while waiting for successful unsuspension call" )
209+ return fmt . Errorf ( "while waiting for successful unsuspension call: %w" , err )
210210 }
211211 c .log .Info (fmt .Sprintf ("Successfully send unsuspension request for %s" , unsuspensionResponse ))
212212 return nil
@@ -248,7 +248,7 @@ func (c *Client) AwaitOperationSucceeded(operationID string, timeout time.Durati
248248 err := wait .PollUntilContextTimeout (context .Background (), 5 * time .Minute , timeout , false , func (ctx context.Context ) (bool , error ) {
249249 err := c .executeRequest (http .MethodGet , lastOperationURL , http .StatusOK , nil , & response )
250250 if err != nil {
251- c .log .Warn (errors . Wrap ( err , "while executing request" ).Error ())
251+ c .log .Warn (fmt . Errorf ( "while executing request: %w" , err ).Error ())
252252 return false , nil
253253 }
254254 c .log .Info (fmt .Sprintf ("Last operation status: %s" , response .State ))
@@ -270,7 +270,7 @@ func (c *Client) AwaitOperationSucceeded(operationID string, timeout time.Durati
270270 }
271271 })
272272 if err != nil {
273- return errors . Wrap ( err , "while waiting for succeeded last operation" )
273+ return fmt . Errorf ( "while waiting for succeeded last operation: %w" , err )
274274 }
275275 return nil
276276}
@@ -283,7 +283,7 @@ func (c *Client) FetchDashboardURL() (string, error) {
283283 err := wait .PollUntilContextTimeout (context .Background (), time .Second , time .Second * 5 , false , func (ctx context.Context ) (bool , error ) {
284284 err := c .executeRequest (http .MethodGet , instanceDetailsURL , http .StatusOK , nil , & response )
285285 if err != nil {
286- c .log .Warn (errors . Wrap ( err , "while executing request" ).Error ())
286+ c .log .Warn (fmt . Errorf ( "while executing request: %w" , err ).Error ())
287287 return false , nil
288288 }
289289 if response .DashboardURL == "" {
@@ -293,7 +293,7 @@ func (c *Client) FetchDashboardURL() (string, error) {
293293 return true , nil
294294 })
295295 if err != nil {
296- return "" , errors . Wrap ( err , "while waiting for dashboardURL" )
296+ return "" , fmt . Errorf ( "while waiting for dashboardURL: %w" , err )
297297 }
298298 c .log .Info (fmt .Sprintf ("Successfully fetched dashboard URL: %s" , response .DashboardURL ))
299299
@@ -316,11 +316,11 @@ func (c *Client) prepareProvisionDetails(customVersion string) ([]byte, error) {
316316 }
317317 rawParameters , err := json .Marshal (parameters )
318318 if err != nil {
319- return nil , errors . Wrap ( err , "while marshalling parameters body" )
319+ return nil , fmt . Errorf ( "while marshalling parameters body: %w" , err )
320320 }
321321 rawContext , err := json .Marshal (ctx )
322322 if err != nil {
323- return nil , errors . Wrap ( err , "while marshalling context body" )
323+ return nil , fmt . Errorf ( "while marshalling context body: %w" , err )
324324 }
325325 requestBody := domain.ProvisionDetails {
326326 ServiceID : kymaClassID ,
@@ -337,7 +337,7 @@ func (c *Client) prepareProvisionDetails(customVersion string) ([]byte, error) {
337337
338338 requestByte , err := json .Marshal (requestBody )
339339 if err != nil {
340- return nil , errors . Wrap ( err , "while marshalling request body" )
340+ return nil , fmt . Errorf ( "while marshalling request body: %w" , err )
341341 }
342342 return requestByte , nil
343343}
@@ -351,7 +351,7 @@ func (c *Client) prepareUpdateDetails(active *bool) ([]byte, error) {
351351 }
352352 rawContext , err := json .Marshal (ctx )
353353 if err != nil {
354- return nil , errors . Wrap ( err , "while marshalling context body" )
354+ return nil , fmt . Errorf ( "while marshalling context body: %w" , err )
355355 }
356356 requestBody := domain.UpdateDetails {
357357 ServiceID : kymaClassID ,
@@ -364,21 +364,21 @@ func (c *Client) prepareUpdateDetails(active *bool) ([]byte, error) {
364364 }
365365 requestByte , err := json .Marshal (requestBody )
366366 if err != nil {
367- return nil , errors . Wrap ( err , "while marshalling request body" )
367+ return nil , fmt . Errorf ( "while marshalling request body: %w" , err )
368368 }
369369 return requestByte , nil
370370}
371371
372372func (c * Client ) executeRequest (method , url string , expectedStatus int , body io.Reader , responseBody interface {}) error {
373373 request , err := http .NewRequest (method , url , body )
374374 if err != nil {
375- return errors . Wrap ( err , "while creating request for provisioning" )
375+ return fmt . Errorf ( "while creating request for provisioning: %w" , err )
376376 }
377377 request .Header .Set ("X-Broker-API-Version" , "2.14" )
378378
379379 resp , err := c .client .Do (request )
380380 if err != nil {
381- return errors . Wrapf ( err , "while executing request URL: %s" , url )
381+ return fmt . Errorf ( "while executing request URL: %s: %w " , url , err )
382382 }
383383 defer c .warnOnError (resp .Body .Close )
384384 if resp .StatusCode != expectedStatus {
@@ -389,12 +389,12 @@ func (c *Client) executeRequest(method, url string, expectedStatus int, body io.
389389 }
390390 bodyString := string (bodyBytes )
391391 c .log .Warn (fmt .Sprintf ("%s" , bodyString ))
392- return errors .Errorf ("got unexpected status code while calling Kyma Environment Broker: want: %d, got: %d (url=%s)" , expectedStatus , resp .StatusCode , url )
392+ return fmt .Errorf ("got unexpected status code while calling Kyma Environment Broker: want: %d, got: %d (url=%s)" , expectedStatus , resp .StatusCode , url )
393393 }
394394
395395 err = json .NewDecoder (resp .Body ).Decode (responseBody )
396396 if err != nil {
397- return errors . Wrapf ( err , "while decoding body" )
397+ return fmt . Errorf ( "while decoding body: %w" , err )
398398 }
399399
400400 return nil
0 commit comments