@@ -30,6 +30,24 @@ func (f *resourceManagerFactory) ResourceDescriptor() acktypes.AWSResourceDescri
3030 return &resourceDescriptor{}
3131}
3232
33+ // GetCachedManager returns a manager object that can manage resources for a
34+ // supplied AWS account if it was already created and cached, or nil if not
35+ func (f *resourceManagerFactory) GetCachedManager(
36+ id ackv1alpha1.AWSAccountID,
37+ region ackv1alpha1.AWSRegion,
38+ roleARN ackv1alpha1.AWSResourceName,
39+ ) acktypes.AWSResourceManager {
40+ // We use the account ID, region, and role ARN to uniquely identify a
41+ // resource manager. This helps us to avoid creating multiple resource
42+ // managers for the same account/region/roleARN combination.
43+ rmId := fmt.Sprintf(" %s/%s/%s" , id, region, roleARN)
44+ f.RLock()
45+ rm, _ := f.rmCache[rmId]
46+ f.RUnlock()
47+
48+ return rm
49+ }
50+
3351// ManagerFor returns a resource manager object that can manage resources for a
3452// supplied AWS account
3553func (f *resourceManagerFactory) ManagerFor(
@@ -40,24 +58,17 @@ func (f *resourceManagerFactory) ManagerFor(
4058 rr acktypes.Reconciler,
4159 id ackv1alpha1.AWSAccountID,
4260 region ackv1alpha1.AWSRegion,
61+ partition ackv1alpha1.AWSPartition,
4362 roleARN ackv1alpha1.AWSResourceName,
4463) (acktypes.AWSResourceManager, error) {
45- // We use the account ID, region, and role ARN to uniquely identify a
46- // resource manager. This helps us to avoid creating multiple resource
47- // managers for the same account/region/roleARN combination.
48- rmId := fmt.Sprintf(" %s/%s/%s" , id, region, roleARN)
49- f.RLock()
50- rm, found := f.rmCache[rmId]
51- f.RUnlock()
52-
53- if found {
54- return rm, nil
55- }
56-
5764 f.Lock()
5865 defer f.Unlock()
5966
60- rm, err := newResourceManager(cfg, clientcfg, log, metrics, rr, id, region)
67+ // We use the account ID, region, partition, and role ARN to uniquely identify a
68+ // resource manager. This helps us to avoid creating multiple resource
69+ // managers for the same account/region/roleARN combination.
70+ rmId := fmt.Sprintf(" %s/%s/%s" , id, region, roleARN)
71+ rm, err := newResourceManager(cfg, clientcfg, log, metrics, rr, id, region, partition)
6172 if err != nil {
6273 return nil, err
6374 }
0 commit comments