Skip to content

Commit 63238ad

Browse files
authored
Only setup necessary configmap informers depending on used CARM version (#157)
Issue #, if available: Description of changes: - if CARMv2 feature gate is enabled, setup `ack-carm-map` map informer, otherwise setup `ack-role-account-map` informer. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent a1359c9 commit 63238ad

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

pkg/runtime/cache/cache.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/jaypipes/envutil"
2222
kubernetes "k8s.io/client-go/kubernetes"
2323
"k8s.io/client-go/tools/cache"
24+
25+
"github.com/aws-controllers-k8s/runtime/pkg/featuregate"
2426
)
2527

2628
const (
@@ -85,10 +87,16 @@ type Caches struct {
8587
}
8688

8789
// New instantiate a new Caches object.
88-
func New(log logr.Logger, config Config) Caches {
90+
func New(log logr.Logger, config Config, features featuregate.FeatureGates) Caches {
91+
var carmMaps, accounts *CARMMap
92+
if features.IsEnabled(featuregate.CARMv2) {
93+
carmMaps = NewCARMMapCache(log)
94+
} else {
95+
accounts = NewCARMMapCache(log)
96+
}
8997
return Caches{
90-
Accounts: NewCARMMapCache(log),
91-
CARMMaps: NewCARMMapCache(log),
98+
Accounts: accounts,
99+
CARMMaps: carmMaps,
92100
Namespaces: NewNamespaceCache(log, config.WatchScope, config.Ignored),
93101
}
94102
}
@@ -110,9 +118,19 @@ func (c Caches) Run(clientSet kubernetes.Interface) {
110118
// WaitForCachesToSync waits for both of the namespace and configMap
111119
// informers to sync - by checking their hasSynced functions.
112120
func (c Caches) WaitForCachesToSync(ctx context.Context) bool {
113-
namespaceSynced := cache.WaitForCacheSync(ctx.Done(), c.Namespaces.hasSynced)
114-
accountSynced := cache.WaitForCacheSync(ctx.Done(), c.Accounts.hasSynced)
115-
return namespaceSynced && accountSynced
121+
// if the cache is not initialized, sync status should be true
122+
namespaceSynced, accountSynced, carmSynced := true, true, true
123+
// otherwise check their hasSynced functions
124+
if c.Namespaces != nil {
125+
namespaceSynced = cache.WaitForCacheSync(ctx.Done(), c.Namespaces.hasSynced)
126+
}
127+
if c.Accounts != nil {
128+
accountSynced = cache.WaitForCacheSync(ctx.Done(), c.Accounts.hasSynced)
129+
}
130+
if c.CARMMaps != nil {
131+
carmSynced = cache.WaitForCacheSync(ctx.Done(), c.CARMMaps.hasSynced)
132+
}
133+
return namespaceSynced && accountSynced && carmSynced
116134
}
117135

118136
// Stop closes the stop channel and cause all the SharedInformers

pkg/runtime/service_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ func (c *serviceController) BindControllerManager(mgr ctrlrt.Manager, cfg ackcfg
217217
NamespaceKubePublic,
218218
NamespaceKubeNodeLease,
219219
}},
220+
cfg.FeatureGates,
220221
)
221222
// We want to run the caches if the length of the namespaces slice is
222223
// either 0 (watching all namespaces) or greater than 1 (watching multiple

0 commit comments

Comments
 (0)