You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: refactor global tenantresource reconcile speed - #2311
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical reconciliation race can remove the finalizer despite newly published cleanup records, leaving targets unprotected, and namespace profile label changes can delay bootstrap until periodic resync.
This PR aims to speed up TenantResource and GlobalTenantResource replication, particularly when new namespaces join a tenant, while retaining full reconciliation for dynamic sources and health checks.
Changes:
Adds tenant-partitioned namespace bootstrap scheduling, indexed source lookups, and a separate bootstrap API budget.
Caches parsed generators, selectors, and verified apply results to reduce repeated work.
Coordinates concurrent inventory publication and adds unit tests, benchmarks, and tenant-aware e2e scenarios.
Caches have bounded retention, and target reads and ownership checks remain part of replication. Performance gains and real-cluster behavior remain unverified here; tests and benchmarks were not run.
File
Description
pkg/template/unstructured.go
Caches parsed generator templates.
pkg/template/generator_cache_test.go
Tests and benchmarks generator caching.
pkg/runtime/ssa/manager.go
Integrates verified apply-cache shortcuts.
pkg/runtime/ssa/condition.go
Preserves replication field-manager tracking.
pkg/runtime/ssa/apply_cache.go
Defines apply-cache identity and freshness checks.
pkg/runtime/ssa/apply_cache_test.go
Tests cache invalidation, drift repair, and apply costs.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A lagging informer snapshot can cause one tenant’s replication manifests to be written into another tenant’s namespace because the target’s current ownership is not validated.
Keep Ready false while merged inventory needs reconciliation
internal/controllers/resources/global.go:668
If a scoped apply publishes failed or partial inventory after the full snapshot, needsReconcile is set but a source without health checks can still publish Ready=True, allowing dependents to proceed before the follow-up succeeds. Keep Ready non-true while the merged inventory needs reconciliation, regardless of health-check configuration. Apply the same change in internal/controllers/resources/namespaced.go:674–676.
Reconcile source when namespace changes deselect resources
When a namespace label change deselects resources from a non-health-enabled GlobalTenantResource, scoped bootstrap does not prune them, so replicas can remain until the periodic resync. Queue an authoritative source reconcile when a profile change removes matches, including when only some resource blocks stop matching. Add a select→deselect regression test without a manual reconcile annotation.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Unresolved reconciliation defects can starve namespaces, retain tenant-wide fan-out, leave stale generated replicas, and delay recovery from transient errors until a 24-hour resync.
If a namespace receives another label or ownership notification during each successful reconciliation, its updated sequence keeps it at the front of the shard and later namespaces can starve. Move renewed work to the tail while preserving its notification, so the next namespace gets a turn. Update the fairness test to assert this rotation rather than immediate reselection.
Profile changes can leave stale generated replicas
When a namespace label changes a generator's output name but the resource block remains selected, bootstrap creates the new replica without pruning the old one, potentially leaving both until a 24-hour resync. Schedule full gather/prune for namespace-dependent dynamic sources on profile changes, not just selector deselections. Include dynamic sources with nil namespace selectors in the candidate index and add a generated-name regression test.
Filtering Namespace CREATE events does not prevent tenant-wide work: the Tenant watch in namespaced.go:122-125 still lists every tenant namespace and queues every TenantResource when namespace membership changes. Raw-only sources therefore still perform a full gather alongside bootstrap, retaining the fan-out this change aims to avoid. Apply additions-only filtering to that Tenant watch and reuse the source index, while preserving full reconciliation for removals and dynamic or health-enabled sources.
Pre-apply client errors can delay retries for 24 hours
After bootstrap hands a failed source to the full controller, a transient client-loading error occurs before checkpoint.start, so an apply-only source can still wait for its 24-hour resync after the manual request is cleared. Retry these pre-apply errors promptly as well; the validation-error check below already excludes permanent validation failures. This affects both callers in namespaced.go:174 and global.go:175.
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
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.
So: