From d75cdfeaf199847c6502f0ee3f58f9ccfcd0b9e7 Mon Sep 17 00:00:00 2001 From: RMT Date: Fri, 16 Aug 2024 21:04:07 +0800 Subject: [PATCH] internal: Use loop instead of recursion in NewAPIController (#10745) use loop instead of recursion --- internal/outpost/ak/api.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/outpost/ak/api.go b/internal/outpost/ak/api.go index 57757b2e2a..2def064273 100644 --- a/internal/outpost/ak/api.go +++ b/internal/outpost/ak/api.go @@ -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")