-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
Kubectl taint node based on label selector #44740
Conversation
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 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. |
Thanks @ravisantoshgudimetla this works for me :)
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). |
/cc @jayunit100.
|
75a5941
to
3a60861
Compare
@k8s-bot test this please |
pkg/kubectl/cmd/taint.go
Outdated
if o.all { | ||
o.builder = o.builder.SelectAllParam(o.all).ResourceTypes("node") | ||
} else { | ||
if len(o.resources) < 2 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/kubectl/cmd/taint.go
Outdated
kubectl taint nodes foo dedicated- | ||
|
||
# Add from node 'foo' all the taints with key 'dedicated' | ||
kubectl taint nodes foo dedicated- |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@kubernetes/sig-cli-pr-reviews ptal |
ec3ce3c
to
4017ccc
Compare
@aveshagarwal PTAL. |
@ravisantoshgudimetla lgtm, now need to figure out the issue with your unit test. |
@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. |
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 |
@derekwaynecarr Thanks for the pointer regarding test case. I will check that and get back in case I am stuck. |
@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. |
@derekwaynecarr @ravisantoshgudimetla ok so sounds like to move forward, we have to do two things...
(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) { |
There was a problem hiding this comment.
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
pkg/kubectl/cmd/taint_test.go
Outdated
}, | ||
{ | ||
taintOpts: TaintOptions{selector: "", all: false, resources: []string{"node"}}, | ||
description: "With both selector and all flags and if node name is not provided", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix desc
so i guess lets move this forward and follow up on #44953 to mock these out properly for better kubectl tests........ |
lgtm |
44b22fb
to
c52b4b0
Compare
@jayunit100 - PTAL, I have addressed your comments on descriptions. |
/lgtm |
c52b4b0
to
081ba02
Compare
@jayunit100 I did a gofmt again. Can you please ask the bot test? |
and the unit tests seem to be a flake.. |
@k8s-bot ok to test |
#45170 - Flake.. |
@k8s-bot unit test this please |
/lgtm |
@kubernetes/sig-cli-maintainers can we get an approve on this ? Thanks :) |
/approve |
[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 |
Automatic merge from submit-queue |
@ravisantoshgudimetla PR needs rebase |
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #44522Release note: