mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Adds breadcrumb to crictl warning
Signed-off-by: Chuck Ha <ha.chuck@gmail.com>
This commit is contained in:
parent
6177b42e62
commit
265a57c11f
@ -200,6 +200,9 @@ const (
|
|||||||
CoreDNS = "coredns"
|
CoreDNS = "coredns"
|
||||||
// KubeDNS defines a variable used internally when referring to the kube-dns addon for a cluster
|
// KubeDNS defines a variable used internally when referring to the kube-dns addon for a cluster
|
||||||
KubeDNS = "kube-dns"
|
KubeDNS = "kube-dns"
|
||||||
|
|
||||||
|
// CRICtlPackage defines the go package that installs crictl
|
||||||
|
CRICtlPackage = "github.com/kubernetes-incubator/cri-tools/cmd/crictl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -347,6 +348,7 @@ type InPathCheck struct {
|
|||||||
mandatory bool
|
mandatory bool
|
||||||
exec utilsexec.Interface
|
exec utilsexec.Interface
|
||||||
label string
|
label string
|
||||||
|
suggestion string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns label for individual InPathCheck. If not known, will return based on path.
|
// 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.
|
// 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)
|
_, err := ipc.exec.LookPath(ipc.executable)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ipc.mandatory {
|
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 nil, []error{fmt.Errorf("%s not found in system path", ipc.executable)}
|
||||||
}
|
}
|
||||||
// Return as a warning:
|
// 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
|
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
|
// 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()
|
warns, _ := criCtlChecker.Check()
|
||||||
useCRI := len(warns) == 0
|
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
|
// 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()
|
warns, _ := criCtlChecker.Check()
|
||||||
useCRI := len(warns) == 0
|
useCRI := len(warns) == 0
|
||||||
|
|
||||||
|
@ -299,6 +299,7 @@ func TestRunChecks(t *testing.T) {
|
|||||||
{[]Checker{ExtraArgsCheck{
|
{[]Checker{ExtraArgsCheck{
|
||||||
APIServerExtraArgs: map[string]string{"invalid-argument": "foo"},
|
APIServerExtraArgs: map[string]string{"invalid-argument": "foo"},
|
||||||
}}, true, "\t[WARNING ExtraArgs]: kube-apiserver: failed to parse extra argument --invalid-argument=foo\n"},
|
}}, 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 {
|
for _, rt := range tokenTest {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
Loading…
Reference in New Issue
Block a user