Skip to content

Values

What problem this solves

Values are usually the integration boundary between your product model and a Helm chart. HelmSharp keeps the familiar Helm precedence model so operators can bring existing values files and --set-style overrides.

Packages to install

powershell
dotnet add package HelmSharp.Chart --version 1.1.0

Minimal complete code

csharp
public static async Task<Dictionary<string, object?>> BuildProductionValuesAsync(
    HelmChart chart,
    string baseValuesPath,
    string productionValuesPath,
    string licenseFilePath,
    CancellationToken cancellationToken)
{
    var licenseContent = await File.ReadAllTextAsync(licenseFilePath, cancellationToken);

    return await HelmValues.BuildAsync(
        chart: chart,
        valuesFiles: [baseValuesPath, productionValuesPath],
        valuesContent: """
            global:
              environment: production
            """,
        setValues: new Dictionary<string, string>
        {
            ["replicaCount"] = "3"
        },
        setFileValues: new Dictionary<string, string>
        {
            ["license.text"] = licenseContent
        },
        setStringValues: new Dictionary<string, string>
        {
            ["image.tag"] = "001"
        },
        setJsonValues: new Dictionary<string, string>
        {
            ["service.ports"] = """[{"name":"http","port":80}]"""
        },
        cancellationToken: cancellationToken);
}

Why these APIs

HelmValues.BuildAsync merges inputs from lowest to highest precedence:

InputMeaning
Chart defaultsvalues.yaml bundled with the chart.
Subchart defaultsDependency defaults under dependency name or alias.
valuesFilesOne or more values files, applied in order.
valuesContentInline YAML from a database, request, or generated config.
setFileValuesFile content assigned to a values path.
setStringValuesString-preserving overrides.
setValuesScalar-coercing --set style overrides.
setJsonValuesJSON object or array overrides.

Production notes

  • Keep the precedence order visible in code reviews.
  • Read file content before passing SetFileValues; the value is content, not a file path.
  • Use SetStringValues for tags such as "001" that must not become numbers.

Next step

Use Template Rendering when values must influence Capabilities, NOTES, or CRD output.

Released under the MIT License.