@@ -30,34 +30,48 @@ func (f *resourceManagerFactory) ResourceDescriptor() acktypes.AWSResourceDescri
3030 return &resourceDescriptor{}
3131}
3232
33- // ManagerFor returns a resource manager object that can manage resources for a
34- // supplied AWS account
35- func (f *resourceManagerFactory) ManagerFor(
36- cfg ackcfg.Config,
37- clientcfg aws.Config,
38- log logr.Logger,
39- metrics *ackmetrics.Metrics,
40- rr acktypes.Reconciler,
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(
4136 id ackv1alpha1.AWSAccountID,
4237 region ackv1alpha1.AWSRegion,
4338 roleARN ackv1alpha1.AWSResourceName,
44- ) ( acktypes.AWSResourceManager, error) {
39+ ) acktypes.AWSResourceManager {
4540 // We use the account ID, region, and role ARN to uniquely identify a
4641 // resource manager. This helps us to avoid creating multiple resource
4742 // managers for the same account/region/roleARN combination.
4843 rmId := fmt.Sprintf(" %s/%s/%s" , id, region, roleARN)
4944 f.RLock()
5045 rm, found := f.rmCache[rmId]
5146 f.RUnlock()
52-
53- if found {
54- return rm, nil
47+ if ! found {
48+ return nil
5549 }
5650
51+ return rm
52+ }
53+
54+ // ManagerFor returns a resource manager object that can manage resources for a
55+ // supplied AWS account
56+ func (f *resourceManagerFactory) ManagerFor(
57+ cfg ackcfg.Config,
58+ clientcfg aws.Config,
59+ log logr.Logger,
60+ metrics *ackmetrics.Metrics,
61+ rr acktypes.Reconciler,
62+ id ackv1alpha1.AWSAccountID,
63+ region ackv1alpha1.AWSRegion,
64+ partition ackv1alpha1.AWSPartition,
65+ roleARN ackv1alpha1.AWSResourceName,
66+ ) (acktypes.AWSResourceManager, error) {
5767 f.Lock()
5868 defer f.Unlock()
5969
60- rm, err := newResourceManager(cfg, clientcfg, log, metrics, rr, id, region)
70+ // We use the account ID, region, partition, and role ARN to uniquely identify a
71+ // resource manager. This helps us to avoid creating multiple resource
72+ // managers for the same account/region/roleARN combination.
73+ rmId := fmt.Sprintf(" %s/%s/%s" , id, region, roleARN)
74+ rm, err := newResourceManager(cfg, clientcfg, log, metrics, rr, id, region, partition)
6175 if err != nil {
6276 return nil, err
6377 }
0 commit comments