Merge pull request #70388 from neolit123/phase-etcd

kubeadm: graduate etcd phase
This commit is contained in:
k8s-ci-robot 2018-11-01 13:44:16 -07:00 committed by GitHub
commit 78b43cc631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 58 additions and 168 deletions

View File

@ -53,7 +53,6 @@ func newCmdPhase(out io.Writer) *cobra.Command {
cmd.AddCommand(phases.NewCmdAddon()) cmd.AddCommand(phases.NewCmdAddon())
cmd.AddCommand(phases.NewCmdBootstrapToken()) cmd.AddCommand(phases.NewCmdBootstrapToken())
cmd.AddCommand(phases.NewCmdEtcd())
cmd.AddCommand(phases.NewCmdMarkMaster()) cmd.AddCommand(phases.NewCmdMarkMaster())
cmd.AddCommand(phases.NewCmdSelfhosting()) cmd.AddCommand(phases.NewCmdSelfhosting())
cmd.AddCommand(phases.NewCmdUploadConfig()) cmd.AddCommand(phases.NewCmdUploadConfig())

View File

@ -48,7 +48,6 @@ import (
clusterinfophase "k8s.io/kubernetes/cmd/kubeadm/app/phases/bootstraptoken/clusterinfo" clusterinfophase "k8s.io/kubernetes/cmd/kubeadm/app/phases/bootstraptoken/clusterinfo"
nodebootstraptokenphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/bootstraptoken/node" nodebootstraptokenphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/bootstraptoken/node"
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs" certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
etcdphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/etcd"
kubeletphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet" kubeletphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet"
markmasterphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/markmaster" markmasterphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/markmaster"
patchnodephase "k8s.io/kubernetes/cmd/kubeadm/app/phases/patchnode" patchnodephase "k8s.io/kubernetes/cmd/kubeadm/app/phases/patchnode"
@ -168,6 +167,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
initRunner.AppendPhase(phases.NewCertsPhase()) initRunner.AppendPhase(phases.NewCertsPhase())
initRunner.AppendPhase(phases.NewKubeConfigPhase()) initRunner.AppendPhase(phases.NewKubeConfigPhase())
initRunner.AppendPhase(phases.NewControlPlanePhase()) initRunner.AppendPhase(phases.NewControlPlanePhase())
initRunner.AppendPhase(phases.NewEtcdPhase())
// TODO: add other phases to the runner. // TODO: add other phases to the runner.
// sets the data builder function, that will be used by the runner // sets the data builder function, that will be used by the runner
@ -434,14 +434,6 @@ func runInit(i *initData, out io.Writer) error {
adminKubeConfigPath := filepath.Join(kubeConfigDir, kubeadmconstants.AdminKubeConfigFileName) adminKubeConfigPath := filepath.Join(kubeConfigDir, kubeadmconstants.AdminKubeConfigFileName)
// Add etcd static pod spec only if external etcd is not configured
if i.cfg.Etcd.External == nil {
glog.V(1).Infof("[init] no external etcd found. Creating manifest for local etcd static pod")
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(manifestDir, i.cfg); err != nil {
return errors.Wrap(err, "error creating local etcd static pod manifest file")
}
}
// If we're dry-running, print the generated manifests // If we're dry-running, print the generated manifests
if err := printFilesIfDryRunning(i.dryRun, manifestDir); err != nil { if err := printFilesIfDryRunning(i.dryRun, manifestDir); err != nil {
return errors.Wrap(err, "error printing files on dryrun") return errors.Wrap(err, "error printing files on dryrun")

View File

@ -65,13 +65,11 @@ go_test(
name = "go_default_test", name = "go_default_test",
srcs = [ srcs = [
"addons_test.go", "addons_test.go",
"etcd_test.go",
"util_test.go", "util_test.go",
], ],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//cmd/kubeadm/app/apis/kubeadm/v1beta1:go_default_library", "//cmd/kubeadm/app/apis/kubeadm/v1beta1:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//cmd/kubeadm/test/cmd:go_default_library", "//cmd/kubeadm/test/cmd:go_default_library",
"//pkg/version:go_default_library", "//pkg/version:go_default_library",
], ],

View File

@ -19,84 +19,71 @@ package phases
import ( import (
"fmt" "fmt"
"github.com/spf13/cobra" "github.com/golang/glog"
"github.com/pkg/errors"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme" "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
kubeadmapiv1beta1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
etcdphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/etcd" etcdphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/etcd"
"k8s.io/kubernetes/pkg/util/normalizer" "k8s.io/kubernetes/pkg/util/normalizer"
) )
var ( var (
etcdLocalLongDesc = fmt.Sprintf(normalizer.LongDesc(`
Generates the static Pod manifest file for a local, single-node etcd instance and saves it to %s file.
`+cmdutil.AlphaDisclaimer), kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.Etcd, kubeadmconstants.GetStaticPodDirectory()))
etcdLocalExample = normalizer.Examples(` etcdLocalExample = normalizer.Examples(`
# Generates the static Pod manifest file for etcd, functionally # Generates the static Pod manifest file for etcd, functionally
# equivalent to what generated by kubeadm init. # equivalent to what is generated by kubeadm init.
kubeadm alpha phase etcd local kubeadm init phase etcd local
# Generates the static Pod manifest file for etcd. # Generates the static Pod manifest file for etcd using options
kubeadm alpha phase etcd local --config masterconfiguration.yaml # read from a configuration file.
kubeadm init phase etcd local --config config.yaml
`) `)
) )
// NewCmdEtcd returns main command for Etcd phase type etcdData interface {
func NewCmdEtcd() *cobra.Command { Cfg() *kubeadmapi.InitConfiguration
cmd := &cobra.Command{ ManifestDir() string
Use: "etcd",
Short: "Generates static Pod manifest file for etcd.",
Long: cmdutil.MacroCommandLongDescription,
}
manifestPath := kubeadmconstants.GetStaticPodDirectory()
cmd.AddCommand(getEtcdSubCommands(manifestPath, "")...)
return cmd
} }
// getEtcdSubCommands returns sub commands for etcd phase // NewEtcdPhase creates a kubeadm workflow phase that implements handling of etcd.
func getEtcdSubCommands(outDir, defaultKubernetesVersion string) []*cobra.Command { func NewEtcdPhase() workflow.Phase {
phase := workflow.Phase{
cfg := &kubeadmapiv1beta1.InitConfiguration{} Name: "etcd",
Short: "Generates static Pod manifest file for local etcd.",
// Default values for the cobra help text Example: etcdLocalExample,
kubeadmscheme.Scheme.Default(cfg) Phases: []workflow.Phase{
newEtcdLocalSubPhase(),
var cfgPath string },
var subCmds []*cobra.Command }
return phase
properties := struct { }
use string
short string func newEtcdLocalSubPhase() workflow.Phase {
long string phase := workflow.Phase{
examples string Name: "local",
cmdFunc func(outDir string, cfg *kubeadmapi.InitConfiguration) error Short: "Generates the static Pod manifest file for a local, single-node local etcd instance.",
}{ Example: etcdLocalExample,
use: "local", Run: runEtcdPhaseLocal(),
short: "Generates the static Pod manifest file for a local, single-node etcd instance", }
long: etcdLocalLongDesc, return phase
examples: etcdLocalExample, }
cmdFunc: etcdphase.CreateLocalEtcdStaticPodManifestFile,
func runEtcdPhaseLocal() func(c workflow.RunData) error {
return func(c workflow.RunData) error {
data, ok := c.(etcdData)
if !ok {
return errors.New("etcd phase invoked with an invalid data struct")
}
cfg := data.Cfg()
// Add etcd static pod spec only if external etcd is not configured
if cfg.Etcd.External == nil {
fmt.Printf("[etcd] Creating static Pod manifest for local etcd in %q\n", data.ManifestDir())
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(data.ManifestDir(), cfg); err != nil {
return errors.Wrap(err, "error creating local etcd static pod manifest file")
}
} else {
glog.V(1).Infof("[etcd] External etcd mode. Skipping the creation of a manifest for local etcd")
}
return nil
} }
// Creates the UX Command
cmd := &cobra.Command{
Use: properties.use,
Short: properties.short,
Long: properties.long,
Example: properties.examples,
Run: runCmdPhase(properties.cmdFunc, &outDir, &cfgPath, cfg, defaultKubernetesVersion),
}
// Add flags to the command
cmd.Flags().StringVar(&cfg.CertificatesDir, "cert-dir", cfg.CertificatesDir, `The path where certificates are stored`)
cmd.Flags().StringVar(&cfgPath, "config", cfgPath, "Path to kubeadm config file. WARNING: Usage of a configuration file is experimental")
subCmds = append(subCmds, cmd)
return subCmds
} }

View File

@ -1,85 +0,0 @@
/*
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"
"os"
"testing"
testutil "k8s.io/kubernetes/cmd/kubeadm/test"
cmdtestutil "k8s.io/kubernetes/cmd/kubeadm/test/cmd"
)
const phaseTestK8sVersion = "v1.11.0"
func TestEtcdSubCommandsHasFlags(t *testing.T) {
subCmds := getEtcdSubCommands("", phaseTestK8sVersion)
commonFlags := []string{
"cert-dir",
"config",
}
var tests = []struct {
command string
additionalFlags []string
}{
{
command: "local",
},
}
for _, test := range tests {
expectedFlags := append(commonFlags, test.additionalFlags...)
cmdtestutil.AssertSubCommandHasFlags(t, subCmds, test.command, expectedFlags...)
}
}
func TestEtcdCreateFilesWithFlags(t *testing.T) {
var tests = []struct {
command string
additionalFlags []string
expectedFiles []string
}{
{
command: "local",
expectedFiles: []string{"etcd.yaml"},
additionalFlags: []string{},
},
}
for _, test := range tests {
// Create temp folder for the test case
tmpdir := testutil.SetupTempDir(t)
defer os.RemoveAll(tmpdir)
// Get subcommands working in the temporary directory
subCmds := getEtcdSubCommands(tmpdir, phaseTestK8sVersion)
// Execute the subcommand
certDirFlag := fmt.Sprintf("--cert-dir=%s", tmpdir)
allFlags := append(test.additionalFlags, certDirFlag)
cmdtestutil.RunSubCommand(t, subCmds, test.command, allFlags...)
// Checks that requested files are there
testutil.AssertFileExists(t, tmpdir, test.expectedFiles...)
}
}

View File

@ -46,7 +46,6 @@ func CreateLocalEtcdStaticPodManifestFile(manifestDir string, cfg *kubeadmapi.In
if cfg.ClusterConfiguration.Etcd.External != nil { if cfg.ClusterConfiguration.Etcd.External != nil {
return errors.New("etcd static pod manifest cannot be generated for cluster using external etcd") return errors.New("etcd static pod manifest cannot be generated for cluster using external etcd")
} }
glog.V(1).Infoln("creating local etcd static pod manifest file")
// gets etcd StaticPodSpec // gets etcd StaticPodSpec
emptyInitialCluster := []etcdutil.Member{} emptyInitialCluster := []etcdutil.Member{}
spec := GetEtcdPodSpec(cfg, emptyInitialCluster) spec := GetEtcdPodSpec(cfg, emptyInitialCluster)
@ -55,7 +54,7 @@ func CreateLocalEtcdStaticPodManifestFile(manifestDir string, cfg *kubeadmapi.In
return err return err
} }
fmt.Printf("[etcd] Wrote Static Pod manifest for a local etcd instance to %q\n", kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.Etcd, manifestDir)) glog.V(1).Infof("[etcd] wrote Static Pod manifest for a local etcd instance to %q\n", kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.Etcd, manifestDir))
return nil return nil
} }

View File

@ -34,8 +34,6 @@ docs/admin/kubeadm_alpha_phase_bootstrap-token_create.md
docs/admin/kubeadm_alpha_phase_bootstrap-token_node.md docs/admin/kubeadm_alpha_phase_bootstrap-token_node.md
docs/admin/kubeadm_alpha_phase_bootstrap-token_node_allow-auto-approve.md docs/admin/kubeadm_alpha_phase_bootstrap-token_node_allow-auto-approve.md
docs/admin/kubeadm_alpha_phase_bootstrap-token_node_allow-post-csrs.md docs/admin/kubeadm_alpha_phase_bootstrap-token_node_allow-post-csrs.md
docs/admin/kubeadm_alpha_phase_etcd.md
docs/admin/kubeadm_alpha_phase_etcd_local.md
docs/admin/kubeadm_alpha_phase_mark-master.md docs/admin/kubeadm_alpha_phase_mark-master.md
docs/admin/kubeadm_alpha_phase_selfhosting.md docs/admin/kubeadm_alpha_phase_selfhosting.md
docs/admin/kubeadm_alpha_phase_selfhosting_convert-from-staticpods.md docs/admin/kubeadm_alpha_phase_selfhosting_convert-from-staticpods.md
@ -73,6 +71,8 @@ docs/admin/kubeadm_init_phase_control-plane.md
docs/admin/kubeadm_init_phase_control-plane_apiserver.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_controller-manager.md
docs/admin/kubeadm_init_phase_control-plane_scheduler.md docs/admin/kubeadm_init_phase_control-plane_scheduler.md
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.md
docs/admin/kubeadm_init_phase_kubeconfig_admin.md docs/admin/kubeadm_init_phase_kubeconfig_admin.md
docs/admin/kubeadm_init_phase_kubeconfig_controller-manager.md docs/admin/kubeadm_init_phase_kubeconfig_controller-manager.md
@ -128,8 +128,6 @@ docs/man/man1/kubeadm-alpha-phase-bootstrap-token-node-allow-auto-approve.1
docs/man/man1/kubeadm-alpha-phase-bootstrap-token-node-allow-post-csrs.1 docs/man/man1/kubeadm-alpha-phase-bootstrap-token-node-allow-post-csrs.1
docs/man/man1/kubeadm-alpha-phase-bootstrap-token-node.1 docs/man/man1/kubeadm-alpha-phase-bootstrap-token-node.1
docs/man/man1/kubeadm-alpha-phase-bootstrap-token.1 docs/man/man1/kubeadm-alpha-phase-bootstrap-token.1
docs/man/man1/kubeadm-alpha-phase-etcd-local.1
docs/man/man1/kubeadm-alpha-phase-etcd.1
docs/man/man1/kubeadm-alpha-phase-mark-master.1 docs/man/man1/kubeadm-alpha-phase-mark-master.1
docs/man/man1/kubeadm-alpha-phase-selfhosting-convert-from-staticpods.1 docs/man/man1/kubeadm-alpha-phase-selfhosting-convert-from-staticpods.1
docs/man/man1/kubeadm-alpha-phase-selfhosting.1 docs/man/man1/kubeadm-alpha-phase-selfhosting.1
@ -168,6 +166,8 @@ 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-controller-manager.1
docs/man/man1/kubeadm-init-phase-control-plane-scheduler.1 docs/man/man1/kubeadm-init-phase-control-plane-scheduler.1
docs/man/man1/kubeadm-init-phase-control-plane.1 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-admin.1
docs/man/man1/kubeadm-init-phase-kubeconfig-controller-manager.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-kubelet.1