Repository navigation
fix(resources): key generator origins per target instead of slice index - #2325
Open
zaidrain06 wants to merge 1 commit into
Open
zaidrain06 wants to merge 1 commit into
zaidrain06 wants to merge 1 commit into
Conversation
Assign generator origins per rendered target occurrence rather than the global output slice index so adding or removing an earlier item does not shift later items and recreate unchanged objects. - Scope generator occurrence counters per target GVK/namespace/name while preserving distinct SSA field managers when a single generator emits multiple documents for the same target. - Migrate existing positional generator origins and SSA managedFields entries in place before pruning so upgrades do not trigger a one-time recreation of existing generated objects. - Sort selector-listed context resources deterministically by namespace and name in ResourceReference.loadResources. Fixes projectcapsule#2324 Signed-off-by: Ömer <[email protected]>
This branch has not been deployed
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.
Fixes #2324
Summary
Generator output in
Collector.Collectpreviously derivedOriginfrom the global slice position (<resourceIndex>/generator-<generatorIndex>-<i>), which becomes part ofResourceID.GetKeyandResourceID.FieldOwner. Whenever an earlier item was removed (or an unsorted informer-backed context list returned items in a different order), every subsequent generated object shifted to a new origin, causingpruneProcessedItemsto delete the live object under its previous origin andapplyAccumulatedItemsto recreate it.Changes
internal/controllers/resources/collect.go): Track the occurrence index per rendered target (GVK + targetNamespace + name) within each generator instead of using the global slice positioni. Unique targets consistently receive<resourceIndex>/generator-<generatorIndex>-0, while multiple documents emitted by the same generator for the same target still get distinct SSA field managers (-0,-1, ...).pkg/api/processor/processor_func.go): Before pruning inReconcile(and before applying inReconcileNamespace), match existing<resourceIndex>/generator-<generatorIndex>-<pos>ProcessedItemsentries whose targetGVK + namespace + name + tenantmatches an unmatched new generator item from the same<resourceIndex>/generator-<generatorIndex>-prefix, rename the live object'smanagedFieldsmanager in place with optimisticresourceVersionlocking, and update the trackedOriginwithout recreating the object.pkg/template/reference.go): SortUnstructuredListitems returned byResourceReference.loadResourcesby(namespace, name)so templates iterating.itemsdirectly over cache-backed list reads receive a deterministic order across reconciles.TestCollectorGeneratorOriginIsIndependentOfSlicePosition(collect_test.go) andTestProcessorMigratesPositionalGeneratorOriginsWithoutRecreatingObjects(processor_func_test.go).Verification
go test ./internal/controllers/resources/... ./pkg/api/processor/... ./pkg/template/...go test -race ./internal/controllers/... -run '^$' -bench '^BenchmarkController' -benchtime=1xgolangci-lint run -c .golangci.yaml