Skip to content

Commit

Permalink
dajudge#264 Support for passing values as file in Helm (dajudge#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszmichalak authored Feb 13, 2024
1 parent bb4367a commit b15291a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/main/java/com/dajudge/kindcontainer/helm/InstallFluent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class InstallFluent<P> {
private final P parent;
private String namespace;
private boolean createNamespace;
private Map<String, String> params = new HashMap<>();
private final Map<String, String> params = new HashMap<>();

private final List<String> values = new ArrayList<>();

public InstallFluent(final ExecInContainer c, final P parent) {
this.c = c;
Expand All @@ -29,6 +31,11 @@ public InstallFluent<P> set(final String key, final String value) {
return this;
}

public InstallFluent<P> values(final String path) {
values.add(path);
return this;
}

public InstallFluent<P> namespace(final String namespace) {
this.namespace = namespace;
return this;
Expand All @@ -53,10 +60,11 @@ public P run(final String releaseName, final String chart) throws IOException, I
if (createNamespace) {
cmdline.add("--create-namespace");
}
params.forEach((k, v) -> {
cmdline.addAll(asList("--set", String.format("%s=%s", k, v)));
});
params.forEach((k, v) -> cmdline.addAll(asList("--set", String.format("%s=%s", k, v))));
cmdline.addAll(asList(releaseName, chart));
values.forEach(v -> {
cmdline.addAll(asList("-f", v));
});
c.safeExecInContainer(cmdline.toArray(new String[]{}));
return parent;
} finally {
Expand Down
11 changes: 7 additions & 4 deletions src/test/java/com/dajudge/kindcontainer/Helm3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.TestFactory;

import java.util.stream.Stream;
import org.testcontainers.utility.MountableFile;

import static com.dajudge.kindcontainer.util.ContainerVersionHelpers.allContainers;
import static com.dajudge.kindcontainer.util.ContainerVersionHelpers.runWithK8s;
Expand All @@ -20,18 +21,20 @@ public Stream<DynamicTest> can_install_something() {

private void assertCanInstallSomething(final KubernetesTestPackage<? extends KubernetesContainer<?>> testPkg) {
runWithK8s(configureContainer(testPkg.newContainer()), k8s -> runWithClient(k8s, client -> {
assertFalse(client.apps().deployments().inNamespace("kubernetes-replicator").list().getItems().isEmpty());
assertFalse(client.apps().deployments().inNamespace("hello").list().getItems().isEmpty());
}));
}

private KubernetesContainer<?> configureContainer(KubernetesContainer<?> container) {
return container.withHelm3(helm -> {
helm.repo.add.run("mittwald", "https://helm.mittwald.de");
helm.copyFileToContainer(MountableFile.forClasspathResource("hello-values.yaml"), "/apps/values.yaml");
helm.repo.add.run("examples", "https://helm.github.io/examples");
helm.repo.update.run();
helm.install
.namespace("kubernetes-replicator")
.namespace("hello")
.createNamespace()
.run("kubernetes-replicator", "mittwald/kubernetes-replicator");
.values("/apps/values.yaml")
.run("hello", "examples/hello-world");
});
}
}
1 change: 1 addition & 0 deletions src/test/resources/hello-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
replicaCount: 2

0 comments on commit b15291a

Please sign in to comment.