Skip to content

Commit 10474d5

Browse files
authored
fix: add namespace cache fallback to IAMRoleSelector cache (#216)
When the IAMRoleSelector feature is enabled, the IAMRoleSelector cache runs its own `NamespaceCache` to support namespace based matching. However, the reconciler's namespace lookup methods (`getDefaultRegion`, `getEndpointURL`, `getDeletionPolicy`) were only checking `carmCache.Namespaces`, causing these values to be unavailable when only the IAMRoleSelector cache was running. This change makes the `Namespaces` field public on the IAMRoleSelector cache and adds fallback logic in the reconciler to check `irsCache.Namespaces` when `carmCache.Namespaces` doesn't have the requested data, ensuring namespace annotations remain accessible regardless of which cache is active.
1 parent db66fa4 commit 10474d5

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

pkg/runtime/iamroleselector/cache.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
// Cache wraps the informer for IAMRoleSelector resources
3535
type Cache struct {
3636
sync.RWMutex
37-
namespaces *ackcache.NamespaceCache
37+
Namespaces *ackcache.NamespaceCache
3838
log logr.Logger
3939
informer cache.SharedIndexInformer
4040
selectors map[string]*ackv1alpha1.IAMRoleSelector // name -> selector
@@ -45,7 +45,7 @@ func NewCache(log logr.Logger) *Cache {
4545
return &Cache{
4646
log: log.WithName("cache.iam-role-selector"),
4747
selectors: make(map[string]*ackv1alpha1.IAMRoleSelector),
48-
namespaces: ackcache.NewNamespaceCache(log, nil, nil),
48+
Namespaces: ackcache.NewNamespaceCache(log, nil, nil),
4949
}
5050
}
5151

@@ -79,7 +79,7 @@ func (c *Cache) Run(client dynamic.Interface, namespaceClient kubernetes.Interfa
7979

8080
factory.Start(stopCh)
8181

82-
c.namespaces.Run(namespaceClient, stopCh)
82+
c.Namespaces.Run(namespaceClient, stopCh)
8383
}
8484

8585
func (c *Cache) handleAdd(obj interface{}) {
@@ -211,7 +211,7 @@ func (c *Cache) Matches(resource runtime.Object) ([]*ackv1alpha1.IAMRoleSelector
211211
}
212212

213213
namespaceName := metaObj.GetNamespace()
214-
namespaceLabels := c.namespaces.GetLabels(namespaceName)
214+
namespaceLabels := c.Namespaces.GetLabels(namespaceName)
215215
// Get GVK - should be set on ACK resources
216216
gvk := resource.GetObjectKind().GroupVersionKind()
217217
if gvk.Empty() {

pkg/runtime/reconciler.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ func (r *resourceReconciler) regionDrifted(desired acktypes.AWSResource) bool {
390390
// look for default region in namespace metadata annotations
391391
ns := desired.MetaObject().GetNamespace()
392392
nsRegion, ok := r.carmCache.Namespaces.GetDefaultRegion(ns)
393+
if !ok {
394+
nsRegion, ok = r.irsCache.Namespaces.GetDefaultRegion(ns)
395+
}
393396
if ok {
394397
return ackv1alpha1.AWSRegion(nsRegion) != *currentRegion
395398
}
@@ -1472,6 +1475,9 @@ func (r *resourceReconciler) getRegion(
14721475
// look for default region in namespace metadata annotations
14731476
ns := res.MetaObject().GetNamespace()
14741477
defaultRegion, ok := r.carmCache.Namespaces.GetDefaultRegion(ns)
1478+
if !ok {
1479+
defaultRegion, ok = r.irsCache.Namespaces.GetDefaultRegion(ns)
1480+
}
14751481
if ok {
14761482
return ackv1alpha1.AWSRegion(defaultRegion)
14771483
}
@@ -1501,6 +1507,9 @@ func (r *resourceReconciler) getDeletionPolicy(
15011507
// look for default deletion policy in namespace metadata annotations
15021508
ns := res.MetaObject().GetNamespace()
15031509
deletionPolicy, ok = r.carmCache.Namespaces.GetDeletionPolicy(ns, r.sc.GetMetadata().ServiceAlias)
1510+
if !ok {
1511+
deletionPolicy, ok = r.irsCache.Namespaces.GetDeletionPolicy(ns, r.sc.GetMetadata().ServiceAlias)
1512+
}
15041513
if ok {
15051514
return ackv1alpha1.DeletionPolicy(deletionPolicy)
15061515
}
@@ -1520,6 +1529,9 @@ func (r *resourceReconciler) getEndpointURL(
15201529
// look for endpoint url in the namespace annotations
15211530
namespace := res.MetaObject().GetNamespace()
15221531
endpointURL, ok := r.carmCache.Namespaces.GetEndpointURL(namespace)
1532+
if !ok {
1533+
endpointURL, ok = r.irsCache.Namespaces.GetEndpointURL(namespace)
1534+
}
15231535
if ok {
15241536
return endpointURL
15251537
}

0 commit comments

Comments
 (0)