@@ -30,34 +30,48 @@ func (f *resourceManagerFactory) ResourceDescriptor() acktypes.AWSResourceDescri
30
30
return &resourceDescriptor{}
31
31
}
32
32
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(
41
36
id ackv1alpha1.AWSAccountID,
42
37
region ackv1alpha1.AWSRegion,
43
38
roleARN ackv1alpha1.AWSResourceName,
44
- ) ( acktypes.AWSResourceManager, error) {
39
+ ) acktypes.AWSResourceManager {
45
40
// We use the account ID, region, and role ARN to uniquely identify a
46
41
// resource manager. This helps us to avoid creating multiple resource
47
42
// managers for the same account/region/roleARN combination.
48
43
rmId := fmt.Sprintf(" %s/%s/%s" , id, region, roleARN)
49
44
f.RLock()
50
45
rm, found := f.rmCache[rmId]
51
46
f.RUnlock()
52
-
53
- if found {
54
- return rm, nil
47
+ if ! found {
48
+ return nil
55
49
}
56
50
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) {
57
67
f.Lock()
58
68
defer f.Unlock()
59
69
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)
61
75
if err != nil {
62
76
return nil, err
63
77
}
0 commit comments