@@ -21,6 +21,8 @@ import (
21
21
"context"
22
22
"os"
23
23
"strconv"
24
+ "strings"
25
+ "time"
24
26
25
27
"github.com/dell/goscaleio"
26
28
"github.com/hashicorp/terraform-plugin-framework/datasource"
@@ -102,7 +104,7 @@ func (p *powerflexProvider) Schema(_ context.Context, _ provider.SchemaRequest,
102
104
// Configure - provider pre-initiate calle function.
103
105
func (p * powerflexProvider ) Configure (ctx context.Context , req provider.ConfigureRequest , resp * provider.ConfigureResponse ) {
104
106
tflog .Info (ctx , "Configuring powerflex client" )
105
-
107
+ retryEOFCounter := 5
106
108
var config powerflexProviderModel
107
109
var timeout int
108
110
diags := req .Config .Get (ctx , & config )
@@ -233,30 +235,50 @@ func (p *powerflexProvider) Configure(ctx context.Context, req provider.Configur
233
235
goscaleioConf .Password = password
234
236
goscaleioConf .Insecure = insecure
235
237
236
- // Create a new PowerFlex gateway client using the configuration values
237
- gatewayClient , err := goscaleio .NewGateway (goscaleioConf .Endpoint , goscaleioConf .Username , goscaleioConf .Password , goscaleioConf .Insecure , true )
238
- if err != nil {
239
- resp .Diagnostics .AddError (
240
- "Unable to Create gateway API Client" ,
241
- "An unexpected error occurred when creating the gateway API client. " +
242
- "If the error is not clear, please contact the provider developers.\n \n " +
243
- "gateway Client Error: " + err .Error (),
244
- )
245
- return
246
- }
247
-
248
- p .gatewayClient = gatewayClient
238
+ for i := 0 ; i < retryEOFCounter ; i ++ {
239
+ // Create a new PowerFlex gateway client using the configuration values
240
+ gatewayClient , err := goscaleio .NewGateway (goscaleioConf .Endpoint , goscaleioConf .Username , goscaleioConf .Password , goscaleioConf .Insecure , true )
241
+ if err != nil {
242
+ // Sometimes the Powerflex Gateway gets inidated with requests
243
+ // In these cases just wait 5 seconds and try again
244
+ // We will retry up to 5 times before just failing
245
+ if strings .Contains (err .Error (), "EOF" ) {
246
+ time .Sleep (2 * time .Second )
247
+ continue
248
+ }
249
+ resp .Diagnostics .AddError (
250
+ "Unable to Create gateway API Client" ,
251
+ "An unexpected error occurred when creating the gateway API client. " +
252
+ "If the error is not clear, please contact the provider developers.\n \n " +
253
+ "gateway Client Error: " + err .Error (),
254
+ )
255
+ return
256
+ }
249
257
250
- _ , err = Client .Authenticate (& goscaleioConf )
258
+ p .gatewayClient = gatewayClient
259
+ break
260
+ }
251
261
252
- if err != nil {
262
+ for i := 0 ; i < retryEOFCounter ; i ++ {
263
+ // Create a new PowerFlex gateway client using the configuration values
264
+ _ , err = Client .Authenticate (& goscaleioConf )
253
265
254
- p .clientError = "An unexpected error occurred when authenticating the Goscaleio API Client. " +
255
- "Unable to Authenticate Goscaleio API Client.\n \n " +
256
- "powerflex Client Error: " + err .Error ()
266
+ if err != nil {
267
+ // Sometimes the Powerflex Gateway gets inidated with request
268
+ // In these cases just wait 2 seconds and try again
269
+ // We will retry up to 5 times before just failing
270
+ if strings .Contains (err .Error (), "EOF" ) {
271
+ time .Sleep (2 * time .Second )
272
+ continue
273
+ }
274
+ p .clientError = "An unexpected error occurred when authenticating the Goscaleio API Client. " +
275
+ "Unable to Authenticate Goscaleio API Client.\n \n " +
276
+ "powerflex Client Error: " + err .Error ()
277
+ return
278
+ }
257
279
258
- } else {
259
280
p .client = Client
281
+ break
260
282
}
261
283
262
284
resp .DataSourceData = p
0 commit comments