Search in sources :

Example 16 with Network

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;
}
Also used : Container(io.fabric8.maven.docker.model.Container) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Network(io.fabric8.maven.docker.model.Network) NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) HashSet(java.util.HashSet)

Aggregations

Network (io.fabric8.maven.docker.model.Network)6 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 ArrayList (java.util.ArrayList)5 NetworkConfig (io.fabric8.maven.docker.config.NetworkConfig)4 Container (io.fabric8.maven.docker.model.Container)4 IOException (java.io.IOException)4 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Container (io.fabric8.api.Container)2 Profile (io.fabric8.api.Profile)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 Test (org.junit.Test)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 DataTable (io.cucumber.datatable.DataTable)1 Given (io.cucumber.java.en.Given)1 Then (io.cucumber.java.en.Then)1 When (io.cucumber.java.en.When)1