This commit is contained in:
Xiang Li 2016-08-21 18:32:46 -07:00
Родитель dbf5f03465
Коммит ae195a169f
4 изменённых файлов: 19 добавлений и 10 удалений

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

@ -48,7 +48,7 @@ type Cluster struct {
backupDir string
}
func newCluster(kclient *unversioned.Client, name string, size int, antiAffinity bool) *Cluster {
func newCluster(kclient *unversioned.Client, name string, spec Spec) *Cluster {
c := &Cluster{
kclient: kclient,
name: name,
@ -58,8 +58,8 @@ func newCluster(kclient *unversioned.Client, name string, size int, antiAffinity
go c.run()
c.send(&clusterEvent{
typ: eventNewCluster,
size: size,
antiAffinity: antiAffinity,
size: spec.Size,
antiAffinity: spec.AntiAffinity,
})
return c
}

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

@ -2,4 +2,5 @@ apiVersion: "coreos.com/v1"
kind: "EtcdCluster"
metadata:
name: "etcd-cluster"
size: 3
spec:
size: 3

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

@ -32,11 +32,7 @@ type EtcdCluster struct {
Kind string `json:"kind"`
ApiVersion string `json:"apiVersion"`
Metadata map[string]string `json:"metadata"`
// TODO: add Spec section
Size int `json:"size"`
// AntiAffinity determines if the controller tries to avoid putting the etcd members
// in the same cluster onto the same node.
AntiAffinity bool `json:"antiAffinity"`
Spec Spec `json: "spec"`
}
type Event struct {
@ -57,7 +53,7 @@ func (c *etcdClusterController) Run() {
clusterName := event.Object.Metadata["name"]
switch event.Type {
case "ADDED":
c.clusters[clusterName] = newCluster(c.kclient, clusterName, event.Object.Size, event.Object.AntiAffinity)
c.clusters[clusterName] = newCluster(c.kclient, clusterName, event.Object.Spec)
case "DELETED":
c.clusters[clusterName].Delete()
delete(c.clusters, clusterName)

12
spec.go Normal file
Просмотреть файл

@ -0,0 +1,12 @@
package main
type Spec struct {
// Size is the expected size of the etcd cluster.
// The controller will eventually make the size of the running
// cluster equal to the expected size.
// The vaild range of the size is from 1 to 7.
Size int `json:"size"`
// AntiAffinity determines if the controller tries to avoid putting
// the etcd members in the same cluster onto the same node.
AntiAffinity bool `json:"antiAffinity"`
}