Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add retry for getting credentials #431

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,30 +253,46 @@ func TestArgoCDEndpoints(ctx context.Context, t *testing.T, baseUrl string) {
}

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

b, err := RunCommand(ctx, fmt.Sprintf("%s get secrets -o json", IdpbuilderBinaryLocation), 10*time.Second)
if err != nil {
return BasicAuth{}, err
}
out := BasicAuth{}
for attempt := 0; attempt < 5; attempt++ {
select {
case <-ctx.Done():
return BasicAuth{}, ctx.Err()
default:
b, err := RunCommand(ctx, fmt.Sprintf("%s get secrets -o json", IdpbuilderBinaryLocation), 10*time.Second)
if err != nil {
lastErr = err
time.Sleep(httpRetryDelay)
continue
}

secs := make([]get.TemplateData, 2)
err = json.Unmarshal(b, &secs)
if err != nil {
return BasicAuth{}, err
}
out := BasicAuth{}
secs := make([]get.TemplateData, 2)
if err = json.Unmarshal(b, &secs); err != nil {
lastErr = err
time.Sleep(httpRetryDelay)
continue
}

for i := range secs {
if secs[i].Name == name {
out.Password = secs[i].Data["password"]
out.Username = secs[i].Data["username"]
break
for i := range secs {
if secs[i].Name == name {
out.Password = secs[i].Data["password"]
out.Username = secs[i].Data["username"]
break
}
}

if out.Password == "" || out.Username == "" {
time.Sleep(httpRetryDelay)
continue
}

return out, nil
}
}
if out.Password == "" || out.Username == "" {
return BasicAuth{}, fmt.Errorf("could not find argocd or gitea credentials: %s", b)
}
return out, nil

return BasicAuth{}, fmt.Errorf("failed after 5 attempts: %w", lastErr)
}

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

if app.Status.Health.Status == "Healthy" && app.Status.Sync.Status == "Synced" {
return true, nil
}

return false, nil
return app.Status.Health.Status == "Healthy" && app.Status.Sync.Status == "Synced", nil
}

func GetKubeClient() (client.Client, error) {
Expand Down
Loading