@@ -25,7 +25,7 @@ func IsRemoteFile(path string) bool {
25
25
return err == nil && (u .Scheme == "http" || u .Scheme == "https" )
26
26
}
27
27
28
- // fileLoader is a kustomization's interface to files.
28
+ // FileLoader is a kustomization's interface to files.
29
29
//
30
30
// The directory in which a kustomization file sits
31
31
// is referred to below as the kustomization's _root_.
@@ -38,49 +38,48 @@ func IsRemoteFile(path string) bool {
38
38
//
39
39
// * supplemental data paths
40
40
//
41
- // `Load` is used to visit these paths.
41
+ // `Load` is used to visit these paths.
42
42
//
43
- // These paths refer to resources, patches,
44
- // data for ConfigMaps and Secrets, etc.
43
+ // These paths refer to resources, patches,
44
+ // data for ConfigMaps and Secrets, etc.
45
45
//
46
- // The loadRestrictor may disallow certain paths
47
- // or classes of paths.
46
+ // The loadRestrictor may disallow certain paths
47
+ // or classes of paths.
48
48
//
49
49
// * bases (other kustomizations)
50
50
//
51
- // `New` is used to load bases.
51
+ // `New` is used to load bases.
52
52
//
53
- // A base can be either a remote git repo URL, or
54
- // a directory specified relative to the current
55
- // root. In the former case, the repo is locally
56
- // cloned, and the new loader is rooted on a path
57
- // in that clone.
53
+ // A base can be either a remote git repo URL, or
54
+ // a directory specified relative to the current
55
+ // root. In the former case, the repo is locally
56
+ // cloned, and the new loader is rooted on a path
57
+ // in that clone.
58
58
//
59
- // As loaders create new loaders, a root history
60
- // is established, and used to disallow:
59
+ // As loaders create new loaders, a root history
60
+ // is established, and used to disallow:
61
61
//
62
- // - A base that is a repository that, in turn,
63
- // specifies a base repository seen previously
64
- // in the loading stack (a cycle).
62
+ // - A base that is a repository that, in turn,
63
+ // specifies a base repository seen previously
64
+ // in the loading stack (a cycle).
65
65
//
66
- // - An overlay depending on a base positioned at
67
- // or above it. I.e. '../foo' is OK, but '.',
68
- // '..', '../..', etc. are disallowed. Allowing
69
- // such a base has no advantages and encourages
70
- // cycles, particularly if some future change
71
- // were to introduce globbing to file
72
- // specifications in the kustomization file.
66
+ // - An overlay depending on a base positioned at
67
+ // or above it. I.e. '../foo' is OK, but '.',
68
+ // '..', '../..', etc. are disallowed. Allowing
69
+ // such a base has no advantages and encourages
70
+ // cycles, particularly if some future change
71
+ // were to introduce globbing to file
72
+ // specifications in the kustomization file.
73
73
//
74
74
// These restrictions assure that kustomizations
75
75
// are self-contained and relocatable, and impose
76
76
// some safety when relying on remote kustomizations,
77
77
// e.g. a remotely loaded ConfigMap generator specified
78
78
// to read from /etc/passwd will fail.
79
- //
80
- type fileLoader struct {
79
+ type FileLoader struct {
81
80
// Loader that spawned this loader.
82
81
// Used to avoid cycles.
83
- referrer * fileLoader
82
+ referrer * FileLoader
84
83
85
84
// An absolute, cleaned path to a directory.
86
85
// The Load function will read non-absolute
@@ -107,23 +106,9 @@ type fileLoader struct {
107
106
cleaner func () error
108
107
}
109
108
110
- // NewFileLoaderAtCwd returns a loader that loads from PWD.
111
- // A convenience for kustomize edit commands.
112
- func NewFileLoaderAtCwd (fSys filesys.FileSystem ) * fileLoader {
113
- return newLoaderOrDie (
114
- RestrictionRootOnly , fSys , filesys .SelfDir )
115
- }
116
-
117
- // NewFileLoaderAtRoot returns a loader that loads from "/".
118
- // A convenience for tests.
119
- func NewFileLoaderAtRoot (fSys filesys.FileSystem ) * fileLoader {
120
- return newLoaderOrDie (
121
- RestrictionRootOnly , fSys , filesys .Separator )
122
- }
123
-
124
109
// Repo returns the absolute path to the repo that contains Root if this fileLoader was created from a url
125
110
// or the empty string otherwise.
126
- func (fl * fileLoader ) Repo () string {
111
+ func (fl * FileLoader ) Repo () string {
127
112
if fl .repoSpec != nil {
128
113
return fl .repoSpec .Dir .String ()
129
114
}
@@ -132,13 +117,13 @@ func (fl *fileLoader) Repo() string {
132
117
133
118
// Root returns the absolute path that is prepended to any
134
119
// relative paths used in Load.
135
- func (fl * fileLoader ) Root () string {
120
+ func (fl * FileLoader ) Root () string {
136
121
return fl .root .String ()
137
122
}
138
123
139
- func newLoaderOrDie (
124
+ func NewLoaderOrDie (
140
125
lr LoadRestrictorFunc ,
141
- fSys filesys.FileSystem , path string ) * fileLoader {
126
+ fSys filesys.FileSystem , path string ) * FileLoader {
142
127
root , err := filesys .ConfirmDir (fSys , path )
143
128
if err != nil {
144
129
log .Fatalf ("unable to make loader at '%s'; %v" , path , err )
@@ -147,12 +132,12 @@ func newLoaderOrDie(
147
132
lr , root , fSys , nil , git .ClonerUsingGitExec )
148
133
}
149
134
150
- // newLoaderAtConfirmedDir returns a new fileLoader with given root.
135
+ // newLoaderAtConfirmedDir returns a new FileLoader with given root.
151
136
func newLoaderAtConfirmedDir (
152
137
lr LoadRestrictorFunc ,
153
138
root filesys.ConfirmedDir , fSys filesys.FileSystem ,
154
- referrer * fileLoader , cloner git.Cloner ) * fileLoader {
155
- return & fileLoader {
139
+ referrer * FileLoader , cloner git.Cloner ) * FileLoader {
140
+ return & FileLoader {
156
141
loadRestrictor : lr ,
157
142
root : root ,
158
143
referrer : referrer ,
@@ -164,7 +149,7 @@ func newLoaderAtConfirmedDir(
164
149
165
150
// New returns a new Loader, rooted relative to current loader,
166
151
// or rooted in a temp directory holding a git repo clone.
167
- func (fl * fileLoader ) New (path string ) (ifc.Loader , error ) {
152
+ func (fl * FileLoader ) New (path string ) (ifc.Loader , error ) {
168
153
if path == "" {
169
154
return nil , errors .Errorf ("new root cannot be empty" )
170
155
}
@@ -200,7 +185,7 @@ func (fl *fileLoader) New(path string) (ifc.Loader, error) {
200
185
// directory holding a cloned git repo.
201
186
func newLoaderAtGitClone (
202
187
repoSpec * git.RepoSpec , fSys filesys.FileSystem ,
203
- referrer * fileLoader , cloner git.Cloner ) (ifc.Loader , error ) {
188
+ referrer * FileLoader , cloner git.Cloner ) (ifc.Loader , error ) {
204
189
cleaner := repoSpec .Cleaner (fSys )
205
190
err := cloner (repoSpec )
206
191
if err != nil {
@@ -229,7 +214,7 @@ func newLoaderAtGitClone(
229
214
return nil , fmt .Errorf ("%q refers to directory outside of repo %q" , repoSpec .AbsPath (),
230
215
repoSpec .CloneDir ())
231
216
}
232
- return & fileLoader {
217
+ return & FileLoader {
233
218
// Clones never allowed to escape root.
234
219
loadRestrictor : RestrictionRootOnly ,
235
220
root : root ,
@@ -241,7 +226,7 @@ func newLoaderAtGitClone(
241
226
}, nil
242
227
}
243
228
244
- func (fl * fileLoader ) errIfGitContainmentViolation (
229
+ func (fl * FileLoader ) errIfGitContainmentViolation (
245
230
base filesys.ConfirmedDir ) error {
246
231
containingRepo := fl .containingRepo ()
247
232
if containingRepo == nil {
@@ -259,7 +244,7 @@ func (fl *fileLoader) errIfGitContainmentViolation(
259
244
260
245
// Looks back through referrers for a git repo, returning nil
261
246
// if none found.
262
- func (fl * fileLoader ) containingRepo () * git.RepoSpec {
247
+ func (fl * FileLoader ) containingRepo () * git.RepoSpec {
263
248
if fl .repoSpec != nil {
264
249
return fl .repoSpec
265
250
}
@@ -271,7 +256,7 @@ func (fl *fileLoader) containingRepo() *git.RepoSpec {
271
256
272
257
// errIfArgEqualOrHigher tests whether the argument,
273
258
// is equal to or above the root of any ancestor.
274
- func (fl * fileLoader ) errIfArgEqualOrHigher (
259
+ func (fl * FileLoader ) errIfArgEqualOrHigher (
275
260
candidateRoot filesys.ConfirmedDir ) error {
276
261
if fl .root .HasPrefix (candidateRoot ) {
277
262
return fmt .Errorf (
@@ -288,7 +273,7 @@ func (fl *fileLoader) errIfArgEqualOrHigher(
288
273
// I.e. Allow a distinction between git URI with
289
274
// path foo and tag bar and a git URI with the same
290
275
// path but a different tag?
291
- func (fl * fileLoader ) errIfRepoCycle (newRepoSpec * git.RepoSpec ) error {
276
+ func (fl * FileLoader ) errIfRepoCycle (newRepoSpec * git.RepoSpec ) error {
292
277
// TODO(monopole): Use parsed data instead of Raw().
293
278
if fl .repoSpec != nil &&
294
279
strings .HasPrefix (fl .repoSpec .Raw (), newRepoSpec .Raw ()) {
@@ -305,7 +290,7 @@ func (fl *fileLoader) errIfRepoCycle(newRepoSpec *git.RepoSpec) error {
305
290
// Load returns the content of file at the given path,
306
291
// else an error. Relative paths are taken relative
307
292
// to the root.
308
- func (fl * fileLoader ) Load (path string ) ([]byte , error ) {
293
+ func (fl * FileLoader ) Load (path string ) ([]byte , error ) {
309
294
if IsRemoteFile (path ) {
310
295
return fl .httpClientGetContent (path )
311
296
}
@@ -319,7 +304,7 @@ func (fl *fileLoader) Load(path string) ([]byte, error) {
319
304
return fl .fSys .ReadFile (path )
320
305
}
321
306
322
- func (fl * fileLoader ) httpClientGetContent (path string ) ([]byte , error ) {
307
+ func (fl * FileLoader ) httpClientGetContent (path string ) ([]byte , error ) {
323
308
var hc * http.Client
324
309
if fl .http != nil {
325
310
hc = fl .http
@@ -344,6 +329,6 @@ func (fl *fileLoader) httpClientGetContent(path string) ([]byte, error) {
344
329
}
345
330
346
331
// Cleanup runs the cleaner.
347
- func (fl * fileLoader ) Cleanup () error {
332
+ func (fl * FileLoader ) Cleanup () error {
348
333
return fl .cleaner ()
349
334
}
0 commit comments