Skip to content
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

merge volumes/networks labels #584

Merged
merged 1 commit into from Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions override/merge.go
Expand Up @@ -41,10 +41,13 @@ var mergeSpecials = map[tree.Path]merger{}

func init() {
mergeSpecials["networks.*.ipam.config"] = mergeIPAMConfig
mergeSpecials["networks.*.labels"] = mergeToSequence
mergeSpecials["volumes.*.labels"] = mergeToSequence
mergeSpecials["services.*.annotations"] = mergeToSequence
mergeSpecials["services.*.build"] = mergeBuild
mergeSpecials["services.*.build.args"] = mergeToSequence
mergeSpecials["services.*.build.additional_contexts"] = mergeToSequence
mergeSpecials["services.*.build.extra_hosts"] = mergeToSequence
mergeSpecials["services.*.build.labels"] = mergeToSequence
mergeSpecials["services.*.command"] = override
mergeSpecials["services.*.depends_on"] = mergeDependsOn
Expand Down
14 changes: 7 additions & 7 deletions override/merge_networks_test.go
Expand Up @@ -187,9 +187,9 @@ networks:
bar: foo
baz: "0"
labels:
com.example.description: "Financial transaction network"
com.example.department-new: "New"
com.example.label-with-empty-value: ""
- "com.example.department-new=New"
- "com.example.description=Financial transaction network"
- "com.example.label-with-empty-value="
network2:
`, `
services:
Expand Down Expand Up @@ -219,10 +219,10 @@ networks:
bar: foo
baz: "0"
labels:
com.example.description: "Financial transaction network"
com.example.department: "Finance"
com.example.label-with-empty-value: ""
com.example.department-new: "New"
- "com.example.department=Finance"
- "com.example.description=Financial transaction network"
- "com.example.label-with-empty-value="
- "com.example.department-new=New"
network2:
`)
}
16 changes: 10 additions & 6 deletions override/uncity.go
Expand Up @@ -107,13 +107,17 @@ func enforceUnicity(value any, p tree.Path) (any, error) {
return value, nil
}

func keyValueIndexer(y any, _ tree.Path) (string, error) {
value := y.(string)
key, _, found := strings.Cut(value, "=")
if !found {
return value, nil
func keyValueIndexer(y any, p tree.Path) (string, error) {
switch value := y.(type) {
case string:
key, _, found := strings.Cut(value, "=")
if !found {
return value, nil
}
return key, nil
default:
return "", fmt.Errorf("%s: unexpected type %T", p, y)
}
return key, nil
}

func volumeIndexer(y any, p tree.Path) (string, error) {
Expand Down