-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
K3sContainer: expose kubeConfig for docker network access (#5097)
Co-authored-by: Sergei Egorov <[email protected]>
- Loading branch information
1 parent
0073001
commit 5533447
Showing
2 changed files
with
93 additions
and
15 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
45 changes: 45 additions & 0 deletions
45
modules/k3s/src/test/java/org/testcontainers/k3s/KubectlContainerTest.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,45 @@ | ||
package org.testcontainers.k3s; | ||
|
||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy; | ||
import org.testcontainers.images.builder.Transferable; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class KubectlContainerTest { | ||
|
||
public static Network network = Network.SHARED; | ||
|
||
@ClassRule | ||
public static K3sContainer k3s = new K3sContainer(DockerImageName.parse("rancher/k3s:v1.21.3-k3s1")) | ||
.withNetwork(network) | ||
.withNetworkAliases("k3s"); | ||
|
||
@Test | ||
public void shouldExposeKubeConfigForNetworkAlias() throws Exception { | ||
String kubeConfigYaml = k3s.generateInternalKubeConfigYaml("k3s"); | ||
|
||
try ( | ||
GenericContainer<?> kubectlContainer = new GenericContainer<>("rancher/kubectl:v1.23.3") | ||
.withNetwork(network) | ||
.withCopyToContainer(Transferable.of(kubeConfigYaml), "/.kube/config") | ||
.withCommand("get namespaces") | ||
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofSeconds(30))) | ||
) { | ||
kubectlContainer.start(); | ||
|
||
assertThat(kubectlContainer.getLogs()).contains("kube-system"); | ||
} | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void shouldThrowAnExceptionForUnknownNetworkAlias() { | ||
k3s.generateInternalKubeConfigYaml("not-set-network-alias"); | ||
} | ||
} |