mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 02:34:03 +00:00
Allow configurable etcd options
This commit is contained in:
parent
5b4a814db2
commit
7e82985f6d
@ -31,7 +31,6 @@ func SetEnvParams() *EnvParams {
|
|||||||
|
|
||||||
envParams := map[string]string{
|
envParams := map[string]string{
|
||||||
"kubernetes_dir": "/etc/kubernetes",
|
"kubernetes_dir": "/etc/kubernetes",
|
||||||
"host_etcd_path": "/var/lib/etcd",
|
|
||||||
"hyperkube_image": "",
|
"hyperkube_image": "",
|
||||||
"repo_prefix": "gcr.io/google_containers",
|
"repo_prefix": "gcr.io/google_containers",
|
||||||
"etcd_image": "",
|
"etcd_image": "",
|
||||||
@ -45,7 +44,6 @@ func SetEnvParams() *EnvParams {
|
|||||||
|
|
||||||
return &EnvParams{
|
return &EnvParams{
|
||||||
KubernetesDir: path.Clean(envParams["kubernetes_dir"]),
|
KubernetesDir: path.Clean(envParams["kubernetes_dir"]),
|
||||||
HostEtcdPath: path.Clean(envParams["host_etcd_path"]),
|
|
||||||
HyperkubeImage: envParams["hyperkube_image"],
|
HyperkubeImage: envParams["hyperkube_image"],
|
||||||
RepositoryPrefix: envParams["repo_prefix"],
|
RepositoryPrefix: envParams["repo_prefix"],
|
||||||
EtcdImage: envParams["etcd_image"],
|
EtcdImage: envParams["etcd_image"],
|
||||||
|
@ -36,6 +36,7 @@ func KubeadmFuzzerFuncs(t apitesting.TestingCommon) []interface{} {
|
|||||||
obj.CertificatesDir = "foo"
|
obj.CertificatesDir = "foo"
|
||||||
obj.APIServerCertSANs = []string{}
|
obj.APIServerCertSANs = []string{}
|
||||||
obj.Token = "foo"
|
obj.Token = "foo"
|
||||||
|
obj.Etcd.DataDir = "foo"
|
||||||
},
|
},
|
||||||
func(obj *kubeadm.NodeConfiguration, c fuzz.Continue) {
|
func(obj *kubeadm.NodeConfiguration, c fuzz.Continue) {
|
||||||
c.FuzzNoCustom(obj)
|
c.FuzzNoCustom(obj)
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
|
|
||||||
type EnvParams struct {
|
type EnvParams struct {
|
||||||
KubernetesDir string
|
KubernetesDir string
|
||||||
HostEtcdPath string
|
|
||||||
HyperkubeImage string
|
HyperkubeImage string
|
||||||
RepositoryPrefix string
|
RepositoryPrefix string
|
||||||
EtcdImage string
|
EtcdImage string
|
||||||
@ -82,6 +81,8 @@ type Etcd struct {
|
|||||||
CAFile string
|
CAFile string
|
||||||
CertFile string
|
CertFile string
|
||||||
KeyFile string
|
KeyFile string
|
||||||
|
DataDir string
|
||||||
|
ExtraArgs map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeConfiguration struct {
|
type NodeConfiguration struct {
|
||||||
|
@ -32,6 +32,7 @@ const (
|
|||||||
DefaultAuthorizationMode = "RBAC"
|
DefaultAuthorizationMode = "RBAC"
|
||||||
DefaultCACertPath = "/etc/kubernetes/pki/ca.crt"
|
DefaultCACertPath = "/etc/kubernetes/pki/ca.crt"
|
||||||
DefaultCertificatesDir = "/etc/kubernetes/pki"
|
DefaultCertificatesDir = "/etc/kubernetes/pki"
|
||||||
|
DefaultEtcdDataDir = "/var/lib/etcd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func addDefaultingFuncs(scheme *runtime.Scheme) error {
|
func addDefaultingFuncs(scheme *runtime.Scheme) error {
|
||||||
@ -70,6 +71,10 @@ func SetDefaults_MasterConfiguration(obj *MasterConfiguration) {
|
|||||||
if obj.TokenTTL == 0 {
|
if obj.TokenTTL == 0 {
|
||||||
obj.TokenTTL = constants.DefaultTokenDuration
|
obj.TokenTTL = constants.DefaultTokenDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if obj.Etcd.DataDir == "" {
|
||||||
|
obj.Etcd.DataDir = DefaultEtcdDataDir
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetDefaults_NodeConfiguration(obj *NodeConfiguration) {
|
func SetDefaults_NodeConfiguration(obj *NodeConfiguration) {
|
||||||
|
@ -74,6 +74,8 @@ type Etcd struct {
|
|||||||
CAFile string `json:"caFile"`
|
CAFile string `json:"caFile"`
|
||||||
CertFile string `json:"certFile"`
|
CertFile string `json:"certFile"`
|
||||||
KeyFile string `json:"keyFile"`
|
KeyFile string `json:"keyFile"`
|
||||||
|
DataDir string `json:"dataDir"`
|
||||||
|
ExtraArgs map[string]string `json:"extraArgs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeConfiguration struct {
|
type NodeConfiguration struct {
|
||||||
|
@ -103,20 +103,15 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
|
|||||||
if len(cfg.Etcd.Endpoints) == 0 {
|
if len(cfg.Etcd.Endpoints) == 0 {
|
||||||
etcdPod := componentPod(api.Container{
|
etcdPod := componentPod(api.Container{
|
||||||
Name: etcd,
|
Name: etcd,
|
||||||
Command: []string{
|
Command: getEtcdCommand(cfg),
|
||||||
"etcd",
|
VolumeMounts: []api.VolumeMount{certsVolumeMount(), etcdVolumeMount(cfg.Etcd.DataDir), k8sVolumeMount()},
|
||||||
"--listen-client-urls=http://127.0.0.1:2379",
|
|
||||||
"--advertise-client-urls=http://127.0.0.1:2379",
|
|
||||||
"--data-dir=/var/lib/etcd",
|
|
||||||
},
|
|
||||||
VolumeMounts: []api.VolumeMount{certsVolumeMount(), etcdVolumeMount(), k8sVolumeMount()},
|
|
||||||
Image: images.GetCoreImage(images.KubeEtcdImage, cfg, kubeadmapi.GlobalEnvParams.EtcdImage),
|
Image: images.GetCoreImage(images.KubeEtcdImage, cfg, kubeadmapi.GlobalEnvParams.EtcdImage),
|
||||||
LivenessProbe: componentProbe(2379, "/health", api.URISchemeHTTP),
|
LivenessProbe: componentProbe(2379, "/health", api.URISchemeHTTP),
|
||||||
}, certsVolume(cfg), etcdVolume(cfg), k8sVolume(cfg))
|
}, certsVolume(cfg), etcdVolume(cfg), k8sVolume(cfg))
|
||||||
|
|
||||||
etcdPod.Spec.SecurityContext = &api.PodSecurityContext{
|
etcdPod.Spec.SecurityContext = &api.PodSecurityContext{
|
||||||
SELinuxOptions: &api.SELinuxOptions{
|
SELinuxOptions: &api.SELinuxOptions{
|
||||||
// Unconfine the etcd container so it can write to /var/lib/etcd with SELinux enforcing:
|
// Unconfine the etcd container so it can write to the data dir with SELinux enforcing:
|
||||||
Type: "spc_t",
|
Type: "spc_t",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -146,15 +141,15 @@ func etcdVolume(cfg *kubeadmapi.MasterConfiguration) api.Volume {
|
|||||||
return api.Volume{
|
return api.Volume{
|
||||||
Name: "etcd",
|
Name: "etcd",
|
||||||
VolumeSource: api.VolumeSource{
|
VolumeSource: api.VolumeSource{
|
||||||
HostPath: &api.HostPathVolumeSource{Path: kubeadmapi.GlobalEnvParams.HostEtcdPath},
|
HostPath: &api.HostPathVolumeSource{Path: cfg.Etcd.DataDir},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func etcdVolumeMount() api.VolumeMount {
|
func etcdVolumeMount(dataDir string) api.VolumeMount {
|
||||||
return api.VolumeMount{
|
return api.VolumeMount{
|
||||||
Name: "etcd",
|
Name: "etcd",
|
||||||
MountPath: "/var/lib/etcd",
|
MountPath: dataDir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,6 +362,21 @@ func getAPIServerCommand(cfg *kubeadmapi.MasterConfiguration, selfHosted bool) [
|
|||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEtcdCommand(cfg *kubeadmapi.MasterConfiguration) []string {
|
||||||
|
var command []string
|
||||||
|
|
||||||
|
defaultArguments := map[string]string{
|
||||||
|
"listen-client-urls": "http://127.0.0.1:2379",
|
||||||
|
"advertise-client-urls": "http://127.0.0.1:2379",
|
||||||
|
"data-dir": cfg.Etcd.DataDir,
|
||||||
|
}
|
||||||
|
|
||||||
|
command = append(command, "etcd")
|
||||||
|
command = append(command, getExtraParameters(cfg.Etcd.ExtraArgs, defaultArguments)...)
|
||||||
|
|
||||||
|
return command
|
||||||
|
}
|
||||||
|
|
||||||
func getControllerManagerCommand(cfg *kubeadmapi.MasterConfiguration, selfHosted bool) []string {
|
func getControllerManagerCommand(cfg *kubeadmapi.MasterConfiguration, selfHosted bool) []string {
|
||||||
var command []string
|
var command []string
|
||||||
|
|
||||||
|
@ -31,7 +31,10 @@ import (
|
|||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testCertsDir = "/var/lib/certs"
|
const (
|
||||||
|
testCertsDir = "/var/lib/certs"
|
||||||
|
etcdDataDir = "/var/lib/etcd"
|
||||||
|
)
|
||||||
|
|
||||||
func TestWriteStaticPodManifests(t *testing.T) {
|
func TestWriteStaticPodManifests(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
@ -122,12 +125,13 @@ func TestEtcdVolume(t *testing.T) {
|
|||||||
expected api.Volume
|
expected api.Volume
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
cfg: &kubeadmapi.MasterConfiguration{},
|
cfg: &kubeadmapi.MasterConfiguration{
|
||||||
|
Etcd: kubeadmapi.Etcd{DataDir: etcdDataDir},
|
||||||
|
},
|
||||||
expected: api.Volume{
|
expected: api.Volume{
|
||||||
Name: "etcd",
|
Name: "etcd",
|
||||||
VolumeSource: api.VolumeSource{
|
VolumeSource: api.VolumeSource{
|
||||||
HostPath: &api.HostPathVolumeSource{
|
HostPath: &api.HostPathVolumeSource{Path: etcdDataDir},
|
||||||
Path: kubeadmapi.GlobalEnvParams.HostEtcdPath},
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -158,13 +162,13 @@ func TestEtcdVolumeMount(t *testing.T) {
|
|||||||
{
|
{
|
||||||
expected: api.VolumeMount{
|
expected: api.VolumeMount{
|
||||||
Name: "etcd",
|
Name: "etcd",
|
||||||
MountPath: "/var/lib/etcd",
|
MountPath: etcdDataDir,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
actual := etcdVolumeMount()
|
actual := etcdVolumeMount(etcdDataDir)
|
||||||
if actual.Name != rt.expected.Name {
|
if actual.Name != rt.expected.Name {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"failed etcdVolumeMount:\n\texpected: %s\n\t actual: %s",
|
"failed etcdVolumeMount:\n\texpected: %s\n\t actual: %s",
|
||||||
@ -624,6 +628,62 @@ func TestGetControllerManagerCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetEtcdCommand(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
cfg *kubeadmapi.MasterConfiguration
|
||||||
|
expected []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
cfg: &kubeadmapi.MasterConfiguration{
|
||||||
|
Etcd: kubeadmapi.Etcd{DataDir: "/var/lib/etcd"},
|
||||||
|
},
|
||||||
|
expected: []string{
|
||||||
|
"etcd",
|
||||||
|
"--listen-client-urls=http://127.0.0.1:2379",
|
||||||
|
"--advertise-client-urls=http://127.0.0.1:2379",
|
||||||
|
"--data-dir=/var/lib/etcd",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cfg: &kubeadmapi.MasterConfiguration{
|
||||||
|
Etcd: kubeadmapi.Etcd{
|
||||||
|
DataDir: "/var/lib/etcd",
|
||||||
|
ExtraArgs: map[string]string{
|
||||||
|
"listen-client-urls": "http://10.0.1.10:2379",
|
||||||
|
"advertise-client-urls": "http://10.0.1.10:2379",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []string{
|
||||||
|
"etcd",
|
||||||
|
"--listen-client-urls=http://10.0.1.10:2379",
|
||||||
|
"--advertise-client-urls=http://10.0.1.10:2379",
|
||||||
|
"--data-dir=/var/lib/etcd",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cfg: &kubeadmapi.MasterConfiguration{
|
||||||
|
Etcd: kubeadmapi.Etcd{DataDir: "/etc/foo"},
|
||||||
|
},
|
||||||
|
expected: []string{
|
||||||
|
"etcd",
|
||||||
|
"--listen-client-urls=http://127.0.0.1:2379",
|
||||||
|
"--advertise-client-urls=http://127.0.0.1:2379",
|
||||||
|
"--data-dir=/etc/foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, rt := range tests {
|
||||||
|
actual := getEtcdCommand(rt.cfg)
|
||||||
|
sort.Strings(actual)
|
||||||
|
sort.Strings(rt.expected)
|
||||||
|
if !reflect.DeepEqual(actual, rt.expected) {
|
||||||
|
t.Errorf("failed getEtcdCommand:\nexpected:\n%v\nsaw:\n%v", rt.expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetSchedulerCommand(t *testing.T) {
|
func TestGetSchedulerCommand(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
cfg *kubeadmapi.MasterConfiguration
|
cfg *kubeadmapi.MasterConfiguration
|
||||||
|
@ -515,7 +515,7 @@ func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
|
|||||||
// Only do etcd related checks when no external endpoints were specified
|
// Only do etcd related checks when no external endpoints were specified
|
||||||
checks = append(checks,
|
checks = append(checks,
|
||||||
PortOpenCheck{port: 2379},
|
PortOpenCheck{port: 2379},
|
||||||
DirAvailableCheck{Path: "/var/lib/etcd"},
|
DirAvailableCheck{Path: cfg.Etcd.DataDir},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// Only check etcd version when external endpoints are specified
|
// Only check etcd version when external endpoints are specified
|
||||||
|
Loading…
Reference in New Issue
Block a user