mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 15:50:10 +00:00
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:
parent
6fbc554c6b
commit
292b18db1f
@ -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",
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user