Skip to main content

helm_rs/command/render/
template.rs

1use std::path::PathBuf;
2
3use crate::backend::Command;
4use crate::command::release::{ReleaseName, release_command};
5use crate::manifest::Rendered;
6
7release_command! {
8    /// `helm template` (`pkg/cmd/template.go`): renders a chart locally, with the flags of
9    /// `helm install` (`addInstallFlags`) and its own. `helm template` is always a dry run, so
10    /// `dry_run` may be `Client` (Helm's default) or `Server` but not `None`. The deprecated
11    /// `--validate` (use `--dry-run=server`) and the no-op `--hide-notes` and
12    /// `--render-subchart-notes` are not modelled.
13    Template, TemplateBuilder, template_builder {
14        required {}
15        collections {
16            api_versions / api_version: String, "--api-versions",
17                "Kubernetes API versions for `Capabilities.APIVersions`";
18            show_only / add_show_only: String, "--show-only",
19                "print only the documents of these templates (globs such as `templates/*.yaml` \
20                work); a template without output is an error";
21        }
22        flags {
23            /// The `NAME` argument or `--name-template`. Without one Helm names the release
24            /// `release-name`, and `Generated` (`--generate-name`) changes nothing: `NameAndChart`
25            /// (`pkg/action/install.go`) returns the preset name before it generates one.
26            name: Option<ReleaseName>,
27            /// Flag `--include-crds`: print the CRDs of `crds/` too.
28            include_crds: bool,
29            /// Flag `--is-upgrade`: set `.Release.IsUpgrade` instead of `.Release.IsInstall`.
30            is_upgrade: bool,
31            /// Flag `--kube-version`: the version for `Capabilities.KubeVersion`.
32            kube_version: Option<String>,
33            /// Flag `--output-dir`: write the documents to files below this directory instead
34            /// of printing them.
35            output_dir: Option<PathBuf>,
36            /// Flag `--replace`: skip the check that the release name is free (`template` always
37            /// does).
38            replace: bool,
39            /// Flag `--server-side`, a boolean here that Helm defaults to true.
40            server_side: Option<bool>,
41            /// Flag `--skip-tests`: leave the `test` hooks out.
42            skip_tests: bool,
43            /// Flag `--release-name`: put the files below `<output_dir>/<release name>`.
44            use_release_name: bool,
45        }
46    }
47}
48
49impl Template {
50    /// A render of `chart` with every setting left to Helm.
51    #[must_use]
52    pub fn new(chart: crate::command::ChartRef) -> Self {
53        Self::builder(chart).build()
54    }
55}
56
57/// What `helm template` produced: the documents it printed, or, with `output_dir`, the files it
58/// wrote instead.
59#[derive(Debug, Clone, PartialEq)]
60pub enum Templated {
61    /// The printed documents: CRDs (with `include_crds`), resources and hooks.
62    Rendered(Rendered),
63    /// The files Helm wrote (`wrote <path>` lines, `pkg/cmd/template.go`), each once, in order.
64    /// A file with several hooks is appended to and listed once. Paths are as Helm printed them:
65    /// `output_dir` joined with the file's `<chart>/templates/...` source, relative to the working
66    /// directory when `output_dir` is.
67    Written(Vec<PathBuf>),
68}
69
70impl Command for Template {
71    type Output = Templated;
72}