Skip to content

Commit 01511da

Browse files
josvazgs-urbaniak
andauthored
CLOUDP-250918: Add test to reproduce issue #1515 (#1621)
* Add reproducing test Signed-off-by: jose.vazquez <[email protected]> * Fix cache and predicate setup * test/e2e/cache_watch_test.go: improve e2e test * Fix gets labels and ns names Signed-off-by: jose.vazquez <[email protected]> * Rename controller predicates helper * Move trim to env reading line --------- Signed-off-by: jose.vazquez <[email protected]> Co-authored-by: Sergiusz Urbaniak <[email protected]>
1 parent 50325b3 commit 01511da

File tree

10 files changed

+404
-47
lines changed

10 files changed

+404
-47
lines changed

.github/workflows/test-e2e.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ jobs:
176176
"deletion-protection",
177177
"atlas-search-nodes",
178178
"atlas-search-index",
179+
"cache-watch",
180+
"reconcile-all",
181+
"reconcile-one",
182+
"reconcile-two",
179183
]
180184
steps:
181185
- name: Get repo files from cache

cmd/manager/main.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func main() {
102102
syncPeriod := time.Hour * 3
103103

104104
var cacheFunc cache.NewCacheFunc
105-
if len(config.WatchedNamespaces) > 1 {
105+
if len(config.WatchedNamespaces) > 0 {
106106
var namespaces []string
107107
for ns := range config.WatchedNamespaces {
108108
namespaces = append(namespaces, ns)
@@ -124,8 +124,7 @@ func main() {
124124
Port: 9443,
125125
}),
126126
Cache: cache.Options{
127-
DefaultNamespaces: map[string]cache.Config{config.Namespace: {}},
128-
SyncPeriod: &syncPeriod,
127+
SyncPeriod: &syncPeriod,
129128
},
130129
HealthProbeBindAddress: config.ProbeAddr,
131130
LeaderElection: config.EnableLeaderElection,
@@ -142,9 +141,10 @@ func main() {
142141
// globalPredicates should be used for general controller Predicates
143142
// that should be applied to all controllers in order to limit the
144143
// resources they receive events for.
144+
predicateNamespaces := controller.NamespacesOrAllPredicate(config.WatchedNamespaces)
145145
globalPredicates := []predicate.Predicate{
146-
watch.CommonPredicates(), // ignore spurious changes. status changes etc.
147-
watch.SelectNamespacesPredicate(config.WatchedNamespaces), // select only desired namespaces
146+
watch.CommonPredicates(), // ignore spurious changes. status changes etc.
147+
watch.SelectNamespacesPredicate(predicateNamespaces), // select only desired namespaces
148148
}
149149

150150
atlasProvider := atlas.NewProductionProvider(config.AtlasDomain, config.GlobalAPISecret, mgr.GetClient())
@@ -294,7 +294,6 @@ type Config struct {
294294
AtlasDomain string
295295
EnableLeaderElection bool
296296
MetricsAddr string
297-
Namespace string
298297
WatchedNamespaces map[string]bool
299298
ProbeAddr string
300299
GlobalAPISecret client.ObjectKey
@@ -335,15 +334,13 @@ func parseConfiguration() Config {
335334

336335
// dev note: we pass the watched namespace as the env variable to use the Kubernetes Downward API. Unfortunately
337336
// there is no way to use it for container arguments
338-
watchedNamespace := os.Getenv("WATCH_NAMESPACE")
339-
config.WatchedNamespaces = make(map[string]bool)
340-
for _, namespace := range strings.Split(watchedNamespace, ",") {
341-
namespace = strings.TrimSpace(namespace)
342-
config.WatchedNamespaces[namespace] = true
343-
}
344-
345-
if len(config.WatchedNamespaces) == 1 {
346-
config.Namespace = watchedNamespace
337+
watchedNamespace := strings.TrimSpace(os.Getenv("WATCH_NAMESPACE"))
338+
if watchedNamespace != "" {
339+
config.WatchedNamespaces = make(map[string]bool)
340+
for _, namespace := range strings.Split(watchedNamespace, ",") {
341+
namespace = strings.TrimSpace(namespace)
342+
config.WatchedNamespaces[namespace] = true
343+
}
347344
}
348345

349346
configureDeletionProtection(&config)

pkg/controller/controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ func CustomLabelSelectorCacheBuilder(obj client.Object, labelsSelector labels.Se
2828
return cache.New(config, opts)
2929
}
3030
}
31+
32+
func NamespacesOrAllPredicate(namespaceMap map[string]bool) map[string]bool {
33+
if len(namespaceMap) > 0 {
34+
return namespaceMap
35+
}
36+
// if no namespaces where specified it must check all namespaces
37+
return map[string]bool{cache.AllNamespaces: true}
38+
}

0 commit comments

Comments
 (0)