Automatic merge from submit-queue (batch tested with PRs 55900, 55995, 55913, 55467, 55376). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix a typo in kubeadm/GetEtcdPodSpec **What this PR does / why we need it**: Fix a typo in kubeadm/GetEtcdPodSpec. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
77 lines
3.0 KiB
Go
77 lines
3.0 KiB
Go
/*
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package etcd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"k8s.io/api/core/v1"
|
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
|
"k8s.io/kubernetes/cmd/kubeadm/app/images"
|
|
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
staticpodutil "k8s.io/kubernetes/cmd/kubeadm/app/util/staticpod"
|
|
)
|
|
|
|
const (
|
|
etcdVolumeName = "etcd"
|
|
)
|
|
|
|
// CreateLocalEtcdStaticPodManifestFile will write local etcd static pod manifest file.
|
|
func CreateLocalEtcdStaticPodManifestFile(manifestDir string, cfg *kubeadmapi.MasterConfiguration) error {
|
|
|
|
// gets etcd StaticPodSpec, actualized for the current MasterConfiguration
|
|
spec := GetEtcdPodSpec(cfg)
|
|
// writes etcd StaticPod to disk
|
|
if err := staticpodutil.WriteStaticPodToDisk(kubeadmconstants.Etcd, manifestDir, spec); err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("[etcd] Wrote Static Pod manifest for a local etcd instance to %q\n", kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.Etcd, manifestDir))
|
|
return nil
|
|
}
|
|
|
|
// GetEtcdPodSpec returns the etcd static Pod actualized to the context of the current MasterConfiguration
|
|
// NB. GetEtcdPodSpec methods holds the information about how kubeadm creates etcd static pod manifests.
|
|
func GetEtcdPodSpec(cfg *kubeadmapi.MasterConfiguration) v1.Pod {
|
|
pathType := v1.HostPathDirectoryOrCreate
|
|
etcdMounts := map[string]v1.Volume{
|
|
etcdVolumeName: staticpodutil.NewVolume(etcdVolumeName, cfg.Etcd.DataDir, &pathType),
|
|
}
|
|
return staticpodutil.ComponentPod(v1.Container{
|
|
Name: kubeadmconstants.Etcd,
|
|
Command: getEtcdCommand(cfg),
|
|
Image: images.GetCoreImage(kubeadmconstants.Etcd, cfg.ImageRepository, cfg.KubernetesVersion, cfg.Etcd.Image),
|
|
// Mount the etcd datadir path read-write so etcd can store data in a more persistent manner
|
|
VolumeMounts: []v1.VolumeMount{staticpodutil.NewVolumeMount(etcdVolumeName, cfg.Etcd.DataDir, false)},
|
|
LivenessProbe: staticpodutil.ComponentProbe(cfg, kubeadmconstants.Etcd, 2379, "/health", v1.URISchemeHTTP),
|
|
}, etcdMounts)
|
|
}
|
|
|
|
// getEtcdCommand builds the right etcd command from the given config object
|
|
func getEtcdCommand(cfg *kubeadmapi.MasterConfiguration) []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 := []string{"etcd"}
|
|
command = append(command, kubeadmutil.BuildArgumentListFromMap(defaultArguments, cfg.Etcd.ExtraArgs)...)
|
|
return command
|
|
}
|