Skip to content

Commit 91f40ae

Browse files
authored
Merge pull request kubernetes#75847 from fabriziopandini/fix-external-etcd
kubeadm: fix join control-plane with external-etcd
2 parents da018a6 + f09d638 commit 91f40ae

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

cmd/kubeadm/app/cmd/phases/init/preflight.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func runPreflight(c workflow.RunData) error {
5757
}
5858

5959
fmt.Println("[preflight] Running pre-flight checks")
60-
if err := preflight.RunInitNodeChecks(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors(), false); err != nil {
60+
if err := preflight.RunInitNodeChecks(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors(), false, false); err != nil {
6161
return err
6262
}
6363

cmd/kubeadm/app/cmd/phases/join/preflight.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ func runPreflight(c workflow.RunData) error {
120120

121121
// run kubeadm init preflight checks for checking all the prerequisites
122122
fmt.Println("[preflight] Running pre-flight checks before initializing the new control plane instance")
123-
if err := preflight.RunInitNodeChecks(utilsexec.New(), initCfg, j.IgnorePreflightErrors(), true); err != nil {
123+
124+
if err := preflight.RunInitNodeChecks(utilsexec.New(), initCfg, j.IgnorePreflightErrors(), true, hasCertificateKey); err != nil {
124125
return err
125126
}
126127

cmd/kubeadm/app/preflight/checks.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,9 @@ func (r IPVSProxierCheck) Name() string {
884884

885885
// RunInitNodeChecks executes all individual, applicable to control-plane node checks.
886886
// The boolean flag 'isSecondaryControlPlane' controls whether we are running checks in a --join-control-plane scenario.
887+
// The boolean flag 'downloadCerts' controls whether we should skip checks on certificates because we are downloading them.
887888
// If the flag is set to true we should skip checks already executed by RunJoinNodeChecks and RunOptionalJoinNodeChecks.
888-
func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfiguration, ignorePreflightErrors sets.String, isSecondaryControlPlane bool) error {
889+
func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfiguration, ignorePreflightErrors sets.String, isSecondaryControlPlane bool, downloadCerts bool) error {
889890
if !isSecondaryControlPlane {
890891
// First, check if we're root separately from the other preflight checks and fail fast
891892
if err := RunRootCheckOnly(ignorePreflightErrors); err != nil {
@@ -927,19 +928,25 @@ func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigura
927928
)
928929
}
929930
}
931+
932+
// if using an external etcd
933+
if cfg.Etcd.External != nil {
934+
// Check external etcd version before creating the cluster
935+
checks = append(checks, ExternalEtcdVersionCheck{Etcd: cfg.Etcd})
936+
}
930937
}
931938

932939
if cfg.Etcd.Local != nil {
933-
// Only do etcd related checks when no external endpoints were specified
940+
// Only do etcd related checks when required to install a local etcd
934941
checks = append(checks,
935942
PortOpenCheck{port: kubeadmconstants.EtcdListenClientPort},
936943
PortOpenCheck{port: kubeadmconstants.EtcdListenPeerPort},
937944
DirAvailableCheck{Path: cfg.Etcd.Local.DataDir},
938945
)
939946
}
940947

941-
if cfg.Etcd.External != nil {
942-
// Only check etcd version when external endpoints are specified
948+
if cfg.Etcd.External != nil && !(isSecondaryControlPlane && downloadCerts) {
949+
// Only check etcd certificates when using an external etcd and not joining with automatic download of certs
943950
if cfg.Etcd.External.CAFile != "" {
944951
checks = append(checks, FileExistingCheck{Path: cfg.Etcd.External.CAFile, Label: "ExternalEtcdClientCertificates"})
945952
}
@@ -949,7 +956,6 @@ func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigura
949956
if cfg.Etcd.External.KeyFile != "" {
950957
checks = append(checks, FileExistingCheck{Path: cfg.Etcd.External.KeyFile, Label: "ExternalEtcdClientCertificates"})
951958
}
952-
checks = append(checks, ExternalEtcdVersionCheck{Etcd: cfg.Etcd})
953959
}
954960

955961
return RunChecks(checks, os.Stderr, ignorePreflightErrors)

cmd/kubeadm/app/preflight/checks_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,11 @@ func (pfct preflightCheckTest) Check() (warning, errorList []error) {
186186

187187
func TestRunInitNodeChecks(t *testing.T) {
188188
var tests = []struct {
189-
name string
190-
cfg *kubeadmapi.InitConfiguration
191-
expected bool
189+
name string
190+
cfg *kubeadmapi.InitConfiguration
191+
expected bool
192+
isSecondaryControlPlane bool
193+
downloadCerts bool
192194
}{
193195
{name: "Test valid advertised address",
194196
cfg: &kubeadmapi.InitConfiguration{
@@ -197,7 +199,7 @@ func TestRunInitNodeChecks(t *testing.T) {
197199
expected: false,
198200
},
199201
{
200-
name: "Test CA file exists if specfied",
202+
name: "Test CA file exists if specified",
201203
cfg: &kubeadmapi.InitConfiguration{
202204
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
203205
Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CAFile: "/foo"}},
@@ -206,7 +208,18 @@ func TestRunInitNodeChecks(t *testing.T) {
206208
expected: false,
207209
},
208210
{
209-
name: "Test Cert file exists if specfied",
211+
name: "Skip test CA file exists if specified/download certs",
212+
cfg: &kubeadmapi.InitConfiguration{
213+
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
214+
Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CAFile: "/foo"}},
215+
},
216+
},
217+
expected: true,
218+
isSecondaryControlPlane: true,
219+
downloadCerts: true,
220+
},
221+
{
222+
name: "Test Cert file exists if specified",
210223
cfg: &kubeadmapi.InitConfiguration{
211224
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
212225
Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CertFile: "/foo"}},
@@ -215,7 +228,7 @@ func TestRunInitNodeChecks(t *testing.T) {
215228
expected: false,
216229
},
217230
{
218-
name: "Test Key file exists if specfied",
231+
name: "Test Key file exists if specified",
219232
cfg: &kubeadmapi.InitConfiguration{
220233
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
221234
Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CertFile: "/foo"}},
@@ -232,7 +245,7 @@ func TestRunInitNodeChecks(t *testing.T) {
232245
}
233246
for _, rt := range tests {
234247
// TODO: Make RunInitNodeChecks accept a ClusterConfiguration object instead of InitConfiguration
235-
actual := RunInitNodeChecks(exec.New(), rt.cfg, sets.NewString(), false)
248+
actual := RunInitNodeChecks(exec.New(), rt.cfg, sets.NewString(), rt.isSecondaryControlPlane, rt.downloadCerts)
236249
if (actual == nil) != rt.expected {
237250
t.Errorf(
238251
"failed RunInitNodeChecks:\n\texpected: %t\n\t actual: %t\n\t error: %v",

0 commit comments

Comments
 (0)