Commit 001ded68 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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 ```
parents 112c401b 292b18db
......@@ -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)
......
......@@ -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",
},
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment