diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftProcessor.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftProcessor.java index d0ca1f7d10e4b..ab3f4f5a3fb7d 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftProcessor.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftProcessor.java @@ -335,31 +335,28 @@ public List createDecorators(ApplicationInfoBuildItem applic ports, config.ports)); - // Handle non-openshift builds - if (deploymentKind == DeploymentResourceKind.DeploymentConfig - && !OpenshiftConfig.isOpenshiftBuildEnabled(containerImageConfig, capabilities)) { - image.ifPresent(i -> { - String registry = i.registry - .or(() -> containerImageConfig.registry) - .orElse(fallbackRegistry.map(f -> f.getRegistry()).orElse(DOCKERIO_REGISTRY)); - String repositoryWithRegistry = registry + "/" + i.getRepository(); - ImageConfiguration imageConfiguration = new ImageConfigurationBuilder() - .withName(name) - .withRegistry(registry) - .build(); - + image.ifPresent(i -> { + String registry = i.registry + .or(() -> containerImageConfig.registry) + .orElse(fallbackRegistry.map(f -> f.getRegistry()).orElse(DOCKERIO_REGISTRY)); + String repositoryWithRegistry = registry + "/" + i.getRepository(); + ImageConfiguration imageConfiguration = new ImageConfigurationBuilder() + .withName(name) + .withRegistry(registry) + .build(); + + String imageStreamWithTag = name + ":" + i.getTag(); + if (deploymentKind == DeploymentResourceKind.DeploymentConfig + && !OpenshiftConfig.isOpenshiftBuildEnabled(containerImageConfig, capabilities)) { result.add(new DecoratorBuildItem(OPENSHIFT, new AddDockerImageStreamResourceDecorator(imageConfiguration, repositoryWithRegistry))); - String imageStreamWithTag = name + ":" + i.getTag(); - result.add(new DecoratorBuildItem(OPENSHIFT, new ApplyContainerImageDecorator(name, imageStreamWithTag))); - // remove the default trigger which has a wrong version - result.add(new DecoratorBuildItem(OPENSHIFT, new RemoveDeploymentTriggerDecorator(name))); - // re-add the trigger with the correct version - result.add(new DecoratorBuildItem(OPENSHIFT, new ChangeDeploymentTriggerDecorator(name, imageStreamWithTag))); - }); - } else if (image.isPresent()) { - result.add(new DecoratorBuildItem(OPENSHIFT, new ApplyContainerImageDecorator(name, image.get().getImage()))); - } + } + result.add(new DecoratorBuildItem(OPENSHIFT, new ApplyContainerImageDecorator(name, i.getImage()))); + // remove the default trigger which has a wrong version + result.add(new DecoratorBuildItem(OPENSHIFT, new RemoveDeploymentTriggerDecorator(name))); + // re-add the trigger with the correct version + result.add(new DecoratorBuildItem(OPENSHIFT, new ChangeDeploymentTriggerDecorator(name, imageStreamWithTag))); + }); // Handle remote debug configuration if (config.remoteDebug.enabled) { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerAndImageTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerAndImageTest.java index ac72f534352ab..422b108a16baa 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerAndImageTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerAndImageTest.java @@ -49,7 +49,7 @@ public void assertGeneratedResources() throws IOException { }); assertThat(h).isInstanceOfSatisfying(DeploymentConfig.class, d -> { Container container = d.getSpec().getTemplate().getSpec().getContainers().get(0); - assertThat(container.getImage()).isEqualTo(APP_NAME + ":1.0"); + assertThat(container.getImage()).isEqualTo("quay.io/user/app:1.0"); DeploymentTriggerImageChangeParams imageTriggerParams = d.getSpec().getTriggers().get(0).getImageChangeParams(); assertThat(imageTriggerParams.getFrom().getKind()).isEqualTo("ImageStreamTag"); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithImageTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithImageTest.java new file mode 100644 index 0000000000000..a9801c3687225 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithImageTest.java @@ -0,0 +1,69 @@ +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.Container; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.openshift.api.model.DeploymentConfig; +import io.fabric8.openshift.api.model.DeploymentTriggerImageChangeParams; +import io.fabric8.openshift.api.model.ImageStream; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithImageTest { + + private static final String APP_NAME = "openshift-with-image"; + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName(APP_NAME) + .setApplicationVersion("0.1-SNAPSHOT") + .overrideConfigKey("quarkus.container-image.image", "user/app:2.0") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + + assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); + List openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo(APP_NAME); + }); + assertThat(h).isInstanceOfSatisfying(DeploymentConfig.class, d -> { + Container container = d.getSpec().getTemplate().getSpec().getContainers().get(0); + assertThat(container.getImage()).endsWith("user/app:2.0"); + + DeploymentTriggerImageChangeParams imageTriggerParams = d.getSpec().getTriggers().get(0).getImageChangeParams(); + assertThat(imageTriggerParams.getFrom().getKind()).isEqualTo("ImageStreamTag"); + assertThat(imageTriggerParams.getFrom().getName()).isEqualTo(APP_NAME + ":2.0"); + }); + }); + + assertThat(openshiftList) + .filteredOn(h -> "ImageStream".equals(h.getKind()) && h.getMetadata().getName().equals(APP_NAME)) + .singleElement().satisfies(h -> { + assertThat(h).isInstanceOfSatisfying(ImageStream.class, i -> { + assertThat(i.getSpec().getDockerImageRepository()).isNull(); + }); + }); + + } +}