From 265a57c11fea2ad028dc9adb49abd4e16a711a52 Mon Sep 17 00:00:00 2001 From: Chuck Ha Date: Fri, 26 Jan 2018 10:52:19 -0500 Subject: [PATCH] Adds breadcrumb to crictl warning Signed-off-by: Chuck Ha --- cmd/kubeadm/app/constants/constants.go | 3 +++ cmd/kubeadm/app/preflight/checks.go | 24 ++++++++++++++++++++---- cmd/kubeadm/app/preflight/checks_test.go | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd/kubeadm/app/constants/constants.go b/cmd/kubeadm/app/constants/constants.go index a5e5e7ff0ff..31855bdd1b9 100644 --- a/cmd/kubeadm/app/constants/constants.go +++ b/cmd/kubeadm/app/constants/constants.go @@ -200,6 +200,9 @@ const ( CoreDNS = "coredns" // KubeDNS defines a variable used internally when referring to the kube-dns addon for a cluster KubeDNS = "kube-dns" + + // CRICtlPackage defines the go package that installs crictl + CRICtlPackage = "github.com/kubernetes-incubator/cri-tools/cmd/crictl" ) var ( diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index 42f71eebf31..0059ac5d168 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -20,6 +20,7 @@ import ( "bufio" "bytes" "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -347,6 +348,7 @@ type InPathCheck struct { mandatory bool exec utilsexec.Interface label string + suggestion string } // Name returns label for individual InPathCheck. If not known, will return based on path. @@ -358,7 +360,7 @@ func (ipc InPathCheck) Name() string { } // Check validates if the given executable is present in the path. -func (ipc InPathCheck) Check() (warnings, errors []error) { +func (ipc InPathCheck) Check() (warnings, errs []error) { _, err := ipc.exec.LookPath(ipc.executable) if err != nil { if ipc.mandatory { @@ -366,7 +368,11 @@ func (ipc InPathCheck) Check() (warnings, errors []error) { return nil, []error{fmt.Errorf("%s not found in system path", ipc.executable)} } // Return as a warning: - return []error{fmt.Errorf("%s not found in system path", ipc.executable)}, nil + warningMessage := fmt.Sprintf("%s not found in system path", ipc.executable) + if ipc.suggestion != "" { + warningMessage += fmt.Sprintf("\nSuggestion: %s", ipc.suggestion) + } + return []error{errors.New(warningMessage)}, nil } return nil, nil } @@ -847,7 +853,12 @@ func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.MasterConfi } // check if we can use crictl to perform checks via the CRI - criCtlChecker := InPathCheck{executable: "crictl", mandatory: false, exec: execer} + criCtlChecker := InPathCheck{ + executable: "crictl", + mandatory: false, + exec: execer, + suggestion: fmt.Sprintf("go get %v", kubeadmconstants.CRICtlPackage), + } warns, _ := criCtlChecker.Check() useCRI := len(warns) == 0 @@ -948,7 +959,12 @@ func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.NodeConfigura } // check if we can use crictl to perform checks via the CRI - criCtlChecker := InPathCheck{executable: "crictl", mandatory: false, exec: execer} + criCtlChecker := InPathCheck{ + executable: "crictl", + mandatory: false, + exec: execer, + suggestion: fmt.Sprintf("go get %v", kubeadmconstants.CRICtlPackage), + } warns, _ := criCtlChecker.Check() useCRI := len(warns) == 0 diff --git a/cmd/kubeadm/app/preflight/checks_test.go b/cmd/kubeadm/app/preflight/checks_test.go index 7fe7c425caa..a283e92eb45 100644 --- a/cmd/kubeadm/app/preflight/checks_test.go +++ b/cmd/kubeadm/app/preflight/checks_test.go @@ -299,6 +299,7 @@ func TestRunChecks(t *testing.T) { {[]Checker{ExtraArgsCheck{ APIServerExtraArgs: map[string]string{"invalid-argument": "foo"}, }}, true, "\t[WARNING ExtraArgs]: kube-apiserver: failed to parse extra argument --invalid-argument=foo\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 { buf := new(bytes.Buffer)