mirror of https://github.com/k3s-io/k3s
kubeadm-organize-phases
parent
9d6ebf6c78
commit
f38217c75b
|
@ -36,7 +36,7 @@ import (
|
||||||
kubeadmapiv1beta1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
|
kubeadmapiv1beta1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
|
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases"
|
phases "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/init"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
||||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
|
@ -168,7 +168,7 @@ func NewCmdInit(out io.Writer, initOptions *initOptions) *cobra.Command {
|
||||||
})
|
})
|
||||||
|
|
||||||
// initialize the workflow runner with the list of phases
|
// initialize the workflow runner with the list of phases
|
||||||
initRunner.AppendPhase(phases.NewPreflightMasterPhase())
|
initRunner.AppendPhase(phases.NewPreflightPhase())
|
||||||
initRunner.AppendPhase(phases.NewKubeletStartPhase())
|
initRunner.AppendPhase(phases.NewKubeletStartPhase())
|
||||||
initRunner.AppendPhase(phases.NewCertsPhase())
|
initRunner.AppendPhase(phases.NewCertsPhase())
|
||||||
initRunner.AppendPhase(phases.NewKubeConfigPhase())
|
initRunner.AppendPhase(phases.NewKubeConfigPhase())
|
||||||
|
|
|
@ -38,7 +38,7 @@ import (
|
||||||
kubeadmapiv1beta1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
|
kubeadmapiv1beta1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
|
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases"
|
phases "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/join"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
||||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
|
@ -198,7 +198,7 @@ func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
|
||||||
addJoinConfigFlags(cmd.Flags(), joinOptions.externalcfg)
|
addJoinConfigFlags(cmd.Flags(), joinOptions.externalcfg)
|
||||||
addJoinOtherFlags(cmd.Flags(), &joinOptions.cfgPath, &joinOptions.ignorePreflightErrors, &joinOptions.controlPlane, &joinOptions.token)
|
addJoinOtherFlags(cmd.Flags(), &joinOptions.cfgPath, &joinOptions.ignorePreflightErrors, &joinOptions.controlPlane, &joinOptions.token)
|
||||||
|
|
||||||
joinRunner.AppendPhase(phases.NewPreflightJoinPhase())
|
joinRunner.AppendPhase(phases.NewPreflightPhase())
|
||||||
joinRunner.AppendPhase(phases.NewControlPlanePreparePhase())
|
joinRunner.AppendPhase(phases.NewControlPlanePreparePhase())
|
||||||
joinRunner.AppendPhase(phases.NewCheckEtcdPhase())
|
joinRunner.AppendPhase(phases.NewCheckEtcdPhase())
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 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 (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
||||||
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
|
||||||
|
"k8s.io/kubernetes/pkg/util/normalizer"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
controlPlaneExample = normalizer.Examples(`
|
||||||
|
# Generates all static Pod manifest files for control plane components,
|
||||||
|
# functionally equivalent to what is generated by kubeadm init.
|
||||||
|
kubeadm init phase control-plane all
|
||||||
|
|
||||||
|
# Generates all static Pod manifest files using options read from a configuration file.
|
||||||
|
kubeadm init phase control-plane all --config config.yaml
|
||||||
|
`)
|
||||||
|
|
||||||
|
controlPlanePhaseProperties = map[string]struct {
|
||||||
|
name string
|
||||||
|
short string
|
||||||
|
}{
|
||||||
|
kubeadmconstants.KubeAPIServer: {
|
||||||
|
name: "apiserver",
|
||||||
|
short: getPhaseDescription(kubeadmconstants.KubeAPIServer),
|
||||||
|
},
|
||||||
|
kubeadmconstants.KubeControllerManager: {
|
||||||
|
name: "controller-manager",
|
||||||
|
short: getPhaseDescription(kubeadmconstants.KubeControllerManager),
|
||||||
|
},
|
||||||
|
kubeadmconstants.KubeScheduler: {
|
||||||
|
name: "scheduler",
|
||||||
|
short: getPhaseDescription(kubeadmconstants.KubeScheduler),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
type controlPlaneData interface {
|
||||||
|
Cfg() *kubeadmapi.InitConfiguration
|
||||||
|
KubeConfigDir() string
|
||||||
|
ManifestDir() string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPhaseDescription(component string) string {
|
||||||
|
return fmt.Sprintf("Generates the %s static Pod manifest", component)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewControlPlanePhase creates a kubeadm workflow phase that implements bootstrapping the control plane.
|
||||||
|
func NewControlPlanePhase() workflow.Phase {
|
||||||
|
phase := workflow.Phase{
|
||||||
|
Name: "control-plane",
|
||||||
|
Short: "Generates all static Pod manifest files necessary to establish the control plane",
|
||||||
|
Long: cmdutil.MacroCommandLongDescription,
|
||||||
|
Phases: []workflow.Phase{
|
||||||
|
{
|
||||||
|
Name: "all",
|
||||||
|
Short: "Generates all static Pod manifest files",
|
||||||
|
InheritFlags: getControlPlanePhaseFlags("all"),
|
||||||
|
Example: controlPlaneExample,
|
||||||
|
RunAllSiblings: true,
|
||||||
|
},
|
||||||
|
newControlPlaneSubphase(kubeadmconstants.KubeAPIServer),
|
||||||
|
newControlPlaneSubphase(kubeadmconstants.KubeControllerManager),
|
||||||
|
newControlPlaneSubphase(kubeadmconstants.KubeScheduler),
|
||||||
|
},
|
||||||
|
Run: runControlPlanePhase,
|
||||||
|
}
|
||||||
|
return phase
|
||||||
|
}
|
||||||
|
|
||||||
|
func newControlPlaneSubphase(component string) workflow.Phase {
|
||||||
|
phase := workflow.Phase{
|
||||||
|
Name: controlPlanePhaseProperties[component].name,
|
||||||
|
Short: controlPlanePhaseProperties[component].short,
|
||||||
|
Run: runControlPlaneSubphase(component),
|
||||||
|
InheritFlags: getControlPlanePhaseFlags(component),
|
||||||
|
}
|
||||||
|
return phase
|
||||||
|
}
|
||||||
|
|
||||||
|
func getControlPlanePhaseFlags(name string) []string {
|
||||||
|
flags := []string{
|
||||||
|
options.CfgPath,
|
||||||
|
options.CertificatesDir,
|
||||||
|
options.KubernetesVersion,
|
||||||
|
options.ImageRepository,
|
||||||
|
}
|
||||||
|
if name == "all" || name == kubeadmconstants.KubeAPIServer {
|
||||||
|
flags = append(flags,
|
||||||
|
options.APIServerAdvertiseAddress,
|
||||||
|
options.APIServerBindPort,
|
||||||
|
options.APIServerExtraArgs,
|
||||||
|
options.FeatureGatesString,
|
||||||
|
options.NetworkingServiceSubnet,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if name == "all" || name == kubeadmconstants.KubeControllerManager {
|
||||||
|
flags = append(flags,
|
||||||
|
options.ControllerManagerExtraArgs,
|
||||||
|
options.NetworkingPodSubnet,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if name == "all" || name == kubeadmconstants.KubeScheduler {
|
||||||
|
flags = append(flags,
|
||||||
|
options.SchedulerExtraArgs,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
func runControlPlanePhase(c workflow.RunData) error {
|
||||||
|
data, ok := c.(controlPlaneData)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("control-plane phase invoked with an invalid data struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("[control-plane] Using manifest folder %q\n", data.ManifestDir())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func runControlPlaneSubphase(component string) func(c workflow.RunData) error {
|
||||||
|
return func(c workflow.RunData) error {
|
||||||
|
data, ok := c.(controlPlaneData)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("control-plane phase invoked with an invalid data struct")
|
||||||
|
}
|
||||||
|
cfg := data.Cfg()
|
||||||
|
|
||||||
|
fmt.Printf("[control-plane] Creating static Pod manifest for %q\n", component)
|
||||||
|
return controlplane.CreateStaticPodFiles(data.ManifestDir(), &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, component)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
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 (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/preflight"
|
||||||
|
"k8s.io/kubernetes/pkg/util/normalizer"
|
||||||
|
utilsexec "k8s.io/utils/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
preflightExample = normalizer.Examples(`
|
||||||
|
# Run pre-flight checks for kubeadm init using a config file.
|
||||||
|
kubeadm init phase preflight --config kubeadm-config.yml
|
||||||
|
`)
|
||||||
|
)
|
||||||
|
|
||||||
|
// preflightData defines the behavior that a runtime data struct passed to the Preflight phase
|
||||||
|
// should have. Please note that we are using an interface in order to make this phase reusable in different workflows
|
||||||
|
// (and thus with different runtime data struct, all of them requested to be compliant to this interface)
|
||||||
|
type preflightData interface {
|
||||||
|
Cfg() *kubeadmapi.InitConfiguration
|
||||||
|
DryRun() bool
|
||||||
|
IgnorePreflightErrors() sets.String
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPreflightPhase creates a kubeadm workflow phase that implements preflight checks for a new control-plane node.
|
||||||
|
func NewPreflightPhase() workflow.Phase {
|
||||||
|
return workflow.Phase{
|
||||||
|
Name: "preflight",
|
||||||
|
Short: "Run pre-flight checks",
|
||||||
|
Long: "Run pre-flight checks for kubeadm init.",
|
||||||
|
Example: preflightExample,
|
||||||
|
Run: runPreflight,
|
||||||
|
InheritFlags: []string{
|
||||||
|
options.CfgPath,
|
||||||
|
options.IgnorePreflightErrors,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// runPreflight executes preflight checks logic.
|
||||||
|
func runPreflight(c workflow.RunData) error {
|
||||||
|
data, ok := c.(preflightData)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("preflight phase invoked with an invalid data struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("[preflight] Running pre-flight checks")
|
||||||
|
if err := preflight.RunInitMasterChecks(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !data.DryRun() {
|
||||||
|
fmt.Println("[preflight] Pulling images required for setting up a Kubernetes cluster")
|
||||||
|
fmt.Println("[preflight] This might take a minute or two, depending on the speed of your internet connection")
|
||||||
|
fmt.Println("[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'")
|
||||||
|
if err := preflight.RunPullImagesCheck(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("[preflight] Would pull the required images (like 'kubeadm config images pull')")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -30,77 +30,14 @@ import (
|
||||||
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
|
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
|
||||||
kubeconfigphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubeconfig"
|
kubeconfigphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubeconfig"
|
||||||
"k8s.io/kubernetes/pkg/util/normalizer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
controlPlaneExample = normalizer.Examples(`
|
|
||||||
# Generates all static Pod manifest files for control plane components,
|
|
||||||
# functionally equivalent to what is generated by kubeadm init.
|
|
||||||
kubeadm init phase control-plane all
|
|
||||||
|
|
||||||
# Generates all static Pod manifest files using options read from a configuration file.
|
|
||||||
kubeadm init phase control-plane all --config config.yaml
|
|
||||||
`)
|
|
||||||
|
|
||||||
controlPlanePhaseProperties = map[string]struct {
|
|
||||||
name string
|
|
||||||
short string
|
|
||||||
}{
|
|
||||||
kubeadmconstants.KubeAPIServer: {
|
|
||||||
name: "apiserver",
|
|
||||||
short: getPhaseDescription(kubeadmconstants.KubeAPIServer),
|
|
||||||
},
|
|
||||||
kubeadmconstants.KubeControllerManager: {
|
|
||||||
name: "controller-manager",
|
|
||||||
short: getPhaseDescription(kubeadmconstants.KubeControllerManager),
|
|
||||||
},
|
|
||||||
kubeadmconstants.KubeScheduler: {
|
|
||||||
name: "scheduler",
|
|
||||||
short: getPhaseDescription(kubeadmconstants.KubeScheduler),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
type controlPlaneData interface {
|
|
||||||
Cfg() *kubeadmapi.InitConfiguration
|
|
||||||
KubeConfigDir() string
|
|
||||||
ManifestDir() string
|
|
||||||
}
|
|
||||||
|
|
||||||
type controlPlanePrepareData interface {
|
type controlPlanePrepareData interface {
|
||||||
Cfg() *kubeadmapi.JoinConfiguration
|
Cfg() *kubeadmapi.JoinConfiguration
|
||||||
ClientSetFromFile(string) (*clientset.Clientset, error)
|
ClientSetFromFile(string) (*clientset.Clientset, error)
|
||||||
InitCfg() (*kubeadmapi.InitConfiguration, error)
|
InitCfg() (*kubeadmapi.InitConfiguration, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPhaseDescription(component string) string {
|
|
||||||
return fmt.Sprintf("Generates the %s static Pod manifest", component)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewControlPlanePhase creates a kubeadm workflow phase that implements bootstrapping the control plane.
|
|
||||||
func NewControlPlanePhase() workflow.Phase {
|
|
||||||
phase := workflow.Phase{
|
|
||||||
Name: "control-plane",
|
|
||||||
Short: "Generates all static Pod manifest files necessary to establish the control plane",
|
|
||||||
Long: cmdutil.MacroCommandLongDescription,
|
|
||||||
Phases: []workflow.Phase{
|
|
||||||
{
|
|
||||||
Name: "all",
|
|
||||||
Short: "Generates all static Pod manifest files",
|
|
||||||
InheritFlags: getControlPlanePhaseFlags("all"),
|
|
||||||
Example: controlPlaneExample,
|
|
||||||
RunAllSiblings: true,
|
|
||||||
},
|
|
||||||
newControlPlaneSubphase(kubeadmconstants.KubeAPIServer),
|
|
||||||
newControlPlaneSubphase(kubeadmconstants.KubeControllerManager),
|
|
||||||
newControlPlaneSubphase(kubeadmconstants.KubeScheduler),
|
|
||||||
},
|
|
||||||
Run: runControlPlanePhase,
|
|
||||||
}
|
|
||||||
return phase
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewControlPlanePreparePhase creates a kubeadm workflow phase that implements the preparation of the node to serve a control plane
|
// NewControlPlanePreparePhase creates a kubeadm workflow phase that implements the preparation of the node to serve a control plane
|
||||||
func NewControlPlanePreparePhase() workflow.Phase {
|
func NewControlPlanePreparePhase() workflow.Phase {
|
||||||
return workflow.Phase{
|
return workflow.Phase{
|
||||||
|
@ -108,6 +45,12 @@ func NewControlPlanePreparePhase() workflow.Phase {
|
||||||
Short: "Prepares the machine for serving a control plane.",
|
Short: "Prepares the machine for serving a control plane.",
|
||||||
Long: cmdutil.MacroCommandLongDescription,
|
Long: cmdutil.MacroCommandLongDescription,
|
||||||
Phases: []workflow.Phase{
|
Phases: []workflow.Phase{
|
||||||
|
{
|
||||||
|
Name: "all",
|
||||||
|
Short: "Prepares the machine for serving a control plane.",
|
||||||
|
InheritFlags: getControlPlanePreparePhaseFlags(),
|
||||||
|
RunAllSiblings: true,
|
||||||
|
},
|
||||||
newControlPlanePrepareCertsSubphase(),
|
newControlPlanePrepareCertsSubphase(),
|
||||||
newControlPlanePrepareKubeconfigSubphase(),
|
newControlPlanePrepareKubeconfigSubphase(),
|
||||||
newControlPlanePrepareManifestsSubphases(),
|
newControlPlanePrepareManifestsSubphases(),
|
||||||
|
@ -115,46 +58,6 @@ func NewControlPlanePreparePhase() workflow.Phase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newControlPlaneSubphase(component string) workflow.Phase {
|
|
||||||
phase := workflow.Phase{
|
|
||||||
Name: controlPlanePhaseProperties[component].name,
|
|
||||||
Short: controlPlanePhaseProperties[component].short,
|
|
||||||
Run: runControlPlaneSubphase(component),
|
|
||||||
InheritFlags: getControlPlanePhaseFlags(component),
|
|
||||||
}
|
|
||||||
return phase
|
|
||||||
}
|
|
||||||
|
|
||||||
func getControlPlanePhaseFlags(name string) []string {
|
|
||||||
flags := []string{
|
|
||||||
options.CfgPath,
|
|
||||||
options.CertificatesDir,
|
|
||||||
options.KubernetesVersion,
|
|
||||||
options.ImageRepository,
|
|
||||||
}
|
|
||||||
if name == "all" || name == kubeadmconstants.KubeAPIServer {
|
|
||||||
flags = append(flags,
|
|
||||||
options.APIServerAdvertiseAddress,
|
|
||||||
options.APIServerBindPort,
|
|
||||||
options.APIServerExtraArgs,
|
|
||||||
options.FeatureGatesString,
|
|
||||||
options.NetworkingServiceSubnet,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if name == "all" || name == kubeadmconstants.KubeControllerManager {
|
|
||||||
flags = append(flags,
|
|
||||||
options.ControllerManagerExtraArgs,
|
|
||||||
options.NetworkingPodSubnet,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if name == "all" || name == kubeadmconstants.KubeScheduler {
|
|
||||||
flags = append(flags,
|
|
||||||
options.SchedulerExtraArgs,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return flags
|
|
||||||
}
|
|
||||||
|
|
||||||
func getControlPlanePreparePhaseFlags() []string {
|
func getControlPlanePreparePhaseFlags() []string {
|
||||||
return []string{
|
return []string{
|
||||||
options.APIServerAdvertiseAddress,
|
options.APIServerAdvertiseAddress,
|
||||||
|
@ -173,7 +76,7 @@ func newControlPlanePrepareCertsSubphase() workflow.Phase {
|
||||||
Name: "certs",
|
Name: "certs",
|
||||||
Short: "Generates the certificates for the new control plane components",
|
Short: "Generates the certificates for the new control plane components",
|
||||||
Run: runControlPlanePrepareCertsPhaseLocal,
|
Run: runControlPlanePrepareCertsPhaseLocal,
|
||||||
InheritFlags: getControlPlanePreparePhaseFlags(),
|
InheritFlags: getControlPlanePreparePhaseFlags(), //NB. eventually in future we would like to break down this in sub phases for each cert or add the --csr option
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,59 +85,37 @@ func newControlPlanePrepareKubeconfigSubphase() workflow.Phase {
|
||||||
Name: "kubeconfig",
|
Name: "kubeconfig",
|
||||||
Short: "Generates the kubeconfig for the new control plane components",
|
Short: "Generates the kubeconfig for the new control plane components",
|
||||||
Run: runControlPlanePrepareKubeconfigPhaseLocal,
|
Run: runControlPlanePrepareKubeconfigPhaseLocal,
|
||||||
InheritFlags: getControlPlanePreparePhaseFlags(),
|
InheritFlags: getControlPlanePreparePhaseFlags(), //NB. eventually in future we would like to break down this in sub phases for each kubeconfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newControlPlanePrepareManifestsSubphases() workflow.Phase {
|
func newControlPlanePrepareManifestsSubphases() workflow.Phase {
|
||||||
return workflow.Phase{
|
return workflow.Phase{
|
||||||
Name: "manifests",
|
Name: "manifests",
|
||||||
Short: "Generates the manifests for the new control plane components",
|
Short: "Generates the manifests for the new control plane components",
|
||||||
Phases: []workflow.Phase{
|
Run: runControlPlaneSubphase,
|
||||||
{
|
InheritFlags: getControlPlanePreparePhaseFlags(), //NB. eventually in future we would like to break down this in sub phases for each component
|
||||||
Name: "all",
|
|
||||||
Short: "Generates all static Pod manifest files",
|
|
||||||
InheritFlags: getControlPlanePreparePhaseFlags(),
|
|
||||||
RunAllSiblings: true,
|
|
||||||
},
|
|
||||||
newControlPlanePrepareSubphase(kubeadmconstants.KubeAPIServer),
|
|
||||||
newControlPlanePrepareSubphase(kubeadmconstants.KubeControllerManager),
|
|
||||||
newControlPlanePrepareSubphase(kubeadmconstants.KubeScheduler),
|
|
||||||
},
|
|
||||||
InheritFlags: getControlPlanePreparePhaseFlags(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newControlPlanePrepareSubphase(component string) workflow.Phase {
|
func runControlPlaneSubphase(c workflow.RunData) error {
|
||||||
return workflow.Phase{
|
data, ok := c.(controlPlanePrepareData)
|
||||||
Name: controlPlanePhaseProperties[component].name,
|
|
||||||
Short: controlPlanePhaseProperties[component].short,
|
|
||||||
Run: runControlPlanePrepareJoinSubphase(component),
|
|
||||||
InheritFlags: getControlPlanePreparePhaseFlags(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func runControlPlanePhase(c workflow.RunData) error {
|
|
||||||
data, ok := c.(controlPlaneData)
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("control-plane phase invoked with an invalid data struct")
|
return errors.New("control-plane-prepare phase invoked with an invalid data struct")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("[control-plane] Using manifest folder %q\n", data.ManifestDir())
|
// Skip if this is not a control plane
|
||||||
return nil
|
if data.Cfg().ControlPlane == nil {
|
||||||
}
|
return nil
|
||||||
|
|
||||||
func runControlPlaneSubphase(component string) func(c workflow.RunData) error {
|
|
||||||
return func(c workflow.RunData) error {
|
|
||||||
data, ok := c.(controlPlaneData)
|
|
||||||
if !ok {
|
|
||||||
return errors.New("control-plane phase invoked with an invalid data struct")
|
|
||||||
}
|
|
||||||
cfg := data.Cfg()
|
|
||||||
|
|
||||||
fmt.Printf("[control-plane] Creating static Pod manifest for %q\n", component)
|
|
||||||
return controlplane.CreateStaticPodFiles(data.ManifestDir(), &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, component)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg, err := data.InitCfg()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate missing certificates (if any)
|
||||||
|
return controlplane.CreateInitStaticPodManifestFiles(kubeadmconstants.GetStaticPodDirectory(), cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runControlPlanePrepareCertsPhaseLocal(c workflow.RunData) error {
|
func runControlPlanePrepareCertsPhaseLocal(c workflow.RunData) error {
|
|
@ -35,11 +35,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
initPreflightExample = normalizer.Examples(`
|
preflightExample = normalizer.Examples(`
|
||||||
# Run master pre-flight checks using a config file.
|
|
||||||
kubeadm init phase preflight --config kubeadm-config.yml
|
|
||||||
`)
|
|
||||||
joinPreflightExample = normalizer.Examples(`
|
|
||||||
# Run join pre-flight checks using a config file.
|
# Run join pre-flight checks using a config file.
|
||||||
kubeadm join phase preflight --config kubeadm-config.yml
|
kubeadm join phase preflight --config kubeadm-config.yml
|
||||||
`)
|
`)
|
||||||
|
@ -56,71 +52,20 @@ var (
|
||||||
`)))
|
`)))
|
||||||
)
|
)
|
||||||
|
|
||||||
// preflightMasterData defines the behavior that a runtime data struct passed to the PreflightMaster master phase
|
type preflightData interface {
|
||||||
// should have. Please note that we are using an interface in order to make this phase reusable in different workflows
|
|
||||||
// (and thus with different runtime data struct, all of them requested to be compliant to this interface)
|
|
||||||
type preflightMasterData interface {
|
|
||||||
Cfg() *kubeadmapi.InitConfiguration
|
|
||||||
DryRun() bool
|
|
||||||
IgnorePreflightErrors() sets.String
|
|
||||||
}
|
|
||||||
|
|
||||||
type preflightJoinData interface {
|
|
||||||
Cfg() *kubeadmapi.JoinConfiguration
|
Cfg() *kubeadmapi.JoinConfiguration
|
||||||
InitCfg() (*kubeadmapi.InitConfiguration, error)
|
InitCfg() (*kubeadmapi.InitConfiguration, error)
|
||||||
IgnorePreflightErrors() sets.String
|
IgnorePreflightErrors() sets.String
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPreflightMasterPhase creates a kubeadm workflow phase that implements preflight checks for a new master node.
|
// NewPreflightPhase creates a kubeadm workflow phase that implements preflight checks for a new node join
|
||||||
func NewPreflightMasterPhase() workflow.Phase {
|
func NewPreflightPhase() workflow.Phase {
|
||||||
return workflow.Phase{
|
|
||||||
Name: "preflight",
|
|
||||||
Short: "Run master pre-flight checks",
|
|
||||||
Long: "Run master pre-flight checks, functionally equivalent to what implemented by kubeadm init.",
|
|
||||||
Example: initPreflightExample,
|
|
||||||
Run: runPreflightMaster,
|
|
||||||
InheritFlags: []string{
|
|
||||||
options.CfgPath,
|
|
||||||
options.IgnorePreflightErrors,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(dmaiocchi): rename all instances of master to controlPlane in this file.
|
|
||||||
// runPreflightMaster executes preflight checks logic.
|
|
||||||
func runPreflightMaster(c workflow.RunData) error {
|
|
||||||
data, ok := c.(preflightMasterData)
|
|
||||||
if !ok {
|
|
||||||
return errors.New("preflight phase invoked with an invalid data struct")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("[preflight] Running pre-flight checks")
|
|
||||||
if err := preflight.RunInitMasterChecks(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !data.DryRun() {
|
|
||||||
fmt.Println("[preflight] Pulling images required for setting up a Kubernetes cluster")
|
|
||||||
fmt.Println("[preflight] This might take a minute or two, depending on the speed of your internet connection")
|
|
||||||
fmt.Println("[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'")
|
|
||||||
if err := preflight.RunPullImagesCheck(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("[preflight] Would pull the required images (like 'kubeadm config images pull')")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPreflightJoinPhase creates a kubeadm workflow phase that implements preflight checks for a new node join
|
|
||||||
func NewPreflightJoinPhase() workflow.Phase {
|
|
||||||
return workflow.Phase{
|
return workflow.Phase{
|
||||||
Name: "preflight",
|
Name: "preflight",
|
||||||
Short: "Run join pre-flight checks",
|
Short: "Run join pre-flight checks",
|
||||||
Long: "Run join pre-flight checks, functionally equivalent to what is implemented by kubeadm join.",
|
Long: "Run pre-flight checks for kubeadm join.",
|
||||||
Example: joinPreflightExample,
|
Example: preflightExample,
|
||||||
Run: runPreflightJoin,
|
Run: runPreflight,
|
||||||
InheritFlags: []string{
|
InheritFlags: []string{
|
||||||
options.CfgPath,
|
options.CfgPath,
|
||||||
options.IgnorePreflightErrors,
|
options.IgnorePreflightErrors,
|
||||||
|
@ -139,12 +84,14 @@ func NewPreflightJoinPhase() workflow.Phase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// runPreflightJoin executes preflight checks logic.
|
// runPreflight executes preflight checks logic.
|
||||||
func runPreflightJoin(c workflow.RunData) error {
|
func runPreflight(c workflow.RunData) error {
|
||||||
j, ok := c.(preflightJoinData)
|
j, ok := c.(preflightData)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("preflight phase invoked with an invalid data struct")
|
return errors.New("preflight phase invoked with an invalid data struct")
|
||||||
}
|
}
|
||||||
|
fmt.Println("[preflight] Running pre-flight checks")
|
||||||
|
|
||||||
// Start with general checks
|
// Start with general checks
|
||||||
klog.V(1).Infoln("[preflight] Running general checks")
|
klog.V(1).Infoln("[preflight] Running general checks")
|
||||||
if err := preflight.RunJoinNodeChecks(utilsexec.New(), j.Cfg(), j.IgnorePreflightErrors()); err != nil {
|
if err := preflight.RunJoinNodeChecks(utilsexec.New(), j.Cfg(), j.IgnorePreflightErrors()); err != nil {
|
||||||
|
@ -182,7 +129,9 @@ func runPreflightJoin(c workflow.RunData) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("[preflight] Pulling control-plane images")
|
fmt.Println("[preflight] Pulling images required for setting up a Kubernetes cluster")
|
||||||
|
fmt.Println("[preflight] This might take a minute or two, depending on the speed of your internet connection")
|
||||||
|
fmt.Println("[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'")
|
||||||
if err := preflight.RunPullImagesCheck(utilsexec.New(), initCfg, j.IgnorePreflightErrors()); err != nil {
|
if err := preflight.RunPullImagesCheck(utilsexec.New(), initCfg, j.IgnorePreflightErrors()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
Loading…
Reference in New Issue