Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for passing values as file in Helm #265

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading