mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
Merge pull request #30162 from juanvallejo/jvallejo_err-kube-run-on-invalid-image-value
Automatic merge from submit-queue return err on `kubectl run --image` with invalid value When running `kubectl run <configname> --image="Invalid$$%ImageValue%%__"`, a configuration is successfully created with an image name that is not a valid value for an image reference. This patch validates that the image name is a valid image reference, and returns an error before creating a config if an invalid value is passed. `$ kubectl run test --image="Invalid__%imagename"` ``` error: Invalid image name "Invalid__%imagename": invalid reference format ``` <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.kubernetes.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.kubernetes.io/reviews/kubernetes/kubernetes/30162) <!-- Reviewable:end -->
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user