Search in sources :

Example 1 with NetworkConfig

use of io.fabric8.maven.docker.config.NetworkConfig in project docker-maven-plugin by fabric8io.

the class StopMojo method getNetworksToRemove.

private Set<Network> getNetworksToRemove(QueryService queryService, PomLabel pomLabel) throws DockerAccessException {
    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()) {
            Network network = getNetworkByName(networks, config.getCustomNetwork());
            if (network != null) {
                customNetworks.add(network);
                for (Container container : getContainersToStop(queryService, image)) {
                    if (!shouldStopContainer(container, pomLabel, image)) {
                        // it's sill in use don't collect it
                        customNetworks.remove(network);
                    }
                }
            }
        }
    }
    return customNetworks;
}
Also used : Container(io.fabric8.maven.docker.model.Container) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) Network(io.fabric8.maven.docker.model.Network) NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) HashSet(java.util.HashSet)

Aggregations

ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)1 NetworkConfig (io.fabric8.maven.docker.config.NetworkConfig)1 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)1 Container (io.fabric8.maven.docker.model.Container)1 Network (io.fabric8.maven.docker.model.Network)1 HashSet (java.util.HashSet)1