|
1 | 1 | package org.testcontainers.k3s; |
2 | 2 |
|
| 3 | +import io.fabric8.kubernetes.api.model.ContainerBuilder; |
| 4 | +import io.fabric8.kubernetes.api.model.ContainerPortBuilder; |
3 | 5 | import io.fabric8.kubernetes.api.model.Node; |
| 6 | +import io.fabric8.kubernetes.api.model.Pod; |
| 7 | +import io.fabric8.kubernetes.api.model.PodBuilder; |
| 8 | +import io.fabric8.kubernetes.api.model.PodSpec; |
| 9 | +import io.fabric8.kubernetes.api.model.PodSpecBuilder; |
| 10 | +import io.fabric8.kubernetes.api.model.ProbeBuilder; |
4 | 11 | import io.fabric8.kubernetes.client.Config; |
5 | 12 | import io.fabric8.kubernetes.client.DefaultKubernetesClient; |
| 13 | +import io.fabric8.kubernetes.client.dsl.PodResource; |
| 14 | +import io.fabric8.kubernetes.client.dsl.Readiable; |
6 | 15 | import lombok.extern.slf4j.Slf4j; |
7 | 16 | import org.assertj.core.api.Assertions; |
| 17 | +import org.assertj.core.api.Condition; |
8 | 18 | import org.junit.Test; |
9 | 19 | import org.testcontainers.containers.output.Slf4jLogConsumer; |
10 | 20 | import org.testcontainers.utility.DockerImageName; |
11 | 21 |
|
12 | 22 | import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | +import java.util.concurrent.TimeUnit; |
13 | 25 |
|
14 | 26 | @Slf4j |
15 | 27 | public class Fabric8K3sContainerTest { |
@@ -38,6 +50,36 @@ public void shouldStartAndHaveListableNode() { |
38 | 50 | // } |
39 | 51 |
|
40 | 52 | Assertions.assertThat(nodes).hasSize(1); |
| 53 | + |
| 54 | + // verify that we can start a pod |
| 55 | + Pod helloworld = dummyStartablePod(); |
| 56 | + client.pods().create(helloworld); |
| 57 | + client.pods().inNamespace("default").withName("helloworld").waitUntilReady(30, TimeUnit.SECONDS); |
| 58 | + |
| 59 | + Assertions.assertThat(client.pods().inNamespace("default").withName("helloworld")) |
| 60 | + .extracting(Readiable::isReady) |
| 61 | + .isEqualTo(true); |
41 | 62 | } |
42 | 63 | } |
| 64 | + |
| 65 | + private Pod dummyStartablePod() { |
| 66 | + PodSpec podSpec = new PodSpecBuilder() |
| 67 | + .withContainers( |
| 68 | + new ContainerBuilder() |
| 69 | + .withName("helloworld") |
| 70 | + .withImage("testcontainers/helloworld:1.1.0") |
| 71 | + .withPorts(new ContainerPortBuilder().withContainerPort(8080).build()) |
| 72 | + .withReadinessProbe(new ProbeBuilder().withNewTcpSocket().withNewPort(8080).endTcpSocket().build()) |
| 73 | + .build() |
| 74 | + ) |
| 75 | + .build(); |
| 76 | + |
| 77 | + return new PodBuilder() |
| 78 | + .withNewMetadata() |
| 79 | + .withName("helloworld") |
| 80 | + .withNamespace("default") |
| 81 | + .endMetadata() |
| 82 | + .withSpec(podSpec) |
| 83 | + .build(); |
| 84 | + } |
43 | 85 | } |
0 commit comments