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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@ new Helm(Paths.get("path", "to", "chart")).dependency().update()
.call();
```

### Get

Equivalent of [`helm get`](https://helm.sh/docs/helm/helm_get/).

This command consists of multiple subcommands which can be used to get extended information about the release, including:

#### Get values

Equivalent of [`helm get values`](https://helm.sh/docs/helm/helm_get_values/).

Downloads a values file for a given release.

``` java
String values = Helm.get("release-name").values()
// Optionally dump all (computed) values, including those from the chart's default values
.allValues()
// Optionally get the named release with a specific revision
.withRevision(1)
// Optionally specify the Kubernetes namespace
.withNamespace("namespace")
// Optionally specify the path to the kubeconfig file to use for CLI requests
.withKubeConfig(Paths.get("path", "to", "kubeconfig"))
// Optionally set the contents of the kubeconfig file as a string (takes precedence over the path)
.withKubeConfigContents("apiVersion: v1\nkind: Config\nclusters:\n...")
.call();
```

### Install

Equivalent of [`helm install`](https://helm.sh/docs/helm/helm_install/).
Expand Down
2 changes: 1 addition & 1 deletion helm-java/src/main/java/com/marcnuri/helm/GetCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public GetValuesSubcommand withNamespace(String namespace) {
}

/**
* Set the path ./kube/config file to use.
* Set the path to the ~/.kube/config file to use.
*
* @param kubeConfig the path to kube config file.
* @return this {@link GetValuesSubcommand} instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public InstallCommand withValuesFile(Path valuesFile) {
}

/**
* Set the path ./kube/config file to use.
* Set the path to the ~/.kube/config file to use.
*
* @param kubeConfig the path to kube config file.
* @return this {@link InstallCommand} instance.
Expand Down
2 changes: 1 addition & 1 deletion helm-java/src/main/java/com/marcnuri/helm/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public ListCommand withNamespace(String namespace) {
}

/**
* Set the path ./kube/config file to use.
* Set the path to the ~/.kube/config file to use.
*
* @param kubeConfig the path to kube config file.
* @return this {@link ListCommand} instance.
Expand Down
2 changes: 1 addition & 1 deletion helm-java/src/main/java/com/marcnuri/helm/TestCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public TestCommand withNamespace(String namespace) {
}

/**
* Set the path ./kube/config file to use.
* Set the path to the ~/.kube/config file to use.
*
* @param kubeConfig the path to kube config file.
* @return this {@link TestCommand} instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public UninstallCommand withNamespace(String namespace) {
}

/**
* Set the path ./kube/config file to use.
* Set the path to the ~/.kube/config file to use.
*
* @param kubeConfig the path to kube config file.
* @return this {@link UninstallCommand} instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public UpgradeCommand withValuesFile(Path valuesFile) {
}

/**
* Set the path ./kube/config file to use.
* Set the path to the ~/.kube/config file to use.
*
* @param kubeConfig the path to kube config file.
* @return this {@link UpgradeCommand} instance.
Expand Down
14 changes: 14 additions & 0 deletions helm-java/src/test/java/com/marcnuri/helm/HelmKubernetesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,20 @@ void withNamespace() {
.call();
assertThat(result).isNotNull();
}

@Test
void withKubeConfigContents() {
helm.install()
.withKubeConfigContents(kubeConfigContents)
.withName("get-values-kube-config-contents")
.set("replicaCount", "4")
.call();
final String result = Helm.get("get-values-kube-config-contents").values()
.withKubeConfigContents(kubeConfigContents)
.call();
assertThat(result)
.contains("replicaCount: 4");
}
}

@Nested
Expand Down
139 changes: 139 additions & 0 deletions native/internal/helm/envtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,142 @@ func TestUpgradeInstall(t *testing.T) {
return
}
}

func TestGetValues(t *testing.T) {
cleanUp, kubeConfigFile := setupEnvTest()
defer cleanUp()
create, _ := Create(&CreateOptions{
Name: "test-get-values",
Dir: t.TempDir(),
})
_, _ = Install(&InstallOptions{
KubeConfig: kubeConfigFile.Name(),
Chart: create,
Name: "test-get-values",
Values: "replicaCount=3",
})
out, err := GetValues(&GetValuesOptions{
KubeConfig: kubeConfigFile.Name(),
ReleaseName: "test-get-values",
})
if err != nil {
t.Errorf("Expected get values to succeed, got %s", err)
return
}
if !strings.Contains(out, "replicaCount: 3") {
t.Errorf("Expected get values to include replicaCount, got %s", out)
return
}
}

func TestGetValuesAllValues(t *testing.T) {
cleanUp, kubeConfigFile := setupEnvTest()
defer cleanUp()
create, _ := Create(&CreateOptions{
Name: "test-get-all-values",
Dir: t.TempDir(),
})
_, _ = Install(&InstallOptions{
KubeConfig: kubeConfigFile.Name(),
Chart: create,
Name: "test-get-all-values",
Values: "replicaCount=2",
})
out, err := GetValues(&GetValuesOptions{
KubeConfig: kubeConfigFile.Name(),
ReleaseName: "test-get-all-values",
AllValues: true,
})
if err != nil {
t.Errorf("Expected get values to succeed, got %s", err)
return
}
if !strings.Contains(out, "replicaCount: 2") {
t.Errorf("Expected get values to include replicaCount, got %s", out)
return
}
// AllValues should include chart defaults like serviceAccount
if !strings.Contains(out, "serviceAccount:") {
t.Errorf("Expected get all values to include serviceAccount, got %s", out)
return
}
}

func TestGetValuesWithRevision(t *testing.T) {
cleanUp, kubeConfigFile := setupEnvTest()
defer cleanUp()
chart, _ := Create(&CreateOptions{
Name: "test-get-revision",
Dir: t.TempDir(),
})
_, _ = Install(&InstallOptions{
KubeConfig: kubeConfigFile.Name(),
Chart: chart,
Name: "test-get-revision",
Values: "replicaCount=1",
})
_, _ = Upgrade(&UpgradeOptions{
KubeConfig: kubeConfigFile.Name(),
Chart: chart,
Name: "test-get-revision",
Values: "replicaCount=5",
})
out, err := GetValues(&GetValuesOptions{
KubeConfig: kubeConfigFile.Name(),
ReleaseName: "test-get-revision",
Revision: 1,
})
if err != nil {
t.Errorf("Expected get values to succeed, got %s", err)
return
}
if !strings.Contains(out, "replicaCount: 1") {
t.Errorf("Expected get values for revision 1 to include replicaCount: 1, got %s", out)
return
}
}

func TestGetValuesUsingKubeConfigContents(t *testing.T) {
cleanUp, kubeConfigFile := setupEnvTest()
defer cleanUp()
kubeConfigContents, _ := os.ReadFile(kubeConfigFile.Name())
create, _ := Create(&CreateOptions{
Name: "test-get-values-contents",
Dir: t.TempDir(),
})
_, _ = Install(&InstallOptions{
KubeConfigContents: string(kubeConfigContents),
Chart: create,
Name: "test-get-values-contents",
Values: "replicaCount=4",
})
out, err := GetValues(&GetValuesOptions{
KubeConfigContents: string(kubeConfigContents),
ReleaseName: "test-get-values-contents",
})
if err != nil {
t.Errorf("Expected get values to succeed, got %s", err)
return
}
if !strings.Contains(out, "replicaCount: 4") {
t.Errorf("Expected get values to include replicaCount, got %s", out)
return
}
}

func TestGetValuesNonExistentRelease(t *testing.T) {
cleanUp, kubeConfigFile := setupEnvTest()
defer cleanUp()
_, err := GetValues(&GetValuesOptions{
KubeConfig: kubeConfigFile.Name(),
ReleaseName: "non-existent-release",
})
if err == nil {
t.Error("Expected get values to fail for non-existent release")
return
}
if !strings.Contains(err.Error(), "not found") {
t.Errorf("Expected error to contain 'not found', got %s", err.Error())
return
}
}
8 changes: 1 addition & 7 deletions native/internal/helm/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package helm

import (
"encoding/json"

"helm.sh/helm/v3/pkg/action"
"sigs.k8s.io/yaml"
)
Expand Down Expand Up @@ -53,11 +51,7 @@ func GetValues(options *GetValuesOptions) (string, error) {
}

// Convert values to YAML format (default Helm output format)
jsonBytes, err := json.Marshal(values)
if err != nil {
return "", err
}
yamlBytes, err := yaml.JSONToYAML(jsonBytes)
yamlBytes, err := yaml.Marshal(values)
if err != nil {
return "", err
}
Expand Down
Loading