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
49a6b629
Commit
49a6b629
authored
Jun 08, 2015
by
krousey
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9171 from jdef/parse_prefix_from_server
parse apiserver prefix from client config host spec
parents
cf741e0c
4b8995f0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
1 deletion
+76
-1
client_config.go
pkg/client/clientcmd/client_config.go
+8
-0
client_config_test.go
pkg/client/clientcmd/client_config_test.go
+39
-1
config_test.go
pkg/kubectl/cmd/config/config_test.go
+29
-0
No files found.
pkg/client/clientcmd/client_config.go
View file @
49a6b629
...
@@ -19,6 +19,7 @@ package clientcmd
...
@@ -19,6 +19,7 @@ package clientcmd
import
(
import
(
"fmt"
"fmt"
"io"
"io"
"net/url"
"os"
"os"
"github.com/imdario/mergo"
"github.com/imdario/mergo"
...
@@ -86,6 +87,13 @@ func (config DirectClientConfig) ClientConfig() (*client.Config, error) {
...
@@ -86,6 +87,13 @@ func (config DirectClientConfig) ClientConfig() (*client.Config, error) {
clientConfig
:=
&
client
.
Config
{}
clientConfig
:=
&
client
.
Config
{}
clientConfig
.
Host
=
configClusterInfo
.
Server
clientConfig
.
Host
=
configClusterInfo
.
Server
if
u
,
err
:=
url
.
ParseRequestURI
(
clientConfig
.
Host
);
err
==
nil
&&
u
.
Opaque
==
""
&&
len
(
u
.
Path
)
>
1
{
clientConfig
.
Prefix
=
u
.
Path
u
.
Path
=
""
u
.
RawQuery
=
""
u
.
Fragment
=
""
clientConfig
.
Host
=
u
.
String
()
}
clientConfig
.
Version
=
configClusterInfo
.
APIVersion
clientConfig
.
Version
=
configClusterInfo
.
APIVersion
// only try to read the auth information if we are secure
// only try to read the auth information if we are secure
...
...
pkg/client/clientcmd/client_config_test.go
View file @
49a6b629
...
@@ -141,11 +141,49 @@ func TestCreateClean(t *testing.T) {
...
@@ -141,11 +141,49 @@ func TestCreateClean(t *testing.T) {
}
}
matchStringArg
(
config
.
Clusters
[
"clean"
]
.
Server
,
clientConfig
.
Host
,
t
)
matchStringArg
(
config
.
Clusters
[
"clean"
]
.
Server
,
clientConfig
.
Host
,
t
)
matchStringArg
(
""
,
clientConfig
.
Prefix
,
t
)
matchStringArg
(
config
.
Clusters
[
"clean"
]
.
APIVersion
,
clientConfig
.
Version
,
t
)
matchStringArg
(
config
.
Clusters
[
"clean"
]
.
APIVersion
,
clientConfig
.
Version
,
t
)
matchBoolArg
(
config
.
Clusters
[
"clean"
]
.
InsecureSkipTLSVerify
,
clientConfig
.
Insecure
,
t
)
matchBoolArg
(
config
.
Clusters
[
"clean"
]
.
InsecureSkipTLSVerify
,
clientConfig
.
Insecure
,
t
)
matchStringArg
(
config
.
AuthInfos
[
"clean"
]
.
Token
,
clientConfig
.
BearerToken
,
t
)
matchStringArg
(
config
.
AuthInfos
[
"clean"
]
.
Token
,
clientConfig
.
BearerToken
,
t
)
}
}
func
TestCreateCleanWithPrefix
(
t
*
testing
.
T
)
{
tt
:=
[]
struct
{
server
string
host
string
prefix
string
}{
{
"https://anything.com:8080/foo/bar"
,
"https://anything.com:8080"
,
"/foo/bar"
},
{
"http://anything.com:8080/foo/bar"
,
"http://anything.com:8080"
,
"/foo/bar"
},
{
"http://anything.com:8080/foo/bar/"
,
"http://anything.com:8080"
,
"/foo/bar/"
},
{
"http://anything.com:8080/"
,
"http://anything.com:8080/"
,
""
},
{
"http://anything.com:8080//"
,
"http://anything.com:8080"
,
"//"
},
{
"anything.com:8080/foo/bar"
,
"anything.com:8080/foo/bar"
,
""
},
{
"anything.com:8080"
,
"anything.com:8080"
,
""
},
{
"anything.com"
,
"anything.com"
,
""
},
{
"anything"
,
"anything"
,
""
},
{
""
,
"http://localhost:8080"
,
""
},
}
for
_
,
tc
:=
range
tt
{
config
:=
createValidTestConfig
()
cleanConfig
:=
config
.
Clusters
[
"clean"
]
cleanConfig
.
Server
=
tc
.
server
config
.
Clusters
[
"clean"
]
=
cleanConfig
clientBuilder
:=
NewNonInteractiveClientConfig
(
*
config
,
"clean"
,
&
ConfigOverrides
{})
clientConfig
,
err
:=
clientBuilder
.
ClientConfig
()
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
matchStringArg
(
tc
.
host
,
clientConfig
.
Host
,
t
)
matchStringArg
(
tc
.
prefix
,
clientConfig
.
Prefix
,
t
)
}
}
func
TestCreateCleanDefault
(
t
*
testing
.
T
)
{
func
TestCreateCleanDefault
(
t
*
testing
.
T
)
{
config
:=
createValidTestConfig
()
config
:=
createValidTestConfig
()
clientBuilder
:=
NewDefaultClientConfig
(
*
config
,
&
ConfigOverrides
{})
clientBuilder
:=
NewDefaultClientConfig
(
*
config
,
&
ConfigOverrides
{})
...
@@ -187,7 +225,7 @@ func matchBoolArg(expected, got bool, t *testing.T) {
...
@@ -187,7 +225,7 @@ func matchBoolArg(expected, got bool, t *testing.T) {
func
matchStringArg
(
expected
,
got
string
,
t
*
testing
.
T
)
{
func
matchStringArg
(
expected
,
got
string
,
t
*
testing
.
T
)
{
if
expected
!=
got
{
if
expected
!=
got
{
t
.
Errorf
(
"Expected %
v, got %v
"
,
expected
,
got
)
t
.
Errorf
(
"Expected %
q, got %q
"
,
expected
,
got
)
}
}
}
}
...
...
pkg/kubectl/cmd/config/config_test.go
View file @
49a6b629
...
@@ -108,6 +108,35 @@ func TestSetIntoExistingStruct(t *testing.T) {
...
@@ -108,6 +108,35 @@ func TestSetIntoExistingStruct(t *testing.T) {
test
.
run
(
t
)
test
.
run
(
t
)
}
}
func
TestSetWithPathPrefixIntoExistingStruct
(
t
*
testing
.
T
)
{
expectedConfig
:=
newRedFederalCowHammerConfig
()
cc
:=
expectedConfig
.
Clusters
[
"cow-clusters"
]
cinfo
:=
&
cc
cinfo
.
Server
=
"http://cow.org:8080/foo/baz"
expectedConfig
.
Clusters
[
"cow-cluster"
]
=
*
cinfo
test
:=
configCommandTest
{
args
:
[]
string
{
"set"
,
"clusters.cow-cluster.server"
,
"http://cow.org:8080/foo/baz"
},
startingConfig
:
newRedFederalCowHammerConfig
(),
expectedConfig
:
expectedConfig
,
}
test
.
run
(
t
)
dc
:=
clientcmd
.
NewDefaultClientConfig
(
expectedConfig
,
&
clientcmd
.
ConfigOverrides
{})
dcc
,
err
:=
dc
.
ClientConfig
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
expectedHost
:=
"http://cow.org:8080"
if
expectedHost
!=
dcc
.
Host
{
t
.
Fatalf
(
"expected client.Config.Host = %q instead of %q"
,
expectedHost
,
dcc
.
Host
)
}
expectedPrefix
:=
"/foo/baz"
if
expectedPrefix
!=
dcc
.
Prefix
{
t
.
Fatalf
(
"expected client.Config.Prefix = %q instead of %q"
,
expectedPrefix
,
dcc
.
Prefix
)
}
}
func
TestUnsetStruct
(
t
*
testing
.
T
)
{
func
TestUnsetStruct
(
t
*
testing
.
T
)
{
expectedConfig
:=
newRedFederalCowHammerConfig
()
expectedConfig
:=
newRedFederalCowHammerConfig
()
delete
(
expectedConfig
.
AuthInfos
,
"red-user"
)
delete
(
expectedConfig
.
AuthInfos
,
"red-user"
)
...
...
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