Search in sources :

Example 16 with VolumeConfig

use of io.fabric8.maven.core.config.VolumeConfig in project fabric8-maven-plugin by fabric8io.

the class PodTemplateHandler method getVolumes.

private List<Volume> getVolumes(ResourceConfig config) {
    List<VolumeConfig> volumeConfigs = config.getVolumes();
    List<Volume> ret = new ArrayList<>();
    if (volumeConfigs != null) {
        for (VolumeConfig volumeConfig : volumeConfigs) {
            VolumeType type = VolumeType.typeFor(volumeConfig.getType());
            if (type != null) {
                ret.add(type.fromConfig(volumeConfig));
            }
        }
    }
    return ret;
}
Also used : VolumeType(io.fabric8.maven.core.config.VolumeType) ArrayList(java.util.ArrayList) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig)

Example 17 with VolumeConfig

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

the class RunService method createVolumesAsPerVolumeBinds.

/**
 * Creates a Volume if a volume is referred to during startup in bind mount mapping and
 * a VolumeConfiguration exists
 *
 * @param hub Service hub
 * @param binds volume binds present in ImageConfiguration
 * @param volumes VolumeConfigs present
 * @return List of volumes created
 * @throws DockerAccessException
 */
public List<String> createVolumesAsPerVolumeBinds(ServiceHub hub, List<String> binds, List<VolumeConfiguration> volumes) throws DockerAccessException {
    Map<String, Integer> indexMap = new HashMap<>();
    List<String> volumesCreated = new ArrayList<>();
    for (int index = 0; index < volumes.size(); index++) {
        indexMap.put(volumes.get(index).getName(), index);
    }
    for (String bind : binds) {
        if (bind.contains(":")) {
            String name = bind.substring(0, bind.indexOf(':'));
            Integer volumeConfigIndex = indexMap.get(name);
            if (volumeConfigIndex != null) {
                VolumeConfiguration volumeConfig = volumes.get(volumeConfigIndex);
                hub.getVolumeService().createVolume(volumeConfig);
                volumesCreated.add(volumeConfig.getName());
            }
        }
    }
    return volumesCreated;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RunVolumeConfiguration(io.fabric8.maven.docker.config.RunVolumeConfiguration) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration)

Aggregations

VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)15 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)7 Test (org.junit.Test)7 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)6 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)6 ArrayList (java.util.ArrayList)6 Before (org.junit.Before)6 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)3 RunVolumeConfiguration (io.fabric8.maven.docker.config.RunVolumeConfiguration)2 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)1 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)1 VolumeType (io.fabric8.maven.core.config.VolumeType)1 ContainerCreateConfig (io.fabric8.maven.docker.access.ContainerCreateConfig)1 ContainerNetworkingConfig (io.fabric8.maven.docker.access.ContainerNetworkingConfig)1 NetworkConfig (io.fabric8.maven.docker.config.NetworkConfig)1 VolumeConfiguration (io.fabric8.maven.docker.config.VolumeConfiguration)1 HashMap (java.util.HashMap)1