Skip to content

Commit

Permalink
feat: add dev services for kubernetes
Browse files Browse the repository at this point in the history
  • Loading branch information
scrocquesel committed Oct 2, 2022
1 parent 3e8eafb commit 7937f2a
Show file tree
Hide file tree
Showing 10 changed files with 698 additions and 0 deletions.
15 changes: 15 additions & 0 deletions extensions/kubernetes-client/deployment-internal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devservices-deployment</artifactId>
</dependency>
<dependency>
<groupId>com.dajudge.kindcontainer</groupId>
<artifactId>kindcontainer</artifactId>
<version>1.3.0</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down

Large diffs are not rendered by default.

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,10 @@ public class KubernetesClientBuildConfig {
@ConfigItem(defaultValue = "true")
public boolean generateRbac;

/**
* Config for dev services
*/
@ConfigItem
public KubernetesDevServicesBuildTimeConfig devservices;

}
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 integration-tests/kubernetes-client-devservices/pom.xml
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.
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());
}
}
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);
}
}
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<module>container-image</module>
<module>kubernetes</module>
<module>kubernetes-client</module>
<module>kubernetes-client-devservices</module>
<module>kubernetes-service-binding-jdbc</module>
<module>kubernetes-service-binding-reactive</module>
<module>openshift-client</module>
Expand Down

0 comments on commit 7937f2a

Please sign in to comment.