Repository navigation
Skip config-remote-sync key adds that would hide keys inherited through YAML merge keys #8175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ilyakuz-db
wants to merge
7
commits into
main
Choose a base branch
from
ilya/config-sync-inherited-key-adds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
447f925
WIP: implement
ilyakuz-db d69fd29
Address review: skip adds no path can take and give them their own re…
ilyakuz-db 55b5823
Request config-remote-sync cloud tests
ilyakuz-db 4ed4d6c
Count only aliased anchors as shared and give scalar parents their ow…
ilyakuz-db c85744b
Request config-remote-sync cloud tests
ilyakuz-db 7ebd017
Skip new elements in aliased lists and cover the undeclared-field rep…
ilyakuz-db 5e45a05
Request config-remote-sync cloud tests
ilyakuz-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -349,9 +349,9 @@ func ResolveChanges(ctx context.Context, b *bundle.Bundle, configChanges Changes | |
|
|
||
| // Decided for every destination before any index bookkeeping, so a change | ||
| // that cannot be written everywhere is skipped as a whole and shifts nothing. | ||
| addPaths, written := writtenDestinations(docs, blocks, targetName, resolved, configChange.Operation, rename.keyField, destinations) | ||
| if !written { | ||
| leaveUnapplied(ctx, configChange, fullPath, "the file does not write it where it is defined") | ||
| addPaths, skipReason := writtenDestinations(docs, blocks, targetName, resolved, configChange.Operation, rename.keyField, b.Config.GetLocationOf(resourcePath).File, destinations) | ||
| if skipReason != "" { | ||
| leaveUnapplied(ctx, configChange, fullPath, skipReason) | ||
| skipped++ | ||
| if isRename { | ||
| skipped++ | ||
|
|
@@ -474,9 +474,10 @@ func leaveUnapplied(ctx context.Context, change *ConfigChangeDesc, fullPath, rea | |
| // merged config can locate a key the file does not write at that path, e.g. one | ||
| // inherited through a merge key ('<<: *anchor'), which an edit cannot reach. Such a | ||
| // replaced key can still be added next to the merge key: addPaths holds where, per | ||
| // destination. Anything else unwritten makes written false. renameKey is the key field | ||
| // a rename rewrites, empty for any other change. | ||
| func writtenDestinations(docs sourceDocs, blocks *blockResolver, target string, resolved resolvedChange, operation OperationType, renameKey string, destinations []routeDestination) (addPaths []string, written bool) { | ||
| // destination. Anything else unwritten, or an add that would change more than what it | ||
| // adds, returns why the change is skipped instead. renameKey is the key field a rename | ||
| // rewrites, empty for any other change. resourceFile is where an unrouted new key is added. | ||
| func writtenDestinations(docs sourceDocs, blocks *blockResolver, target string, resolved resolvedChange, operation OperationType, renameKey, resourceFile string, destinations []routeDestination) (addPaths []string, skipReason string) { | ||
| addPaths = make([]string, len(destinations)) | ||
| for i, destination := range destinations { | ||
| block := destination.block | ||
|
|
@@ -492,6 +493,17 @@ func writtenDestinations(docs sourceDocs, blocks *blockResolver, target string, | |
| case !isDefinedInConfig && operation == OperationAdd && !addressesKey && block != nil: | ||
| // A new element goes into its sequence, which the block has to write. | ||
| file = block.file | ||
| case !isDefinedInConfig && addressesKey && operation != OperationRemove: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No test reaches the replace half of this case: limiting it to adds keeps every test green. Could one cover a replace of an undeclared field under a shared mapping? |
||
| // A new key is added, also for a replace of a field the file does not declare. | ||
| file = resourceFile | ||
| if block != nil { | ||
| file = block.file | ||
| } | ||
| writePath, altWritePath := writeAddress(blocks, block, target, path) | ||
| if reason := docs.addSkipReason(file, writePath, altWritePath); reason != "" { | ||
| return nil, reason | ||
| } | ||
| continue | ||
| default: | ||
| continue | ||
| } | ||
|
|
@@ -500,6 +512,10 @@ func writtenDestinations(docs sourceDocs, blocks *blockResolver, target string, | |
| path = path.Parent() | ||
| } | ||
| writePath, altWritePath := writeAddress(blocks, block, target, path) | ||
| if !isDefinedInConfig && !addressesKey && docs.aliased(file, writePath) { | ||
| // A new element would show up wherever an alias shares its sequence. | ||
| return nil, "the list it would be added to is shared through a YAML anchor" | ||
| } | ||
| // The target override wins the target merge, so a top-level key it also supplies | ||
| // would not take effect. | ||
| shadowed := addressesKey && operation == OperationReplace && (block == nil || !block.override) && | ||
|
|
@@ -519,10 +535,10 @@ func writtenDestinations(docs sourceDocs, blocks *blockResolver, target string, | |
| case addressesKey && operation == OperationReplace && parentPath != "": | ||
| addPaths[i] = parentPath | ||
| default: | ||
| return nil, false | ||
| return nil, "the file does not write it where it is defined" | ||
| } | ||
| } | ||
| return addPaths, true | ||
| return addPaths, "" | ||
| } | ||
|
|
||
| // translateWorkspacePaths recursively converts absolute workspace paths to relative | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new element in a list shared through an alias lands in the anchor, so each job using it gains it. Should element adds skip too, or is this intended?