@@ -22,7 +22,6 @@ import (
2222 "os"
2323 "path/filepath"
2424 "strings"
25- "unicode"
2625
2726 "github.com/spf13/pflag"
2827
@@ -159,53 +158,24 @@ func (p *initSubcommand) PostScaffold() error {
159158}
160159
161160// checkDir will return error if the current directory has files which are not allowed.
162- // Note that, it is expected that the directory to scaffold the project is cleaned.
163- // Otherwise, it might face issues to do the scaffold.
161+ // Only the PROJECT file is disallowed as it will be generated by the scaffolding tool.
164162func checkDir () error {
165163 err := filepath .Walk ("." ,
166164 func (path string , info os.FileInfo , err error ) error {
167165 if err != nil {
168166 return fmt .Errorf ("error walking path %q: %w" , path , err )
169167 }
170- // Allow directory trees starting with '.'
168+ // Skip dot directories
171169 if info .IsDir () && strings .HasPrefix (info .Name (), "." ) && info .Name () != "." {
172170 return filepath .SkipDir
173171 }
174- // Allow files starting with '.'
175- if strings .HasPrefix (info .Name (), "." ) {
176- return nil
172+ // Only block PROJECT file (reserved for scaffolding)
173+ if ! info .IsDir () && info .Name () == "PROJECT" {
174+ return fmt .Errorf ("PROJECT file found in target directory. " +
175+ "This file is reserved and will be generated by kubebuilder" )
177176 }
178- // Allow files ending with '.md' extension
179- if strings .HasSuffix (info .Name (), ".md" ) && ! info .IsDir () {
180- return nil
181- }
182- // Allow capitalized files except PROJECT
183- isCapitalized := true
184- for _ , l := range info .Name () {
185- if ! unicode .IsUpper (l ) {
186- isCapitalized = false
187- break
188- }
189- }
190- if isCapitalized && info .Name () != "PROJECT" {
191- return nil
192- }
193- disallowedExtensions := []string {
194- ".go" ,
195- ".yaml" ,
196- ".mod" ,
197- ".sum" ,
198- }
199- // Deny files with .go or .yaml or .mod or .sum extensions
200- for _ , ext := range disallowedExtensions {
201- if strings .HasSuffix (info .Name (), ext ) {
202- return nil
203- }
204- }
205- // Do not allow any other file
206- return fmt .Errorf ("target directory is not empty and contains a disallowed file %q. " +
207- "files with the following extensions [%s] are not allowed to avoid conflicts with the tooling" ,
208- path , strings .Join (disallowedExtensions , ", " ))
177+ // Allow everything else
178+ return nil
209179 })
210180 if err != nil {
211181 return fmt .Errorf ("error walking directory: %w" , err )
0 commit comments