Skip to content

Commit dea6d55

Browse files
committed
Merge branch 'add-zone' into 'master'
Add zone See merge request !48
2 parents be055d9 + 4f80e8a commit dea6d55

File tree

10 files changed

+170
-142
lines changed

10 files changed

+170
-142
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ permdir: "/mnt/mfs/permdirs" # 宿主机的 permdir 的路径
6969
etcd: # etcd 集群的地址
7070
- "http://127.0.0.1:2379"
7171
etcd_lock_prefix: "/eru-core/_lock" # etcd 分布式锁的前缀, 一般会用隐藏文件夹
72+
zone: "c1" # 机房区域
7273

7374
git:
7475
public_key: "[path_to_pub_key]" # git clone 使用的公钥

cluster/calcium/meta.go

+4
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ func (c *calcium) GetContainer(id string) (*types.Container, error) {
6767
func (c *calcium) GetContainers(ids []string) ([]*types.Container, error) {
6868
return c.store.GetContainers(ids)
6969
}
70+
71+
func (c *calcium) GetZone() string {
72+
return c.config.Zone
73+
}

cluster/cluster.go

+3
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ type Cluster interface {
2424
UpgradeContainer(ids []string, image string) (chan *types.UpgradeContainerMessage, error)
2525
RemoveContainer(ids []string) (chan *types.RemoveContainerMessage, error)
2626
RemoveImage(podname, nodename string, images []string) (chan *types.RemoveImageMessage, error)
27+
28+
// cluster attribute methods
29+
GetZone() string
2730
}

core.yaml.sample

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ etcd_lock_prefix: "/eru-core/_lock"
88
resource_alloc: "cpu-period"
99
statsd: "statsd2.ricebook.net:8125"
1010

11+
zone: "c1"
12+
1113
git:
1214
public_key: "***REMOVED***"
1315
private_key: "***REMOVED***"

devtools/core_pb2.py

+59-52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/gen/core.pb.go

+93-85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/gen/core.proto

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ message Node {
5252
map<string, int64> cpu = 5;
5353
string info = 6;
5454
bool available = 7;
55+
string zone = 8;
5556
}
5657

5758
message Nodes {

rpc/rpc.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (v *virbranium) AddNode(ctx context.Context, opts *pb.AddNodeOptions) (*pb.
6363
return nil, err
6464
}
6565

66-
return toRPCNode(n), nil
66+
return toRPCNode(n, v.cluster.GetZone()), nil
6767
}
6868

6969
// AddNode saves a node and returns it to client
@@ -84,7 +84,7 @@ func (v *virbranium) GetNode(ctx context.Context, opts *pb.GetNodeOptions) (*pb.
8484
return nil, err
8585
}
8686

87-
return toRPCNode(n), nil
87+
return toRPCNode(n, v.cluster.GetZone()), nil
8888
}
8989

9090
// ListPodNodes returns a list of node for pod
@@ -96,7 +96,7 @@ func (v *virbranium) ListPodNodes(ctx context.Context, opts *pb.ListNodesOptions
9696

9797
nodes := []*pb.Node{}
9898
for _, n := range ns {
99-
nodes = append(nodes, toRPCNode(n))
99+
nodes = append(nodes, toRPCNode(n, v.cluster.GetZone()))
100100
}
101101
return &pb.Nodes{Nodes: nodes}, nil
102102
}
@@ -172,7 +172,7 @@ func (v *virbranium) SetNodeAvailable(ctx context.Context, opts *pb.NodeAvailabl
172172
if err != nil {
173173
return nil, err
174174
}
175-
return toRPCNode(n), nil
175+
return toRPCNode(n, v.cluster.GetZone()), nil
176176
}
177177

178178
// streamed returned functions

rpc/transform.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func toRPCNetwork(n *types.Network) *pb.Network {
2323
return &pb.Network{Name: n.Name, Subnets: n.Subnets}
2424
}
2525

26-
func toRPCNode(n *types.Node) *pb.Node {
26+
func toRPCNode(n *types.Node, zone string) *pb.Node {
2727
bytes := []byte("")
2828
if info, err := n.Info(); err == nil {
2929
bytes, _ = json.Marshal(info)
@@ -37,6 +37,7 @@ func toRPCNode(n *types.Node) *pb.Node {
3737
Cpu: toRPCCPUMap(n.CPU),
3838
Info: string(bytes),
3939
Available: n.Available,
40+
Zone: zone,
4041
}
4142
}
4243

types/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Config struct {
99
EtcdLockPrefix string `yaml:"etcd_lock_prefix"` // etcd lock prefix, all locks will be created under this dir
1010
ResourceAlloc string `yaml:"resource_alloc"` // scheduler or cpu-period TODO give it a good name
1111
Statsd string `yaml:"statsd"` // Statsd host and port
12+
Zone string `yaml:"zone"` // zone for core, e.g. C1, C2
1213

1314
Git GitConfig `yaml:"git"`
1415
Docker DockerConfig `yaml:"docker"`

0 commit comments

Comments
 (0)