Search in sources :

Example 11 with JKubeServiceException

use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.

the class OpenshiftBuildService method buildSingleImage.

@Override
public void buildSingleImage(ImageConfiguration imageConfig) throws JKubeServiceException {
    initClient();
    String buildName = null;
    try {
        final ImageConfiguration.ImageConfigurationBuilder applicableImageConfigBuilder = imageConfig.toBuilder();
        if (imageConfig.getBuildConfiguration() != null && !imageConfig.getBuildConfiguration().isDockerFileMode() && imageConfig.getBuildConfiguration().getAssembly() != null) {
            applicableImageConfigBuilder.build(imageConfig.getBuild().toBuilder().assembly(imageConfig.getBuildConfiguration().getAssembly().getFlattenedClone(jKubeServiceHub.getConfiguration())).build());
        }
        final ImageConfiguration applicableImageConfig = applicableImageConfigBuilder.build();
        ImageName imageName = new ImageName(applicableImageConfig.getName());
        File dockerTar = createBuildArchive(jKubeServiceHub, applicableImageConfig);
        KubernetesListBuilder builder = new KubernetesListBuilder();
        // Check for buildconfig / imagestream / pullSecret and create them if necessary
        String openshiftPullSecret = buildServiceConfig.getOpenshiftPullSecret();
        final boolean usePullSecret = checkOrCreatePullSecret(client, builder, openshiftPullSecret, applicableImageConfig);
        if (usePullSecret) {
            buildName = updateOrCreateBuildConfig(buildServiceConfig, client, builder, applicableImageConfig, openshiftPullSecret);
        } else {
            buildName = updateOrCreateBuildConfig(buildServiceConfig, client, builder, applicableImageConfig, null);
        }
        if (buildServiceConfig.getBuildOutputKind() == null || IMAGE_STREAM_TAG.equals(buildServiceConfig.getBuildOutputKind())) {
            checkOrCreateImageStream(buildServiceConfig, client, builder, resolveImageStreamName(imageName));
            applyBuild(buildName, dockerTar, builder);
            // Create a file with generated image streams
            addImageStreamToFile(getImageStreamFile(), imageName, client);
        } else {
            applyBuild(buildName, dockerTar, builder);
        }
    } catch (JKubeServiceException e) {
        throw e;
    } catch (Exception ex) {
        // Log additional details in case of any IOException
        if (ex.getCause() instanceof IOException) {
            log.error("Build for %s failed: %s", buildName, ex.getCause().getMessage());
            logBuildFailure(client, buildName);
        } else {
            throw new JKubeServiceException("Unable to build the image using the OpenShift build service", ex);
        }
    }
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageName(org.eclipse.jkube.kit.config.image.ImageName) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) IOException(java.io.IOException) File(java.io.File) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) WatcherException(io.fabric8.kubernetes.client.WatcherException) IOException(java.io.IOException)

Example 12 with JKubeServiceException

use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.

the class OpenshiftBuildServiceIntegrationTest method build_withDockerfileModeAndFlattenedAssembly_shouldThrowException.

@Test
public void build_withDockerfileModeAndFlattenedAssembly_shouldThrowException() {
    // Given
    image.setBuild(BuildConfiguration.builder().dockerFile(new File(target, "Dockerfile").getAbsolutePath()).assembly(AssemblyConfiguration.builder().layer(Assembly.builder().id("one").build()).build().getFlattenedClone(jKubeServiceHub.getConfiguration())).build());
    image.getBuildConfiguration().initAndValidate();
    final OpenshiftBuildService openshiftBuildService = new OpenshiftBuildService(jKubeServiceHub);
    // When
    final JKubeServiceException result = assertThrows(JKubeServiceException.class, () -> openshiftBuildService.build(image));
    // Then
    assertThat(result).getCause().hasMessage("This image has already been flattened, you can only flatten the image once");
}
Also used : JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) File(java.io.File) Test(org.junit.Test)

Example 13 with JKubeServiceException

use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.

the class OpenshiftBuildServiceIntegrationTest method testFailedBuild.

@Test
public void testFailedBuild() {
    withBuildServiceConfig(defaultConfig.build());
    final OpenshiftBuildService openshiftBuildService = new OpenshiftBuildService(jKubeServiceHub);
    final JKubeServiceException result = assertThrows(JKubeServiceException.class, () -> openshiftBuildService.build(image));
    assertThat(result).hasMessageContaining("Unable to build the image using the OpenShift build service");
}
Also used : JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Test(org.junit.Test)

Aggregations

JKubeServiceException (org.eclipse.jkube.kit.config.service.JKubeServiceException)13 IOException (java.io.IOException)9 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)6 Test (org.junit.Test)6 File (java.io.File)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 Collections (java.util.Collections)2 List (java.util.List)2 ArchiverCustomizer (org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer)2 ImageName (org.eclipse.jkube.kit.config.image.ImageName)2 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)2 GradleException (org.gradle.api.GradleException)2 Credential (com.google.cloud.tools.jib.api.Credential)1 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)1 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 LocalObjectReferenceBuilder (io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder)1 Status (io.fabric8.kubernetes.api.model.Status)1 WatcherException (io.fabric8.kubernetes.client.WatcherException)1 Build (io.fabric8.openshift.api.model.Build)1