diff --git a/pkg/minikube/bootstrapper/bsutil/extraconfig.go b/pkg/minikube/bootstrapper/bsutil/extraconfig.go index 5033ad34b973..0f64b89f10db 100644 --- a/pkg/minikube/bootstrapper/bsutil/extraconfig.go +++ b/pkg/minikube/bootstrapper/bsutil/extraconfig.go @@ -49,6 +49,7 @@ var componentToKubeadmConfigKey = map[string]string{ Apiserver: "apiServer", ControllerManager: "controllerManager", Scheduler: "scheduler", + Etcd: "etcd", Kubeadm: "kubeadm", // The KubeProxy is handled in different config block Kubeproxy: "", @@ -183,20 +184,21 @@ func optionPairsForComponent(component string, version semver.Version, cp config // kubeadm extra args should not be included in the kubeadm config in the extra args section (instead, they must // be inserted explicitly in the appropriate places or supplied from the command line); here we remove all of the // kubeadm extra args from the slice +// etcd must also not be included in that section, as those extra args exist in the `etcd` section // createExtraComponentConfig generates a map of component to extra args for all of the components except kubeadm func createExtraComponentConfig(extraOptions config.ExtraOptionSlice, version semver.Version, componentFeatureArgs string, cp config.Node) ([]componentOptions, error) { extraArgsSlice, err := newComponentOptions(extraOptions, version, componentFeatureArgs, cp) if err != nil { return nil, err } - - for i, extraArgs := range extraArgsSlice { - if extraArgs.Component == Kubeadm { - extraArgsSlice = append(extraArgsSlice[:i], extraArgsSlice[i+1:]...) - break + validComponents := []componentOptions{} + for _, extraArgs := range extraArgsSlice { + if extraArgs.Component == Kubeadm || extraArgs.Component == Etcd { + continue } + validComponents = append(validComponents, extraArgs) } - return extraArgsSlice, nil + return validComponents, nil } // createKubeProxyOptions generates a map of extra config for kube-proxy diff --git a/pkg/minikube/bootstrapper/bsutil/ktmpl/v1beta2.go b/pkg/minikube/bootstrapper/bsutil/ktmpl/v1beta2.go index a4507c0654a9..b5dc4f7e2721 100644 --- a/pkg/minikube/bootstrapper/bsutil/ktmpl/v1beta2.go +++ b/pkg/minikube/bootstrapper/bsutil/ktmpl/v1beta2.go @@ -63,6 +63,12 @@ dns: etcd: local: dataDir: {{.EtcdDataDir}} +{{- if .EtcdExtraArgs}} + extraArgs: +{{- range $i, $val := printMapInOrder .EtcdExtraArgs ": " }} + {{$val}} +{{- end}} +{{- end}} controllerManager: extraArgs: "leader-elect": "false" diff --git a/pkg/minikube/bootstrapper/bsutil/kubeadm.go b/pkg/minikube/bootstrapper/bsutil/kubeadm.go index 155cd1d494ac..580983711a88 100644 --- a/pkg/minikube/bootstrapper/bsutil/kubeadm.go +++ b/pkg/minikube/bootstrapper/bsutil/kubeadm.go @@ -73,6 +73,7 @@ func GenerateKubeadmYAML(cc config.ClusterConfig, n config.Node, r cruntime.Mana APIServerPort int KubernetesVersion string EtcdDataDir string + EtcdExtraArgs map[string]string ClusterName string NodeName string DNSDomain string @@ -92,6 +93,7 @@ func GenerateKubeadmYAML(cc config.ClusterConfig, n config.Node, r cruntime.Mana APIServerPort: nodePort, KubernetesVersion: k8s.KubernetesVersion, EtcdDataDir: EtcdDataDir(), + EtcdExtraArgs: etcdExtraArgs(k8s.ExtraOptions), ClusterName: cc.Name, //kubeadm uses NodeName as the --hostname-override parameter, so this needs to be the name of the machine NodeName: KubeNodeName(cc, n), @@ -138,6 +140,7 @@ const ( Scheduler = "scheduler" ControllerManager = "controller-manager" Kubeproxy = "kube-proxy" + Etcd = "etcd" ) // InvokeKubeadm returns the invocation command for Kubeadm @@ -149,3 +152,14 @@ func InvokeKubeadm(version string) string { func EtcdDataDir() string { return path.Join(vmpath.GuestPersistentDir, "etcd") } + +func etcdExtraArgs(extraOpts config.ExtraOptionSlice) map[string]string { + args := map[string]string{} + for _, eo := range extraOpts { + if eo.Component != Etcd { + continue + } + args[eo.Key] = eo.Value + } + return args +} diff --git a/pkg/minikube/bootstrapper/bsutil/kubeadm_test.go b/pkg/minikube/bootstrapper/bsutil/kubeadm_test.go index ff61653a8323..6362b45132a2 100644 --- a/pkg/minikube/bootstrapper/bsutil/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/bsutil/kubeadm_test.go @@ -22,6 +22,7 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" "github.com/pmezard/go-difflib/difflib" "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/constants" @@ -240,9 +241,24 @@ func TestGenerateKubeadmYAML(t *testing.T) { t.Fatalf("diff error: %v", err) } if diff != "" { - t.Errorf("unexpected diff:\n%s\n===== [RAW OUTPUT] =====\n%s", diff, got) + t.Errorf("unexpected diff:\n%s\n", diff) } }) } } } + +func TestEtcdExtraArgs(t *testing.T) { + expected := map[string]string{ + "key": "value", + } + extraOpts := append(getExtraOpts(), config.ExtraOption{ + Component: Etcd, + Key: "key", + Value: "value", + }) + actual := etcdExtraArgs(extraOpts) + if diff := cmp.Diff(expected, actual); diff != "" { + t.Errorf("machines mismatch (-want +got):\n%s", diff) + } +}