Skip to content

Commit d24dcc3

Browse files
authored
feat: support kube-version in install and template command (#278)
1 parent 42d394d commit d24dcc3

File tree

8 files changed

+49
-0
lines changed

8 files changed

+49
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ Release result = installCommand
124124
.withNamespace("namespace")
125125
// Optionally create the namespace if not present
126126
.createNamespace()
127+
// Optionally, specify the kubernetes version
128+
.withKubeVersion("1.21.0")
127129
// Optionally, if set, the installation process deletes the installation on failure
128130
.atomic()
129131
// Optionally specify a custom description for the release
@@ -594,6 +596,8 @@ String result = templateCommand
594596
.withVersion("^1.0.0")
595597
// Optionally specify the Kubernetes namespace for the release
596598
.withNamespace("namespace")
599+
// Optionally, specify the kubernetes version
600+
.withKubeVersion("1.21.0")
597601
// Optionally update dependencies if they are missing before installing the chart
598602
.dependencyUpdate()
599603
// Optionally set values for the chart

helm-java/src/main/java/com/marcnuri/helm/InstallCommand.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class InstallCommand extends HelmCommand<Release> {
4343
private String version;
4444
private String chart;
4545
private String namespace;
46+
private String kubeVersion;
4647
private boolean atomic;
4748
private boolean createNamespace;
4849
private String description;
@@ -88,6 +89,7 @@ public Release call() {
8889
version,
8990
chart,
9091
namespace,
92+
kubeVersion,
9193
toInt(atomic),
9294
toInt(createNamespace),
9395
description,
@@ -184,6 +186,17 @@ public InstallCommand withNamespace(String namespace) {
184186
return this;
185187
}
186188

189+
/**
190+
* Kubernetes version for this request.
191+
*
192+
* @param kubeVersion the Kubernetes version for this request.
193+
* @return this {@link InstallCommand} instance.
194+
*/
195+
public InstallCommand withKubeVersion(String kubeVersion) {
196+
this.kubeVersion = kubeVersion;
197+
return this;
198+
}
199+
187200
/**
188201
* Create the release namespace if not present.
189202
*

helm-java/src/main/java/com/marcnuri/helm/TemplateCommand.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class TemplateCommand extends HelmCommand<String> {
3636
private String version;
3737
private String chart;
3838
private String namespace;
39+
private String kubeVersion;
3940
private boolean dependencyUpdate;
4041
private boolean skipCrds;
4142
private final Map<String, String> values;
@@ -67,6 +68,7 @@ public String call() {
6768
version,
6869
chart,
6970
namespace,
71+
kubeVersion,
7072
toInt(dependencyUpdate),
7173
toInt(skipCrds),
7274
urlEncode(values),
@@ -130,6 +132,17 @@ public TemplateCommand withNamespace(String namespace) {
130132
return this;
131133
}
132134

135+
/**
136+
* Kubernetes version for this request.
137+
*
138+
* @param kubeVersion the Kubernetes version for this request.
139+
* @return this {@link TemplateCommand} instance.
140+
*/
141+
public TemplateCommand withKubeVersion(String kubeVersion) {
142+
this.kubeVersion = kubeVersion;
143+
return this;
144+
}
145+
133146
/**
134147
* Update dependencies if they are missing before rendering the chart.
135148
*

lib/api/src/main/java/com/marcnuri/helm/jni/InstallOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"version",
3333
"chart",
3434
"namespace",
35+
"kubeVersion",
3536
"atomic",
3637
"createNamespace",
3738
"description",
@@ -65,6 +66,7 @@ public class InstallOptions extends Structure {
6566
public String version;
6667
public String chart;
6768
public String namespace;
69+
public String kubeVersion;
6870
public int atomic;
6971
public int createNamespace;
7072
public String description;
@@ -97,6 +99,7 @@ public InstallOptions(
9799
String version,
98100
String chart,
99101
String namespace,
102+
String kubeVersion,
100103
int atomic,
101104
int createNamespace,
102105
String description,
@@ -128,6 +131,7 @@ public InstallOptions(
128131
this.version = version;
129132
this.chart = chart;
130133
this.namespace = namespace;
134+
this.kubeVersion = kubeVersion;
131135
this.atomic = atomic;
132136
this.createNamespace = createNamespace;
133137
this.description = description;

lib/api/src/main/java/com/marcnuri/helm/jni/TemplateOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"version",
2929
"chart",
3030
"namespace",
31+
"kubeVersion",
3132
"dependencyUpdate",
3233
"skipCRDs",
3334
"values",
@@ -46,6 +47,7 @@ public class TemplateOptions extends Structure {
4647
public String version;
4748
public String chart;
4849
public String namespace;
50+
public String kubeVersion;
4951
public int dependencyUpdate;
5052
public int skipCRDs;
5153
public String values;
@@ -64,6 +66,7 @@ public TemplateOptions(
6466
String version,
6567
String chart,
6668
String namespace,
69+
String kubeVersion,
6770
int dependencyUpdate,
6871
int skipCRDs,
6972
String values,
@@ -81,6 +84,7 @@ public TemplateOptions(
8184
this.version = version;
8285
this.chart = chart;
8386
this.namespace = namespace;
87+
this.kubeVersion = kubeVersion;
8488
this.dependencyUpdate = dependencyUpdate;
8589
this.skipCRDs = skipCRDs;
8690
this.values = values;

native/internal/helm/install.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"helm.sh/helm/v3/pkg/action"
2525
"helm.sh/helm/v3/pkg/chart"
2626
"helm.sh/helm/v3/pkg/chart/loader"
27+
"helm.sh/helm/v3/pkg/chartutil"
2728
"helm.sh/helm/v3/pkg/cli"
2829
"helm.sh/helm/v3/pkg/cli/values"
2930
"helm.sh/helm/v3/pkg/getter"
@@ -45,6 +46,7 @@ type InstallOptions struct {
4546
Version string
4647
Chart string
4748
Namespace string
49+
KubeVersion string
4850
Atomic bool
4951
CreateNamespace bool
5052
Description string
@@ -125,6 +127,9 @@ func install(options *InstallOptions) (*release.Release, *installOutputs, error)
125127
}
126128
client.ReleaseName = name
127129
client.Namespace = options.Namespace
130+
if options.KubeVersion != "" {
131+
client.KubeVersion, err = chartutil.ParseKubeVersion(options.KubeVersion)
132+
}
128133
client.Atomic = options.Atomic
129134
client.CreateNamespace = options.CreateNamespace
130135
client.Description = options.Description

native/internal/helm/template.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type TemplateOptions struct {
2828
Version string
2929
Chart string
3030
Namespace string
31+
KubeVersion string
3132
DependencyUpdate bool
3233
SkipCRDs bool
3334
Values string
@@ -51,6 +52,7 @@ func Template(options *TemplateOptions) (string, error) {
5152
Version: options.Version,
5253
Chart: options.Chart,
5354
Namespace: options.Namespace,
55+
KubeVersion: options.KubeVersion,
5456
DependencyUpdate: options.DependencyUpdate,
5557
SkipCRDs: options.SkipCRDs,
5658
Values: options.Values,

native/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct InstallOptions {
4747
char* version;
4848
char* chart;
4949
char* namespace;
50+
char* kubeVersion;
5051
int atomic;
5152
int createNamespace;
5253
char* description;
@@ -169,6 +170,7 @@ struct TemplateOptions {
169170
char* version;
170171
char* chart;
171172
char* namespace;
173+
char* kubeVersion;
172174
int dependencyUpdate;
173175
int skipCRDs;
174176
char* values;
@@ -348,6 +350,7 @@ func Install(options *C.struct_InstallOptions) C.Result {
348350
Version: C.GoString(options.version),
349351
Chart: C.GoString(options.chart),
350352
Namespace: C.GoString(options.namespace),
353+
KubeVersion: C.GoString(options.kubeVersion),
351354
Atomic: options.atomic == 1,
352355
CreateNamespace: options.createNamespace == 1,
353356
Description: C.GoString(options.description),
@@ -610,6 +613,7 @@ func Template(options *C.struct_TemplateOptions) C.Result {
610613
Version: C.GoString(options.version),
611614
Chart: C.GoString(options.chart),
612615
Namespace: C.GoString(options.namespace),
616+
KubeVersion: C.GoString(options.kubeVersion),
613617
DependencyUpdate: options.dependencyUpdate == 1,
614618
SkipCRDs: options.skipCRDs == 1,
615619
Values: C.GoString(options.values),

0 commit comments

Comments
 (0)