mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
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:
commit
001ded68e4
@ -156,6 +156,9 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
|
|||||||
|
|
||||||
// validate image name
|
// validate image name
|
||||||
imageName := cmdutil.GetFlagString(cmd, "image")
|
imageName := cmdutil.GetFlagString(cmd, "image")
|
||||||
|
if imageName == "" {
|
||||||
|
return fmt.Errorf("--image is required")
|
||||||
|
}
|
||||||
validImageRef := reference.ReferenceRegexp.MatchString(imageName)
|
validImageRef := reference.ReferenceRegexp.MatchString(imageName)
|
||||||
if !validImageRef {
|
if !validImageRef {
|
||||||
return fmt.Errorf("Invalid image name %q: %v", imageName, reference.ErrReferenceInvalidFormat)
|
return fmt.Errorf("Invalid image name %q: %v", imageName, reference.ErrReferenceInvalidFormat)
|
||||||
|
@ -361,6 +361,13 @@ func TestRunValidations(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
args: []string{"test"},
|
args: []string{"test"},
|
||||||
|
expectedErr: "--image is required",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"test"},
|
||||||
|
flags: map[string]string{
|
||||||
|
"image": "#",
|
||||||
|
},
|
||||||
expectedErr: "Invalid image name",
|
expectedErr: "Invalid image name",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user