Merge pull request #8551 from priyawadhwa/etcd-extra-args

Allow passing in extra args to etcd via command line
pull/8562/head
priyawadhwa 2020-06-25 09:37:41 -07:00 committed by GitHub
commit d368674457
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 7 deletions

View File

@ -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

View File

@ -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"

View File

@ -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
}

View File

@ -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)
}
}