Skip to main content

Crate helm_rs

Crate helm_rs 

Source
Expand description

Typed Rust API for Helm 4.

helm-rs drives Helm; it never reimplements Helm’s engine. Everything Helm defines by a file format or data (charts, values, schemas, release records, rendered manifests) is read natively in Rust. Everything defined by Helm’s behaviour (rendering, coalescing values, dependencies, hooks, install, upgrade, wait) goes through a Backend.

The backend is a type parameter of Helm, chosen statically; each backend sits behind its own Cargo feature:

  • cli (default): cli::Cli runs the helm binary, Helm 4 only.
  • mock: mock::Mock, a scriptable backend for tests.
  • kube: native reads that need a cluster connection (release::store).

See cli::Cli for a no_run example against a real Helm and mock::Mock for a runnable one.

§Building commands

Every command in command has a builder derived with bon. The arguments Helm requires go to builder(...), so leaving one out does not compile; each flag is a setter, with maybe_<flag> taking an Option and &str accepted wherever a String or a path is stored. Repeated flags have a setter for the whole list and one for a single item. Command::new(...) is the same command with every flag left to Helm.

use std::time::Duration;

use helm_rs::command::{ChartPathOptions, ChartRef, Install, ReleaseName, WaitStrategy};
use helm_rs::{Helm, Values};

let helm = Helm::detect().await?.with_namespace("prod");
let install = Install::builder(
    ReleaseName::Named("web".to_owned()),
    ChartRef::Repo("charts/web".to_owned()),
)
.chart_path(ChartPathOptions::builder().version("^2.0.0").build())
.values(Values::new().set("replicas", 3))
.create_namespace(true)
.label("team", "web")
.wait(WaitStrategy::Watcher)
.timeout(Duration::from_secs(300))
.build();
let release = helm.run(install).await?;

println!("{}", release.name);

§Loading charts

Chart::fetch loads a chart from wherever it lives: a path natively, a repository, URL or oci:// chart through helm pull into a temporary directory that is removed afterwards.

use helm_rs::command::{ChartPathOptions, ChartRef};
use helm_rs::{Chart, Helm};

let helm = Helm::detect().await?;
let options = ChartPathOptions::builder().version("1.2.3").build();
let chart = Chart::fetch(&helm, &ChartRef::Repo("charts/web".into()), &options).await?;

println!("{}", chart.name());

Re-exports§

pub use backend::Backend;
pub use backend::Command;
pub use backend::Execute;
pub use chart::Chart;
pub use cli::Cli;
pub use helm::Helm;
pub use manifest::Manifest;
pub use options::GlobalOptions;
pub use options::Secret;
pub use release::Release;
pub use values::Values;

Modules§

backend
The traits that connect typed commands to backends.
chart
Charts as data: Chart.yaml, Chart.lock, values, schema, templates and subcharts, loaded natively from a directory or a .tgz archive without the helm binary.
cli
The helm binary backend.
command
Typed Helm commands, one file per group. Each command is a plain struct implementing Command; backends implement Execute for the ones they support.
helm
The Helm handle.
manifest
Rendered manifest parsing.
mock
A scriptable backend for tests of code built on helm-rs.
options
Helm’s global flags and environment settings.
release
Helm 4 release records, read natively.
repo
A chart repository’s index.yaml, read natively.
schema
values.schema.json validation, mirroring Helm v4.3.0 ValidateAgainstSchema (pkg/chart/common/util/jsonschema.go).
values
Value sources for install, upgrade, template and lint.
version
Semantic versions and constraints the way Helm reads them.

Enums§

Error
Everything that can go wrong when driving Helm through a backend.

Type Aliases§

Result
Result alias using the crate Error.