diff --git a/k8sdeps/configmapandsecret/configmapfactory_test.go b/k8sdeps/configmapandsecret/configmapfactory_test.go index 15f86c6aa..b3914f5ad 100644 --- a/k8sdeps/configmapandsecret/configmapfactory_test.go +++ b/k8sdeps/configmapandsecret/configmapfactory_test.go @@ -92,7 +92,7 @@ func TestConstructConfigMap(t *testing.T) { { description: "construct config map from env", input: types.ConfigMapArgs{ - Name: "envConfigMap", + GeneratorArgs: types.GeneratorArgs{Name: "envConfigMap"}, DataSources: types.DataSources{ EnvSource: "configmap/app.env", }, @@ -103,7 +103,7 @@ func TestConstructConfigMap(t *testing.T) { { description: "construct config map from file", input: types.ConfigMapArgs{ - Name: "fileConfigMap", + GeneratorArgs: types.GeneratorArgs{Name: "fileConfigMap"}, DataSources: types.DataSources{ FileSources: []string{"configmap/app-init.ini"}, }, @@ -114,7 +114,7 @@ func TestConstructConfigMap(t *testing.T) { { description: "construct config map from literal", input: types.ConfigMapArgs{ - Name: "literalConfigMap", + GeneratorArgs: types.GeneratorArgs{Name: "literalConfigMap"}, DataSources: types.DataSources{ LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"}, }, diff --git a/pkg/commands/edit/add/configmap.go b/pkg/commands/edit/add/configmap.go index 6a5ace43a..7fc93518f 100644 --- a/pkg/commands/edit/add/configmap.go +++ b/pkg/commands/edit/add/configmap.go @@ -125,7 +125,7 @@ func makeConfigMapArgs(m *types.Kustomization, name string) *types.ConfigMapArgs } } // config map not found, create new one and add it to the kustomization file. - cm := &types.ConfigMapArgs{Name: name} + cm := &types.ConfigMapArgs{GeneratorArgs: types.GeneratorArgs{Name: name}} m.ConfigMapGenerator = append(m.ConfigMapGenerator, *cm) return &m.ConfigMapGenerator[len(m.ConfigMapGenerator)-1] } diff --git a/pkg/resmap/factory_test.go b/pkg/resmap/factory_test.go index 36805c017..5d41548eb 100644 --- a/pkg/resmap/factory_test.go +++ b/pkg/resmap/factory_test.go @@ -151,7 +151,7 @@ func TestNewFromConfigMaps(t *testing.T) { description: "construct config map from env", input: []types.ConfigMapArgs{ { - Name: "envConfigMap", + GeneratorArgs: types.GeneratorArgs{Name: "envConfigMap"}, DataSources: types.DataSources{ EnvSource: "app.env", }, @@ -177,7 +177,7 @@ func TestNewFromConfigMaps(t *testing.T) { { description: "construct config map from file", input: []types.ConfigMapArgs{{ - Name: "fileConfigMap", + GeneratorArgs: types.GeneratorArgs{Name: "fileConfigMap"}, DataSources: types.DataSources{ FileSources: []string{"app-init.ini"}, }, @@ -205,7 +205,7 @@ BAR=baz description: "construct config map from literal", input: []types.ConfigMapArgs{ { - Name: "literalConfigMap", + GeneratorArgs: types.GeneratorArgs{Name: "literalConfigMap"}, DataSources: types.DataSources{ LiteralSources: []string{"a=x", "b=y", "c=\"Good Morning\"", "d=\"false\""}, }, @@ -251,7 +251,7 @@ var secret = gvk.Gvk{Version: "v1", Kind: "Secret"} func TestNewResMapFromSecretArgs(t *testing.T) { secrets := []types.SecretArgs{ { - Name: "apple", + GeneratorArgs: types.GeneratorArgs{Name: "apple"}, CommandSources: types.CommandSources{ Commands: map[string]string{ "DB_USERNAME": "printf admin", @@ -261,7 +261,7 @@ func TestNewResMapFromSecretArgs(t *testing.T) { Type: ifc.SecretTypeOpaque, }, { - Name: "peanuts", + GeneratorArgs: types.GeneratorArgs{Name: "peanuts"}, CommandSources: types.CommandSources{ EnvCommand: "printf \"DB_USERNAME=admin\nDB_PASSWORD=somepw\"", }, @@ -314,7 +314,7 @@ func TestSecretTimeout(t *testing.T) { timeout := int64(1) secrets := []types.SecretArgs{ { - Name: "slow", + GeneratorArgs: types.GeneratorArgs{Name: "slow"}, TimeoutSeconds: &timeout, CommandSources: types.CommandSources{ Commands: map[string]string{ diff --git a/pkg/types/kustomization.go b/pkg/types/kustomization.go index 8591ced4f..e1badbc6d 100644 --- a/pkg/types/kustomization.go +++ b/pkg/types/kustomization.go @@ -146,21 +146,27 @@ func (k *Kustomization) DealWithDeprecatedFields() { } } -// ConfigMapArgs contains the metadata of how to generate a configmap. -type ConfigMapArgs struct { - // Name of the configmap. - // The full name should be Kustomization.NamePrefix + Configmap.Name + - // hash(content of configmap). - Name string `json:"name,omitempty" yaml:"name,omitempty"` - +// GeneratorArgs contains arguments common to generators. +type GeneratorArgs struct { // Namespace for the configmap, optional Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"` - // behavior of configmap, must be one of create, merge and replace - // 'create': create a new one; - // 'replace': replace the existing one; - // 'merge': merge the existing one. + // Name - actually the partial name - of the generated resource. + // The full name ends up being something like + // NamePrefix + this.Name + hash(content of generated resource). + Name string `json:"name,omitempty" yaml:"name,omitempty"` + + // Behavior of generated resource, must be one of: + // 'create': create a new one + // 'replace': replace the existing one + // 'merge': merge with the existing one Behavior string `json:"behavior,omitempty" yaml:"behavior,omitempty"` +} + +// ConfigMapArgs contains the metadata of how to generate a configmap. +type ConfigMapArgs struct { + // GeneratorArgs for the configmap. + GeneratorArgs `json:",inline,omitempty" yaml:",inline,omitempty"` // DataSources for configmap. DataSources `json:",inline,omitempty" yaml:",inline,omitempty"` @@ -168,19 +174,8 @@ type ConfigMapArgs struct { // SecretArgs contains the metadata of how to generate a secret. type SecretArgs struct { - // Name of the secret. - // The full name should be Kustomization.NamePrefix + SecretGenerator.Name + - // hash(content of secret). - Name string `json:"name,omitempty" yaml:"name,omitempty"` - - // Namespace for the secret, optional - Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"` - - // behavior of secretGenerator, must be one of create, merge and replace - // 'create': create a new one; - // 'replace': replace the existing one; - // 'merge': merge the existing one. - Behavior string `json:"behavior,omitempty" yaml:"behavior,omitempty"` + // GeneratorArgs for the secret. + GeneratorArgs `json:",inline,omitempty" yaml:",inline,omitempty"` // Type of the secret. //