Kubeadm: Add some validation for external etcd config

This commit is contained in:
Feng Min 2017-10-02 16:30:04 -07:00
parent ce4afa8418
commit a25161a96a
2 changed files with 35 additions and 3 deletions

View File

@ -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},
)

View File

@ -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,
)
}
}