DataSources is now common to Secrets and ConfigMaps.

This commit is contained in:
jregan
2019-01-22 18:57:11 -08:00
parent 244b3a2c59
commit d141b2421c
4 changed files with 55 additions and 38 deletions

View File

@@ -95,9 +95,11 @@ func TestConstructConfigMap(t *testing.T) {
{ {
description: "construct config map from env", description: "construct config map from env",
input: types.ConfigMapArgs{ input: types.ConfigMapArgs{
GeneratorArgs: types.GeneratorArgs{Name: "envConfigMap"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "envConfigMap",
EnvSource: "configmap/app.env", DataSources: types.DataSources{
EnvSource: "configmap/app.env",
},
}, },
}, },
options: nil, options: nil,
@@ -106,9 +108,11 @@ func TestConstructConfigMap(t *testing.T) {
{ {
description: "construct config map from file", description: "construct config map from file",
input: types.ConfigMapArgs{ input: types.ConfigMapArgs{
GeneratorArgs: types.GeneratorArgs{Name: "fileConfigMap"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "fileConfigMap",
FileSources: []string{"configmap/app-init.ini", "configmap/app.bin"}, DataSources: types.DataSources{
FileSources: []string{"configmap/app-init.ini", "configmap/app.bin"},
},
}, },
}, },
options: nil, options: nil,
@@ -117,9 +121,11 @@ func TestConstructConfigMap(t *testing.T) {
{ {
description: "construct config map from literal", description: "construct config map from literal",
input: types.ConfigMapArgs{ input: types.ConfigMapArgs{
GeneratorArgs: types.GeneratorArgs{Name: "literalConfigMap"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "literalConfigMap",
LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"}, DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"},
},
}, },
}, },
options: &types.GeneratorOptions{ options: &types.GeneratorOptions{

View File

@@ -93,9 +93,11 @@ func TestConstructSecret(t *testing.T) {
{ {
description: "construct secret from env", description: "construct secret from env",
input: types.SecretArgs{ input: types.SecretArgs{
GeneratorArgs: types.GeneratorArgs{Name: "envSecret"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "envSecret",
EnvSource: "secret/app.env", DataSources: types.DataSources{
EnvSource: "secret/app.env",
},
}, },
}, },
options: nil, options: nil,
@@ -104,9 +106,11 @@ func TestConstructSecret(t *testing.T) {
{ {
description: "construct secret from file", description: "construct secret from file",
input: types.SecretArgs{ input: types.SecretArgs{
GeneratorArgs: types.GeneratorArgs{Name: "fileSecret"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "fileSecret",
FileSources: []string{"secret/app-init.ini"}, DataSources: types.DataSources{
FileSources: []string{"secret/app-init.ini"},
},
}, },
}, },
options: nil, options: nil,
@@ -115,9 +119,11 @@ func TestConstructSecret(t *testing.T) {
{ {
description: "construct secret from literal", description: "construct secret from literal",
input: types.SecretArgs{ input: types.SecretArgs{
GeneratorArgs: types.GeneratorArgs{Name: "literalSecret"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "literalSecret",
LiteralSources: []string{"a=x", "b=y"}, DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y"},
},
}, },
}, },
options: &types.GeneratorOptions{ options: &types.GeneratorOptions{

View File

@@ -151,9 +151,11 @@ func TestNewFromConfigMaps(t *testing.T) {
description: "construct config map from env", description: "construct config map from env",
input: []types.ConfigMapArgs{ input: []types.ConfigMapArgs{
{ {
GeneratorArgs: types.GeneratorArgs{Name: "envConfigMap"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "envConfigMap",
EnvSource: "app.env", DataSources: types.DataSources{
EnvSource: "app.env",
},
}, },
}, },
}, },
@@ -177,9 +179,11 @@ func TestNewFromConfigMaps(t *testing.T) {
{ {
description: "construct config map from file", description: "construct config map from file",
input: []types.ConfigMapArgs{{ input: []types.ConfigMapArgs{{
GeneratorArgs: types.GeneratorArgs{Name: "fileConfigMap"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "fileConfigMap",
FileSources: []string{"app-init.ini"}, DataSources: types.DataSources{
FileSources: []string{"app-init.ini"},
},
}, },
}, },
}, },
@@ -205,9 +209,11 @@ BAR=baz
description: "construct config map from literal", description: "construct config map from literal",
input: []types.ConfigMapArgs{ input: []types.ConfigMapArgs{
{ {
GeneratorArgs: types.GeneratorArgs{Name: "literalConfigMap"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "literalConfigMap",
LiteralSources: []string{"a=x", "b=y", "c=\"Good Morning\"", "d=\"false\""}, DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y", "c=\"Good Morning\"", "d=\"false\""},
},
}, },
}, },
}, },
@@ -251,11 +257,13 @@ var secret = gvk.Gvk{Version: "v1", Kind: "Secret"}
func TestNewResMapFromSecretArgs(t *testing.T) { func TestNewResMapFromSecretArgs(t *testing.T) {
secrets := []types.SecretArgs{ secrets := []types.SecretArgs{
{ {
GeneratorArgs: types.GeneratorArgs{Name: "apple"}, GeneratorArgs: types.GeneratorArgs{
DataSources: types.DataSources{ Name: "apple",
LiteralSources: []string{ DataSources: types.DataSources{
"DB_USERNAME=admin", LiteralSources: []string{
"DB_PASSWORD=somepw", "DB_USERNAME=admin",
"DB_PASSWORD=somepw",
},
}, },
}, },
Type: ifc.SecretTypeOpaque, Type: ifc.SecretTypeOpaque,

View File

@@ -206,15 +206,15 @@ type GeneratorArgs struct {
// 'replace': replace the existing one // 'replace': replace the existing one
// 'merge': merge with the existing one // 'merge': merge with the existing one
Behavior string `json:"behavior,omitempty" yaml:"behavior,omitempty"` Behavior string `json:"behavior,omitempty" yaml:"behavior,omitempty"`
// DataSources for the generator.
DataSources `json:",inline,omitempty" yaml:",inline,omitempty"`
} }
// ConfigMapArgs contains the metadata of how to generate a configmap. // ConfigMapArgs contains the metadata of how to generate a configmap.
type ConfigMapArgs struct { type ConfigMapArgs struct {
// GeneratorArgs for the configmap. // GeneratorArgs for the configmap.
GeneratorArgs `json:",inline,omitempty" yaml:",inline,omitempty"` GeneratorArgs `json:",inline,omitempty" yaml:",inline,omitempty"`
// DataSources for configmap.
DataSources `json:",inline,omitempty" yaml:",inline,omitempty"`
} }
// SecretArgs contains the metadata of how to generate a secret. // SecretArgs contains the metadata of how to generate a secret.
@@ -230,9 +230,6 @@ type SecretArgs struct {
// If type is "kubernetes.io/tls", then "literals" or "files" must have exactly two // If type is "kubernetes.io/tls", then "literals" or "files" must have exactly two
// keys: "tls.key" and "tls.crt" // keys: "tls.key" and "tls.crt"
Type string `json:"type,omitempty" yaml:"type,omitempty"` Type string `json:"type,omitempty" yaml:"type,omitempty"`
// DataSources for secret.
DataSources `json:",inline,omitempty" yaml:",inline,omitempty"`
} }
// DataSources contains some generic sources for configmaps. // DataSources contains some generic sources for configmaps.