diff --git a/cluster/calcium/capacity_test.go b/cluster/calcium/capacity_test.go index 34c84b189..d8af43649 100644 --- a/cluster/calcium/capacity_test.go +++ b/cluster/calcium/capacity_test.go @@ -40,7 +40,7 @@ func TestCalculateCapacity(t *testing.T) { Entrypoint: &types.Entrypoint{ Name: "entry", }, - Resources: &types.Resources{}, + Resources: types.Resources{}, DeployStrategy: strategy.Auto, NodeFilter: &types.NodeFilter{ Includes: []string{name}, diff --git a/cluster/calcium/create.go b/cluster/calcium/create.go index d3d0310dc..890fe55fc 100644 --- a/cluster/calcium/create.go +++ b/cluster/calcium/create.go @@ -52,9 +52,9 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio deployMap map[string]int rollbackMap map[string][]int // map[nodename][]Resources - engineParamsMap = map[string][]*types.Resources{} + engineParamsMap = map[string][]types.Resources{} // map[nodename][]Resources - workloadResourcesMap = map[string][]*types.Resources{} + workloadResourcesMap = map[string][]types.Resources{} ) _ = c.pool.Invoke(func() { @@ -151,7 +151,7 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio } for nodename, rollbackIndices := range rollbackMap { if e := c.withNodePodLocked(ctx, nodename, func(ctx context.Context, node *types.Node) error { - rollbackResources := utils.Map(rollbackIndices, func(idx int) *types.Resources { + rollbackResources := utils.Map(rollbackIndices, func(idx int) types.Resources { return workloadResourcesMap[nodename][idx] }) return c.rmgr.RollbackAlloc(ctx, nodename, rollbackResources) @@ -173,8 +173,8 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio func (c *Calcium) doDeployWorkloads(ctx context.Context, ch chan *types.CreateWorkloadMessage, opts *types.DeployOptions, - engineParamsMap map[string][]*types.Resources, - workloadResourcesMap map[string][]*types.Resources, + engineParamsMap map[string][]types.Resources, + workloadResourcesMap map[string][]types.Resources, deployMap map[string]int) (_ map[string][]int, err error) { wg := sync.WaitGroup{} @@ -220,8 +220,8 @@ func (c *Calcium) doDeployWorkloadsOnNode(ctx context.Context, nodename string, opts *types.DeployOptions, deploy int, - engineParams []*types.Resources, - workloadResources []*types.Resources, + engineParams []types.Resources, + workloadResources []types.Resources, seq int) (indices []int, err error) { logger := log.WithFunc("calcium.doDeployWorkloadsOnNode").WithField("node", nodename).WithField("ident", opts.ProcessIdent).WithField("deploy", deploy).WithField("seq", seq) diff --git a/cluster/calcium/create_test.go b/cluster/calcium/create_test.go index 91f590c68..000bb324e 100644 --- a/cluster/calcium/create_test.go +++ b/cluster/calcium/create_test.go @@ -68,7 +68,7 @@ func TestCreateWorkloadTxn(t *testing.T) { Count: 2, DeployStrategy: strategy.Auto, Podname: "p1", - Resources: &types.Resources{}, + Resources: types.Resources{}, Image: "zc:test", Entrypoint: &types.Entrypoint{ Name: "good-entrypoint", @@ -149,8 +149,8 @@ func TestCreateWorkloadTxn(t *testing.T) { assert.True(t, walCommitted) walCommitted = false rmgr.On("Alloc", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - []*types.Resources{{}, {}}, - []*types.Resources{ + []types.Resources{{}, {}}, + []types.Resources{ {node1.Name: {}}, {node2.Name: {}}, }, diff --git a/cluster/calcium/dissociate.go b/cluster/calcium/dissociate.go index 27fc1e9b1..25b3bf526 100644 --- a/cluster/calcium/dissociate.go +++ b/cluster/calcium/dissociate.go @@ -32,7 +32,7 @@ func (c *Calcium) DissociateWorkload(ctx context.Context, IDs []string) (chan *t ctx, // if func(ctx context.Context) (err error) { - _, _, err = c.rmgr.SetNodeResourceUsage(ctx, node.Name, nil, nil, []*types.Resources{workload.Resources}, true, plugins.Decr) + _, _, err = c.rmgr.SetNodeResourceUsage(ctx, node.Name, nil, nil, []types.Resources{workload.Resources}, true, plugins.Decr) return err }, // then @@ -44,7 +44,7 @@ func (c *Calcium) DissociateWorkload(ctx context.Context, IDs []string) (chan *t if failedByCond { return nil } - _, _, err = c.rmgr.SetNodeResourceUsage(ctx, node.Name, nil, nil, []*types.Resources{workload.Resources}, true, plugins.Incr) + _, _, err = c.rmgr.SetNodeResourceUsage(ctx, node.Name, nil, nil, []types.Resources{workload.Resources}, true, plugins.Incr) return err }, c.config.GlobalTimeout, diff --git a/cluster/calcium/dissociate_test.go b/cluster/calcium/dissociate_test.go index 364fd47cf..b843d47f8 100644 --- a/cluster/calcium/dissociate_test.go +++ b/cluster/calcium/dissociate_test.go @@ -25,7 +25,7 @@ func TestDissociateWorkload(t *testing.T) { lock.On("Unlock", mock.Anything).Return(nil) c1 := &types.Workload{ - Resources: &types.Resources{}, + Resources: types.Resources{}, ID: "c1", Podname: "p1", Nodename: "node1", @@ -55,8 +55,8 @@ func TestDissociateWorkload(t *testing.T) { store.On("CreateLock", mock.Anything, mock.Anything).Return(lock, nil) // failed by RemoveWorkload rmgr.On("SetNodeResourceUsage", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, - &types.Resources{}, + types.Resources{}, + types.Resources{}, nil, ) store.On("RemoveWorkload", mock.Anything, mock.Anything).Return(types.ErrMockError).Once() diff --git a/cluster/calcium/lambda_test.go b/cluster/calcium/lambda_test.go index 351fa30ef..5fbf8505c 100644 --- a/cluster/calcium/lambda_test.go +++ b/cluster/calcium/lambda_test.go @@ -41,7 +41,7 @@ func TestRunAndWaitFailedThenWALCommitted(t *testing.T) { Count: 2, DeployStrategy: strategy.Auto, Podname: "p1", - Resources: &types.Resources{}, + Resources: types.Resources{}, Image: "zc:test", Entrypoint: &types.Entrypoint{ Name: "good-entrypoint", @@ -77,7 +77,7 @@ func TestLambdaWithWorkloadIDReturned(t *testing.T) { Count: 2, DeployStrategy: strategy.Auto, Podname: "p1", - Resources: &types.Resources{}, + Resources: types.Resources{}, Image: "zc:test", Entrypoint: &types.Entrypoint{ Name: "good-entrypoint", @@ -129,7 +129,7 @@ func TestLambdaWithError(t *testing.T) { Count: 2, DeployStrategy: strategy.Auto, Podname: "p1", - Resources: &types.Resources{}, + Resources: types.Resources{}, Image: "zc:test", Entrypoint: &types.Entrypoint{ Name: "good-entrypoint", @@ -195,8 +195,8 @@ func newLambdaCluster(t *testing.T) (*Calcium, []*types.Node) { store := c.store.(*storemocks.Store) rmgr := c.rmgr.(*resourcemocks.Manager) rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, - &types.Resources{}, + types.Resources{}, + types.Resources{}, []string{}, nil, ) @@ -218,8 +218,8 @@ func newLambdaCluster(t *testing.T) (*Calcium, []*types.Node) { 20, nil, ) rmgr.On("Alloc", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - []*types.Resources{{}, {}}, - []*types.Resources{ + []types.Resources{{}, {}}, + []types.Resources{ {node1.Name: {}}, {node2.Name: {}}, }, diff --git a/cluster/calcium/node.go b/cluster/calcium/node.go index 9e63d8ca6..2ac2b0e22 100644 --- a/cluster/calcium/node.go +++ b/cluster/calcium/node.go @@ -20,7 +20,7 @@ func (c *Calcium) AddNode(ctx context.Context, opts *types.AddNodeOptions) (*typ logger.Error(ctx, err) return nil, err } - var res *types.Resources + var res types.Resources var node *types.Node var err error @@ -212,8 +212,8 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ n.Labels = opts.Labels } - var origin *types.Resources - if len((*opts.Resources)) == 0 { + var origin types.Resources + if len(opts.Resources) == 0 { return nil } diff --git a/cluster/calcium/node_test.go b/cluster/calcium/node_test.go index 63ca6d973..d26cdf166 100644 --- a/cluster/calcium/node_test.go +++ b/cluster/calcium/node_test.go @@ -42,7 +42,7 @@ func TestAddNode(t *testing.T) { assert.Error(t, err) rmgr.AssertExpectations(t) rmgr.On("AddNode", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, nil) + types.Resources{}, nil) rmgr.On("RemoveNode", mock.Anything, mock.Anything).Return(nil) // failed by store.AddNode @@ -248,7 +248,7 @@ func TestSetNode(t *testing.T) { opts.Labels = labels // failed by SetNodeResourceCapacity - opts.Resources = &types.Resources{"a": {"a": 1}} + opts.Resources = types.Resources{"a": {"a": 1}} rmgr.On("SetNodeResourceCapacity", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( nil, nil, types.ErrMockError, ).Once() diff --git a/cluster/calcium/realloc.go b/cluster/calcium/realloc.go index 90c98dd03..1289fe6b4 100644 --- a/cluster/calcium/realloc.go +++ b/cluster/calcium/realloc.go @@ -31,9 +31,9 @@ func (c *Calcium) ReallocResource(ctx context.Context, opts *types.ReallocOption } func (c *Calcium) doReallocOnNode(ctx context.Context, node *types.Node, workload *types.Workload, originWorkload types.Workload, opts *types.ReallocOptions) error { - var resources *types.Resources - var deltaResources *types.Resources - var engineParams *types.Resources + var resources types.Resources + var deltaResources types.Resources + var engineParams types.Resources var err error logger := log.WithFunc("calcium.doReallocOnNode").WithField("opts", opts) diff --git a/cluster/calcium/realloc_test.go b/cluster/calcium/realloc_test.go index a22c5462f..380657b76 100644 --- a/cluster/calcium/realloc_test.go +++ b/cluster/calcium/realloc_test.go @@ -47,7 +47,7 @@ func TestRealloc(t *testing.T) { ID: "c1", Podname: "p1", Engine: engine, - Resources: &types.Resources{}, + Resources: types.Resources{}, Nodename: "node1", }, } @@ -56,7 +56,7 @@ func TestRealloc(t *testing.T) { store.On("GetWorkload", mock.Anything, "c1").Return(newC1(context.Background(), nil)[0], nil) opts := &types.ReallocOptions{ ID: "c1", - Resources: &types.Resources{}, + Resources: types.Resources{}, } // failed by GetNode @@ -76,14 +76,14 @@ func TestRealloc(t *testing.T) { // failed by plugin rmgr.On("Realloc", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, nil, nil, types.ErrMockError, + types.Resources{}, nil, nil, types.ErrMockError, ).Once() err = c.ReallocResource(ctx, opts) assert.Error(t, err) rmgr.On("Realloc", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, - &types.Resources{}, - &types.Resources{}, + types.Resources{}, + types.Resources{}, + types.Resources{}, nil, ) rmgr.On("RollbackRealloc", mock.Anything, mock.Anything, mock.Anything).Return(nil) diff --git a/cluster/calcium/remap.go b/cluster/calcium/remap.go index 34ef3e55d..22790a865 100644 --- a/cluster/calcium/remap.go +++ b/cluster/calcium/remap.go @@ -48,10 +48,10 @@ func (c *Calcium) doRemapResource(ctx context.Context, node *types.Node) (ch cha return nil, err } - ch = make(chan *remapMsg, len(*engineParamsMap)) + ch = make(chan *remapMsg, len(engineParamsMap)) _ = c.pool.Invoke(func() { defer close(ch) - for workloadID, engineParams := range *engineParamsMap { + for workloadID, engineParams := range engineParamsMap { ch <- &remapMsg{ ID: workloadID, err: node.Engine.VirtualizationUpdateResource(ctx, workloadID, &enginetypes.VirtualizationResource{EngineParams: engineParams}), diff --git a/cluster/calcium/remap_test.go b/cluster/calcium/remap_test.go index 5383a7643..13d297e5d 100644 --- a/cluster/calcium/remap_test.go +++ b/cluster/calcium/remap_test.go @@ -20,19 +20,19 @@ func TestRemapResource(t *testing.T) { store := c.store.(*storemocks.Store) rmgr := c.rmgr.(*resourcemocks.Manager) rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{"test": {"abc": 123}}, - &types.Resources{"test": {"abc": 123}}, + types.Resources{"test": {"abc": 123}}, + types.Resources{"test": {"abc": 123}}, []string{types.ErrMockError.Error()}, nil) rmgr.On("Remap", mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, + types.Resources{}, nil, ) engine := &enginemocks.API{} node := &types.Node{Engine: engine} workload := &types.Workload{ - Resources: &types.Resources{}, + Resources: types.Resources{}, } store.On("ListNodeWorkloads", mock.Anything, mock.Anything, mock.Anything).Return([]*types.Workload{workload}, nil) ch := make(chan enginetypes.VirtualizationRemapMessage, 1) diff --git a/cluster/calcium/remove.go b/cluster/calcium/remove.go index a66fb31c2..8b78f14e2 100644 --- a/cluster/calcium/remove.go +++ b/cluster/calcium/remove.go @@ -40,7 +40,7 @@ func (c *Calcium) RemoveWorkload(ctx context.Context, IDs []string, force bool) ctx, // if func(ctx context.Context) error { - _, _, err = c.rmgr.SetNodeResourceUsage(ctx, node.Name, nil, nil, []*types.Resources{workload.Resources}, true, plugins.Decr) + _, _, err = c.rmgr.SetNodeResourceUsage(ctx, node.Name, nil, nil, []types.Resources{workload.Resources}, true, plugins.Decr) return err }, // then @@ -55,7 +55,7 @@ func (c *Calcium) RemoveWorkload(ctx context.Context, IDs []string, force bool) if failedByCond { return nil } - _, _, err = c.rmgr.SetNodeResourceUsage(ctx, node.Name, nil, nil, []*types.Resources{workload.Resources}, true, plugins.Incr) + _, _, err = c.rmgr.SetNodeResourceUsage(ctx, node.Name, nil, nil, []types.Resources{workload.Resources}, true, plugins.Incr) return err }, c.config.GlobalTimeout, diff --git a/cluster/calcium/remove_test.go b/cluster/calcium/remove_test.go index aefb332d8..c56047d79 100644 --- a/cluster/calcium/remove_test.go +++ b/cluster/calcium/remove_test.go @@ -27,8 +27,8 @@ func TestRemoveWorkload(t *testing.T) { rmgr := c.rmgr.(*resourcemocks.Manager) rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, nil, nil) rmgr.On("SetNodeResourceUsage", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, - &types.Resources{}, + types.Resources{}, + types.Resources{}, nil, ) rmgr.On("GetNodeMetrics", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*plugintypes.Metrics{}, nil) diff --git a/cluster/calcium/resource_test.go b/cluster/calcium/resource_test.go index a982e0e6d..68a586708 100644 --- a/cluster/calcium/resource_test.go +++ b/cluster/calcium/resource_test.go @@ -48,8 +48,8 @@ func TestPodResource(t *testing.T) { assert.NotEmpty(t, msg.Diffs) store.AssertExpectations(t) workloads := []*types.Workload{ - {Resources: &types.Resources{}}, - {Resources: &types.Resources{}}, + {Resources: types.Resources{}}, + {Resources: types.Resources{}}, } store.On("ListNodeWorkloads", mock.Anything, mock.Anything, mock.Anything).Return(workloads, nil) @@ -63,8 +63,8 @@ func TestPodResource(t *testing.T) { assert.NotEmpty(t, msg.Diffs) store.AssertExpectations(t) rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{"test": {"abc": 123}}, - &types.Resources{"test": {"abc": 123}}, + types.Resources{"test": {"abc": 123}}, + types.Resources{"test": {"abc": 123}}, []string{}, nil) @@ -98,14 +98,14 @@ func TestNodeResource(t *testing.T) { store.On("CreateLock", mock.Anything, mock.Anything).Return(lock, nil) rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{"test": {"abc": 123}}, - &types.Resources{"test": {"abc": 123}}, + types.Resources{"test": {"abc": 123}}, + types.Resources{"test": {"abc": 123}}, []string{}, nil) workloads := []*types.Workload{ - {Resources: &types.Resources{}, Engine: engine}, - {Resources: &types.Resources{}, Engine: engine}, + {Resources: types.Resources{}, Engine: engine}, + {Resources: types.Resources{}, Engine: engine}, } store.On("ListNodeWorkloads", mock.Anything, mock.Anything, mock.Anything).Return(workloads, nil) engine.On("VirtualizationInspect", mock.Anything, mock.Anything).Return(nil, types.ErrMockError) diff --git a/cluster/calcium/wal_test.go b/cluster/calcium/wal_test.go index 186a9b0a5..579bc2586 100644 --- a/cluster/calcium/wal_test.go +++ b/cluster/calcium/wal_test.go @@ -26,8 +26,8 @@ func TestHandleCreateWorkloadNoHandle(t *testing.T) { c.wal = wal rmgr := c.rmgr.(*resourcemocks.Manager) rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, - &types.Resources{}, + types.Resources{}, + types.Resources{}, []string{}, nil, ) @@ -58,8 +58,8 @@ func TestHandleCreateWorkloadError(t *testing.T) { c.wal = wal rmgr := c.rmgr.(*resourcemocks.Manager) rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, - &types.Resources{}, + types.Resources{}, + types.Resources{}, []string{}, nil, ) @@ -112,8 +112,8 @@ func TestHandleCreateWorkloadHandled(t *testing.T) { c.wal = wal rmgr := c.rmgr.(*resourcemocks.Manager) rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, - &types.Resources{}, + types.Resources{}, + types.Resources{}, []string{}, nil, ) @@ -160,19 +160,19 @@ func TestHandleCreateLambda(t *testing.T) { c.wal = wal rmgr := c.rmgr.(*resourcemocks.Manager) rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, - &types.Resources{}, + types.Resources{}, + types.Resources{}, []string{}, nil, ) rmgr.On("SetNodeResourceUsage", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, - &types.Resources{}, + types.Resources{}, + types.Resources{}, nil, ) rmgr.On("GetNodeMetrics", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*plugintypes.Metrics{}, nil) rmgr.On("Remap", mock.Anything, mock.Anything, mock.Anything).Return( - &types.Resources{}, + types.Resources{}, nil, ) diff --git a/resource/cobalt/alloc.go b/resource/cobalt/alloc.go index 811f32487..1a90a1f2c 100644 --- a/resource/cobalt/alloc.go +++ b/resource/cobalt/alloc.go @@ -23,24 +23,24 @@ opts struct }, } */ -func (m Manager) Alloc(ctx context.Context, nodename string, deployCount int, opts *types.Resources) ([]*types.Resources, []*types.Resources, error) { +func (m Manager) Alloc(ctx context.Context, nodename string, deployCount int, opts types.Resources) ([]types.Resources, []types.Resources, error) { logger := log.WithFunc("resource.coblat.Alloc") // index -> no, map by plugin name - workloadsParams := []*types.Resources{} - engineParams := []*types.Resources{} + workloadsParams := []types.Resources{} + engineParams := []types.Resources{} // init engine args for i := 0; i < deployCount; i++ { - workloadsParams[i] = &types.Resources{} - engineParams[i] = &types.Resources{} + workloadsParams[i] = types.Resources{} + engineParams[i] = types.Resources{} } return workloadsParams, engineParams, utils.PCR(ctx, // prepare: calculate engine args and resource args func(ctx context.Context) error { resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.CalculateDeployResponse, error) { - resp, err := plugin.CalculateDeploy(ctx, nodename, deployCount, (*opts)[plugin.Name()]) + resp, err := plugin.CalculateDeploy(ctx, nodename, deployCount, opts[plugin.Name()]) if err != nil { logger.Errorf(ctx, err, "plugin %+v failed to compute alloc args, request %+v, node %+v, deploy count %+v", plugin.Name(), opts, nodename, deployCount) } @@ -54,16 +54,16 @@ func (m Manager) Alloc(ctx context.Context, nodename string, deployCount int, op for plugin, resp := range resps { logger.Debug(ctx, plugin.Name()) for index, params := range resp.WorkloadsResource { - (*workloadsParams[index])[plugin.Name()] = params + workloadsParams[index][plugin.Name()] = params } for index, params := range resp.EnginesParams { - v := (*engineParams[index])[plugin.Name()] + v := engineParams[index][plugin.Name()] vMerged, err := m.mergeEngineParams(ctx, v, params) if err != nil { logger.Error(ctx, err, "invalid engine args") return err } - (*engineParams[index])[plugin.Name()] = vMerged + engineParams[index][plugin.Name()] = vMerged } } return nil @@ -86,7 +86,7 @@ func (m Manager) Alloc(ctx context.Context, nodename string, deployCount int, op } // RollbackAlloc rollbacks the allocated resource -func (m Manager) RollbackAlloc(ctx context.Context, nodename string, workloadsParams []*types.Resources) error { +func (m Manager) RollbackAlloc(ctx context.Context, nodename string, workloadsParams []types.Resources) error { _, _, err := m.SetNodeResourceUsage(ctx, nodename, nil, nil, workloadsParams, true, plugins.Decr) return err } diff --git a/resource/cobalt/node.go b/resource/cobalt/node.go index 1423b0e52..33bc6632d 100644 --- a/resource/cobalt/node.go +++ b/resource/cobalt/node.go @@ -17,9 +17,9 @@ import ( ) // AddNode . -func (m Manager) AddNode(ctx context.Context, nodename string, opts *types.Resources, nodeInfo *enginetypes.Info) (*types.Resources, error) { +func (m Manager) AddNode(ctx context.Context, nodename string, opts types.Resources, nodeInfo *enginetypes.Info) (types.Resources, error) { logger := log.WithFunc("resource.cobalt.AddNode").WithField("node", nodename) - res := &types.Resources{} + res := types.Resources{} rollbackPlugins := []plugins.Plugin{} return res, utils.PCR(ctx, @@ -30,7 +30,7 @@ func (m Manager) AddNode(ctx context.Context, nodename string, opts *types.Resou // commit: call plugins to add the node func(ctx context.Context) error { resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.AddNodeResponse, error) { - r := (*opts)[plugin.Name()] + r := opts[plugin.Name()] resp, err := plugin.AddNode(ctx, nodename, r, nodeInfo) if err != nil { logger.Errorf(ctx, err, "node %+v plugin %+v failed to add node, req: %+v", nodename, plugin.Name(), litter.Sdump(opts)) @@ -46,7 +46,7 @@ func (m Manager) AddNode(ctx context.Context, nodename string, opts *types.Resou } for plugin, resp := range resps { - (*res)[plugin.Name()] = resp.Capacity + res[plugin.Name()] = resp.Capacity } return nil @@ -73,8 +73,8 @@ func (m Manager) AddNode(ctx context.Context, nodename string, opts *types.Resou // RemoveNode . func (m Manager) RemoveNode(ctx context.Context, nodename string) error { logger := log.WithFunc("resource.cobalt.RemoveNode").WithField("node", nodename) - var nodeCapacity *types.Resources - var nodeUsage *types.Resources + var nodeCapacity types.Resources + var nodeUsage types.Resources rollbackPlugins := []plugins.Plugin{} return utils.PCR(ctx, @@ -111,8 +111,8 @@ func (m Manager) RemoveNode(ctx context.Context, nodename string) error { // rollback: add node func(ctx context.Context) error { _, err := call(ctx, rollbackPlugins, func(plugin plugins.Plugin) (*plugintypes.SetNodeResourceInfoResponse, error) { - capacity := (*nodeCapacity)[plugin.Name()] - usage := (*nodeUsage)[plugin.Name()] + capacity := nodeCapacity[plugin.Name()] + usage := nodeUsage[plugin.Name()] resp, err := plugin.SetNodeResourceInfo(ctx, nodename, capacity, usage) if err != nil { @@ -163,9 +163,9 @@ func (m Manager) GetMostIdleNode(ctx context.Context, nodenames []string) (strin } // GetNodeResourceInfo . -func (m Manager) GetNodeResourceInfo(ctx context.Context, nodename string, workloads []*types.Workload, fix bool) (*types.Resources, *types.Resources, []string, error) { - nodeCapacity := &types.Resources{} - nodeUsage := &types.Resources{} +func (m Manager) GetNodeResourceInfo(ctx context.Context, nodename string, workloads []*types.Workload, fix bool) (types.Resources, types.Resources, []string, error) { + nodeCapacity := types.Resources{} + nodeUsage := types.Resources{} resourceDiffs := []string{} ps := m.plugins @@ -179,10 +179,10 @@ func (m Manager) GetNodeResourceInfo(ctx context.Context, nodename string, workl var resp *plugintypes.GetNodeResourceInfoResponse var err error - wrks := []*plugintypes.WorkloadResource{} + wrks := []plugintypes.WorkloadResource{} for _, wrk := range workloads { - r := (*wrk.Resources)[plugin.Name()] + r := wrk.Resources[plugin.Name()] wrks = append(wrks, r) } @@ -202,8 +202,8 @@ func (m Manager) GetNodeResourceInfo(ctx context.Context, nodename string, workl } for plugin, resp := range resps { - (*nodeCapacity)[plugin.Name()] = resp.Capacity - (*nodeUsage)[plugin.Name()] = resp.Usage + nodeCapacity[plugin.Name()] = resp.Capacity + nodeUsage[plugin.Name()] = resp.Usage resourceDiffs = append(resourceDiffs, resp.Diffs...) } @@ -211,34 +211,34 @@ func (m Manager) GetNodeResourceInfo(ctx context.Context, nodename string, workl } // SetNodeResourceUsage . -func (m Manager) SetNodeResourceUsage(ctx context.Context, nodename string, nodeResource *types.Resources, nodeResourceRequest *types.Resources, workloadsResource []*types.Resources, delta bool, incr bool) (*types.Resources, *types.Resources, error) { +func (m Manager) SetNodeResourceUsage(ctx context.Context, nodename string, nodeResource types.Resources, nodeResourceRequest types.Resources, workloadsResource []types.Resources, delta bool, incr bool) (types.Resources, types.Resources, error) { logger := log.WithFunc("resource.cobalt.SetNodeResourceUsage") - wrksResource := map[string][]*types.RawParams{} + wrksResource := map[string][]types.RawParams{} rollbackPlugins := []plugins.Plugin{} - before := &types.Resources{} - after := &types.Resources{} + before := types.Resources{} + after := types.Resources{} return before, after, utils.PCR(ctx, func(ctx context.Context) error { // prepare: covert []types.Resources to map[plugin]types.Resources // [{"cpu-plugin": {"cpu": 1}}, {"cpu-plugin": {"cpu": 1}}] -> {"cpu-plugin": [{"cpu": 1}, {"cpu": 1}]} for _, workloadResource := range workloadsResource { - for plugin, params := range *workloadResource { + for plugin, params := range workloadResource { if _, ok := wrksResource[plugin]; !ok { - wrksResource[plugin] = []*types.RawParams{} + wrksResource[plugin] = []types.RawParams{} } wrksResource[plugin] = append(wrksResource[plugin], params) } } if nodeResourceRequest == nil { - nodeResourceRequest = &types.Resources{} + nodeResourceRequest = types.Resources{} } return nil }, // 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) + 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()) } @@ -248,8 +248,8 @@ func (m Manager) SetNodeResourceUsage(ctx context.Context, nodename string, node if err != nil { for plugin, resp := range resps { rollbackPlugins = append(rollbackPlugins, plugin) - (*before)[plugin.Name()] = resp.Before - (*after)[plugin.Name()] = resp.After + before[plugin.Name()] = resp.Before + after[plugin.Name()] = resp.After } logger.Errorf(ctx, err, "failed to set node resource for node %+v", nodename) } @@ -258,7 +258,7 @@ func (m Manager) SetNodeResourceUsage(ctx context.Context, nodename string, node // rollback: set the rollback resource args in reverse func(ctx context.Context) error { _, err := call(ctx, rollbackPlugins, func(plugin plugins.Plugin) (*plugintypes.SetNodeResourceUsageResponse, error) { - resp, err := plugin.SetNodeResourceUsage(ctx, nodename, (*before)[plugin.Name()], nil, nil, false, false) + resp, err := plugin.SetNodeResourceUsage(ctx, nodename, before[plugin.Name()], nil, nil, false, false) if err != nil { logger.Errorf(ctx, err, "node %+v plugin %+v failed to rollback node resource", nodename, plugin.Name()) } @@ -273,14 +273,14 @@ func (m Manager) SetNodeResourceUsage(ctx context.Context, nodename string, node // GetNodesDeployCapacity returns available nodes which meet all the requirements // the caller should require locks // pure calculation -func (m Manager) GetNodesDeployCapacity(ctx context.Context, nodenames []string, opts *types.Resources) (map[string]*plugintypes.NodeDeployCapacity, int, error) { +func (m Manager) GetNodesDeployCapacity(ctx context.Context, nodenames []string, opts types.Resources) (map[string]*plugintypes.NodeDeployCapacity, int, error) { logger := log.WithFunc("resource.cobalt.GetNodesDeployCapacity") var resp map[string]*plugintypes.NodeDeployCapacity resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.GetNodesDeployCapacityResponse, error) { - resp, err := plugin.GetNodesDeployCapacity(ctx, nodenames, (*opts)[plugin.Name()]) + resp, err := plugin.GetNodesDeployCapacity(ctx, nodenames, opts[plugin.Name()]) if err != nil { - logger.Errorf(ctx, err, "plugin %+v failed to get available nodenames, request %+v", plugin.Name(), (*opts)[plugin.Name()]) + logger.Errorf(ctx, err, "plugin %+v failed to get available nodenames, request %+v", plugin.Name(), opts[plugin.Name()]) } return resp, err }) @@ -310,24 +310,24 @@ func (m Manager) GetNodesDeployCapacity(ctx context.Context, nodenames []string, // SetNodeResourceCapacity updates node resource capacity // receives resource options instead of resource args -func (m Manager) SetNodeResourceCapacity(ctx context.Context, nodename string, nodeResource *types.Resources, nodeResourceRequest *types.Resources, delta bool, incr bool) (*types.Resources, *types.Resources, error) { +func (m Manager) SetNodeResourceCapacity(ctx context.Context, nodename string, nodeResource types.Resources, nodeResourceRequest types.Resources, delta bool, incr bool) (types.Resources, types.Resources, error) { logger := log.WithFunc("resource.cobalt.SetNodeResourceCapacity").WithField("node", nodename) rollbackPlugins := []plugins.Plugin{} - before := &types.Resources{} - after := &types.Resources{} + before := types.Resources{} + after := types.Resources{} return before, after, utils.PCR(ctx, func(ctx context.Context) error { if nodeResourceRequest == nil { - nodeResourceRequest = &types.Resources{} + nodeResourceRequest = types.Resources{} } return nil }, // 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) { - resp, err := plugin.SetNodeResourceCapacity(ctx, nodename, (*nodeResource)[plugin.Name()], (*nodeResourceRequest)[plugin.Name()], delta, incr) + 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()) } @@ -337,8 +337,8 @@ func (m Manager) SetNodeResourceCapacity(ctx context.Context, nodename string, n if err != nil { for plugin, resp := range resps { rollbackPlugins = append(rollbackPlugins, plugin) - (*before)[plugin.Name()] = resp.Before - (*after)[plugin.Name()] = resp.After + before[plugin.Name()] = resp.Before + after[plugin.Name()] = resp.After } logger.Errorf(ctx, err, "failed to set node resource for node %+v", nodename) return err @@ -348,7 +348,7 @@ func (m Manager) SetNodeResourceCapacity(ctx context.Context, nodename string, n // rollback: set the rollback resource args in reverse func(ctx context.Context) error { _, err := call(ctx, rollbackPlugins, func(plugin plugins.Plugin) (*plugintypes.SetNodeResourceCapacityResponse, error) { - resp, err := plugin.SetNodeResourceCapacity(ctx, nodename, nil, (*before)[plugin.Name()], false, false) + resp, err := plugin.SetNodeResourceCapacity(ctx, nodename, nil, before[plugin.Name()], false, false) if err != nil { logger.Errorf(ctx, err, "node %+v plugin %+v failed to rollback node resource capacity", nodename, plugin.Name()) } diff --git a/resource/cobalt/realloc.go b/resource/cobalt/realloc.go index ae6e9734d..9d558495d 100644 --- a/resource/cobalt/realloc.go +++ b/resource/cobalt/realloc.go @@ -11,17 +11,17 @@ import ( ) // Realloc . -func (m Manager) Realloc(ctx context.Context, nodename string, nodeResource *types.Resources, opts *types.Resources) (*types.Resources, *types.Resources, *types.Resources, error) { +func (m Manager) Realloc(ctx context.Context, nodename string, nodeResource types.Resources, opts types.Resources) (types.Resources, types.Resources, types.Resources, error) { logger := log.WithFunc("resource.cobalt.Realloc").WithField("node", nodename) - engineParams := &types.Resources{} - deltaResources := &types.Resources{} - workloadResource := &types.Resources{} + engineParams := types.Resources{} + deltaResources := types.Resources{} + workloadResource := types.Resources{} return engineParams, deltaResources, workloadResource, utils.PCR(ctx, // prepare: calculate engine args, delta node resource args and final workload resource args func(ctx context.Context) error { resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.CalculateReallocResponse, error) { - resp, err := plugin.CalculateRealloc(ctx, nodename, (*nodeResource)[plugin.Name()], (*opts)[plugin.Name()]) + resp, err := plugin.CalculateRealloc(ctx, nodename, nodeResource[plugin.Name()], opts[plugin.Name()]) if err != nil { logger.Errorf(ctx, err, "plugin %+v failed to calculate realloc args", plugin.Name()) } @@ -33,20 +33,20 @@ func (m Manager) Realloc(ctx context.Context, nodename string, nodeResource *typ } for plugin, resp := range resps { - (*engineParams)[plugin.Name()] = resp.EngineParams + engineParams[plugin.Name()] = resp.EngineParams // if engineParams, err = m.mergeEngineParams(ctx, engineParams, resp.EngineParams); err != nil { // logger.Error(ctx, err, "invalid engine args") // return err // } - (*deltaResources)[plugin.Name()] = resp.DeltaResource - (*workloadResource)[plugin.Name()] = resp.WorkloadResource + deltaResources[plugin.Name()] = resp.DeltaResource + workloadResource[plugin.Name()] = resp.WorkloadResource } return nil }, // commit: update node resource func(ctx context.Context) error { // TODO 存在问题??3个参数是完整的变化,差值变化,按照 workloads 的变化 - if _, _, err := m.SetNodeResourceUsage(ctx, nodename, nil, nil, []*types.Resources{workloadResource}, true, plugins.Incr); err != nil { + if _, _, err := m.SetNodeResourceUsage(ctx, nodename, nil, nil, []types.Resources{workloadResource}, true, plugins.Incr); err != nil { logger.Error(ctx, err, "failed to update nodename resource") return err } @@ -61,7 +61,7 @@ func (m Manager) Realloc(ctx context.Context, nodename string, nodeResource *typ } // RollbackRealloc . -func (m Manager) RollbackRealloc(ctx context.Context, nodename string, workloadParams *types.Resources) error { - _, _, err := m.SetNodeResourceUsage(ctx, nodename, nil, nil, []*types.Resources{workloadParams}, true, plugins.Decr) +func (m Manager) RollbackRealloc(ctx context.Context, nodename string, workloadParams types.Resources) error { + _, _, err := m.SetNodeResourceUsage(ctx, nodename, nil, nil, []types.Resources{workloadParams}, true, plugins.Decr) return err } diff --git a/resource/cobalt/remap.go b/resource/cobalt/remap.go index c231f6e02..c6eecff37 100644 --- a/resource/cobalt/remap.go +++ b/resource/cobalt/remap.go @@ -11,13 +11,13 @@ import ( // Remap remaps resource and returns engine args for workloads. format: {"workload-1": {"cpus": ["1-3"]}} // remap doesn't change resource args -func (m Manager) Remap(ctx context.Context, nodename string, workloads []*types.Workload) (*types.Resources, error) { +func (m Manager) Remap(ctx context.Context, nodename string, workloads []*types.Workload) (types.Resources, error) { logger := log.WithFunc("resource.cobalt.GetRemapArgs").WithField("node", nodename) // call plugins to remap resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.CalculateRemapResponse, error) { - workloadsResourceMap := map[string]*plugintypes.WorkloadResource{} + workloadsResourceMap := map[string]plugintypes.WorkloadResource{} for _, workload := range workloads { - workloadsResourceMap[workload.ID] = (*workload.Resources)[plugin.Name()] + workloadsResourceMap[workload.ID] = workload.Resources[plugin.Name()] } resp, err := plugin.CalculateRemap(ctx, nodename, workloadsResourceMap) if err != nil { @@ -29,20 +29,20 @@ func (m Manager) Remap(ctx context.Context, nodename string, workloads []*types. return nil, err } - enginesParams := &types.Resources{} + enginesParams := types.Resources{} // merge engine args for _, resp := range resps { for workloadID, engineParams := range resp.EngineParamsMap { - if _, ok := (*enginesParams)[workloadID]; !ok { - (*enginesParams)[workloadID] = &types.RawParams{} + if _, ok := enginesParams[workloadID]; !ok { + enginesParams[workloadID] = types.RawParams{} } - v := (*enginesParams)[workloadID] + v := enginesParams[workloadID] vMerged, err := m.mergeEngineParams(ctx, v, engineParams) if err != nil { logger.Error(ctx, err, "invalid engine args") return nil, err } - (*enginesParams)[workloadID] = vMerged + enginesParams[workloadID] = vMerged } } @@ -51,23 +51,23 @@ func (m Manager) Remap(ctx context.Context, nodename string, workloads []*types. // mergeEngineParams e.g. {"file": ["/bin/sh:/bin/sh"], "cpu": 1.2, "cpu-bind": true} + {"file": ["/bin/ls:/bin/ls"], "mem": "1PB"} // => {"file": ["/bin/sh:/bin/sh", "/bin/ls:/bin/ls"], "cpu": 1.2, "cpu-bind": true, "mem": "1PB"} -func (m Manager) mergeEngineParams(ctx context.Context, m1 *plugintypes.EngineParams, m2 *plugintypes.EngineParams) (*plugintypes.EngineParams, error) { - r := &plugintypes.EngineParams{} - for key, value := range *m1 { - (*r)[key] = value +func (m Manager) mergeEngineParams(ctx context.Context, m1 plugintypes.EngineParams, m2 plugintypes.EngineParams) (plugintypes.EngineParams, error) { + r := plugintypes.EngineParams{} + for key, value := range m1 { + r[key] = value } - for key, value := range *m2 { - if _, ok := (*r)[key]; ok { + for key, value := range m2 { + if _, ok := r[key]; ok { // only two string slices can be merged - _, ok1 := (*r)[key].([]string) + _, ok1 := r[key].([]string) _, ok2 := value.([]string) if !ok1 || !ok2 { - log.WithFunc("resource.cobalt.mergeEngineParams").Errorf(ctx, types.ErrInvalidEngineArgs, "only two string slices can be merged! error key %+v, m1[key] = %+v, m2[key] = %+v", key, (*m1)[key], (*m2)[key]) + log.WithFunc("resource.cobalt.mergeEngineParams").Errorf(ctx, types.ErrInvalidEngineArgs, "only two string slices can be merged! error key %+v, m1[key] = %+v, m2[key] = %+v", key, m1[key], m2[key]) return nil, types.ErrInvalidEngineArgs } - (*r)[key] = append((*r)[key].([]string), value.([]string)...) + r[key] = append(r[key].([]string), value.([]string)...) } else { - (*r)[key] = value + r[key] = value } } return r, nil diff --git a/resource/manager.go b/resource/manager.go index 6f522c3f6..afba868d4 100644 --- a/resource/manager.go +++ b/resource/manager.go @@ -11,19 +11,19 @@ import ( // Manager indicate manages // coretypes --> manager to rawparams --> plugins types type Manager interface { - AddNode(context.Context, string, *types.Resources, *enginetypes.Info) (*types.Resources, error) + AddNode(context.Context, string, types.Resources, *enginetypes.Info) (types.Resources, error) RemoveNode(context.Context, string) error - GetNodesDeployCapacity(context.Context, []string, *types.Resources) (map[string]*plugintypes.NodeDeployCapacity, int, error) - SetNodeResourceCapacity(context.Context, string, *types.Resources, *types.Resources, bool, bool) (*types.Resources, *types.Resources, error) - SetNodeResourceUsage(context.Context, string, *types.Resources, *types.Resources, []*types.Resources, bool, bool) (*types.Resources, *types.Resources, error) - GetNodeResourceInfo(context.Context, string, []*types.Workload, bool) (*types.Resources, *types.Resources, []string, error) + GetNodesDeployCapacity(context.Context, []string, types.Resources) (map[string]*plugintypes.NodeDeployCapacity, int, error) + SetNodeResourceCapacity(context.Context, string, types.Resources, types.Resources, bool, bool) (types.Resources, types.Resources, error) + SetNodeResourceUsage(context.Context, string, types.Resources, types.Resources, []types.Resources, bool, bool) (types.Resources, types.Resources, error) + GetNodeResourceInfo(context.Context, string, []*types.Workload, bool) (types.Resources, types.Resources, []string, error) GetMostIdleNode(context.Context, []string) (string, error) - Alloc(context.Context, string, int, *types.Resources) ([]*types.Resources, []*types.Resources, error) - RollbackAlloc(context.Context, string, []*types.Resources) error - Realloc(context.Context, string, *types.Resources, *types.Resources) (*types.Resources, *types.Resources, *types.Resources, error) - RollbackRealloc(context.Context, string, *types.Resources) error - Remap(context.Context, string, []*types.Workload) (*types.Resources, error) + Alloc(context.Context, string, int, types.Resources) ([]types.Resources, []types.Resources, error) + RollbackAlloc(context.Context, string, []types.Resources) error + Realloc(context.Context, string, types.Resources, types.Resources) (types.Resources, types.Resources, types.Resources, error) + RollbackRealloc(context.Context, string, types.Resources) error + Remap(context.Context, string, []*types.Workload) (types.Resources, error) GetNodeMetrics(context.Context, *types.Node) ([]*plugintypes.Metrics, error) GetMetricsDescription(context.Context) ([]*plugintypes.MetricsDescription, error) diff --git a/resource/mocks/Manager.go b/resource/mocks/Manager.go index b0d2241fa..bd7c0a9a2 100644 --- a/resource/mocks/Manager.go +++ b/resource/mocks/Manager.go @@ -19,20 +19,20 @@ type Manager struct { } // AddNode provides a mock function with given fields: _a0, _a1, _a2, _a3 -func (_m *Manager) AddNode(_a0 context.Context, _a1 string, _a2 *types.Resources, _a3 *enginetypes.Info) (*types.Resources, error) { +func (_m *Manager) AddNode(_a0 context.Context, _a1 string, _a2 types.Resources, _a3 *enginetypes.Info) (types.Resources, error) { ret := _m.Called(_a0, _a1, _a2, _a3) - var r0 *types.Resources - if rf, ok := ret.Get(0).(func(context.Context, string, *types.Resources, *enginetypes.Info) *types.Resources); ok { + var r0 types.Resources + if rf, ok := ret.Get(0).(func(context.Context, string, types.Resources, *enginetypes.Info) types.Resources); ok { r0 = rf(_a0, _a1, _a2, _a3) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Resources) + r0 = ret.Get(0).(types.Resources) } } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *types.Resources, *enginetypes.Info) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, types.Resources, *enginetypes.Info) error); ok { r1 = rf(_a0, _a1, _a2, _a3) } else { r1 = ret.Error(1) @@ -42,29 +42,29 @@ func (_m *Manager) AddNode(_a0 context.Context, _a1 string, _a2 *types.Resources } // Alloc provides a mock function with given fields: _a0, _a1, _a2, _a3 -func (_m *Manager) Alloc(_a0 context.Context, _a1 string, _a2 int, _a3 *types.Resources) ([]*types.Resources, []*types.Resources, error) { +func (_m *Manager) Alloc(_a0 context.Context, _a1 string, _a2 int, _a3 types.Resources) ([]types.Resources, []types.Resources, error) { ret := _m.Called(_a0, _a1, _a2, _a3) - var r0 []*types.Resources - if rf, ok := ret.Get(0).(func(context.Context, string, int, *types.Resources) []*types.Resources); ok { + var r0 []types.Resources + if rf, ok := ret.Get(0).(func(context.Context, string, int, types.Resources) []types.Resources); ok { r0 = rf(_a0, _a1, _a2, _a3) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*types.Resources) + r0 = ret.Get(0).([]types.Resources) } } - var r1 []*types.Resources - if rf, ok := ret.Get(1).(func(context.Context, string, int, *types.Resources) []*types.Resources); ok { + var r1 []types.Resources + if rf, ok := ret.Get(1).(func(context.Context, string, int, types.Resources) []types.Resources); ok { r1 = rf(_a0, _a1, _a2, _a3) } else { if ret.Get(1) != nil { - r1 = ret.Get(1).([]*types.Resources) + r1 = ret.Get(1).([]types.Resources) } } var r2 error - if rf, ok := ret.Get(2).(func(context.Context, string, int, *types.Resources) error); ok { + if rf, ok := ret.Get(2).(func(context.Context, string, int, types.Resources) error); ok { r2 = rf(_a0, _a1, _a2, _a3) } else { r2 = ret.Error(2) @@ -141,24 +141,24 @@ func (_m *Manager) GetNodeMetrics(_a0 context.Context, _a1 *types.Node) ([]*plug } // GetNodeResourceInfo provides a mock function with given fields: _a0, _a1, _a2, _a3 -func (_m *Manager) GetNodeResourceInfo(_a0 context.Context, _a1 string, _a2 []*types.Workload, _a3 bool) (*types.Resources, *types.Resources, []string, error) { +func (_m *Manager) GetNodeResourceInfo(_a0 context.Context, _a1 string, _a2 []*types.Workload, _a3 bool) (types.Resources, types.Resources, []string, error) { ret := _m.Called(_a0, _a1, _a2, _a3) - var r0 *types.Resources - if rf, ok := ret.Get(0).(func(context.Context, string, []*types.Workload, bool) *types.Resources); ok { + var r0 types.Resources + if rf, ok := ret.Get(0).(func(context.Context, string, []*types.Workload, bool) types.Resources); ok { r0 = rf(_a0, _a1, _a2, _a3) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Resources) + r0 = ret.Get(0).(types.Resources) } } - var r1 *types.Resources - if rf, ok := ret.Get(1).(func(context.Context, string, []*types.Workload, bool) *types.Resources); ok { + var r1 types.Resources + if rf, ok := ret.Get(1).(func(context.Context, string, []*types.Workload, bool) types.Resources); ok { r1 = rf(_a0, _a1, _a2, _a3) } else { if ret.Get(1) != nil { - r1 = ret.Get(1).(*types.Resources) + r1 = ret.Get(1).(types.Resources) } } @@ -182,11 +182,11 @@ func (_m *Manager) GetNodeResourceInfo(_a0 context.Context, _a1 string, _a2 []*t } // GetNodesDeployCapacity provides a mock function with given fields: _a0, _a1, _a2 -func (_m *Manager) GetNodesDeployCapacity(_a0 context.Context, _a1 []string, _a2 *types.Resources) (map[string]*pluginstypes.NodeDeployCapacity, int, error) { +func (_m *Manager) GetNodesDeployCapacity(_a0 context.Context, _a1 []string, _a2 types.Resources) (map[string]*pluginstypes.NodeDeployCapacity, int, error) { ret := _m.Called(_a0, _a1, _a2) var r0 map[string]*pluginstypes.NodeDeployCapacity - if rf, ok := ret.Get(0).(func(context.Context, []string, *types.Resources) map[string]*pluginstypes.NodeDeployCapacity); ok { + if rf, ok := ret.Get(0).(func(context.Context, []string, types.Resources) map[string]*pluginstypes.NodeDeployCapacity); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { @@ -195,14 +195,14 @@ func (_m *Manager) GetNodesDeployCapacity(_a0 context.Context, _a1 []string, _a2 } var r1 int - if rf, ok := ret.Get(1).(func(context.Context, []string, *types.Resources) int); ok { + if rf, ok := ret.Get(1).(func(context.Context, []string, types.Resources) int); ok { r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Get(1).(int) } var r2 error - if rf, ok := ret.Get(2).(func(context.Context, []string, *types.Resources) error); ok { + if rf, ok := ret.Get(2).(func(context.Context, []string, types.Resources) error); ok { r2 = rf(_a0, _a1, _a2) } else { r2 = ret.Error(2) @@ -212,38 +212,38 @@ func (_m *Manager) GetNodesDeployCapacity(_a0 context.Context, _a1 []string, _a2 } // Realloc provides a mock function with given fields: _a0, _a1, _a2, _a3 -func (_m *Manager) Realloc(_a0 context.Context, _a1 string, _a2 *types.Resources, _a3 *types.Resources) (*types.Resources, *types.Resources, *types.Resources, error) { +func (_m *Manager) Realloc(_a0 context.Context, _a1 string, _a2 types.Resources, _a3 types.Resources) (types.Resources, types.Resources, types.Resources, error) { ret := _m.Called(_a0, _a1, _a2, _a3) - var r0 *types.Resources - if rf, ok := ret.Get(0).(func(context.Context, string, *types.Resources, *types.Resources) *types.Resources); ok { + var r0 types.Resources + if rf, ok := ret.Get(0).(func(context.Context, string, types.Resources, types.Resources) types.Resources); ok { r0 = rf(_a0, _a1, _a2, _a3) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Resources) + r0 = ret.Get(0).(types.Resources) } } - var r1 *types.Resources - if rf, ok := ret.Get(1).(func(context.Context, string, *types.Resources, *types.Resources) *types.Resources); ok { + var r1 types.Resources + if rf, ok := ret.Get(1).(func(context.Context, string, types.Resources, types.Resources) types.Resources); ok { r1 = rf(_a0, _a1, _a2, _a3) } else { if ret.Get(1) != nil { - r1 = ret.Get(1).(*types.Resources) + r1 = ret.Get(1).(types.Resources) } } - var r2 *types.Resources - if rf, ok := ret.Get(2).(func(context.Context, string, *types.Resources, *types.Resources) *types.Resources); ok { + var r2 types.Resources + if rf, ok := ret.Get(2).(func(context.Context, string, types.Resources, types.Resources) types.Resources); ok { r2 = rf(_a0, _a1, _a2, _a3) } else { if ret.Get(2) != nil { - r2 = ret.Get(2).(*types.Resources) + r2 = ret.Get(2).(types.Resources) } } var r3 error - if rf, ok := ret.Get(3).(func(context.Context, string, *types.Resources, *types.Resources) error); ok { + if rf, ok := ret.Get(3).(func(context.Context, string, types.Resources, types.Resources) error); ok { r3 = rf(_a0, _a1, _a2, _a3) } else { r3 = ret.Error(3) @@ -253,15 +253,15 @@ func (_m *Manager) Realloc(_a0 context.Context, _a1 string, _a2 *types.Resources } // Remap provides a mock function with given fields: _a0, _a1, _a2 -func (_m *Manager) Remap(_a0 context.Context, _a1 string, _a2 []*types.Workload) (*types.Resources, error) { +func (_m *Manager) Remap(_a0 context.Context, _a1 string, _a2 []*types.Workload) (types.Resources, error) { ret := _m.Called(_a0, _a1, _a2) - var r0 *types.Resources - if rf, ok := ret.Get(0).(func(context.Context, string, []*types.Workload) *types.Resources); ok { + var r0 types.Resources + if rf, ok := ret.Get(0).(func(context.Context, string, []*types.Workload) types.Resources); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Resources) + r0 = ret.Get(0).(types.Resources) } } @@ -290,11 +290,11 @@ func (_m *Manager) RemoveNode(_a0 context.Context, _a1 string) error { } // RollbackAlloc provides a mock function with given fields: _a0, _a1, _a2 -func (_m *Manager) RollbackAlloc(_a0 context.Context, _a1 string, _a2 []*types.Resources) error { +func (_m *Manager) RollbackAlloc(_a0 context.Context, _a1 string, _a2 []types.Resources) error { ret := _m.Called(_a0, _a1, _a2) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, []*types.Resources) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, []types.Resources) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -304,11 +304,11 @@ func (_m *Manager) RollbackAlloc(_a0 context.Context, _a1 string, _a2 []*types.R } // RollbackRealloc provides a mock function with given fields: _a0, _a1, _a2 -func (_m *Manager) RollbackRealloc(_a0 context.Context, _a1 string, _a2 *types.Resources) error { +func (_m *Manager) RollbackRealloc(_a0 context.Context, _a1 string, _a2 types.Resources) error { ret := _m.Called(_a0, _a1, _a2) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, *types.Resources) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, types.Resources) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -318,29 +318,29 @@ func (_m *Manager) RollbackRealloc(_a0 context.Context, _a1 string, _a2 *types.R } // SetNodeResourceCapacity provides a mock function with given fields: _a0, _a1, _a2, _a3, _a4, _a5 -func (_m *Manager) SetNodeResourceCapacity(_a0 context.Context, _a1 string, _a2 *types.Resources, _a3 *types.Resources, _a4 bool, _a5 bool) (*types.Resources, *types.Resources, error) { +func (_m *Manager) SetNodeResourceCapacity(_a0 context.Context, _a1 string, _a2 types.Resources, _a3 types.Resources, _a4 bool, _a5 bool) (types.Resources, types.Resources, error) { ret := _m.Called(_a0, _a1, _a2, _a3, _a4, _a5) - var r0 *types.Resources - if rf, ok := ret.Get(0).(func(context.Context, string, *types.Resources, *types.Resources, bool, bool) *types.Resources); ok { + var r0 types.Resources + if rf, ok := ret.Get(0).(func(context.Context, string, types.Resources, types.Resources, bool, bool) types.Resources); ok { r0 = rf(_a0, _a1, _a2, _a3, _a4, _a5) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Resources) + r0 = ret.Get(0).(types.Resources) } } - var r1 *types.Resources - if rf, ok := ret.Get(1).(func(context.Context, string, *types.Resources, *types.Resources, bool, bool) *types.Resources); ok { + var r1 types.Resources + if rf, ok := ret.Get(1).(func(context.Context, string, types.Resources, types.Resources, bool, bool) types.Resources); ok { r1 = rf(_a0, _a1, _a2, _a3, _a4, _a5) } else { if ret.Get(1) != nil { - r1 = ret.Get(1).(*types.Resources) + r1 = ret.Get(1).(types.Resources) } } var r2 error - if rf, ok := ret.Get(2).(func(context.Context, string, *types.Resources, *types.Resources, bool, bool) error); ok { + if rf, ok := ret.Get(2).(func(context.Context, string, types.Resources, types.Resources, bool, bool) error); ok { r2 = rf(_a0, _a1, _a2, _a3, _a4, _a5) } else { r2 = ret.Error(2) @@ -350,29 +350,29 @@ func (_m *Manager) SetNodeResourceCapacity(_a0 context.Context, _a1 string, _a2 } // SetNodeResourceUsage provides a mock function with given fields: _a0, _a1, _a2, _a3, _a4, _a5, _a6 -func (_m *Manager) SetNodeResourceUsage(_a0 context.Context, _a1 string, _a2 *types.Resources, _a3 *types.Resources, _a4 []*types.Resources, _a5 bool, _a6 bool) (*types.Resources, *types.Resources, error) { +func (_m *Manager) SetNodeResourceUsage(_a0 context.Context, _a1 string, _a2 types.Resources, _a3 types.Resources, _a4 []types.Resources, _a5 bool, _a6 bool) (types.Resources, types.Resources, error) { ret := _m.Called(_a0, _a1, _a2, _a3, _a4, _a5, _a6) - var r0 *types.Resources - if rf, ok := ret.Get(0).(func(context.Context, string, *types.Resources, *types.Resources, []*types.Resources, bool, bool) *types.Resources); ok { + var r0 types.Resources + if rf, ok := ret.Get(0).(func(context.Context, string, types.Resources, types.Resources, []types.Resources, bool, bool) types.Resources); ok { r0 = rf(_a0, _a1, _a2, _a3, _a4, _a5, _a6) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Resources) + r0 = ret.Get(0).(types.Resources) } } - var r1 *types.Resources - if rf, ok := ret.Get(1).(func(context.Context, string, *types.Resources, *types.Resources, []*types.Resources, bool, bool) *types.Resources); ok { + var r1 types.Resources + if rf, ok := ret.Get(1).(func(context.Context, string, types.Resources, types.Resources, []types.Resources, bool, bool) types.Resources); ok { r1 = rf(_a0, _a1, _a2, _a3, _a4, _a5, _a6) } else { if ret.Get(1) != nil { - r1 = ret.Get(1).(*types.Resources) + r1 = ret.Get(1).(types.Resources) } } var r2 error - if rf, ok := ret.Get(2).(func(context.Context, string, *types.Resources, *types.Resources, []*types.Resources, bool, bool) error); ok { + if rf, ok := ret.Get(2).(func(context.Context, string, types.Resources, types.Resources, []types.Resources, bool, bool) error); ok { r2 = rf(_a0, _a1, _a2, _a3, _a4, _a5, _a6) } else { r2 = ret.Error(2) diff --git a/resource/plugins/binary/calculate.go b/resource/plugins/binary/calculate.go index 4665ab15c..d03de0f4e 100644 --- a/resource/plugins/binary/calculate.go +++ b/resource/plugins/binary/calculate.go @@ -8,7 +8,7 @@ import ( ) // CalculateDeploy . -func (p Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCount int, resourceRequest *plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateDeployResponse, error) { +func (p Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCount int, resourceRequest plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateDeployResponse, error) { req := &binarytypes.CalculateDeployRequest{ Nodename: nodename, DeployCount: deployCount, @@ -19,7 +19,7 @@ func (p Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCoun } // CalculateRealloc . -func (p Plugin) CalculateRealloc(ctx context.Context, nodename string, resource *plugintypes.WorkloadResource, resourceRequest *plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateReallocResponse, error) { +func (p Plugin) CalculateRealloc(ctx context.Context, nodename string, resource plugintypes.WorkloadResource, resourceRequest plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateReallocResponse, error) { req := &binarytypes.CalculateReallocRequest{ Nodename: nodename, WorkloadResource: resource, @@ -30,7 +30,7 @@ func (p Plugin) CalculateRealloc(ctx context.Context, nodename string, resource } // CalculateRemap . -func (p Plugin) CalculateRemap(ctx context.Context, nodename string, workloadsResource map[string]*plugintypes.WorkloadResource) (*plugintypes.CalculateRemapResponse, error) { +func (p Plugin) CalculateRemap(ctx context.Context, nodename string, workloadsResource map[string]plugintypes.WorkloadResource) (*plugintypes.CalculateRemapResponse, error) { req := &binarytypes.CalculateRemapRequest{ Nodename: nodename, WorkloadsResource: workloadsResource, diff --git a/resource/plugins/binary/node.go b/resource/plugins/binary/node.go index 7124686d0..8b141a4df 100644 --- a/resource/plugins/binary/node.go +++ b/resource/plugins/binary/node.go @@ -9,7 +9,7 @@ import ( ) // AddNode . -func (p Plugin) AddNode(ctx context.Context, nodename string, resource *plugintypes.NodeResourceRequest, info *enginetypes.Info) (*plugintypes.AddNodeResponse, error) { +func (p Plugin) AddNode(ctx context.Context, nodename string, resource plugintypes.NodeResourceRequest, info *enginetypes.Info) (*plugintypes.AddNodeResponse, error) { req := &binarytypes.AddNodeRequest{ Nodename: nodename, Resource: resource, @@ -29,7 +29,7 @@ func (p Plugin) RemoveNode(ctx context.Context, nodename string) (*plugintypes.R } // GetNodesDeployCapacity . -func (p Plugin) GetNodesDeployCapacity(ctx context.Context, nodenames []string, resource *plugintypes.WorkloadResourceRequest) (*plugintypes.GetNodesDeployCapacityResponse, error) { +func (p Plugin) GetNodesDeployCapacity(ctx context.Context, nodenames []string, resource plugintypes.WorkloadResourceRequest) (*plugintypes.GetNodesDeployCapacityResponse, error) { req := &binarytypes.GetNodesDeployCapacityRequest{ Nodenames: nodenames, WorkloadResource: resource, @@ -39,7 +39,7 @@ func (p Plugin) GetNodesDeployCapacity(ctx context.Context, nodenames []string, } // SetNodeResourceCapacity . -func (p Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, resource *plugintypes.NodeResource, resourceRequest *plugintypes.NodeResourceRequest, delta bool, incr bool) (*plugintypes.SetNodeResourceCapacityResponse, error) { +func (p Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, resource plugintypes.NodeResource, resourceRequest plugintypes.NodeResourceRequest, delta bool, incr bool) (*plugintypes.SetNodeResourceCapacityResponse, error) { req := &binarytypes.SetNodeResourceCapacityRequest{ Nodename: nodename, Resource: resource, @@ -53,12 +53,12 @@ func (p Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, re } // GetNodeResourceInfo . -func (p Plugin) GetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []*plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) { +func (p Plugin) GetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) { return p.doGetNodeResourceInfo(ctx, nodename, workloadsResource, false) // Get do not fix the resource } // SetNodeResourceInfo . -func (p Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capacity *plugintypes.NodeResource, usage *plugintypes.NodeResource) (*plugintypes.SetNodeResourceInfoResponse, error) { +func (p Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capacity plugintypes.NodeResource, usage plugintypes.NodeResource) (*plugintypes.SetNodeResourceInfoResponse, error) { req := &binarytypes.SetNodeResourceInfoRequest{ Nodename: nodename, Capacity: capacity, @@ -70,7 +70,7 @@ func (p Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capaci } // SetNodeResourceUsage . -func (p Plugin) SetNodeResourceUsage(ctx context.Context, nodename string, resource *plugintypes.NodeResource, resourceRequest *plugintypes.NodeResourceRequest, workloadsResource []*plugintypes.WorkloadResource, delta bool, incr bool) (*plugintypes.SetNodeResourceUsageResponse, error) { +func (p Plugin) SetNodeResourceUsage(ctx context.Context, nodename string, resource plugintypes.NodeResource, resourceRequest plugintypes.NodeResourceRequest, workloadsResource []plugintypes.WorkloadResource, delta bool, incr bool) (*plugintypes.SetNodeResourceUsageResponse, error) { req := &binarytypes.SetNodeResourceUsageRequest{ Nodename: nodename, WorkloadsResource: workloadsResource, @@ -94,11 +94,11 @@ func (p Plugin) GetMostIdleNode(ctx context.Context, nodenames []string) (*plugi } // FixNodeResource . -func (p Plugin) FixNodeResource(ctx context.Context, nodename string, workloadsResource []*plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) { +func (p Plugin) FixNodeResource(ctx context.Context, nodename string, workloadsResource []plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) { return p.doGetNodeResourceInfo(ctx, nodename, workloadsResource, true) } -func (p Plugin) doGetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []*plugintypes.WorkloadResource, fix bool) (*plugintypes.GetNodeResourceInfoResponse, error) { +func (p Plugin) doGetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []plugintypes.WorkloadResource, fix bool) (*plugintypes.GetNodeResourceInfoResponse, error) { req := &binarytypes.GetNodeResourceInfoRequest{ Nodename: nodename, WorkloadsResource: workloadsResource, diff --git a/resource/plugins/binary/types/calculate.go b/resource/plugins/binary/types/calculate.go index 1de6f33e2..47ea477b1 100644 --- a/resource/plugins/binary/types/calculate.go +++ b/resource/plugins/binary/types/calculate.go @@ -6,20 +6,20 @@ import ( // CalculateDeployRequest . type CalculateDeployRequest struct { - Nodename string `json:"nodename" mapstructure:"nodename"` - DeployCount int `json:"deploy_count" mapstructure:"deploy_count"` - WorkloadResourceRequest *plugintypes.WorkloadResourceRequest `json:"workload_resource_request" mapstructure:"workload_resource_request"` + Nodename string `json:"nodename" mapstructure:"nodename"` + DeployCount int `json:"deploy_count" mapstructure:"deploy_count"` + WorkloadResourceRequest plugintypes.WorkloadResourceRequest `json:"workload_resource_request" mapstructure:"workload_resource_request"` } // CalculateReallocRequest . type CalculateReallocRequest struct { - Nodename string `json:"nodename" mapstructure:"nodename"` - WorkloadResource *plugintypes.WorkloadResource `json:"workload_request" mapstructure:"workload_request"` - WorkloadResourceRequest *plugintypes.WorkloadResourceRequest `json:"workload_resource_request" mapstructure:"workload_resource_request"` + Nodename string `json:"nodename" mapstructure:"nodename"` + WorkloadResource plugintypes.WorkloadResource `json:"workload_request" mapstructure:"workload_request"` + WorkloadResourceRequest plugintypes.WorkloadResourceRequest `json:"workload_resource_request" mapstructure:"workload_resource_request"` } // CalculateRemapRequest . type CalculateRemapRequest struct { - Nodename string `json:"nodename" mapstructure:"nodename"` - WorkloadsResource map[string]*plugintypes.WorkloadResource `json:"workloads_resource" mapstructure:"workloads_resource"` + Nodename string `json:"nodename" mapstructure:"nodename"` + WorkloadsResource map[string]plugintypes.WorkloadResource `json:"workloads_resource" mapstructure:"workloads_resource"` } diff --git a/resource/plugins/binary/types/node.go b/resource/plugins/binary/types/node.go index 2631cdb2e..6fb15780e 100644 --- a/resource/plugins/binary/types/node.go +++ b/resource/plugins/binary/types/node.go @@ -7,9 +7,9 @@ import ( // AddNodeRequest . type AddNodeRequest struct { - Nodename string `json:"nodename" mapstructure:"nodename"` - Resource *plugintypes.NodeResource `json:"resource" mapstructure:"resource"` - Info *enginetypes.Info `json:"info" mapstructure:"info"` + Nodename string `json:"nodename" mapstructure:"nodename"` + Resource plugintypes.NodeResource `json:"resource" mapstructure:"resource"` + Info *enginetypes.Info `json:"info" mapstructure:"info"` } // RemoveNodeRequest . @@ -19,40 +19,40 @@ type RemoveNodeRequest struct { // GetNodesDeployCapacityRequest . type GetNodesDeployCapacityRequest struct { - Nodenames []string `json:"nodenames" mapstructure:"nodenames"` - WorkloadResource *plugintypes.WorkloadResource `json:"workload_resource" mapstructure:"workload_resource"` + Nodenames []string `json:"nodenames" mapstructure:"nodenames"` + WorkloadResource plugintypes.WorkloadResource `json:"workload_resource" mapstructure:"workload_resource"` } // SetNodeResourceCapacityRequest . type SetNodeResourceCapacityRequest struct { - Nodename string `json:"nodename" mapstructure:"nodename"` - Resource *plugintypes.NodeResource `json:"resource" mapstructure:"resource"` - ResourceRequest *plugintypes.NodeResource `json:"resource_request" mapstructure:"resource_request"` - Delta bool `json:"delta" mapstructure:"delta"` - Incr bool `json:"incr" mapstructure:"incr"` + Nodename string `json:"nodename" mapstructure:"nodename"` + Resource plugintypes.NodeResource `json:"resource" mapstructure:"resource"` + ResourceRequest plugintypes.NodeResource `json:"resource_request" mapstructure:"resource_request"` + Delta bool `json:"delta" mapstructure:"delta"` + Incr bool `json:"incr" mapstructure:"incr"` } // GetNodeResourceInfoRequest . type GetNodeResourceInfoRequest struct { - Nodename string `json:"nodename" mapstructure:"nodename"` - WorkloadsResource []*plugintypes.WorkloadResource `json:"workloads_resource" mapstructure:"workloads_resource"` + Nodename string `json:"nodename" mapstructure:"nodename"` + WorkloadsResource []plugintypes.WorkloadResource `json:"workloads_resource" mapstructure:"workloads_resource"` } // SetNodeResourceInfoRequest . type SetNodeResourceInfoRequest struct { - Nodename string `json:"nodename" mapstructure:"nodename"` - Capacity *plugintypes.NodeResource `json:"capacity" mapstructure:"capacity"` - Usage *plugintypes.NodeResource `json:"usage" mapstructure:"usage"` + Nodename string `json:"nodename" mapstructure:"nodename"` + Capacity plugintypes.NodeResource `json:"capacity" mapstructure:"capacity"` + Usage plugintypes.NodeResource `json:"usage" mapstructure:"usage"` } // SetNodeResourceUsageRequest . type SetNodeResourceUsageRequest struct { - Nodename string `json:"nodename" mapstructure:"nodename"` - WorkloadsResource []*plugintypes.WorkloadResource `json:"workloads_resource" mapstructure:"workloads_resource"` - Resource *plugintypes.NodeResource `json:"resource" mapstructure:"resource"` - ResourceRequest *plugintypes.NodeResource `json:"resource_request" mapstructure:"resource_request"` - Delta bool `json:"delta" mapstructure:"delta"` - Incr bool `json:"incr" mapstructure:"incr"` + Nodename string `json:"nodename" mapstructure:"nodename"` + WorkloadsResource []plugintypes.WorkloadResource `json:"workloads_resource" mapstructure:"workloads_resource"` + Resource plugintypes.NodeResource `json:"resource" mapstructure:"resource"` + ResourceRequest plugintypes.NodeResource `json:"resource_request" mapstructure:"resource_request"` + Delta bool `json:"delta" mapstructure:"delta"` + Incr bool `json:"incr" mapstructure:"incr"` } // GetMostIdleNodeRequest . diff --git a/resource/plugins/cpumem/calculate.go b/resource/plugins/cpumem/calculate.go index c06326550..a1cacc0e1 100644 --- a/resource/plugins/cpumem/calculate.go +++ b/resource/plugins/cpumem/calculate.go @@ -13,7 +13,7 @@ import ( ) // CalculateDeploy . -func (p Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCount int, resourceRequest *plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateDeployResponse, error) { +func (p Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCount int, resourceRequest plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateDeployResponse, error) { logger := log.WithFunc("resource.cpumem.CalculateDeploy").WithField("node", nodename) req := &cpumemtypes.WorkloadResourceRequest{} if err := req.Parse(resourceRequest); err != nil { @@ -50,7 +50,7 @@ func (p Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCoun } // CalculateRealloc . -func (p Plugin) CalculateRealloc(ctx context.Context, nodename string, resource *plugintypes.WorkloadResource, resourceRequest *plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateReallocResponse, error) { +func (p Plugin) CalculateRealloc(ctx context.Context, nodename string, resource plugintypes.WorkloadResource, resourceRequest plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateReallocResponse, error) { req := &cpumemtypes.WorkloadResourceRequest{} if err := req.Parse(resourceRequest); err != nil { return nil, err @@ -140,7 +140,7 @@ func (p Plugin) CalculateRealloc(ctx context.Context, nodename string, resource } // CalculateRemap . -func (p Plugin) CalculateRemap(ctx context.Context, nodename string, workloadsResource map[string]*plugintypes.WorkloadResource) (*plugintypes.CalculateRemapResponse, error) { +func (p Plugin) CalculateRemap(ctx context.Context, nodename string, workloadsResource map[string]plugintypes.WorkloadResource) (*plugintypes.CalculateRemapResponse, error) { resp := &plugintypes.CalculateRemapResponse{} engineParamsMap := map[string]*cpumemtypes.EngineParams{} if len(workloadsResource) == 0 { diff --git a/resource/plugins/cpumem/calculate_test.go b/resource/plugins/cpumem/calculate_test.go index 44211e7a0..da191f6ed 100644 --- a/resource/plugins/cpumem/calculate_test.go +++ b/resource/plugins/cpumem/calculate_test.go @@ -20,7 +20,7 @@ func TestCalculateDeploy(t *testing.T) { node := nodes[0] // invalid opts - req := &plugintypes.WorkloadResourceRequest{ + req := plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": -1, } @@ -28,7 +28,7 @@ func TestCalculateDeploy(t *testing.T) { assert.True(t, errors.Is(err, types.ErrInvalidCPU)) // non-existent node - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 1, } @@ -36,7 +36,7 @@ func TestCalculateDeploy(t *testing.T) { assert.True(t, errors.Is(err, coretypes.ErrInvaildCount)) // cpu bind - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 1.1, } @@ -44,14 +44,14 @@ func TestCalculateDeploy(t *testing.T) { assert.Nil(t, err) // cpu bind & insufficient resource - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 2.2, } _, err = cm.CalculateDeploy(ctx, node, 1, req) assert.True(t, errors.Is(err, coretypes.ErrInsufficientCapacity)) - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 1, } @@ -59,14 +59,14 @@ func TestCalculateDeploy(t *testing.T) { assert.True(t, errors.Is(err, coretypes.ErrInsufficientCapacity)) // alloc by memory - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "memory-request": fmt.Sprintf("%v", units.GB), } _, err = cm.CalculateDeploy(ctx, node, 1, req) assert.Nil(t, err) // alloc by memory & insufficient cpu - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "memory-request": fmt.Sprintf("%v", units.GB), "cpu-request": 1000, } @@ -74,7 +74,7 @@ func TestCalculateDeploy(t *testing.T) { assert.True(t, errors.Is(err, coretypes.ErrInsufficientCapacity)) // alloc by memory & insufficient mem - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "memory-request": fmt.Sprintf("%v", 5*units.GB), "cpu-request": 1, } @@ -82,7 +82,7 @@ func TestCalculateDeploy(t *testing.T) { assert.True(t, errors.Is(err, coretypes.ErrInsufficientCapacity)) // mem_request == 0 - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "memory-request": "0", "cpu-request": 1, } @@ -90,7 +90,7 @@ func TestCalculateDeploy(t *testing.T) { assert.Nil(t, err) // numa node - resource := &plugintypes.NodeResource{ + resource := plugintypes.NodeResource{ "cpu": 4.0, "cpu_map": map[string]int64{ "0": 100, @@ -114,7 +114,7 @@ func TestCalculateDeploy(t *testing.T) { _, err = cm.SetNodeResourceCapacity(ctx, node, resource, nil, false, true) assert.Nil(t, err) - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "memory": fmt.Sprintf("%v", units.GB), "cpu-request": 1.3, @@ -131,7 +131,7 @@ func TestCalculateRealloc(t *testing.T) { node := nodes[0] // numa node - resource := &plugintypes.NodeResource{ + resource := plugintypes.NodeResource{ "cpu": 2.0, "cpu_map": map[string]int64{ "0": 100, @@ -151,15 +151,15 @@ func TestCalculateRealloc(t *testing.T) { _, err := cm.SetNodeResourceCapacity(ctx, node, resource, nil, false, true) assert.Nil(t, err) - origin := &plugintypes.WorkloadResource{} - req := &plugintypes.WorkloadResourceRequest{} + origin := plugintypes.WorkloadResource{} + req := plugintypes.WorkloadResourceRequest{} // non-existent node _, err = cm.CalculateRealloc(ctx, "xxx", origin, req) assert.True(t, errors.Is(err, coretypes.ErrInvaildCount)) // invalid resource opts - origin = &plugintypes.WorkloadResource{ + origin = plugintypes.WorkloadResource{ "cpu_request": 1, "cpu_limit": 1, "memory_request": units.GB, @@ -168,7 +168,7 @@ func TestCalculateRealloc(t *testing.T) { "numa_memory": types.NUMAMemory{"0": units.GB}, "numa_node": "0", } - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "keep-cpu-bind": true, "cpu-request": -3, } @@ -176,7 +176,7 @@ func TestCalculateRealloc(t *testing.T) { assert.True(t, errors.Is(err, types.ErrInvalidCPU)) // insufficient cpu - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "keep-cpu-bind": true, "cpu-request": 2, } @@ -184,7 +184,7 @@ func TestCalculateRealloc(t *testing.T) { assert.True(t, errors.Is(err, coretypes.ErrInsufficientResource)) // normal case (with cpu-bind) - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "keep-cpu-bind": true, "cpu-request": -0.5, "cpu-limit": -0.5, @@ -193,12 +193,12 @@ func TestCalculateRealloc(t *testing.T) { assert.Nil(t, err) // normal case (without cpu-bind) - req = &plugintypes.WorkloadResourceRequest{} + req = plugintypes.WorkloadResourceRequest{} _, err = cm.CalculateRealloc(ctx, node, origin, req) assert.Nil(t, err) // insufficient mem - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "memory-request": fmt.Sprintf("%v", units.PB), "memory-limit": fmt.Sprintf("%v", units.PB), } @@ -212,7 +212,7 @@ func TestCalculateRemap(t *testing.T) { nodes := generateNodes(ctx, t, cm, 1, 4, 4*units.GB, 100, 0) node := nodes[0] - resource := &plugintypes.NodeResource{ + resource := plugintypes.NodeResource{ "cpu_map": map[string]int64{ "0": 100, "1": 100, @@ -221,7 +221,7 @@ func TestCalculateRemap(t *testing.T) { _, err := cm.SetNodeResourceUsage(ctx, node, resource, nil, nil, false, true) assert.Nil(t, err) - workloadsResource := map[string]*plugintypes.WorkloadResource{ + workloadsResource := map[string]plugintypes.WorkloadResource{ "id1": { "cpu_request": 1, "cpu_limit": 1, @@ -253,11 +253,11 @@ func TestCalculateRemap(t *testing.T) { assert.Len(t, r.EngineParamsMap, 2) w1 := r.EngineParamsMap["id1"] w2 := r.EngineParamsMap["id2"] - assert.Len(t, (*w1)["CPUMap"], 2) - assert.Len(t, (*w2)["CPUMap"], 2) + assert.Len(t, w1["CPUMap"], 2) + assert.Len(t, w2["CPUMap"], 2) // empty share cpu map - workloadsResource["id4"] = &plugintypes.WorkloadResource{ + workloadsResource["id4"] = plugintypes.WorkloadResource{ "cpu_map": types.CPUMap{"2": 100, "3": 100}, "cpu_request": 2, "cpu_limit": 2, @@ -265,7 +265,7 @@ func TestCalculateRemap(t *testing.T) { "memory_limit": units.GB, } - resource = &plugintypes.NodeResource{ + resource = plugintypes.NodeResource{ "cpu_map": map[string]int64{ "0": 100, "1": 100, @@ -281,6 +281,6 @@ func TestCalculateRemap(t *testing.T) { assert.Len(t, r.EngineParamsMap, 2) w1 = r.EngineParamsMap["id1"] w2 = r.EngineParamsMap["id2"] - assert.Len(t, (*w1)["CPUMap"], 4) - assert.Len(t, (*w2)["CPUMap"], 4) + assert.Len(t, w1["CPUMap"], 4) + assert.Len(t, w2["CPUMap"], 4) } diff --git a/resource/plugins/cpumem/cpumem_test.go b/resource/plugins/cpumem/cpumem_test.go index 385b5288b..0ec20da47 100644 --- a/resource/plugins/cpumem/cpumem_test.go +++ b/resource/plugins/cpumem/cpumem_test.go @@ -52,10 +52,10 @@ func generateNodes( return names } -func generateNodeResourceRequests(t *testing.T, nums int, cores int, memory int64, shares, index int) map[string]*plugintypes.NodeResourceRequest { - infos := map[string]*plugintypes.NodeResourceRequest{} +func generateNodeResourceRequests(t *testing.T, nums int, cores int, memory int64, shares, index int) map[string]plugintypes.NodeResourceRequest { + infos := map[string]plugintypes.NodeResourceRequest{} for i := index; i < index+nums; i++ { - info := &plugintypes.NodeResourceRequest{ + info := plugintypes.NodeResourceRequest{ "cpu": cores, "share": shares, "memory": fmt.Sprintf("%v", memory), diff --git a/resource/plugins/cpumem/node.go b/resource/plugins/cpumem/node.go index ced691e3b..82f075353 100644 --- a/resource/plugins/cpumem/node.go +++ b/resource/plugins/cpumem/node.go @@ -20,7 +20,7 @@ import ( ) // AddNode . -func (p Plugin) AddNode(ctx context.Context, nodename string, resource *plugintypes.NodeResourceRequest, info *enginetypes.Info) (*plugintypes.AddNodeResponse, error) { +func (p Plugin) AddNode(ctx context.Context, nodename string, resource plugintypes.NodeResourceRequest, info *enginetypes.Info) (*plugintypes.AddNodeResponse, error) { // try to get the node resource var err error if _, err = p.doGetNodeResourceInfo(ctx, nodename); err == nil { @@ -91,7 +91,7 @@ func (p Plugin) RemoveNode(ctx context.Context, nodename string) (*plugintypes.R } // GetNodesDeployCapacity returns available nodes and total capacity -func (p Plugin) GetNodesDeployCapacity(ctx context.Context, nodenames []string, resource *plugintypes.WorkloadResourceRequest) (*plugintypes.GetNodesDeployCapacityResponse, error) { +func (p Plugin) GetNodesDeployCapacity(ctx context.Context, nodenames []string, resource plugintypes.WorkloadResourceRequest) (*plugintypes.GetNodesDeployCapacityResponse, error) { logger := log.WithFunc("resource.cpumem.GetNodesDeployCapacity") req := &cpumemtypes.WorkloadResourceRequest{} if err := req.Parse(resource); err != nil { @@ -131,7 +131,7 @@ func (p Plugin) GetNodesDeployCapacity(ctx context.Context, nodenames []string, } // SetNodeResourceCapacity sets the amount of total resource info -func (p Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, resource *plugintypes.NodeResource, resourceRequest *plugintypes.NodeResourceRequest, delta bool, incr bool) (*plugintypes.SetNodeResourceCapacityResponse, error) { +func (p Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, resource plugintypes.NodeResource, resourceRequest plugintypes.NodeResourceRequest, delta bool, incr bool) (*plugintypes.SetNodeResourceCapacityResponse, error) { logger := log.WithFunc("resource.cpumem.SetNodeResourceCapacity").WithField("node", "nodename") req, nodeResource, _, nodeResourceInfo, err := p.parseNodeResourceInfos(ctx, nodename, resource, resourceRequest, nil) if err != nil { @@ -167,7 +167,7 @@ func (p Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, re } // GetNodeResourceInfo . -func (p Plugin) GetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []*plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) { +func (p Plugin) GetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) { nodeResourceInfo, _, diffs, err := p.getNodeResourceInfo(ctx, nodename, workloadsResource) if err != nil { return nil, err @@ -182,7 +182,7 @@ func (p Plugin) GetNodeResourceInfo(ctx context.Context, nodename string, worklo } // SetNodeResourceInfo . -func (p Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capacity *plugintypes.NodeResource, usage *plugintypes.NodeResource) (*plugintypes.SetNodeResourceInfoResponse, error) { +func (p Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capacity plugintypes.NodeResource, usage plugintypes.NodeResource) (*plugintypes.SetNodeResourceInfoResponse, error) { capacityResource := &cpumemtypes.NodeResource{} usageResource := &cpumemtypes.NodeResource{} if err := capacityResource.Parse(capacity); err != nil { @@ -200,7 +200,7 @@ func (p Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capaci } // SetNodeResourceUsage . -func (p Plugin) SetNodeResourceUsage(ctx context.Context, nodename string, resource *plugintypes.NodeResource, resourceRequest *plugintypes.NodeResourceRequest, workloadsResource []*plugintypes.WorkloadResource, delta bool, incr bool) (*plugintypes.SetNodeResourceUsageResponse, error) { +func (p Plugin) SetNodeResourceUsage(ctx context.Context, nodename string, resource plugintypes.NodeResource, resourceRequest plugintypes.NodeResourceRequest, workloadsResource []plugintypes.WorkloadResource, delta bool, incr bool) (*plugintypes.SetNodeResourceUsageResponse, error) { logger := log.WithFunc("resource.cpumem.SetNodeResourceUsage").WithField("node", "nodename") req, nodeResource, wrksResource, nodeResourceInfo, err := p.parseNodeResourceInfos(ctx, nodename, resource, resourceRequest, workloadsResource) if err != nil { @@ -251,7 +251,7 @@ func (p Plugin) GetMostIdleNode(ctx context.Context, nodenames []string) (*plugi } // FixNodeResource . -func (p Plugin) FixNodeResource(ctx context.Context, nodename string, workloadsResource []*plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) { +func (p Plugin) FixNodeResource(ctx context.Context, nodename string, workloadsResource []plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) { nodeResourceInfo, actuallyWorkloadsUsage, diffs, err := p.getNodeResourceInfo(ctx, nodename, workloadsResource) if err != nil { return nil, err @@ -278,7 +278,7 @@ func (p Plugin) FixNodeResource(ctx context.Context, nodename string, workloadsR }, resp) } -func (p Plugin) getNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []*plugintypes.WorkloadResource) (*cpumemtypes.NodeResourceInfo, *cpumemtypes.WorkloadResource, []string, error) { +func (p Plugin) getNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []plugintypes.WorkloadResource) (*cpumemtypes.NodeResourceInfo, *cpumemtypes.WorkloadResource, []string, error) { logger := log.WithFunc("resource.cpumem.getNodeResourceInfo").WithField("node", nodename) nodeResourceInfo, err := p.doGetNodeResourceInfo(ctx, nodename) if err != nil { @@ -451,9 +451,9 @@ func (p Plugin) calculateNodeResource(req *cpumemtypes.NodeResourceRequest, node func (p Plugin) parseNodeResourceInfos( ctx context.Context, nodename string, - resource *plugintypes.NodeResource, - resourceRequest *plugintypes.NodeResourceRequest, - workloadsResource []*plugintypes.WorkloadResource, + resource plugintypes.NodeResource, + resourceRequest plugintypes.NodeResourceRequest, + workloadsResource []plugintypes.WorkloadResource, ) ( *cpumemtypes.NodeResourceRequest, *cpumemtypes.NodeResource, diff --git a/resource/plugins/cpumem/node_test.go b/resource/plugins/cpumem/node_test.go index 8e125d31d..a795e77f2 100644 --- a/resource/plugins/cpumem/node_test.go +++ b/resource/plugins/cpumem/node_test.go @@ -22,7 +22,7 @@ func TestAddNode(t *testing.T) { node := nodes[0] nodeForAdd := "test2" - req := &plugintypes.NodeResourceRequest{ + req := plugintypes.NodeResourceRequest{ "numa-cpu": []string{"0", "1"}, } @@ -35,7 +35,7 @@ func TestAddNode(t *testing.T) { // normal case r, err := cm.AddNode(ctx, nodeForAdd, req, info) assert.Nil(t, err) - assert.Equal(t, (*r.Capacity)["memory"], int64(4*units.GB*rate/10)) + assert.Equal(t, r.Capacity["memory"], int64(4*units.GB*rate/10)) } func TestRemoveNode(t *testing.T) { @@ -56,7 +56,7 @@ func TestGetNodesDeployCapacityWithCPUBind(t *testing.T) { cm := initCPUMEM(ctx, t) nodes := generateNodes(ctx, t, cm, 2, 2, 4*units.GB, 100, 0) - req := &plugintypes.WorkloadResourceRequest{ + req := plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 0.5, "memory-request": "1", @@ -72,7 +72,7 @@ func TestGetNodesDeployCapacityWithCPUBind(t *testing.T) { assert.True(t, r.Total >= 1) // more cpu - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 2, "memory-request": "1", @@ -82,7 +82,7 @@ func TestGetNodesDeployCapacityWithCPUBind(t *testing.T) { assert.True(t, r.Total < 3) // more - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 3, "memory-request": "1", @@ -92,7 +92,7 @@ func TestGetNodesDeployCapacityWithCPUBind(t *testing.T) { assert.True(t, r.Total < 2) // less - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 1, "memory-request": "1", @@ -108,7 +108,7 @@ func TestGetNodesDeployCapacityWithCPUBind(t *testing.T) { nodes = append(nodes, generateNodes(ctx, t, cm, 1, 18, 12*units.GB, 100, 13)...) nodes = append(nodes, generateNodes(ctx, t, cm, 1, 8, 12*units.GB, 100, 14)...) - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 1.7, "memory-request": "1", @@ -123,7 +123,7 @@ func TestGetNodesDeployCapacityWithMemoryAndCPUBind(t *testing.T) { cm := initCPUMEM(ctx, t) nodes := generateNodes(ctx, t, cm, 2, 2, 1024, 100, 0) - req := &plugintypes.WorkloadResourceRequest{ + req := plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 0.1, "memory-request": "1024", @@ -133,7 +133,7 @@ func TestGetNodesDeployCapacityWithMemoryAndCPUBind(t *testing.T) { assert.Nil(t, err) assert.Equal(t, r.Total, 2) - (*req)["memory-request"] = "1025" + req["memory-request"] = "1025" r, err = cm.GetNodesDeployCapacity(ctx, nodes, req) assert.Nil(t, err) assert.Equal(t, r.Total, 0) @@ -146,7 +146,7 @@ func TestGetNodesDeployCapacityWithMaxShareLimit(t *testing.T) { nodes := generateNodes(ctx, t, cm, 1, 6, 12*units.GB, 100, 0) node := nodes[0] - req := &plugintypes.WorkloadResourceRequest{ + req := plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 1.7, "memory-request": "1", @@ -157,7 +157,7 @@ func TestGetNodesDeployCapacityWithMaxShareLimit(t *testing.T) { assert.Equal(t, r.Total, 2) // numa node - resource := &plugintypes.NodeResource{ + resource := plugintypes.NodeResource{ "cpu": 4.0, "cpu_map": map[string]int64{ "0": 0, @@ -171,7 +171,7 @@ func TestGetNodesDeployCapacityWithMaxShareLimit(t *testing.T) { _, err = cm.SetNodeResourceCapacity(ctx, node, resource, nil, false, true) assert.Nil(t, err) - (*req)["cpu-request"] = 1.2 + req["cpu-request"] = 1.2 r, err = cm.GetNodesDeployCapacity(ctx, nodes, req) assert.Nil(t, err) assert.Equal(t, r.Total, 1) @@ -182,7 +182,7 @@ func TestGetNodesDeployCapacityWithMemory(t *testing.T) { cm := initCPUMEM(ctx, t) nodes := generateNodes(ctx, t, cm, 2, 2, 4*units.GiB, 100, 0) - req := &plugintypes.WorkloadResourceRequest{ + req := plugintypes.WorkloadResourceRequest{ "memory-request": "-1", } @@ -191,7 +191,7 @@ func TestGetNodesDeployCapacityWithMemory(t *testing.T) { assert.True(t, errors.Is(err, types.ErrInvalidMemory)) // cpu + mem - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-request": 1, "memory-request": fmt.Sprintf("%v", 512*units.MB), } @@ -201,7 +201,7 @@ func TestGetNodesDeployCapacityWithMemory(t *testing.T) { assert.Equal(t, r.Total, 16) // unlimited cpu - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "memory-request": fmt.Sprintf("%v", 512*units.MB), } r, err = cm.GetNodesDeployCapacity(ctx, nodes, req) @@ -209,7 +209,7 @@ func TestGetNodesDeployCapacityWithMemory(t *testing.T) { assert.Equal(t, r.Total, 16) // insufficient cpu - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-request": 3, "memory-request": fmt.Sprintf("%v", 512*units.MB), } @@ -218,7 +218,7 @@ func TestGetNodesDeployCapacityWithMemory(t *testing.T) { assert.Equal(t, r.Total, 0) // mem_request == 0 - req = &plugintypes.WorkloadResourceRequest{ + req = plugintypes.WorkloadResourceRequest{ "cpu-request": 1, } r, err = cm.GetNodesDeployCapacity(ctx, nodes, req) @@ -235,7 +235,7 @@ func TestSetNodeResourceCapacity(t *testing.T) { _, err := cm.GetNodeResourceInfo(ctx, node, nil) assert.Nil(t, err) - nodeResource := &plugintypes.NodeResource{ + nodeResource := plugintypes.NodeResource{ "cpu_map": map[string]int{ "2": 100, "3": 100, @@ -252,7 +252,7 @@ func TestSetNodeResourceCapacity(t *testing.T) { }, } - newNodeResource := &plugintypes.NodeResource{ + newNodeResource := plugintypes.NodeResource{ "cpu_map": map[string]int{ "0": 100, "1": 100, @@ -262,47 +262,47 @@ func TestSetNodeResourceCapacity(t *testing.T) { } gb := fmt.Sprintf("%v", units.GB) - nodeResourceRequest := &plugintypes.NodeResourceRequest{ + nodeResourceRequest := plugintypes.NodeResourceRequest{ "cpu": "2:100,3:100", "numa-memory": []string{gb, gb}, "numa-cpu": []string{"0,1", "2,3"}, } - noChangeRequest := &plugintypes.NodeResourceRequest{ + noChangeRequest := plugintypes.NodeResourceRequest{ "cpu": "0:100,1:100,2:100,3:100", "memory": fmt.Sprintf("%v", 2*units.GB), } r, err := cm.SetNodeResourceCapacity(ctx, node, nodeResource, nil, true, true) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 4) + assert.Len(t, r.After["cpu_map"], 4) r, err = cm.SetNodeResourceCapacity(ctx, node, nodeResource, nil, true, false) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) - assert.Len(t, (*r.After)["numa_memory"], 2) - assert.Len(t, (*r.After)["numa"], 4) + assert.Len(t, r.After["cpu_map"], 2) + assert.Len(t, r.After["numa_memory"], 2) + assert.Len(t, r.After["numa"], 4) r, err = cm.SetNodeResourceCapacity(ctx, node, nil, nodeResourceRequest, true, true) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 4) - assert.Len(t, (*r.After)["numa_memory"], 2) - assert.Len(t, (*r.After)["numa"], 4) + assert.Len(t, r.After["cpu_map"], 4) + assert.Len(t, r.After["numa_memory"], 2) + assert.Len(t, r.After["numa"], 4) r, err = cm.SetNodeResourceCapacity(ctx, node, nil, nodeResourceRequest, true, false) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) - assert.Len(t, (*r.After)["numa_memory"], 2) - assert.Len(t, (*r.After)["numa"], 4) + assert.Len(t, r.After["cpu_map"], 2) + assert.Len(t, r.After["numa_memory"], 2) + assert.Len(t, r.After["numa"], 4) r, err = cm.SetNodeResourceCapacity(ctx, node, nil, noChangeRequest, false, true) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 4) + assert.Len(t, r.After["cpu_map"], 4) r, err = cm.SetNodeResourceCapacity(ctx, node, newNodeResource, nil, false, false) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) - assert.Len(t, (*r.After)["numa"], 0) + assert.Len(t, r.After["cpu_map"], 2) + assert.Len(t, r.After["numa"], 0) } func TestGetAndFixNodeResourceInfo(t *testing.T) { @@ -319,13 +319,13 @@ func TestGetAndFixNodeResourceInfo(t *testing.T) { assert.Nil(t, err) assert.Len(t, r.Diffs, 0) - (*r.Capacity)["numa"] = types.NUMA{"0": "0", "1": "1"} - (*r.Capacity)["numa_memory"] = types.NUMAMemory{"0": units.GB, "1": units.GB} + r.Capacity["numa"] = types.NUMA{"0": "0", "1": "1"} + r.Capacity["numa_memory"] = types.NUMAMemory{"0": units.GB, "1": units.GB} _, err = cm.SetNodeResourceInfo(ctx, node, r.Capacity, r.Usage) assert.Nil(t, err) - workloadsResource := []*plugintypes.WorkloadResource{ + workloadsResource := []plugintypes.WorkloadResource{ { "cpu_request": 2.0, "cpu_map": types.CPUMap{"0": 100, "1": 100}, @@ -340,7 +340,7 @@ func TestGetAndFixNodeResourceInfo(t *testing.T) { r, err = cm.FixNodeResource(ctx, node, workloadsResource) assert.Nil(t, err) assert.Len(t, r.Diffs, 6) - assert.Len(t, (*r.Usage)["numa_memory"], 2) + assert.Len(t, r.Usage["numa_memory"], 2) } func TestSetNodeResourceInfo(t *testing.T) { @@ -365,7 +365,7 @@ func TestSetNodeResourceUsage(t *testing.T) { _, err := cm.GetNodeResourceInfo(ctx, node, nil) assert.Nil(t, err) - nodeResource := &plugintypes.NodeResource{ + nodeResource := plugintypes.NodeResource{ "cpu_map": map[string]int{ "0": 100, "1": 100, @@ -373,12 +373,12 @@ func TestSetNodeResourceUsage(t *testing.T) { "memory": 2 * units.GB, } - nodeResourceRequest := &plugintypes.NodeResourceRequest{ + nodeResourceRequest := plugintypes.NodeResourceRequest{ "cpu": "0:100,1:100", "memory": fmt.Sprintf("%v", 2*units.GB), } - workloadsResource := []*plugintypes.WorkloadResource{ + workloadsResource := []plugintypes.WorkloadResource{ { "cpu_request": 2.0, "cpu_map": types.CPUMap{ @@ -391,52 +391,52 @@ func TestSetNodeResourceUsage(t *testing.T) { r, err := cm.SetNodeResourceUsage(ctx, node, nodeResource, nil, nil, true, true) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) + assert.Len(t, r.After["cpu_map"], 2) r, err = cm.SetNodeResourceUsage(ctx, node, nodeResource, nil, nil, true, false) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) - assert.Equal(t, (*r.After)["cpu"], 0.0) - assert.Equal(t, (*r.After)["memory"], int64(0)) + assert.Len(t, r.After["cpu_map"], 2) + assert.Equal(t, r.After["cpu"], 0.0) + assert.Equal(t, r.After["memory"], int64(0)) r, err = cm.SetNodeResourceUsage(ctx, node, nil, nodeResourceRequest, nil, true, true) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) + assert.Len(t, r.After["cpu_map"], 2) r, err = cm.SetNodeResourceUsage(ctx, node, nil, nodeResourceRequest, nil, true, false) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) - assert.Equal(t, (*r.After)["cpu"], 0.0) - assert.Equal(t, (*r.After)["memory"], int64(0)) + assert.Len(t, r.After["cpu_map"], 2) + assert.Equal(t, r.After["cpu"], 0.0) + assert.Equal(t, r.After["memory"], int64(0)) r, err = cm.SetNodeResourceUsage(ctx, node, nil, nil, workloadsResource, true, true) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) + assert.Len(t, r.After["cpu_map"], 2) r, err = cm.SetNodeResourceUsage(ctx, node, nil, nil, workloadsResource, true, false) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) - assert.Equal(t, (*r.After)["cpu"], 0.0) - assert.Equal(t, (*r.After)["memory"], int64(0)) + assert.Len(t, r.After["cpu_map"], 2) + assert.Equal(t, r.After["cpu"], 0.0) + assert.Equal(t, r.After["memory"], int64(0)) r, err = cm.SetNodeResourceUsage(ctx, node, nil, nil, nil, true, false) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) - assert.Equal(t, (*r.After)["cpu"], 0.0) - assert.Equal(t, (*r.After)["memory"], int64(0)) + assert.Len(t, r.After["cpu_map"], 2) + assert.Equal(t, r.After["cpu"], 0.0) + assert.Equal(t, r.After["memory"], int64(0)) r, err = cm.SetNodeResourceUsage(ctx, node, nil, nodeResourceRequest, nil, false, false) assert.Nil(t, err) - assert.Len(t, (*r.After)["cpu_map"], 2) - assert.Equal(t, (*r.After)["cpu"], 2.0) - assert.Equal(t, (*r.After)["memory"], int64(2*units.GB)) + assert.Len(t, r.After["cpu_map"], 2) + assert.Equal(t, r.After["cpu"], 2.0) + assert.Equal(t, r.After["memory"], int64(2*units.GB)) } func TestGetMostIdleNode(t *testing.T) { ctx := context.Background() cm := initCPUMEM(ctx, t) nodes := generateNodes(ctx, t, cm, 2, 2, 2*units.GB, 100, 0) - usage := &plugintypes.NodeResourceRequest{"memory": "100"} + usage := plugintypes.NodeResourceRequest{"memory": "100"} _, err := cm.SetNodeResourceUsage(ctx, nodes[1], nil, usage, nil, false, false) assert.Nil(t, err) @@ -456,7 +456,7 @@ func BenchmarkGetNodesCapacity(b *testing.B) { ctx := context.Background() cm := initCPUMEM(ctx, t) nodes := generateNodes(ctx, t, cm, 1000, 24, 128*units.GB, 100, 0) - req := &plugintypes.WorkloadResourceRequest{ + req := plugintypes.WorkloadResourceRequest{ "cpu-bind": true, "cpu-request": 1.3, "memory-request": "1", diff --git a/resource/plugins/cpumem/types/node.go b/resource/plugins/cpumem/types/node.go index 83dfa4d45..645a54541 100644 --- a/resource/plugins/cpumem/types/node.go +++ b/resource/plugins/cpumem/types/node.go @@ -20,7 +20,7 @@ type NodeResource struct { } // Parse . -func (r *NodeResource) Parse(rawParams *coretypes.RawParams) error { +func (r *NodeResource) Parse(rawParams coretypes.RawParams) error { return mapstructure.Decode(rawParams, r) } @@ -175,7 +175,7 @@ type NodeResourceRequest struct { NUMAMemory NUMAMemory `json:"numa_memory"` } -func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams *coretypes.RawParams) error { +func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams coretypes.RawParams) error { var err error if n.CPUMap == nil { @@ -232,7 +232,7 @@ func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams *coretype return nil } -func (n *NodeResourceRequest) LoadFromOrigin(nodeResource *NodeResource, rawParams *coretypes.RawParams) { +func (n *NodeResourceRequest) LoadFromOrigin(nodeResource *NodeResource, rawParams coretypes.RawParams) { if n == nil { return } diff --git a/resource/plugins/cpumem/types/workload.go b/resource/plugins/cpumem/types/workload.go index e67e7bc24..51e975860 100644 --- a/resource/plugins/cpumem/types/workload.go +++ b/resource/plugins/cpumem/types/workload.go @@ -19,7 +19,7 @@ type WorkloadResource struct { } // ParseFromRawParams . -func (w *WorkloadResource) Parse(rawParams *coretypes.RawParams) error { +func (w *WorkloadResource) Parse(rawParams coretypes.RawParams) error { return mapstructure.Decode(rawParams, w) } @@ -113,7 +113,7 @@ func (w *WorkloadResourceRequest) Validate() error { } // Parse . -func (w *WorkloadResourceRequest) Parse(rawParams *coretypes.RawParams) (err error) { +func (w *WorkloadResourceRequest) Parse(rawParams coretypes.RawParams) (err error) { w.KeepCPUBind = rawParams.Bool("keep-cpu-bind") w.CPUBind = rawParams.Bool("cpu-bind") diff --git a/resource/plugins/mocks/Plugin.go b/resource/plugins/mocks/Plugin.go index ae2449bf8..b374ab269 100644 --- a/resource/plugins/mocks/Plugin.go +++ b/resource/plugins/mocks/Plugin.go @@ -19,11 +19,11 @@ type Plugin struct { } // AddNode provides a mock function with given fields: ctx, nodename, resource, info -func (_m *Plugin) AddNode(ctx context.Context, nodename string, resource *types.RawParams, info *enginetypes.Info) (*pluginstypes.AddNodeResponse, error) { +func (_m *Plugin) AddNode(ctx context.Context, nodename string, resource types.RawParams, info *enginetypes.Info) (*pluginstypes.AddNodeResponse, error) { ret := _m.Called(ctx, nodename, resource, info) var r0 *pluginstypes.AddNodeResponse - if rf, ok := ret.Get(0).(func(context.Context, string, *types.RawParams, *enginetypes.Info) *pluginstypes.AddNodeResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, types.RawParams, *enginetypes.Info) *pluginstypes.AddNodeResponse); ok { r0 = rf(ctx, nodename, resource, info) } else { if ret.Get(0) != nil { @@ -32,7 +32,7 @@ func (_m *Plugin) AddNode(ctx context.Context, nodename string, resource *types. } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *types.RawParams, *enginetypes.Info) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, types.RawParams, *enginetypes.Info) error); ok { r1 = rf(ctx, nodename, resource, info) } else { r1 = ret.Error(1) @@ -42,11 +42,11 @@ func (_m *Plugin) AddNode(ctx context.Context, nodename string, resource *types. } // CalculateDeploy provides a mock function with given fields: ctx, nodename, deployCount, resourceRequest -func (_m *Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCount int, resourceRequest *types.RawParams) (*pluginstypes.CalculateDeployResponse, error) { +func (_m *Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCount int, resourceRequest types.RawParams) (*pluginstypes.CalculateDeployResponse, error) { ret := _m.Called(ctx, nodename, deployCount, resourceRequest) var r0 *pluginstypes.CalculateDeployResponse - if rf, ok := ret.Get(0).(func(context.Context, string, int, *types.RawParams) *pluginstypes.CalculateDeployResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, int, types.RawParams) *pluginstypes.CalculateDeployResponse); ok { r0 = rf(ctx, nodename, deployCount, resourceRequest) } else { if ret.Get(0) != nil { @@ -55,7 +55,7 @@ func (_m *Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCo } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, int, *types.RawParams) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, int, types.RawParams) error); ok { r1 = rf(ctx, nodename, deployCount, resourceRequest) } else { r1 = ret.Error(1) @@ -65,11 +65,11 @@ func (_m *Plugin) CalculateDeploy(ctx context.Context, nodename string, deployCo } // CalculateRealloc provides a mock function with given fields: ctx, nodename, resource, resourceRequest -func (_m *Plugin) CalculateRealloc(ctx context.Context, nodename string, resource *types.RawParams, resourceRequest *types.RawParams) (*pluginstypes.CalculateReallocResponse, error) { +func (_m *Plugin) CalculateRealloc(ctx context.Context, nodename string, resource types.RawParams, resourceRequest types.RawParams) (*pluginstypes.CalculateReallocResponse, error) { ret := _m.Called(ctx, nodename, resource, resourceRequest) var r0 *pluginstypes.CalculateReallocResponse - if rf, ok := ret.Get(0).(func(context.Context, string, *types.RawParams, *types.RawParams) *pluginstypes.CalculateReallocResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, types.RawParams, types.RawParams) *pluginstypes.CalculateReallocResponse); ok { r0 = rf(ctx, nodename, resource, resourceRequest) } else { if ret.Get(0) != nil { @@ -78,7 +78,7 @@ func (_m *Plugin) CalculateRealloc(ctx context.Context, nodename string, resourc } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *types.RawParams, *types.RawParams) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, types.RawParams, types.RawParams) error); ok { r1 = rf(ctx, nodename, resource, resourceRequest) } else { r1 = ret.Error(1) @@ -88,11 +88,11 @@ func (_m *Plugin) CalculateRealloc(ctx context.Context, nodename string, resourc } // CalculateRemap provides a mock function with given fields: ctx, nodename, workloadsResource -func (_m *Plugin) CalculateRemap(ctx context.Context, nodename string, workloadsResource map[string]*types.RawParams) (*pluginstypes.CalculateRemapResponse, error) { +func (_m *Plugin) CalculateRemap(ctx context.Context, nodename string, workloadsResource map[string]types.RawParams) (*pluginstypes.CalculateRemapResponse, error) { ret := _m.Called(ctx, nodename, workloadsResource) var r0 *pluginstypes.CalculateRemapResponse - if rf, ok := ret.Get(0).(func(context.Context, string, map[string]*types.RawParams) *pluginstypes.CalculateRemapResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, map[string]types.RawParams) *pluginstypes.CalculateRemapResponse); ok { r0 = rf(ctx, nodename, workloadsResource) } else { if ret.Get(0) != nil { @@ -101,7 +101,7 @@ func (_m *Plugin) CalculateRemap(ctx context.Context, nodename string, workloads } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, map[string]*types.RawParams) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, map[string]types.RawParams) error); ok { r1 = rf(ctx, nodename, workloadsResource) } else { r1 = ret.Error(1) @@ -111,11 +111,11 @@ func (_m *Plugin) CalculateRemap(ctx context.Context, nodename string, workloads } // FixNodeResource provides a mock function with given fields: ctx, nodename, workloadsResource -func (_m *Plugin) FixNodeResource(ctx context.Context, nodename string, workloadsResource []*types.RawParams) (*pluginstypes.GetNodeResourceInfoResponse, error) { +func (_m *Plugin) FixNodeResource(ctx context.Context, nodename string, workloadsResource []types.RawParams) (*pluginstypes.GetNodeResourceInfoResponse, error) { ret := _m.Called(ctx, nodename, workloadsResource) var r0 *pluginstypes.GetNodeResourceInfoResponse - if rf, ok := ret.Get(0).(func(context.Context, string, []*types.RawParams) *pluginstypes.GetNodeResourceInfoResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, []types.RawParams) *pluginstypes.GetNodeResourceInfoResponse); ok { r0 = rf(ctx, nodename, workloadsResource) } else { if ret.Get(0) != nil { @@ -124,7 +124,7 @@ func (_m *Plugin) FixNodeResource(ctx context.Context, nodename string, workload } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, []*types.RawParams) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, []types.RawParams) error); ok { r1 = rf(ctx, nodename, workloadsResource) } else { r1 = ret.Error(1) @@ -203,11 +203,11 @@ func (_m *Plugin) GetMostIdleNode(ctx context.Context, nodenames []string) (*plu } // GetNodeResourceInfo provides a mock function with given fields: ctx, nodename, workloadsResource -func (_m *Plugin) GetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []*types.RawParams) (*pluginstypes.GetNodeResourceInfoResponse, error) { +func (_m *Plugin) GetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []types.RawParams) (*pluginstypes.GetNodeResourceInfoResponse, error) { ret := _m.Called(ctx, nodename, workloadsResource) var r0 *pluginstypes.GetNodeResourceInfoResponse - if rf, ok := ret.Get(0).(func(context.Context, string, []*types.RawParams) *pluginstypes.GetNodeResourceInfoResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, []types.RawParams) *pluginstypes.GetNodeResourceInfoResponse); ok { r0 = rf(ctx, nodename, workloadsResource) } else { if ret.Get(0) != nil { @@ -216,7 +216,7 @@ func (_m *Plugin) GetNodeResourceInfo(ctx context.Context, nodename string, work } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, []*types.RawParams) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, []types.RawParams) error); ok { r1 = rf(ctx, nodename, workloadsResource) } else { r1 = ret.Error(1) @@ -226,11 +226,11 @@ func (_m *Plugin) GetNodeResourceInfo(ctx context.Context, nodename string, work } // GetNodesDeployCapacity provides a mock function with given fields: ctx, nodenames, resource -func (_m *Plugin) GetNodesDeployCapacity(ctx context.Context, nodenames []string, resource *types.RawParams) (*pluginstypes.GetNodesDeployCapacityResponse, error) { +func (_m *Plugin) GetNodesDeployCapacity(ctx context.Context, nodenames []string, resource types.RawParams) (*pluginstypes.GetNodesDeployCapacityResponse, error) { ret := _m.Called(ctx, nodenames, resource) var r0 *pluginstypes.GetNodesDeployCapacityResponse - if rf, ok := ret.Get(0).(func(context.Context, []string, *types.RawParams) *pluginstypes.GetNodesDeployCapacityResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, []string, types.RawParams) *pluginstypes.GetNodesDeployCapacityResponse); ok { r0 = rf(ctx, nodenames, resource) } else { if ret.Get(0) != nil { @@ -239,7 +239,7 @@ func (_m *Plugin) GetNodesDeployCapacity(ctx context.Context, nodenames []string } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, []string, *types.RawParams) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, []string, types.RawParams) error); ok { r1 = rf(ctx, nodenames, resource) } else { r1 = ret.Error(1) @@ -286,11 +286,11 @@ func (_m *Plugin) RemoveNode(ctx context.Context, nodename string) (*pluginstype } // SetNodeResourceCapacity provides a mock function with given fields: ctx, nodename, resource, resourceRequest, delta, incr -func (_m *Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, resource *types.RawParams, resourceRequest *types.RawParams, delta bool, incr bool) (*pluginstypes.SetNodeResourceCapacityResponse, error) { +func (_m *Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, resource types.RawParams, resourceRequest types.RawParams, delta bool, incr bool) (*pluginstypes.SetNodeResourceCapacityResponse, error) { ret := _m.Called(ctx, nodename, resource, resourceRequest, delta, incr) var r0 *pluginstypes.SetNodeResourceCapacityResponse - if rf, ok := ret.Get(0).(func(context.Context, string, *types.RawParams, *types.RawParams, bool, bool) *pluginstypes.SetNodeResourceCapacityResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, types.RawParams, types.RawParams, bool, bool) *pluginstypes.SetNodeResourceCapacityResponse); ok { r0 = rf(ctx, nodename, resource, resourceRequest, delta, incr) } else { if ret.Get(0) != nil { @@ -299,7 +299,7 @@ func (_m *Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *types.RawParams, *types.RawParams, bool, bool) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, types.RawParams, types.RawParams, bool, bool) error); ok { r1 = rf(ctx, nodename, resource, resourceRequest, delta, incr) } else { r1 = ret.Error(1) @@ -309,11 +309,11 @@ func (_m *Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, } // SetNodeResourceInfo provides a mock function with given fields: ctx, nodename, capacity, usage -func (_m *Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capacity *types.RawParams, usage *types.RawParams) (*pluginstypes.SetNodeResourceInfoResponse, error) { +func (_m *Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capacity types.RawParams, usage types.RawParams) (*pluginstypes.SetNodeResourceInfoResponse, error) { ret := _m.Called(ctx, nodename, capacity, usage) var r0 *pluginstypes.SetNodeResourceInfoResponse - if rf, ok := ret.Get(0).(func(context.Context, string, *types.RawParams, *types.RawParams) *pluginstypes.SetNodeResourceInfoResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, types.RawParams, types.RawParams) *pluginstypes.SetNodeResourceInfoResponse); ok { r0 = rf(ctx, nodename, capacity, usage) } else { if ret.Get(0) != nil { @@ -322,7 +322,7 @@ func (_m *Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capa } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *types.RawParams, *types.RawParams) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, types.RawParams, types.RawParams) error); ok { r1 = rf(ctx, nodename, capacity, usage) } else { r1 = ret.Error(1) @@ -332,11 +332,11 @@ func (_m *Plugin) SetNodeResourceInfo(ctx context.Context, nodename string, capa } // SetNodeResourceUsage provides a mock function with given fields: ctx, nodename, resource, resourceRequest, workloadsResource, delta, incr -func (_m *Plugin) SetNodeResourceUsage(ctx context.Context, nodename string, resource *types.RawParams, resourceRequest *types.RawParams, workloadsResource []*types.RawParams, delta bool, incr bool) (*pluginstypes.SetNodeResourceUsageResponse, error) { +func (_m *Plugin) SetNodeResourceUsage(ctx context.Context, nodename string, resource types.RawParams, resourceRequest types.RawParams, workloadsResource []types.RawParams, delta bool, incr bool) (*pluginstypes.SetNodeResourceUsageResponse, error) { ret := _m.Called(ctx, nodename, resource, resourceRequest, workloadsResource, delta, incr) var r0 *pluginstypes.SetNodeResourceUsageResponse - if rf, ok := ret.Get(0).(func(context.Context, string, *types.RawParams, *types.RawParams, []*types.RawParams, bool, bool) *pluginstypes.SetNodeResourceUsageResponse); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, types.RawParams, types.RawParams, []types.RawParams, bool, bool) *pluginstypes.SetNodeResourceUsageResponse); ok { r0 = rf(ctx, nodename, resource, resourceRequest, workloadsResource, delta, incr) } else { if ret.Get(0) != nil { @@ -345,7 +345,7 @@ func (_m *Plugin) SetNodeResourceUsage(ctx context.Context, nodename string, res } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *types.RawParams, *types.RawParams, []*types.RawParams, bool, bool) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, types.RawParams, types.RawParams, []types.RawParams, bool, bool) error); ok { r1 = rf(ctx, nodename, resource, resourceRequest, workloadsResource, delta, incr) } else { r1 = ret.Error(1) diff --git a/resource/plugins/plugin.go b/resource/plugins/plugin.go index 09231caa1..9c09a6bd1 100644 --- a/resource/plugins/plugin.go +++ b/resource/plugins/plugin.go @@ -20,47 +20,47 @@ type Plugin interface { // CalculateDeploy tries to allocate resource, returns engine params for each workload, format: [{"cpus": 1.2}, {"cpus": 1.2}] // also returns resource params for each workload, format: [{"cpus": 1.2}, {"cpus": 1.2}] // pure calculation - CalculateDeploy(ctx context.Context, nodename string, deployCount int, resourceRequest *plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateDeployResponse, error) + CalculateDeploy(ctx context.Context, nodename string, deployCount int, resourceRequest plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateDeployResponse, error) // CalculateRealloc tries to reallocate resource, returns engine params, delta resource params and final resource params. // should return error if resource of some node is not enough for the realloc operation. // pure calculation - CalculateRealloc(ctx context.Context, nodename string, resource *plugintypes.WorkloadResource, resourceRequest *plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateReallocResponse, error) + CalculateRealloc(ctx context.Context, nodename string, resource plugintypes.WorkloadResource, resourceRequest plugintypes.WorkloadResourceRequest) (*plugintypes.CalculateReallocResponse, error) // CalculateRemap tries to remap resource based on workload metadata and node resource usage, then returns engine params for workloads. // pure calculation, for clarification, here use map's key to store the workload ID - CalculateRemap(ctx context.Context, nodename string, workloadsResource map[string]*plugintypes.WorkloadResource) (*plugintypes.CalculateRemapResponse, error) + CalculateRemap(ctx context.Context, nodename string, workloadsResource map[string]plugintypes.WorkloadResource) (*plugintypes.CalculateRemapResponse, error) // AddNode adds a node with requested resource, returns resource capacity and (empty) resource usage // should return error if the node already exists - AddNode(ctx context.Context, nodename string, resource *plugintypes.NodeResourceRequest, info *enginetypes.Info) (*plugintypes.AddNodeResponse, error) + AddNode(ctx context.Context, nodename string, resource plugintypes.NodeResourceRequest, info *enginetypes.Info) (*plugintypes.AddNodeResponse, error) // RemoveNode removes node RemoveNode(ctx context.Context, nodename string) (*plugintypes.RemoveNodeResponse, error) // GetNodesDeployCapacity returns available nodes and total capacity - GetNodesDeployCapacity(ctx context.Context, nodenames []string, resource *plugintypes.WorkloadResourceRequest) (*plugintypes.GetNodesDeployCapacityResponse, error) + GetNodesDeployCapacity(ctx context.Context, nodenames []string, resource plugintypes.WorkloadResourceRequest) (*plugintypes.GetNodesDeployCapacityResponse, error) // SetNodeResourceCapacity sets the amount of total resource info - SetNodeResourceCapacity(ctx context.Context, nodename string, resource *plugintypes.NodeResource, resourceRequest *plugintypes.NodeResourceRequest, delta bool, incr bool) (*plugintypes.SetNodeResourceCapacityResponse, error) + SetNodeResourceCapacity(ctx context.Context, nodename string, resource plugintypes.NodeResource, resourceRequest plugintypes.NodeResourceRequest, delta bool, incr bool) (*plugintypes.SetNodeResourceCapacityResponse, error) // GetNodeResourceInfo returns total resource info and available resource info of the node, format: {"cpu": 2} // also returns diffs, format: ["node.VolumeUsed != sum(workload.VolumeRequest"] - GetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []*plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) + GetNodeResourceInfo(ctx context.Context, nodename string, workloadsResource []plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) // SetNodeResourceInfo sets both total node resource info and allocated resource info // used for rollback of RemoveNode // notice: here uses absolute values, not delta values - SetNodeResourceInfo(ctx context.Context, nodename string, capacity *plugintypes.NodeResource, usage *plugintypes.NodeResource) (*plugintypes.SetNodeResourceInfoResponse, error) + SetNodeResourceInfo(ctx context.Context, nodename string, capacity plugintypes.NodeResource, usage plugintypes.NodeResource) (*plugintypes.SetNodeResourceInfoResponse, error) // SetNodeResourceUsage sets the amount of allocated resource info - SetNodeResourceUsage(ctx context.Context, nodename string, resource *plugintypes.NodeResource, resourceRequest *plugintypes.NodeResourceRequest, workloadsResource []*plugintypes.WorkloadResource, delta bool, incr bool) (*plugintypes.SetNodeResourceUsageResponse, error) + SetNodeResourceUsage(ctx context.Context, nodename string, resource plugintypes.NodeResource, resourceRequest plugintypes.NodeResourceRequest, workloadsResource []plugintypes.WorkloadResource, delta bool, incr bool) (*plugintypes.SetNodeResourceUsageResponse, error) // GetMostIdleNode returns the most idle node for building GetMostIdleNode(ctx context.Context, nodenames []string) (*plugintypes.GetMostIdleNodeResponse, error) // FixNodeResource fixes the node resource usage by its workloads - FixNodeResource(ctx context.Context, nodename string, workloadsResource []*plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) + FixNodeResource(ctx context.Context, nodename string, workloadsResource []plugintypes.WorkloadResource) (*plugintypes.GetNodeResourceInfoResponse, error) // GetMetricsDescription returns metrics description GetMetricsDescription(ctx context.Context) (*plugintypes.GetMetricsDescriptionResponse, error) diff --git a/resource/plugins/types/calculate.go b/resource/plugins/types/calculate.go index c7854e182..16010450e 100644 --- a/resource/plugins/types/calculate.go +++ b/resource/plugins/types/calculate.go @@ -2,18 +2,18 @@ package types // CalculateDeployResponse . type CalculateDeployResponse struct { - EnginesParams []*EngineParams `json:"engines_params" mapstructure:"engines_params"` - WorkloadsResource []*WorkloadResource `json:"workloads_resource" mapstructure:"workloads_resource"` + EnginesParams []EngineParams `json:"engines_params" mapstructure:"engines_params"` + WorkloadsResource []WorkloadResource `json:"workloads_resource" mapstructure:"workloads_resource"` } // CalculateReallocResponse . type CalculateReallocResponse struct { - EngineParams *EngineParams `json:"engine_params" mapstructure:"engine_params"` - DeltaResource *WorkloadResource `json:"delta_resource" mapstructure:"delta_resource"` - WorkloadResource *WorkloadResource `json:"workload_resource" mapstructure:"workload_resource"` + EngineParams EngineParams `json:"engine_params" mapstructure:"engine_params"` + DeltaResource WorkloadResource `json:"delta_resource" mapstructure:"delta_resource"` + WorkloadResource WorkloadResource `json:"workload_resource" mapstructure:"workload_resource"` } // CalculateRemapResponse . type CalculateRemapResponse struct { - EngineParamsMap map[string]*EngineParams `json:"engine_params_map" mapstructure:"engine_params_map"` + EngineParamsMap map[string]EngineParams `json:"engine_params_map" mapstructure:"engine_params_map"` } diff --git a/resource/plugins/types/node.go b/resource/plugins/types/node.go index ea9f343f0..af34d3be7 100644 --- a/resource/plugins/types/node.go +++ b/resource/plugins/types/node.go @@ -12,8 +12,8 @@ type NodeResource = coretypes.RawParams // AddNodeResponse . type AddNodeResponse struct { - Capacity *NodeResource `json:"capacity" mapstructure:"capacity"` - Usage *NodeResource `json:"usage" mapstructure:"usage"` + Capacity NodeResource `json:"capacity" mapstructure:"capacity"` + Usage NodeResource `json:"usage" mapstructure:"usage"` } // RemoveNodeResponse . @@ -38,15 +38,15 @@ type GetNodesDeployCapacityResponse struct { // SetNodeResourceCapacityResponse . type SetNodeResourceCapacityResponse struct { - Before *NodeResource `json:"before" mapstructure:"before"` - After *NodeResource `json:"after" mapstructure:"after"` + Before NodeResource `json:"before" mapstructure:"before"` + After NodeResource `json:"after" mapstructure:"after"` } // GetNodeResourceInfoResponse , type GetNodeResourceInfoResponse struct { - Capacity *NodeResource `json:"capacity" mapstructure:"capacity"` - Usage *NodeResource `json:"usage" mapstructure:"usage"` - Diffs []string `json:"diffs" mapstructure:"diffs"` + Capacity NodeResource `json:"capacity" mapstructure:"capacity"` + Usage NodeResource `json:"usage" mapstructure:"usage"` + Diffs []string `json:"diffs" mapstructure:"diffs"` } // SetNodeResourceInfoResponse . @@ -54,8 +54,8 @@ type SetNodeResourceInfoResponse struct{} // SetNodeResourceUsageResponse . type SetNodeResourceUsageResponse struct { - Before *NodeResource `json:"before" mapstructure:"before"` - After *NodeResource `json:"after" mapstructure:"after"` + Before NodeResource `json:"before" mapstructure:"before"` + After NodeResource `json:"after" mapstructure:"after"` } // GetMostIdleNodeResponse . diff --git a/rpc/transform.go b/rpc/transform.go index 7d1f438d5..b3fa2ee95 100644 --- a/rpc/transform.go +++ b/rpc/transform.go @@ -533,15 +533,15 @@ func toCoreRemoveImageOptions(opts *pb.RemoveImageOptions) *types.ImageOptions { } } -func toCoreResources(resources map[string][]byte) *types.Resources { - r := &types.Resources{} +func toCoreResources(resources map[string][]byte) types.Resources { + r := types.Resources{} for k, v := range resources { - rp := &types.RawParams{} - if err := json.Unmarshal(v, rp); err != nil { + rp := types.RawParams{} + if err := json.Unmarshal(v, &rp); err != nil { log.WithFunc("toCoreResources").Errorf(nil, err, "%v", string(v)) // nolint continue } - (*r)[k] = rp + r[k] = rp } return r } diff --git a/types/message.go b/types/message.go index 6576ebd8b..31d3deeff 100644 --- a/types/message.go +++ b/types/message.go @@ -79,8 +79,8 @@ type ControlWorkloadMessage struct { // CreateWorkloadMessage for create message type CreateWorkloadMessage struct { - EngineParams *Resources - Resources *Resources + EngineParams Resources + Resources Resources Podname string Nodename string WorkloadID string diff --git a/types/node.go b/types/node.go index a6ac99304..931939448 100644 --- a/types/node.go +++ b/types/node.go @@ -28,8 +28,8 @@ func (n NodeMeta) DeepCopy() (nn NodeMeta, err error) { // NodeResourceInfo for node resource info type NodeResourceInfo struct { Name string `json:"-"` - Capacity *Resources `json:"capacity,omitempty"` - Usage *Resources `json:"usage,omitempty"` + Capacity Resources `json:"capacity,omitempty"` + Usage Resources `json:"usage,omitempty"` Diffs []string `json:"diffs,omitempty"` Workloads []*Workload `json:"-"` } diff --git a/types/options.go b/types/options.go index b555b5670..f36dc4ca8 100644 --- a/types/options.go +++ b/types/options.go @@ -9,7 +9,7 @@ import ( // DeployOptions is options for deploying type DeployOptions struct { - Resources *Resources + Resources Resources Name string // Name of application Entrypoint *Entrypoint // entrypoint Podname string // Name of pod to deploy @@ -190,7 +190,7 @@ type AddNodeOptions struct { Cert string Key string Labels map[string]string - Resources *Resources + Resources Resources } // Validate checks options @@ -212,7 +212,7 @@ type SetNodeOptions struct { Nodename string Endpoint string WorkloadsDown bool - Resources *Resources + Resources Resources Delta bool Labels map[string]string Bypass TriOptions @@ -260,7 +260,7 @@ type ExecuteWorkloadOptions struct { // ReallocOptions . type ReallocOptions struct { ID string - Resources *Resources + Resources Resources } // TriOptions . diff --git a/types/options_test.go b/types/options_test.go index e54a0d7de..137999081 100644 --- a/types/options_test.go +++ b/types/options_test.go @@ -17,7 +17,7 @@ func TestParseTriOption(t *testing.T) { func TestSetNodeOptions(t *testing.T) { o := &SetNodeOptions{ - Resources: &Resources{}, + Resources: Resources{}, } assert.Equal(t, ErrEmptyNodeName, o.Validate()) diff --git a/types/resource.go b/types/resource.go index 03a6cf916..f3d460e6d 100644 --- a/types/resource.go +++ b/types/resource.go @@ -69,24 +69,24 @@ func (r RawParams) Bool(key string) bool { } // RawParams . -func (r RawParams) RawParams(key string) *RawParams { - var n *RawParams +func (r RawParams) RawParams(key string) RawParams { + var n RawParams if r.IsSet(key) { if m, ok := r[key].(map[string]interface{}); ok { - n = &RawParams{} - _ = mapstructure.Decode(m, n) + n = RawParams{} + _ = mapstructure.Decode(m, &n) } } return n } // SliceRawParams . -func (r RawParams) SliceRawParams(key string) []*RawParams { +func (r RawParams) SliceRawParams(key string) []RawParams { res := sliceHelper[map[string]interface{}](r, key) if res == nil { return nil } - n := make([]*RawParams, len(res)) + n := make([]RawParams, len(res)) for i, v := range res { _ = mapstructure.Decode(v, &n[i]) } @@ -129,4 +129,4 @@ func intHelper[T int | int64](r RawParams, key string) T { } // Resources all cosmos use this -type Resources map[string]*RawParams +type Resources map[string]RawParams diff --git a/types/resource_test.go b/types/resource_test.go index 75135b6a7..6fea20345 100644 --- a/types/resource_test.go +++ b/types/resource_test.go @@ -53,7 +53,7 @@ func TestRawParams(t *testing.T) { assert.Equal(t, r.StringSlice("string-slice"), []string{"string", "string"}) assert.Equal(t, r.OneOfStringSlice("?", "string-slice"), []string{"string", "string"}) assert.Equal(t, r.Bool("bool"), true) - assert.Equal(t, (*r.RawParams("raw-params"))["int64"], 1) - assert.Equal(t, (*r.SliceRawParams("slice-raw-params")[0])["int"], 1) + assert.Equal(t, r.RawParams("raw-params")["int64"], 1) + assert.Equal(t, r.SliceRawParams("slice-raw-params")[0]["int"], 1) assert.Equal(t, r.IsSet("?"), false) } diff --git a/types/workload.go b/types/workload.go index 7a5c96762..c605edcc5 100644 --- a/types/workload.go +++ b/types/workload.go @@ -35,8 +35,8 @@ type LabelMeta struct { // only relationship with pod and node is stored // if you wanna get realtime information, use Inspect method type Workload struct { - Resources *Resources `json:"resources"` - EngineParams *Resources `json:"engine_params"` + Resources Resources `json:"resources"` + EngineParams Resources `json:"engine_params"` ID string `json:"id"` Name string `json:"name"` Podname string `json:"podname"`