@@ -214,13 +214,13 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
214
214
}
215
215
216
216
var (
217
- expected [] string
217
+ expected = utils . NewSet [ string ]()
218
218
watched = map [string ]int {}
219
219
replaced []string
220
220
)
221
221
for _ , c := range containers {
222
222
if isRequired (c ) {
223
- expected = append ( expected , c .ID )
223
+ expected . Add ( c .ID )
224
224
}
225
225
watched [c .ID ] = 0
226
226
}
@@ -242,7 +242,7 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
242
242
// be able to inspect in time before they're gone from the
243
243
// API, so just remove the watch without erroring
244
244
delete (watched , event .Container )
245
- expected = utils .Remove (expected , event .Container )
245
+ expected .Remove (event .Container )
246
246
return nil
247
247
}
248
248
return err
@@ -253,7 +253,6 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
253
253
Labels : inspected .Config .Labels ,
254
254
}
255
255
name := getContainerNameWithoutProject (container )
256
-
257
256
service := container .Labels [api .ServiceLabel ]
258
257
switch event .Status {
259
258
case "stop" :
@@ -278,7 +277,7 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
278
277
}
279
278
280
279
delete (watched , container .ID )
281
- expected = utils .Remove (expected , container .ID )
280
+ expected .Remove (container .ID )
282
281
case "die" :
283
282
restarted := watched [container .ID ]
284
283
watched [container .ID ] = restarted + 1
@@ -308,15 +307,15 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
308
307
if ! willRestart {
309
308
// we're done with this one
310
309
delete (watched , container .ID )
311
- expected = utils .Remove (expected , container .ID )
310
+ expected .Remove (container .ID )
312
311
}
313
312
case "start" :
314
313
count , ok := watched [container .ID ]
315
314
mustAttach := ok && count > 0 // Container restarted, need to re-attach
316
315
if ! ok {
317
316
// A new container has just been added to service by scale
318
317
watched [container .ID ] = 0
319
- expected = append ( expected , container .ID )
318
+ expected . Add ( container .ID )
320
319
mustAttach = true
321
320
}
322
321
if mustAttach {
@@ -333,17 +332,15 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
333
332
if err != nil {
334
333
return err
335
334
}
336
- if utils .StringContains (expected , id ) {
337
- expected = append (expected , inspected .ID )
335
+ if expected .Has (id ) {
336
+ expected .Add (inspected .ID )
337
+ expected .Add (container .ID )
338
338
}
339
339
watched [container .ID ] = 1
340
- if utils .Contains (expected , id ) {
341
- expected = append (expected , container .ID )
342
- }
343
340
} else if ofInterest (container ) {
344
341
watched [container .ID ] = 1
345
342
if isRequired (container ) {
346
- expected = append ( expected , container .ID )
343
+ expected . Add ( container .ID )
347
344
}
348
345
}
349
346
}
0 commit comments