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

@@ -155,7 +155,6 @@ type Kustomization struct {
// moving content of deprecated fields to newer
// fields.
func (k *Kustomization) FixKustomizationPostUnmarshalling() {
if k.Kind == "" {
k.Kind = KustomizationKind
}
@@ -168,6 +167,20 @@ func (k *Kustomization) FixKustomizationPostUnmarshalling() {
}
k.Resources = append(k.Resources, k.Bases...)
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

View File

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

View File

@@ -28,4 +28,9 @@ type KvPairSources struct {
// or npm ".env" file or a ".ini" file
// (wikipedia.org/wiki/INI_file)
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"`
}