kubeadm: fix preflight checks.

This commit is contained in:
Paulo Pires 2016-10-14 18:03:27 +01:00
parent 928b8cbdb8
commit cf000bff95
No known key found for this signature in database
GPG Key ID: F3F6ED5C522EAA71
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" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubemaster "k8s.io/kubernetes/cmd/kubeadm/app/master" kubemaster "k8s.io/kubernetes/cmd/kubeadm/app/master"
"k8s.io/kubernetes/cmd/kubeadm/app/preflight" "k8s.io/kubernetes/cmd/kubeadm/app/preflight"
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/cloudprovider" "k8s.io/kubernetes/pkg/cloudprovider"
@ -55,14 +54,9 @@ func NewCmdInit(out io.Writer) *cobra.Command {
Use: "init", Use: "init",
Short: "Run this in order to set up the Kubernetes master.", Short: "Run this in order to set up the Kubernetes master.",
Run: func(cmd *cobra.Command, args []string) { 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) i, err := NewInit(cfgPath, cfg, skipPreFlight)
check(err) kubeadmutil.CheckErr(err)
check(i.Run(out)) 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", "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().MarkDeprecated("external-etcd-keyfile", "this flag will be removed when componentconfig exists")
cmd.PersistentFlags().BoolVar( cmd.PersistentFlags().BoolVar(
&skipPreFlight, "skip-preflight-checks", false, &skipPreFlight, "skip-preflight-checks", false,
"skip preflight checks normally run before modifying the system", "skip preflight checks normally run before modifying the system",
@ -150,10 +145,10 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, skipPreFlight
} }
if !skipPreFlight { if !skipPreFlight {
fmt.Println("<cmd/init> Running pre-flight checks") fmt.Println("Running pre-flight checks")
err := preflight.RunInitMasterChecks() err := preflight.RunInitMasterChecks()
if err != nil { if err != nil {
return nil, err return nil, &preflight.PreFlightError{Msg: err.Error()}
} }
} else { } else {
fmt.Println("Skipping pre-flight checks") fmt.Println("Skipping pre-flight checks")
@ -180,9 +175,8 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, skipPreFlight
return &Init{cfg: cfg}, nil 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 { func (i *Init) Run(out io.Writer) error {
if err := kubemaster.CreateTokenAuthFile(&i.cfg.Secrets); err != nil { if err := kubemaster.CreateTokenAuthFile(&i.cfg.Secrets); err != nil {
return err 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") fmt.Println("Running pre-flight checks")
err := preflight.RunJoinNodeChecks() err := preflight.RunJoinNodeChecks()
if err != nil { if err != nil {
return err return &preflight.PreFlightError{Msg: err.Error()}
} }
} else { } else {
fmt.Println("Skipping pre-flight checks") fmt.Println("Skipping pre-flight checks")

View File

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