2
2
3
3
import com .dajudge .kindcontainer .BaseSidecarContainer .ExecInContainer ;
4
4
import com .dajudge .kindcontainer .exception .ExecutionException ;
5
+ import org .testcontainers .containers .ContainerState ;
6
+ import org .testcontainers .utility .MountableFile ;
5
7
6
8
import java .io .IOException ;
7
- import java .util .ArrayList ;
8
- import java .util .HashMap ;
9
- import java .util .List ;
10
- import java .util .Map ;
9
+ import java .util .*;
11
10
12
11
import static java .util .Arrays .asList ;
13
12
@@ -17,6 +16,7 @@ public class InstallFluent<P> {
17
16
private final P parent ;
18
17
private String namespace ;
19
18
private boolean createNamespace ;
19
+ private String version ;
20
20
private final Map <String , String > params = new HashMap <>();
21
21
22
22
private final List <String > values = new ArrayList <>();
@@ -26,31 +26,77 @@ public InstallFluent(final ExecInContainer c, final P parent) {
26
26
this .parent = parent ;
27
27
}
28
28
29
+ /**
30
+ * Adds the given key/value as --set parameter to the Helm install command.
31
+ * @param key required
32
+ * @param value required
33
+ * @return The fluent API
34
+ */
29
35
public InstallFluent <P > set (final String key , final String value ) {
30
36
params .put (key , value );
31
37
return this ;
32
38
}
33
39
40
+ /**
41
+ * Adds the given values file as -f parameter to the Helm install command.
42
+ * Make sure the values file is available in the Helm container.
43
+ * @see ContainerState#copyFileToContainer(MountableFile, String)
44
+ * @param path Path to the values file in the Helm container.
45
+ * @return The fluent API
46
+ */
34
47
public InstallFluent <P > values (final String path ) {
35
48
values .add (path );
36
49
return this ;
37
50
}
38
51
52
+ /**
53
+ * Sets the given namespace as target namespace (--namespace parameter) for the Helm install command.
54
+ * @param namespace required
55
+ * @return The fluent API
56
+ */
39
57
public InstallFluent <P > namespace (final String namespace ) {
40
58
this .namespace = namespace ;
41
59
return this ;
42
60
}
43
61
62
+ /**
63
+ * Enables or disables the creation of the target namespace for the Helm install command. (--create-namespace parameter)
64
+ * @param createNamespace true to enable creation, false otherwise
65
+ * @return The fluent API
66
+ */
44
67
public InstallFluent <P > createNamespace (final boolean createNamespace ) {
45
68
this .createNamespace = createNamespace ;
46
69
return this ;
47
70
}
48
71
49
72
73
+ /**
74
+ * Enables the creation of the target namespace for the Helm install command.
75
+ * @return The fluent API
76
+ */
50
77
public InstallFluent <P > createNamespace () {
51
78
return createNamespace (true );
52
79
}
53
80
81
+ /**
82
+ * Sets the version for the Helm chart to be installed. (--version parameter)
83
+ * @param version required
84
+ * @return The fluent API
85
+ */
86
+ public InstallFluent <P > version (final String version ) {
87
+ this .version = version ;
88
+ return this ;
89
+ }
90
+
91
+ /**
92
+ * Runs the Helm install command.
93
+ * @param releaseName The release name of the Helm installation
94
+ * @param chart The chart name of the Helm installation
95
+ * @return Parent container
96
+ * @throws IOException
97
+ * @throws InterruptedException
98
+ * @throws ExecutionException
99
+ */
54
100
public P run (final String releaseName , final String chart ) throws IOException , InterruptedException , ExecutionException {
55
101
try {
56
102
final List <String > cmdline = new ArrayList <>(asList ("helm" , "install" ));
@@ -60,6 +106,9 @@ public P run(final String releaseName, final String chart) throws IOException, I
60
106
if (createNamespace ) {
61
107
cmdline .add ("--create-namespace" );
62
108
}
109
+ if (version != null ) {
110
+ cmdline .addAll (asList ("--version" , version ));
111
+ }
63
112
params .forEach ((k , v ) -> cmdline .addAll (asList ("--set" , String .format ("%s=%s" , k , v ))));
64
113
cmdline .addAll (asList (releaseName , chart ));
65
114
values .forEach (v -> {
@@ -70,6 +119,7 @@ public P run(final String releaseName, final String chart) throws IOException, I
70
119
} finally {
71
120
createNamespace = false ;
72
121
namespace = null ;
122
+ version = null ;
73
123
params .clear ();
74
124
}
75
125
}
0 commit comments