Skip to content

Commit

Permalink
Merge pull request #23054 from ioforks/fix-20987
Browse files Browse the repository at this point in the history
Mounts, ports and environment variables are now added to the application container
  • Loading branch information
iocanel authored Jan 25, 2022
2 parents a0d9e35 + 10a30b7 commit fa039f8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<kotlin.version>1.6.10</kotlin.version>
<kotlin.coroutine.version>1.6.0</kotlin.coroutine.version>
<kotlin-serialization.version>1.3.2</kotlin-serialization.version>
<dekorate.version>2.6.0</dekorate.version>
<dekorate.version>2.8.0</dekorate.version>
<maven-invoker.version>3.0.1</maven-invoker.version>
<awaitility.version>4.1.1</awaitility.version>
<jboss-logmanager.version>1.0.9</jboss-logmanager.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
public class ContainerAdapter {

private static final String ANY = null;

public static Container adapt(io.dekorate.kubernetes.config.Container container) {
String name = container.getName();
if (Strings.isNullOrEmpty(name)) {
Expand All @@ -34,14 +36,14 @@ public static Container adapt(io.dekorate.kubernetes.config.Container container)
.withArgs(container.getArguments());

for (Env env : container.getEnvVars()) {
builder.accept(new AddEnvVarDecorator(env));
builder.accept(new AddEnvVarDecorator(ANY, name, env));
}
for (Port port : container.getPorts()) {
// this was changed to use our patched port decorator
builder.accept(new AddPortDecorator(port));
builder.accept(new AddPortDecorator(ANY, name, port));
}
for (Mount mount : container.getMounts()) {
builder.accept(new AddMountDecorator(mount));
builder.accept(new AddMountDecorator(ANY, name, mount));
}

builder.accept(new ApplyImagePullPolicyDecorator(name, container.getImagePullPolicy()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

public class KubernetesCommonHelper {

private static final String ANY = null;
private static final String OUTPUT_ARTIFACT_FORMAT = "%s%s.jar";
private static final String[] PROMETHEUS_ANNOTATION_TARGETS = { "Service",
"Deployment", "DeploymentConfig" };
Expand Down Expand Up @@ -329,7 +330,7 @@ private static List<DecoratorBuildItem> createAppConfigVolumeAndEnvDecorators(Op
config.getAppSecret().ifPresent(s -> {
result.add(new DecoratorBuildItem(target, new AddSecretVolumeDecorator(new SecretVolumeBuilder()
.withSecretName(s)
.withNewVolumeName("app-secret")
.withVolumeName("app-secret")
.build())));
result.add(new DecoratorBuildItem(target, new AddMountDecorator(new MountBuilder()
.withName("app-secret")
Expand All @@ -341,7 +342,7 @@ private static List<DecoratorBuildItem> createAppConfigVolumeAndEnvDecorators(Op
config.getAppConfigMap().ifPresent(s -> {
result.add(new DecoratorBuildItem(target, new AddConfigMapVolumeDecorator(new ConfigMapVolumeBuilder()
.withConfigMapName(s)
.withNewVolumeName("app-config-map")
.withVolumeName("app-config-map")
.build())));
result.add(new DecoratorBuildItem(target, new AddMountDecorator(new MountBuilder()
.withName("app-config-map")
Expand All @@ -366,7 +367,7 @@ private static List<DecoratorBuildItem> createMountAndVolumeDecorators(Optional<
List<DecoratorBuildItem> result = new ArrayList<>();

config.getMounts().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(target, new AddMountDecorator(MountConverter.convert(e))));
result.add(new DecoratorBuildItem(target, new AddMountDecorator(ANY, name, MountConverter.convert(e))));
});

config.getSecretVolumes().entrySet().forEach(e -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import io.dekorate.kubernetes.annotation.ServiceType;
import io.dekorate.kubernetes.config.EnvBuilder;
import io.dekorate.kubernetes.config.ImageConfiguration;
import io.dekorate.kubernetes.config.ImageConfigurationBuilder;
import io.dekorate.kubernetes.decorator.AddEnvVarDecorator;
import io.dekorate.kubernetes.decorator.AddLabelDecorator;
import io.dekorate.kubernetes.decorator.ApplicationContainerDecorator;
Expand All @@ -27,6 +29,7 @@
import io.dekorate.s2i.config.S2iBuildConfig;
import io.dekorate.s2i.config.S2iBuildConfigBuilder;
import io.dekorate.s2i.decorator.AddBuilderImageStreamResourceDecorator;
import io.dekorate.s2i.decorator.AddDockerImageStreamResourceDecorator;
import io.dekorate.utils.Labels;
import io.fabric8.kubernetes.client.Config;
import io.quarkus.container.image.deployment.ContainerImageConfig;
Expand Down Expand Up @@ -252,6 +255,14 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
&& !capabilities.isPresent("io.quarkus.openshift")
&& !capabilities.isPresent(Capability.CONTAINER_IMAGE_OPENSHIFT)) {
result.add(new DecoratorBuildItem(OPENSHIFT, new RemoveDeploymentTriggerDecorator()));
ImageConfiguration imageConfiguration = new ImageConfigurationBuilder()
.build();

image.ifPresent(i -> {
String repo = i.getRegistry().map(reg -> reg + "/" + i.getRepository()).orElse(i.getRepository());
result.add(new DecoratorBuildItem(OPENSHIFT,
new AddDockerImageStreamResourceDecorator(imageConfiguration, repo)));
});
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.builder.Version;
import io.quarkus.test.ProdBuildResults;
import io.quarkus.test.ProdModeTestResults;
import io.quarkus.test.QuarkusProdModeTest;
Expand All @@ -23,7 +26,11 @@ public class KubernetesWithQuarkusAppNameTest {
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class))
.setApplicationName("kubernetes-with-quarkus-app-name")
.setApplicationVersion("0.1-SNAPSHOT")
.withConfigurationResource("kubernetes-with-quarkus-app-name.properties");
.withConfigurationResource("kubernetes-with-quarkus-app-name.properties")
.setForcedDependencies(
Arrays.asList(
new AppArtifact("io.quarkus", "quarkus-kubernetes", Version.getVersion()),
new AppArtifact("io.quarkus", "quarkus-container-image-s2i", Version.getVersion())));

@ProdBuildResults
private ProdModeTestResults prodModeTestResults;
Expand All @@ -48,7 +55,7 @@ public void assertGeneratedResources() throws IOException {
List<HasMetadata> openshiftList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("openshift.yml"));
assertThat(openshiftList).allSatisfy(h -> {
assertThat(h.getMetadata().getName()).isIn("ofoo", "s2ifoo", "s2i-java");
assertThat(h.getMetadata().getName()).isIn("ofoo", "foo", "openjdk-11");
assertThat(h.getMetadata().getLabels()).contains(entry("app.kubernetes.io/name", "ofoo"),
entry("app.kubernetes.io/version", "1.0-openshift"));
});
Expand Down

0 comments on commit fa039f8

Please sign in to comment.