Skip to content

Commit

Permalink
feat: kong Root() timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mflendrich committed Aug 11, 2020
1 parent f901e55 commit af1fe7a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cli/ingress-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func init() {
}

func main() {
ctx := context.Background()

color.Output = ioutil.Discard
rand.Seed(time.Now().UnixNano())

Expand Down Expand Up @@ -247,7 +249,7 @@ func main() {
const backoffID = "kong-admin-api"
retryCount := 0
for {
root, err = kongClient.Root(context.Background())
root, err = rootWithTimeout(ctx, kongClient)
if err == nil {
break
}
Expand Down Expand Up @@ -287,7 +289,7 @@ func main() {

req, _ := http.NewRequest("GET",
cliConfig.KongAdminURL+"/tags", nil)
res, err := kongClient.Do(context.Background(), req, nil)
res, err := kongClient.Do(ctx, req, nil)
if err == nil && res.StatusCode == 200 {
controllerConfig.Kong.HasTagSupport = true
}
Expand Down Expand Up @@ -619,6 +621,12 @@ func createApiserverClient(apiserverHost string, kubeConfig string,
return cfg, client, nil
}

func rootWithTimeout(ctx context.Context, kc *kong.Client) (map[string]interface{}, error) {
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
defer cancel()
return kc.Root(ctx)
}

const (
// High enough QPS to fit all expected use cases. QPS=0 is not set here, because
// client code is overriding it.
Expand Down

0 comments on commit af1fe7a

Please sign in to comment.