Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
e78053e2
Unverified
Commit
e78053e2
authored
Feb 12, 2024
by
Derek Nola
Committed by
GitHub
Feb 12, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Release-1.26] Enable longer http timeout requests (#9446)
Signed-off-by:
Derek Nola
<
derek.nola@suse.com
>
parent
62448e1e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
7 deletions
+21
-7
token.go
pkg/clientaccess/token.go
+21
-7
No files found.
pkg/clientaccess/token.go
View file @
e78053e2
...
...
@@ -41,6 +41,9 @@ var (
}
)
// ClientOption is a callback to mutate the http client prior to use
type
ClientOption
func
(
*
http
.
Client
)
// Info contains fields that track parsed parts of a cluster join token
type
Info
struct
{
*
kubeadm
.
BootstrapTokenString
...
...
@@ -233,7 +236,7 @@ func parseToken(token string) (*Info, error) {
// If the CA bundle is not empty but does not contain any valid certs, it validates using
// an empty CA bundle (which will always fail).
// If valid cert+key paths can be loaded from the provided paths, they are used for client cert auth.
func
GetHTTPClient
(
cacerts
[]
byte
,
certFile
,
keyFile
string
)
*
http
.
Client
{
func
GetHTTPClient
(
cacerts
[]
byte
,
certFile
,
keyFile
string
,
option
...
ClientOption
)
*
http
.
Client
{
if
len
(
cacerts
)
==
0
{
return
defaultClient
}
...
...
@@ -250,18 +253,29 @@ func GetHTTPClient(cacerts []byte, certFile, keyFile string) *http.Client {
if
err
==
nil
{
tlsConfig
.
Certificates
=
[]
tls
.
Certificate
{
cert
}
}
return
&
http
.
Client
{
client
:=
&
http
.
Client
{
Timeout
:
defaultClientTimeout
,
Transport
:
&
http
.
Transport
{
DisableKeepAlives
:
true
,
TLSClientConfig
:
tlsConfig
,
},
}
for
_
,
o
:=
range
option
{
o
(
client
)
}
return
client
}
func
WithTimeout
(
d
time
.
Duration
)
ClientOption
{
return
func
(
c
*
http
.
Client
)
{
c
.
Timeout
=
d
c
.
Transport
.
(
*
http
.
Transport
)
.
ResponseHeaderTimeout
=
d
}
}
// Get makes a request to a subpath of info's BaseURL
func
(
i
*
Info
)
Get
(
path
string
)
([]
byte
,
error
)
{
func
(
i
*
Info
)
Get
(
path
string
,
option
...
ClientOption
)
([]
byte
,
error
)
{
u
,
err
:=
url
.
Parse
(
i
.
BaseURL
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -272,11 +286,11 @@ func (i *Info) Get(path string) ([]byte, error) {
}
p
.
Scheme
=
u
.
Scheme
p
.
Host
=
u
.
Host
return
get
(
p
.
String
(),
GetHTTPClient
(
i
.
CACerts
,
i
.
CertFile
,
i
.
KeyFile
),
i
.
Username
,
i
.
Password
,
i
.
Token
())
return
get
(
p
.
String
(),
GetHTTPClient
(
i
.
CACerts
,
i
.
CertFile
,
i
.
KeyFile
,
option
...
),
i
.
Username
,
i
.
Password
,
i
.
Token
())
}
// Put makes a request to a subpath of info's BaseURL
func
(
i
*
Info
)
Put
(
path
string
,
body
[]
byte
)
error
{
func
(
i
*
Info
)
Put
(
path
string
,
body
[]
byte
,
option
...
ClientOption
)
error
{
u
,
err
:=
url
.
Parse
(
i
.
BaseURL
)
if
err
!=
nil
{
return
err
...
...
@@ -287,7 +301,7 @@ func (i *Info) Put(path string, body []byte) error {
}
p
.
Scheme
=
u
.
Scheme
p
.
Host
=
u
.
Host
return
put
(
p
.
String
(),
body
,
GetHTTPClient
(
i
.
CACerts
,
i
.
CertFile
,
i
.
KeyFile
),
i
.
Username
,
i
.
Password
,
i
.
Token
())
return
put
(
p
.
String
(),
body
,
GetHTTPClient
(
i
.
CACerts
,
i
.
CertFile
,
i
.
KeyFile
,
option
...
),
i
.
Username
,
i
.
Password
,
i
.
Token
())
}
// setServer sets the BaseURL and CACerts fields of the Info by connecting to the server
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment