Skip to content

Commit

Permalink
Only setup necessary configmap informers depending on used CARM versi…
Browse files Browse the repository at this point in the history
…on (#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.
  • Loading branch information
TiberiuGC committed Aug 13, 2024
1 parent a1359c9 commit 63238ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
30 changes: 24 additions & 6 deletions pkg/runtime/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/jaypipes/envutil"
kubernetes "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"

"github.com/aws-controllers-k8s/runtime/pkg/featuregate"
)

const (
Expand Down Expand Up @@ -85,10 +87,16 @@ type Caches struct {
}

// New instantiate a new Caches object.
func New(log logr.Logger, config Config) Caches {
func New(log logr.Logger, config Config, features featuregate.FeatureGates) Caches {
var carmMaps, accounts *CARMMap
if features.IsEnabled(featuregate.CARMv2) {
carmMaps = NewCARMMapCache(log)
} else {
accounts = NewCARMMapCache(log)
}
return Caches{
Accounts: NewCARMMapCache(log),
CARMMaps: NewCARMMapCache(log),
Accounts: accounts,
CARMMaps: carmMaps,
Namespaces: NewNamespaceCache(log, config.WatchScope, config.Ignored),
}
}
Expand All @@ -110,9 +118,19 @@ func (c Caches) Run(clientSet kubernetes.Interface) {
// WaitForCachesToSync waits for both of the namespace and configMap
// informers to sync - by checking their hasSynced functions.
func (c Caches) WaitForCachesToSync(ctx context.Context) bool {
namespaceSynced := cache.WaitForCacheSync(ctx.Done(), c.Namespaces.hasSynced)
accountSynced := cache.WaitForCacheSync(ctx.Done(), c.Accounts.hasSynced)
return namespaceSynced && accountSynced
// if the cache is not initialized, sync status should be true
namespaceSynced, accountSynced, carmSynced := true, true, true
// otherwise check their hasSynced functions
if c.Namespaces != nil {
namespaceSynced = cache.WaitForCacheSync(ctx.Done(), c.Namespaces.hasSynced)
}
if c.Accounts != nil {
accountSynced = cache.WaitForCacheSync(ctx.Done(), c.Accounts.hasSynced)
}
if c.CARMMaps != nil {
carmSynced = cache.WaitForCacheSync(ctx.Done(), c.CARMMaps.hasSynced)
}
return namespaceSynced && accountSynced && carmSynced
}

// Stop closes the stop channel and cause all the SharedInformers
Expand Down
1 change: 1 addition & 0 deletions pkg/runtime/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (c *serviceController) BindControllerManager(mgr ctrlrt.Manager, cfg ackcfg
NamespaceKubePublic,
NamespaceKubeNodeLease,
}},
cfg.FeatureGates,
)
// We want to run the caches if the length of the namespaces slice is
// either 0 (watching all namespaces) or greater than 1 (watching multiple
Expand Down

0 comments on commit 63238ad

Please sign in to comment.