Skip to content

opt: scope Secret/templateResourceRefs caching to cut memory - #1920

Merged
gianlucam76 merged 1 commit into
projectsveltos:mainfrom
gianlucam76:secret-caching
Aug 17, 2026
Merged

opt: scope Secret/templateResourceRefs caching to cut memory#1920
gianlucam76 merged 1 commit into
projectsveltos:mainfrom
gianlucam76:secret-caching

Conversation

@gianlucam76

Copy link
Copy Markdown
Member

This PR reduces addon-controller's steady-state memory footprint

  1. templateResourceRefs/policyRefs/kustomizationRefs watcher no longer caches full objects it never reads The dynamic watcher in clustersummary_watchers.go used a full SharedIndexInformer per referenced GVK. Replaced with a cache.Reflector backed by a discardingStore that tracks only each object's last-seen Generation not the object itself. Behavior is unchanged: consumers are still notified on Add/Update/Delete, and templateResourceRefsWatchedIgnoreStatus still skips status-only updates via the tracked Generation.

  2. Secret cache scoped to ClusterProfileSecretType, made unconditional Only Secrets of type=addons.projectsveltos.io/cluster-profile are cached.

  3. Uncached client for all non-ClusterProfileSecretType Secret reads With Secret cache scoping now permanent, any code path reading a Secret of a different type through the cached client would start seeing silent NotFound errors. Added getManagementClusterDirectClient(), an uncached client built once in SetManagementClusterAccess, and routed every such read through it instead: - kubeconfig Secrets for SveltosCluster and CAPI managed clusters (direct clusterproxy.GetKubernetesClient calls, and everything that goes through libsveltos/lib/clustercache's GetKubernetesRestConfig/ GetKubernetesClient/GetMapper/GetCachedDiscoveryClient, which thread the passed-in client straight through to the same kubeconfig Secret read on cache miss) - Helm registry credentials/CA Secrets (RegistryCredentialsConfig) - Helm chart version-check registry auth Secret - cosign public-key and GPG keyring Secrets for chart provenance verification

This PR reduces addon-controller's steady-state memory footprint
1. **templateResourceRefs/policyRefs/kustomizationRefs watcher no longer
caches full objects it never reads**
The dynamic watcher in clustersummary_watchers.go used a full
SharedIndexInformer per referenced GVK. Replaced with a cache.Reflector
backed by a discardingStore that tracks only each object's last-seen
Generation not the object itself. Behavior is unchanged: consumers are
still notified on Add/Update/Delete, and templateResourceRefsWatchedIgnoreStatus
still skips status-only updates via the tracked Generation.
2. **Secret cache scoped to ClusterProfileSecretType, made unconditional**
Only Secrets of type=addons.projectsveltos.io/cluster-profile are cached.
3. **Uncached client for all non-ClusterProfileSecretType Secret reads**
With Secret cache scoping now permanent, any code path reading a Secret
of a different type through the cached client would start seeing silent
NotFound errors. Added getManagementClusterDirectClient(), an uncached
client built once in SetManagementClusterAccess, and routed every such
read through it instead:
- kubeconfig Secrets for SveltosCluster and CAPI managed clusters
(direct clusterproxy.GetKubernetesClient calls, and everything that
goes through libsveltos/lib/clustercache's GetKubernetesRestConfig/
GetKubernetesClient/GetMapper/GetCachedDiscoveryClient, which thread
the passed-in client straight through to the same kubeconfig Secret
read on cache miss)
- Helm registry credentials/CA Secrets (RegistryCredentialsConfig)
- Helm chart version-check registry auth Secret
- cosign public-key and GPG keyring Secrets for chart provenance
verification
4. **Every remaining kubeconfig-Secret read now goes through clustercache,
not a bare client build**
@gianlucam76
gianlucam76 merged commit b626de6 into projectsveltos:mainAug 17, 2026
11 checks passed
@gianlucam76
gianlucam76 deleted the secret-caching branch August 17, 2026 11:08
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@gianlucam76