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
137 changes: 137 additions & 0 deletions helm-java/src/main/java/com/marcnuri/helm/GetCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright 2026 Marc Nuri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.marcnuri.helm;

import com.marcnuri.helm.jni.GetValuesOptions;
import com.marcnuri.helm.jni.HelmLib;

import java.nio.file.Path;

/**
* This command consists of multiple subcommands which can be used to get extended information about the release.
*
* @author Antonio Fernandez Alhambra
*/
public class GetCommand {

private final HelmLib helmLib;
private final String releaseName;

GetCommand(HelmLib helmLib, String releaseName) {
this.helmLib = helmLib;
this.releaseName = releaseName;
}

/**
* This command downloads the values file for a given release.
*
* @return the {@link GetValuesSubcommand} subcommand.
*/
public GetValuesSubcommand values() {
return new GetValuesSubcommand(helmLib, releaseName);
}

public static final class GetValuesSubcommand extends HelmCommand<String> {

private final String releaseName;
private boolean allValues;
private int revision;
private String namespace;
private Path kubeConfig;
private String kubeConfigContents;

private GetValuesSubcommand(HelmLib helmLib, String releaseName) {
super(helmLib);
this.releaseName = releaseName;
}

/**
* Execute the get values subcommand.
*
* @return a {@link String} containing the values in YAML format.
*/
@Override
public String call() {
return run(hl -> hl.GetValues(new GetValuesOptions(
releaseName,
toInt(allValues),
revision,
namespace,
toString(kubeConfig),
kubeConfigContents
))).out;
}

/**
* Dump all (computed) values.
* <p>
* When set, all computed values are returned, including the default values from the chart.
*
* @return this {@link GetValuesSubcommand} instance.
*/
public GetValuesSubcommand allValues() {
this.allValues = true;
return this;
}

/**
* Get the named release with revision.
* <p>
* If not specified, the latest release is returned.
*
* @param revision the revision number.
* @return this {@link GetValuesSubcommand} instance.
*/
public GetValuesSubcommand withRevision(int revision) {
this.revision = revision;
return this;
}

/**
* Kubernetes namespace scope for this request.
*
* @param namespace the Kubernetes namespace for this request.
* @return this {@link GetValuesSubcommand} instance.
*/
public GetValuesSubcommand withNamespace(String namespace) {
this.namespace = namespace;
return this;
}

/**
* Set the path ./kube/config file to use.
*
* @param kubeConfig the path to kube config file.
* @return this {@link GetValuesSubcommand} instance.
*/
public GetValuesSubcommand withKubeConfig(Path kubeConfig) {
this.kubeConfig = kubeConfig;
return this;
}

/**
* Set the kube config to use.
*
* @param kubeConfigContents the contents of the kube config file.
* @return this {@link GetValuesSubcommand} instance.
*/
public GetValuesSubcommand withKubeConfigContents(String kubeConfigContents) {
this.kubeConfigContents = kubeConfigContents;
return this;
}
}
}
11 changes: 11 additions & 0 deletions helm-java/src/main/java/com/marcnuri/helm/Helm.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* @author Marc Nuri
* @author Andres F. Vallecilla
* @author Antonio Fernandez Alhambra
*/
public class Helm {

Expand Down Expand Up @@ -96,6 +97,16 @@ public static ListCommand list() {
return new ListCommand(HelmLibHolder.INSTANCE);
}

/**
* This command consists of multiple subcommands which can be used to get extended information about the release.
*
* @param releaseName the name of the release.
* @return the {@link GetCommand} command.
*/
public static GetCommand get(String releaseName) {
return new GetCommand(HelmLibHolder.INSTANCE, releaseName);
}

/**
* This command packages a chart into a versioned chart archive file.
* If a path is given, this will look at that path for a chart (which must contain a Chart.yaml file) and then package that directory.
Expand Down
85 changes: 85 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 @@ -762,4 +762,89 @@ void withInstallAndInvalidKubeVersion() {
}
}
}

@Nested
class Get {

@Nested
class Values {

@Test
void returnsUserSuppliedValues() {
helm.install()
.withKubeConfig(kubeConfigFile)
.withName("get-values-user-supplied")
.set("replicaCount", "3")
.call();
final String result = Helm.get("get-values-user-supplied").values()
.withKubeConfig(kubeConfigFile)
.call();
assertThat(result)
.contains("replicaCount: 3");
}

@Test
void allValuesIncludesDefaultValues() {
helm.install()
.withKubeConfig(kubeConfigFile)
.withName("get-values-all")
.set("replicaCount", "2")
.call();
final String result = Helm.get("get-values-all").values()
.withKubeConfig(kubeConfigFile)
.allValues()
.call();
assertThat(result)
.contains("replicaCount: 2")
.contains("serviceAccount:");
}

@Test
void withRevision() {
helm.install()
.withKubeConfig(kubeConfigFile)
.withName("get-values-revision")
.set("replicaCount", "1")
.call();
helm.upgrade()
.withKubeConfig(kubeConfigFile)
.withName("get-values-revision")
.set("replicaCount", "5")
.call();
final String result = Helm.get("get-values-revision").values()
.withKubeConfig(kubeConfigFile)
.withRevision(1)
.call();
assertThat(result)
.contains("replicaCount: 1");
}

@Test
void withNamespace() {
helm.install()
.withKubeConfig(kubeConfigFile)
.withName("get-values-namespace")
.withNamespace("default")
.call();
final String result = Helm.get("get-values-namespace").values()
.withKubeConfig(kubeConfigFile)
.withNamespace("default")
.call();
assertThat(result).isNotNull();
}
}

@Nested
class Invalid {

@Test
void missingRelease() {
final GetCommand.GetValuesSubcommand getValues = Helm.get("non-existent-release").values()
.withKubeConfig(kubeConfigFile);
assertThatThrownBy(getValues::call)
.message()
.contains("not found");
}
}
}
}
48 changes: 48 additions & 0 deletions lib/api/src/main/java/com/marcnuri/helm/jni/GetValuesOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2026 Marc Nuri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.marcnuri.helm.jni;

import com.sun.jna.Structure;

/**
* @author Antonio Fernandez Alhambra
*/
@Structure.FieldOrder({
"releaseName",
"allValues",
"revision",
"namespace",
"kubeConfig",
"kubeConfigContents"
})
public class GetValuesOptions extends Structure {
public String releaseName;
public int allValues;
public int revision;
public String namespace;
public String kubeConfig;
public String kubeConfigContents;

public GetValuesOptions(String releaseName, int allValues, int revision, String namespace, String kubeConfig, String kubeConfigContents) {
this.releaseName = releaseName;
this.allValues = allValues;
this.revision = revision;
this.namespace = namespace;
this.kubeConfig = kubeConfig;
this.kubeConfigContents = kubeConfigContents;
}
}
3 changes: 3 additions & 0 deletions lib/api/src/main/java/com/marcnuri/helm/jni/HelmLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/**
* @author Marc Nuri
* @author Andres F. Vallecilla
* @author Antonio Fernandez Alhambra
*/
public interface HelmLib extends Library {

Expand All @@ -38,6 +39,8 @@ public interface HelmLib extends Library {

Result List(ListOptions options);

Result GetValues(GetValuesOptions options);

Result Package(PackageOptions options);

Result Push(PushOptions options);
Expand Down
65 changes: 65 additions & 0 deletions native/internal/helm/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2026 Marc Nuri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package helm

import (
"encoding/json"

"helm.sh/helm/v3/pkg/action"
"sigs.k8s.io/yaml"
)

type GetValuesOptions struct {
ReleaseName string
AllValues bool
Revision int
Namespace string
KubeConfig string
KubeConfigContents string
}

func GetValues(options *GetValuesOptions) (string, error) {
cfg, err := NewCfg(&CfgOptions{
KubeConfig: options.KubeConfig,
KubeConfigContents: options.KubeConfigContents,
Namespace: options.Namespace,
})
if err != nil {
return "", err
}
client := action.NewGetValues(cfg)
client.AllValues = options.AllValues
if options.Revision > 0 {
client.Version = options.Revision
}

values, err := client.Run(options.ReleaseName)
if err != nil {
return "", err
}

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