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

Add global timeout flag #33958

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Oct 3, 2016

Release note:

Add a new global option "--request-timeout" to the `kubectl` client

UPSTREAM: kubernetes/client-go#10

This patch adds a global timeout flag (viewable with kubectl -h) with
a default value of 0s (meaning no timeout).

The timeout value is added to the default http client, so that zero
values and default behavior are enforced by the client.

Adding a global timeout ensures that user-made scripts won't hang for an
indefinite amount of time while performing remote calls (right now, remote
calls are re-tried up to 10 times when each attempt fails, however, there is
no option to set a timeout in order to prevent any of these 10 attempts from
hanging indefinitely).

Example

$ kubectl get pods # no timeout flag set - default to 0s (which means no
timeout)
NAME                      READY     STATUS    RESTARTS   AGE
docker-registry-1-h7etw   1/1       Running   1          2h
router-1-uv0f9            1/1       Running   1          2h

$ kubectl get pods --request-timeout=0 # zero means no timeout no timeout flag set
NAME                      READY     STATUS    RESTARTS   AGE
docker-registry-1-h7etw   1/1       Running   1          2h
router-1-uv0f9            1/1       Running   1          2h

$kubectl get pods --request-timeout=1ms
Unable to connect to the server: net/http: request canceled while
waiting for connection (Client.Timeout exceeded while awaiting headers)

This change is Reviewable

@k8s-ci-robot
Copy link
Contributor

Can a kubernetes member verify that this patch is reasonable to test? If so, please reply with "@k8s-bot ok to test" on its own line.

Regular contributors should join the org to skip this step.

@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 Oct 3, 2016
@@ -91,7 +91,7 @@ func NewCmdRollingUpdate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
}
cmd.Flags().Duration("update-period", updatePeriod, `Time to wait between updating pods. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`)
cmd.Flags().Duration("poll-interval", pollInterval, `Time delay between polling for replication controller status after the update. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`)
cmd.Flags().Duration("timeout", timeout, `Max time to wait for a replication controller to update before giving up. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`)
Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot change these flag names without breaking existing scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted local flag names back to timeout. Updated global flag to --request-timeout 396551b

@0xmichalis
Copy link
Contributor

cc: @kubernetes/kubectl

@juanvallejo
Copy link
Contributor Author

@deads2k or @fabianofranz could you take a look please?

@@ -121,6 +138,7 @@ const (
FlagImpersonate = "as"
FlagUsername = "username"
FlagPassword = "password"
FlagTimeout = "request-timeout"
Copy link
Contributor

Choose a reason for hiding this comment

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

@kubernetes/kubectl Any comments on the flag name? --timeout was already take by commands that use reapers for a different meaning.

Copy link

Choose a reason for hiding this comment

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

request-timeout sounds good to me.

@deads2k
Copy link
Contributor

deads2k commented Oct 5, 2016

Squash and lgtm.

I'll leave it open a day for comments on the flag name.

@deads2k
Copy link
Contributor

deads2k commented Oct 5, 2016

Oh, and test-cmd test. A kubectl get -w --request-timeout ought to return, right?

@juanvallejo
Copy link
Contributor Author

@deads2k

A kubectl get -w --request-timeout ought to return, right?

Yes, when using the default 0 value, it behaves as usual (watches a resource until a user terminates the process).

When used with a non-zero request-timeout value, it does timeout after the time specified:

$ oc get pod zookeeper-1 -w --request-timeout=10s
NAME          READY     STATUS    RESTARTS   AGE
zookeeper-1   1/1       Running   2          6h

After 10s, the complete output from the command above is:

NAME          READY     STATUS    RESTARTS   AGE
zookeeper-1   1/1       Running   2          6h
E1005 15:50:25.125415   11319 streamwatcher.go:109] Unable to decode an event from the watch stream: net/http: request canceled (Client.Timeout exceeded while reading body)

@deads2k
Copy link
Contributor

deads2k commented Oct 5, 2016

Yes, when using the default 0 value, it behaves as usual (watches a resource until a user terminates the process).

Right, just pointed that out for your test-cmd.sh test.

@juanvallejo juanvallejo force-pushed the jvallejo/add-global-timeout-flag branch from 396551b to 5933816 Compare October 5, 2016 20:27
@adohe-zz
Copy link

adohe-zz commented Oct 6, 2016

@juanvallejo any priority between local timeout flag and global flag?

@soltysh
Copy link
Contributor

soltysh commented Oct 6, 2016

@juanvallejo any priority between local timeout flag and global flag?

I guess, since request-timeout is applied at transport layer it'll have priority over local timeout, which is usually applied to a bigger chunk of operation (ie. for reapers it's applied while waiting for scale down operation).

The changes LGTM, but since this is a new feature, release not is needed @juanvallejo,

@juanvallejo
Copy link
Contributor Author

Thanks for the feedback, release note added!

@juanvallejo juanvallejo force-pushed the jvallejo/add-global-timeout-flag branch from 5933816 to 778e57e Compare October 6, 2016 14:17
@soltysh soltysh added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Oct 6, 2016
@soltysh
Copy link
Contributor

soltysh commented Oct 6, 2016

If there are no objections I'm gonna tag it for merge later today.

@soltysh
Copy link
Contributor

soltysh commented Oct 6, 2016

@k8s-bot ok to test

@soltysh
Copy link
Contributor

soltysh commented Oct 6, 2016

Flake #32430

@k8s-bot node e2e test this

@@ -105,6 +108,20 @@ func (f FlagInfo) BindBoolFlag(flags *pflag.FlagSet, target *bool) {
}
}

// BindDurationFlag binds the flag based on the provided info. If LongName == "", nothing is registered
func (f FlagInfo) BindDurationFlag(flags *pflag.FlagSet, target *time.Duration) {
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 believe --request-timeout should support values without units, which defaults to seconds like every other timeout flag out there. Like in ssh, timeout, scp, curl, and so on.

You'd probably have to use string and parse it by yourself like in here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Like --request-timeout=30 is the first thing I'll try.

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 for providing the example

@juanvallejo juanvallejo force-pushed the jvallejo/add-global-timeout-flag branch from 778e57e to 1742dc5 Compare October 6, 2016 21:50
@fabianofranz
Copy link
Contributor

LGTM

@soltysh
Copy link
Contributor

soltysh commented Oct 7, 2016

@juanvallejo can you look into those test failures and link to flakes?

@soltysh soltysh added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 7, 2016
@juanvallejo juanvallejo force-pushed the jvallejo/add-global-timeout-flag branch from 1742dc5 to 10571e3 Compare October 7, 2016 17:20
@caesarxuchao caesarxuchao self-assigned this Oct 15, 2016
@caesarxuchao caesarxuchao added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 15, 2016
@caesarxuchao
Copy link
Member

LGTM. Thanks!

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit c0bd6e8 into kubernetes:master Oct 15, 2016
@juanvallejo juanvallejo deleted the jvallejo/add-global-timeout-flag branch October 17, 2016 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. 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.

None yet

10 participants