Skip to content

Commit be892de

Browse files
authored
add retry for getting credentials (#431)
Signed-off-by: Manabu McCloskey <[email protected]>
1 parent a29c580 commit be892de

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

tests/e2e/e2e.go

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -253,30 +253,46 @@ func TestArgoCDEndpoints(ctx context.Context, t *testing.T, baseUrl string) {
253253
}
254254

255255
func GetBasicAuth(ctx context.Context, name string) (BasicAuth, error) {
256+
var lastErr error
256257

257-
b, err := RunCommand(ctx, fmt.Sprintf("%s get secrets -o json", IdpbuilderBinaryLocation), 10*time.Second)
258-
if err != nil {
259-
return BasicAuth{}, err
260-
}
261-
out := BasicAuth{}
258+
for attempt := 0; attempt < 5; attempt++ {
259+
select {
260+
case <-ctx.Done():
261+
return BasicAuth{}, ctx.Err()
262+
default:
263+
b, err := RunCommand(ctx, fmt.Sprintf("%s get secrets -o json", IdpbuilderBinaryLocation), 10*time.Second)
264+
if err != nil {
265+
lastErr = err
266+
time.Sleep(httpRetryDelay)
267+
continue
268+
}
262269

263-
secs := make([]get.TemplateData, 2)
264-
err = json.Unmarshal(b, &secs)
265-
if err != nil {
266-
return BasicAuth{}, err
267-
}
270+
out := BasicAuth{}
271+
secs := make([]get.TemplateData, 2)
272+
if err = json.Unmarshal(b, &secs); err != nil {
273+
lastErr = err
274+
time.Sleep(httpRetryDelay)
275+
continue
276+
}
268277

269-
for i := range secs {
270-
if secs[i].Name == name {
271-
out.Password = secs[i].Data["password"]
272-
out.Username = secs[i].Data["username"]
273-
break
278+
for i := range secs {
279+
if secs[i].Name == name {
280+
out.Password = secs[i].Data["password"]
281+
out.Username = secs[i].Data["username"]
282+
break
283+
}
284+
}
285+
286+
if out.Password == "" || out.Username == "" {
287+
time.Sleep(httpRetryDelay)
288+
continue
289+
}
290+
291+
return out, nil
274292
}
275293
}
276-
if out.Password == "" || out.Username == "" {
277-
return BasicAuth{}, fmt.Errorf("could not find argocd or gitea credentials: %s", b)
278-
}
279-
return out, nil
294+
295+
return BasicAuth{}, fmt.Errorf("failed after 5 attempts: %w", lastErr)
280296
}
281297

282298
func GetArgoCDSessionToken(ctx context.Context, endpoint string) (string, error) {
@@ -350,11 +366,7 @@ func isArgoAppSyncedAndHealthy(ctx context.Context, kubeClient client.Client, na
350366
return false, err
351367
}
352368

353-
if app.Status.Health.Status == "Healthy" && app.Status.Sync.Status == "Synced" {
354-
return true, nil
355-
}
356-
357-
return false, nil
369+
return app.Status.Health.Status == "Healthy" && app.Status.Sync.Status == "Synced", nil
358370
}
359371

360372
func GetKubeClient() (client.Client, error) {

0 commit comments

Comments
 (0)