diff --git a/pkg/kubectl/cmd/resource/get.go b/pkg/kubectl/cmd/resource/get.go index b55936c8888..56d458c5a78 100644 --- a/pkg/kubectl/cmd/resource/get.go +++ b/pkg/kubectl/cmd/resource/get.go @@ -25,6 +25,8 @@ import ( "github.com/golang/glog" "github.com/spf13/cobra" + "net/url" + kapierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -216,8 +218,16 @@ func (options *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args // Validate checks the set of flags provided by the user. func (options *GetOptions) Validate(cmd *cobra.Command) error { - if len(options.Raw) > 0 && (options.Watch || options.WatchOnly || len(options.LabelSelector) > 0 || options.Export) { - return fmt.Errorf("--raw may not be specified with other flags that filter the server request or alter the output") + if len(options.Raw) > 0 { + if options.Watch || options.WatchOnly || len(options.LabelSelector) > 0 || options.Export { + return fmt.Errorf("--raw may not be specified with other flags that filter the server request or alter the output") + } + if len(cmdutil.GetFlagString(cmd, "output")) > 0 { + return cmdutil.UsageErrorf(cmd, "--raw and --output are mutually exclusive") + } + if _, err := url.ParseRequestURI(options.Raw); err != nil { + return cmdutil.UsageErrorf(cmd, "--raw must be a valid URL path: %v", err) + } } if cmdutil.GetFlagBool(cmd, "show-labels") { outputOption := cmd.Flags().Lookup("output").Value.String()