diff --git a/Gopkg.lock b/Gopkg.lock index 490962737..849150309 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -330,11 +330,11 @@ [[projects]] branch = "improve-comment-parsing" - digest = "1:044881d3282dd4e9ac8a2a8d77f6f802ea98a71d5894f8d6c3a817cceaf7adc9" + digest = "1:b19f021fce8ceef9284606de1375b68bde8ec3b4b72433ed724813195f4a12cb" name = "github.com/emosbaugh/yaml" packages = ["."] pruneopts = "UT" - revision = "2abc69c54a5148a107ff1e82865daa42aa4e9d20" + revision = "8ed2da1637f01691123a80b59f56ac3e48e5db31" [[projects]] digest = "1:b48d19e79fa607e9e3715ff9a73cdd3777a9cac254b50b9af721466f687e850d" diff --git a/pkg/lifecycle/render/helm/values.go b/pkg/lifecycle/render/helm/values.go index da8abe07b..882fa2b39 100644 --- a/pkg/lifecycle/render/helm/values.go +++ b/pkg/lifecycle/render/helm/values.go @@ -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) @@ -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) } diff --git a/pkg/lifecycle/render/helm/values_test.go b/pkg/lifecycle/render/helm/values_test.go index 32ea83dbf..9ab2fee2d 100644 --- a/pkg/lifecycle/render/helm/values_test.go +++ b/pkg/lifecycle/render/helm/values_test.go @@ -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 +`, }, } diff --git a/vendor/github.com/emosbaugh/yaml/emitterc.go b/vendor/github.com/emosbaugh/yaml/emitterc.go index bbfd823b5..7eb6428b5 100644 --- a/vendor/github.com/emosbaugh/yaml/emitterc.go +++ b/vendor/github.com/emosbaugh/yaml/emitterc.go @@ -576,7 +576,7 @@ func yaml_emitter_emit_flow_mapping_value(emitter *yaml_emitter_t, event *yaml_e // Expect a block item node. func yaml_emitter_emit_block_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { + if first && event.typ != yaml_COMMENT_EVENT { if !yaml_emitter_increase_indent(emitter, false, emitter.mapping_context && !emitter.indention) { return false } diff --git a/vendor/github.com/emosbaugh/yaml/scannerc.go b/vendor/github.com/emosbaugh/yaml/scannerc.go index 469ddb01d..3005425e2 100644 --- a/vendor/github.com/emosbaugh/yaml/scannerc.go +++ b/vendor/github.com/emosbaugh/yaml/scannerc.go @@ -1495,6 +1495,17 @@ func yaml_parser_scan_to_next_token(parser *yaml_parser_t) bool { if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { return false } + if parser.mark.column == 0 && parser.parse_comments { + // This is an empty line. + token := yaml_token_t{ + typ: yaml_COMMENT_TOKEN, + start_mark: parser.mark, + end_mark: parser.mark, + value: []byte(""), + style: yaml_PLAIN_SCALAR_STYLE, + } + yaml_insert_token(parser, -1, &token) + } skip_line(parser) // In the block context, a new line may start a simple key.