Reinstate configmap/secret generator env field.

This commit is contained in:
monopole
2021-03-07 20:03:43 -08:00
parent 9c4966ccc8
commit a8b851f84a
4 changed files with 43 additions and 4 deletions

View File

@@ -132,6 +132,7 @@ configMapGenerator:
- vegetable=broccoli - vegetable=broccoli
envs: envs:
- foo.env - foo.env
env: bar.env
files: files:
- passphrase=phrase.dat - passphrase=phrase.dat
- forces.txt - forces.txt
@@ -153,10 +154,14 @@ secretGenerator:
files: files:
- passphrase=phrase.dat - passphrase=phrase.dat
- forces.txt - forces.txt
env: bar.env
`) `)
th.WriteF("foo.env", ` th.WriteF("foo.env", `
MOUNTAIN=everest MOUNTAIN=everest
OCEAN=pacific OCEAN=pacific
`)
th.WriteF("bar.env", `
BIRD=falcon
`) `)
th.WriteF("phrase.dat", ` th.WriteF("phrase.dat", `
Life is short. Life is short.
@@ -173,6 +178,7 @@ weak nuclear
m := th.Run(".", opts) m := th.Run(".", opts)
expFmt := `apiVersion: v1 expFmt := `apiVersion: v1
data: data:
BIRD: falcon
MOUNTAIN: everest MOUNTAIN: everest
OCEAN: pacific OCEAN: pacific
forces.txt: |2 forces.txt: |2
@@ -190,7 +196,7 @@ data:
vegetable: broccoli vegetable: broccoli
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: blah-bob-d87t8m8tgm name: blah-bob-g9df72cd5b
--- ---
apiVersion: v1 apiVersion: v1
data: data:
@@ -203,6 +209,7 @@ metadata:
--- ---
apiVersion: v1 apiVersion: v1
data: data:
BIRD: ZmFsY29u
MOUNTAIN: ZXZlcmVzdA== MOUNTAIN: ZXZlcmVzdA==
OCEAN: cGFjaWZpYw== OCEAN: cGFjaWZpYw==
forces.txt: %s forces.txt: %s
@@ -230,7 +237,7 @@ type: Opaque
CmdyYXZpdGF0aW9uYWwKZWxlY3Ryb21hZ25ldGljCnN0cm9uZyBudWNsZWFyCndlYWsgbn CmdyYXZpdGF0aW9uYWwKZWxlY3Ryb21hZ25ldGljCnN0cm9uZyBudWNsZWFyCndlYWsgbn
VjbGVhcgo=`, `| VjbGVhcgo=`, `|
CkxpZmUgaXMgc2hvcnQuCkJ1dCB0aGUgeWVhcnMgYXJlIGxvbmcuCk5vdCB3aGlsZSB0aG CkxpZmUgaXMgc2hvcnQuCkJ1dCB0aGUgeWVhcnMgYXJlIGxvbmcuCk5vdCB3aGlsZSB0aG
UgZXZpbCBkYXlzIGNvbWUgbm90Lgo=`, `9t25t44gg4`))) UgZXZpbCBkYXlzIGNvbWUgbm90Lgo=`, `58g62h555c`)))
} }
// TODO: These should be errors instead. // TODO: These should be errors instead.

View File

@@ -155,7 +155,6 @@ type Kustomization struct {
// moving content of deprecated fields to newer // moving content of deprecated fields to newer
// fields. // fields.
func (k *Kustomization) FixKustomizationPostUnmarshalling() { func (k *Kustomization) FixKustomizationPostUnmarshalling() {
if k.Kind == "" { if k.Kind == "" {
k.Kind = KustomizationKind k.Kind = KustomizationKind
} }
@@ -168,6 +167,20 @@ func (k *Kustomization) FixKustomizationPostUnmarshalling() {
} }
k.Resources = append(k.Resources, k.Bases...) k.Resources = append(k.Resources, k.Bases...)
k.Bases = nil k.Bases = nil
for i, g := range k.ConfigMapGenerator {
if g.EnvSource != "" {
k.ConfigMapGenerator[i].EnvSources =
append(g.EnvSources, g.EnvSource)
k.ConfigMapGenerator[i].EnvSource = ""
}
}
for i, g := range k.SecretGenerator {
if g.EnvSource != "" {
k.SecretGenerator[i].EnvSources =
append(g.EnvSources, g.EnvSource)
k.SecretGenerator[i].EnvSource = ""
}
}
} }
// FixKustomizationPreMarshalling fixes things // FixKustomizationPreMarshalling fixes things

View File

@@ -1,6 +1,7 @@
package types package types
import ( import (
"reflect"
"testing" "testing"
) )
@@ -15,6 +16,12 @@ func fixKustomizationPostUnmarshallingCheck(k, e *Kustomization) bool {
func TestFixKustomizationPostUnmarshalling(t *testing.T) { func TestFixKustomizationPostUnmarshalling(t *testing.T) {
var k Kustomization var k Kustomization
k.Bases = append(k.Bases, "foo") k.Bases = append(k.Bases, "foo")
k.ConfigMapGenerator = []ConfigMapArgs{{GeneratorArgs{
KvPairSources: KvPairSources{
EnvSources: []string{"a", "b"},
EnvSource: "c",
},
}}}
k.FixKustomizationPostUnmarshalling() k.FixKustomizationPostUnmarshalling()
expected := Kustomization{ expected := Kustomization{
@@ -23,8 +30,15 @@ func TestFixKustomizationPostUnmarshalling(t *testing.T) {
APIVersion: KustomizationVersion, APIVersion: KustomizationVersion,
}, },
Resources: []string{"foo"}, Resources: []string{"foo"},
ConfigMapGenerator: []ConfigMapArgs{{GeneratorArgs{
KvPairSources: KvPairSources{
EnvSources: []string{"a", "b", "c"},
},
}}},
}
if !reflect.DeepEqual(k, expected) {
t.Fatalf("unexpected output: %v", k)
} }
if !fixKustomizationPostUnmarshallingCheck(&k, &expected) { if !fixKustomizationPostUnmarshallingCheck(&k, &expected) {
t.Fatalf("unexpected output: %v", k) t.Fatalf("unexpected output: %v", k)
} }

View File

@@ -28,4 +28,9 @@ type KvPairSources struct {
// or npm ".env" file or a ".ini" file // or npm ".env" file or a ".ini" file
// (wikipedia.org/wiki/INI_file) // (wikipedia.org/wiki/INI_file)
EnvSources []string `json:"envs,omitempty" yaml:"envs,omitempty"` EnvSources []string `json:"envs,omitempty" yaml:"envs,omitempty"`
// Older, singular form of EnvSources.
// On edits (e.g. `kustomize fix`) this is merged into the plural form
// for consistency with LiteralSources and FileSources.
EnvSource string `json:"env,omitempty" yaml:"env,omitempty"`
} }