mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #54083 from juanvallejo/jvallejo/update-resource-builder-cmd-drain
Automatic merge from submit-queue. 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>. update resource selector - kubectl drain Followup to https://github.com/kubernetes/kubernetes/pull/52917 **Release note**: ```release-note NONE ``` Updates resource builder in cmd/drain.go to parse resource args similar to other commands. cc @liggitt
This commit is contained in:
commit
2ad7d6f711
@ -916,7 +916,7 @@ __EOF__
|
||||
}
|
||||
|
||||
# runs specific kubectl create tests
|
||||
run_create_tests() {
|
||||
run_create_secret_tests() {
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
|
||||
@ -4297,11 +4297,17 @@ run_cluster_management_tests() {
|
||||
response=$(! kubectl cordon 2>&1)
|
||||
kube::test::if_has_string "${response}" 'error\: USAGE\: cordon NODE'
|
||||
|
||||
### kubectl cordon selects all nodes with an empty --selector=
|
||||
### kubectl cordon selects no nodes with an empty --selector=
|
||||
# Pre-condition: node "127.0.0.1" is uncordoned
|
||||
kubectl uncordon "127.0.0.1"
|
||||
response=$(kubectl cordon --selector=)
|
||||
response=$(! kubectl cordon --selector= 2>&1)
|
||||
kube::test::if_has_string "${response}" 'must provide one or more resources'
|
||||
# test=label matches our node
|
||||
response=$(kubectl cordon --selector test=label)
|
||||
kube::test::if_has_string "${response}" 'node "127.0.0.1" cordoned'
|
||||
# invalid=label does not match any nodes
|
||||
response=$(kubectl cordon --selector invalid=label)
|
||||
kube::test::if_has_not_string "${response}" 'cordoned'
|
||||
# Post-condition: node "127.0.0.1" is cordoned
|
||||
kube::test::get_object_assert "nodes 127.0.0.1" "{{.spec.unschedulable}}" 'true'
|
||||
|
||||
@ -4607,7 +4613,7 @@ runTests() {
|
||||
# Create #
|
||||
######################
|
||||
if kube::test::if_supports_resource "${secrets}" ; then
|
||||
record_command run_create_tests
|
||||
record_command run_create_secret_tests
|
||||
fi
|
||||
|
||||
##################
|
||||
|
@ -237,20 +237,18 @@ func (o *DrainOptions) SetupDrain(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
nameArgs := []string{"nodes"}
|
||||
if len(args) > 0 {
|
||||
nameArgs = append(nameArgs, args[0])
|
||||
if strings.Contains(args[0], "/") {
|
||||
nameArgs = []string{args[0]}
|
||||
}
|
||||
builder := o.Factory.NewBuilder().
|
||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
||||
ResourceNames("nodes", args...).
|
||||
SingleResourceType().
|
||||
Flatten()
|
||||
|
||||
if len(o.Selector) > 0 {
|
||||
builder = builder.SelectorParam(o.Selector).
|
||||
ResourceTypes("nodes")
|
||||
}
|
||||
|
||||
r := o.Factory.NewBuilder().
|
||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
||||
SelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(true, nameArgs...).
|
||||
Flatten().
|
||||
Do()
|
||||
r := builder.Do()
|
||||
|
||||
if err = r.Err(); err != nil {
|
||||
return err
|
||||
@ -260,6 +258,10 @@ func (o *DrainOptions) SetupDrain(cmd *cobra.Command, args []string) error {
|
||||
if err != nil {
|
||||
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)
|
||||
return nil
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user