Skip to content

Commit f703da4

Browse files
author
OpenShift Bot
authored
Merge pull request #12062 from juanvallejo/jvallejo/add-request-timeout-val-to-oc-login-restclient
Merged by openshift-bot
2 parents 3b06cc0 + a684fe8 commit f703da4

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

pkg/cmd/cli/cmd/login/login.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
kapierrors "k8s.io/apimachinery/pkg/api/errors"
1313
"k8s.io/apimachinery/pkg/runtime/schema"
14+
kclientcmd "k8s.io/client-go/tools/clientcmd"
1415
kclientcmdapi "k8s.io/client-go/tools/clientcmd/api"
1516
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
1617
"k8s.io/kubernetes/pkg/util/term"
@@ -105,6 +106,13 @@ func (o *LoginOptions) Complete(f *osclientcmd.Factory, cmd *cobra.Command, args
105106
o.StartingKubeConfig = kclientcmdapi.NewConfig()
106107
}
107108

109+
unparsedTimeout := kcmdutil.GetFlagString(cmd, "request-timeout")
110+
timeout, err := kclientcmd.ParseTimeout(unparsedTimeout)
111+
if err != nil {
112+
return err
113+
}
114+
o.RequestTimeout = timeout
115+
108116
o.CommandName = commandName
109117
if o.CommandName == "" {
110118
o.CommandName = "oc"

pkg/cmd/cli/cmd/login/loginoptions.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"os"
1212
"path/filepath"
13+
"time"
1314

1415
kerrors "k8s.io/apimachinery/pkg/api/errors"
1516
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -66,7 +67,8 @@ type LoginOptions struct {
6667

6768
PathOptions *kclientcmd.PathOptions
6869

69-
CommandName string
70+
CommandName string
71+
RequestTimeout time.Duration
7072
}
7173

7274
// Gather all required information in a comprehensive order.
@@ -100,6 +102,11 @@ func (o *LoginOptions) getClientConfig() (*restclient.Config, error) {
100102

101103
clientConfig := &restclient.Config{}
102104

105+
// ensure clientConfig has timeout option
106+
if o.RequestTimeout > 0 {
107+
clientConfig.Timeout = o.RequestTimeout
108+
}
109+
103110
// normalize the provided server to a format expected by config
104111
serverNormalized, err := config.NormalizeServerURL(o.Server)
105112
if err != nil {

test/cmd/timeout.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ os::cmd::expect_success_and_text 'oc new-app node' 'Success'
1616
os::cmd::expect_success_and_text 'oc get dc node -w --request-timeout=1s 2>&1' 'Timeout exceeded while reading body'
1717
os::cmd::expect_success_and_text 'oc get dc node --request-timeout=1s' 'node'
1818
os::cmd::expect_success_and_text 'oc get dc node --request-timeout=1' 'node'
19+
os::cmd::expect_failure_and_text 'oc login -u testuser -p test --request-timeout=1ns' 'Timeout exceeded while awaiting headers'
1920

2021
echo "request-timeout: ok"
2122
os::test::junit::declare_suite_end

0 commit comments

Comments
 (0)