@@ -23,6 +23,8 @@ var kustomizeBuildMutex sync.Mutex
2323func Kustomize (ctx context.Context , path string ) (resmap.ResMap , error ) {
2424 kfile := filepath .Join (path , konfig .DefaultKustomizationFileName ())
2525 fs := filesys .MakeFsOnDisk ()
26+ pvd := provider .NewDefaultDepProvider ()
27+ singleFile := false
2628
2729 _ , err := os .Stat (kfile )
2830 if err != nil {
@@ -32,6 +34,7 @@ func Kustomize(ctx context.Context, path string) (resmap.ResMap, error) {
3234 }
3335
3436 if path == "/dev/stdin" || path == "-" {
37+ singleFile = true
3538 d , err := os .MkdirTemp (os .TempDir (), "" )
3639 if err != nil {
3740 return nil , err
@@ -53,6 +56,7 @@ func Kustomize(ctx context.Context, path string) (resmap.ResMap, error) {
5356 _ = os .RemoveAll (d )
5457 }()
5558 } else if ! stat .IsDir () {
59+ singleFile = true
5660 d , err := os .MkdirTemp (os .TempDir (), "" )
5761 if err != nil {
5862 return nil , err
@@ -78,8 +82,7 @@ func Kustomize(ctx context.Context, path string) (resmap.ResMap, error) {
7882 _ = os .Remove (kfile )
7983 }()
8084
81- pvd := provider .NewDefaultDepProvider ()
82- err = createKustomization (path , fs , pvd .GetResourceFactory ())
85+ err = createKustomization (path , fs , pvd .GetResourceFactory (), singleFile )
8386 if err != nil {
8487 return nil , fmt .Errorf ("failed create kustomization: %w" , err )
8588 }
@@ -98,7 +101,7 @@ func Kustomize(ctx context.Context, path string) (resmap.ResMap, error) {
98101 return kustomizer .Run (fs , path )
99102}
100103
101- func createKustomization (path string , fSys filesys.FileSystem , rf * resource.Factory ) error {
104+ func createKustomization (path string , fSys filesys.FileSystem , rf * resource.Factory , singleFile bool ) error {
102105 kfile := filepath .Join (path , konfig .DefaultKustomizationFileName ())
103106 kus := kustypes.Kustomization {
104107 TypeMeta : kustypes.TypeMeta {
@@ -107,7 +110,7 @@ func createKustomization(path string, fSys filesys.FileSystem, rf *resource.Fact
107110 },
108111 }
109112
110- detected , err := detectResources (fSys , rf , path , true )
113+ detected , err := detectResources (fSys , rf , path , singleFile )
111114 if err != nil {
112115 return err
113116 }
@@ -122,7 +125,7 @@ func createKustomization(path string, fSys filesys.FileSystem, rf *resource.Fact
122125 return os .WriteFile (kfile , kd , os .ModePerm )
123126}
124127
125- func detectResources (fSys filesys.FileSystem , rf * resource.Factory , base string , recursive bool ) ([]string , error ) {
128+ func detectResources (fSys filesys.FileSystem , rf * resource.Factory , base string , singleFile bool ) ([]string , error ) {
126129 var paths []string
127130
128131 err := fSys .Walk (base , func (path string , info os.FileInfo , err error ) error {
@@ -140,9 +143,6 @@ func detectResources(fSys filesys.FileSystem, rf *resource.Factory, base string,
140143 }
141144
142145 if info .IsDir () {
143- if ! recursive {
144- return filepath .SkipDir
145- }
146146 // If a sub-directory contains an existing kustomization file add the
147147 // directory as a resource and do not decend into it.
148148 for _ , kfilename := range konfig .RecognizedKustomizationFileNames () {
@@ -158,8 +158,13 @@ func detectResources(fSys filesys.FileSystem, rf *resource.Factory, base string,
158158 return err
159159 }
160160 if _ , err := rf .SliceFromBytes (fContents ); err != nil {
161- return err
161+ if singleFile {
162+ return err
163+ }
164+
165+ return nil
162166 }
167+
163168 paths = append (paths , normalizedPath )
164169 return nil
165170 })
0 commit comments