mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #57381 from niuzhenguo/get-raw-cleanup
Automatic merge from submit-queue (batch tested with PRs 52912, 57381). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add more validators when run kubectl get with --raw **What this PR does / why we need it**: 1. Make --raw and --output mutually exclusive for kubectl get cmd 2. Add url/ParseRequestURI check for the specified raw URI **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #57379 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
b04c28e80e
@ -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,9 +218,17 @@ 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) {
|
||||
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()
|
||||
if outputOption != "" && outputOption != "wide" {
|
||||
|
Loading…
Reference in New Issue
Block a user