diff --git a/cluster/calcium/node.go b/cluster/calcium/node.go index ee3b6f114..212ee9fbb 100644 --- a/cluster/calcium/node.go +++ b/cluster/calcium/node.go @@ -220,7 +220,7 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ if len(opts.Resources) == 0 { return nil } - origin, _, err = c.rmgr.SetNodeResourceCapacity(ctx, n.Name, opts.Resources, nil, opts.Delta, plugins.Incr) + origin, _, err = c.rmgr.SetNodeResourceCapacity(ctx, n.Name, nil, opts.Resources, opts.Delta, plugins.Incr) return err }, // then: update node metadata @@ -233,6 +233,8 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ n.ResourceInfo.Capacity, n.ResourceInfo.Usage, n.ResourceInfo.Diffs, _ = c.rmgr.GetNodeResourceInfo(ctx, node.Name, nil, false) // use send to update the usage _ = c.pool.Invoke(func() { c.doSendNodeMetrics(context.TODO(), n) }) + // remap all container + _ = c.pool.Invoke(func() { c.RemapResourceAndLog(ctx, logger, node) }) return nil }, // rollback: update node resource capacity in reverse diff --git a/resource/cobalt/node.go b/resource/cobalt/node.go index 6de5e7638..879971797 100644 --- a/resource/cobalt/node.go +++ b/resource/cobalt/node.go @@ -324,6 +324,9 @@ func (m Manager) SetNodeResourceCapacity(ctx context.Context, nodename string, n // commit: call plugins to set node resource func(ctx context.Context) error { resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.SetNodeResourceCapacityResponse, error) { + if nodeResource[plugin.Name()] == nil && nodeResourceRequest[plugin.Name()] == nil { + return nil, nil + } resp, err := plugin.SetNodeResourceCapacity(ctx, nodename, nodeResource[plugin.Name()], nodeResourceRequest[plugin.Name()], delta, incr) if err != nil { 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 if err != nil { for plugin, resp := range resps { + if resp == nil { + continue + } rollbackPlugins = append(rollbackPlugins, plugin) before[plugin.Name()] = resp.Before after[plugin.Name()] = resp.After diff --git a/resource/plugins/cpumem/types/node.go b/resource/plugins/cpumem/types/node.go index 83df7d4b3..0ab393bde 100644 --- a/resource/plugins/cpumem/types/node.go +++ b/resource/plugins/cpumem/types/node.go @@ -104,9 +104,14 @@ func (n *NodeResourceInfo) RemoveEmptyCores() { } func (n *NodeResourceInfo) Validate() error { - if n.Capacity == nil || len(n.Capacity.CPUMap) == 0 { + if n.Capacity == nil { return ErrInvalidCapacity } + + if len(n.Capacity.CPUMap) == 0 { + return ErrInvalidCPUMap + } + if n.Usage == nil { n.Usage = &NodeResource{ CPU: 0, @@ -125,12 +130,9 @@ func (n *NodeResourceInfo) Validate() error { n.Usage.NUMA[cpuID] = numaNodeID } } - if len(n.Capacity.CPUMap) == 0 { - return ErrInvalidCPUMap - } for cpu, piecesUsed := range n.Usage.CPUMap { - if totalPieces, ok := n.Capacity.CPUMap[cpu]; !ok || piecesUsed < 0 || totalPieces < 0 || piecesUsed > totalPieces { + if totalPieces, ok := n.Capacity.CPUMap[cpu]; !ok || totalPieces < 0 || piecesUsed > totalPieces { return ErrInvalidCPUMap } } @@ -221,9 +223,9 @@ func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams resourcet } } - for index, numaMemoryNode := range rawParams.StringSlice("numa-memory") { + for index, nodeMemory := range rawParams.StringSlice("numa-memory") { nodeID := fmt.Sprintf("%d", index) - mem, err := coreutils.ParseRAMInHuman(numaMemoryNode) + mem, err := coreutils.ParseRAMInHuman(nodeMemory) if err != nil { return err } @@ -233,20 +235,20 @@ func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams resourcet return nil } -func (n *NodeResourceRequest) LoadFromOrigin(nodeResource *NodeResource, rawParams resourcetypes.RawParams) { +func (n *NodeResourceRequest) LoadFromOrigin(nodeResource *NodeResource, resourceRequest resourcetypes.RawParams) { if n == nil { return } - if !rawParams.IsSet("cpu") { + if !resourceRequest.IsSet("cpu") { n.CPUMap = nodeResource.CPUMap } - if !rawParams.IsSet("memory") { + if !resourceRequest.IsSet("memory") { n.Memory = nodeResource.Memory } - if !rawParams.IsSet("numa-cpu") { + if !resourceRequest.IsSet("numa-cpu") { n.NUMA = nodeResource.NUMA } - if !rawParams.IsSet("numa-memory") { + if !resourceRequest.IsSet("numa-memory") { n.NUMAMemory = nodeResource.NUMAMemory } }