use of io.fabric8.maven.docker.model.Network in project docker-maven-plugin by fabric8io.
the class StopMojo method getNetworksToRemove.
private Set<Network> getNetworksToRemove(QueryService queryService, GavLabel gavLabel) throws IOException {
if (!autoCreateCustomNetworks) {
return Collections.emptySet();
}
Set<Network> customNetworks = new HashSet<>();
Set<Network> networks = queryService.getNetworks();
for (ImageConfiguration image : getResolvedImages()) {
final NetworkConfig config = image.getRunConfiguration().getNetworkingConfig();
if (!config.isCustomNetwork() || config.getName() == null) {
continue;
}
final Network network = getNetworkByName(networks, config.getCustomNetwork());
if (network == null) {
continue;
}
customNetworks.add(network);
Collection<Container> existingContainers = ContainerNamingUtil.getContainersToStop(image, containerNamePattern, getBuildTimestamp(), queryService.getContainersForImage(image.getName(), !keepContainer));
for (Container container : existingContainers) {
if (!shouldStopContainer(container, gavLabel)) {
// it's sill in use don't collect it
customNetworks.remove(network);
}
}
}
return customNetworks;
}
Aggregations