Skip to content

Commit

Permalink
internal: Use loop instead of recursion in NewAPIController (#10745)
Browse files Browse the repository at this point in the history
use loop instead of recursion
  • Loading branch information
RMTT authored Aug 16, 2024
1 parent c3d3646 commit d75cdfe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/outpost/ak/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ func NewAPIController(akURL url.URL, token string) *APIController {

// Because we don't know the outpost UUID, we simply do a list and pick the first
// The service account this token belongs to should only have access to a single outpost
outposts, _, err := apiClient.OutpostsApi.OutpostsInstancesList(context.Background()).Execute()
if err != nil {
var outposts *api.PaginatedOutpostList
var err error
for {
outposts, _, err = apiClient.OutpostsApi.OutpostsInstancesList(context.Background()).Execute()

if err == nil {
break
}

log.WithError(err).Error("Failed to fetch outpost configuration, retrying in 3 seconds")
time.Sleep(time.Second * 3)
return NewAPIController(akURL, token)
}
if len(outposts.Results) < 1 {
panic("No outposts found with given token, ensure the given token corresponds to an authenitk Outpost")
Expand Down

0 comments on commit d75cdfe

Please sign in to comment.