Search in sources :

Example 11 with ContainerBuilder

use of io.fabric8.kubernetes.api.model.ContainerBuilder in project flink by apache.

the class PodTemplateMountDecorator method decorateFlinkPod.

@Override
public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
    if (!getTaskManagerPodTemplateFile().isPresent()) {
        return flinkPod;
    }
    final Pod mountedPod = decoratePod(flinkPod.getPodWithoutMainContainer());
    final Container mountedMainContainer = new ContainerBuilder(flinkPod.getMainContainer()).addNewVolumeMount().withName(POD_TEMPLATE_VOLUME).withMountPath(POD_TEMPLATE_DIR_IN_POD).endVolumeMount().build();
    return new FlinkPod.Builder(flinkPod).withPod(mountedPod).withMainContainer(mountedMainContainer).build();
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod)

Example 12 with ContainerBuilder

use of io.fabric8.kubernetes.api.model.ContainerBuilder in project TOSCAna by StuPro-TOSCAna.

the class ResourceDeployment method build.

@Override
public ResourceDeployment build() {
    ArrayList<Container> containers = new ArrayList<>();
    // Create the Container objects of the containers belonging in the Pod
    pod.getContainers().forEach(e -> {
        Container container = new ContainerBuilder().withImage(e.getDockerImageTag().get()).withName(e.getCleanStackName()).withImagePullPolicy("Always").addAllToPorts(e.getOpenPorts().stream().map(Port::toContainerPort).collect(Collectors.toList())).build();
        containers.add(container);
    });
    deployment = new DeploymentBuilder().withNewMetadata().withName(pod.getDeploymentName()).addToLabels("app", name).endMetadata().withNewSpec().withReplicas(pod.getReplicaCount()).withNewSelector().addToMatchLabels("app", name).endSelector().withNewTemplate().withNewMetadata().withName(name).addToLabels("app", name).endMetadata().withNewSpec().addAllToContainers(containers).endSpec().endTemplate().endSpec().build();
    return this;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ArrayList(java.util.ArrayList) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Example 13 with ContainerBuilder

use of io.fabric8.kubernetes.api.model.ContainerBuilder in project docker-maven-plugin by fabric8io.

the class JibServiceUtilTest method testContainerFromImageConfiguration.

@Test
public void testContainerFromImageConfiguration(@Mocked JibContainerBuilder containerBuilder) throws Exception {
    // Given
    ImageConfiguration imageConfiguration = getSampleImageConfiguration();
    // When
    JibContainerBuilder jibContainerBuilder = containerFromImageConfiguration(ImageFormat.Docker.name(), imageConfiguration, null);
    // Then
    // @formatter:off
    new Verifications() {

        {
            jibContainerBuilder.addLabel("foo", "bar");
            times = 1;
            jibContainerBuilder.setEntrypoint(Arrays.asList("java", "-jar", "foo.jar"));
            times = 1;
            jibContainerBuilder.setExposedPorts(new HashSet<>(Collections.singletonList(Port.tcp(8080))));
            times = 1;
            jibContainerBuilder.setUser("root");
            times = 1;
            jibContainerBuilder.setWorkingDirectory(AbsoluteUnixPath.get("/home/foo"));
            times = 1;
            jibContainerBuilder.setVolumes(new HashSet<>(Collections.singletonList(AbsoluteUnixPath.get("/mnt/volume1"))));
            times = 1;
            jibContainerBuilder.setFormat(ImageFormat.Docker);
            times = 1;
        }
    };
// @formatter:on
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) JibServiceUtil.containerFromImageConfiguration(io.fabric8.maven.docker.util.JibServiceUtil.containerFromImageConfiguration) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 14 with ContainerBuilder

use of io.fabric8.kubernetes.api.model.ContainerBuilder in project docker-maven-plugin by fabric8io.

the class JibBuildService method build.

public void build(String jibImageFormat, ImageConfiguration imageConfig, RegistryService.RegistryConfig registryConfig) throws MojoExecutionException {
    try {
        log.info("[[B]]JIB[[B]] image build started");
        if (imageConfig.getBuildConfiguration().isDockerFileMode()) {
            throw new MojoExecutionException("Dockerfile mode is not supported with JIB build strategy");
        }
        prependRegistry(imageConfig, mojoParameters.getProject().getProperties().getProperty(PUSH_REGISTRY));
        BuildDirs buildDirs = new BuildDirs(imageConfig.getName(), mojoParameters);
        final Credential pullRegistryCredential = getRegistryCredentials(registryConfig, false, imageConfig, log);
        final JibContainerBuilder containerBuilder = containerFromImageConfiguration(jibImageFormat, imageConfig, pullRegistryCredential);
        File dockerTarArchive = getAssemblyTarArchive(imageConfig, serviceHub, mojoParameters, log);
        for (AssemblyConfiguration assemblyConfiguration : imageConfig.getBuildConfiguration().getAssemblyConfigurations()) {
            // TODO: Improve Assembly Manager so that the effective assemblyFileEntries computed can be properly shared
            // the call to DockerAssemblyManager.getInstance().createDockerTarArchive should not be necessary,
            // files should be added using the AssemblyFileEntry list. DockerAssemblyManager, should provide
            // a common way to achieve this so that both the tar builder and any other builder could get a hold of
            // archive customizers, file entries, etc.
            AssemblyFiles assemblyFiles = serviceHub.getDockerAssemblyManager().getAssemblyFiles(imageConfig.getName(), assemblyConfiguration, mojoParameters, log);
            final Map<File, AssemblyFiles.Entry> files = assemblyFiles.getUpdatedEntriesAndRefresh().stream().collect(Collectors.toMap(AssemblyFiles.Entry::getDestFile, Function.identity(), (oldV, newV) -> newV));
            JibServiceUtil.copyToContainer(containerBuilder, buildDirs.getOutputDirectory(), buildDirs.getOutputDirectory().getAbsolutePath(), files);
        }
        JibServiceUtil.buildContainer(containerBuilder, TarImage.at(dockerTarArchive.toPath()).named(imageConfig.getName()), log);
        log.info(" %s successfully built", dockerTarArchive.getAbsolutePath());
    } catch (Exception ex) {
        throw new MojoExecutionException("Error when building JIB image", ex);
    }
}
Also used : Arrays(java.util.Arrays) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) ImageName(io.fabric8.maven.docker.util.ImageName) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Logger(io.fabric8.maven.docker.util.Logger) Function(java.util.function.Function) Credential(com.google.cloud.tools.jib.api.Credential) JibServiceUtil(io.fabric8.maven.docker.util.JibServiceUtil) BuildDirs(io.fabric8.maven.docker.assembly.BuildDirs) Map(java.util.Map) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) AuthConfigFactory(io.fabric8.maven.docker.util.AuthConfigFactory) Collection(java.util.Collection) JibServiceUtil.containerFromImageConfiguration(io.fabric8.maven.docker.util.JibServiceUtil.containerFromImageConfiguration) TarImage(com.google.cloud.tools.jib.api.TarImage) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) ArchiveCompression(io.fabric8.maven.docker.config.ArchiveCompression) JibServiceUtil.getBaseImage(io.fabric8.maven.docker.util.JibServiceUtil.getBaseImage) EnvUtil(io.fabric8.maven.docker.util.EnvUtil) AssemblyFiles(io.fabric8.maven.docker.assembly.AssemblyFiles) Credential(com.google.cloud.tools.jib.api.Credential) AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AssemblyFiles(io.fabric8.maven.docker.assembly.AssemblyFiles) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) BuildDirs(io.fabric8.maven.docker.assembly.BuildDirs) File(java.io.File) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 15 with ContainerBuilder

use of io.fabric8.kubernetes.api.model.ContainerBuilder in project vertx-openshift-it by cescoffier.

the class PhantomJSDeployment method createPhantomPod.

private void createPhantomPod() {
    if (!retrievePod()) {
        Container c = new ContainerBuilder().withName(PHANTOMJS).withImage("maschmid/phantomjs").withImagePullPolicy("Always").withEnv(new EnvVar("IGNORE_SSL_ERRORS", "true", null)).withPorts(new ContainerPortBuilder().withContainerPort(4444).withName("webdriver").build()).build();
        Pod pb = new PodBuilder().withNewMetadata().withName(PHANTOMJS).addToLabels("name", PHANTOMJS).endMetadata().withNewSpec().withTerminationGracePeriodSeconds(0L).withDnsPolicy("ClusterFirst").withRestartPolicy("Always").withContainers(c).endSpec().build();
        client.pods().create(pb);
    }
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Aggregations

ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)21 Container (io.fabric8.kubernetes.api.model.Container)13 ArrayList (java.util.ArrayList)9 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)7 Pod (io.fabric8.kubernetes.api.model.Pod)7 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)5 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)5 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)5 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)5 List (java.util.List)5 Map (java.util.Map)5 FlinkPod (org.apache.flink.kubernetes.kubeclient.FlinkPod)5 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)4 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)4 Volume (io.fabric8.kubernetes.api.model.Volume)4 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)4 DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 Service (io.fabric8.kubernetes.api.model.Service)3