Skip to content

Commit d141b24

Browse files
committed
DataSources is now common to Secrets and ConfigMaps.
1 parent 244b3a2 commit d141b24

File tree

4 files changed

+55
-38
lines changed

4 files changed

+55
-38
lines changed

k8sdeps/configmapandsecret/configmapfactory_test.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ func TestConstructConfigMap(t *testing.T) {
9595
{
9696
description: "construct config map from env",
9797
input: types.ConfigMapArgs{
98-
GeneratorArgs: types.GeneratorArgs{Name: "envConfigMap"},
99-
DataSources: types.DataSources{
100-
EnvSource: "configmap/app.env",
98+
GeneratorArgs: types.GeneratorArgs{
99+
Name: "envConfigMap",
100+
DataSources: types.DataSources{
101+
EnvSource: "configmap/app.env",
102+
},
101103
},
102104
},
103105
options: nil,
@@ -106,9 +108,11 @@ func TestConstructConfigMap(t *testing.T) {
106108
{
107109
description: "construct config map from file",
108110
input: types.ConfigMapArgs{
109-
GeneratorArgs: types.GeneratorArgs{Name: "fileConfigMap"},
110-
DataSources: types.DataSources{
111-
FileSources: []string{"configmap/app-init.ini", "configmap/app.bin"},
111+
GeneratorArgs: types.GeneratorArgs{
112+
Name: "fileConfigMap",
113+
DataSources: types.DataSources{
114+
FileSources: []string{"configmap/app-init.ini", "configmap/app.bin"},
115+
},
112116
},
113117
},
114118
options: nil,
@@ -117,9 +121,11 @@ func TestConstructConfigMap(t *testing.T) {
117121
{
118122
description: "construct config map from literal",
119123
input: types.ConfigMapArgs{
120-
GeneratorArgs: types.GeneratorArgs{Name: "literalConfigMap"},
121-
DataSources: types.DataSources{
122-
LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"},
124+
GeneratorArgs: types.GeneratorArgs{
125+
Name: "literalConfigMap",
126+
DataSources: types.DataSources{
127+
LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"},
128+
},
123129
},
124130
},
125131
options: &types.GeneratorOptions{

k8sdeps/configmapandsecret/secretfactory_test.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ func TestConstructSecret(t *testing.T) {
9393
{
9494
description: "construct secret from env",
9595
input: types.SecretArgs{
96-
GeneratorArgs: types.GeneratorArgs{Name: "envSecret"},
97-
DataSources: types.DataSources{
98-
EnvSource: "secret/app.env",
96+
GeneratorArgs: types.GeneratorArgs{
97+
Name: "envSecret",
98+
DataSources: types.DataSources{
99+
EnvSource: "secret/app.env",
100+
},
99101
},
100102
},
101103
options: nil,
@@ -104,9 +106,11 @@ func TestConstructSecret(t *testing.T) {
104106
{
105107
description: "construct secret from file",
106108
input: types.SecretArgs{
107-
GeneratorArgs: types.GeneratorArgs{Name: "fileSecret"},
108-
DataSources: types.DataSources{
109-
FileSources: []string{"secret/app-init.ini"},
109+
GeneratorArgs: types.GeneratorArgs{
110+
Name: "fileSecret",
111+
DataSources: types.DataSources{
112+
FileSources: []string{"secret/app-init.ini"},
113+
},
110114
},
111115
},
112116
options: nil,
@@ -115,9 +119,11 @@ func TestConstructSecret(t *testing.T) {
115119
{
116120
description: "construct secret from literal",
117121
input: types.SecretArgs{
118-
GeneratorArgs: types.GeneratorArgs{Name: "literalSecret"},
119-
DataSources: types.DataSources{
120-
LiteralSources: []string{"a=x", "b=y"},
122+
GeneratorArgs: types.GeneratorArgs{
123+
Name: "literalSecret",
124+
DataSources: types.DataSources{
125+
LiteralSources: []string{"a=x", "b=y"},
126+
},
121127
},
122128
},
123129
options: &types.GeneratorOptions{

pkg/resmap/factory_test.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ func TestNewFromConfigMaps(t *testing.T) {
151151
description: "construct config map from env",
152152
input: []types.ConfigMapArgs{
153153
{
154-
GeneratorArgs: types.GeneratorArgs{Name: "envConfigMap"},
155-
DataSources: types.DataSources{
156-
EnvSource: "app.env",
154+
GeneratorArgs: types.GeneratorArgs{
155+
Name: "envConfigMap",
156+
DataSources: types.DataSources{
157+
EnvSource: "app.env",
158+
},
157159
},
158160
},
159161
},
@@ -177,9 +179,11 @@ func TestNewFromConfigMaps(t *testing.T) {
177179
{
178180
description: "construct config map from file",
179181
input: []types.ConfigMapArgs{{
180-
GeneratorArgs: types.GeneratorArgs{Name: "fileConfigMap"},
181-
DataSources: types.DataSources{
182-
FileSources: []string{"app-init.ini"},
182+
GeneratorArgs: types.GeneratorArgs{
183+
Name: "fileConfigMap",
184+
DataSources: types.DataSources{
185+
FileSources: []string{"app-init.ini"},
186+
},
183187
},
184188
},
185189
},
@@ -205,9 +209,11 @@ BAR=baz
205209
description: "construct config map from literal",
206210
input: []types.ConfigMapArgs{
207211
{
208-
GeneratorArgs: types.GeneratorArgs{Name: "literalConfigMap"},
209-
DataSources: types.DataSources{
210-
LiteralSources: []string{"a=x", "b=y", "c=\"Good Morning\"", "d=\"false\""},
212+
GeneratorArgs: types.GeneratorArgs{
213+
Name: "literalConfigMap",
214+
DataSources: types.DataSources{
215+
LiteralSources: []string{"a=x", "b=y", "c=\"Good Morning\"", "d=\"false\""},
216+
},
211217
},
212218
},
213219
},
@@ -251,11 +257,13 @@ var secret = gvk.Gvk{Version: "v1", Kind: "Secret"}
251257
func TestNewResMapFromSecretArgs(t *testing.T) {
252258
secrets := []types.SecretArgs{
253259
{
254-
GeneratorArgs: types.GeneratorArgs{Name: "apple"},
255-
DataSources: types.DataSources{
256-
LiteralSources: []string{
257-
"DB_USERNAME=admin",
258-
"DB_PASSWORD=somepw",
260+
GeneratorArgs: types.GeneratorArgs{
261+
Name: "apple",
262+
DataSources: types.DataSources{
263+
LiteralSources: []string{
264+
"DB_USERNAME=admin",
265+
"DB_PASSWORD=somepw",
266+
},
259267
},
260268
},
261269
Type: ifc.SecretTypeOpaque,

pkg/types/kustomization.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ type GeneratorArgs struct {
206206
// 'replace': replace the existing one
207207
// 'merge': merge with the existing one
208208
Behavior string `json:"behavior,omitempty" yaml:"behavior,omitempty"`
209+
210+
// DataSources for the generator.
211+
DataSources `json:",inline,omitempty" yaml:",inline,omitempty"`
209212
}
210213

211214
// ConfigMapArgs contains the metadata of how to generate a configmap.
212215
type ConfigMapArgs struct {
213216
// GeneratorArgs for the configmap.
214217
GeneratorArgs `json:",inline,omitempty" yaml:",inline,omitempty"`
215-
216-
// DataSources for configmap.
217-
DataSources `json:",inline,omitempty" yaml:",inline,omitempty"`
218218
}
219219

220220
// SecretArgs contains the metadata of how to generate a secret.
@@ -230,9 +230,6 @@ type SecretArgs struct {
230230
// If type is "kubernetes.io/tls", then "literals" or "files" must have exactly two
231231
// keys: "tls.key" and "tls.crt"
232232
Type string `json:"type,omitempty" yaml:"type,omitempty"`
233-
234-
// DataSources for secret.
235-
DataSources `json:",inline,omitempty" yaml:",inline,omitempty"`
236233
}
237234

238235
// DataSources contains some generic sources for configmaps.

0 commit comments

Comments
 (0)