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

Fix kubectl drain --timeout option when eviction is used #64378

Merged
merged 1 commit into from
Jun 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/kubectl/cmd/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ func (o *DrainOptions) evictPods(pods []corev1.Pod, policyGroupVersion string, g
} else {
globalTimeout = o.Timeout
}
globalTimeoutCh := time.After(globalTimeout)
for {
select {
case err := <-errCh:
Expand All @@ -619,7 +620,7 @@ func (o *DrainOptions) evictPods(pods []corev1.Pod, policyGroupVersion string, g
if doneCount == len(pods) {
return nil
}
case <-time.After(globalTimeout):
case <-globalTimeoutCh:
Copy link
Member

Choose a reason for hiding this comment

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

Does it make any difference with the previous implementation?

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, in the previous implementation it's basically a timeout per pod.

Run the following code locally and notice it never ends because the timer gets reset on each for loop iteration: https://play.golang.org/p/uq1I8nLx5Af

Copy link
Member

Choose a reason for hiding this comment

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

The length of time to wait before giving up, zero means infinite

Umm, yes. The timeout here refreshes every time when a pod is successfully evicted which is inconsistent with the docs.

return fmt.Errorf("Drain did not complete within %v", globalTimeout)
}
}
Expand Down