Skip to content

Commit

Permalink
no pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Feb 3, 2023
1 parent d615e8c commit 34750be
Show file tree
Hide file tree
Showing 45 changed files with 442 additions and 442 deletions.
2 changes: 1 addition & 1 deletion cluster/calcium/capacity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
14 changes: 7 additions & 7 deletions cluster/calcium/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions cluster/calcium/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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: {}},
},
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/dissociate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions cluster/calcium/dissociate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions cluster/calcium/lambda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
)
Expand All @@ -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: {}},
},
Expand Down
6 changes: 3 additions & 3 deletions cluster/calcium/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions cluster/calcium/realloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions cluster/calcium/realloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestRealloc(t *testing.T) {
ID: "c1",
Podname: "p1",
Engine: engine,
Resources: &types.Resources{},
Resources: types.Resources{},
Nodename: "node1",
},
}
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/remap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
Expand Down
8 changes: 4 additions & 4 deletions cluster/calcium/remap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions cluster/calcium/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 34750be

Please sign in to comment.