Skip to content

Commit 318e034

Browse files
node resource can check volume diff and fix (#427)
1 parent 9c127c3 commit 318e034

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

cluster/calcium/create.go

+1
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ func (c *Calcium) doDeployOneWorkload(
362362
if err := c.store.AddWorkload(ctx, workload); err != nil {
363363
return errors.WithStack(err)
364364
}
365+
log.Infof(ctx, "[doDeployOneWorkload] workload created and saved: %s", workload.ID)
365366
msg.WorkloadID = workload.ID
366367
msg.WorkloadName = workload.Name
367368
msg.Podname = workload.Podname

cluster/calcium/resource.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,17 @@ func (c *Calcium) doGetNodeResource(ctx context.Context, nodename string, fix bo
7171
memory := int64(0)
7272
storage := int64(0)
7373
cpumap := types.CPUMap{}
74+
volumes := int64(0)
75+
volumeMap := types.VolumeMap{}
7476
for _, workload := range workloads {
7577
cpus = utils.Round(cpus + workload.CPUQuotaRequest)
7678
memory += workload.MemoryRequest
7779
storage += workload.StorageRequest
7880
cpumap.Add(workload.CPU)
81+
for _, vmap := range workload.VolumePlanRequest {
82+
volumes += vmap.Total()
83+
volumeMap.Add(vmap)
84+
}
7985
}
8086
nr.CPUPercent = cpus / float64(len(node.InitCPU))
8187
nr.MemoryPercent = float64(memory) / float64(node.InitMemCap)
@@ -108,12 +114,22 @@ func (c *Calcium) doGetNodeResource(ctx context.Context, nodename string, fix bo
108114
}
109115
}
110116

117+
if node.VolumeUsed != volumes {
118+
nr.Diffs = append(nr.Diffs, fmt.Sprintf("volumes used: %d diff: %d", node.VolumeUsed, volumes))
119+
}
120+
node.Volume.Add(volumeMap)
121+
for vol, cap := range node.Volume {
122+
if node.InitVolume[vol] != cap {
123+
nr.Diffs = append(nr.Diffs, fmt.Sprintf("volume %s diff %d", vol, node.InitVolume[vol]-cap))
124+
}
125+
}
126+
111127
if err := node.Engine.ResourceValidate(ctx, cpus, cpumap, memory, storage); err != nil {
112128
nr.Diffs = append(nr.Diffs, err.Error())
113129
}
114130

115131
if fix {
116-
if err := c.doFixDiffResource(ctx, node, cpus, memory, storage); err != nil {
132+
if err := c.doFixDiffResource(ctx, node, cpus, memory, storage, volumes); err != nil {
117133
log.Warnf(ctx, "[doGetNodeResource] fix node resource failed %v", err)
118134
}
119135
}
@@ -122,7 +138,7 @@ func (c *Calcium) doGetNodeResource(ctx context.Context, nodename string, fix bo
122138
})
123139
}
124140

125-
func (c *Calcium) doFixDiffResource(ctx context.Context, node *types.Node, cpus float64, memory, storage int64) error {
141+
func (c *Calcium) doFixDiffResource(ctx context.Context, node *types.Node, cpus float64, memory, storage, volumes int64) error {
126142
var n *types.Node
127143
var err error
128144
return utils.Txn(ctx,
@@ -136,6 +152,10 @@ func (c *Calcium) doFixDiffResource(ctx context.Context, node *types.Node, cpus
136152
}
137153
n.MemCap += node.InitMemCap - (memory + node.MemCap)
138154
n.StorageCap += node.InitStorageCap - (storage + node.StorageCap)
155+
n.VolumeUsed = volumes
156+
for vol, cap := range node.Volume {
157+
n.Volume[vol] += node.InitVolume[vol] - cap
158+
}
139159
return nil
140160
},
141161
func(ctx context.Context) error {

0 commit comments

Comments
 (0)