8000 fix: build a cluster-wide cache when watching all namespaces by Kitio-Tek · Pull Request #2124 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmd/operator/app/informer_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,16 @@ func TestKeeperCacheOptionsNarrowsEveryServedType(t *testing.T) {
}

}

// TestCacheOptionsWatchAllNamespacesBuildsClusterWideCache covers watch.namespaces unset, where
// GetCacheNamespaces returns only NamespaceAll. controller-runtime builds a multi-namespace cache
// whenever DefaultNamespaces has an entry, and in v0.18 its List refuses any namespace that is not
// a key, so a lone "" key made every namespaced list in CHK discovery fail.
func TestCacheOptionsWatchAllNamespacesBuildsClusterWideCache(t *testing.T) {
log := funcr.New(func(prefix, args string) {}, funcr.Options{})
all := []string{meta.NamespaceAll}

require.Empty(t, newKeeperCacheOptions(log, all).DefaultNamespaces, "keeper cache must be cluster-wide when watching all namespaces")
require.Empty(t, newBackupCacheOptions(log, all).DefaultNamespaces, "backup cache must be cluster-wide when watching all namespaces")
require.Len(t, newKeeperCacheOptions(log, []string{"ns1"}).DefaultNamespaces, 1, "a named namespace must stay scoped")
}
7 changes: 7 additions & 0 deletions cmd/operator/app/init_retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"time"

meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/cache"

Expand Down Expand Up @@ -101,7 +102,13 @@ func initWithRetry(ctx context.Context, component string, init func(context.Cont
// DNS labels, enabling per-namespace cache scoping. It falls back to NamespaceAll when the include
// list is unset or any watch namespace is a regexp pattern (the controllers' Reconcile guard
// handles filtering in that case). ByObject entries that leave Namespaces nil inherit this scoping.
//
// NamespaceAll alone yields nil, so the cache is a single cluster-wide one. A lone "" key would make
// controller-runtime build a multi-namespace cache whose List rejects every concrete namespace.
func newCacheNamespaces(cacheNamespaces []string) map[string]cache.Config {
if len(cacheNamespaces) == 1 && cacheNamespaces[0] == meta.NamespaceAll {
return nil
}
defaultNamespaces := make(map[string]cache.Config)
for _, ns := range cacheNamespaces {
defaultNamespaces[ns] = cache.Config{}
Expand Down
0