Merge pull request #55903 from fabriziopandini/kubeadm-markmaster

Automatic merge from submit-queue (batch tested with PRs 55233, 55927, 55903, 54867, 55940). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Enhance kubeadm markmaster

**What this PR does / why we need it**:
This PR is part of the effort for improving kubeadm phases, and more specifically improves `mark-master` phase by implementing a behaviour similar to `kubeadm init`, that is:
- dynamically initialise node name if not provided 
- allow to override with `--node-name` flag or with `--config` 

Also reference doc for `mark-master` was improved.

**Which issue(s) this PR fixes** 
part of the effort for [#454](https://github.com/kubernetes/kubeadm/issues/454)
part of the effort for [#265](https://github.com/kubernetes/kubeadm/issues/265)

**Special notes for your reviewer**:
Alpha disclaimer aligned to change requested on the website.

**Release note**:
```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-11-18 12:26:12 -08:00 committed by GitHub
commit f48b00b0d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 8 deletions

View File

@ -19,31 +19,70 @@ package phases
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
kubeadmapiext "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha1"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util" cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
markmasterphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/markmaster" markmasterphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/markmaster"
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig" kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/util/normalizer"
)
var (
markMasterLongDesc = normalizer.LongDesc(`
Applies a label that specifies that a node is a master and a taint that forces workloads to be deployed accordingly.
` + cmdutil.AlphaDisclaimer)
markMasterExample = normalizer.Examples(`
# Applies master label and taint to the current node, functionally equivalent to what executed by kubeadm init.
kubeadm alpha phase mark-master
# Applies master label and taint to a specific node
kubeadm alpha phase mark-master --node-name myNode
`)
) )
// NewCmdMarkMaster returns the Cobra command for running the mark-master phase // NewCmdMarkMaster returns the Cobra command for running the mark-master phase
func NewCmdMarkMaster() *cobra.Command { func NewCmdMarkMaster() *cobra.Command {
var kubeConfigFile string
cfg := &kubeadmapiext.MasterConfiguration{
// KubernetesVersion is not used by mark master, but we set this explicitly to avoid
// the lookup of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig
KubernetesVersion: "v1.9.0",
}
// Default values for the cobra help text
legacyscheme.Scheme.Default(cfg)
var cfgPath, kubeConfigFile string
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "mark-master <node-name>", Use: "mark-master",
Short: "Mark a node as master.", Short: "Mark a node as master",
Long: markMasterLongDesc,
Example: markMasterExample,
Aliases: []string{"markmaster"}, Aliases: []string{"markmaster"},
RunE: func(_ *cobra.Command, args []string) error { Run: func(cmd *cobra.Command, args []string) {
err := cmdutil.ValidateExactArgNumber(args, []string{"node-name"}) if err := validation.ValidateMixedArguments(cmd.Flags()); err != nil {
kubeadmutil.CheckErr(err)
}
// This call returns the ready-to-use configuration based on the configuration file that might or might not exist and the default cfg populated by flags
internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg)
kubeadmutil.CheckErr(err) kubeadmutil.CheckErr(err)
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
kubeadmutil.CheckErr(err) kubeadmutil.CheckErr(err)
nodeName := args[0] err = markmasterphase.MarkMaster(client, internalcfg.NodeName)
return markmasterphase.MarkMaster(client, nodeName) kubeadmutil.CheckErr(err)
}, },
} }
cmd.Flags().StringVar(&kubeConfigFile, "kubeconfig", "/etc/kubernetes/admin.conf", "The KubeConfig file to use when talking to the cluster") cmd.Flags().StringVar(&kubeConfigFile, "kubeconfig", "/etc/kubernetes/admin.conf", "The KubeConfig file to use when talking to the cluster")
cmd.Flags().StringVar(&cfgPath, "config", cfgPath, "Path to kubeadm config file (WARNING: Usage of a configuration file is experimental)")
cmd.Flags().StringVar(&cfg.NodeName, "node-name", cfg.NodeName, `The node name to which label and taints should apply`)
return cmd return cmd
} }

View File

@ -23,7 +23,7 @@ import (
var ( var (
// AlphaDisclaimer to be places at the end of description of commands in alpha release // AlphaDisclaimer to be places at the end of description of commands in alpha release
AlphaDisclaimer = ` AlphaDisclaimer = `
Alpha Disclaimer: this command is currently alpha but, please try it out and give us feedback! Alpha Disclaimer: this command is currently alpha.
` `
// MacroCommandLongDescription provide a standard description for "macro" commands // MacroCommandLongDescription provide a standard description for "macro" commands