mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +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/resource: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/util/i18n:go_default_library",
|
||||
"//staging/src/k8s.io/kubectl/pkg/util/templates:go_default_library",
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kubectl/pkg/explain"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
@ -59,6 +60,8 @@ type TaintOptions struct {
|
||||
ClientForMapping func(*meta.RESTMapping) (resource.RESTClient, error)
|
||||
|
||||
genericclioptions.IOStreams
|
||||
|
||||
Mapper meta.RESTMapper
|
||||
}
|
||||
|
||||
var (
|
||||
@ -129,6 +132,11 @@ func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
|
||||
return err
|
||||
}
|
||||
|
||||
o.Mapper, err = f.ToRESTMapper()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.DryRunStrategy, err = cmdutil.GetDryRunStrategy(cmd)
|
||||
if err != nil {
|
||||
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.
|
||||
func (o TaintOptions) Validate() error {
|
||||
resourceType := strings.ToLower(o.resources[0])
|
||||
validResources, isValidResource := []string{"node", "nodes"}, false
|
||||
for _, validResource := range validResources {
|
||||
if resourceType == validResource {
|
||||
isValidResource = true
|
||||
break
|
||||
}
|
||||
fullySpecifiedGVR, _, err := explain.SplitAndParseResourceRequest(resourceType, o.Mapper)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !isValidResource {
|
||||
return fmt.Errorf("invalid resource type %s, only %q are supported", o.resources[0], validResources)
|
||||
|
||||
gvk, err := o.Mapper.KindFor(fullySpecifiedGVR)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user