Skip to content

Commit

Permalink
Merge pull request #13128 from kubernetes/revert-13125-refactorExtraO…
Browse files Browse the repository at this point in the history
…ptions

Revert "Refactored to remove config.ExtraOptions"
  • Loading branch information
spowelljr authored Dec 8, 2021
2 parents ed380db + 9d16d24 commit 90300a4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 27 deletions.
11 changes: 4 additions & 7 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,7 @@ func validateFlags(cmd *cobra.Command, drvName string) {
}

// validate kubeadm extra args
extraOptions := getExtraOptions()
if invalidOpts := bsutil.FindInvalidExtraConfigFlags(extraOptions); len(invalidOpts) > 0 {
if invalidOpts := bsutil.FindInvalidExtraConfigFlags(config.ExtraOptions); len(invalidOpts) > 0 {
out.WarningT(
"These --extra-config parameters are invalid: {{.invalid_extra_opts}}",
out.V{"invalid_extra_opts": invalidOpts},
Expand All @@ -1213,7 +1212,7 @@ func validateFlags(cmd *cobra.Command, drvName string) {
}

// check that kubeadm extra args contain only allowed parameters
for param := range extraOptions.AsMap().Get(bsutil.Kubeadm) {
for param := range config.ExtraOptions.AsMap().Get(bsutil.Kubeadm) {
if !config.ContainsParam(bsutil.KubeadmExtraArgsAllowed[bsutil.KubeadmCmdParam], param) &&
!config.ContainsParam(bsutil.KubeadmExtraArgsAllowed[bsutil.KubeadmConfigParam], param) {
exit.Message(reason.Usage, "Sorry, the kubeadm.{{.parameter_name}} parameter is currently not supported by --extra-config", out.V{"parameter_name": param})
Expand Down Expand Up @@ -1473,19 +1472,17 @@ func autoSetDriverOptions(cmd *cobra.Command, drvName string) (err error) {
err = nil
hints := driver.FlagDefaults(drvName)
if len(hints.ExtraOptions) > 0 {
extraOptionVals := getExtraOptions()
for _, eo := range hints.ExtraOptions {
if extraOptionVals.Exists(eo) {
if config.ExtraOptions.Exists(eo) {
klog.Infof("skipping extra-config %q.", eo)
continue
}
klog.Infof("auto setting extra-config to %q.", eo)
err = extraOptionVals.Set(eo)
err = config.ExtraOptions.Set(eo)
if err != nil {
err = errors.Wrapf(err, "setting extra option %s", eo)
}
}
viper.Set(extraOptions, extraOptionVals)
}

if !cmd.Flags().Changed(cacheImages) {
Expand Down
22 changes: 4 additions & 18 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ const (
listenAddress = "listen-address"
extraDisks = "extra-disks"
certExpiration = "cert-expiration"
extraOptions = "extra-config"
)

var (
Expand Down Expand Up @@ -180,7 +179,7 @@ func initMinikubeFlags() {
func initKubernetesFlags() {
startCmd.Flags().String(kubernetesVersion, "", fmt.Sprintf("The Kubernetes version that the minikube VM will use (ex: v1.2.3, 'stable' for %s, 'latest' for %s). Defaults to 'stable'.", constants.DefaultKubernetesVersion, constants.NewestKubernetesVersion))
startCmd.Flags().String(startNamespace, "default", "The named space to activate after start")
startCmd.Flags().String(extraOptions, "",
startCmd.Flags().Var(&config.ExtraOptions, "extra-config",
`A set of key=value pairs that describe configuration that may be passed to different components.
The key should be '.' separated, and the first part before the dot is the component to apply the configuration to.
Valid components are: kubelet, kubeadm, apiserver, controller-manager, etcd, proxy, scheduler
Expand Down Expand Up @@ -403,19 +402,6 @@ func getCNIConfig(cmd *cobra.Command) string {
return chosenCNI
}

// getExtraOptions gets Kubernetes extra options from flags
func getExtraOptions() config.ExtraOptionSlice {
extraOptionVals := config.ExtraOptionSlice{}
val := viper.GetString(extraOptions)
if val == "" {
return extraOptionVals
}
if err := extraOptionVals.Set(val); err != nil {
klog.Errorf("Invalid %s flag provided, flag will be ignored: %v", extraOptions, err)
}
return extraOptionVals
}

// generateNewConfigFromFlags generate a config.ClusterConfig based on flags
func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) config.ClusterConfig {
var cc config.ClusterConfig
Expand Down Expand Up @@ -494,7 +480,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName s
NetworkPlugin: chosenNetworkPlugin,
ServiceCIDR: viper.GetString(serviceCIDR),
ImageRepository: getRepository(cmd, k8sVersion),
ExtraOptions: getExtraOptions(),
ExtraOptions: config.ExtraOptions,
ShouldLoadCachedImages: viper.GetBool(cacheImages),
CNI: getCNIConfig(cmd),
NodePort: viper.GetInt(apiServerPort),
Expand Down Expand Up @@ -694,8 +680,8 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
cc.KubernetesConfig.KubernetesVersion = getKubernetesVersion(existing)
}

if cmd.Flags().Changed(extraOptions) {
cc.KubernetesConfig.ExtraOptions = getExtraOptions()
if cmd.Flags().Changed("extra-config") {
cc.KubernetesConfig.ExtraOptions = config.ExtraOptions
}

if cmd.Flags().Changed(cniFlag) || cmd.Flags().Changed(enableDefaultCNI) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var (
DockerEnv []string
// DockerOpt contains the option parameters
DockerOpt []string
// ExtraOptions contains extra options (if any)
ExtraOptions ExtraOptionSlice
)

// ErrNotExist is the error returned when a config does not exist
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func setupKubeAdm(mAPI libmachine.API, cfg config.ClusterConfig, n config.Node,
if err != nil {
exit.Error(reason.InternalBootstrapper, "Failed to get bootstrapper", err)
}
for _, eo := range cfg.KubernetesConfig.ExtraOptions {
for _, eo := range config.ExtraOptions {
out.Infof("{{.extra_option_component_name}}.{{.key}}={{.value}}", out.V{"extra_option_component_name": eo.Component, "key": eo.Key, "value": eo.Value})
}
// Loads cached images, generates config files, download binaries
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/commands/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ minikube start [flags]
--dry-run dry-run mode. Validates configuration, but does not mutate system state
--embed-certs if true, will embed the certs in kubeconfig.
--enable-default-cni DEPRECATED: Replaced by --cni=bridge
--extra-config string A set of key=value pairs that describe configuration that may be passed to different components.
--extra-config ExtraOption A set of key=value pairs that describe configuration that may be passed to different components.
The key should be '.' separated, and the first part before the dot is the component to apply the configuration to.
Valid components are: kubelet, kubeadm, apiserver, controller-manager, etcd, proxy, scheduler
Valid kubeadm parameters: ignore-preflight-errors, dry-run, kubeconfig, kubeconfig-dir, node-name, cri-socket, experimental-upload-certs, certificate-key, rootfs, skip-phases, pod-network-cidr
Expand Down

0 comments on commit 90300a4

Please sign in to comment.