Skip to content

Commit

Permalink
Merge pull request #4385 from kubernetes-sigs/revert-4329-configMapIssue
Browse files Browse the repository at this point in the history
Revert "[fix] configMapGenerator: extra space in end of line gives "\n" instead of line breaks"
  • Loading branch information
k8s-ci-robot committed Jan 12, 2022
2 parents 13e2600 + b063645 commit 6e82b21
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 82 deletions.
7 changes: 1 addition & 6 deletions api/internal/generators/utils.go
Expand Up @@ -5,7 +5,6 @@ package generators

import (
"fmt"
"strings"

"github.com/go-errors/errors"
"sigs.k8s.io/kustomize/api/ifc"
Expand Down Expand Up @@ -51,11 +50,7 @@ func makeValidatedDataMap(
return nil, errors.Errorf(
"configmap %s illegally repeats the key `%s`", name, p.Key)
}
lines := strings.Split(p.Value, "\n")
for i := range lines {
lines[i] = strings.TrimSuffix(lines[i], " ")
}
knownKeys[p.Key] = strings.Join(lines, "\n")
knownKeys[p.Key] = p.Value
}
return knownKeys, nil
}
Expand Down
8 changes: 3 additions & 5 deletions api/krusty/baseandoverlaymedium_test.go
Expand Up @@ -292,10 +292,8 @@ metadata:
---
apiVersion: v1
data:
nonsense: |
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
nonsense: "Lorem ipsum dolor sit amet, consectetur\nadipiscing elit, sed do eiusmod
tempor\nincididunt ut labore et dolore magna aliqua. \n"
kind: ConfigMap
metadata:
annotations:
Expand All @@ -304,6 +302,6 @@ metadata:
app: mungebot
org: kubernetes
repo: test-infra
name: test-infra-app-config-4thktg822m
name: test-infra-app-config-49d6f5h7b5
`)
}
71 changes: 0 additions & 71 deletions api/krusty/configmaps_test.go
Expand Up @@ -572,74 +572,3 @@ metadata:
name: test-k9cc55dfm5
`)
}

// regression test for https://github.com/kubernetes-sigs/kustomize/issues/4287
func TestMultilineDataEndsWithSpace(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
- name: config_bla
files:
- cfg.text=cfg.text
`)
th.WriteF("cfg.text", `bla
bla
bla
`)

m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(
m, `apiVersion: v1
data:
cfg.text: |
bla
bla
bla
kind: ConfigMap
metadata:
name: config_bla-4k548khbf5
`)
}

// regression test to record the behavior prior to the fix for https://github.com/kubernetes-sigs/kustomize/issues/4287
// to ensure that the fix does not affect leading and trailing newlines in ConfigMap data
func TestMultilineDataEndsLeadingAndTrailingNewlines(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
- name: config_bla
files:
- cfg.text=cfg.text
`)
th.WriteF("cfg.text", `
bla
bla
bla
`)

m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(
m, `apiVersion: v1
data:
cfg.text: |2+
bla
bla
bla
kind: ConfigMap
metadata:
name: config_bla-8dm6c68g22
`)
}

0 comments on commit 6e82b21

Please sign in to comment.