Skip to content

Commit 09d4822

Browse files
committed
refactor nodefilter
1 parent 3b6423b commit 09d4822

29 files changed

+106
-98
lines changed

cluster/calcium/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (c *Calcium) selectBuildNode(ctx context.Context) (*types.Node, error) {
6262
}
6363

6464
// get nodes
65-
nodes, err := c.store.GetNodesByPod(ctx, c.config.Docker.BuildPod, nil, false)
65+
nodes, err := c.store.GetNodesByPod(ctx, &types.NodeFilter{Podname: c.config.Docker.BuildPod})
6666
if err != nil {
6767
return nil, err
6868
}

cluster/calcium/build_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ func TestBuild(t *testing.T) {
6464
c.config.Docker.BuildPod = "test"
6565
// failed by ListPodNodes failed
6666
store := c.store.(*storemocks.Store)
67-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrBadMeta).Once()
67+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return(nil, types.ErrBadMeta).Once()
6868
ch, err := c.BuildImage(ctx, opts)
6969
assert.Error(t, err)
7070
// failed by no nodes
71-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
71+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
7272
ch, err = c.BuildImage(ctx, opts)
7373
assert.Error(t, err)
7474
engine := &enginemocks.API{}
@@ -80,7 +80,7 @@ func TestBuild(t *testing.T) {
8080
Available: true,
8181
Engine: engine,
8282
}
83-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{node}, nil)
83+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{node}, nil)
8484
// failed by plugin error
8585
rmgr := c.rmgr.(*resourcemocks.Manager)
8686
rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, nil, nil)

cluster/calcium/capacity_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestCalculateCapacity(t *testing.T) {
4242
},
4343
ResourceOpts: types.WorkloadResourceOpts{},
4444
DeployStrategy: strategy.Auto,
45-
NodeFilter: types.NodeFilter{
45+
NodeFilter: &types.NodeFilter{
4646
Includes: []string{name},
4747
},
4848
Count: 3,

cluster/calcium/create_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestCreateWorkloadValidating(t *testing.T) {
3131
Entrypoint: &types.Entrypoint{
3232
Name: "some-nice-entrypoint",
3333
},
34+
NodeFilter: &types.NodeFilter{},
3435
}
3536
// failed by validating
3637
opts.Name = ""
@@ -72,6 +73,7 @@ func TestCreateWorkloadTxn(t *testing.T) {
7273
Entrypoint: &types.Entrypoint{
7374
Name: "good-entrypoint",
7475
},
76+
NodeFilter: &types.NodeFilter{},
7577
}
7678

7779
store := c.store.(*storemocks.Store)
@@ -274,7 +276,7 @@ func newCreateWorkloadCluster(t *testing.T) (*Calcium, []*types.Node) {
274276
store.On("CreateLock", mock.Anything, mock.Anything).Return(lock, nil)
275277

276278
// for get node
277-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nodes, nil)
279+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return(nodes, nil)
278280
store.On("GetNode", mock.Anything, mock.Anything).Return(
279281
func(_ context.Context, name string) (node *types.Node) {
280282
node = node1

cluster/calcium/image.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (c *Calcium) CacheImage(ctx context.Context, opts *types.ImageOptions) (cha
2020
return nil, logger.ErrWithTracing(ctx, err)
2121
}
2222

23-
nodes, err := c.filterNodes(ctx, types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
23+
nodes, err := c.filterNodes(ctx, &types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
2424
if err != nil {
2525
return nil, logger.ErrWithTracing(ctx, err)
2626
}
@@ -67,7 +67,7 @@ func (c *Calcium) RemoveImage(ctx context.Context, opts *types.ImageOptions) (ch
6767
return nil, logger.ErrWithTracing(ctx, err)
6868
}
6969

70-
nodes, err := c.filterNodes(ctx, types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
70+
nodes, err := c.filterNodes(ctx, &types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
7171
if err != nil {
7272
return nil, logger.ErrWithTracing(ctx, err)
7373
}
@@ -121,7 +121,7 @@ func (c *Calcium) RemoveImage(ctx context.Context, opts *types.ImageOptions) (ch
121121
func (c *Calcium) ListImage(ctx context.Context, opts *types.ImageOptions) (chan *types.ListImageMessage, error) {
122122
logger := log.WithField("Calcium", "ListImage").WithField("opts", opts)
123123

124-
nodes, err := c.filterNodes(ctx, types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
124+
nodes, err := c.filterNodes(ctx, &types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
125125
if err != nil {
126126
return nil, logger.ErrWithTracing(ctx, err)
127127
}

cluster/calcium/image_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ func TestCacheImage(t *testing.T) {
2323
_, err := c.CacheImage(ctx, &types.ImageOptions{Podname: ""})
2424
assert.Error(t, err)
2525
// fail by get nodes
26-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
26+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
2727
_, err = c.CacheImage(ctx, &types.ImageOptions{Podname: "podname"})
2828
assert.Error(t, err)
2929
// fail 0 nodes
30-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
30+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
3131
_, err = c.CacheImage(ctx, &types.ImageOptions{Podname: "podname"})
3232
assert.Error(t, err)
3333
engine := &enginemocks.API{}
@@ -39,7 +39,7 @@ func TestCacheImage(t *testing.T) {
3939
Engine: engine,
4040
},
4141
}
42-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nodes, nil)
42+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return(nodes, nil)
4343
// fail by ImageRemoteDigest
4444
engine.On("ImageLocalDigests", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
4545
engine.On("ImageRemoteDigest", mock.Anything, mock.Anything).Return("", types.ErrNoETCD).Once()
@@ -68,10 +68,10 @@ func TestRemoveImage(t *testing.T) {
6868
_, err := c.RemoveImage(ctx, &types.ImageOptions{Podname: ""})
6969
assert.Error(t, err)
7070
// fail by get nodes
71-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
71+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
7272
_, err = c.RemoveImage(ctx, &types.ImageOptions{Podname: "podname"})
7373
assert.Error(t, err)
74-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
74+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
7575
// fail 0 nodes
7676
_, err = c.RemoveImage(ctx, &types.ImageOptions{Podname: "podname"})
7777
assert.Error(t, err)
@@ -84,7 +84,7 @@ func TestRemoveImage(t *testing.T) {
8484
Engine: engine,
8585
},
8686
}
87-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nodes, nil)
87+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return(nodes, nil)
8888
// fail remove
8989
engine.On("ImageRemove", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
9090
ch, err := c.RemoveImage(ctx, &types.ImageOptions{Podname: "podname", Images: []string{"xx"}})
@@ -112,11 +112,11 @@ func TestListImage(t *testing.T) {
112112
ctx := context.Background()
113113
store := c.store.(*storemocks.Store)
114114
// fail by get nodes
115-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
115+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
116116
_, err := c.ListImage(ctx, &types.ImageOptions{Podname: "podname"})
117117
assert.Error(t, err)
118118
// fail 0 nodes
119-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
119+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
120120
_, err = c.ListImage(ctx, &types.ImageOptions{Podname: "podname"})
121121
assert.Error(t, err)
122122
engine := &enginemocks.API{}
@@ -128,7 +128,7 @@ func TestListImage(t *testing.T) {
128128
Engine: engine,
129129
},
130130
}
131-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nodes, nil)
131+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return(nodes, nil)
132132
// fail by ImageList
133133
engine.On("ImageList", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
134134
ch, err := c.ListImage(ctx, &types.ImageOptions{Podname: "podname"})

cluster/calcium/lambda_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestRunAndWaitFailedThenWALCommitted(t *testing.T) {
4747
Entrypoint: &types.Entrypoint{
4848
Name: "good-entrypoint",
4949
},
50+
NodeFilter: &types.NodeFilter{},
5051
}
5152

5253
_, ch, err := c.RunAndWait(context.Background(), opts, make(chan []byte))
@@ -82,6 +83,7 @@ func TestLambdaWithWorkloadIDReturned(t *testing.T) {
8283
Entrypoint: &types.Entrypoint{
8384
Name: "good-entrypoint",
8485
},
86+
NodeFilter: &types.NodeFilter{},
8587
}
8688

8789
r1, w1 := io.Pipe()
@@ -133,6 +135,7 @@ func TestLambdaWithError(t *testing.T) {
133135
Entrypoint: &types.Entrypoint{
134136
Name: "good-entrypoint",
135137
},
138+
NodeFilter: &types.NodeFilter{},
136139
}
137140

138141
store.On("GetWorkload", mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error")).Twice()
@@ -234,7 +237,7 @@ func newLambdaCluster(t *testing.T) (*Calcium, []*types.Node) {
234237
lock.On("Lock", mock.Anything).Return(context.Background(), nil)
235238
lock.On("Unlock", mock.Anything).Return(nil)
236239
store.On("CreateLock", mock.Anything, mock.Anything).Return(lock, nil)
237-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nodes, nil)
240+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return(nodes, nil)
238241
store.On("GetNode",
239242
mock.AnythingOfType("*context.emptyCtx"),
240243
mock.AnythingOfType("string"),

cluster/calcium/lock.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ func (c *Calcium) withWorkloadsLocked(ctx context.Context, ids []string, f func(
9595
}
9696

9797
func (c *Calcium) withNodePodLocked(ctx context.Context, nodename string, f func(context.Context, *types.Node) error) error {
98-
nf := types.NodeFilter{
98+
nodeFilter := &types.NodeFilter{
9999
Includes: []string{nodename},
100100
All: true,
101101
}
102-
return c.withNodesPodLocked(ctx, nf, func(ctx context.Context, nodes map[string]*types.Node) error {
102+
return c.withNodesPodLocked(ctx, nodeFilter, func(ctx context.Context, nodes map[string]*types.Node) error {
103103
if n, ok := nodes[nodename]; ok {
104104
return f(ctx, n)
105105
}
@@ -108,33 +108,33 @@ func (c *Calcium) withNodePodLocked(ctx context.Context, nodename string, f func
108108
}
109109

110110
func (c *Calcium) withNodeOperationLocked(ctx context.Context, nodename string, f func(context.Context, *types.Node) error) error {
111-
nf := types.NodeFilter{
111+
nodeFilter := &types.NodeFilter{
112112
Includes: []string{nodename},
113113
All: true,
114114
}
115-
return c.withNodesOperationLocked(ctx, nf, func(ctx context.Context, nodes map[string]*types.Node) error {
115+
return c.withNodesOperationLocked(ctx, nodeFilter, func(ctx context.Context, nodes map[string]*types.Node) error {
116116
if n, ok := nodes[nodename]; ok {
117117
return f(ctx, n)
118118
}
119119
return errors.WithStack(types.ErrNodeNotExists)
120120
})
121121
}
122122

123-
func (c *Calcium) withNodesOperationLocked(ctx context.Context, nf types.NodeFilter, f func(context.Context, map[string]*types.Node) error) error { // nolint
123+
func (c *Calcium) withNodesOperationLocked(ctx context.Context, nodeFilter *types.NodeFilter, f func(context.Context, map[string]*types.Node) error) error { // nolint
124124
genKey := func(node *types.Node) string {
125125
return fmt.Sprintf(cluster.NodeOperationLock, node.Podname, node.Name)
126126
}
127-
return c.withNodesLocked(ctx, nf, genKey, f)
127+
return c.withNodesLocked(ctx, nodeFilter, genKey, f)
128128
}
129129

130-
func (c *Calcium) withNodesPodLocked(ctx context.Context, nf types.NodeFilter, f func(context.Context, map[string]*types.Node) error) error {
130+
func (c *Calcium) withNodesPodLocked(ctx context.Context, nodeFilter *types.NodeFilter, f func(context.Context, map[string]*types.Node) error) error {
131131
genKey := func(node *types.Node) string {
132132
return fmt.Sprintf(cluster.PodLock, node.Podname)
133133
}
134-
return c.withNodesLocked(ctx, nf, genKey, f)
134+
return c.withNodesLocked(ctx, nodeFilter, genKey, f)
135135
}
136136

137-
func (c *Calcium) withNodesLocked(ctx context.Context, nf types.NodeFilter, genKey func(*types.Node) string, f func(context.Context, map[string]*types.Node) error) error {
137+
func (c *Calcium) withNodesLocked(ctx context.Context, nodeFilter *types.NodeFilter, genKey func(*types.Node) string, f func(context.Context, map[string]*types.Node) error) error {
138138
nodes := map[string]*types.Node{}
139139
locks := map[string]lock.DistributedLock{}
140140
lockKeys := []string{}
@@ -144,7 +144,7 @@ func (c *Calcium) withNodesLocked(ctx context.Context, nf types.NodeFilter, genK
144144
log.Debugf(ctx, "[withNodesLocked] keys %v unlocked", lockKeys)
145145
}()
146146

147-
ns, err := c.filterNodes(ctx, nf)
147+
ns, err := c.filterNodes(ctx, nodeFilter)
148148
if err != nil {
149149
return err
150150
}

cluster/calcium/lock_test.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,22 @@ func TestWithNodesPodLocked(t *testing.T) {
132132
Available: true,
133133
}
134134
// failed by list nodes
135-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, types.ErrNoETCD).Once()
136-
err := c.withNodesPodLocked(ctx, types.NodeFilter{Podname: "test", All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
135+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, types.ErrNoETCD).Once()
136+
err := c.withNodesPodLocked(ctx, &types.NodeFilter{Podname: "test", All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
137137
assert.Error(t, err)
138-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
138+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
139139
// failed by filter
140140
var ns map[string]*types.Node
141-
err = c.withNodesPodLocked(ctx, types.NodeFilter{Podname: "test", Labels: map[string]string{"eru": "2"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error {
141+
err = c.withNodesPodLocked(ctx, &types.NodeFilter{Podname: "test", Labels: map[string]string{"eru": "2"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error {
142142
ns = nodes
143143
return nil
144144
})
145145
assert.NoError(t, err)
146146
assert.Empty(t, ns)
147-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, nil)
147+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, nil)
148148
// failed by getnode
149149
store.On("GetNode", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
150-
err = c.withNodesPodLocked(ctx, types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
150+
err = c.withNodesPodLocked(ctx, &types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
151151
assert.Error(t, err)
152152
store.On("GetNode", mock.Anything, mock.Anything).Return(node1, nil).Once()
153153
// failed by lock
@@ -156,16 +156,16 @@ func TestWithNodesPodLocked(t *testing.T) {
156156
lock.On("Unlock", mock.Anything).Return(nil)
157157
// failed to get lock
158158
lock.On("Lock", mock.Anything).Return(context.TODO(), types.ErrNoETCD).Once()
159-
err = c.withNodesPodLocked(ctx, types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
159+
err = c.withNodesPodLocked(ctx, &types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
160160
assert.Error(t, err)
161161
lock.On("Lock", mock.Anything).Return(ctx, nil)
162162
// failed by get locked node
163163
store.On("GetNode", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
164-
err = c.withNodesPodLocked(ctx, types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
164+
err = c.withNodesPodLocked(ctx, &types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
165165
assert.Error(t, err)
166166
store.On("GetNode", mock.Anything, mock.Anything).Return(node1, nil)
167167
// success
168-
err = c.withNodesPodLocked(ctx, types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error {
168+
err = c.withNodesPodLocked(ctx, &types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error {
169169
assert.Len(t, nodes, 1)
170170
return nil
171171
})
@@ -224,22 +224,22 @@ func TestWithNodesOperationLocked(t *testing.T) {
224224
Available: true,
225225
}
226226
// failed by list nodes
227-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, types.ErrNoETCD).Once()
228-
err := c.withNodesOperationLocked(ctx, types.NodeFilter{Podname: "test", All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
227+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, types.ErrNoETCD).Once()
228+
err := c.withNodesOperationLocked(ctx, &types.NodeFilter{Podname: "test", All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
229229
assert.Error(t, err)
230-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
230+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, nil).Once()
231231
// failed by filter
232232
var ns map[string]*types.Node
233-
err = c.withNodesOperationLocked(ctx, types.NodeFilter{Podname: "test", Labels: map[string]string{"eru": "2"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error {
233+
err = c.withNodesOperationLocked(ctx, &types.NodeFilter{Podname: "test", Labels: map[string]string{"eru": "2"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error {
234234
ns = nodes
235235
return nil
236236
})
237237
assert.NoError(t, err)
238238
assert.Empty(t, ns)
239-
store.On("GetNodesByPod", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*types.Node{}, nil)
239+
store.On("GetNodesByPod", mock.Anything, mock.Anything).Return([]*types.Node{}, nil)
240240
// failed by getnode
241241
store.On("GetNode", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
242-
err = c.withNodesOperationLocked(ctx, types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
242+
err = c.withNodesOperationLocked(ctx, &types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
243243
assert.Error(t, err)
244244
store.On("GetNode", mock.Anything, mock.Anything).Return(node1, nil).Once()
245245
// failed by lock
@@ -248,16 +248,16 @@ func TestWithNodesOperationLocked(t *testing.T) {
248248
lock.On("Unlock", mock.Anything).Return(nil)
249249
// failed to get lock
250250
lock.On("Lock", mock.Anything).Return(context.TODO(), types.ErrNoETCD).Once()
251-
err = c.withNodesOperationLocked(ctx, types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
251+
err = c.withNodesOperationLocked(ctx, &types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
252252
assert.Error(t, err)
253253
lock.On("Lock", mock.Anything).Return(ctx, nil)
254254
// failed by get locked node
255255
store.On("GetNode", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
256-
err = c.withNodesOperationLocked(ctx, types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
256+
err = c.withNodesOperationLocked(ctx, &types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error { return nil })
257257
assert.Error(t, err)
258258
store.On("GetNode", mock.Anything, mock.Anything).Return(node1, nil)
259259
// success
260-
err = c.withNodesOperationLocked(ctx, types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error {
260+
err = c.withNodesOperationLocked(ctx, &types.NodeFilter{Podname: "test", Includes: []string{"test"}, All: false}, func(ctx context.Context, nodes map[string]*types.Node) error {
261261
assert.Len(t, nodes, 1)
262262
return nil
263263
})

0 commit comments

Comments
 (0)