Skip to content

Commit

Permalink
unite node info, add tools for update
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Dec 5, 2018
1 parent 23db44d commit 3b4be32
Show file tree
Hide file tree
Showing 19 changed files with 1,047 additions and 992 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ test*.py
set*
test.yaml
local.yaml
tools/*
tools/update
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mock: deps
mockery -dir ./vendor/google.golang.org/grpc -name ServerStream -output 3rdmocks

cloc:
cloc --exclude-dir=vendor,3rdmocks,mocks --not-match-f=test .
cloc --exclude-dir=vendor,3rdmocks,mocks,tools --not-match-f=test .

unit-test:
go vet `go list ./... | grep -v '/vendor/'`
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func getNodesInfo(nodes map[string]*types.Node, cpu float64, memory int64) []typ
MemCap: node.MemCap,
CPURate: cpu / float64(len(node.InitCPU)),
MemRate: float64(memory) / float64(node.InitMemCap),
CPUUsage: node.CPUUsage / float64(len(node.InitCPU)),
CPUUsed: node.CPUUsed / float64(len(node.InitCPU)),
MemUsage: 1.0 - float64(node.MemCap)/float64(node.InitMemCap),
Capacity: 0,
Count: 0,
Expand Down
8 changes: 4 additions & 4 deletions cluster/calcium/realloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ func (c *Calcium) doUpdateContainerWithMemoryPrior(
}
// 记录CPU变动
if cpu > 0 {
node.SetCPUUsage(cpu, types.IncrUsage)
node.SetCPUUsed(cpu, types.IncrUsage)
} else {
node.SetCPUUsage(cpu, types.DecrUsage)
node.SetCPUUsed(cpu, types.DecrUsage)
}
// 更新容器元信息
container.Quota = newCPU
Expand Down Expand Up @@ -248,7 +248,7 @@ func (c *Calcium) doReallocNodesCPUMem(
for _, container := range containers {
// 不更新 etcd,内存计算
node.CPU.Add(container.CPU)
node.SetCPUUsage(container.Quota, types.DecrUsage)
node.SetCPUUsed(container.Quota, types.DecrUsage)
node.MemCap += container.Memory
}

Expand Down Expand Up @@ -307,7 +307,7 @@ func (c *Calcium) doUpdateContainersWithCPUPrior(
}
// 成功的时候应该记录变动
node.CPU.Sub(cpuPlan)
node.SetCPUUsage(newCPU, types.IncrUsage)
node.SetCPUUsed(newCPU, types.IncrUsage)
node.MemCap -= newMem
container.CPU = cpuPlan
container.Quota = newCPU
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func (c *Calcium) PodResource(ctx context.Context, podname string) (*types.PodRe
r.Diff[node.Name] = true
r.Detail[node.Name] = ""
cpumap.Add(node.CPU)
if cpus != node.CPUUsage {
if cpus != node.CPUUsed {
r.Diff[node.Name] = false
r.Detail[node.Name] += fmt.Sprintf("cpus %f now %f ", node.CPUUsage, cpus)
r.Detail[node.Name] += fmt.Sprintf("cpus %f now %f ", node.CPUUsed, cpus)
}
for i, v := range cpumap {
if node.InitCPU[i] != v {
Expand Down
Loading

0 comments on commit 3b4be32

Please sign in to comment.