Search in sources :

Example 31 with Image

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

the class OpenshiftBuildServiceTest method testFailedBuild.

@Test(expected = Fabric8ServiceException.class)
public void testFailedBuild() throws Exception {
    BuildService.BuildServiceConfig config = defaultConfig.build();
    WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, false, 50, false, false);
    OpenShiftMockServer mockServer = collector.getMockServer();
    OpenShiftClient client = mockServer.createOpenShiftClient();
    OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
    service.build(image);
}
Also used : OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) BuildService(io.fabric8.maven.core.service.BuildService) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Test(org.junit.Test)

Example 32 with Image

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

the class OpenshiftBuildServiceTest method testSuccessfulSecondBuild.

@Test
public void testSuccessfulSecondBuild() throws Exception {
    int nTries = 0;
    boolean bTestComplete = false;
    do {
        try {
            nTries++;
            BuildService.BuildServiceConfig config = defaultConfig.build();
            WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, true, true);
            OpenShiftMockServer mockServer = collector.getMockServer();
            OpenShiftClient client = mockServer.createOpenShiftClient();
            OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
            service.build(image);
            assertTrue(mockServer.getRequestCount() > 8);
            collector.assertEventsRecordedInOrder("build-config-check", "patch-build-config", "pushed");
            collector.assertEventsNotRecorded("new-build-config");
            bTestComplete = true;
        } catch (Fabric8ServiceException exception) {
            Throwable rootCause = getRootCause(exception);
            logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
            // Let's wait for a while, and then retry again
            if (rootCause != null && rootCause instanceof IOException) {
                continue;
            }
        }
    } while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
Also used : OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) BuildService(io.fabric8.maven.core.service.BuildService) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) IOException(java.io.IOException) Test(org.junit.Test)

Example 33 with Image

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

the class OpenshiftBuildServiceTest method init.

@Before
public void init() throws Exception {
    final File dockerFile = new File(baseDir, "Docker.tar");
    dockerFile.getParentFile().mkdirs();
    dockerFile.createNewFile();
    imageStreamFile.delete();
    new Expectations() {

        {
            dockerServiceHub.getArchiveService();
            result = archiveService;
            archiveService.createDockerBuildArchive(withAny(ImageConfiguration.class.cast(null)), withAny(MojoParameters.class.cast(null)));
            result = dockerFile;
            minTimes = 0;
            project.getArtifact();
            result = "myapp";
            minTimes = 0;
            dockerMojoParameters.getProject();
            result = project;
            minTimes = 0;
        }
    };
    image = new ImageConfiguration.Builder().name(projectName).buildConfig(new BuildImageConfiguration.Builder().from(projectName).build()).build();
    defaultConfig = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-s2i-suffix2").openshiftBuildStrategy(OpenShiftBuildStrategy.s2i).dockerMojoParameters(dockerMojoParameters);
}
Also used : Expectations(mockit.Expectations) BuildService(io.fabric8.maven.core.service.BuildService) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Before(org.junit.Before)

Example 34 with Image

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

the class DefaultControllerEnricher method addMissingResources.

@Override
public void addMissingResources(KubernetesListBuilder builder) {
    final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()));
    final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getConfig(Config.pullPolicy)).withReplicas(Configs.asInt(getConfig(Config.replicaCount))).build();
    final List<ImageConfiguration> images = getImages();
    // Check if at least a replica set is added. If not add a default one
    if (!KubernetesResourceUtil.checkForKind(builder, POD_CONTROLLER_KINDS)) {
        // At least one image must be present, otherwise the resulting config will be invalid
        if (!Lists.isNullOrEmpty(images)) {
            String type = getConfig(Config.type);
            if ("deployment".equalsIgnoreCase(type)) {
                log.info("Adding a default Deployment");
                builder.addToDeploymentItems(deployHandler.getDeployment(config, images));
            } else if ("statefulSet".equalsIgnoreCase(type)) {
                log.info("Adding a default StatefulSet");
                builder.addToStatefulSetItems(statefulSetHandler.getStatefulSet(config, images));
            } else if ("daemonSet".equalsIgnoreCase(type)) {
                log.info("Adding a default DaemonSet");
                builder.addToDaemonSetItems(daemonSetHandler.getDaemonSet(config, images));
            } else if ("replicaSet".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicaSet");
                builder.addToReplicaSetItems(rsHandler.getReplicaSet(config, images));
            } else if ("replicationController".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicationController");
                builder.addToReplicationControllerItems(rcHandler.getReplicationController(config, images));
            } else if ("job".equalsIgnoreCase(type)) {
                log.info("Adding a default Job");
                builder.addToJobItems(jobHandler.getJob(config, images));
            }
        }
    } else if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
        final StatefulSetSpec spec = statefulSetHandler.getStatefulSet(config, images).getSpec();
        if (spec != null) {
            builder.accept(new TypedVisitor<StatefulSetBuilder>() {

                @Override
                public void visit(StatefulSetBuilder statefulSetBuilder) {
                    statefulSetBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                    mergeStatefulSetSpec(statefulSetBuilder, spec);
                }
            });
            if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                final PodSpec podSpec = spec.getTemplate().getSpec();
                builder.accept(new TypedVisitor<PodSpecBuilder>() {

                    @Override
                    public void visit(PodSpecBuilder builder) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    } else {
        final DeploymentSpec spec = deployHandler.getDeployment(config, images).getSpec();
        if (spec != null) {
            builder.accept(new TypedVisitor<DeploymentBuilder>() {

                @Override
                public void visit(DeploymentBuilder deploymentBuilder) {
                    deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                    mergeDeploymentSpec(deploymentBuilder, spec);
                }
            });
            if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                final PodSpec podSpec = spec.getTemplate().getSpec();
                builder.accept(new TypedVisitor<PodSpecBuilder>() {

                    @Override
                    public void visit(PodSpecBuilder builder) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    }
}
Also used : TypedVisitor(io.fabric8.kubernetes.api.builder.TypedVisitor) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) StatefulSetSpec(io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Example 35 with Image

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

the class DefaultServiceEnricher method extractPorts.

// ========================================================================================================
// Port handling
private List<ServicePort> extractPorts(List<ImageConfiguration> images) {
    List<ServicePort> ret = new ArrayList<>();
    boolean isMultiPort = Boolean.parseBoolean(getConfig(Config.multiPort));
    List<ServicePort> configuredPorts = extractPortsFromConfig();
    for (ImageConfiguration image : images) {
        List<String> podPorts = getPortsFromBuildConfiguration(image);
        if (podPorts.isEmpty()) {
            continue;
        }
        // Extract first port and remove first element
        addPortIfNotNull(ret, extractPortsFromImageSpec(image.getName(), podPorts.remove(0), shiftOrNull(configuredPorts)));
        // Remaining port specs if multi-port is selected
        if (isMultiPort) {
            for (String port : podPorts) {
                addPortIfNotNull(ret, extractPortsFromImageSpec(image.getName(), port, shiftOrNull(configuredPorts)));
            }
        }
    }
    // If there are still ports configured add them directly
    if (isMultiPort) {
        ret.addAll(mirrorMissingTargetPorts(configuredPorts));
    } else if (ret.isEmpty() && !configuredPorts.isEmpty()) {
        ret.addAll(mirrorMissingTargetPorts(Collections.singletonList(configuredPorts.get(0))));
    }
    return ret;
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration)

Aggregations

Test (org.junit.Test)35 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)28 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)20 IOException (java.io.IOException)16 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)15 File (java.io.File)13 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)12 ImageStream (io.fabric8.openshift.api.model.ImageStream)10 Arguments (io.fabric8.maven.docker.config.Arguments)8 Service (io.fabric8.kubernetes.api.model.Service)7 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)7 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)6 BuildService (io.fabric8.maven.core.service.BuildService)6 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)6 HashMap (java.util.HashMap)6 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)5 ImageName (io.fabric8.maven.docker.util.ImageName)5 ImageStreamTag (io.fabric8.openshift.api.model.ImageStreamTag)5