Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Helm values preserve newlines in comments (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh authored Nov 22, 2018
1 parent 130fb1a commit 21fa63f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion pkg/lifecycle/render/helm/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func deepMerge(base, user, vendor yaml.MapSlice) (yaml.MapSlice, error) {
allKeys := getAllKeys(vendor, user) // we can drop keys that have been dropped by the vendor

for _, k := range allKeys {
// don't merge comments
if _, ok := k.(yaml.Comment); ok {
merged = append(merged, yaml.MapItem{Key: k})
continue
}

baseVal, baseOk := getValueFromKey(base, k)
userVal, userOk := getValueFromKey(user, k)
vendorVal, vendorOk := getValueFromKey(vendor, k)
Expand Down Expand Up @@ -115,7 +121,10 @@ func getAllKeys(maps ...yaml.MapSlice) (allKeys []interface{}) {
seenKeys := map[interface{}]bool{}
for _, m := range maps {
for _, item := range m {
if _, ok := seenKeys[item.Key]; !ok {
// comments are unique
if _, ok := item.Key.(yaml.Comment); ok {
allKeys = append(allKeys, item.Key)
} else if _, ok := seenKeys[item.Key]; !ok {
seenKeys[item.Key] = true
allKeys = append(allKeys, item.Key)
}
Expand Down
69 changes: 68 additions & 1 deletion pkg/lifecycle/render/helm/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,74 @@ key3: modified-by-vendor
key3: 4
# another user comment`,
vendor: "# comment prefix\nkey1: 1\n # indented comment\n\n# empty line\nnested_key:\n # nested comment line 1\n # nested comment line 2\n key2: 2 # inline comment\n # nested comment line 3\nkey3: 3\n# comment suffix\n",
expected: "# comment prefix\nkey1: 1\n # indented comment\n# empty line\nnested_key:\n # nested comment line 1\n # nested comment line 2\n key2: 2\n # inline comment\n # nested comment line 3\nkey3: 4\n# comment suffix\n",
expected: "# comment prefix\nkey1: 1\n # indented comment\n\n# empty line\nnested_key:\n # nested comment line 1\n # nested comment line 2\n key2: 2\n # inline comment\n # nested comment line 3\nkey3: 4\n# comment suffix\n",
},
{
name: "mysql",
base: "",
user: "mysqlPassword: my-super-secret-password",
vendor: `## mysql image version
## ref: https://hub.docker.com/r/library/mysql/tags/
##
image: "mysql"
imageTag: "5.7.14"
## Specify password for root user
##
## Default: random 10 character string
# mysqlRootPassword: testing
## Create a database user
##
# mysqlUser:
## Default: random 10 character string
# mysqlPassword:
## Allow unauthenticated access, uncomment to enable
##
# mysqlAllowEmptyPassword: true
## Create a database
##
# mysqlDatabase:
## Specify an imagePullPolicy (Required)
## It's recommended to change this to 'Always' if the image tag is 'latest'
## ref: http://kubernetes.io/docs/user-guide/images/#updating-images
##
imagePullPolicy: IfNotPresent`,
expected: `## mysql image version
## ref: https://hub.docker.com/r/library/mysql/tags/
##
image: mysql
imageTag: 5.7.14
## Specify password for root user
##
## Default: random 10 character string
# mysqlRootPassword: testing
## Create a database user
##
# mysqlUser:
## Default: random 10 character string
# mysqlPassword:
## Allow unauthenticated access, uncomment to enable
##
# mysqlAllowEmptyPassword: true
## Create a database
##
# mysqlDatabase:
## Specify an imagePullPolicy (Required)
## It's recommended to change this to 'Always' if the image tag is 'latest'
## ref: http://kubernetes.io/docs/user-guide/images/#updating-images
##
imagePullPolicy: IfNotPresent
mysqlPassword: my-super-secret-password
`,
},
}

Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/emosbaugh/yaml/emitterc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/emosbaugh/yaml/scannerc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 21fa63f

Please sign in to comment.