mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Kubectl Taint now also accepts short forms for "node","nodes","no"
This commit is contained in:
parent
e7de96e635
commit
8fda1f361c
@ -23,6 +23,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/cli-runtime/pkg/printers:go_default_library",
|
"//staging/src/k8s.io/cli-runtime/pkg/printers:go_default_library",
|
||||||
"//staging/src/k8s.io/cli-runtime/pkg/resource:go_default_library",
|
"//staging/src/k8s.io/cli-runtime/pkg/resource:go_default_library",
|
||||||
"//staging/src/k8s.io/kubectl/pkg/cmd/util:go_default_library",
|
"//staging/src/k8s.io/kubectl/pkg/cmd/util:go_default_library",
|
||||||
|
"//staging/src/k8s.io/kubectl/pkg/explain:go_default_library",
|
||||||
"//staging/src/k8s.io/kubectl/pkg/scheme:go_default_library",
|
"//staging/src/k8s.io/kubectl/pkg/scheme:go_default_library",
|
||||||
"//staging/src/k8s.io/kubectl/pkg/util/i18n:go_default_library",
|
"//staging/src/k8s.io/kubectl/pkg/util/i18n:go_default_library",
|
||||||
"//staging/src/k8s.io/kubectl/pkg/util/templates:go_default_library",
|
"//staging/src/k8s.io/kubectl/pkg/util/templates:go_default_library",
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
"k8s.io/kubectl/pkg/explain"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
@ -59,6 +60,8 @@ type TaintOptions struct {
|
|||||||
ClientForMapping func(*meta.RESTMapping) (resource.RESTClient, error)
|
ClientForMapping func(*meta.RESTMapping) (resource.RESTClient, error)
|
||||||
|
|
||||||
genericclioptions.IOStreams
|
genericclioptions.IOStreams
|
||||||
|
|
||||||
|
Mapper meta.RESTMapper
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -129,6 +132,11 @@ func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
o.Mapper, err = f.ToRESTMapper()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
o.DryRunStrategy, err = cmdutil.GetDryRunStrategy(cmd)
|
o.DryRunStrategy, err = cmdutil.GetDryRunStrategy(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -219,15 +227,18 @@ func (o TaintOptions) validateFlags() error {
|
|||||||
// Validate checks to the TaintOptions to see if there is sufficient information run the command.
|
// Validate checks to the TaintOptions to see if there is sufficient information run the command.
|
||||||
func (o TaintOptions) Validate() error {
|
func (o TaintOptions) Validate() error {
|
||||||
resourceType := strings.ToLower(o.resources[0])
|
resourceType := strings.ToLower(o.resources[0])
|
||||||
validResources, isValidResource := []string{"node", "nodes"}, false
|
fullySpecifiedGVR, _, err := explain.SplitAndParseResourceRequest(resourceType, o.Mapper)
|
||||||
for _, validResource := range validResources {
|
if err != nil {
|
||||||
if resourceType == validResource {
|
return err
|
||||||
isValidResource = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gvk, err := o.Mapper.KindFor(fullySpecifiedGVR)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if !isValidResource {
|
|
||||||
return fmt.Errorf("invalid resource type %s, only %q are supported", o.resources[0], validResources)
|
if gvk.Kind != "Node" {
|
||||||
|
return fmt.Errorf("invalid resource type %s, only node types are supported", resourceType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the format of taint args and checks removed taints aren't in the new taints list
|
// check the format of taint args and checks removed taints aren't in the new taints list
|
||||||
|
Loading…
Reference in New Issue
Block a user