mirror of https://github.com/k3s-io/k3s
return err on kubectl run --image with invalid value
parent
13f376c9af
commit
af37981812
|
@ -1066,6 +1066,18 @@ __EOF__
|
|||
# teardown
|
||||
kubectl delete thirdpartyresources foo.company.com "${kube_flags[@]}"
|
||||
|
||||
#################
|
||||
# Run cmd w img #
|
||||
#################
|
||||
|
||||
# Test that a valid image reference value is provided as the value of --image in `kubectl run <name> --image`
|
||||
output_message=$(kubectl run test1 --image=validname)
|
||||
kube::test::if_has_string "${output_message}" 'deployment "test1" created'
|
||||
# test invalid image name
|
||||
output_message=$(! kubectl run test2 --image=InvalidImageName 2>&1)
|
||||
kube::test::if_has_string "${output_message}" 'error: Invalid image name "InvalidImageName": invalid reference format'
|
||||
|
||||
|
||||
#####################################
|
||||
# Recursive Resources via directory #
|
||||
#####################################
|
||||
|
|
|
@ -24,6 +24,9 @@ import (
|
|||
|
||||
"github.com/renstrom/dedent"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
|
@ -135,6 +138,13 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
|
|||
return cmdutil.UsageError(cmd, "NAME is required for run")
|
||||
}
|
||||
|
||||
// validate image name
|
||||
imageName := cmdutil.GetFlagString(cmd, "image")
|
||||
validImageRef := reference.ReferenceRegexp.MatchString(imageName)
|
||||
if !validImageRef {
|
||||
return fmt.Errorf("Invalid image name %q: %v", imageName, reference.ErrReferenceInvalidFormat)
|
||||
}
|
||||
|
||||
interactive := cmdutil.GetFlagBool(cmd, "stdin")
|
||||
tty := cmdutil.GetFlagBool(cmd, "tty")
|
||||
if tty && !interactive {
|
||||
|
|
Loading…
Reference in New Issue