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

Changes for typecasting node in drain #48082

Conversation

ravisantoshgudimetla
Copy link
Contributor

@ravisantoshgudimetla ravisantoshgudimetla commented Jun 26, 2017

What this PR does / why we need it:

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

Special notes for your reviewer:
Precursor to #44944

Release note:

kubectl drain now uses PATCH instead of PUT to update the node. The node object is now of type v1 instead of using internal api.

@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 /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.

I understand the commands that are listed here.

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 Jun 26, 2017
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Jun 26, 2017
@ravisantoshgudimetla
Copy link
Contributor Author

/cc @mml
/sig cli

@k8s-ci-robot k8s-ci-robot requested a review from mml June 26, 2017 18:00
@k8s-ci-robot k8s-ci-robot added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Jun 26, 2017
@ravisantoshgudimetla ravisantoshgudimetla force-pushed the kubectl_drain_node_conversion branch 3 times, most recently from 205e77c to 16970e4 Compare June 26, 2017 18:15
oldData, err := json.Marshal(obj)
node, ok := obj.(*v1.Node)
if !ok {
fmt.Println("Here Type%T", obj)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this print for debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is, thanks for pointing. I will remove this.

@shiywang
Copy link
Contributor

/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 Jun 27, 2017
@ravisantoshgudimetla
Copy link
Contributor Author

@shiywang Thanks for reviewing, I wanted to check if the change is ok. If it is, I will proceed with build generation after which the tests should be passing.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 27, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 27, 2017
@ravisantoshgudimetla ravisantoshgudimetla force-pushed the kubectl_drain_node_conversion branch 3 times, most recently from 45d9d43 to 92d621a Compare June 27, 2017 20:42
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2017
@ravisantoshgudimetla
Copy link
Contributor Author

@shiywang This is ready for another round of review. Can you please let me know, if you have any other comments?

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 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 Jul 8, 2017
@@ -43,7 +47,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubelet/types"
ktypes "k8s.io/kubernetes/pkg/kubelet/types"
Copy link
Member

Choose a reason for hiding this comment

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

This dependency should be gone after rebase.

@ravisantoshgudimetla ravisantoshgudimetla force-pushed the kubectl_drain_node_conversion branch 2 times, most recently from 56e644e to a147060 Compare July 12, 2017 16:48
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 12, 2017
@ravisantoshgudimetla ravisantoshgudimetla force-pushed the kubectl_drain_node_conversion branch 2 times, most recently from 3ed161f to c3137ee Compare July 12, 2017 17:41
@ravisantoshgudimetla
Copy link
Contributor Author

@mengqiy I have rebased the file. Any other changes needed?

if createdPatch {
_, err = helper.Patch(cmdNamespace, o.nodeInfo.Name, types.StrategicMergePatchType, patchBytes)
} else {
_, err := helper.Replace(cmdNamespace, o.nodeInfo.Name, false, obj)
Copy link
Member

Choose a reason for hiding this comment

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

Don't shadow this error. Or I will return the wrong error.

@@ -17,11 +17,11 @@ limitations under the License.
package cmd

import (
"encoding/json"
Copy link
Member

Choose a reason for hiding this comment

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

Please use "k8s.io/apimachinery/pkg/util/json", even though it doesn't have any difference when you only do marshal.

@@ -32,12 +32,13 @@ import (
"time"

"github.com/spf13/cobra"
Copy link
Member

Choose a reason for hiding this comment

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

Add a new line here.

if createdPatch {
_, err = helper.Patch(cmdNamespace, o.nodeInfo.Name, types.StrategicMergePatchType, patchBytes)
} else {
_, err := helper.Replace(cmdNamespace, o.nodeInfo.Name, false, obj)
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to overwrite any more?
It used to be Replace(cmdNamespace, o.nodeInfo.Name, true, o.nodeInfo.Object)

Why cannot we switch to PATCH completely? It should not have any backward compatibility issue. Any other concerns?

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, I had this impression of Replace being an alternate to Patch in case it fails but didn't want it to overwrite and I wasn't sure if it is completely backward compatible but I will remove it completely now.

// It's a race, no need to sleep
newData, err := json.Marshal(obj)
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, obj)
createdPatch := err == nil
Copy link
Member

Choose a reason for hiding this comment

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

Error handling can be simplified here. It seems we don't need createdPatch any 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.

Thanks for correction. I just copied it from taints code. Deleted that now.

Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

One last nit

patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, obj)
if err != nil {
return err
} else {
Copy link
Member

Choose a reason for hiding this comment

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

This else can be dropped as well.

patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, obj)
if err != nil {
  return err
}
_, err = helper.Patch(cmdNamespace, o.nodeInfo.Name, types.StrategicMergePatchType, patchBytes)
if err != nil {
  return err
}

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. Thanks again :)

@ravisantoshgudimetla
Copy link
Contributor Author

/test pull-kubernetes-node-e2e

@mengqiy
Copy link
Member

mengqiy commented Jul 13, 2017

I think we need a release note saying that kubectl drain now uses PATCH instead of PUT to update the node.

@mengqiy
Copy link
Member

mengqiy commented Jul 13, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 13, 2017
@fabianofranz
Copy link
Contributor

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabianofranz, mengqiy, ravisantoshgudimetla

Associated issue: 48059

The full list of commands accepted by this bot can be found here.

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 Jul 13, 2017
@ravisantoshgudimetla
Copy link
Contributor Author

/test pull-kubernetes-federation-e2e-gce

@ravisantoshgudimetla
Copy link
Contributor Author

/retest

1 similar comment
@ravisantoshgudimetla
Copy link
Contributor Author

/retest

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 48082, 48815, 48901, 48824)

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-none Denotes a PR that doesn't merit a release note. sig/cli Categorizes an issue or PR as relevant to SIG CLI. 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.

kubectl drain needs to be typecasted to node object instead of using Values after introspection.
8 participants