Skip to content

Commit d368674

Browse files
author
priyawadhwa
authored
Merge pull request #8551 from priyawadhwa/etcd-extra-args
Allow passing in extra args to etcd via command line
2 parents abca4d0 + 1b0de27 commit d368674

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

pkg/minikube/bootstrapper/bsutil/extraconfig.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var componentToKubeadmConfigKey = map[string]string{
4949
Apiserver: "apiServer",
5050
ControllerManager: "controllerManager",
5151
Scheduler: "scheduler",
52+
Etcd: "etcd",
5253
Kubeadm: "kubeadm",
5354
// The KubeProxy is handled in different config block
5455
Kubeproxy: "",
@@ -183,20 +184,21 @@ func optionPairsForComponent(component string, version semver.Version, cp config
183184
// kubeadm extra args should not be included in the kubeadm config in the extra args section (instead, they must
184185
// be inserted explicitly in the appropriate places or supplied from the command line); here we remove all of the
185186
// kubeadm extra args from the slice
187+
// etcd must also not be included in that section, as those extra args exist in the `etcd` section
186188
// createExtraComponentConfig generates a map of component to extra args for all of the components except kubeadm
187189
func createExtraComponentConfig(extraOptions config.ExtraOptionSlice, version semver.Version, componentFeatureArgs string, cp config.Node) ([]componentOptions, error) {
188190
extraArgsSlice, err := newComponentOptions(extraOptions, version, componentFeatureArgs, cp)
189191
if err != nil {
190192
return nil, err
191193
}
192-
193-
for i, extraArgs := range extraArgsSlice {
194-
if extraArgs.Component == Kubeadm {
195-
extraArgsSlice = append(extraArgsSlice[:i], extraArgsSlice[i+1:]...)
196-
break
194+
validComponents := []componentOptions{}
195+
for _, extraArgs := range extraArgsSlice {
196+
if extraArgs.Component == Kubeadm || extraArgs.Component == Etcd {
197+
continue
197198
}
199+
validComponents = append(validComponents, extraArgs)
198200
}
199-
return extraArgsSlice, nil
201+
return validComponents, nil
200202
}
201203

202204
// createKubeProxyOptions generates a map of extra config for kube-proxy

pkg/minikube/bootstrapper/bsutil/ktmpl/v1beta2.go

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ dns:
6363
etcd:
6464
local:
6565
dataDir: {{.EtcdDataDir}}
66+
{{- if .EtcdExtraArgs}}
67+
extraArgs:
68+
{{- range $i, $val := printMapInOrder .EtcdExtraArgs ": " }}
69+
{{$val}}
70+
{{- end}}
71+
{{- end}}
6672
controllerManager:
6773
extraArgs:
6874
"leader-elect": "false"

pkg/minikube/bootstrapper/bsutil/kubeadm.go

+14
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func GenerateKubeadmYAML(cc config.ClusterConfig, n config.Node, r cruntime.Mana
7373
APIServerPort int
7474
KubernetesVersion string
7575
EtcdDataDir string
76+
EtcdExtraArgs map[string]string
7677
ClusterName string
7778
NodeName string
7879
DNSDomain string
@@ -92,6 +93,7 @@ func GenerateKubeadmYAML(cc config.ClusterConfig, n config.Node, r cruntime.Mana
9293
APIServerPort: nodePort,
9394
KubernetesVersion: k8s.KubernetesVersion,
9495
EtcdDataDir: EtcdDataDir(),
96+
EtcdExtraArgs: etcdExtraArgs(k8s.ExtraOptions),
9597
ClusterName: cc.Name,
9698
//kubeadm uses NodeName as the --hostname-override parameter, so this needs to be the name of the machine
9799
NodeName: KubeNodeName(cc, n),
@@ -138,6 +140,7 @@ const (
138140
Scheduler = "scheduler"
139141
ControllerManager = "controller-manager"
140142
Kubeproxy = "kube-proxy"
143+
Etcd = "etcd"
141144
)
142145

143146
// InvokeKubeadm returns the invocation command for Kubeadm
@@ -149,3 +152,14 @@ func InvokeKubeadm(version string) string {
149152
func EtcdDataDir() string {
150153
return path.Join(vmpath.GuestPersistentDir, "etcd")
151154
}
155+
156+
func etcdExtraArgs(extraOpts config.ExtraOptionSlice) map[string]string {
157+
args := map[string]string{}
158+
for _, eo := range extraOpts {
159+
if eo.Component != Etcd {
160+
continue
161+
}
162+
args[eo.Key] = eo.Value
163+
}
164+
return args
165+
}

pkg/minikube/bootstrapper/bsutil/kubeadm_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323
"testing"
2424

25+
"github.com/google/go-cmp/cmp"
2526
"github.com/pmezard/go-difflib/difflib"
2627
"k8s.io/minikube/pkg/minikube/config"
2728
"k8s.io/minikube/pkg/minikube/constants"
@@ -240,9 +241,24 @@ func TestGenerateKubeadmYAML(t *testing.T) {
240241
t.Fatalf("diff error: %v", err)
241242
}
242243
if diff != "" {
243-
t.Errorf("unexpected diff:\n%s\n===== [RAW OUTPUT] =====\n%s", diff, got)
244+
t.Errorf("unexpected diff:\n%s\n", diff)
244245
}
245246
})
246247
}
247248
}
248249
}
250+
251+
func TestEtcdExtraArgs(t *testing.T) {
252+
expected := map[string]string{
253+
"key": "value",
254+
}
255+
extraOpts := append(getExtraOpts(), config.ExtraOption{
256+
Component: Etcd,
257+
Key: "key",
258+
Value: "value",
259+
})
260+
actual := etcdExtraArgs(extraOpts)
261+
if diff := cmp.Diff(expected, actual); diff != "" {
262+
t.Errorf("machines mismatch (-want +got):\n%s", diff)
263+
}
264+
}

0 commit comments

Comments
 (0)