From 6a25bdaac8f1373d4356437ed00da1f73e0c7c5c Mon Sep 17 00:00:00 2001 From: Paco Xu Date: Tue, 1 Jul 2025 10:54:14 +0800 Subject: [PATCH] kubeadm: fix missing log of health check --- cmd/kubeadm/app/preflight/checks.go | 2 +- cmd/kubeadm/app/preflight/checks_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index 18e2bd95a03..36978405d19 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -1128,7 +1128,7 @@ func RunChecks(checks []Checker, ww io.Writer, ignorePreflightErrors sets.Set[st } } if errsBuffer.Len() > 0 { - return handleError(&errsBuffer, errsBuffer.String()) + return handleError(ww, errsBuffer.String()) } return nil } diff --git a/cmd/kubeadm/app/preflight/checks_test.go b/cmd/kubeadm/app/preflight/checks_test.go index b74c51cf6e8..1720677797f 100644 --- a/cmd/kubeadm/app/preflight/checks_test.go +++ b/cmd/kubeadm/app/preflight/checks_test.go @@ -423,16 +423,16 @@ func TestRunChecks(t *testing.T) { }{ {[]Checker{}, true, ""}, {[]Checker{preflightCheckTest{"warning"}}, true, "\t[WARNING preflightCheckTest]: warning\n"}, // should just print warning - {[]Checker{preflightCheckTest{"error"}}, false, ""}, - {[]Checker{preflightCheckTest{"test"}}, false, ""}, + {[]Checker{preflightCheckTest{"error"}}, false, "[preflight] Some fatal errors occurred:\n\t[ERROR preflightCheckTest]: fake error\n[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`\n"}, + {[]Checker{preflightCheckTest{"test"}}, false, "[preflight] Some fatal errors occurred:\n\t[ERROR preflightCheckTest]: fake error\n[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`\n"}, {[]Checker{DirAvailableCheck{Path: "/does/not/exist"}}, true, ""}, - {[]Checker{DirAvailableCheck{Path: "/"}}, false, ""}, + {[]Checker{DirAvailableCheck{Path: "/"}}, false, "[preflight] Some fatal errors occurred:\n\t[ERROR DirAvailable--]: / is not empty\n[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`\n"}, {[]Checker{FileAvailableCheck{Path: "/does/not/exist"}}, true, ""}, - {[]Checker{FileContentCheck{Path: "/does/not/exist"}}, false, ""}, + {[]Checker{FileContentCheck{Path: "/does/not/exist"}}, false, "[preflight] Some fatal errors occurred:\n\t[ERROR FileContent--does-not-exist]: /does/not/exist does not exist\n[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`\n"}, {[]Checker{FileContentCheck{Path: "/"}}, true, ""}, - {[]Checker{FileContentCheck{Path: "/", Content: []byte("does not exist")}}, false, ""}, + {[]Checker{FileContentCheck{Path: "/", Content: []byte("content can not be read")}}, false, "[preflight] Some fatal errors occurred:\n\t[ERROR FileContent--]: / could not be read\n[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`\n"}, {[]Checker{InPathCheck{executable: "foobarbaz", exec: exec.New()}}, true, "\t[WARNING FileExisting-foobarbaz]: foobarbaz not found in system path\n"}, - {[]Checker{InPathCheck{executable: "foobarbaz", mandatory: true, exec: exec.New()}}, false, ""}, + {[]Checker{InPathCheck{executable: "foobarbaz", mandatory: true, exec: exec.New()}}, false, "[preflight] Some fatal errors occurred:\n\t[ERROR FileExisting-foobarbaz]: foobarbaz not found in system path\n[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`\n"}, {[]Checker{InPathCheck{executable: "foobar", mandatory: false, exec: exec.New(), suggestion: "install foobar"}}, true, "\t[WARNING FileExisting-foobar]: foobar not found in system path\nSuggestion: install foobar\n"}, } for _, rt := range tokenTest {