Bound the informer cache for cluster-scoped deployments#949
Open
LipatovAlexander wants to merge 1 commit into
Open
Bound the informer cache for cluster-scoped deployments#949LipatovAlexander wants to merge 1 commit into
LipatovAlexander wants to merge 1 commit into
Conversation
In cluster-scoped mode (empty WATCH_NAMESPACE) the manager cache was fully unscoped: it listed and cached every Pod, StatefulSet, PodDisruptionBudget, Service and Secret across all namespaces, and cached reads lazily instantiated cluster-wide informers for PersistentVolumeClaims, StorageClasses, Endpoints and EndpointSlices. On a mid-size production cluster (286 namespaces, 6.5k pods) the operator OOM-killed at startup with a 512Mi limit; after this change it runs at ~90Mi on clusters up to 17.5k pods (memory no longer scales with cluster size). The scoping model: - Pod/StatefulSet/PodDisruptionBudget/Service informers are label-scoped (cache.Options.ByObject) to app.kubernetes.io/managed-by=cass-operator. The operator only ever reads objects it created and it labels all of them; the existing managedByCassandraOperatorPredicate on Owns() already asserted the same invariant on events. Hot per-reconcile reads stay cached. - Secrets cannot be label-scoped: the operator reads user-provided secrets (SuperuserSecretName, Spec.Users, ConfigSecret, management API TLS) that carry no operator label. They are read live instead (Client.Cache.DisableFor), and both Secret watches use metadata-only projection (builder.OnlyMetadata) — their map fns and predicate only inspect annotations — so no full-object Secret informer ever exists. configSecretMapFn drops its *corev1.Secret type assertion, which would fail on PartialObjectMetadata. - PVC/StorageClass/Endpoints/EndpointSlice/ConfigMap reads are cold paths (resize, decommission, additional-seeds, image config) and go live as well, so no informers are created for them at all. - All cached objects are stripped of managedFields and the kubectl last-applied-configuration annotation (the latter embeds the full object and survives metadata-only projection). Namespace-scoped deployments benefit too (~7x memory reduction observed), since the same unscoped informers previously cached every object in the watched namespaces. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Alexander Lipatov <lipatov@mindbox.cloud>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does:
Bounds the manager's informer cache so operator memory no longer scales with cluster size (details and production numbers in #947):
cache.Options.ByObjectlabel-scopes the Pod/StatefulSet/PodDisruptionBudget/Service informers toapp.kubernetes.io/managed-by=cass-operator. The operator only reads objects it created and labels; the existingmanagedByCassandraOperatorPredicateonOwns()already asserts the same invariant on events. Hot per-reconcile reads stay cached.client.CacheOptions.DisableFor): the operator also reads user-provided secrets (SuperuserSecretName,Spec.Users, ConfigSecret, management-API TLS) that carry no operator label, so they cannot be label-scoped. Both Secret watches become metadata-only projections (builder.OnlyMetadata); their map fn / predicate only inspect annotations.configSecretMapFndrops its*corev1.Secrettype assertion accordingly.Production results (cluster-scoped): OOMKilled at startup with 512Mi → 87-91Mi steady state on clusters from 5.7k to 17.5k pods. Namespace-scoped deployments also drop ~7x.
Independent of the Events PR; both compose.
Which issue(s) this PR fixes:
Fixes #947
Checklist