Merge pull request #47803 from gtirloni/kubeadm-phase-preflight

Automatic merge from submit-queue (batch tested with PRs 47694, 47772, 47783, 47803, 47673)

Add "alpha phase preflight" command

**What this PR does / why we need it:**

Adds "alpha phase preflight" command to kubeadm in order to run pre-flight checks independently of init phase.

**Which issue this PR fixes:** fixes kubernetes/kubeadm#314

/cc @luxas
This commit is contained in:
Kubernetes Submit Queue 2017-06-23 08:29:30 -07:00 committed by GitHub
commit 0fe8006455
6 changed files with 77 additions and 13 deletions

View File

@ -167,12 +167,6 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, skipPreFlight,
if !skipPreFlight {
fmt.Println("[preflight] Running pre-flight checks")
// First, check if we're root separately from the other preflight checks and fail fast
if err := preflight.RunRootCheckOnly(); err != nil {
return nil, err
}
// Then continue with the others...
if err := preflight.RunInitMasterChecks(cfg); err != nil {
return nil, err
}

View File

@ -147,11 +147,6 @@ func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, s
if !skipPreFlight {
fmt.Println("[preflight] Running pre-flight checks")
// First, check if we're root separately from the other preflight checks and fail fast
if err := preflight.RunRootCheckOnly(); err != nil {
return nil, err
}
// Then continue with the others...
if err := preflight.RunJoinNodeChecks(cfg); err != nil {
return nil, err

View File

@ -13,6 +13,7 @@ go_library(
"certs.go",
"kubeconfig.go",
"phase.go",
"preflight.go",
"validate.go",
],
tags = ["automanaged"],
@ -23,6 +24,7 @@ go_library(
"//cmd/kubeadm/app/phases/certs:go_default_library",
"//cmd/kubeadm/app/phases/kubeconfig:go_default_library",
"//cmd/kubeadm/app/phases/validate:go_default_library",
"//cmd/kubeadm/app/preflight:go_default_library",
"//cmd/kubeadm/app/util:go_default_library",
"//pkg/api:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",

View File

@ -33,6 +33,7 @@ func NewCmdPhase(out io.Writer) *cobra.Command {
cmd.AddCommand(NewCmdKubeConfig(out))
cmd.AddCommand(NewCmdCerts())
cmd.AddCommand(NewCmdValidate())
cmd.AddCommand(NewCmdPreFlight())
return cmd
}
@ -46,8 +47,8 @@ func subCmdRunE(name string) func(*cobra.Command, []string) error {
return func(_ *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("missing subcommand; %q is not meant to be run on its own", name)
} else {
return fmt.Errorf("invalid subcommand: %q", args[0])
}
return fmt.Errorf("invalid subcommand: %q", args[0])
}
}

View File

@ -0,0 +1,62 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package phases
import (
"github.com/spf13/cobra"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/preflight"
)
func NewCmdPreFlight() *cobra.Command {
cmd := &cobra.Command{
Use: "preflight",
Short: "Run pre-flight checks",
RunE: subCmdRunE("preflight"),
}
cmd.AddCommand(NewCmdPreFlightMaster())
cmd.AddCommand(NewCmdPreFlightNode())
return cmd
}
func NewCmdPreFlightMaster() *cobra.Command {
cmd := &cobra.Command{
Use: "master",
Short: "Run master pre-flight checks",
RunE: func(cmd *cobra.Command, args []string) error {
cfg := &kubeadmapi.MasterConfiguration{}
return preflight.RunInitMasterChecks(cfg)
},
}
return cmd
}
func NewCmdPreFlightNode() *cobra.Command {
cmd := &cobra.Command{
Use: "node",
Short: "Run node pre-flight checks",
RunE: func(cmd *cobra.Command, args []string) error {
cfg := &kubeadmapi.NodeConfiguration{}
return preflight.RunJoinNodeChecks(cfg)
},
}
return cmd
}

View File

@ -485,6 +485,11 @@ func getEtcdVersionResponse(client *http.Client, url string, target interface{})
return err
}
func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
// First, check if we're root separately from the other preflight checks and fail fast
if err := RunRootCheckOnly(); err != nil {
return err
}
checks := []Checker{
SystemVerificationCheck{},
IsRootCheck{},
@ -538,6 +543,11 @@ func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
}
func RunJoinNodeChecks(cfg *kubeadmapi.NodeConfiguration) error {
// First, check if we're root separately from the other preflight checks and fail fast
if err := RunRootCheckOnly(); err != nil {
return err
}
checks := []Checker{
SystemVerificationCheck{},
IsRootCheck{},