Merge pull request #3431 from Shell32-Natsu/newline

keep \n in the end of resource yaml
This commit is contained in:
Jeff Regan
2021-01-10 12:51:36 -08:00
committed by GitHub
2 changed files with 42 additions and 0 deletions

View File

@@ -440,3 +440,40 @@ metadata:
name: cm-o2-5k95kd76ft
`)
}
func TestConfigMapGeneratorLiteralNewline(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("/app", `
generators:
- configmaps.yaml
`)
th.WriteF("/app/configmaps.yaml", `
apiVersion: builtin
kind: ConfigMapGenerator
metadata:
name: testing
literals:
- |
initial.txt=greetings
everyone
- |
final.txt=different
behavior
---
`)
m := th.Run("/app", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(
m, `
apiVersion: v1
data:
final.txt: |
different
behavior
initial.txt: |
greetings
everyone
kind: ConfigMap
metadata:
name: testing-tt4769fb52
`)
}

View File

@@ -149,6 +149,11 @@ func (r *ByteReader) Read() ([]*yaml.RNode, error) {
index := 0
for i := range values {
// the Split used above will eat the tail '\n' from each resource. This may affect the
// literal string value since '\n' is meaningful in it.
if i != len(values)-1 {
values[i] += "\n"
}
decoder := yaml.NewDecoder(bytes.NewBufferString(values[i]))
node, err := r.decode(index, decoder)
if err == io.EOF {