Search in sources :

Example 16 with ImageName

use of org.eclipse.jkube.kit.config.image.ImageName in project jkube by eclipse.

the class OpenShiftBuildServiceUtilsTest method computeS2IBuildName_withImageNameAndEmptyBuildServiceConfig_shouldReturnName.

@Test
public void computeS2IBuildName_withImageNameAndEmptyBuildServiceConfig_shouldReturnName() {
    // Given
    final ImageName imageName = new ImageName("registry/name:tag");
    // When
    final String result = computeS2IBuildName(new BuildServiceConfig(), imageName);
    // Then
    assertThat(result).isEqualTo("name");
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) ImageName(org.eclipse.jkube.kit.config.image.ImageName) Test(org.junit.Test)

Example 17 with ImageName

use of org.eclipse.jkube.kit.config.image.ImageName in project jkube by eclipse.

the class OpenShiftBuildServiceUtilsTest method computeS2IBuildName_withImageNameAndBuildServiceWithS2I_shouldReturnNameWithDefaultSuffix.

@Test
public void computeS2IBuildName_withImageNameAndBuildServiceWithS2I_shouldReturnNameWithDefaultSuffix() {
    // Given
    final BuildServiceConfig buildServiceConfig = BuildServiceConfig.builder().jKubeBuildStrategy(JKubeBuildStrategy.s2i).buildDirectory(temporaryFolder.getRoot().getAbsolutePath()).build();
    final ImageName imageName = new ImageName("registry/name:tag");
    // When
    final String result = computeS2IBuildName(buildServiceConfig, imageName);
    // Then
    assertThat(result).isEqualTo("name-s2i");
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) ImageName(org.eclipse.jkube.kit.config.image.ImageName) Test(org.junit.Test)

Example 18 with ImageName

use of org.eclipse.jkube.kit.config.image.ImageName in project jkube by eclipse.

the class KubernetesClientUtil method deleteOpenShiftEntities.

public static void deleteOpenShiftEntities(KubernetesClient kubernetes, String namespace, Collection<HasMetadata> entities, String s2iBuildNameSuffix, KitLogger log) {
    // For OpenShift cluster, also delete s2i buildconfig
    OpenShiftClient openshiftClient = OpenshiftHelper.asOpenShiftClient(kubernetes);
    if (openshiftClient == null) {
        return;
    }
    for (HasMetadata entity : entities) {
        if ("ImageStream".equals(KubernetesHelper.getKind(entity))) {
            ImageName imageName = new ImageName(entity.getMetadata().getName());
            String buildName = getS2IBuildName(imageName, s2iBuildNameSuffix);
            log.info("Deleting resource BuildConfig %s/%s and Builds", namespace, buildName);
            openshiftClient.builds().inNamespace(namespace).withLabel("buildconfig", buildName).delete();
            openshiftClient.buildConfigs().inNamespace(namespace).withName(buildName).delete();
        }
    }
}
Also used : ImageName(org.eclipse.jkube.kit.config.image.ImageName) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient)

Example 19 with ImageName

use of org.eclipse.jkube.kit.config.image.ImageName 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 20 with ImageName

use of org.eclipse.jkube.kit.config.image.ImageName in project jkube by eclipse.

the class ContainerHandler method getImageName.

private String getImageName(ImageConfiguration imageConfiguration) {
    if (StringUtils.isBlank(imageConfiguration.getName())) {
        return null;
    }
    Properties props = getPropertiesWithSystemOverrides(this.configurationProperties);
    String configuredRegistry = EnvUtil.firstRegistryOf(imageConfiguration.getRegistry(), props.getProperty("jkube.docker.pull.registry"), props.getProperty("jkube.docker.registry"));
    return new ImageName(imageConfiguration.getName()).getFullName(configuredRegistry);
}
Also used : ImageName(org.eclipse.jkube.kit.config.image.ImageName) Properties(java.util.Properties)

Aggregations

ImageName (org.eclipse.jkube.kit.config.image.ImageName)22 BuildServiceConfig (org.eclipse.jkube.kit.config.service.BuildServiceConfig)6 Test (org.junit.Test)6 IOException (java.io.IOException)5 BuildOutput (io.fabric8.openshift.api.model.BuildOutput)4 OpenShiftBuildServiceUtils.createBuildOutput (org.eclipse.jkube.kit.config.service.openshift.OpenShiftBuildServiceUtils.createBuildOutput)4 AuthConfig (org.eclipse.jkube.kit.build.api.auth.AuthConfig)3 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 WatcherException (io.fabric8.kubernetes.client.WatcherException)2 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)2 BuildConfigSpec (io.fabric8.openshift.api.model.BuildConfigSpec)2 BuildStrategy (io.fabric8.openshift.api.model.BuildStrategy)2 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)2 File (java.io.File)2 Map (java.util.Map)2 DockerAccessException (org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException)2 AuthConfigFactory (org.eclipse.jkube.kit.build.service.docker.auth.AuthConfigFactory)2 OpenShiftBuildServiceUtils.createBuildStrategy (org.eclipse.jkube.kit.config.service.openshift.OpenShiftBuildServiceUtils.createBuildStrategy)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1