Skip to content

Commit 981aa57

Browse files
authored
Merge pull request #668 from rawmind0/timeout
Added timeout to CatalogV2Client function when getting new catalog v2 client
2 parents 23691a9 + 5110369 commit 981aa57

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 1.15.1 (May 21, 2021)
2+
3+
FEATURES:
4+
5+
6+
7+
ENHANCEMENTS:
8+
9+
10+
11+
BUG FIXES:
12+
13+
* Added timeout to `CatalogV2Client` function when getting new catalog v2 client
14+
115
## 1.15.0 (May 20, 2021)
216

317
FEATURES:
@@ -12,7 +26,7 @@ FEATURES:
1226

1327
ENHANCEMENTS:
1428

15-
29+
* Added timeout to `CatalogV2Client` function when getting new catalog v2 client
1630

1731
BUG FIXES:
1832

rancher2/config.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,26 @@ func (c *Config) CatalogV2Client(id string) (*clientbase.APIBaseClient, error) {
294294
return nil, err
295295
}
296296

297+
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
298+
defer cancel()
297299
// Setup the cluster client
298300
options := c.CreateClientOpts()
299301
options.URL = options.URL + "/k8s/clusters/" + id + rancher2CatalogAPIVersion
300-
cli, err := clientbase.NewAPIClient(options)
301-
if err != nil {
302-
return nil, err
302+
for {
303+
cli, err := clientbase.NewAPIClient(options)
304+
if err == nil {
305+
c.Client.CatalogV2[id] = &cli
306+
return c.Client.CatalogV2[id], err
307+
}
308+
if !IsServerError(err) && !IsUnknownSchemaType(err) {
309+
return nil, err
310+
}
311+
select {
312+
case <-time.After(rancher2RetriesWait * time.Second):
313+
case <-ctx.Done():
314+
return nil, err
315+
}
303316
}
304-
c.Client.CatalogV2[id] = &cli
305-
return c.Client.CatalogV2[id], err
306317
}
307318

308319
// ClusterClient creates a Rancher client scoped to a Cluster API
@@ -730,13 +741,13 @@ func (c *Config) getObjectV2ByID(clusterID, id, APIType string, resp interface{}
730741
return fmt.Errorf("Object API V2 type is nil")
731742
}
732743

733-
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
734-
defer cancel()
735-
736744
client, err := c.CatalogV2Client(clusterID)
737745
if err != nil {
738746
return err
739747
}
748+
749+
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
750+
defer cancel()
740751
for {
741752
err = client.ByID(APIType, id, resp)
742753
if err == nil {

0 commit comments

Comments
 (0)