-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dev services for kubernetes
- Loading branch information
1 parent
3e8eafb
commit 7937f2a
Showing
10 changed files
with
698 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
415 changes: 415 additions & 0 deletions
415
...src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java
Large diffs are not rendered by default.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
.../src/main/java/io/quarkus/kubernetes/client/deployment/NoQuarkusTestKubernetesClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkus.kubernetes.client.deployment; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.BooleanSupplier; | ||
|
||
class NoQuarkusTestKubernetesClient implements BooleanSupplier { | ||
static final String IO_QUARKUS_TEST_KUBERNETES_CLIENT_PACKAGE = "io.quarkus.test.kubernetes.client"; | ||
static final Boolean IO_QUARKUS_TEST_KUBERNETES_CLIENT_AVAILABLE = Arrays.asList(Package.getPackages()) | ||
.stream() | ||
.map(p -> p.getName()).anyMatch(p -> p.startsWith(IO_QUARKUS_TEST_KUBERNETES_CLIENT_PACKAGE)); | ||
|
||
@Override | ||
public boolean getAsBoolean() { | ||
return !IO_QUARKUS_TEST_KUBERNETES_CLIENT_AVAILABLE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
.../main/java/io/quarkus/kubernetes/client/runtime/KubernetesDevServicesBuildTimeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package io.quarkus.kubernetes.client.runtime; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class KubernetesDevServicesBuildTimeConfig { | ||
|
||
/** | ||
* If dev services for Kubernetes should be used. (default to true) | ||
* | ||
* If this is true and kubernetes client is not configured then a kubernetes cluster | ||
* will be started and will be used. | ||
*/ | ||
@ConfigItem(defaultValue = "true") | ||
public boolean enabled; | ||
|
||
/** | ||
* The kubernetes api server version to use. | ||
* | ||
* If not set, dev services for Kubernetes will use the latest supported version of the given flavor. | ||
* see https://github.com/dajudge/kindcontainer/blob/master/k8s-versions.json | ||
*/ | ||
@ConfigItem | ||
public Optional<String> apiVersion; | ||
|
||
/** | ||
* The flavor to use (kind, s3 or api-only). Default to api-only. | ||
*/ | ||
@ConfigItem(defaultValue = "API_ONLY") | ||
public Flavor flavor; | ||
|
||
/** | ||
* By default, if a kubeconfig is found, dev services for Kubernetes will not start. | ||
* Set this to true to override the kubeconfig config. | ||
*/ | ||
@ConfigItem(defaultValue = "false") | ||
public boolean overrideKubeconfig; | ||
|
||
/** | ||
* Indicates if the Kubernetes cluster managed by Quarkus Dev Services is shared. | ||
* When shared, Quarkus looks for running containers using label-based service discovery. | ||
* If a matching container is found, it is used, and so a second one is not started. | ||
* Otherwise, Dev Services for Kubernetes starts a new container. | ||
* <p> | ||
* The discovery uses the {@code quarkus-dev-service-kubernetes} label. | ||
* The value is configured using the {@code service-name} property. | ||
* <p> | ||
* Container sharing is only used in dev mode. | ||
*/ | ||
@ConfigItem(defaultValue = "true") | ||
public boolean shared; | ||
|
||
/** | ||
* The value of the {@code quarkus-dev-service-kubernetes} label attached to the started container. | ||
* This property is used when {@code shared} is set to {@code true}. | ||
* In this case, before starting a container, Dev Services for Kubernetes looks for a container with the | ||
* {@code quarkus-dev-service-kubernetes} label | ||
* set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it | ||
* starts a new container with the {@code quarkus-dev-service-kubernetes} label set to the specified value. | ||
* <p> | ||
* This property is used when you need multiple shared Kubernetes clusters. | ||
*/ | ||
@ConfigItem(defaultValue = "kubernetes") | ||
public String serviceName; | ||
|
||
public static enum Flavor { | ||
/** | ||
* kind (needs priviledge docker) | ||
*/ | ||
KIND, | ||
/** | ||
* k3s (needs priviledge docker) | ||
*/ | ||
K3S, | ||
/** | ||
* api only | ||
*/ | ||
API_ONLY; | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
integration-tests/kubernetes-client-devservices/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?xml version="1.0"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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> | ||
<parent> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-integration-tests-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>quarkus-integration-test-kubernetes-client-devservices</artifactId> | ||
<name>Quarkus - Integration Tests - Kubernetes Client DevService</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-kubernetes-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-kubernetes-client-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<!-- Note: the container is started via Dev Services --> | ||
<profile> | ||
<id>test-kubernetes-client</id> | ||
<activation> | ||
<property> | ||
<name>test-containers</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skip>false</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<configuration> | ||
<skip>false</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
Empty file.
27 changes: 27 additions & 0 deletions
27
...src/test/java/io/quarkus/kubernetes/client/devservices/it/DevServicesKubernetesITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.kubernetes.client.devservices.it; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.quarkus.kubernetes.client.devservices.it.profiles.DevServiceKubernetes; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@QuarkusTest | ||
@TestProfile(DevServiceKubernetes.class) | ||
public class DevServicesKubernetesITest { | ||
|
||
@Inject | ||
KubernetesClient kubernetesClient; | ||
|
||
@Test | ||
@DisplayName("given kubernetes container must communicate with it and return its version") | ||
public void shouldReturnAllKeys() { | ||
Assertions.assertEquals("v" + DevServiceKubernetes.API_VERSION, | ||
kubernetesClient.getKubernetesVersion().getGitVersion()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../test/java/io/quarkus/kubernetes/client/devservices/it/profiles/DevServiceKubernetes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.kubernetes.client.devservices.it.profiles; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
|
||
public class DevServiceKubernetes implements QuarkusTestProfile { | ||
|
||
public static final String API_VERSION = "1.24.1"; | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
|
||
return Collections.singletonMap("quarkus.kubernetes-client.devservices.api-version", API_VERSION); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters