Skip to content

Commit

Permalink
Increased timeout for image prefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
catttam committed Jul 24, 2023
1 parent cd78d76 commit 9fe82bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

const infoPath = "/system/info"
const configPath = "/system/config"
const _DEFAULT_TIMEOUT = 20

var (
// ErrParsingEndpoint error message for cluster endpoint parsing
Expand Down Expand Up @@ -81,7 +82,9 @@ func (trt *tokenRoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
}

// GetClient returns an HTTP client to communicate with the cluster
func (cluster *Cluster) GetClient() *http.Client {
func (cluster *Cluster) GetClient(args ...int) *http.Client {
timeout := _DEFAULT_TIMEOUT

var transport http.RoundTripper = &http.Transport{
// Enable/disable ssl verification
TLSClientConfig: &tls.Config{InsecureSkipVerify: !cluster.SSLVerify},
Expand Down Expand Up @@ -114,9 +117,13 @@ func (cluster *Cluster) GetClient() *http.Client {
}
}

if len(args) != 0 {
timeout = args[0]
}

return &http.Client{
Transport: transport,
Timeout: time.Second * 400,
Timeout: time.Second * time.Duration(timeout),
}
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ func ApplyService(svc *types.Service, c *cluster.Cluster, method string) error {
if err != nil {
return cluster.ErrMakingRequest
}
res, err := c.GetClient().Do(req)

client := c.GetClient()
// Increase timeout to avoid errors due to daemonset execution
if svc.ImagePrefetch {
client = c.GetClient(400)
}
res, err := client.Do(req)
if err != nil {
return cluster.ErrSendingRequest
}
Expand Down

0 comments on commit 9fe82bf

Please sign in to comment.