helm_rs/command/release/lifecycle.rs
1use std::time::Duration;
2
3use super::{DryRun, Force, ServerSide, WaitStrategy};
4use crate::backend::Command;
5use crate::command::builder_collections;
6use crate::release::Revision;
7
8/// `helm rollback` (`pkg/cmd/rollback.go`): rolls a release back to an earlier revision. Helm
9/// prints only a success line, so there is no output; read the result with
10/// [`Status`](crate::command::Status).
11#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
12#[builder(on(String, into), on(bool, default))]
13pub struct Rollback {
14 /// The `RELEASE` argument.
15 #[builder(start_fn)]
16 pub release: String,
17 /// The `REVISION` argument; without it (or with revision 0) Helm rolls back to the previous
18 /// revision.
19 pub revision: Option<Revision>,
20 /// Flag `--cleanup-on-fail`: delete the resources this rollback created if it fails.
21 pub cleanup_on_fail: bool,
22 /// Flag `--description`: a custom description of at most 256 characters (Helm checks).
23 pub description: Option<String>,
24 /// Flag `--dry-run`.
25 pub dry_run: Option<DryRun>,
26 /// Flags `--force-replace` and `--force-conflicts`.
27 pub force: Option<Force>,
28 /// Flag `--history-max`: how many revisions to keep; 0 keeps all (Helm's default is 10).
29 pub history_max: Option<u32>,
30 /// Flag `--no-hooks`: skip hooks.
31 pub no_hooks: bool,
32 /// Flag `--server-side` (Helm's default is `auto`).
33 pub server_side: Option<ServerSide>,
34 /// Flag `--timeout` for any single Kubernetes operation (Helm's default is five minutes).
35 pub timeout: Option<Duration>,
36 /// Flag `--wait` (Helm's default is `hookOnly`).
37 pub wait: Option<WaitStrategy>,
38 /// Flag `--wait-for-jobs`: with a wait, also wait for Jobs to complete.
39 pub wait_for_jobs: bool,
40}
41
42impl Rollback {
43 /// A rollback of `release` to the previous revision with every other setting left to Helm.
44 #[must_use]
45 pub fn new(release: impl Into<String>) -> Self {
46 Self::builder(release).build()
47 }
48}
49
50impl Command for Rollback {
51 type Output = ();
52}
53
54/// How Helm deletes the objects that depend on a release's resources (`--cascade`).
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub enum Cascade {
57 /// `background`: delete the owner, then the dependents (Helm's default).
58 Background,
59 /// `orphan`: leave the dependents.
60 Orphan,
61 /// `foreground`: delete the dependents first; combine with a wait to block until they are
62 /// gone.
63 Foreground,
64}
65
66impl Cascade {
67 /// The flag value.
68 #[must_use]
69 pub fn as_str(self) -> &'static str {
70 match self {
71 Self::Background => "background",
72 Self::Orphan => "orphan",
73 Self::Foreground => "foreground",
74 }
75 }
76}
77
78/// `helm uninstall` (`pkg/cmd/uninstall.go`): removes one or more releases. Helm prints one
79/// `release "name" uninstalled` line per release (also for a missing one under
80/// `ignore_not_found`, and for a dry run), which carries no more than success, so there is no
81/// output. A release that does not exist is [`Error::ReleaseNotFound`](crate::Error) unless
82/// `ignore_not_found` is set. Helm stops at the first failure; earlier releases stay uninstalled.
83#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
84#[builder(start_fn(name = start, vis = ""), on(String, into), on(bool, default))]
85#[allow(clippy::struct_excessive_bools, reason = "one field per Helm flag")]
86pub struct Uninstall {
87 /// The `RELEASE_NAME` arguments (Helm needs at least one).
88 #[builder(field)]
89 pub releases: Vec<String>,
90 /// Flag `--cascade` (Helm's default is `background`).
91 pub cascade: Option<Cascade>,
92 /// Flag `--description`: a custom description.
93 pub description: Option<String>,
94 /// Flag `--dry-run`: only simulate.
95 pub dry_run: bool,
96 /// Flag `--ignore-not-found`: a missing release is a success.
97 pub ignore_not_found: bool,
98 /// Flag `--keep-history`: mark the release uninstalled but keep its history.
99 pub keep_history: bool,
100 /// Flag `--no-hooks`: skip hooks.
101 pub no_hooks: bool,
102 /// Flag `--timeout` for any single Kubernetes operation (Helm's default is five minutes).
103 pub timeout: Option<Duration>,
104 /// Flag `--wait` (Helm's default is `hookOnly`).
105 pub wait: Option<WaitStrategy>,
106}
107
108builder_collections! {
109 UninstallBuilder, uninstall_builder;
110 vec releases / release: String, "`RELEASE_NAME` arguments", "the releases to uninstall";
111}
112
113impl Uninstall {
114 /// Starts building an uninstall of `release`, the first of the required `RELEASE_NAME...`.
115 pub fn builder(release: impl Into<String>) -> UninstallBuilder {
116 Self::start().release(release)
117 }
118
119 /// An uninstall of `release` with every other setting left to Helm.
120 #[must_use]
121 pub fn new(release: impl Into<String>) -> Self {
122 Self::builder(release).build()
123 }
124}
125
126impl Command for Uninstall {
127 type Output = ();
128}
129
130/// `helm test` (`pkg/cmd/release_testing.go`): runs the test hooks of a release. Helm has no
131/// machine-readable output for it (there is no `-o`), so the output is the status text it prints
132/// (including a `TEST SUITE` block per test); the structured result is the hooks' `last_run` in
133/// the release read afterwards with [`Status`](crate::command::Status). A failing test makes
134/// Helm exit with an error, which is reported as [`Error::Backend`](crate::Error).
135#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
136#[builder(on(String, into), on(bool, default))]
137pub struct Test {
138 /// The `RELEASE` argument.
139 #[builder(start_fn)]
140 pub release: String,
141 /// Flag `--filter`, repeated: `name=value` to include or `!name=value` to exclude a test.
142 #[builder(field)]
143 pub filter: Vec<String>,
144 /// Flag `--logs`: print the logs of the test pods.
145 pub logs: bool,
146 /// Flag `--timeout` for any single Kubernetes operation (Helm's default is five minutes).
147 pub timeout: Option<Duration>,
148}
149
150builder_collections! {
151 TestBuilder, test_builder;
152 vec filter / add_filter: String, "repeated flag `--filter`",
153 "`name=value` to include or `!name=value` to exclude a test";
154}
155
156impl Test {
157 /// A test run of `release` with every other setting left to Helm.
158 #[must_use]
159 pub fn new(release: impl Into<String>) -> Self {
160 Self::builder(release).build()
161 }
162}
163
164impl Command for Test {
165 type Output = String;
166}