Skip to content

Commit

Permalink
feat: document 2.2.0-beta, fix: test were failing because temporary p…
Browse files Browse the repository at this point in the history
…roperty was static
  • Loading branch information
JeanBaptisteWATENBERG committed Sep 8, 2020
1 parent 40c7495 commit fec2422
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@ It hence fills the lack of kubernetes support of testcontainers while the librar
<dependency>
<groupId>com.github.jeanbaptistewatenberg.junit5kubernetes</groupId>
<artifactId>core</artifactId>
<version>2.1.0</version>
<version>2.2.0-beta</version>
<scope>test</scope>
</dependency>
```

## Gradle installation

```
testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:core:2.1.0")
testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:core:2.2.0-beta")
```

## *NEW* 2.2.0-beta Usage

Version `2.2.0-beta` introduces a new java property `junitKubernetesUsePortService`,
when it is set to true it will create a `NodePort` service aside of your pods in order to ease pods access from outside your kubernetes cluster.

I am going to test this approach in the upcoming days and stabilize it if I see some benefits from using it.

If you want to test it out you can refer to [TestUsingNodePortService.java](./core/src/test/java/com/github/jeanbaptistewatenberg/junit5kubernetes/core/TestUsingNodePortService.java) and feel free to report

## Usage

```java
Expand Down Expand Up @@ -96,14 +105,14 @@ Available `WaitStrategies` are :
<dependency>
<groupId>com.github.jeanbaptistewatenberg.junit5kubernetes</groupId>
<artifactId>postgresql</artifactId>
<version>2.1.0</version>
<version>2.2.0-beta</version>
</dependency>
```

#### Gradle

```
testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:postgresql:2.1.0")
testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:postgresql:2.2.0-beta")
```

#### Usage
Expand Down Expand Up @@ -143,14 +152,14 @@ public class Test {
<dependency>
<groupId>com.github.jeanbaptistewatenberg.junit5kubernetes</groupId>
<artifactId>rabbitmq</artifactId>
<version>2.1.0</version>
<version>2.2.0-beta</version>
</dependency>
```

#### Gradle

```
testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:rabbitmq:2.1.0")
testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:rabbitmq:2.2.0-beta")
```

#### Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public class Pod extends KubernetesGenericObject<Pod> {
protected static final String SYSTEM_PULL_SECRETS = System.getProperty("kubernetesPullSecrets");
protected static final String DEBUG = System.getProperty("junitKubernetesDebug");
protected static final String DISABLE_HTTP2 = System.getProperty("junitKubernetesDisableHttp2");
protected static final String USE_NODE_PORT_SERVICE = System.getProperty("junitKubernetesUsePortService");
protected static final String NAMESPACE = SYSTEM_NAMESPACE != null && !SYSTEM_NAMESPACE.trim().equals("") ? SYSTEM_NAMESPACE : "default";
private static final Logger LOGGER = Logger.getLogger(Pod.class.getName());
protected final String USE_NODE_PORT_SERVICE = System.getProperty("junitKubernetesUsePortService");
protected final CoreV1Api coreV1Api;
private final List<FileToMountOnceStarted> filesToMountOnceStarted = new ArrayList<>();
private Map<Integer, Integer> mappedPorts = new HashMap<>();
Expand Down Expand Up @@ -304,7 +304,7 @@ public void create() {
onBeforeCreateKubernetesObject();
podToCreate.getMetadata().putLabelsItem(JUNIT_5_KUBERNETES_LABEL, podName);
List<V1ServicePort> ports = new ArrayList<>();
if (USE_NODE_PORT_SERVICE.equalsIgnoreCase("true")) {
if (USE_NODE_PORT_SERVICE != null && USE_NODE_PORT_SERVICE.equalsIgnoreCase("true")) {
ports = podToCreate.getSpec().getContainers().stream().flatMap(container -> {
if (container.getPorts() == null) {
return new ArrayList<V1ServicePort>().stream();
Expand All @@ -327,7 +327,7 @@ public void create() {
});
}
V1Pod createdPod = coreV1Api.createNamespacedPod(NAMESPACE, podToCreate, null, null, null);
if (USE_NODE_PORT_SERVICE.equalsIgnoreCase("true")) {
if (USE_NODE_PORT_SERVICE != null && USE_NODE_PORT_SERVICE.equalsIgnoreCase("true")) {
Map<String, String> selectorLabels = new HashMap<>();
selectorLabels.put(JUNIT_5_KUBERNETES_LABEL, podName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public void should_use_service() throws IOException {
int status = TestUtils.responseStatus(url);
assertThat(status).isEqualTo(200);
}
System.setProperty("junitKubernetesUsePortService", "false");
}
}

0 comments on commit fec2422

Please sign in to comment.