Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubectl taint node based on label selector #44740

Conversation

ravisantoshgudimetla
Copy link
Contributor

@ravisantoshgudimetla ravisantoshgudimetla commented Apr 20, 2017

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #44522
Release note:

Taints the node based on label selector

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 20, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-ci-robot
Copy link
Contributor

Hi @ravisantoshgudimetla. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 20, 2017
@k8s-github-robot k8s-github-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. release-note-label-needed release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Apr 20, 2017
@jayunit100
Copy link
Member

Thanks @ravisantoshgudimetla this works for me :)

cluster/kubectl.sh label nodes --all "myLabel=x" ; cluster/kubectl.sh taint nodes --selector='myLabel==x' dedicated=foo:PreferNoSchedule ;
node "127.0.0.1" labeled
node "127.0.0.1" tainted

Do we need the unit tests in order to merge this ? I'd prefer to push it forward since the unit tests (we think) don't seem to support combining kubectl labelling with tainting (although maybe there is way to do so, its just not obvious).

@ravisantoshgudimetla
Copy link
Contributor Author

/cc @jayunit100.

@ravisantoshgudimetla ravisantoshgudimetla force-pushed the kubectl_taints_label_selector#44522 branch from 75a5941 to 3a60861 Compare April 20, 2017 21:27
@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 20, 2017
@ravisantoshgudimetla
Copy link
Contributor Author

cc @aveshagarwal

@jayunit100
Copy link
Member

@k8s-bot test this please

@jayunit100
Copy link
Member

cc @nimeshksingh

if o.all {
o.builder = o.builder.SelectAllParam(o.all).ResourceTypes("node")
} else {
if len(o.resources) < 2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aveshagarwal ok to get rid of this check?

Copy link
Member

@aveshagarwal aveshagarwal Apr 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems No. if both "selector" and "all" are NOT provided, we should do this check to verify the sequence of <resource> <name>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aveshagarwal So, in the below command, I have a resource node without selector and all options. Its throwing a valid error.
cluster/kubectl.sh taint node 127.0.0.1
error: at least one taint update is required

Copy link
Member

@aveshagarwal aveshagarwal Apr 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant this errneous case:
kubectl taint node key=value:Noschedule

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IOW, if you dont specify node name, but just the resource type node.

Copy link
Contributor Author

@ravisantoshgudimetla ravisantoshgudimetla Apr 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for the information @aveshagarwal. So, we already have a check at API server to handle it. There is no need to validate it here again.

cluster/kubectl.sh taint node dedicated=foo:PreferNoSchedule
error: You must provide one or more resources by argument or filename.
Example resource specifications include:
'-f rsrc.yaml'
'--filename=rsrc.json'
'pods my-pod'
'services'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of command line validation, and should be done in kubectl too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if that is the case, it should be something like if(o.selector)!=="" and o.all=false then we should throw this error. I can make that change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sound good. And as you are at this, make sure one of selector and all is present not both simultaneously if not already.

kubectl taint nodes foo dedicated-

# Add from node 'foo' all the taints with key 'dedicated'
kubectl taint nodes foo dedicated-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commands for Add and Remove examples are the same. Any error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems incorrect, the format with hyphen in the end ("dedicated-") is only for deletion. It does not make sense with addition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Its a mistake, Thanks for catching it @supereagle & @aveshagarwal , I will change this.

@0xmichalis
Copy link
Contributor

@kubernetes/sig-cli-pr-reviews ptal

@ravisantoshgudimetla ravisantoshgudimetla force-pushed the kubectl_taints_label_selector#44522 branch 3 times, most recently from ec3ce3c to 4017ccc Compare April 21, 2017 19:16
@ravisantoshgudimetla
Copy link
Contributor Author

@aveshagarwal PTAL.

@aveshagarwal
Copy link
Member

@ravisantoshgudimetla lgtm, now need to figure out the issue with your unit test.

@jayunit100
Copy link
Member

@kubernetes/sig-cli-pr-reviews Can we merge this, it fixes a pretty important label + kubectl bug ? @ravisantoshgudimetla can you create a follow on issue for adding a unit test.

@derekwaynecarr
Copy link
Member

the code looks fine to me, for a unit test, we appear to have testing for label selectors in delete_test.go that may have a convention you could follow in TestDeleteMultipleSelector. if there is no urgency, would prefer a test case with the code in one pr.

@ravisantoshgudimetla
Copy link
Contributor Author

@derekwaynecarr Thanks for the pointer regarding test case. I will check that and get back in case I am stuck.

@ravisantoshgudimetla
Copy link
Contributor Author

@derekwaynecarr I tried running the cmd using the way in deleted_test.go and it is causing the same error. The test case that is failing is https://gist.github.com/ravisantoshgudimetla/d66fb36b1279f118395e540cc8c61505#file-taint_test-go-L106.

As updated earlier, It seems the issue is with object being built using builder. The ones coming from unit tests are not having name created at https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/taint.go#L320. So, wondering if there is a way to work around that to write a unit test. Initially I was thinking of mopdifying RunTaint() to take some arguments(especially for builders). Please lmk, if you have other thoughts or if I missed anything.

@jayunit100
Copy link
Member

@derekwaynecarr @ravisantoshgudimetla ok so sounds like to move forward, we have to do two things...

  1. Lets create a follow on issue delineating the lack of the builder mocks needed for better higher level tests, and aim to improve the general situation for kubectl tests in general, so that in the future we can more declaratively test the subtleties of taints w/ different builder+label+... situations and so on.
  2. per @derekwaynecarr suggestion , we can make a unit test for this patch by making a separate function for object creation.

(derek let us know if this sounds good to you as well, i think that will solve everything brought up in this issue, including getting this much needed fix merged :))

@@ -332,3 +334,50 @@ func TestTaint(t *testing.T) {
}
}
}

func TestValidateFlags(t *testing.T) {
Copy link
Member

@jayunit100 jayunit100 Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is way cleaner, thanks ravi ,test looks good modulo description fixes

},
{
taintOpts: TaintOptions{selector: "", all: false, resources: []string{"node"}},
description: "With both selector and all flags and if node name is not provided",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix desc

@jayunit100
Copy link
Member

jayunit100 commented Apr 27, 2017

  • the fix seems to work
  • now I think the test is sufficient to prevent regressions now

so i guess lets move this forward and follow up on #44953 to mock these out properly for better kubectl tests........

PTAL @derekwaynecarr @aveshagarwal

@aveshagarwal
Copy link
Member

lgtm

@ravisantoshgudimetla ravisantoshgudimetla force-pushed the kubectl_taints_label_selector#44522 branch from 44b22fb to c52b4b0 Compare April 28, 2017 01:02
@ravisantoshgudimetla
Copy link
Contributor Author

@jayunit100 - PTAL, I have addressed your comments on descriptions.

@jayunit100
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 28, 2017
@ravisantoshgudimetla ravisantoshgudimetla force-pushed the kubectl_taints_label_selector#44522 branch from c52b4b0 to 081ba02 Compare April 28, 2017 14:28
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 28, 2017
@ravisantoshgudimetla
Copy link
Contributor Author

@jayunit100 I did a gofmt again. Can you please ask the bot test?

@ravisantoshgudimetla
Copy link
Contributor Author

and the unit tests seem to be a flake..

@jayunit100
Copy link
Member

@k8s-bot ok to test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 2, 2017
@ravisantoshgudimetla
Copy link
Contributor Author

#45170 - Flake..

@jayunit100
Copy link
Member

@k8s-bot unit test this please

@jayunit100
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 3, 2017
@jayunit100
Copy link
Member

@kubernetes/sig-cli-maintainers can we get an approve on this ? Thanks :)

@pwittrock
Copy link
Member

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jayunit100, pwittrock, ravisantoshgudimetla

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 5, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit cc1f9f7 into kubernetes:master May 5, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 5, 2017
@k8s-github-robot
Copy link

@ravisantoshgudimetla PR needs rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Label selector not supported in kubectl taint
10 participants