@@ -18,6 +18,7 @@ type vibranium struct {
18
18
cluster cluster.Cluster
19
19
config types.Config
20
20
counter sync.WaitGroup
21
+ TaskNum int
21
22
}
22
23
23
24
// Implementations for grpc server interface
@@ -70,8 +71,7 @@ func (v *vibranium) AddNode(ctx context.Context, opts *pb.AddNodeOptions) (*pb.N
70
71
return toRPCNode (n , v .cluster .GetZone ()), nil
71
72
}
72
73
73
- // AddNode saves a node and returns it to client
74
- // Method must be called synchronously, or nothing will be returned
74
+ // RemoveNode removes the node from etcd
75
75
func (v * vibranium ) RemoveNode (ctx context.Context , opts * pb.RemoveNodeOptions ) (* pb.Pod , error ) {
76
76
p , err := v .cluster .RemoveNode (opts .Nodename , opts .Podname )
77
77
if err != nil {
@@ -143,11 +143,16 @@ func (v *vibranium) GetContainers(ctx context.Context, cids *pb.ContainerIDs) (*
143
143
for _ , c := range containers {
144
144
info , err := c .Inspect ()
145
145
if err != nil {
146
+ // catch这个error(Container因为某种原因inspect失败的话),防止其在etcd中变成脏数据
147
+ log .Errorf ("[GetContainers] Inspect container error: %s" , err )
148
+ errorInfo := fmt .Sprintf ("Inspect container error: %s" , err )
149
+ cs = append (cs , toRPCContainer (c , errorInfo ))
146
150
continue
147
151
}
148
152
149
153
bytes , err := json .Marshal (info )
150
154
if err != nil {
155
+ log .Errorf ("[GetContainers] Marshal info json error: %s" , err )
151
156
continue
152
157
}
153
158
@@ -182,6 +187,9 @@ func (v *vibranium) SetNodeAvailable(ctx context.Context, opts *pb.NodeAvailable
182
187
// streamed returned functions
183
188
// caller must ensure that timeout will not be too short because these actions take a little time
184
189
func (v * vibranium ) BuildImage (opts * pb.BuildImageOptions , stream pb.CoreRPC_BuildImageServer ) error {
190
+ v .taskAdd ("BuildImage" , true )
191
+ defer v .taskDone ("BuildImage" , true )
192
+
185
193
ch , err := v .cluster .BuildImage (opts .Repo , opts .Version , opts .Uid , opts .Artifact )
186
194
if err != nil {
187
195
return err
@@ -202,6 +210,7 @@ func (v *vibranium) BuildImage(opts *pb.BuildImageOptions, stream pb.CoreRPC_Bui
202
210
203
211
func (v * vibranium ) CreateContainer (opts * pb.DeployOptions , stream pb.CoreRPC_CreateContainerServer ) error {
204
212
v .taskAdd ("CreateContainer" , true )
213
+ defer v .taskDone ("CreateContainer" , true )
205
214
206
215
specs , err := types .LoadSpecs (opts .Specs )
207
216
if err != nil {
@@ -216,7 +225,6 @@ func (v *vibranium) CreateContainer(opts *pb.DeployOptions, stream pb.CoreRPC_Cr
216
225
for m := range ch {
217
226
if err := stream .Send (toRPCCreateContainerMessage (m )); err != nil {
218
227
go func () {
219
- defer v .taskDone ("CreateContainer" , true )
220
228
for r := range ch {
221
229
log .Infof ("[CreateContainer] Unsent streamed message: %v" , r )
222
230
}
@@ -225,7 +233,6 @@ func (v *vibranium) CreateContainer(opts *pb.DeployOptions, stream pb.CoreRPC_Cr
225
233
}
226
234
}
227
235
228
- v .taskDone ("CreateContainer" , true )
229
236
return nil
230
237
}
231
238
@@ -249,8 +256,8 @@ func (v *vibranium) RunAndWait(stream pb.CoreRPC_RunAndWaitServer) error {
249
256
defer stdinReader .Close ()
250
257
ch , err := v .cluster .RunAndWait (specs , toCoreDeployOptions (opts ), stdinReader )
251
258
if err != nil {
259
+ // `ch` is nil now
252
260
log .Errorf ("[RunAndWait] Start run and wait failed %s" , err )
253
- stream .Send (toRPCRunAndWaitMessage (<- ch ))
254
261
return err
255
262
}
256
263
@@ -293,6 +300,7 @@ func (v *vibranium) RunAndWait(stream pb.CoreRPC_RunAndWaitServer) error {
293
300
294
301
func (v * vibranium ) UpgradeContainer (opts * pb.UpgradeOptions , stream pb.CoreRPC_UpgradeContainerServer ) error {
295
302
v .taskAdd ("UpgradeContainer" , true )
303
+ defer v .taskDone ("UpgradeContainer" , true )
296
304
297
305
ids := []string {}
298
306
for _ , id := range opts .Ids {
@@ -307,7 +315,6 @@ func (v *vibranium) UpgradeContainer(opts *pb.UpgradeOptions, stream pb.CoreRPC_
307
315
for m := range ch {
308
316
if err := stream .Send (toRPCUpgradeContainerMessage (m )); err != nil {
309
317
go func () {
310
- defer v .taskDone ("UpgradeContainer" , true )
311
318
for r := range ch {
312
319
log .Infof ("[UpgradeContainer] Unsent streamed message: %v" , r )
313
320
}
@@ -316,12 +323,12 @@ func (v *vibranium) UpgradeContainer(opts *pb.UpgradeOptions, stream pb.CoreRPC_
316
323
}
317
324
}
318
325
319
- v .taskDone ("UpgradeContainer" , true )
320
326
return nil
321
327
}
322
328
323
329
func (v * vibranium ) RemoveContainer (cids * pb.ContainerIDs , stream pb.CoreRPC_RemoveContainerServer ) error {
324
330
v .taskAdd ("RemoveContainer" , true )
331
+ defer v .taskDone ("RemoveContainer" , true )
325
332
326
333
ids := []string {}
327
334
for _ , id := range cids .Ids {
@@ -340,7 +347,6 @@ func (v *vibranium) RemoveContainer(cids *pb.ContainerIDs, stream pb.CoreRPC_Rem
340
347
for m := range ch {
341
348
if err := stream .Send (toRPCRemoveContainerMessage (m )); err != nil {
342
349
go func () {
343
- defer v .taskDone ("RemoveContainer" , true )
344
350
for r := range ch {
345
351
log .Infof ("[RemoveContainer] Unsent streamed message: %v" , r )
346
352
}
@@ -349,11 +355,13 @@ func (v *vibranium) RemoveContainer(cids *pb.ContainerIDs, stream pb.CoreRPC_Rem
349
355
}
350
356
}
351
357
352
- v .taskDone ("RemoveContainer" , true )
353
358
return nil
354
359
}
355
360
356
361
func (v * vibranium ) RemoveImage (opts * pb.RemoveImageOptions , stream pb.CoreRPC_RemoveImageServer ) error {
362
+ v .taskAdd ("RemoveImage" , true )
363
+ defer v .taskDone ("RemoveImage" , true )
364
+
357
365
ch , err := v .cluster .RemoveImage (opts .Podname , opts .Nodename , opts .Images )
358
366
if err != nil {
359
367
return err
0 commit comments