Merge pull request #49476 from CaoShuFeng/image-name

Automatic merge from submit-queue (batch tested with PRs 47357, 49514, 49271, 49572, 49476)

enhance kubectl run error message

Before this change:
 $ kubectl run nginx
 error: Invalid image name "": invalid reference format

After this change:
 $ kubectl run nginx
 error: --image is required


**Release note**:
```
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-07-26 12:03:52 -07:00 committed by GitHub
commit 001ded68e4
2 changed files with 10 additions and 0 deletions

View File

@ -156,6 +156,9 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
// validate image name
imageName := cmdutil.GetFlagString(cmd, "image")
if imageName == "" {
return fmt.Errorf("--image is required")
}
validImageRef := reference.ReferenceRegexp.MatchString(imageName)
if !validImageRef {
return fmt.Errorf("Invalid image name %q: %v", imageName, reference.ErrReferenceInvalidFormat)

View File

@ -361,6 +361,13 @@ func TestRunValidations(t *testing.T) {
},
{
args: []string{"test"},
expectedErr: "--image is required",
},
{
args: []string{"test"},
flags: map[string]string{
"image": "#",
},
expectedErr: "Invalid image name",
},
{