Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (jkube-kit/config/service) : Preserve Assembly Image Layers for Non-S2I Builds (#2379) #2413

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Usage:
* Fix #2200: Support for Helm `values.yaml` fragments
* Fix #2356: Helm values.yaml parameter names preserve case
* Fix #2369: Helm chart apiVersion can be configured
* Fix #2379: Do not flatten image assembly layers in case of OpenShift Docker build strategy.
* Fix #2386: Helm icon inferred from annotations in independent resource files (not aggregated kubernetes/openshift.yaml)
* Fix #2397: Default JKube work directory (`jkube.workDir`) changed from `${project.build.directory}/jkube` to `${project.build.directory}/jkube-temp`
* Fix #2393: Remove timestamp from `org.label-schema.build-date` LABEL to utilize docker cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.jkube.kit.common.RegistryConfig;
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration;
import org.eclipse.jkube.kit.common.JKubeConfiguration;
import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy;
import org.eclipse.jkube.kit.config.resource.RuntimeMode;
import org.eclipse.jkube.kit.config.service.AbstractImageBuildService;
import org.eclipse.jkube.kit.config.service.BuildServiceConfig;
Expand Down Expand Up @@ -229,7 +230,7 @@ protected String updateOrCreateBuildConfig(BuildServiceConfig config, OpenShiftC
ImageConfiguration getApplicableImageConfiguration(ImageConfiguration imageConfig, RegistryConfig registryConfig) {
final ImageConfiguration.ImageConfigurationBuilder applicableImageConfigBuilder = imageConfig.toBuilder();
if (imageConfig.getBuildConfiguration() != null && !imageConfig.getBuildConfiguration().isDockerFileMode()
&& imageConfig.getBuildConfiguration().getAssembly() != null) {
&& imageConfig.getBuildConfiguration().getAssembly() != null && buildServiceConfig.getJKubeBuildStrategy() != null && buildServiceConfig.getJKubeBuildStrategy().equals(JKubeBuildStrategy.s2i)) {
applicableImageConfigBuilder.build(imageConfig.getBuild().toBuilder().assembly(
imageConfig.getBuildConfiguration().getAssembly().getFlattenedClone(jKubeServiceHub.getConfiguration()))
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@

import io.fabric8.openshift.client.OpenShiftClient;
import org.eclipse.jkube.kit.build.service.docker.ArchiveService;
import org.eclipse.jkube.kit.common.Assembly;
import org.eclipse.jkube.kit.common.AssemblyConfiguration;
import org.eclipse.jkube.kit.common.JKubeConfiguration;
import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.common.KitLogger;
import org.eclipse.jkube.kit.common.RegistryConfig;
import org.eclipse.jkube.kit.config.image.ImageConfiguration;
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration;
import org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy;
import org.eclipse.jkube.kit.config.service.BuildServiceConfig;
import org.eclipse.jkube.kit.config.service.JKubeServiceException;
import org.eclipse.jkube.kit.config.service.JKubeServiceHub;
Expand Down Expand Up @@ -56,6 +61,11 @@ void setUp() {
final OpenShiftClient oc = mock(OpenShiftClient.class);
when(jKubeServiceHub.getClient()).thenReturn(oc);
when(jKubeServiceHub.getClusterAccess().createDefaultClient()).thenReturn(oc);
when(jKubeServiceHub.getConfiguration()).thenReturn(JKubeConfiguration.builder()
.project(JavaProject.builder()
.buildFinalName("test-project")
.build())
.build());
when(oc.adapt(OpenShiftClient.class)).thenReturn(oc);
// @formatter:off
imageConfiguration = ImageConfiguration.builder()
Expand Down Expand Up @@ -154,4 +164,61 @@ void getApplicableImageConfiguration_withRegistryInImageConfiguration_shouldNotA
assertThat(applicableImageConfig)
.hasFieldOrPropertyWithValue("name", "foo/bar:latest");
}

@Test
void getApplicableImageConfiguration_withMultipleLayersAndBuildOutputKindDockerImage_shouldNotFlattenLayers() {
// Given
imageConfiguration = createMultiLayerImageConfiguration();
when(jKubeServiceHub.getBuildServiceConfig()).thenReturn(BuildServiceConfig.builder()
.jKubeBuildStrategy(JKubeBuildStrategy.docker)
.build());
OpenshiftBuildService openshiftBuildService = new OpenshiftBuildService(jKubeServiceHub);

// When
ImageConfiguration applicableImageConfig = openshiftBuildService.getApplicableImageConfiguration(imageConfiguration, RegistryConfig.builder().build());

// Then
assertThat(applicableImageConfig)
.extracting(ImageConfiguration::getBuild)
.extracting(BuildConfiguration::getAssembly)
.extracting(AssemblyConfiguration::getLayers)
.asList()
.hasSize(2);
}

@Test
void getApplicableImageConfiguration_withMultipleLayersAndBuildOutputKindImageStreamTag_shouldFlattenLayers() {
// Given
imageConfiguration = createMultiLayerImageConfiguration();
when(jKubeServiceHub.getBuildServiceConfig()).thenReturn(BuildServiceConfig.builder()
.jKubeBuildStrategy(JKubeBuildStrategy.s2i)
.build());
OpenshiftBuildService openshiftBuildService = new OpenshiftBuildService(jKubeServiceHub);

// When
ImageConfiguration applicableImageConfig = openshiftBuildService.getApplicableImageConfiguration(imageConfiguration, RegistryConfig.builder().build());

// Then
assertThat(applicableImageConfig)
.extracting(ImageConfiguration::getBuild)
.extracting(BuildConfiguration::getAssembly)
.extracting(AssemblyConfiguration::getLayers)
.asList()
.hasSize(1);
}

private ImageConfiguration createMultiLayerImageConfiguration() {
return imageConfiguration.toBuilder()
.build(imageConfiguration.getBuild().toBuilder()
.assembly(AssemblyConfiguration.builder()
.layer(Assembly.builder()
.id("layer1")
.build())
.layer(Assembly.builder()
.id("layer2")
.build())
.build())
.build())
.build();
}
}