Skip to content

Commit 7a982eb

Browse files
feat: add support for --skip-crds flag (#317)
1 parent e60602d commit 7a982eb

File tree

13 files changed

+102
-0
lines changed

13 files changed

+102
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class InstallCommand extends HelmCommand<Release> {
5050
private boolean disableOpenApiValidation;
5151
private boolean dryRun;
5252
private DryRun dryRunOption;
53+
private boolean skipCrds;
5354
private boolean wait;
5455
private int timeout;
5556
private final Map<String, String> values;
@@ -94,6 +95,7 @@ public Release call() {
9495
toInt(disableOpenApiValidation),
9596
toInt(dryRun),
9697
dryRunOption == null ? null : dryRunOption.name().toLowerCase(Locale.ROOT),
98+
toInt(skipCrds),
9799
toInt(wait),
98100
timeout,
99101
urlEncode(values),
@@ -267,6 +269,18 @@ public InstallCommand withDryRunOption(DryRun dryRunOption) {
267269
return this;
268270
}
269271

272+
/**
273+
* Skip CRDs during installation.
274+
* <p>
275+
* If set, no CRDs will be installed. By default, CRDs are installed if not already present.
276+
*
277+
* @return this {@link InstallCommand} instance.
278+
*/
279+
public InstallCommand skipCrds() {
280+
this.skipCrds = true;
281+
return this;
282+
}
283+
270284
/**
271285
* Waits until all Pods are in a ready state, PVCs are bound, Deployments have minimum
272286
* (Desired minus maxUnavailable) Pods in ready state and Services have an IP address

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class TemplateCommand extends HelmCommand<String> {
3636
private String chart;
3737
private String namespace;
3838
private boolean dependencyUpdate;
39+
private boolean skipCrds;
3940
private final Map<String, String> values;
4041
private final List<Path> valuesFiles;
4142
private Path certFile;
@@ -66,6 +67,7 @@ public String call() {
6667
chart,
6768
namespace,
6869
toInt(dependencyUpdate),
70+
toInt(skipCrds),
6971
urlEncode(values),
7072
toString(valuesFiles),
7173
toString(certFile),
@@ -137,6 +139,18 @@ public TemplateCommand dependencyUpdate() {
137139
return this;
138140
}
139141

142+
/**
143+
* Skip CRDs during template rendering.
144+
* <p>
145+
* If set, no CRDs will be included in the rendered templates.
146+
*
147+
* @return this {@link TemplateCommand} instance.
148+
*/
149+
public TemplateCommand skipCrds() {
150+
this.skipCrds = true;
151+
return this;
152+
}
153+
140154
/**
141155
* Set values for the chart.
142156
*

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class UpgradeCommand extends HelmCommand<Release> {
5454
private boolean disableOpenApiValidation;
5555
private boolean dryRun;
5656
private DryRun dryRunOption;
57+
private boolean skipCrds;
5758
private boolean wait;
5859
private int timeout;
5960
private final Map<String, String> values;
@@ -102,6 +103,7 @@ public Release call() {
102103
toInt(disableOpenApiValidation),
103104
toInt(dryRun),
104105
dryRunOption == null ? null : dryRunOption.name().toLowerCase(Locale.ROOT),
106+
toInt(skipCrds),
105107
toInt(wait),
106108
timeout,
107109
urlEncode(values),
@@ -319,6 +321,18 @@ public UpgradeCommand withDryRunOption(DryRun dryRunOption) {
319321
return this;
320322
}
321323

324+
/**
325+
* Skip CRDs during upgrade.
326+
* <p>
327+
* If set, no CRDs will be installed or upgraded. By default, CRDs are installed if not already present.
328+
*
329+
* @return this {@link UpgradeCommand} instance.
330+
*/
331+
public UpgradeCommand skipCrds() {
332+
this.skipCrds = true;
333+
return this;
334+
}
335+
322336
/**
323337
* Waits until all Pods are in a ready state, PVCs are bound, Deployments have minimum
324338
* (Desired minus maxUnavailable) Pods in ready state and Services have an IP address

helm-java/src/test/java/com/marcnuri/helm/HelmInstallTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ void withDisableOpenApiValidation() {
228228
.hasFieldOrPropertyWithValue("name", "test")
229229
.hasFieldOrPropertyWithValue("status", "deployed");
230230
}
231+
232+
@Test
233+
void skipCrds() {
234+
final Release result = helm.install()
235+
.clientOnly()
236+
.debug()
237+
.withName("test-skip-crds")
238+
.skipCrds()
239+
.call();
240+
assertThat(result)
241+
.returns("test-skip-crds", Release::getName)
242+
.returns("deployed", Release::getStatus);
243+
}
231244
}
232245

233246
@Nested

helm-java/src/test/java/com/marcnuri/helm/HelmKubernetesTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,19 @@ void withWaitAndCustomTimeout() {
555555
"beginning wait for 3 resources with timeout of 5m30s"
556556
);
557557
}
558+
559+
@Test
560+
void skipCrds() {
561+
helm.install().withName("upgrade-skip-crds").withKubeConfig(kubeConfigFile).call();
562+
final Release result = helm.upgrade()
563+
.withKubeConfig(kubeConfigFile)
564+
.withName("upgrade-skip-crds")
565+
.skipCrds()
566+
.call();
567+
assertThat(result)
568+
.returns("2", Release::getRevision)
569+
.returns("deployed", Release::getStatus);
570+
}
558571
}
559572

560573
@Nested

helm-java/src/test/java/com/marcnuri/helm/HelmTemplateTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ void withInvalidValuesAndDebug() {
107107
.hasMessageContaining("# Source: local-chart-test")
108108
.hasMessageContaining("name: release-name-local-chart-test");
109109
}
110+
111+
@Test
112+
void skipCrds() {
113+
final String result = helm.template()
114+
.skipCrds()
115+
.call();
116+
assertThat(result)
117+
.contains("name: release-name-local-chart-test");
118+
}
110119
}
111120

112121
@Nested

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
@@ -39,6 +39,7 @@
3939
"disableOpenApiValidation",
4040
"dryRun",
4141
"dryRunOption",
42+
"skipCRDs",
4243
"wait",
4344
"timeout",
4445
"values",
@@ -71,6 +72,7 @@ public class InstallOptions extends Structure {
7172
public int disableOpenApiValidation;
7273
public int dryRun;
7374
public String dryRunOption;
75+
public int skipCRDs;
7476
public int wait;
7577
public int timeout;
7678
public String values;
@@ -102,6 +104,7 @@ public InstallOptions(
102104
int disableOpenApiValidation,
103105
int dryRun,
104106
String dryRunOption,
107+
int skipCRDs,
105108
int wait,
106109
int timeout,
107110
String values,
@@ -132,6 +135,7 @@ public InstallOptions(
132135
this.disableOpenApiValidation = disableOpenApiValidation;
133136
this.dryRun = dryRun;
134137
this.dryRunOption = dryRunOption;
138+
this.skipCRDs = skipCRDs;
135139
this.wait = wait;
136140
this.timeout = timeout;
137141
this.values = values;

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
"chart",
2929
"namespace",
3030
"dependencyUpdate",
31+
"skipCRDs",
3132
"values",
3233
"valuesFiles",
3334
"certFile",
@@ -45,6 +46,7 @@ public class TemplateOptions extends Structure {
4546
public String chart;
4647
public String namespace;
4748
public int dependencyUpdate;
49+
public int skipCRDs;
4850
public String values;
4951
public String valuesFiles;
5052
public String certFile;
@@ -62,6 +64,7 @@ public TemplateOptions(
6264
String chart,
6365
String namespace,
6466
int dependencyUpdate,
67+
int skipCRDs,
6568
String values,
6669
String valuesFiles,
6770
String certFile,
@@ -78,6 +81,7 @@ public TemplateOptions(
7881
this.chart = chart;
7982
this.namespace = namespace;
8083
this.dependencyUpdate = dependencyUpdate;
84+
this.skipCRDs = skipCRDs;
8185
this.values = values;
8286
this.valuesFiles = valuesFiles;
8387
this.certFile = certFile;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"disableOpenApiValidation",
4444
"dryRun",
4545
"dryRunOption",
46+
"skipCRDs",
4647
"wait",
4748
"timeout",
4849
"values",
@@ -78,6 +79,7 @@ public class UpgradeOptions extends Structure {
7879
public int disableOpenApiValidation;
7980
public int dryRun;
8081
public String dryRunOption;
82+
public int skipCRDs;
8183
public int wait;
8284
public int timeout;
8385
public String values;
@@ -113,6 +115,7 @@ public UpgradeOptions(
113115
int disableOpenApiValidation,
114116
int dryRun,
115117
String dryRunOption,
118+
int skipCRDs,
116119
int wait,
117120
int timeout,
118121
String values,
@@ -147,6 +150,7 @@ public UpgradeOptions(
147150
this.disableOpenApiValidation = disableOpenApiValidation;
148151
this.dryRun = dryRun;
149152
this.dryRunOption = dryRunOption;
153+
this.skipCRDs = skipCRDs;
150154
this.wait = wait;
151155
this.timeout = timeout;
152156
this.values = values;

native/internal/helm/install.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type InstallOptions struct {
5353
DisableOpenApiValidation bool
5454
DryRun bool
5555
DryRunOption string
56+
SkipCRDs bool
5657
Wait bool
5758
Timeout time.Duration
5859
Values string
@@ -130,6 +131,7 @@ func install(options *InstallOptions) (*release.Release, *installOutputs, error)
130131
client.Devel = options.Devel
131132
client.DryRun = options.DryRun
132133
client.DryRunOption = dryRunOption(options.DryRunOption)
134+
client.SkipCRDs = options.SkipCRDs
133135
client.Wait = options.Wait
134136
client.Timeout = options.Timeout
135137
client.ClientOnly = options.ClientOnly

0 commit comments

Comments
 (0)