Skip to content

Commit 62ac3b7

Browse files
committed
fix node set
1 parent f4a05d8 commit 62ac3b7

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

cluster/calcium/node.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ
220220
if len(opts.Resources) == 0 {
221221
return nil
222222
}
223-
origin, _, err = c.rmgr.SetNodeResourceCapacity(ctx, n.Name, opts.Resources, nil, opts.Delta, plugins.Incr)
223+
origin, _, err = c.rmgr.SetNodeResourceCapacity(ctx, n.Name, nil, opts.Resources, opts.Delta, plugins.Incr)
224224
return err
225225
},
226226
// then: update node metadata
@@ -233,6 +233,8 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ
233233
n.ResourceInfo.Capacity, n.ResourceInfo.Usage, n.ResourceInfo.Diffs, _ = c.rmgr.GetNodeResourceInfo(ctx, node.Name, nil, false)
234234
// use send to update the usage
235235
_ = c.pool.Invoke(func() { c.doSendNodeMetrics(context.TODO(), n) })
236+
// remap all container
237+
_ = c.pool.Invoke(func() { c.RemapResourceAndLog(ctx, logger, node) })
236238
return nil
237239
},
238240
// rollback: update node resource capacity in reverse

resource/cobalt/node.go

+6
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ func (m Manager) SetNodeResourceCapacity(ctx context.Context, nodename string, n
324324
// commit: call plugins to set node resource
325325
func(ctx context.Context) error {
326326
resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.SetNodeResourceCapacityResponse, error) {
327+
if nodeResource[plugin.Name()] == nil && nodeResourceRequest[plugin.Name()] == nil {
328+
return nil, nil
329+
}
327330
resp, err := plugin.SetNodeResourceCapacity(ctx, nodename, nodeResource[plugin.Name()], nodeResourceRequest[plugin.Name()], delta, incr)
328331
if err != nil {
329332
logger.Errorf(ctx, err, "plugin %+v failed to set node resource capacity", plugin.Name())
@@ -333,6 +336,9 @@ func (m Manager) SetNodeResourceCapacity(ctx context.Context, nodename string, n
333336

334337
if err != nil {
335338
for plugin, resp := range resps {
339+
if resp == nil {
340+
continue
341+
}
336342
rollbackPlugins = append(rollbackPlugins, plugin)
337343
before[plugin.Name()] = resp.Before
338344
after[plugin.Name()] = resp.After

resource/plugins/cpumem/types/node.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,14 @@ func (n *NodeResourceInfo) RemoveEmptyCores() {
104104
}
105105

106106
func (n *NodeResourceInfo) Validate() error {
107-
if n.Capacity == nil || len(n.Capacity.CPUMap) == 0 {
107+
if n.Capacity == nil {
108108
return ErrInvalidCapacity
109109
}
110+
111+
if len(n.Capacity.CPUMap) == 0 {
112+
return ErrInvalidCPUMap
113+
}
114+
110115
if n.Usage == nil {
111116
n.Usage = &NodeResource{
112117
CPU: 0,
@@ -125,12 +130,9 @@ func (n *NodeResourceInfo) Validate() error {
125130
n.Usage.NUMA[cpuID] = numaNodeID
126131
}
127132
}
128-
if len(n.Capacity.CPUMap) == 0 {
129-
return ErrInvalidCPUMap
130-
}
131133

132134
for cpu, piecesUsed := range n.Usage.CPUMap {
133-
if totalPieces, ok := n.Capacity.CPUMap[cpu]; !ok || piecesUsed < 0 || totalPieces < 0 || piecesUsed > totalPieces {
135+
if totalPieces, ok := n.Capacity.CPUMap[cpu]; !ok || totalPieces < 0 || piecesUsed > totalPieces {
134136
return ErrInvalidCPUMap
135137
}
136138
}
@@ -221,9 +223,9 @@ func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams resourcet
221223
}
222224
}
223225

224-
for index, numaMemoryNode := range rawParams.StringSlice("numa-memory") {
226+
for index, nodeMemory := range rawParams.StringSlice("numa-memory") {
225227
nodeID := fmt.Sprintf("%d", index)
226-
mem, err := coreutils.ParseRAMInHuman(numaMemoryNode)
228+
mem, err := coreutils.ParseRAMInHuman(nodeMemory)
227229
if err != nil {
228230
return err
229231
}
@@ -233,20 +235,20 @@ func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams resourcet
233235
return nil
234236
}
235237

236-
func (n *NodeResourceRequest) LoadFromOrigin(nodeResource *NodeResource, rawParams resourcetypes.RawParams) {
238+
func (n *NodeResourceRequest) LoadFromOrigin(nodeResource *NodeResource, resourceRequest resourcetypes.RawParams) {
237239
if n == nil {
238240
return
239241
}
240-
if !rawParams.IsSet("cpu") {
242+
if !resourceRequest.IsSet("cpu") {
241243
n.CPUMap = nodeResource.CPUMap
242244
}
243-
if !rawParams.IsSet("memory") {
245+
if !resourceRequest.IsSet("memory") {
244246
n.Memory = nodeResource.Memory
245247
}
246-
if !rawParams.IsSet("numa-cpu") {
248+
if !resourceRequest.IsSet("numa-cpu") {
247249
n.NUMA = nodeResource.NUMA
248250
}
249-
if !rawParams.IsSet("numa-memory") {
251+
if !resourceRequest.IsSet("numa-memory") {
250252
n.NUMAMemory = nodeResource.NUMAMemory
251253
}
252254
}

0 commit comments

Comments
 (0)