@@ -23,6 +23,7 @@ import (
23
23
"github.com/pingcap/kvproto/pkg/pdpb"
24
24
"github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1"
25
25
"github.com/pingcap/tidb-operator/pkg/label"
26
+ "github.com/pingcap/tidb-operator/pkg/pdapi"
26
27
corev1 "k8s.io/api/core/v1"
27
28
apierrors "k8s.io/apimachinery/pkg/api/errors"
28
29
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -43,16 +44,15 @@ func TestPodControlUpdateMetaInfoSuccess(t *testing.T) {
43
44
pod := newPod (tc )
44
45
fakeClient , pdControl , podLister , _ , recorder := newFakeClientRecorderAndPDControl ()
45
46
control := NewRealPodControl (fakeClient , pdControl , podLister , recorder )
46
- pdClient := NewFakePDClient ()
47
- pdControl .SetPDClient (tc , pdClient )
48
- pdClient .AddReaction (GetClusterActionType , func (action * Action ) (interface {}, error ) {
47
+ pdClient := NewFakePDClient (pdControl , tc )
48
+ pdClient .AddReaction (pdapi .GetClusterActionType , func (action * pdapi.Action ) (interface {}, error ) {
49
49
cluster := & metapb.Cluster {
50
50
Id : 222 ,
51
51
}
52
52
return cluster , nil
53
53
})
54
- pdClient .AddReaction (GetMembersActionType , func (action * Action ) (interface {}, error ) {
55
- membersInfo := & MembersInfo {
54
+ pdClient .AddReaction (pdapi . GetMembersActionType , func (action * pdapi. Action ) (interface {}, error ) {
55
+ membersInfo := & pdapi. MembersInfo {
56
56
Members : []* pdpb.Member {
57
57
{
58
58
MemberId : 111 ,
@@ -61,11 +61,11 @@ func TestPodControlUpdateMetaInfoSuccess(t *testing.T) {
61
61
}
62
62
return membersInfo , nil
63
63
})
64
- pdClient .AddReaction (GetStoresActionType , func (action * Action ) (interface {}, error ) {
65
- storesInfo := & StoresInfo {
66
- Stores : []* StoreInfo {
64
+ pdClient .AddReaction (pdapi . GetStoresActionType , func (action * pdapi. Action ) (interface {}, error ) {
65
+ storesInfo := & pdapi. StoresInfo {
66
+ Stores : []* pdapi. StoreInfo {
67
67
{
68
- Store : & MetaStore {
68
+ Store : & pdapi. MetaStore {
69
69
Store : & metapb.Store {
70
70
Id : 333 ,
71
71
Address : fmt .Sprintf ("%s.web" , TestPodName ),
@@ -94,13 +94,12 @@ func TestPodControlUpdateMetaInfoGetClusterFailed(t *testing.T) {
94
94
pod := newPod (tc )
95
95
fakeClient , pdControl , podLister , _ , recorder := newFakeClientRecorderAndPDControl ()
96
96
control := NewRealPodControl (fakeClient , pdControl , podLister , recorder )
97
- pdClient := NewFakePDClient ()
98
- pdControl .SetPDClient (tc , pdClient )
99
- pdClient .AddReaction (GetClusterActionType , func (action * Action ) (interface {}, error ) {
97
+ pdClient := NewFakePDClient (pdControl , tc )
98
+ pdClient .AddReaction (pdapi .GetClusterActionType , func (action * pdapi.Action ) (interface {}, error ) {
100
99
return nil , errors .New ("failed to get cluster info from PD server" )
101
100
})
102
- pdClient .AddReaction (GetMembersActionType , func (action * Action ) (interface {}, error ) {
103
- membersInfo := & MembersInfo {
101
+ pdClient .AddReaction (pdapi . GetMembersActionType , func (action * pdapi. Action ) (interface {}, error ) {
102
+ membersInfo := & pdapi. MembersInfo {
104
103
Members : []* pdpb.Member {
105
104
{
106
105
MemberId : 111 ,
@@ -109,11 +108,11 @@ func TestPodControlUpdateMetaInfoGetClusterFailed(t *testing.T) {
109
108
}
110
109
return membersInfo , nil
111
110
})
112
- pdClient .AddReaction (GetStoresActionType , func (action * Action ) (interface {}, error ) {
113
- storesInfo := & StoresInfo {
114
- Stores : []* StoreInfo {
111
+ pdClient .AddReaction (pdapi . GetStoresActionType , func (action * pdapi. Action ) (interface {}, error ) {
112
+ storesInfo := & pdapi. StoresInfo {
113
+ Stores : []* pdapi. StoreInfo {
115
114
{
116
- Store : & MetaStore {
115
+ Store : & pdapi. MetaStore {
117
116
Store : & metapb.Store {
118
117
Id : 333 ,
119
118
Address : fmt .Sprintf ("%s.web" , TestPodName ),
@@ -141,22 +140,21 @@ func TestPodControlUpdateMetaInfoGetMemberFailed(t *testing.T) {
141
140
pod := newPod (tc )
142
141
fakeClient , pdControl , podLister , _ , recorder := newFakeClientRecorderAndPDControl ()
143
142
control := NewRealPodControl (fakeClient , pdControl , podLister , recorder )
144
- pdClient := NewFakePDClient ()
145
- pdControl .SetPDClient (tc , pdClient )
146
- pdClient .AddReaction (GetClusterActionType , func (action * Action ) (interface {}, error ) {
143
+ pdClient := NewFakePDClient (pdControl , tc )
144
+ pdClient .AddReaction (pdapi .GetClusterActionType , func (action * pdapi.Action ) (interface {}, error ) {
147
145
cluster := & metapb.Cluster {
148
146
Id : 222 ,
149
147
}
150
148
return cluster , nil
151
149
})
152
- pdClient .AddReaction (GetMembersActionType , func (action * Action ) (interface {}, error ) {
150
+ pdClient .AddReaction (pdapi . GetMembersActionType , func (action * pdapi. Action ) (interface {}, error ) {
153
151
return nil , errors .New ("failed to get member info from PD server" )
154
152
})
155
- pdClient .AddReaction (GetStoresActionType , func (action * Action ) (interface {}, error ) {
156
- storesInfo := & StoresInfo {
157
- Stores : []* StoreInfo {
153
+ pdClient .AddReaction (pdapi . GetStoresActionType , func (action * pdapi. Action ) (interface {}, error ) {
154
+ storesInfo := & pdapi. StoresInfo {
155
+ Stores : []* pdapi. StoreInfo {
158
156
{
159
- Store : & MetaStore {
157
+ Store : & pdapi. MetaStore {
160
158
Store : & metapb.Store {
161
159
Id : 333 ,
162
160
Address : fmt .Sprintf ("%s.web" , TestPodName ),
@@ -185,16 +183,15 @@ func TestPodControlUpdateMetaInfoGetStoreFailed(t *testing.T) {
185
183
pod := newPod (tc )
186
184
fakeClient , pdControl , podLister , _ , recorder := newFakeClientRecorderAndPDControl ()
187
185
control := NewRealPodControl (fakeClient , pdControl , podLister , recorder )
188
- pdClient := NewFakePDClient ()
189
- pdControl .SetPDClient (tc , pdClient )
190
- pdClient .AddReaction (GetClusterActionType , func (action * Action ) (interface {}, error ) {
186
+ pdClient := NewFakePDClient (pdControl , tc )
187
+ pdClient .AddReaction (pdapi .GetClusterActionType , func (action * pdapi.Action ) (interface {}, error ) {
191
188
cluster := & metapb.Cluster {
192
189
Id : 222 ,
193
190
}
194
191
return cluster , nil
195
192
})
196
- pdClient .AddReaction (GetMembersActionType , func (action * Action ) (interface {}, error ) {
197
- membersInfo := & MembersInfo {
193
+ pdClient .AddReaction (pdapi . GetMembersActionType , func (action * pdapi. Action ) (interface {}, error ) {
194
+ membersInfo := & pdapi. MembersInfo {
198
195
Members : []* pdpb.Member {
199
196
{
200
197
MemberId : 111 ,
@@ -203,7 +200,7 @@ func TestPodControlUpdateMetaInfoGetStoreFailed(t *testing.T) {
203
200
}
204
201
return membersInfo , nil
205
202
})
206
- pdClient .AddReaction (GetStoresActionType , func (action * Action ) (interface {}, error ) {
203
+ pdClient .AddReaction (pdapi . GetStoresActionType , func (action * pdapi. Action ) (interface {}, error ) {
207
204
return nil , errors .New ("failed to get store info from PD server" )
208
205
})
209
206
@@ -224,16 +221,15 @@ func TestPodControlUpdateMetaInfoUpdatePodFailed(t *testing.T) {
224
221
pod := newPod (tc )
225
222
fakeClient , pdControl , podLister , _ , recorder := newFakeClientRecorderAndPDControl ()
226
223
control := NewRealPodControl (fakeClient , pdControl , podLister , recorder )
227
- pdClient := NewFakePDClient ()
228
- pdControl .SetPDClient (tc , pdClient )
229
- pdClient .AddReaction (GetClusterActionType , func (action * Action ) (interface {}, error ) {
224
+ pdClient := NewFakePDClient (pdControl , tc )
225
+ pdClient .AddReaction (pdapi .GetClusterActionType , func (action * pdapi.Action ) (interface {}, error ) {
230
226
cluster := & metapb.Cluster {
231
227
Id : 222 ,
232
228
}
233
229
return cluster , nil
234
230
})
235
- pdClient .AddReaction (GetMembersActionType , func (action * Action ) (interface {}, error ) {
236
- membersInfo := & MembersInfo {
231
+ pdClient .AddReaction (pdapi . GetMembersActionType , func (action * pdapi. Action ) (interface {}, error ) {
232
+ membersInfo := & pdapi. MembersInfo {
237
233
Members : []* pdpb.Member {
238
234
{
239
235
MemberId : 111 ,
@@ -242,11 +238,11 @@ func TestPodControlUpdateMetaInfoUpdatePodFailed(t *testing.T) {
242
238
}
243
239
return membersInfo , nil
244
240
})
245
- pdClient .AddReaction (GetStoresActionType , func (action * Action ) (interface {}, error ) {
246
- storesInfo := & StoresInfo {
247
- Stores : []* StoreInfo {
241
+ pdClient .AddReaction (pdapi . GetStoresActionType , func (action * pdapi. Action ) (interface {}, error ) {
242
+ storesInfo := & pdapi. StoresInfo {
243
+ Stores : []* pdapi. StoreInfo {
248
244
{
249
- Store : & MetaStore {
245
+ Store : & pdapi. MetaStore {
250
246
Store : & metapb.Store {
251
247
Id : 333 ,
252
248
Address : fmt .Sprintf ("%s.web" , TestPodName ),
@@ -278,16 +274,15 @@ func TestPodControlUpdateMetaInfoConflictSuccess(t *testing.T) {
278
274
fakeClient , pdControl , podLister , podIndexer , recorder := newFakeClientRecorderAndPDControl ()
279
275
podIndexer .Add (oldPod )
280
276
control := NewRealPodControl (fakeClient , pdControl , podLister , recorder )
281
- pdClient := NewFakePDClient ()
282
- pdControl .SetPDClient (tc , pdClient )
283
- pdClient .AddReaction (GetClusterActionType , func (action * Action ) (interface {}, error ) {
277
+ pdClient := NewFakePDClient (pdControl , tc )
278
+ pdClient .AddReaction (pdapi .GetClusterActionType , func (action * pdapi.Action ) (interface {}, error ) {
284
279
cluster := & metapb.Cluster {
285
280
Id : 222 ,
286
281
}
287
282
return cluster , nil
288
283
})
289
- pdClient .AddReaction (GetMembersActionType , func (action * Action ) (interface {}, error ) {
290
- membersInfo := & MembersInfo {
284
+ pdClient .AddReaction (pdapi . GetMembersActionType , func (action * pdapi. Action ) (interface {}, error ) {
285
+ membersInfo := & pdapi. MembersInfo {
291
286
Members : []* pdpb.Member {
292
287
{
293
288
MemberId : 111 ,
@@ -296,11 +291,11 @@ func TestPodControlUpdateMetaInfoConflictSuccess(t *testing.T) {
296
291
}
297
292
return membersInfo , nil
298
293
})
299
- pdClient .AddReaction (GetStoresActionType , func (action * Action ) (interface {}, error ) {
300
- storesInfo := & StoresInfo {
301
- Stores : []* StoreInfo {
294
+ pdClient .AddReaction (pdapi . GetStoresActionType , func (action * pdapi. Action ) (interface {}, error ) {
295
+ storesInfo := & pdapi. StoresInfo {
296
+ Stores : []* pdapi. StoreInfo {
302
297
{
303
- Store : & MetaStore {
298
+ Store : & pdapi. MetaStore {
304
299
Store : & metapb.Store {
305
300
Id : 333 ,
306
301
Address : fmt .Sprintf ("%s.web" , TestPodName ),
@@ -385,9 +380,9 @@ func TestPodControlUpdatePodConflictSuccess(t *testing.T) {
385
380
g .Expect (events [0 ]).To (ContainSubstring (corev1 .EventTypeNormal ))
386
381
}
387
382
388
- func newFakeClientRecorderAndPDControl () (* fake.Clientset , * FakePDControl , corelisters.PodLister , cache.Indexer , * record.FakeRecorder ) {
383
+ func newFakeClientRecorderAndPDControl () (* fake.Clientset , * pdapi. FakePDControl , corelisters.PodLister , cache.Indexer , * record.FakeRecorder ) {
389
384
fakeClient := & fake.Clientset {}
390
- pdControl := NewFakePDControl ()
385
+ pdControl := pdapi . NewFakePDControl ()
391
386
kubeCli := kubefake .NewSimpleClientset ()
392
387
recorder := record .NewFakeRecorder (10 )
393
388
kubeInformerFactory := kubeinformers .NewSharedInformerFactory (kubeCli , 0 )
0 commit comments