@@ -23,6 +23,7 @@ import (
23
23
24
24
"github.com/spf13/cobra"
25
25
"k8s.io/klog"
26
+ "k8s.io/kubectl/pkg/explain"
26
27
27
28
v1 "k8s.io/api/core/v1"
28
29
"k8s.io/apimachinery/pkg/api/meta"
@@ -59,6 +60,8 @@ type TaintOptions struct {
59
60
ClientForMapping func (* meta.RESTMapping ) (resource.RESTClient , error )
60
61
61
62
genericclioptions.IOStreams
63
+
64
+ Mapper meta.RESTMapper
62
65
}
63
66
64
67
var (
@@ -129,6 +132,11 @@ func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
129
132
return err
130
133
}
131
134
135
+ o .Mapper , err = f .ToRESTMapper ()
136
+ if err != nil {
137
+ return err
138
+ }
139
+
132
140
o .DryRunStrategy , err = cmdutil .GetDryRunStrategy (cmd )
133
141
if err != nil {
134
142
return err
@@ -219,15 +227,18 @@ func (o TaintOptions) validateFlags() error {
219
227
// Validate checks to the TaintOptions to see if there is sufficient information run the command.
220
228
func (o TaintOptions ) Validate () error {
221
229
resourceType := strings .ToLower (o .resources [0 ])
222
- validResources , isValidResource := []string {"node" , "nodes" }, false
223
- for _ , validResource := range validResources {
224
- if resourceType == validResource {
225
- isValidResource = true
226
- break
227
- }
230
+ fullySpecifiedGVR , _ , err := explain .SplitAndParseResourceRequest (resourceType , o .Mapper )
231
+ if err != nil {
232
+ return err
233
+ }
234
+
235
+ gvk , err := o .Mapper .KindFor (fullySpecifiedGVR )
236
+ if err != nil {
237
+ return err
228
238
}
229
- if ! isValidResource {
230
- return fmt .Errorf ("invalid resource type %s, only %q are supported" , o .resources [0 ], validResources )
239
+
240
+ if gvk .Kind != "Node" {
241
+ return fmt .Errorf ("invalid resource type %s, only node types are supported" , resourceType )
231
242
}
232
243
233
244
// check the format of taint args and checks removed taints aren't in the new taints list
0 commit comments