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

WIP: Refactor most of `kubectl drain` as a library #72827

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@errordeveloper
Copy link
Member

errordeveloper commented Jan 11, 2019

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Currently draining a node is only possible with kubectl drain. Other projects, e.g. cluster autoscaler and openshift have reinvented some of this code. This PR moves what can be moved easily from pkg/kubectl/cmd/drain into pkg/util/node/drain.

This is intended as a simple code move, there are no changes to in behaviour.

Does this PR introduce a user-facing change?:

NONE
return []corev1.Pod{}, errors.New(fs.Message())
}
if len(ws) > 0 {
fmt.Fprintf(o.ErrOut, "WARNING: %s\n", ws.Message())

This comment has been minimized.

@errordeveloper

errordeveloper Jan 11, 2019

Member

This is a little odd side-effect, I'll see if I can get rid of it easily.

@@ -640,7 +430,7 @@ func (o *DrainOptions) deletePods(pods []corev1.Pod, getPodFn func(namespace, na
return err
}

func (o *DrainOptions) waitForDelete(pods []corev1.Pod, interval, timeout time.Duration, usingEviction bool, getPodFn func(string, string) (*corev1.Pod, error)) ([]corev1.Pod, error) {
func (o *DrainCmdOptions) waitForDelete(pods []corev1.Pod, interval, timeout time.Duration, usingEviction bool, getPodFn func(string, string) (*corev1.Pod, error)) ([]corev1.Pod, error) {

This comment has been minimized.

@errordeveloper

errordeveloper Jan 11, 2019

Member

This function wants to write output a lot, I've not moved it cause I believe ideally libraries shouldn't write output. I've not figured out how alternative version of this would look like, and decide to not do that for the purpose of first PR.

@errordeveloper errordeveloper force-pushed the errordeveloper:drain-pkg branch from 150282e to 9963ebb Jan 11, 2019

@errordeveloper

This comment has been minimized.

Copy link
Member

errordeveloper commented Jan 11, 2019

/test pull-kubernetes-integration

@errordeveloper errordeveloper changed the title Refactor most of `kubectl drain` as a library WIP: Refactor most of `kubectl drain` as a library Jan 11, 2019

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

k8s-ci-robot commented Jan 11, 2019

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: errordeveloper
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: smarterclayton

If they are not already assigned, you can assign the PR to them by writing /assign @smarterclayton in a comment when ready.

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wking

This comment has been minimized.

Copy link
Contributor

wking commented Jan 12, 2019

It's going to take me a bit to work through the diff of this vs. openshift/kubernetes-drain, but just comparing the APIs, it looks like you've decided to not include (un)cordon functions? Are you expecting to do that in follow-up work? It seems like they'd be important for folks trying to use a drain library.

@errordeveloper

This comment has been minimized.

Copy link
Member

errordeveloper commented Jan 12, 2019

APIs, it looks like you've decided to not include (un)cordon functions? Are you expecting to do that in follow-up work?

Yes, indeed I am intending to do that. I also need those myself, of course.

@errordeveloper

This comment has been minimized.

Copy link
Member

errordeveloper commented Jan 12, 2019

It's going to take me a bit to work through the diff of this vs. openshift/kubernetes-drain

Have you tried to compare it to what's in master here in k/k now?

@wking

This comment has been minimized.

Copy link
Contributor

wking commented Jan 12, 2019

It's going to take me a bit to work through the diff of this vs. openshift/kubernetes-drain

Have you tried to compare it to what's in master here in k/k now?

From openshift/kubernetes-drain@2b21795, you can see that I split off from the then-current d43e1b3. Changes since then:

$ git describe --always origin/master
v1.14.0-alpha.0-1656-gdc6f3d6
$ git log --oneline --decorate d43e1b3..dc6f3d6 -- pkg/kubectl/cmd/drain.go
33adf36 Move each kubectl command to a separate directory
97b2992 Update gofmt for go1.11
fecb5ed Merge pull request #66266 from wking/kubectl-drain-drop-backOff
686f29f (origin/pr/69438) Merge pull request #66301 from wking/kubectl-drain-drop-typer
f008365 Merge pull request #68806 from seans3/legacy-scheme-update
ab993e3 (origin/pr/66266) kubectl: Drop backOff from DrainOptions
7a2a987 Move legacyscheme (internal version) to kubectl scheme (external version)
452615c (origin/pr/68767) Fix drain for evicting terminal DS pods and pods with local storage
967280b (origin/pr/68069) Add --server-dry-run flag to `kubectl apply`
5b55e1f (origin/pr/67658) Create cli-runtime staging repository
0d81e83 (origin/pr/66301) kubectl: Drop typer from DrainOptions

#66266 and #66301 ported some of my downstream changes back upstream here. I'll take a close look at #68767, #68806, and the others when I get a moment.

@errordeveloper errordeveloper force-pushed the errordeveloper:drain-pkg branch 4 times, most recently from 6c1298a to 3a1dbf4 Jan 12, 2019

@errordeveloper errordeveloper force-pushed the errordeveloper:drain-pkg branch from 3a1dbf4 to 5a40f5a Jan 12, 2019

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

k8s-ci-robot commented Jan 12, 2019

@errordeveloper: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-bazel-test 5a40f5a link /test pull-kubernetes-bazel-test
pull-kubernetes-integration 5a40f5a link /test pull-kubernetes-integration
pull-kubernetes-verify 5a40f5a link /test pull-kubernetes-verify

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.

@errordeveloper

This comment has been minimized.

Copy link
Member

errordeveloper commented Jan 14, 2019

I am really not sure why this error appears in tests:

            error: unable to cordon node "node": no kind "Node" is registered for the internal version of group "" in scheme "pkg/kubectl/scheme/scheme.go:28"

I assume it breaks tests as output has changed, but I worry that the above error was there before this change.

@neolit123

This comment has been minimized.

Copy link
Member

neolit123 commented Jan 14, 2019

/priority important-longterm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment