From a26cbbf3d043c8f6bbc89bb1f515e73a2eedad8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20K=C3=A4ldstr=C3=B6m?= Date: Sat, 12 Nov 2016 16:37:12 +0200 Subject: [PATCH] Add the system verification check to the kubeadm preflight checks --- cmd/kubeadm/app/preflight/BUILD | 1 + cmd/kubeadm/app/preflight/checks.go | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cmd/kubeadm/app/preflight/BUILD b/cmd/kubeadm/app/preflight/BUILD index 69051be0514..d12bc13740b 100644 --- a/cmd/kubeadm/app/preflight/BUILD +++ b/cmd/kubeadm/app/preflight/BUILD @@ -19,6 +19,7 @@ go_library( "//pkg/api/validation:go_default_library", "//pkg/util/initsystem:go_default_library", "//pkg/util/node:go_default_library", + "//test/e2e_node/system:go_default_library", ], ) diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index 1b0950745ff..b8142ace558 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -17,6 +17,7 @@ limitations under the License. package preflight import ( + "bufio" "errors" "fmt" "io" @@ -29,6 +30,7 @@ import ( "k8s.io/kubernetes/pkg/api/validation" "k8s.io/kubernetes/pkg/util/initsystem" "k8s.io/kubernetes/pkg/util/node" + "k8s.io/kubernetes/test/e2e_node/system" ) type PreFlightError struct { @@ -213,9 +215,26 @@ func (hst HttpProxyCheck) Check() (warnings, errors []error) { return nil, nil } +type SystemVerificationCheck struct{} + +func (sysver SystemVerificationCheck) Check() (warnings, errors []error) { + // Create a buffered writer and choose a quite large value (1M) and suppose the output from the system verification test won't exceed the limit + bufw := bufio.NewWriterSize(os.Stdout, 1*1024*1024) + + // Run the system verification check, but write to out buffered writer instead of stdout + err := system.Validate(system.DefaultSysSpec, &system.StreamReporter{WriteStream: bufw}) + if err != nil { + // Only print the output from the system verification check if the check failed + fmt.Println("System verification failed. Printing the output from the verification...") + bufw.Flush() + return nil, []error{err} + } + return nil, nil +} + func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error { - // TODO: Some of these ports should come from kubeadm config eventually: checks := []PreFlightCheck{ + SystemVerificationCheck{}, IsRootCheck{root: true}, HostnameCheck{}, ServiceCheck{Service: "kubelet"}, @@ -249,8 +268,8 @@ func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error { } func RunJoinNodeChecks(cfg *kubeadmapi.NodeConfiguration) error { - // TODO: Some of these ports should come from kubeadm config eventually: checks := []PreFlightCheck{ + SystemVerificationCheck{}, IsRootCheck{root: true}, HostnameCheck{}, ServiceCheck{Service: "docker"},