Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing in extra args to etcd via command line #8551

Merged
merged 5 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pkg/minikube/bootstrapper/bsutil/extraconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/minikube/bootstrapper/bsutil/ktmpl/v1beta2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions pkg/minikube/bootstrapper/bsutil/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -138,6 +140,7 @@ const (
Scheduler = "scheduler"
ControllerManager = "controller-manager"
Kubeproxy = "kube-proxy"
Etcd = "etcd"
)

// InvokeKubeadm returns the invocation command for Kubeadm
Expand All @@ -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
}
18 changes: 17 additions & 1 deletion pkg/minikube/bootstrapper/bsutil/kubeadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}