Skip to content

Scope ConfigMap watch cache to reduce memory footprint #2195

Description

@geetikabatra

Description

The current ConfigMap watch in SetupWithManager watches all ConfigMaps cluster-wide. This means the controller's informer cache stores every ConfigMap across every namespace, regardless of whether any Nautobot CR references it.

For clusters with many ConfigMaps this can become a significant memory overhead.

Current Behavior

go

Watches(&corev1.ConfigMap{}, handler.EnqueueRequestsFromMapFunc(r.configMapToNautobotRequests))
This caches all ConfigMaps on the island (cluster-wide) — the mapFunc filters at reconcile-trigger time, but the informer still holds everything in memory.

Desired Behavior

Narrow the watch scope so the cache only holds ConfigMaps that are actually referenced by Nautobot CRs. Options to explore:

Namespace-scoped filtering — only watch namespaces that are referenced in at least one Nautobot CR's ConfigMapRef fields
Label-based filtering — require a label (e.g. nautobotop.sync.rax.io/watched: "true") on ConfigMaps that should be watched, and add a label selector predicate to the watch
Dynamic namespace cache — use a cache.Options.ByObject with namespace restrictions derived from the current set of Nautobot CRs
Context
The Nautobot CRD is cluster-scoped, and ConfigMaps can live in arbitrary namespaces
The mapFunc (configMapToNautobotRequests) already filters correctly — only matching ConfigMaps trigger reconciles
The concern is purely memory: the informer cache stores objects it will never act on
For small clusters this is fine; for large clusters with thousands of ConfigMaps it could matter

Acceptance Criteria

The controller only caches ConfigMaps it might need to act on
No regression in functionality — referenced ConfigMap edits still trigger immediate reconcile
The filtering approach should not require manual operator intervention for each ConfigMap (prefer automatic over label-based if feasible)
Notes
This is a future optimization, not a correctness issue. The current implementation is functionally correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions