@@ -22,7 +22,7 @@ func newCmdAddConfigMap(
22
22
) * cobra.Command {
23
23
var flags configmapSecretFlagsAndArgs
24
24
cmd := & cobra.Command {
25
- Use : "configmap NAME [--behavior={create|merge|replace}] [--from-file=[key=]source] [--from-literal=key1=value1]" ,
25
+ Use : "configmap NAME [--namespace=namespace-name] [-- behavior={create|merge|replace}] [--from-file=[key=]source] [--from-literal=key1=value1]" ,
26
26
Short : "Adds a configmap to the kustomization file" ,
27
27
Long : "" ,
28
28
Example : `
@@ -36,7 +36,10 @@ func newCmdAddConfigMap(
36
36
kustomize edit add configmap my-configmap --from-env-file=env/path.env
37
37
38
38
# Adds a configmap from env-file with behavior merge
39
- kustomize edit add configmap my-configmap --behavior=merge --from-env-file=env/path.env
39
+ kustomize edit add configmap my-configmap --behavior=merge --from-env-file=env/path.env
40
+
41
+ # Adds a configmap to the kustomization file with a specific namespace
42
+ kustomize edit add configmap my-configmap --namespace test-ns --from-literal=my-key=my-value
40
43
` ,
41
44
RunE : func (_ * cobra.Command , args []string ) error {
42
45
return runEditAddConfigMap (flags , fSys , args , ldr , rf )
@@ -62,16 +65,21 @@ func newCmdAddConfigMap(
62
65
"Specify the path to a file to read lines of key=val pairs to create a configmap (i.e. a Docker .env file)." )
63
66
cmd .Flags ().BoolVar (
64
67
& flags .DisableNameSuffixHash ,
65
- flagDisableNameSuffixHash ,
68
+ disableNameSuffixHashFlag ,
66
69
false ,
67
70
"Disable the name suffix for the configmap" )
68
71
cmd .Flags ().StringVar (
69
72
& flags .Behavior ,
70
- flagBehavior ,
73
+ behaviorFlag ,
71
74
"" ,
72
75
"Specify the behavior for config map generation, i.e whether to create a new configmap (the default), " +
73
76
"to merge with a previously defined one, or to replace an existing one. Merge and replace should be used only " +
74
77
" when overriding an existing configmap defined in a base" )
78
+ cmd .Flags ().StringVar (
79
+ & flags .Namespace ,
80
+ namespaceFlag ,
81
+ "" ,
82
+ "Specify the namespace of the ConfigMap" )
75
83
76
84
return cmd
77
85
}
@@ -128,7 +136,7 @@ func addConfigMap(
128
136
flags configmapSecretFlagsAndArgs ,
129
137
rf * resource.Factory ,
130
138
) error {
131
- args := findOrMakeConfigMapArgs (k , flags .Name )
139
+ args := findOrMakeConfigMapArgs (k , flags .Name , flags . Namespace )
132
140
mergeFlagsIntoGeneratorArgs (& args .GeneratorArgs , flags )
133
141
// Validate by trying to create corev1.configmap.
134
142
args .Options = types .MergeGlobalOptionsIntoLocal (
@@ -137,15 +145,15 @@ func addConfigMap(
137
145
return err
138
146
}
139
147
140
- func findOrMakeConfigMapArgs (m * types.Kustomization , name string ) * types.ConfigMapArgs {
148
+ func findOrMakeConfigMapArgs (m * types.Kustomization , name , namespace string ) * types.ConfigMapArgs {
141
149
for i , v := range m .ConfigMapGenerator {
142
- if name == v .Name {
150
+ if name == v .Name && namespace == v . Namespace {
143
151
return & m .ConfigMapGenerator [i ]
144
152
}
145
153
}
146
154
// config map not found, create new one and add it to the kustomization file.
147
155
cm := & types.ConfigMapArgs {
148
- GeneratorArgs : types.GeneratorArgs {Name : name },
156
+ GeneratorArgs : types.GeneratorArgs {Name : name , Namespace : namespace },
149
157
}
150
158
m .ConfigMapGenerator = append (m .ConfigMapGenerator , * cm )
151
159
return & m .ConfigMapGenerator [len (m .ConfigMapGenerator )- 1 ]
0 commit comments