Merge pull request #42969 from apprenda/kubeadm_preflight_warning_nil

Automatic merge from submit-queue (batch tested with PRs 42969, 42966)

kubeadm: fixed warning nil logging

**What this PR does / why we need it**: Fix bug in warning aggregation for preflight checks. Would cause logging like this:

`[preflight] WARNING: %!s(<nil>)`

Will now only append non-nil cases to warning.

**Special notes for your reviewer**: /cc @jbeda 

**Release note**:
```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-03-12 18:08:23 -07:00 committed by GitHub
commit c0ebd72437
2 changed files with 9 additions and 8 deletions

View File

@ -22,7 +22,6 @@ go_library(
"//test/e2e_node/system:go_default_library", "//test/e2e_node/system:go_default_library",
"//vendor:github.com/PuerkitoBio/purell", "//vendor:github.com/PuerkitoBio/purell",
"//vendor:github.com/blang/semver", "//vendor:github.com/blang/semver",
"//vendor:k8s.io/apimachinery/pkg/util/errors",
], ],
) )

View File

@ -38,7 +38,6 @@ import (
"net/url" "net/url"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants" kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/pkg/api/validation" "k8s.io/kubernetes/pkg/api/validation"
@ -335,16 +334,19 @@ func (sysver SystemVerificationCheck) Check() (warnings, errors []error) {
// Run all validators // Run all validators
for _, v := range validators { for _, v := range validators {
warn, err := v.Validate(system.DefaultSysSpec) warn, err := v.Validate(system.DefaultSysSpec)
errs = append(errs, err) if err != nil {
warns = append(warns, warn) errs = append(errs, err)
}
if warn != nil {
warns = append(warns, warn)
}
} }
err := utilerrors.NewAggregate(errs) if len(errs) != 0 {
if err != nil {
// Only print the output from the system verification check if the check failed // Only print the output from the system verification check if the check failed
fmt.Println("[preflight] The system verification failed. Printing the output from the verification:") fmt.Println("[preflight] The system verification failed. Printing the output from the verification:")
bufw.Flush() bufw.Flush()
return warns, []error{err} return warns, errs
} }
return warns, nil return warns, nil
} }
@ -575,7 +577,7 @@ func RunChecks(checks []Checker, ww io.Writer) error {
for _, c := range checks { for _, c := range checks {
warnings, errs := c.Check() warnings, errs := c.Check()
for _, w := range warnings { for _, w := range warnings {
io.WriteString(ww, fmt.Sprintf("[preflight] WARNING: %s\n", w)) io.WriteString(ww, fmt.Sprintf("[preflight] WARNING: %v\n", w))
} }
found = append(found, errs...) found = append(found, errs...)
} }