@@ -14,9 +14,8 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- // Package app implements state for the set of all resources being customized.
18
- // Should rename this - there's nothing "app"y about it.
19
- package app
17
+ // Package target implements state for the set of all resources being customized.
18
+ package target
20
19
21
20
import (
22
21
"bytes"
@@ -42,19 +41,18 @@ import (
42
41
"sigs.k8s.io/kustomize/pkg/types"
43
42
)
44
43
45
- // Application implements the guts of the kustomize 'build' command.
46
- // TODO: Change name, as "application" is overloaded and somewhat
47
- // misleading (one can customize an RBAC policy). Perhaps "Target"
48
- // https://github.com/kubernetes-sigs/kustomize/blob/master/docs/glossary.md#target
49
- type Application struct {
44
+ // KustTarget encapsulates the entirety of a kustomization build.
45
+ type KustTarget struct {
50
46
kustomization * types.Kustomization
51
47
ldr loader.Loader
52
48
fSys fs.FileSystem
53
49
tcfg * transformerconfig.TransformerConfig
54
50
}
55
51
56
- // NewApplication returns a new instance of Application primed with a Loader.
57
- func NewApplication (ldr loader.Loader , fSys fs.FileSystem , tcfg * transformerconfig.TransformerConfig ) (* Application , error ) {
52
+ // NewKustTarget returns a new instance of KustTarget primed with a Loader.
53
+ func NewKustTarget (
54
+ ldr loader.Loader , fSys fs.FileSystem ,
55
+ tcfg * transformerconfig.TransformerConfig ) (* KustTarget , error ) {
58
56
content , err := ldr .Load (constants .KustomizationFileName )
59
57
if err != nil {
60
58
return nil , err
@@ -65,7 +63,7 @@ func NewApplication(ldr loader.Loader, fSys fs.FileSystem, tcfg *transformerconf
65
63
if err != nil {
66
64
return nil , err
67
65
}
68
- return & Application {
66
+ return & KustTarget {
69
67
kustomization : & m ,
70
68
ldr : ldr ,
71
69
fSys : fSys ,
@@ -86,33 +84,33 @@ func unmarshal(y []byte, o interface{}) error {
86
84
87
85
// MakeCustomizedResMap creates a ResMap per kustomization instructions.
88
86
// The Resources in the returned ResMap are fully customized.
89
- func (a * Application ) MakeCustomizedResMap () (resmap.ResMap , error ) {
90
- m , err := a .loadCustomizedResMap ()
87
+ func (kt * KustTarget ) MakeCustomizedResMap () (resmap.ResMap , error ) {
88
+ m , err := kt .loadCustomizedResMap ()
91
89
if err != nil {
92
90
return nil , err
93
91
}
94
- return a .resolveRefsToGeneratedResources (m )
92
+ return kt .resolveRefsToGeneratedResources (m )
95
93
}
96
94
97
95
// resolveRefsToGeneratedResources fixes all name references.
98
- func (a * Application ) resolveRefsToGeneratedResources (m resmap.ResMap ) (resmap.ResMap , error ) {
96
+ func (kt * KustTarget ) resolveRefsToGeneratedResources (m resmap.ResMap ) (resmap.ResMap , error ) {
99
97
err := transformers .NewNameHashTransformer ().Transform (m )
100
98
if err != nil {
101
99
return nil , err
102
100
}
103
101
104
102
var r []transformers.Transformer
105
- t , err := transformers .NewNameReferenceTransformer (a .tcfg .NameReference )
103
+ t , err := transformers .NewNameReferenceTransformer (kt .tcfg .NameReference )
106
104
if err != nil {
107
105
return nil , err
108
106
}
109
107
r = append (r , t )
110
108
111
- refVars , err := a .resolveRefVars (m )
109
+ refVars , err := kt .resolveRefVars (m )
112
110
if err != nil {
113
111
return nil , err
114
112
}
115
- t = transformers .NewRefVarTransformer (refVars , a .tcfg .VarReference )
113
+ t = transformers .NewRefVarTransformer (refVars , kt .tcfg .VarReference )
116
114
r = append (r , t )
117
115
118
116
err = transformers .NewMultiTransformer (r ).Transform (m )
@@ -123,26 +121,26 @@ func (a *Application) resolveRefsToGeneratedResources(m resmap.ResMap) (resmap.R
123
121
}
124
122
125
123
// loadCustomizedResMap loads and customizes resources to build a ResMap.
126
- func (a * Application ) loadCustomizedResMap () (resmap.ResMap , error ) {
124
+ func (kt * KustTarget ) loadCustomizedResMap () (resmap.ResMap , error ) {
127
125
errs := & interror.KustomizationErrors {}
128
- result , err := a .loadResMapFromBasesAndResources ()
126
+ result , err := kt .loadResMapFromBasesAndResources ()
129
127
if err != nil {
130
128
errs .Append (errors .Wrap (err , "loadResMapFromBasesAndResources" ))
131
129
}
132
- crdPathConfigs , err := crds .RegisterCRDs (a .ldr , a .kustomization .Crds )
133
- a .tcfg = a .tcfg .Merge (crdPathConfigs )
130
+ crdPathConfigs , err := crds .RegisterCRDs (kt .ldr , kt .kustomization .Crds )
131
+ kt .tcfg = kt .tcfg .Merge (crdPathConfigs )
134
132
if err != nil {
135
133
errs .Append (errors .Wrap (err , "RegisterCRDs" ))
136
134
}
137
135
cms , err := resmap .NewResMapFromConfigMapArgs (
138
- configmapandsecret .NewConfigMapFactory (a .fSys , a .ldr ),
139
- a .kustomization .ConfigMapGenerator )
136
+ configmapandsecret .NewConfigMapFactory (kt .fSys , kt .ldr ),
137
+ kt .kustomization .ConfigMapGenerator )
140
138
if err != nil {
141
139
errs .Append (errors .Wrap (err , "NewResMapFromConfigMapArgs" ))
142
140
}
143
141
secrets , err := resmap .NewResMapFromSecretArgs (
144
- configmapandsecret .NewSecretFactory (a .fSys , a .ldr .Root ()),
145
- a .kustomization .SecretGenerator )
142
+ configmapandsecret .NewSecretFactory (kt .fSys , kt .ldr .Root ()),
143
+ kt .kustomization .SecretGenerator )
146
144
if err != nil {
147
145
errs .Append (errors .Wrap (err , "NewResMapFromSecretArgs" ))
148
146
}
@@ -156,8 +154,11 @@ func (a *Application) loadCustomizedResMap() (resmap.ResMap, error) {
156
154
return nil , err
157
155
}
158
156
159
- a .kustomization .PatchesStrategicMerge = patch .Append (a .kustomization .PatchesStrategicMerge , a .kustomization .Patches ... )
160
- patches , err := resmap .NewResourceSliceFromPatches (a .ldr , a .kustomization .PatchesStrategicMerge )
157
+ kt .kustomization .PatchesStrategicMerge = patch .Append (
158
+ kt .kustomization .PatchesStrategicMerge ,
159
+ kt .kustomization .Patches ... )
160
+ patches , err := resmap .NewResourceSliceFromPatches (
161
+ kt .ldr , kt .kustomization .PatchesStrategicMerge )
161
162
if err != nil {
162
163
errs .Append (errors .Wrap (err , "NewResourceSliceFromPatches" ))
163
164
}
@@ -167,17 +168,18 @@ func (a *Application) loadCustomizedResMap() (resmap.ResMap, error) {
167
168
}
168
169
169
170
var r []transformers.Transformer
170
- t , err := a .newTransformer (patches )
171
+ t , err := kt .newTransformer (patches )
171
172
if err != nil {
172
173
return nil , err
173
174
}
174
175
r = append (r , t )
175
- t , err = patchtransformer .NewPatchJson6902Factory (a .ldr ).MakePatchJson6902Transformer (a .kustomization .PatchesJson6902 )
176
+ t , err = patchtransformer .NewPatchJson6902Factory (kt .ldr ).
177
+ MakePatchJson6902Transformer (kt .kustomization .PatchesJson6902 )
176
178
if err != nil {
177
179
return nil , err
178
180
}
179
181
r = append (r , t )
180
- t , err = transformers .NewImageTagTransformer (a .kustomization .ImageTags )
182
+ t , err = transformers .NewImageTagTransformer (kt .kustomization .ImageTags )
181
183
if err != nil {
182
184
return nil , err
183
185
}
@@ -191,9 +193,9 @@ func (a *Application) loadCustomizedResMap() (resmap.ResMap, error) {
191
193
}
192
194
193
195
// Gets Bases and Resources as advertised.
194
- func (a * Application ) loadResMapFromBasesAndResources () (resmap.ResMap , error ) {
195
- bases , errs := a .loadCustomizedBases ()
196
- resources , err := resmap .NewResMapFromFiles (a .ldr , a .kustomization .Resources )
196
+ func (kt * KustTarget ) loadResMapFromBasesAndResources () (resmap.ResMap , error ) {
197
+ bases , errs := kt .loadCustomizedBases ()
198
+ resources , err := resmap .NewResMapFromFiles (kt .ldr , kt .kustomization .Resources )
197
199
if err != nil {
198
200
errs .Append (errors .Wrap (err , "rawResources failed to read Resources" ))
199
201
}
@@ -205,21 +207,21 @@ func (a *Application) loadResMapFromBasesAndResources() (resmap.ResMap, error) {
205
207
206
208
// Loop through the Bases of this kustomization recursively loading resources.
207
209
// Combine into one ResMap, demanding unique Ids for each resource.
208
- func (a * Application ) loadCustomizedBases () (resmap.ResMap , * interror.KustomizationErrors ) {
210
+ func (kt * KustTarget ) loadCustomizedBases () (resmap.ResMap , * interror.KustomizationErrors ) {
209
211
var list []resmap.ResMap
210
212
errs := & interror.KustomizationErrors {}
211
- for _ , path := range a .kustomization .Bases {
212
- ldr , err := a .ldr .New (path )
213
+ for _ , path := range kt .kustomization .Bases {
214
+ ldr , err := kt .ldr .New (path )
213
215
if err != nil {
214
216
errs .Append (errors .Wrap (err , "couldn't make ldr for " + path ))
215
217
continue
216
218
}
217
- app , err := NewApplication (ldr , a .fSys , a .tcfg )
219
+ target , err := NewKustTarget (ldr , kt .fSys , kt .tcfg )
218
220
if err != nil {
219
- errs .Append (errors .Wrap (err , "couldn't make app for " + path ))
221
+ errs .Append (errors .Wrap (err , "couldn't make target for " + path ))
220
222
continue
221
223
}
222
- resMap , err := app .loadCustomizedResMap ()
224
+ resMap , err := target .loadCustomizedResMap ()
223
225
if err != nil {
224
226
errs .Append (errors .Wrap (err , "SemiResources" ))
225
227
continue
@@ -234,21 +236,21 @@ func (a *Application) loadCustomizedBases() (resmap.ResMap, *interror.Kustomizat
234
236
return result , errs
235
237
}
236
238
237
- func (a * Application ) loadBasesAsFlatList () ([]* Application , error ) {
238
- var result []* Application
239
+ func (kt * KustTarget ) loadBasesAsFlatList () ([]* KustTarget , error ) {
240
+ var result []* KustTarget
239
241
errs := & interror.KustomizationErrors {}
240
- for _ , path := range a .kustomization .Bases {
241
- ldr , err := a .ldr .New (path )
242
+ for _ , path := range kt .kustomization .Bases {
243
+ ldr , err := kt .ldr .New (path )
242
244
if err != nil {
243
245
errs .Append (err )
244
246
continue
245
247
}
246
- a , err := NewApplication (ldr , a .fSys , a .tcfg )
248
+ target , err := NewKustTarget (ldr , kt .fSys , kt .tcfg )
247
249
if err != nil {
248
250
errs .Append (err )
249
251
continue
250
252
}
251
- result = append (result , a )
253
+ result = append (result , target )
252
254
}
253
255
if len (errs .Get ()) > 0 {
254
256
return nil , errs
@@ -257,35 +259,39 @@ func (a *Application) loadBasesAsFlatList() ([]*Application, error) {
257
259
}
258
260
259
261
// newTransformer makes a Transformer that does everything except resolve generated names.
260
- func (a * Application ) newTransformer (patches []* resource.Resource ) (transformers.Transformer , error ) {
262
+ func (kt * KustTarget ) newTransformer (patches []* resource.Resource ) (transformers.Transformer , error ) {
261
263
var r []transformers.Transformer
262
264
t , err := transformers .NewPatchTransformer (patches )
263
265
if err != nil {
264
266
return nil , err
265
267
}
266
268
r = append (r , t )
267
- r = append (r , transformers .NewNamespaceTransformer (string (a .kustomization .Namespace ), a .tcfg .NameSpace ))
268
- t , err = transformers .NewNamePrefixTransformer (string (a .kustomization .NamePrefix ), a .tcfg .NamePrefix )
269
+ r = append (r , transformers .NewNamespaceTransformer (
270
+ string (kt .kustomization .Namespace ), kt .tcfg .NameSpace ))
271
+ t , err = transformers .NewNamePrefixTransformer (
272
+ string (kt .kustomization .NamePrefix ), kt .tcfg .NamePrefix )
269
273
if err != nil {
270
274
return nil , err
271
275
}
272
276
r = append (r , t )
273
- t , err = transformers .NewLabelsMapTransformer (a .kustomization .CommonLabels , a .tcfg .CommonLabels )
277
+ t , err = transformers .NewLabelsMapTransformer (
278
+ kt .kustomization .CommonLabels , kt .tcfg .CommonLabels )
274
279
if err != nil {
275
280
return nil , err
276
281
}
277
282
r = append (r , t )
278
- t , err = transformers .NewAnnotationsMapTransformer (a .kustomization .CommonAnnotations , a .tcfg .CommonAnnotations )
283
+ t , err = transformers .NewAnnotationsMapTransformer (
284
+ kt .kustomization .CommonAnnotations , kt .tcfg .CommonAnnotations )
279
285
if err != nil {
280
286
return nil , err
281
287
}
282
288
r = append (r , t )
283
289
return transformers .NewMultiTransformer (r ), nil
284
290
}
285
291
286
- func (a * Application ) resolveRefVars (m resmap.ResMap ) (map [string ]string , error ) {
292
+ func (kt * KustTarget ) resolveRefVars (m resmap.ResMap ) (map [string ]string , error ) {
287
293
result := map [string ]string {}
288
- vars , err := a .getAllVars ()
294
+ vars , err := kt .getAllVars ()
289
295
if err != nil {
290
296
return result , err
291
297
}
@@ -306,11 +312,11 @@ func (a *Application) resolveRefVars(m resmap.ResMap) (map[string]string, error)
306
312
}
307
313
308
314
// getAllVars returns all the "environment" style Var instances defined in the app.
309
- func (a * Application ) getAllVars () ([]types.Var , error ) {
315
+ func (kt * KustTarget ) getAllVars () ([]types.Var , error ) {
310
316
var result []types.Var
311
317
errs := & interror.KustomizationErrors {}
312
318
313
- bases , err := a .loadBasesAsFlatList ()
319
+ bases , err := kt .loadBasesAsFlatList ()
314
320
if err != nil {
315
321
return nil , err
316
322
}
@@ -325,7 +331,7 @@ func (a *Application) getAllVars() ([]types.Var, error) {
325
331
b .ldr .Cleanup ()
326
332
result = append (result , vars ... )
327
333
}
328
- for _ , v := range a .kustomization .Vars {
334
+ for _ , v := range kt .kustomization .Vars {
329
335
v .Defaulting ()
330
336
result = append (result , v )
331
337
}
0 commit comments