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
e9cad12e
Commit
e9cad12e
authored
Sep 01, 2016
by
Angus Salkeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a check in ConfirmUsable() to validate the contextName
parent
3269849d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
13 deletions
+27
-13
client_config.go
pkg/client/unversioned/clientcmd/client_config.go
+15
-0
client_config_test.go
pkg/client/unversioned/clientcmd/client_config_test.go
+8
-10
kubectl_test.go
test/integration/kubectl/kubectl_test.go
+4
-3
No files found.
pkg/client/unversioned/clientcmd/client_config.go
View file @
e9cad12e
...
...
@@ -263,6 +263,21 @@ func (config *DirectClientConfig) ConfigAccess() ConfigAccess {
// but no errors in the sections requested or referenced. It does not return early so that it can find as many errors as possible.
func
(
config
*
DirectClientConfig
)
ConfirmUsable
()
error
{
validationErrors
:=
make
([]
error
,
0
)
var
contextName
string
if
len
(
config
.
contextName
)
!=
0
{
contextName
=
config
.
contextName
}
else
{
contextName
=
config
.
config
.
CurrentContext
}
if
len
(
contextName
)
>
0
{
_
,
exists
:=
config
.
config
.
Contexts
[
contextName
]
if
!
exists
{
validationErrors
=
append
(
validationErrors
,
&
errContextNotFound
{
contextName
})
}
}
validationErrors
=
append
(
validationErrors
,
validateAuthInfo
(
config
.
getAuthInfoName
(),
config
.
getAuthInfo
())
...
)
validationErrors
=
append
(
validationErrors
,
validateClusterInfo
(
config
.
getClusterName
(),
config
.
getCluster
())
...
)
// when direct client config is specified, and our only error is that no server is defined, we should
...
...
pkg/client/unversioned/clientcmd/client_config_test.go
View file @
e9cad12e
...
...
@@ -20,10 +20,10 @@ import (
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
"github.com/imdario/mergo"
"k8s.io/kubernetes/pkg/client/restclient"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
)
...
...
@@ -357,22 +357,20 @@ func TestCreateMissingContextNoDefault(t *testing.T) {
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
func
TestCreateMissingContext
(
t
*
testing
.
T
)
{
const
expectedErrorContains
=
"
Context was not found for specified contex
t"
const
expectedErrorContains
=
"
context was not found for specified context: not-presen
t"
config
:=
createValidTestConfig
()
clientBuilder
:=
NewNonInteractiveClientConfig
(
*
config
,
"not-present"
,
&
ConfigOverrides
{
ClusterDefaults
:
DefaultCluster
,
},
nil
)
clientConfig
,
err
:=
clientBuilder
.
ClientConfig
()
if
err
!
=
nil
{
t
.
Fatalf
(
"
Unexpected error: %v"
,
err
)
_
,
err
:=
clientBuilder
.
ClientConfig
()
if
err
=
=
nil
{
t
.
Fatalf
(
"
Expected error: %v"
,
expectedErrorContains
)
}
expectedConfig
:=
&
restclient
.
Config
{
Host
:
clientConfig
.
Host
}
if
!
reflect
.
DeepEqual
(
expectedConfig
,
clientConfig
)
{
t
.
Errorf
(
"Expected %#v, got %#v"
,
expectedConfig
,
clientConfig
)
if
!
strings
.
Contains
(
err
.
Error
(),
expectedErrorContains
)
{
t
.
Fatalf
(
"Expected error: %v, but got %v"
,
expectedErrorContains
,
err
)
}
}
...
...
test/integration/kubectl/kubectl_test.go
View file @
e9cad12e
...
...
@@ -49,12 +49,13 @@ func TestKubectlValidation(t *testing.T) {
// Enable swagger api on master.
components
.
KubeMaster
.
InstallSwaggerAPI
()
cluster
:=
clientcmdapi
.
NewCluster
()
cluster
.
Server
=
components
.
ApiServer
.
URL
cluster
.
InsecureSkipTLSVerify
=
true
cfg
.
Contexts
=
map
[
string
]
*
clientcmdapi
.
Context
{
"test"
:
ctx
}
cfg
.
CurrentContext
=
"test"
overrides
:=
clientcmd
.
ConfigOverrides
{
ClusterInfo
:
*
cluster
,
Context
:
*
ctx
,
CurrentContext
:
"test"
,
ClusterInfo
:
*
cluster
,
}
cmdConfig
:=
clientcmd
.
NewNonInteractiveClientConfig
(
*
cfg
,
"test"
,
&
overrides
,
nil
)
factory
:=
util
.
NewFactory
(
cmdConfig
)
...
...
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