Merge pull request #73998 from yagonobre/fix-mixed-args

Allow the usage of --kubeconfig-dir and --config flags on kubeadm init
pull/564/head
Kubernetes Prow Robot 2019-02-13 09:45:28 -08:00 committed by GitHub
commit 2bfbbc3141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View File

@ -402,8 +402,8 @@ func ValidateMixedArguments(flag *pflag.FlagSet) error {
mixedInvalidFlags := []string{}
flag.Visit(func(f *pflag.Flag) {
if f.Name == "config" || f.Name == "ignore-preflight-errors" || strings.HasPrefix(f.Name, "skip-") || f.Name == "dry-run" || f.Name == "kubeconfig" || f.Name == "v" || f.Name == "rootfs" || f.Name == "print-join-command" || f.Name == "node-name" || f.Name == "cri-socket" {
// "--skip-*" flags or other whitelisted flags can be set with --config
if isAllowedFlag(f.Name) {
// "--skip-*" flags or other allowed flags can be set with --config
return
}
mixedInvalidFlags = append(mixedInvalidFlags, f.Name)
@ -415,6 +415,26 @@ func ValidateMixedArguments(flag *pflag.FlagSet) error {
return nil
}
func isAllowedFlag(flagName string) bool {
isAllowed := false
switch flagName {
case kubeadmcmdoptions.CfgPath,
kubeadmcmdoptions.IgnorePreflightErrors,
kubeadmcmdoptions.DryRun,
kubeadmcmdoptions.KubeconfigPath,
kubeadmcmdoptions.NodeName,
kubeadmcmdoptions.NodeCRISocket,
kubeadmcmdoptions.KubeconfigDir,
"print-join-command", "rootfs", "v":
isAllowed = true
default:
if strings.HasPrefix(flagName, "skip-") {
isAllowed = true
}
}
return isAllowed
}
// ValidateFeatureGates validates provided feature gates
func ValidateFeatureGates(featureGates map[string]bool, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

View File

@ -243,12 +243,12 @@ func AddInitOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipTokenPrint, d
ignorePreflightErrors, options.IgnorePreflightErrors, *ignorePreflightErrors,
"A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.",
)
// Note: All flags that are not bound to the cfg object should be whitelisted in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
// Note: All flags that are not bound to the cfg object should be allowed in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
flagSet.BoolVar(
skipTokenPrint, options.SkipTokenPrint, *skipTokenPrint,
"Skip printing of the default bootstrap token generated by 'kubeadm init'.",
)
// Note: All flags that are not bound to the cfg object should be whitelisted in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
// Note: All flags that are not bound to the cfg object should be allowed in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
flagSet.BoolVar(
dryRun, options.DryRun, *dryRun,
"Don't apply any changes; just output what would be done.",
@ -333,7 +333,7 @@ func newInitData(cmd *cobra.Command, args []string, options *initOptions, out io
// Checks if an external CA is provided by the user.
externalCA, _ := certsphase.UsingExternalCA(&cfg.ClusterConfiguration)
if externalCA {
kubeconfigDir := kubeadmconstants.KubernetesDir
kubeconfigDir := options.kubeconfigDir
if options.dryRun {
kubeconfigDir = dryRunDir
}