Skip to content
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
8 changes: 7 additions & 1 deletion bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<awssdk.version>2.8.0</awssdk.version>
<azure-functions-java-library.version>1.3.0</azure-functions-java-library.version>
<kotlin.version>1.3.41</kotlin.version>
<dekorate.version>0.9.3</dekorate.version>
<dekorate.version>0.9.4</dekorate.version>
<maven-artifact-transfer.version>0.10.0</maven-artifact-transfer.version>
<jline.version>2.14.6</jline.version>
<maven-invoker.version>3.0.1</maven-invoker.version>
Expand Down Expand Up @@ -728,6 +728,12 @@
<version>${dekorate.version}</version>
<classifier>noapt</classifier>
</dependency>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>openshift-annotations</artifactId>
<version>${dekorate.version}</version>
<classifier>noapt</classifier>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
Expand Down
67 changes: 66 additions & 1 deletion docs/src/main/asciidoc/kubernetes-resources.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ mvn io.quarkus:quarkus-maven-plugin:{quarkus-version}:create \
== Enable Kubernetes support

Quarkus offers the ability to automatically generate Kubernetes resources based on sane defaults and user supplied configuration. The implementation that takes care
of generating the actual Kubernetes resources is provided by https://github.com/dekorateio/dekorate/[dekorate].
of generating the actual Kubernetes resources is provided by https://github.com/dekorateio/dekorate/[dekorate]. Currently it supports the generation of resources for
vanilla Kubernetes and Openshift.

When we added the `kubernetes` extension to the command line invocation above, the following dependency was added to the `pom.xml`

Expand Down Expand Up @@ -392,4 +393,68 @@ Below you will find tables describing all available types.
| registry | String | | |
| auto-push-enabled | boolean | | false
| auto-build-enabled | boolean | | false
|====

=== Openshift support

To enable the generation of Openshift resources, you need to include Openshift in the target platforms:

[source]
----
kubernetes.deployment.target=openshift
----

If you need to generate resources for both platforms (vanilla kubernetes and opesnhift), then you need to include both (coma separated).

[source]
----
kubernetes.deployment.target=kubernetes, openshift
----

The Openshfit resources can be customized in a similar approach with kubernetes.

.Openshift
|====
| Property | Type | Description | Default Value
| openshift.group | String | |
| openshift.name | String | |
| openshift.version | String | |
| openshift.init-containers | Container[] | |
| openshift.labels | Label[] | |
| openshift.annotations | Annotation[] | |
| openshift.env-vars | Env[] | |
| openshift.working-dir | String | |
| openshift.command | String[] | |
| openshift.arguments | String[] | |
| openshift.replicas | int | | 1
| openshift.service-account | String | |
| openshift.host | String | |
| openshift.ports | Port[] | |
| openshift.service-type | ServiceType | | ClusterIP
| openshift.pvc-volumes | PersistentVolumeClaimVolume[] | |
| openshift.secret-volumes | SecretVolume[] | |
| openshift.config-map-volumes | ConfigMapVolume[] | |
| openshift.git-repo-volumes | GitRepoVolume[] | |
| openshift.aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | |
| openshift.azure-disk-volumes | AzureDiskVolume[] | |
| openshift.azure-file-volumes | AzureFileVolume[] | |
| openshift.mounts | Mount[] | |
| openshift.image-pull-policy | ImagePullPolicy | | IfNotPresent
| openshift.image-pull-secrets | String[] | |
| openshift.liveness-probe | Probe | | ( see Probe )
| openshift.readiness-probe | Probe | | ( see Probe )
| openshift.sidecars | Container[] | |
| openshift.expose | boolean | | false
| openshift.auto-deploy-enabled | boolean | | false
|====

.S2i
|====
| Property | Type | Description | Default Value
| s2i.enabled | boolean | | true
| s2i.registry | String | |
| s2i.builder-image | String | | fabric8/s2i-java:2.3
| s2i.build-env-vars | Env[] | |
| s2i.auto-push-enabled | boolean | | false
| s2i.auto-build-enabled | boolean | | false
|====
11 changes: 11 additions & 0 deletions extensions/kubernetes/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>openshift-annotations</artifactId>
<classifier>noapt</classifier>
<exclusions>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -48,6 +49,9 @@ class KubernetesProcessor {
private static final String PROPERTY_PREFIX = "dekorate.";
private static final String ALLOWED_GENERATOR = "kubernetes";

private static final String DEPLOYMENT_TARGET = "kubernetes.deployment.target";
private static final String KUBERNETES = "kubernetes";

@Inject
BuildProducer<GeneratedFileSystemResourceBuildItem> generatedResourceProducer;

Expand Down Expand Up @@ -79,6 +83,12 @@ public void build(ApplicationInfoBuildItem applicationInfo,
}

Config config = ConfigProvider.getConfig();
List<String> deploymentTargets = Arrays
.stream(config.getOptionalValue(DEPLOYMENT_TARGET, String.class)
.orElse(KUBERNETES).split(","))
.map(String::trim)
.collect(Collectors.toList());

Map<String, Object> configAsMap = StreamSupport.stream(config.getPropertyNames().spliterator(), false)
.filter(k -> ALLOWED_GENERATOR.equals(generatorName(k)))
.collect(Collectors.toMap(k -> PROPERTY_PREFIX + k, k -> config.getValue(k, String.class)));
Expand All @@ -90,17 +100,27 @@ public void build(ApplicationInfoBuildItem applicationInfo,
session.setWriter(sessionWriter);
session.feed(Maps.fromProperties(configAsMap));

//Apply build item configurations to the dekorate session.
//apply build item configurations to the dekorate session.
applyBuildItems(session, applicationInfo, kubernetesPortBuildItems, kubernetesHealthLivenessPathBuildItem,
kubernetesHealthReadinessPathBuildItem);

// write the generated resources to the filesystem
final Map<String, String> generatedResourcesMap = session.close();
for (Map.Entry<String, String> resourceEntry : generatedResourcesMap.entrySet()) {
String fileName = resourceEntry.getKey().replace(root.toAbsolutePath().toString(), "");
String relativePath = resourceEntry.getKey().replace(root.toAbsolutePath().toString(), "kubernetes");
if (relativePath.startsWith("kubernetes" + File.separator + ".")) { // ignore some of Dekorate's internal files
continue;

if (fileName.endsWith(".yml") || fileName.endsWith(".json")) {
String target = fileName.substring(0, fileName.lastIndexOf("."));
if (target.startsWith(File.separator)) {
target = target.substring(1);
}

if (!deploymentTargets.contains(target)) {
continue;
}
}

generatedResourceProducer.produce(
new GeneratedFileSystemResourceBuildItem(
// we need to make sure we are only passing the relative path to the build item
Expand Down Expand Up @@ -159,7 +179,8 @@ private Project createProject(ApplicationInfoBuildItem app, ArchiveRootBuildItem
//Let dekorate create a Project instance and then override with what is found in ApplicationInfoBuildItem.
Project project = FileProjectFactory.create(archiveRootBuildItem.getArchiveLocation().toFile());
BuildInfo buildInfo = new BuildInfo(app.getName(), app.getVersion(),
"jar", project.getBuildInfo().getOutputFile(),
"jar", project.getBuildInfo().getBuildTool(),
project.getBuildInfo().getOutputFile(),
project.getBuildInfo().getClassOutputDir());

return new Project(project.getRoot(), buildInfo, project.getScmInfo());
Expand Down
5 changes: 5 additions & 0 deletions integration-tests/kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<artifactId>kubernetes-annotations</artifactId>
<classifier>noapt</classifier>
</dependency>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>openshift-annotations</artifactId>
<classifier>noapt</classifier>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>kubernetes-with-smallrye-health</artifactId>
<artifactId>kubernetes-with-application-properties</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down
117 changes: 117 additions & 0 deletions integration-tests/kubernetes/src/it/openshift/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>openshift</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>@project.version@</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.acme;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class Hello {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}
Loading