Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ Release result = installCommand
.withTimeout(int timeout)
// Optionally set typed values for the chart (can be repeated)
.set("key", "value")
// Optionally set a values file to source values for the chart
.withValuesFile(Paths.get("path", "to", "valuesFile"))
// Optionally specify the path to the kubeconfig file to use for CLI requests
.withKubeConfig(Paths.get("path", "to", "kubeconfig"))
// Optionally specify an SSL certificate file to identify the registry client
Expand Down
13 changes: 13 additions & 0 deletions helm-java/src/main/java/com/marcnuri/helm/InstallCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class InstallCommand extends HelmCommand<Release> {
private boolean wait;
private int timeout;
private final Map<String, String> values;
private Path valuesFile;
private Path kubeConfig;
private Path certFile;
private Path keyFile;
Expand Down Expand Up @@ -86,6 +87,7 @@ public Release call() {
toInt(wait),
timeout,
urlEncode(values),
toString(valuesFile),
toString(kubeConfig),
toString(certFile),
toString(keyFile),
Expand Down Expand Up @@ -289,6 +291,17 @@ public InstallCommand set(String key, Object value) {
return this;
}

/**
* Set values file for the chart.
*
* @param valuesFile the path to a values file
* @return this {@link InstallCommand} instance.
*/
public InstallCommand withValuesFile(Path valuesFile) {
this.valuesFile = valuesFile;
return this;
}

/**
* Set the path ./kube/config file to use.
*
Expand Down
13 changes: 13 additions & 0 deletions helm-java/src/main/java/com/marcnuri/helm/UpgradeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class UpgradeCommand extends HelmCommand<Release> {
private boolean wait;
private int timeout;
private final Map<String, String> values;
private Path valuesFile;
private Path kubeConfig;
private Path certFile;
private Path keyFile;
Expand Down Expand Up @@ -94,6 +95,7 @@ public Release call() {
toInt(wait),
timeout,
urlEncode(values),
toString(valuesFile),
toString(kubeConfig),
toString(certFile),
toString(keyFile),
Expand Down Expand Up @@ -341,6 +343,17 @@ public UpgradeCommand set(String key, Object value) {
return this;
}

/**
* Set values file for the chart.
*
* @param valuesFile the path to a values file
* @return this {@link InstallCommand} instance.
*/
public UpgradeCommand withValuesFile(Path valuesFile) {
this.valuesFile = valuesFile;
return this;
}

/**
* Set the path ./kube/config file to use.
*
Expand Down
25 changes: 25 additions & 0 deletions helm-java/src/test/java/com/marcnuri/helm/HelmInstallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,31 @@ void withValues() {
);
}

@Test
void withValuesFile(@TempDir Path tempDir) throws IOException {
final Path valuesFile = Files.write(tempDir.resolve("newValues.yaml"),
(
"nix: baz\n" +
"foo: bar"
).getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE);

final Release result = helm.install()
.clientOnly()
.debug()
.withName("test")
.set("foo", "notBar") // set values override values file.
.withValuesFile(valuesFile)
.call();
assertThat(result)
.extracting(Release::getOutput).asString()
.contains(
"NAME: test\n",
"foo: notBar",
"nix: baz"
);
}

@Test
void withDisableOpenApiValidation() {
final Release result = helm.install()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"wait",
"timeout",
"values",
"valuesFile",
"kubeConfig",
"certFile",
"keyFile",
Expand Down Expand Up @@ -66,6 +67,7 @@ public class InstallOptions extends Structure {
public int wait;
public int timeout;
public String values;
public String valuesFile;
public String kubeConfig;
public String certFile;
public String keyFile;
Expand Down Expand Up @@ -95,6 +97,7 @@ public InstallOptions(
int wait,
int timeout,
String values,
String valuesFile,
String kubeConfig,
String certFile,
String keyFile,
Expand Down Expand Up @@ -123,6 +126,7 @@ public InstallOptions(
this.wait = wait;
this.timeout = timeout;
this.values = values;
this.valuesFile = valuesFile;
this.kubeConfig = kubeConfig;
this.certFile = certFile;
this.keyFile = keyFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"wait",
"timeout",
"values",
"valuesFile",
"kubeConfig",
"certFile",
"keyFile",
Expand Down Expand Up @@ -73,6 +74,7 @@ public class UpgradeOptions extends Structure {
public int wait;
public int timeout;
public String values;
public String valuesFile;
public String kubeConfig;
public String certFile;
public String keyFile;
Expand Down Expand Up @@ -106,6 +108,7 @@ public UpgradeOptions(
int wait,
int timeout,
String values,
String valuesFile,
String kubeConfig,
String certFile,
String keyFile,
Expand Down Expand Up @@ -138,6 +141,7 @@ public UpgradeOptions(
this.wait = wait;
this.timeout = timeout;
this.values = values;
this.valuesFile = valuesFile;
this.kubeConfig = kubeConfig;
this.certFile = certFile;
this.keyFile = keyFile;
Expand Down
16 changes: 15 additions & 1 deletion native/internal/helm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/strvals"
"maps"
"net/url"
"os"
"os/signal"
Expand Down Expand Up @@ -54,6 +56,7 @@ type InstallOptions struct {
Wait bool
Timeout time.Duration
Values string
ValuesFile string
KubeConfig string
Debug bool
// For testing purposes only, prevents connecting to Kubernetes (happens even with DryRun=true and DryRunOption=client)
Expand Down Expand Up @@ -152,10 +155,21 @@ func install(options *InstallOptions) (*release.Release, *installOutputs, error)
return nil, outputs, invalidDryRun
}
// Values
var values, invalidValues = parseValues(options.Values)
values := make(map[string]interface{})
// Values from values file
if options.ValuesFile != "" {
fileValues, err := chartutil.ReadValuesFile(options.ValuesFile)
if err != nil {
return nil, outputs, err
}
maps.Copy(values, fileValues)
}
// Values from set values
var paramValues, invalidValues = parseValues(options.Values)
if invalidValues != nil {
return nil, outputs, invalidValues
}
maps.Copy(values, paramValues)

// Create context that handles SIGINT, SIGTERM
ctx := context.Background()
Expand Down
27 changes: 27 additions & 0 deletions native/internal/helm/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,33 @@ func TestInstallValues(t *testing.T) {
}
}


func TestInstallWithValuesFile(t *testing.T) {
tmpDir := t.TempDir()
create, _ := Create(&CreateOptions{
Name: "test",
Dir: tmpDir,
})
valuesFilePath := path.Join(tmpDir, "valuesFile.yaml")
valuesBytes := []byte("nix: baz\n")
err := os.WriteFile(valuesFilePath, valuesBytes, 0666)
out, err := Install(&InstallOptions{
Chart: create,
Name: "test",
ValuesFile: valuesFilePath,
Debug: true,
ClientOnly: true,
})
if err != nil {
t.Errorf("Expected install to succeed, got %s", err)
return
}
if !strings.Contains(out, "USER-SUPPLIED VALUES:") || !strings.Contains(out, "nix: baz") {
t.Errorf("Expected install to contain specific values from valuesFile, got %s", out)
return
}
}

func TestInstallDependencyUpdate(t *testing.T) {
chart, _ := Create(&CreateOptions{
Name: "test",
Expand Down
16 changes: 15 additions & 1 deletion native/internal/helm/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"bytes"
"context"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/storage/driver"
"maps"
"time"
)

Expand All @@ -47,6 +49,7 @@ type UpgradeOptions struct {
Wait bool
Timeout time.Duration
Values string
ValuesFile string
KubeConfig string
Debug bool
// For testing purposes only, prevents connecting to Kubernetes (happens even with DryRun=true and DryRunOption=client)
Expand Down Expand Up @@ -156,10 +159,21 @@ func Upgrade(options *UpgradeOptions) (string, error) {
}
ctx := context.Background()
// Values
var values, invalidValues = parseValues(options.Values)
values := make(map[string]interface{})
// values from values file
if options.ValuesFile != "" {
fileValues, err := chartutil.ReadValuesFile(options.ValuesFile)
if err != nil {
return "", err
}
maps.Copy(values, fileValues)
}
// Values from set values
var paramValues, invalidValues = parseValues(options.Values)
if invalidValues != nil {
return "", invalidValues
}
maps.Copy(values, paramValues)
// Run
release, err := client.RunWithContext(ctx, options.Name, chartRequested, values)
// Generate report
Expand Down
4 changes: 4 additions & 0 deletions native/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct InstallOptions {
int wait;
int timeout;
char* values;
char* valuesFile;
char* kubeConfig;
char* certFile;
char* keyFile;
Expand Down Expand Up @@ -219,6 +220,7 @@ struct UpgradeOptions {
int wait;
int timeout;
char* values;
char* valuesFile;
char* kubeConfig;
char* certFile;
char* keyFile;
Expand Down Expand Up @@ -348,6 +350,7 @@ func Install(options *C.struct_InstallOptions) C.Result {
Wait: options.wait == 1,
Timeout: timeout,
Values: C.GoString(options.values),
ValuesFile: C.GoString(options.valuesFile),
KubeConfig: C.GoString(options.kubeConfig),
CertOptions: helm.CertOptions{
CertFile: C.GoString(options.certFile),
Expand Down Expand Up @@ -678,6 +681,7 @@ func Upgrade(options *C.struct_UpgradeOptions) C.Result {
Wait: options.wait == 1,
Timeout: timeout,
Values: C.GoString(options.values),
ValuesFile: C.GoString(options.valuesFile),
KubeConfig: C.GoString(options.kubeConfig),
CertOptions: helm.CertOptions{
CertFile: C.GoString(options.certFile),
Expand Down
Loading