@@ -32,8 +32,8 @@ const (
3232// Client are the client kind for a Rancher v3 API
3333type Client struct {
3434 Management * managementClient.Client
35- Cluster * clusterClient.Client
36- Project * projectClient.Client
35+ Cluster map [ string ] * clusterClient.Client
36+ Project map [ string ] * projectClient.Client
3737 Catalog map [string ]catalogController.ClusterRepoController
3838 Factory map [string ]* k8sFactory
3939}
@@ -289,19 +289,23 @@ func (c *Config) UpdateToken(token string) error {
289289 return err
290290 }
291291
292- if c .Client .Cluster != nil {
293- c .Client .Cluster = nil
294- _ , err := c .ClusterClient (c .ClusterID )
295- if err != nil {
296- return err
297- }
292+ for i := range c .Client .Cluster {
293+ if c .Client .Cluster [i ] != nil {
294+ c .Client .Cluster [i ] = nil
295+ _ , err := c .ClusterClient (i )
296+ if err != nil {
297+ return err
298+ }
298299
300+ }
299301 }
300- if c .Client .Project != nil {
301- c .Client .Project = nil
302- _ , err := c .ProjectClient (c .ProjectID )
303- if err != nil {
304- return err
302+ for i := range c .Client .Project {
303+ if c .Client .Project [i ] != nil {
304+ c .Client .Project [i ] = nil
305+ _ , err := c .ProjectClient (i )
306+ if err != nil {
307+ return err
308+ }
305309 }
306310 }
307311
@@ -344,15 +348,19 @@ func (c *Config) ManagementClient() (*managementClient.Client, error) {
344348
345349// ClusterClient creates a Rancher client scoped to a Cluster API
346350func (c * Config ) ClusterClient (id string ) (* clusterClient.Client , error ) {
351+ if id == "" {
352+ return nil , fmt .Errorf ("[ERROR] Rancher Cluster Client: cluster ID is nil" )
353+ }
354+
347355 c .Sync .Lock ()
348356 defer c .Sync .Unlock ()
349357
350- if id == "" {
351- return nil , fmt . Errorf ( "[ERROR] Rancher Cluster Client: cluster ID is nil" )
358+ if c . Client . Cluster == nil {
359+ c . Client . Cluster = map [ string ] * clusterClient. Client {}
352360 }
353361
354- if c .Client .Cluster != nil && id == c . ClusterID {
355- return c .Client .Cluster , nil
362+ if c .Client .Cluster [ id ] != nil {
363+ return c .Client .Cluster [ id ] , nil
356364 }
357365
358366 err := c .isRancherReady ()
@@ -367,23 +375,26 @@ func (c *Config) ClusterClient(id string) (*clusterClient.Client, error) {
367375 if err != nil {
368376 return nil , err
369377 }
370- c .Client .Cluster = cClient
371- c .ClusterID = id
378+ c .Client .Cluster [id ] = cClient
372379
373- return c .Client .Cluster , nil
380+ return c .Client .Cluster [ id ] , nil
374381}
375382
376383// ProjectClient creates a Rancher client scoped to a Project API
377384func (c * Config ) ProjectClient (id string ) (* projectClient.Client , error ) {
385+ if id == "" {
386+ return nil , fmt .Errorf ("[ERROR] Rancher Project Client: project ID is nil" )
387+ }
388+
378389 c .Sync .Lock ()
379390 defer c .Sync .Unlock ()
380391
381- if id == "" {
382- return nil , fmt . Errorf ( "[ERROR] Rancher Project Client: project ID is nil" )
392+ if c . Client . Project == nil {
393+ c . Client . Project = map [ string ] * projectClient. Client {}
383394 }
384395
385- if c .Client .Project != nil && id == c . ProjectID {
386- return c .Client .Project , nil
396+ if c .Client .Project [ id ] != nil {
397+ return c .Client .Project [ id ] , nil
387398 }
388399
389400 err := c .isRancherReady ()
@@ -399,10 +410,9 @@ func (c *Config) ProjectClient(id string) (*projectClient.Client, error) {
399410 return nil , err
400411 }
401412
402- c .Client .Project = pClient
403- c .ProjectID = id
413+ c .Client .Project [id ] = pClient
404414
405- return c .Client .Project , nil
415+ return c .Client .Project [ id ] , nil
406416}
407417
408418func (c * Config ) NormalizeURL () {
@@ -418,7 +428,6 @@ func (c *Config) CreateClientOpts() *clientbase.ClientOpts {
418428 CACerts : c .CACerts ,
419429 Insecure : c .Insecure ,
420430 }
421-
422431 return options
423432}
424433
0 commit comments