Skip to content

Commit

Permalink
merge volumes/networks labels
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof authored and glours committed Feb 21, 2024
1 parent 6e8b7bf commit b32c8a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions override/merge.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit b32c8a1

Please sign in to comment.