Merge pull request #71069 from fabriziopandini/kubeadm-phases-add-all-subcommands

Kubeadm - add all subcommands to phases
This commit is contained in:
k8s-ci-robot 2018-11-16 15:17:03 -08:00 committed by GitHub
commit f4fd7b0b2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 132 additions and 25 deletions

View File

@ -23,6 +23,7 @@ import (
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"
dnsaddon "k8s.io/kubernetes/cmd/kubeadm/app/phases/addons/dns"
proxyaddon "k8s.io/kubernetes/cmd/kubeadm/app/phases/addons/proxy"
"k8s.io/kubernetes/pkg/util/normalizer"
@ -47,10 +48,16 @@ type addonData interface {
// NewAddonPhase returns the addon Cobra command
func NewAddonPhase() workflow.Phase {
return workflow.Phase{
Name: "addon",
Short: "Installs required addons for passing Conformance tests",
InheritFlags: getAddonPhaseFlags("all"),
Name: "addon",
Short: "Installs required addons for passing Conformance tests",
Long: cmdutil.MacroCommandLongDescription,
Phases: []workflow.Phase{
{
Name: "all",
Short: "Installs all the addons",
InheritFlags: getAddonPhaseFlags("all"),
RunAllSiblings: true,
},
{
Name: "coredns",
Short: "Installs the CoreDNS addon to a Kubernetes cluster",

View File

@ -66,12 +66,11 @@ type certsData interface {
// NewCertsPhase returns the phase for the certs
func NewCertsPhase() workflow.Phase {
return workflow.Phase{
Name: "certs",
Short: "Certificate generation",
Phases: newCertSubPhases(),
Run: runCerts,
InheritFlags: getCertPhaseFlags("all"),
LocalFlags: localFlags(),
Name: "certs",
Short: "Certificate generation",
Phases: newCertSubPhases(),
Run: runCerts,
Long: cmdutil.MacroCommandLongDescription,
}
}
@ -86,6 +85,17 @@ func localFlags() *pflag.FlagSet {
func newCertSubPhases() []workflow.Phase {
subPhases := []workflow.Phase{}
// All subphase
allPhase := workflow.Phase{
Name: "all",
Short: "Generates all certificates",
InheritFlags: getCertPhaseFlags("all"),
RunAllSiblings: true,
LocalFlags: localFlags(),
}
subPhases = append(subPhases, allPhase)
certTree, _ := certsphase.GetDefaultCertList().AsMap().CertTree()
for ca, certList := range certTree {

View File

@ -19,9 +19,11 @@ package phases
import (
"errors"
"fmt"
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"
@ -69,16 +71,21 @@ func getPhaseDescription(component string) string {
// 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",
Example: controlPlaneExample,
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"),
RunAllSiblings: true,
},
newControlPlaneSubPhase(kubeadmconstants.KubeAPIServer),
newControlPlaneSubPhase(kubeadmconstants.KubeControllerManager),
newControlPlaneSubPhase(kubeadmconstants.KubeScheduler),
},
Run: runControlPlanePhase,
InheritFlags: getControlPlanePhaseFlags("all"),
Run: runControlPlanePhase,
}
return phase
}

View File

@ -24,6 +24,7 @@ import (
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"
etcdphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/etcd"
"k8s.io/kubernetes/pkg/util/normalizer"
)
@ -48,13 +49,12 @@ type etcdData interface {
// NewEtcdPhase creates a kubeadm workflow phase that implements handling of etcd.
func NewEtcdPhase() workflow.Phase {
phase := workflow.Phase{
Name: "etcd",
Short: "Generates static Pod manifest file for local etcd.",
Example: etcdLocalExample,
Name: "etcd",
Short: "Generates static Pod manifest file for local etcd.",
Long: cmdutil.MacroCommandLongDescription,
Phases: []workflow.Phase{
newEtcdLocalSubPhase(),
},
InheritFlags: getEtcdPhaseFlags(),
}
return phase
}

View File

@ -23,6 +23,7 @@ import (
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"
kubeconfigphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubeconfig"
"k8s.io/kubernetes/pkg/util/normalizer"
@ -77,14 +78,20 @@ func NewKubeConfigPhase() workflow.Phase {
return workflow.Phase{
Name: "kubeconfig",
Short: "Generates all kubeconfig files necessary to establish the control plane and the admin kubeconfig file",
Long: cmdutil.MacroCommandLongDescription,
Phases: []workflow.Phase{
{
Name: "all",
Short: "Generates all kubeconfig files",
InheritFlags: getKubeConfigPhaseFlags("all"),
RunAllSiblings: true,
},
NewKubeConfigFilePhase(kubeadmconstants.AdminKubeConfigFileName),
NewKubeConfigFilePhase(kubeadmconstants.KubeletKubeConfigFileName),
NewKubeConfigFilePhase(kubeadmconstants.ControllerManagerKubeConfigFileName),
NewKubeConfigFilePhase(kubeadmconstants.SchedulerKubeConfigFileName),
},
Run: runKubeConfig,
InheritFlags: getKubeConfigPhaseFlags("all"),
Run: runKubeConfig,
}
}

View File

@ -71,6 +71,11 @@ func NewUploadConfigPhase() workflow.Phase {
Short: "Uploads the kubeadm and kubelet configuration to a ConfigMap",
Long: cmdutil.MacroCommandLongDescription,
Phases: []workflow.Phase{
{
Name: "all",
Short: "Uploads all configuration to a config map",
RunAllSiblings: true,
},
{
Name: "kubeadm",
Short: "Uploads the kubeadm ClusterConfiguration to a ConfigMap",

View File

@ -45,6 +45,11 @@ type Phase struct {
// Phases defines a nested, ordered sequence of phases.
Phases []Phase
// RunAllSiblings allows to assign to a phase the responsibility to
// run all the sibling phases
// Nb. phase marked as RunAllSiblings can not have Run functions
RunAllSiblings bool
// Run defines a function implementing the phase action.
// It is recommended to implent type assertion, e.g. using golang type switch,
// for validating the RunData type.

View File

@ -211,6 +211,12 @@ func (e *Runner) Run() error {
return nil
}
// Errors if phases that are meant to create special subcommands only
// are wrongly assigned Run Methods
if p.RunAllSiblings && (p.RunIf != nil || p.Run != nil) {
return errors.Wrapf(err, "phase marked as RunAllSiblings can not have Run functions %s", p.generatedName)
}
// If the phase defines a condition to be checked before executing the phase action.
if p.RunIf != nil {
// Check the condition and returns if the condition isn't satisfied (or fails)
@ -244,7 +250,7 @@ func (e *Runner) Help(cmdUse string) string {
// computes the max length of for each phase use line
maxLength := 0
e.visitAll(func(p *phaseRunner) error {
if !p.Hidden {
if !p.Hidden && !p.RunAllSiblings {
length := len(p.use)
if maxLength < length {
maxLength = length
@ -259,7 +265,7 @@ func (e *Runner) Help(cmdUse string) string {
line += "```\n"
offset := 2
e.visitAll(func(p *phaseRunner) error {
if !p.Hidden {
if !p.Hidden && !p.RunAllSiblings {
padding := maxLength - len(p.use) + offset
line += strings.Repeat(" ", offset*p.level) // indentation
line += p.use // name + aliases
@ -312,17 +318,31 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
return nil
}
// creates nested phase subcommand
var phaseCmd = &cobra.Command{
// initialize phase selector
phaseSelector := p.generatedName
// if requested, set the phase to run all the sibling phases
if p.RunAllSiblings {
phaseSelector = p.parent.generatedName
}
// creates phase subcommand
phaseCmd := &cobra.Command{
Use: strings.ToLower(p.Name),
Short: p.Short,
Long: p.Long,
Example: p.Example,
Aliases: p.Aliases,
Run: func(cmd *cobra.Command, args []string) {
// if the phase has subphases, print the help and exits
if len(p.Phases) > 0 {
cmd.Help()
return
}
// overrides the command triggering the Runner using the phaseCmd
e.runCmd = cmd
e.Options.FilterPhases = []string{p.generatedName}
e.Options.FilterPhases = []string{phaseSelector}
if err := e.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
@ -405,6 +425,12 @@ func (e *Runner) prepareForExecution() {
e.phaseRunners = []*phaseRunner{}
var parentRunner *phaseRunner
for _, phase := range e.Phases {
// skips phases that are meant to create special subcommands only
if phase.RunAllSiblings {
continue
}
// add phases to the execution list
addPhaseRunner(e, parentRunner, phase)
}
}

View File

@ -42,10 +42,12 @@ docs/admin/kubeadm_config_view.md
docs/admin/kubeadm_init.md
docs/admin/kubeadm_init_phase.md
docs/admin/kubeadm_init_phase_addon.md
docs/admin/kubeadm_init_phase_addon_all.md
docs/admin/kubeadm_init_phase_addon_coredns.md
docs/admin/kubeadm_init_phase_addon_kube-proxy.md
docs/admin/kubeadm_init_phase_bootstrap-token.md
docs/admin/kubeadm_init_phase_certs.md
docs/admin/kubeadm_init_phase_certs_all.md
docs/admin/kubeadm_init_phase_certs_apiserver-etcd-client.md
docs/admin/kubeadm_init_phase_certs_apiserver-kubelet-client.md
docs/admin/kubeadm_init_phase_certs_apiserver.md
@ -58,6 +60,7 @@ docs/admin/kubeadm_init_phase_certs_front-proxy-ca.md
docs/admin/kubeadm_init_phase_certs_front-proxy-client.md
docs/admin/kubeadm_init_phase_certs_sa.md
docs/admin/kubeadm_init_phase_control-plane.md
docs/admin/kubeadm_init_phase_control-plane_all.md
docs/admin/kubeadm_init_phase_control-plane_apiserver.md
docs/admin/kubeadm_init_phase_control-plane_controller-manager.md
docs/admin/kubeadm_init_phase_control-plane_scheduler.md
@ -65,6 +68,7 @@ docs/admin/kubeadm_init_phase_etcd.md
docs/admin/kubeadm_init_phase_etcd_local.md
docs/admin/kubeadm_init_phase_kubeconfig.md
docs/admin/kubeadm_init_phase_kubeconfig_admin.md
docs/admin/kubeadm_init_phase_kubeconfig_all.md
docs/admin/kubeadm_init_phase_kubeconfig_controller-manager.md
docs/admin/kubeadm_init_phase_kubeconfig_kubelet.md
docs/admin/kubeadm_init_phase_kubeconfig_scheduler.md
@ -72,6 +76,7 @@ docs/admin/kubeadm_init_phase_kubelet-start.md
docs/admin/kubeadm_init_phase_mark-control-plane.md
docs/admin/kubeadm_init_phase_preflight.md
docs/admin/kubeadm_init_phase_upload-config.md
docs/admin/kubeadm_init_phase_upload-config_all.md
docs/admin/kubeadm_init_phase_upload-config_kubeadm.md
docs/admin/kubeadm_init_phase_upload-config_kubelet.md
docs/admin/kubeadm_join.md
@ -131,10 +136,12 @@ docs/man/man1/kubeadm-config-upload-from-flags.1
docs/man/man1/kubeadm-config-upload.1
docs/man/man1/kubeadm-config-view.1
docs/man/man1/kubeadm-config.1
docs/man/man1/kubeadm-init-phase-addon-all.1
docs/man/man1/kubeadm-init-phase-addon-coredns.1
docs/man/man1/kubeadm-init-phase-addon-kube-proxy.1
docs/man/man1/kubeadm-init-phase-addon.1
docs/man/man1/kubeadm-init-phase-bootstrap-token.1
docs/man/man1/kubeadm-init-phase-certs-all.1
docs/man/man1/kubeadm-init-phase-certs-apiserver-etcd-client.1
docs/man/man1/kubeadm-init-phase-certs-apiserver-kubelet-client.1
docs/man/man1/kubeadm-init-phase-certs-apiserver.1
@ -147,6 +154,7 @@ docs/man/man1/kubeadm-init-phase-certs-front-proxy-ca.1
docs/man/man1/kubeadm-init-phase-certs-front-proxy-client.1
docs/man/man1/kubeadm-init-phase-certs-sa.1
docs/man/man1/kubeadm-init-phase-certs.1
docs/man/man1/kubeadm-init-phase-control-plane-all.1
docs/man/man1/kubeadm-init-phase-control-plane-apiserver.1
docs/man/man1/kubeadm-init-phase-control-plane-controller-manager.1
docs/man/man1/kubeadm-init-phase-control-plane-scheduler.1
@ -154,6 +162,7 @@ docs/man/man1/kubeadm-init-phase-control-plane.1
docs/man/man1/kubeadm-init-phase-etcd-local.1
docs/man/man1/kubeadm-init-phase-etcd.1
docs/man/man1/kubeadm-init-phase-kubeconfig-admin.1
docs/man/man1/kubeadm-init-phase-kubeconfig-all.1
docs/man/man1/kubeadm-init-phase-kubeconfig-controller-manager.1
docs/man/man1/kubeadm-init-phase-kubeconfig-kubelet.1
docs/man/man1/kubeadm-init-phase-kubeconfig-scheduler.1
@ -161,6 +170,7 @@ docs/man/man1/kubeadm-init-phase-kubeconfig.1
docs/man/man1/kubeadm-init-phase-kubelet-start.1
docs/man/man1/kubeadm-init-phase-mark-control-plane.1
docs/man/man1/kubeadm-init-phase-preflight.1
docs/man/man1/kubeadm-init-phase-upload-config-all.1
docs/man/man1/kubeadm-init-phase-upload-config-kubeadm.1
docs/man/man1/kubeadm-init-phase-upload-config-kubelet.1
docs/man/man1/kubeadm-init-phase-upload-config.1

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.

View File

@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.