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

Refactoring reorganize taints function in kubectl to expose operations #43171

Merged

Conversation

ravisantoshgudimetla
Copy link
Contributor

@ravisantoshgudimetla ravisantoshgudimetla commented Mar 15, 2017

What this PR does / why we need it:
This adds some UX functionality when specifying taints using kubectl.
For example:

./kubectl.sh taint nodes XYZ dedicated1=abca2:NoSchedule 
node "XYZ" tainted
 ./kubectl.sh taint nodes XYZ dedicated1=abca1:NoSchedule --overwrite=True
node "XYZ overwritten
./kubectl.sh taint nodes XYZ dedicated1-
node "XYZ" untainted
./kubectl.sh taint nodes XYZ dedicated=abca1:NoSchedule dedicated1-
node "XYZ" modified

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

Release note:

Fixed the output of kubectl taint node command with minor improvements.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 15, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed labels Mar 15, 2017
@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.

@ravisantoshgudimetla
Copy link
Contributor Author

/cc @jayunit100.

@k8s-reviewable
Copy link

This change is Reviewable

@ravisantoshgudimetla ravisantoshgudimetla changed the title Refactoring reorganize taints function to expose operations Refactoring reorganize taints function in kubectl to expose operations Mar 15, 2017
@ravisantoshgudimetla
Copy link
Contributor Author

@smarterclayton PTAL.

@ethernetdan
Copy link
Contributor

@k8s-bot ok to test

@ravisantoshgudimetla
Copy link
Contributor Author

@fabianofranz - As I not able to mention sig-cli and sig-cli-pr-reviewers.

@fabianofranz
Copy link
Contributor

@kubernetes/sig-cli-pr-reviews

@ravisantoshgudimetla
Copy link
Contributor Author

@fabianofranz I just wanted to make sure if this PR can be reviewed as 1.6 code freeze has officially ended.
P.S:, Should I be a member to mention sig-cli-pr reviewers?

@@ -366,23 +382,20 @@ func validateNoTaintOverwrites(obj runtime.Object, taints []v1.Taint) error {
}

// updateTaints updates taints of obj
Copy link
Member

Choose a reason for hiding this comment

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

can we improve this comment as part of this PR? the fact that its validating, and reorganizing, ... not sure what 'update' really is doing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am just reorganizing in this PR. I will create one more with some other modifications.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the comment here. There's no point of having separate PR for that - we want to keep review load as low as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't see fixed comment...

Copy link
Member

Choose a reason for hiding this comment

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

@ravisantoshgudimetla updateTaints applies taints to a node in a clusters and returns a human understandable description of the resulting operation.

return allErrs, taintsBefore != len(*newTaints)
}

// AddTaints adds the newTaints list to existing ones and updates the newTaints List.
Copy link
Member

Choose a reason for hiding this comment

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

s/AddTaints/addTaints for godoc . surprised this isnt caught by golint actually...

allErrs := []error{}
taintsBefore := len(*newTaints)
for _, taintToRemove := range taintsToRemove {
removed := false
if len(taintToRemove.Effect) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we can make this taintToRemove.Effect != "" ? Otherwise seems to imply that there can be multiple effects....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When can do that but the problem is Effect here is a type again. So this is the convention that others have been using in other locations as well.

Copy link
Member

Choose a reason for hiding this comment

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

can you clarify Effect here is type again ? If != works it seems like a better comparison.

}
if !removed {
allErrs = append(allErrs, fmt.Errorf("taint %q not found", taintToRemove.ToString()))
}
}
return newTaints, utilerrors.NewAggregate(allErrs)
return allErrs, taintsBefore != len(*newTaints)
Copy link
Member

@jayunit100 jayunit100 Mar 24, 2017

Choose a reason for hiding this comment

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

is this redundant to saying return allErrs, len(allErrs) > 0? if so i'd say just return []error as the function header , rather then []error, bool.

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, here the errors are different and taints are different, we are returning errors as well as checking if the original length of taints list is equal to old length of taints to check if some of them got deleted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the latter equivalent to removed, i.e. it's always true if we reached this part of the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess not, if we do not enter the loop in first place, we cannot return true and 'removed' variable is declared inside loop. So, if we have removed outside loop, then I guess we can.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair point. I think such change would make the code cleaner.

@jayunit100
Copy link
Member

lgtm but im not an owner for this section

@aveshagarwal
Copy link
Member

This adds some UX functionality when specifying taints using kubectl.
For example:
./kubectl.sh taint nodes XYZ dedicated1=abca2:NoSchedule
node "XYZ" tainted
./kubectl.sh taint nodes XYZ dedicated1=abca1:NoSchedule --overwrite=True
node "XYZ overwritten
./kubectl.sh taint nodes XYZ dedicated1-
node "XYZ" untainted

The above one seem a bit confusing as there might still be other taints left.

./kubectl.sh taint nodes XYZ dedicated=abca1:NoSchedule dedicated1-
node "XYZ" modified

In general, I am wondering how these UI changes are going to be helpful? May be I am missing something?

Also there are several possibilities I am not sure these UI changes cover all of them:

On one or multiple nodes:

  1. Addition of new taints (one or multiple)
  2. Deletion of existing taints (one or multiple)
  3. Modification/Updates/Overwritten of existing taints (one or multiple)
  4. And a combination of above operations.

@ravisantoshgudimetla
Copy link
Contributor Author

So the composite operations(which are complementary like adding taints and deleting them) in a single command will always result in "modified" output, if the composite operations are non-complementary(in this case addition of multiple taints or removal of them) will always result in either "tainted" or "untainted".

If you have atleast one overwritten operation, the output will be "overwritten".

This is something that I came up with but if you have other suggestions, I am more than happy to include.

@jayunit100
Copy link
Member

jayunit100 commented Mar 30, 2017

@aveshagarwal do you agree that we should provide more feedback ? or you think just saying 'tainted' is enough.

  • I see your point that some of this is not super informative,

But

  • i think 'tainted','modified','untainted', etc... is better then just returning tainted every time.

So

  • If the goal is to just return tainted every time , then i guess we can close this PR.
  • If the goal is to return more information, lets decide in the parent issue what the expected output should be kubectl reporting wrong for taints. #43167 , and then ravi can reimplement it here.

@davidopp
Copy link
Member

@kubernetes/sig-scheduling-pr-reviews

@timothysc timothysc added the sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. label Apr 3, 2017
@timothysc timothysc added this to the v1.7 milestone Apr 3, 2017
@timothysc timothysc added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Apr 3, 2017
@@ -40,6 +40,13 @@ import (
utiltaints "k8s.io/kubernetes/pkg/util/taints"
)

const (
MODIFIED = "modified"
Copy link
Member

Choose a reason for hiding this comment

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

These should not be here.
They should either be in a scheduling library or near the api itself.

Copy link
Member

@jayunit100 jayunit100 Apr 3, 2017

Choose a reason for hiding this comment

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

To decide where the right place is, we should decide: what is this describing .... I guess maybe we could satisfy tim's suggestion by making this more localized.

  • localize the definitions If this is describing a kubelet result, then I guess putting them here and making them more descriptive is ok, i.e
MODIFICATION="taint was modified"
UNTAINTED="taint was removed"

... and so on, we can isolate the semantics unambiguously to kubectl so that this doesn't blur the lines between API constants and UX constants.

  • In addition, we should unexport these (i.e. s/MODIFIED/modified).

I think (1) + (2) might make this less 'sprawly'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timothysc These are the constants that are being used in output of kubectl, doesn't it make sense to have them here instead of API?
@jayunit100 This gets appended to 'node 'XYZ' from printSuccess at https://github.com/kubernetes/kubernetes/pull/43171/files#diff-92dd749c11309adffd4b2b2112b36303R364. I guess a better way would be to remove 'node 'XYZ' ' part when printing and tell if the taint was added or deleted. I guess that will be a different PR but if you want it, I can include it here.

Copy link
Member

@jayunit100 jayunit100 Apr 3, 2017

Choose a reason for hiding this comment

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

I think we can all agree these constants shouldnt be exported , if they are going to be specific to kubectl result processing, then i think thats ok. as of now they are higher level then that , which is why tim has mentioned they shouldn't be here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wherever we decide to put it, I think we should just use standard verbs: Added, Removed, Modified.

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 17, 2017
@ravisantoshgudimetla
Copy link
Contributor Author

@k82cn Apologies for the confusion. I was trying to access files from another machine and messed up my git history. There is no generated code in my case as I am touching a single file :).

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 17, 2017
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Apr 17, 2017

@ravisantoshgudimetla: The following test(s) failed:

Test name Commit Details Rerun command
pull-kubernetes-cross e8966112ab50976952a08761b90ec71815cd2119 link @k8s-bot pull-kubernetes-cross test this

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 17, 2017
@@ -366,24 +379,21 @@ func validateNoTaintOverwrites(obj runtime.Object, taints []v1.Taint) error {
return utilerrors.NewAggregate(allErrs)
}

// updateTaints updates taints of obj
func (o TaintOptions) updateTaints(obj runtime.Object) error {
// updateTaints applies a taint option(o) to a node in cluster after validating conditions like overwriting of option and returns a human understandable description of the said option result.
Copy link
Member

Choose a reason for hiding this comment

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

+// updateTaints applies a taint option (o) to a node in the cluster, and after computing the net effect of the operation (i.e. does it result in an overwrite?), it reports the end result back in a way that a user can easily interpret.

@jayunit100
Copy link
Member

@gmarek @timothysc @adohe PTAL , LGTM on my end.

@jayunit100
Copy link
Member

bump :)

@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 20, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jayunit100, ravisantoshgudimetla
We suggest the following additional approver: @fabianofranz

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

@jayunit100
Copy link
Member

Ping @sig-cli-maintainers this one is ready to merge now, reached consensus.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

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. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubectl reporting wrong for taints.