Skip to content

Commit

Permalink
fix realloc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Feb 3, 2023
1 parent b035c80 commit db8a63e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion resource/cobalt/alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (m Manager) Alloc(ctx context.Context, nodename string, deployCount int, op
},
// commit: update node resources
func(ctx context.Context) error {
// TODO why incr?
// 因为用了资源所以 usage 增加
if _, _, err := m.SetNodeResourceUsage(ctx, nodename, nil, nil, workloadsParams, true, plugins.Incr); err != nil {
logger.Error(ctx, err, "failed to update node resource")
return err
Expand Down
10 changes: 3 additions & 7 deletions resource/cobalt/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (m Manager) GetNodeResourceInfo(ctx context.Context, nodename string, workl

// SetNodeResourceUsage .
func (m Manager) SetNodeResourceUsage(ctx context.Context, nodename string, nodeResource resourcetypes.Resources, nodeResourceRequest resourcetypes.Resources, workloadsResource []resourcetypes.Resources, delta bool, incr bool) (resourcetypes.Resources, resourcetypes.Resources, error) {
logger := log.WithFunc("resource.cobalt.SetNodeResourceUsage")
logger := log.WithFunc("resource.cobalt.SetNodeResourceUsage").WithField("node", nodename)
wrksResource := map[string][]resourcetypes.RawParams{}
rollbackPlugins := []plugins.Plugin{}
before := resourcetypes.Resources{}
Expand All @@ -239,11 +239,7 @@ func (m Manager) SetNodeResourceUsage(ctx context.Context, nodename string, node
// commit: call plugins to set node resource
func(ctx context.Context) error {
resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.SetNodeResourceUsageResponse, error) {
resp, err := plugin.SetNodeResourceUsage(ctx, nodename, nodeResource[plugin.Name()], nodeResourceRequest[plugin.Name()], wrksResource[plugin.Name()], delta, incr)
if err != nil {
logger.Errorf(ctx, err, "node %+v plugin %+v failed to update node resource", nodename, plugin.Name())
}
return resp, err
return plugin.SetNodeResourceUsage(ctx, nodename, nodeResource[plugin.Name()], nodeResourceRequest[plugin.Name()], wrksResource[plugin.Name()], delta, incr)
})

if err != nil {
Expand All @@ -252,7 +248,7 @@ func (m Manager) SetNodeResourceUsage(ctx context.Context, nodename string, node
before[plugin.Name()] = resp.Before
after[plugin.Name()] = resp.After
}
logger.Errorf(ctx, err, "failed to set node resource for node %+v", nodename)
logger.Error(ctx, err, "failed to set node resource")
}
return err
},
Expand Down
2 changes: 1 addition & 1 deletion resource/cobalt/realloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (m Manager) Realloc(ctx context.Context, nodename string, nodeResource reso
// commit: update node resource
func(ctx context.Context) error {
// TODO 存在问题??3个参数是完整的变化,差值变化,按照 workloads 的变化
if _, _, err := m.SetNodeResourceUsage(ctx, nodename, nil, nil, []resourcetypes.Resources{workloadResource}, true, plugins.Incr); err != nil {
if _, _, err := m.SetNodeResourceUsage(ctx, nodename, nil, nil, []resourcetypes.Resources{deltaResources}, true, plugins.Incr); err != nil {
logger.Error(ctx, err, "failed to update nodename resource")
return err
}
Expand Down

0 comments on commit db8a63e

Please sign in to comment.