Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataSources is now common to Secrets and ConfigMaps. #714

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions k8sdeps/configmapandsecret/configmapfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ func TestConstructConfigMap(t *testing.T) {
{
description: "construct config map from env",
input: types.ConfigMapArgs{
GeneratorArgs: types.GeneratorArgs{Name: "envConfigMap"},
DataSources: types.DataSources{
EnvSource: "configmap/app.env",
GeneratorArgs: types.GeneratorArgs{
Name: "envConfigMap",
DataSources: types.DataSources{
EnvSource: "configmap/app.env",
},
},
},
options: nil,
Expand All @@ -106,9 +108,11 @@ func TestConstructConfigMap(t *testing.T) {
{
description: "construct config map from file",
input: types.ConfigMapArgs{
GeneratorArgs: types.GeneratorArgs{Name: "fileConfigMap"},
DataSources: types.DataSources{
FileSources: []string{"configmap/app-init.ini", "configmap/app.bin"},
GeneratorArgs: types.GeneratorArgs{
Name: "fileConfigMap",
DataSources: types.DataSources{
FileSources: []string{"configmap/app-init.ini", "configmap/app.bin"},
},
},
},
options: nil,
Expand All @@ -117,9 +121,11 @@ func TestConstructConfigMap(t *testing.T) {
{
description: "construct config map from literal",
input: types.ConfigMapArgs{
GeneratorArgs: types.GeneratorArgs{Name: "literalConfigMap"},
DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"},
GeneratorArgs: types.GeneratorArgs{
Name: "literalConfigMap",
DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"},
},
},
},
options: &types.GeneratorOptions{
Expand Down
24 changes: 15 additions & 9 deletions k8sdeps/configmapandsecret/secretfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ func TestConstructSecret(t *testing.T) {
{
description: "construct secret from env",
input: types.SecretArgs{
GeneratorArgs: types.GeneratorArgs{Name: "envSecret"},
DataSources: types.DataSources{
EnvSource: "secret/app.env",
GeneratorArgs: types.GeneratorArgs{
Name: "envSecret",
DataSources: types.DataSources{
EnvSource: "secret/app.env",
},
},
},
options: nil,
Expand All @@ -104,9 +106,11 @@ func TestConstructSecret(t *testing.T) {
{
description: "construct secret from file",
input: types.SecretArgs{
GeneratorArgs: types.GeneratorArgs{Name: "fileSecret"},
DataSources: types.DataSources{
FileSources: []string{"secret/app-init.ini"},
GeneratorArgs: types.GeneratorArgs{
Name: "fileSecret",
DataSources: types.DataSources{
FileSources: []string{"secret/app-init.ini"},
},
},
},
options: nil,
Expand All @@ -115,9 +119,11 @@ func TestConstructSecret(t *testing.T) {
{
description: "construct secret from literal",
input: types.SecretArgs{
GeneratorArgs: types.GeneratorArgs{Name: "literalSecret"},
DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y"},
GeneratorArgs: types.GeneratorArgs{
Name: "literalSecret",
DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y"},
},
},
},
options: &types.GeneratorOptions{
Expand Down
36 changes: 22 additions & 14 deletions pkg/resmap/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ func TestNewFromConfigMaps(t *testing.T) {
description: "construct config map from env",
input: []types.ConfigMapArgs{
{
GeneratorArgs: types.GeneratorArgs{Name: "envConfigMap"},
DataSources: types.DataSources{
EnvSource: "app.env",
GeneratorArgs: types.GeneratorArgs{
Name: "envConfigMap",
DataSources: types.DataSources{
EnvSource: "app.env",
},
},
},
},
Expand All @@ -177,9 +179,11 @@ func TestNewFromConfigMaps(t *testing.T) {
{
description: "construct config map from file",
input: []types.ConfigMapArgs{{
GeneratorArgs: types.GeneratorArgs{Name: "fileConfigMap"},
DataSources: types.DataSources{
FileSources: []string{"app-init.ini"},
GeneratorArgs: types.GeneratorArgs{
Name: "fileConfigMap",
DataSources: types.DataSources{
FileSources: []string{"app-init.ini"},
},
},
},
},
Expand All @@ -205,9 +209,11 @@ BAR=baz
description: "construct config map from literal",
input: []types.ConfigMapArgs{
{
GeneratorArgs: types.GeneratorArgs{Name: "literalConfigMap"},
DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y", "c=\"Good Morning\"", "d=\"false\""},
GeneratorArgs: types.GeneratorArgs{
Name: "literalConfigMap",
DataSources: types.DataSources{
LiteralSources: []string{"a=x", "b=y", "c=\"Good Morning\"", "d=\"false\""},
},
},
},
},
Expand Down Expand Up @@ -251,11 +257,13 @@ var secret = gvk.Gvk{Version: "v1", Kind: "Secret"}
func TestNewResMapFromSecretArgs(t *testing.T) {
secrets := []types.SecretArgs{
{
GeneratorArgs: types.GeneratorArgs{Name: "apple"},
DataSources: types.DataSources{
LiteralSources: []string{
"DB_USERNAME=admin",
"DB_PASSWORD=somepw",
GeneratorArgs: types.GeneratorArgs{
Name: "apple",
DataSources: types.DataSources{
LiteralSources: []string{
"DB_USERNAME=admin",
"DB_PASSWORD=somepw",
},
},
},
Type: ifc.SecretTypeOpaque,
Expand Down
9 changes: 3 additions & 6 deletions pkg/types/kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ type GeneratorArgs struct {
// 'replace': replace the existing one
// 'merge': merge with the existing one
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.
type ConfigMapArgs struct {
// GeneratorArgs for the configmap.
GeneratorArgs `json:",inline,omitempty" yaml:",inline,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, I prefer this PR to a PR that does an even stronger coupling:

type SecretArgs {
  ConfigMapArgs
  Type string
}

but might change my mind.

The current PR draws a stronger distinction between the two types, for what that's worth,
leaving an obvious opening as to how they could further differ.

Maybe that option isn't worth much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the option for them to further differ. I'm really hoping we can find a way to get secret generation back in a way that is compatible with kubectl


// DataSources for configmap.
DataSources `json:",inline,omitempty" yaml:",inline,omitempty"`
}

// SecretArgs contains the metadata of how to generate a secret.
Expand All @@ -230,9 +230,6 @@ type SecretArgs struct {
// If type is "kubernetes.io/tls", then "literals" or "files" must have exactly two
// keys: "tls.key" and "tls.crt"
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.
Expand Down