update resource selector - kubectl drain

This commit is contained in:
juanvallejo 2017-10-17 13:24:50 -04:00
parent 78ada62c30
commit ee2f9c95e7
No known key found for this signature in database
GPG Key ID: 7D2C958002D6448D

View File

@ -237,20 +237,18 @@ func (o *DrainOptions) SetupDrain(cmd *cobra.Command, args []string) error {
return err return err
} }
nameArgs := []string{"nodes"} builder := o.Factory.NewBuilder().
if len(args) > 0 { NamespaceParam(cmdNamespace).DefaultNamespace().
nameArgs = append(nameArgs, args[0]) ResourceNames("nodes", args...).
if strings.Contains(args[0], "/") { SingleResourceType().
nameArgs = []string{args[0]} Flatten()
}
if len(o.Selector) > 0 {
builder = builder.SelectorParam(o.Selector).
ResourceTypes("nodes")
} }
r := o.Factory.NewBuilder(). r := builder.Do()
NamespaceParam(cmdNamespace).DefaultNamespace().
SelectorParam(o.Selector).
ResourceTypeOrNameArgs(true, nameArgs...).
Flatten().
Do()
if err = r.Err(); err != nil { if err = r.Err(); err != nil {
return err return err
@ -260,6 +258,10 @@ func (o *DrainOptions) SetupDrain(cmd *cobra.Command, args []string) error {
if err != nil { if err != nil {
return err return err
} }
if info.Mapping.Resource != "nodes" {
return fmt.Errorf("error: expected resource of type node, got %q", info.Mapping.Resource)
}
o.nodeInfos = append(o.nodeInfos, info) o.nodeInfos = append(o.nodeInfos, info)
return nil return nil
}) })