This commit is contained in:
Xiang Li 2016-10-05 15:58:13 -07:00
Родитель b4105d0292
Коммит db6a921ec8
3 изменённых файлов: 23 добавлений и 8 удалений

Просмотреть файл

@ -205,8 +205,8 @@ func (c *Cluster) migrateSeedMember() error {
initialCluster = append(initialCluster, fmt.Sprintf("%s=%s", m.Name, purl))
}
pod := k8sutil.MakeEtcdPod(m, initialCluster, c.name, "existing", "", c.spec.AntiAffinity, c.spec.HostNetwork)
pod = k8sutil.WithAddMemberInitContainer(pod, c.spec.Seed.MemberClientEndpoints, m.Name, mpurls)
pod := k8sutil.MakeEtcdPod(m, initialCluster, c.name, "existing", "", c.spec)
pod = k8sutil.PodWithAddMemberInitContainer(pod, c.spec.Seed.MemberClientEndpoints, m.Name, mpurls)
if err := k8sutil.CreateAndWaitPod(c.kclient, pod, m, c.namespace); err != nil {
return err
@ -353,7 +353,7 @@ func (c *Cluster) createPodAndService(members etcdutil.MemberSet, m *etcdutil.Me
if state == "new" {
token = uuid.New()
}
pod := k8sutil.MakeEtcdPod(m, members.PeerURLPairs(), c.name, state, token, c.spec.AntiAffinity, c.spec.HostNetwork)
pod := k8sutil.MakeEtcdPod(m, members.PeerURLPairs(), c.name, state, token, c.spec)
if needRecovery {
k8sutil.AddRecoveryToPod(pod, c.name, m.Name, token)
}

Просмотреть файл

@ -17,6 +17,12 @@ type ClusterSpec struct {
// cluster equal to the expected size.
// The vaild range of the size is from 1 to 7.
Size int `json:"size"`
// NodeSelector specifies a map of key-value pairs. For the pod to be eligible
// to run on a node, the node must have each of the indicated key-value pairs as
// labels.
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// AntiAffinity determines if the controller tries to avoid putting
// the etcd members in the same cluster onto the same node.
AntiAffinity bool `json:"antiAffinity"`

Просмотреть файл

@ -8,6 +8,7 @@ import (
"strings"
"time"
"github.com/coreos/kube-etcd-controller/pkg/spec"
"github.com/coreos/kube-etcd-controller/pkg/util/etcdutil"
"k8s.io/kubernetes/pkg/api"
apierrors "k8s.io/kubernetes/pkg/api/errors"
@ -75,7 +76,7 @@ func MakeBackupHostPort(clusterName string) string {
return fmt.Sprintf("%s:19999", makeBackupName(clusterName))
}
func WithAddMemberInitContainer(p *api.Pod, endpoints []string, name string, peerURLs []string) *api.Pod {
func PodWithAddMemberInitContainer(p *api.Pod, endpoints []string, name string, peerURLs []string) *api.Pod {
spec := []api.Container{
{
Name: "add-member",
@ -97,6 +98,11 @@ func WithAddMemberInitContainer(p *api.Pod, endpoints []string, name string, pee
return p
}
func PodWithNodeSelector(p *api.Pod, ns map[string]string) *api.Pod {
p.Spec.NodeSelector = ns
return p
}
func makeBackupName(clusterName string) string {
return fmt.Sprintf("%s-backup-tool", clusterName)
}
@ -193,8 +199,7 @@ func AddRecoveryToPod(pod *api.Pod, clusterName, name, token string) {
pod.Annotations[k8sv1api.PodInitContainersAnnotationKey] = makeRestoreInitContainerSpec(MakeBackupHostPort(clusterName), name, token)
}
// todo: use a struct to replace the huge arg list.
func MakeEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state, token string, antiAffinity bool, hostNet bool) *api.Pod {
func MakeEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state, token string, cspec *spec.ClusterSpec) *api.Pod {
commands := []string{
"/usr/local/bin/etcd",
"--data-dir",
@ -277,7 +282,7 @@ func MakeEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state
},
RestartPolicy: api.RestartPolicyNever,
SecurityContext: &api.PodSecurityContext{
HostNetwork: hostNet,
HostNetwork: cspec.HostNetwork,
},
Volumes: []api.Volume{
{Name: "etcd-data", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
@ -285,7 +290,7 @@ func MakeEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state
},
}
if !antiAffinity {
if !cspec.AntiAffinity {
return pod
}
@ -311,6 +316,10 @@ func MakeEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state
pod.Annotations[api.AffinityAnnotationKey] = string(affinityb)
if len(cspec.NodeSelector) != 0 {
pod = PodWithNodeSelector(pod, cspec.NodeSelector)
}
return pod
}