mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Kubeadm: Add some validation for external etcd config
This commit is contained in:
parent
ce4afa8418
commit
a25161a96a
@ -677,6 +677,15 @@ func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
|
||||
)
|
||||
} else {
|
||||
// Only check etcd version when external endpoints are specified
|
||||
if cfg.Etcd.CAFile != "" {
|
||||
checks = append(checks, FileExistingCheck{Path: cfg.Etcd.CAFile})
|
||||
}
|
||||
if cfg.Etcd.CertFile != "" {
|
||||
checks = append(checks, FileExistingCheck{Path: cfg.Etcd.CertFile})
|
||||
}
|
||||
if cfg.Etcd.KeyFile != "" {
|
||||
checks = append(checks, FileExistingCheck{Path: cfg.Etcd.KeyFile})
|
||||
}
|
||||
checks = append(checks,
|
||||
ExternalEtcdVersionCheck{Etcd: cfg.Etcd},
|
||||
)
|
||||
|
@ -174,24 +174,47 @@ func (pfct preflightCheckTest) Check() (warning, errors []error) {
|
||||
|
||||
func TestRunInitMasterChecks(t *testing.T) {
|
||||
var tests = []struct {
|
||||
name string
|
||||
cfg *kubeadmapi.MasterConfiguration
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
{name: "Test valid advertised address",
|
||||
cfg: &kubeadmapi.MasterConfiguration{
|
||||
API: kubeadmapi.API{AdvertiseAddress: "foo"},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "Test CA file exists if specfied",
|
||||
cfg: &kubeadmapi.MasterConfiguration{
|
||||
Etcd: kubeadmapi.Etcd{CAFile: "/foo"},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "Test Cert file exists if specfied",
|
||||
cfg: &kubeadmapi.MasterConfiguration{
|
||||
Etcd: kubeadmapi.Etcd{CertFile: "/foo"},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "Test Key file exists if specfied",
|
||||
cfg: &kubeadmapi.MasterConfiguration{
|
||||
Etcd: kubeadmapi.Etcd{CertFile: "/foo"},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, rt := range tests {
|
||||
actual := RunInitMasterChecks(rt.cfg)
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
"failed RunInitMasterChecks:\n\texpected: %t\n\t actual: %t",
|
||||
"failed RunInitMasterChecks:\n\texpected: %t\n\t actual: %t\n\t error: %v",
|
||||
rt.expected,
|
||||
(actual != nil),
|
||||
(actual == nil),
|
||||
actual,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user