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
This commit is contained in:
Cao Shufeng 2017-07-24 16:31:22 +08:00
parent 6fbc554c6b
commit 292b18db1f
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",
},
{