Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to get: x/y because of unknown namespace for the cache #4168

Closed
barkbay opened this issue Jan 28, 2021 · 6 comments
Closed

unable to get: x/y because of unknown namespace for the cache #4168

barkbay opened this issue Jan 28, 2021 · 6 comments
Assignees
Labels
>enhancement Enhancement of existing functionality good first issue Good for newcomers

Comments

@barkbay
Copy link
Contributor

barkbay commented Jan 28, 2021

I observed this error in our e2e tests, it seems to be harmless but it makes the logs harder to read and I think we should understand where it comes from:

{
	"log.level": "error",
	"@timestamp": "2021-01-28T01:42:34.794Z",
	"log.logger": "manager.eck-operator.controller.beat-es-association-controller",
	"message": "Reconciler error",
	"service.version": "1.5.0-SNAPSHOT+7257dd51",
	"service.type": "eck",
	"ecs.version": "1.4.0",
	"name": "filebeat",
	"namespace": "e2e-xdhm8",
	"error": "unable to get: e2e-xdhm8/filebeat because of unknown namespace for the cache",
	"error.stack_trace": "sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.8.1/pkg/internal/controller/controller.go:252\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func1.2\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.8.1/pkg/internal/controller/controller.go:215\nk8s.io/apimachinery/pkg/util/wait.JitterUntilWithContext.func1\n\t/go/pkg/mod/k8s.io/apimachinery@v0.20.2/pkg/util/wait/wait.go:185\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil.func1\n\t/go/pkg/mod/k8s.io/apimachinery@v0.20.2/pkg/util/wait/wait.go:155\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil\n\t/go/pkg/mod/k8s.io/apimachinery@v0.20.2/pkg/util/wait/wait.go:156\nk8s.io/apimachinery/pkg/util/wait.JitterUntil\n\t/go/pkg/mod/k8s.io/apimachinery@v0.20.2/pkg/util/wait/wait.go:133\nk8s.io/apimachinery/pkg/util/wait.JitterUntilWithContext\n\t/go/pkg/mod/k8s.io/apimachinery@v0.20.2/pkg/util/wait/wait.go:185\nk8s.io/apimachinery/pkg/util/wait.UntilWithContext\n\t/go/pkg/mod/k8s.io/apimachinery@v0.20.2/pkg/util/wait/wait.go:99"
}
@barkbay barkbay added the >test Related to unit/integration/e2e tests label Jan 28, 2021
@pebrc
Copy link
Collaborator

pebrc commented Feb 18, 2021

This message comes from the multi-namespace cache in controller runtime. Any user running ECK in restricted mode with access to only a subset of namespaces will run into this.

So it seems that the controllers get the events for edits on all instances of our CRDs no matter whether they are inside one of the relevant namespaces. We could implement our own Predicate that filters out any event for irrelevant namespaces. Also I wonder if this is something we should raise as an issue against controller runtime.

@pebrc pebrc added >enhancement Enhancement of existing functionality good first issue Good for newcomers and removed >test Related to unit/integration/e2e tests labels Feb 18, 2021
@ferozsalam
Copy link

I would appreciate this being filtered out by default - it causes a large amount of noise which makes other issues more difficult to identify.

@barkbay
Copy link
Contributor Author

barkbay commented Dec 1, 2021

Just to add some context and explain what is happening (it took me a moment to get it): this issue happens iif the following 2 conditions are met:

  1. the operator is managing a restricted set of namespaces
  2. storage class validation is enabled

In that particular case we add an empty namespace ("") to the list of managed namespaces:

log.Info("Operator configured to manage multiple namespaces", "namespaces", managedNamespaces, "operator_namespace", operatorNamespace)
// The managed cache should always include the operator namespace so that we can work with operator-internal resources.
managedNamespaces = append(managedNamespaces, operatorNamespace)


// Add the empty namespace to allow watching cluster-scoped resources if storage class validation is enabled.
if viper.GetBool(operator.ValidateStorageClassFlag) {
    managedNamespaces = append(managedNamespaces, "")
}


opts.NewCache = cache.MultiNamespacedCacheBuilder(managedNamespaces)

The operator then watches all the resources on the cluster (even the ones which are not managed) while the multiNamespaceCache contains only cache entries for a limited set of namespaces:

image

Note the odd entry "" in the namespaceToCache map ^

@thbkrkr
Copy link
Contributor

thbkrkr commented Dec 1, 2021

@barkbay
Copy link
Contributor Author

barkbay commented Dec 1, 2021

kubernetes-sigs/controller-runtime#1435 introduced Options.SelectorsByObject as a cache options, but cache.Options is hard coded:

// New constructs a brand new cluster.
func New(config *rest.Config, opts ...Option) (Cluster, error) {
...
	options := Options{}
	for _, opt := range opts {
		opt(&options)
	}
	options = setOptionsDefaults(options)
...

	// Create the cache for the cached read client and registering informers
	cache, err := options.NewCache(config, cache.Options{Scheme: options.Scheme, Mapper: mapper, Resync: options.SyncPeriod, Namespace: options.Namespace})
	if err != nil {
		return nil, err
	}

🤔

@naemono
Copy link
Contributor

naemono commented Oct 3, 2022

Closing as completed/resolved in #5187 and #6013

@naemono naemono closed this as completed Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement Enhancement of existing functionality good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants