Merge pull request #34834 from apprenda/kubeadm_fix_preflight

Automatic merge from submit-queue

kubeadm: fix preflight checks

This PR fixes a couple issues cause by some bad rebases:
* When a pre-flight check returned errors, `kubeadm` would exit with error code `1` instead of `2` as the original pre-flight PR meant. This would also cause the output of `kubeadm` to include some stuff that was not supposed to be there.
* Duplicated `k8s.io/kubernetes/cmd/kubeadm/app/util` import.

I also took the freedom to do some output clean-up based on the input from the original pre-flight PR.

/cc @dmmcquay @dgoodwin @luxas
This commit is contained in:
Kubernetes Submit Queue 2016-10-14 15:50:25 -07:00 committed by GitHub
commit 8e6eb1a1ef
3 changed files with 16 additions and 25 deletions

View File

@ -27,7 +27,6 @@ import (
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubemaster "k8s.io/kubernetes/cmd/kubeadm/app/master"
"k8s.io/kubernetes/cmd/kubeadm/app/preflight"
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/cloudprovider"
@ -55,14 +54,9 @@ func NewCmdInit(out io.Writer) *cobra.Command {
Use: "init",
Short: "Run this in order to set up the Kubernetes master.",
Run: func(cmd *cobra.Command, args []string) {
check := func(err error) {
if err != nil {
cmdutil.CheckErr(fmt.Errorf("<cmd/init> %v", err))
}
}
i, err := NewInit(cfgPath, cfg, skipPreFlight)
check(err)
check(i.Run(out))
kubeadmutil.CheckErr(err)
kubeadmutil.CheckErr(i.Run(out))
},
}
@ -126,6 +120,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
"etcd client key file. Note: The path must be in /etc/ssl/certs",
)
cmd.PersistentFlags().MarkDeprecated("external-etcd-keyfile", "this flag will be removed when componentconfig exists")
cmd.PersistentFlags().BoolVar(
&skipPreFlight, "skip-preflight-checks", false,
"skip preflight checks normally run before modifying the system",
@ -150,10 +145,10 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, skipPreFlight
}
if !skipPreFlight {
fmt.Println("<cmd/init> Running pre-flight checks")
fmt.Println("Running pre-flight checks")
err := preflight.RunInitMasterChecks()
if err != nil {
return nil, err
return nil, &preflight.PreFlightError{Msg: err.Error()}
}
} else {
fmt.Println("Skipping pre-flight checks")
@ -180,9 +175,8 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, skipPreFlight
return &Init{cfg: cfg}, nil
}
// RunInit executes master node provisioning, including certificates, needed static pod manifests, etc.
// Run executes master node provisioning, including certificates, needed static pod manifests, etc.
func (i *Init) Run(out io.Writer) error {
if err := kubemaster.CreateTokenAuthFile(&i.cfg.Secrets); err != nil {
return err
}

View File

@ -73,7 +73,7 @@ func RunJoin(out io.Writer, cmd *cobra.Command, args []string, s *kubeadmapi.Nod
fmt.Println("Running pre-flight checks")
err := preflight.RunJoinNodeChecks()
if err != nil {
return err
return &preflight.PreFlightError{Msg: err.Error()}
}
} else {
fmt.Println("Skipping pre-flight checks")

View File

@ -17,6 +17,7 @@ limitations under the License.
package preflight
import (
"errors"
"fmt"
"io"
"net"
@ -27,12 +28,11 @@ import (
)
type PreFlightError struct {
Msg string
Count int
Msg string
}
func (e *PreFlightError) Error() string {
return fmt.Sprintf("preflight check error\n count: %d \n msg: %s", e.Count, e.Msg)
return fmt.Sprintf("preflight check errors:\n%s", e.Msg)
}
// PreFlightCheck validates the state of the system to ensure kubeadm will be
@ -216,23 +216,20 @@ func RunJoinNodeChecks() error {
func runChecks(checks []PreFlightCheck) error {
found := []error{}
for _, c := range checks {
warnings, errors := c.Check()
warnings, errs := c.Check()
for _, w := range warnings {
fmt.Printf("<preflight/checks> WARNING: %s\n", w)
fmt.Printf("WARNING: %s\n", w)
}
for _, e := range errors {
for _, e := range errs {
found = append(found, e)
}
}
if len(found) > 0 {
errors := "\n"
errs := ""
for _, i := range found {
errors += "\t" + i.Error() + "\n"
}
return &PreFlightError{
Msg: errors,
Count: len(found),
errs += "\t" + i.Error() + "\n"
}
return errors.New(errs)
}
return nil
}