Skip to content

Commit 061dba9

Browse files
staal0SlyngDK
andauthored
Simplify network list criteria
Co-authored-by: Simon Bengtsson <[email protected]>
1 parent e718ce5 commit 061dba9

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

main.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,20 +487,12 @@ func (m *manager) getNetworkNames(containerNames []string) ([]string, error) {
487487
if err != nil {
488488
return nil, err
489489
}
490-
491-
// Count currently attached containerNames
492-
attachedContainerNames := 0
493-
494-
for _, container := range containerNames {
495-
if containerInNetworks(container, attached) {
496-
attachedContainerNames = attachedContainerNames + 1
497-
}
498-
}
499-
500-
// If more than 0 containers in a network (excluding containers from config)
501-
if (len(attached.Containers) - attachedContainerNames) > 0 {
502-
if (network.Attachable || network.Scope == "local") && !containsString(ignoredNetworkNames, network.Name) {
490+
for _, endpoint := range attached.Containers {
491+
if !containsString(containerNames, endpoint.Name) &&
492+
(network.Attachable || network.Scope == "local") &&
493+
!containsString(ignoredNetworkNames, network.Name) {
503494
names = append(names, network.Name)
495+
break
504496
}
505497
}
506498
}

0 commit comments

Comments
 (0)