add spec
This commit is contained in:
Родитель
dbf5f03465
Коммит
ae195a169f
|
@ -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
|
||||
|
|
8
main.go
8
main.go
|
@ -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)
|
||||
|
|
|
@ -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"`
|
||||
}
|
Загрузка…
Ссылка в новой задаче