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
b836fa43
Unverified
Commit
b836fa43
authored
Oct 05, 2018
by
k8s-ci-robot
Committed by
GitHub
Oct 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #69420 from ereslibre/fix-kubeadm-panic
kubeadm: do not panic if etcd local alpha phase is called when an external etcd config is used
parents
1aba19a2
503c6c7b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
18 deletions
+62
-18
local.go
cmd/kubeadm/app/phases/etcd/local.go
+3
-0
local_test.go
cmd/kubeadm/app/phases/etcd/local_test.go
+48
-18
util.go
cmd/kubeadm/test/util.go
+11
-0
No files found.
cmd/kubeadm/app/phases/etcd/local.go
View file @
b836fa43
...
...
@@ -37,6 +37,9 @@ const (
// CreateLocalEtcdStaticPodManifestFile will write local etcd static pod manifest file.
func
CreateLocalEtcdStaticPodManifestFile
(
manifestDir
string
,
cfg
*
kubeadmapi
.
InitConfiguration
)
error
{
if
cfg
.
ClusterConfiguration
.
Etcd
.
External
!=
nil
{
return
fmt
.
Errorf
(
"etcd static pod manifest cannot be generated for cluster using external etcd"
)
}
glog
.
V
(
1
)
.
Infoln
(
"creating local etcd static pod manifest file"
)
// gets etcd StaticPodSpec, actualized for the current InitConfiguration
spec
:=
GetEtcdPodSpec
(
cfg
)
...
...
cmd/kubeadm/app/phases/etcd/local_test.go
View file @
b836fa43
...
...
@@ -54,34 +54,64 @@ func TestGetEtcdPodSpec(t *testing.T) {
}
func
TestCreateLocalEtcdStaticPodManifestFile
(
t
*
testing
.
T
)
{
// Create temp folder for the test case
tmpdir
:=
testutil
.
SetupTempDir
(
t
)
defer
os
.
RemoveAll
(
tmpdir
)
// Creates a Master Configuration
cfg
:=
&
kubeadmapi
.
InitConfiguration
{
ClusterConfiguration
:
kubeadmapi
.
ClusterConfiguration
{
KubernetesVersion
:
"v1.7.0"
,
Etcd
:
kubeadmapi
.
Etcd
{
Local
:
&
kubeadmapi
.
LocalEtcd
{
DataDir
:
"/var/lib/etcd"
,
Image
:
"k8s.gcr.io/etcd"
,
var
tests
=
[]
struct
{
cfg
*
kubeadmapi
.
InitConfiguration
expectedError
bool
}{
{
cfg
:
&
kubeadmapi
.
InitConfiguration
{
ClusterConfiguration
:
kubeadmapi
.
ClusterConfiguration
{
KubernetesVersion
:
"v1.7.0"
,
Etcd
:
kubeadmapi
.
Etcd
{
Local
:
&
kubeadmapi
.
LocalEtcd
{
DataDir
:
"/var/lib/etcd"
,
Image
:
"k8s.gcr.io/etcd"
,
},
},
},
},
expectedError
:
false
,
},
{
cfg
:
&
kubeadmapi
.
InitConfiguration
{
ClusterConfiguration
:
kubeadmapi
.
ClusterConfiguration
{
KubernetesVersion
:
"v1.7.0"
,
Etcd
:
kubeadmapi
.
Etcd
{
External
:
&
kubeadmapi
.
ExternalEtcd
{
Endpoints
:
[]
string
{
"https://etcd-instance:2379"
,
},
CAFile
:
"/etc/kubernetes/pki/etcd/ca.crt"
,
CertFile
:
"/etc/kubernetes/pki/etcd/apiserver-etcd-client.crt"
,
KeyFile
:
"/etc/kubernetes/pki/etcd/apiserver-etcd-client.key"
,
},
},
},
},
expectedError
:
true
,
},
}
// Execute createStaticPodFunction
manifestPath
:=
filepath
.
Join
(
tmpdir
,
kubeadmconstants
.
ManifestsSubDirName
)
err
:=
CreateLocalEtcdStaticPodManifestFile
(
manifestPath
,
cfg
)
if
err
!=
nil
{
t
.
Errorf
(
"Error executing CreateEtcdStaticPodManifestFile: %v"
,
err
)
for
_
,
test
:=
range
tests
{
// Execute createStaticPodFunction
manifestPath
:=
filepath
.
Join
(
tmpdir
,
kubeadmconstants
.
ManifestsSubDirName
)
err
:=
CreateLocalEtcdStaticPodManifestFile
(
manifestPath
,
test
.
cfg
)
if
!
test
.
expectedError
{
if
err
!=
nil
{
t
.
Errorf
(
"CreateLocalEtcdStaticPodManifestFile failed when not expected: %v"
,
err
)
}
// Assert expected files are there
testutil
.
AssertFilesCount
(
t
,
manifestPath
,
1
)
testutil
.
AssertFileExists
(
t
,
manifestPath
,
kubeadmconstants
.
Etcd
+
".yaml"
)
}
else
{
testutil
.
AssertError
(
t
,
err
,
"etcd static pod manifest cannot be generated for cluster using external etcd"
)
}
}
// Assert expected files are there
testutil
.
AssertFilesCount
(
t
,
manifestPath
,
1
)
testutil
.
AssertFileExists
(
t
,
manifestPath
,
kubeadmconstants
.
Etcd
+
".yaml"
)
}
func
TestGetEtcdCommand
(
t
*
testing
.
T
)
{
...
...
cmd/kubeadm/test/util.go
View file @
b836fa43
...
...
@@ -143,6 +143,17 @@ func AssertFileExists(t *testing.T, dirName string, fileNames ...string) {
}
}
// AssertError checks that the provided error matches the expected output
func
AssertError
(
t
*
testing
.
T
,
err
error
,
expected
string
)
{
if
err
==
nil
{
t
.
Errorf
(
"no error was found, but '%s' was expected"
,
expected
)
return
}
if
err
.
Error
()
!=
expected
{
t
.
Errorf
(
"error '%s' does not match expected error: '%s'"
,
err
.
Error
(),
expected
)
}
}
// GetDefaultInternalConfig returns a defaulted kubeadmapi.InitConfiguration
func
GetDefaultInternalConfig
(
t
*
testing
.
T
)
*
kubeadmapi
.
InitConfiguration
{
internalcfg
,
err
:=
configutil
.
ConfigFileAndDefaultsToInternalConfig
(
""
,
&
kubeadmapiv1beta1
.
InitConfiguration
{})
...
...
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