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
710bfb44
Unverified
Commit
710bfb44
authored
Nov 05, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70606 from mikedanese/tfreload
periodically reload tokens read from TokenFile in kubeconfig
parents
5960971e
718adb74
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
6 deletions
+22
-6
config.go
staging/src/k8s.io/client-go/rest/config.go
+1
-1
token_source.go
staging/src/k8s.io/client-go/rest/token_source.go
+3
-1
client_config.go
...ing/src/k8s.io/client-go/tools/clientcmd/client_config.go
+3
-3
client_config_test.go
...rc/k8s.io/client-go/tools/clientcmd/client_config_test.go
+15
-1
No files found.
staging/src/k8s.io/client-go/rest/config.go
View file @
710bfb44
...
@@ -322,7 +322,7 @@ func InClusterConfig() (*Config, error) {
...
@@ -322,7 +322,7 @@ func InClusterConfig() (*Config, error) {
return
nil
,
ErrNotInCluster
return
nil
,
ErrNotInCluster
}
}
ts
:=
newCachedPath
TokenSource
(
tokenFile
)
ts
:=
NewCachedFile
TokenSource
(
tokenFile
)
if
_
,
err
:=
ts
.
Token
();
err
!=
nil
{
if
_
,
err
:=
ts
.
Token
();
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
staging/src/k8s.io/client-go/rest/token_source.go
View file @
710bfb44
...
@@ -42,7 +42,9 @@ func TokenSourceWrapTransport(ts oauth2.TokenSource) func(http.RoundTripper) htt
...
@@ -42,7 +42,9 @@ func TokenSourceWrapTransport(ts oauth2.TokenSource) func(http.RoundTripper) htt
}
}
}
}
func
newCachedPathTokenSource
(
path
string
)
oauth2
.
TokenSource
{
// NewCachedFileTokenSource returns a oauth2.TokenSource reads a token from a
// file at a specified path and periodically reloads it.
func
NewCachedFileTokenSource
(
path
string
)
oauth2
.
TokenSource
{
return
&
cachingTokenSource
{
return
&
cachingTokenSource
{
now
:
time
.
Now
,
now
:
time
.
Now
,
leeway
:
1
*
time
.
Minute
,
leeway
:
1
*
time
.
Minute
,
...
...
staging/src/k8s.io/client-go/tools/clientcmd/client_config.go
View file @
710bfb44
...
@@ -229,11 +229,11 @@ func (config *DirectClientConfig) getUserIdentificationPartialConfig(configAuthI
...
@@ -229,11 +229,11 @@ func (config *DirectClientConfig) getUserIdentificationPartialConfig(configAuthI
if
len
(
configAuthInfo
.
Token
)
>
0
{
if
len
(
configAuthInfo
.
Token
)
>
0
{
mergedConfig
.
BearerToken
=
configAuthInfo
.
Token
mergedConfig
.
BearerToken
=
configAuthInfo
.
Token
}
else
if
len
(
configAuthInfo
.
TokenFile
)
>
0
{
}
else
if
len
(
configAuthInfo
.
TokenFile
)
>
0
{
t
okenBytes
,
err
:=
ioutil
.
ReadFil
e
(
configAuthInfo
.
TokenFile
)
t
s
:=
restclient
.
NewCachedFileTokenSourc
e
(
configAuthInfo
.
TokenFile
)
if
err
!=
nil
{
if
_
,
err
:=
ts
.
Token
();
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
mergedConfig
.
BearerToken
=
string
(
tokenByte
s
)
mergedConfig
.
WrapTransport
=
restclient
.
TokenSourceWrapTransport
(
t
s
)
}
}
if
len
(
configAuthInfo
.
Impersonate
)
>
0
{
if
len
(
configAuthInfo
.
Impersonate
)
>
0
{
mergedConfig
.
Impersonate
=
restclient
.
ImpersonationConfig
{
mergedConfig
.
Impersonate
=
restclient
.
ImpersonationConfig
{
...
...
staging/src/k8s.io/client-go/tools/clientcmd/client_config_test.go
View file @
710bfb44
...
@@ -18,12 +18,14 @@ package clientcmd
...
@@ -18,12 +18,14 @@ package clientcmd
import
(
import
(
"io/ioutil"
"io/ioutil"
"net/http"
"os"
"os"
"reflect"
"reflect"
"strings"
"strings"
"testing"
"testing"
"github.com/imdario/mergo"
"github.com/imdario/mergo"
restclient
"k8s.io/client-go/rest"
restclient
"k8s.io/client-go/rest"
clientcmdapi
"k8s.io/client-go/tools/clientcmd/api"
clientcmdapi
"k8s.io/client-go/tools/clientcmd/api"
)
)
...
@@ -332,7 +334,19 @@ func TestBasicTokenFile(t *testing.T) {
...
@@ -332,7 +334,19 @@ func TestBasicTokenFile(t *testing.T) {
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
matchStringArg
(
token
,
clientConfig
.
BearerToken
,
t
)
var
out
*
http
.
Request
clientConfig
.
WrapTransport
(
fakeTransport
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
out
=
req
return
&
http
.
Response
{},
nil
}))
.
RoundTrip
(
&
http
.
Request
{})
matchStringArg
(
token
,
strings
.
TrimPrefix
(
out
.
Header
.
Get
(
"Authorization"
),
"Bearer "
),
t
)
}
type
fakeTransport
func
(
*
http
.
Request
)
(
*
http
.
Response
,
error
)
func
(
ft
fakeTransport
)
RoundTrip
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
return
ft
(
req
)
}
}
func
TestPrecedenceTokenFile
(
t
*
testing
.
T
)
{
func
TestPrecedenceTokenFile
(
t
*
testing
.
T
)
{
...
...
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