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
e2ca0f7c
Unverified
Commit
e2ca0f7c
authored
Jun 19, 2018
by
Lucas Käldström
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix kubeadm unit tests relying on internet access
parent
988243cb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
7 deletions
+26
-7
config.go
cmd/kubeadm/app/cmd/config.go
+8
-2
config_test.go
cmd/kubeadm/app/cmd/config_test.go
+17
-5
util.go
cmd/kubeadm/test/util.go
+1
-0
No files found.
cmd/kubeadm/app/cmd/config.go
View file @
e2ca0f7c
...
@@ -358,7 +358,7 @@ func NewCmdConfigImages(out io.Writer) *cobra.Command {
...
@@ -358,7 +358,7 @@ func NewCmdConfigImages(out io.Writer) *cobra.Command {
Short
:
"Interact with container images used by kubeadm."
,
Short
:
"Interact with container images used by kubeadm."
,
RunE
:
cmdutil
.
SubCmdRunE
(
"images"
),
RunE
:
cmdutil
.
SubCmdRunE
(
"images"
),
}
}
cmd
.
AddCommand
(
NewCmdConfigImagesList
(
out
))
cmd
.
AddCommand
(
NewCmdConfigImagesList
(
out
,
nil
))
cmd
.
AddCommand
(
NewCmdConfigImagesPull
())
cmd
.
AddCommand
(
NewCmdConfigImagesPull
())
return
cmd
return
cmd
}
}
...
@@ -416,12 +416,18 @@ func (ip *ImagesPull) PullAll() error {
...
@@ -416,12 +416,18 @@ func (ip *ImagesPull) PullAll() error {
}
}
// NewCmdConfigImagesList returns the "kubeadm config images list" command
// NewCmdConfigImagesList returns the "kubeadm config images list" command
func
NewCmdConfigImagesList
(
out
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdConfigImagesList
(
out
io
.
Writer
,
mockK8sVersion
*
string
)
*
cobra
.
Command
{
cfg
:=
&
kubeadmapiv1alpha2
.
MasterConfiguration
{}
cfg
:=
&
kubeadmapiv1alpha2
.
MasterConfiguration
{}
kubeadmscheme
.
Scheme
.
Default
(
cfg
)
kubeadmscheme
.
Scheme
.
Default
(
cfg
)
var
cfgPath
,
featureGatesString
string
var
cfgPath
,
featureGatesString
string
var
err
error
var
err
error
// This just sets the kubernetes version for unit testing so kubeadm won't try to
// lookup the latest release from the internet.
if
mockK8sVersion
!=
nil
{
cfg
.
KubernetesVersion
=
*
mockK8sVersion
}
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"list"
,
Use
:
"list"
,
Short
:
"Print a list of images kubeadm will use. The configuration file is used in case any images or image repositories are customized."
,
Short
:
"Print a list of images kubeadm will use. The configuration file is used in case any images or image repositories are customized."
,
...
...
cmd/kubeadm/app/cmd/config_test.go
View file @
e2ca0f7c
...
@@ -34,11 +34,15 @@ import (
...
@@ -34,11 +34,15 @@ import (
const
(
const
(
defaultNumberOfImages
=
8
defaultNumberOfImages
=
8
// dummyKubernetesVersion is just used for unit testing, in order to not make
// kubeadm lookup dl.k8s.io to resolve what the latest stable release is
dummyKubernetesVersion
=
"v1.10.0"
)
)
func
TestNewCmdConfigImagesList
(
t
*
testing
.
T
)
{
func
TestNewCmdConfigImagesList
(
t
*
testing
.
T
)
{
var
output
bytes
.
Buffer
var
output
bytes
.
Buffer
images
:=
cmd
.
NewCmdConfigImagesList
(
&
output
)
mockK8sVersion
:=
dummyKubernetesVersion
images
:=
cmd
.
NewCmdConfigImagesList
(
&
output
,
&
mockK8sVersion
)
images
.
Run
(
nil
,
nil
)
images
.
Run
(
nil
,
nil
)
actual
:=
strings
.
Split
(
output
.
String
(),
"
\n
"
)
actual
:=
strings
.
Split
(
output
.
String
(),
"
\n
"
)
if
len
(
actual
)
!=
defaultNumberOfImages
{
if
len
(
actual
)
!=
defaultNumberOfImages
{
...
@@ -63,7 +67,7 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
...
@@ -63,7 +67,7 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
configContents
:
[]
byte
(
dedent
.
Dedent
(
`
configContents
:
[]
byte
(
dedent
.
Dedent
(
`
apiVersion: kubeadm.k8s.io/v1alpha2
apiVersion: kubeadm.k8s.io/v1alpha2
kind: MasterConfiguration
kind: MasterConfiguration
kubernetesVersion: 1.10.1
kubernetesVersion:
v
1.10.1
`
)),
`
)),
},
},
{
{
...
@@ -75,9 +79,9 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
...
@@ -75,9 +79,9 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
configContents
:
[]
byte
(
dedent
.
Dedent
(
`
configContents
:
[]
byte
(
dedent
.
Dedent
(
`
apiVersion: kubeadm.k8s.io/v1alpha2
apiVersion: kubeadm.k8s.io/v1alpha2
kind: MasterConfiguration
kind: MasterConfiguration
kubernetesVersion: 1.11.0
kubernetesVersion:
v
1.11.0
featureGates:
featureGates:
CoreDNS: True
CoreDNS: True
`
)),
`
)),
},
},
}
}
...
@@ -96,7 +100,9 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
...
@@ -96,7 +100,9 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
t
.
Fatalf
(
"Failed writing a config file: %v"
,
err
)
t
.
Fatalf
(
"Failed writing a config file: %v"
,
err
)
}
}
i
,
err
:=
cmd
.
NewImagesList
(
configFilePath
,
&
kubeadmapiv1alpha2
.
MasterConfiguration
{})
i
,
err
:=
cmd
.
NewImagesList
(
configFilePath
,
&
kubeadmapiv1alpha2
.
MasterConfiguration
{
KubernetesVersion
:
dummyKubernetesVersion
,
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Failed getting the kubeadm images command: %v"
,
err
)
t
.
Fatalf
(
"Failed getting the kubeadm images command: %v"
,
err
)
}
}
...
@@ -127,6 +133,9 @@ func TestConfigImagesListRunWithoutPath(t *testing.T) {
...
@@ -127,6 +133,9 @@ func TestConfigImagesListRunWithoutPath(t *testing.T) {
{
{
name
:
"empty config"
,
name
:
"empty config"
,
expectedImages
:
defaultNumberOfImages
,
expectedImages
:
defaultNumberOfImages
,
cfg
:
kubeadmapiv1alpha2
.
MasterConfiguration
{
KubernetesVersion
:
dummyKubernetesVersion
,
},
},
},
{
{
name
:
"external etcd configuration"
,
name
:
"external etcd configuration"
,
...
@@ -136,6 +145,7 @@ func TestConfigImagesListRunWithoutPath(t *testing.T) {
...
@@ -136,6 +145,7 @@ func TestConfigImagesListRunWithoutPath(t *testing.T) {
Endpoints
:
[]
string
{
"https://some.etcd.com:2379"
},
Endpoints
:
[]
string
{
"https://some.etcd.com:2379"
},
},
},
},
},
KubernetesVersion
:
dummyKubernetesVersion
,
},
},
expectedImages
:
defaultNumberOfImages
-
1
,
expectedImages
:
defaultNumberOfImages
-
1
,
},
},
...
@@ -145,6 +155,7 @@ func TestConfigImagesListRunWithoutPath(t *testing.T) {
...
@@ -145,6 +155,7 @@ func TestConfigImagesListRunWithoutPath(t *testing.T) {
FeatureGates
:
map
[
string
]
bool
{
FeatureGates
:
map
[
string
]
bool
{
features
.
CoreDNS
:
true
,
features
.
CoreDNS
:
true
,
},
},
KubernetesVersion
:
dummyKubernetesVersion
,
},
},
expectedImages
:
defaultNumberOfImages
,
expectedImages
:
defaultNumberOfImages
,
},
},
...
@@ -198,6 +209,7 @@ func TestMigrate(t *testing.T) {
...
@@ -198,6 +209,7 @@ func TestMigrate(t *testing.T) {
cfg
:=
[]
byte
(
dedent
.
Dedent
(
`
cfg
:=
[]
byte
(
dedent
.
Dedent
(
`
apiVersion: kubeadm.k8s.io/v1alpha2
apiVersion: kubeadm.k8s.io/v1alpha2
kind: MasterConfiguration
kind: MasterConfiguration
kubernetesVersion: v1.10.0
`
))
`
))
configFile
,
cleanup
:=
tempConfig
(
t
,
cfg
)
configFile
,
cleanup
:=
tempConfig
(
t
,
cfg
)
defer
cleanup
()
defer
cleanup
()
...
...
cmd/kubeadm/test/util.go
View file @
e2ca0f7c
...
@@ -61,6 +61,7 @@ func SetupMasterConfigurationFile(t *testing.T, tmpdir string, cfg *kubeadmapi.M
...
@@ -61,6 +61,7 @@ func SetupMasterConfigurationFile(t *testing.T, tmpdir string, cfg *kubeadmapi.M
bindPort: {{.API.BindPort}}
bindPort: {{.API.BindPort}}
nodeRegistration:
nodeRegistration:
name: {{.NodeRegistration.Name}}
name: {{.NodeRegistration.Name}}
kubernetesVersion: v1.10.0
`
)))
`
)))
f
,
err
:=
os
.
Create
(
cfgPath
)
f
,
err
:=
os
.
Create
(
cfgPath
)
...
...
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