Merge pull request #48244 from xilabao/add-validation-when-create-directory

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

add validation in kubectl create if no file in directory

**What this PR does / why we need it**:
if no yaml or json file in a directory
```
# ./cluster/kubectl.sh create -f ../0/1 --dry-run
pod "nginx" created (dry run)

# ./cluster/kubectl.sh create -f ../0
error: You must provide one or more resources by argument or filename.
Example resource specifications include:
   '-f rsrc.yaml'
   '--filename=rsrc.json'
   '<resource> <name>'
   '<resource>'
```
expected:
```
# ./cluster/kubectl.sh create -f ../0
error: error reading [../0]: please make sure the file extension is [.json .yaml .yml]
```

**Which issue this PR fixes**: fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/8/head
Kubernetes Submit Queue 2018-04-18 11:08:55 -07:00 committed by GitHub
commit c36e66dd66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -287,6 +287,9 @@ func (b *Builder) Path(recursive bool, paths ...string) *Builder {
b.paths = append(b.paths, visitors...) b.paths = append(b.paths, visitors...)
} }
if len(b.paths) == 0 && len(b.errs) == 0 {
b.errs = append(b.errs, fmt.Errorf("error reading %v: recognized file extensions are %v", paths, FileExtensions))
}
return b return b
} }