Skip to main content

helm_rs/release/
hook.rs

1//! Hook records (`pkg/release/v1/hook.go`).
2
3use jiff::Timestamp;
4use serde::{Deserialize, Serialize};
5
6use super::kinds::{DeletePolicy, HookEvent, HookPhase, OutputLogPolicy};
7use crate::go_json::{null_default, omit_zero};
8
9/// A hook of a release as Helm records it (`Hook`): the manifest plus how and when it runs.
10#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
11pub struct Hook {
12    /// The resource name (`metadata.name`).
13    #[serde(default, skip_serializing_if = "String::is_empty")]
14    pub name: String,
15    /// The Kubernetes kind.
16    #[serde(default, skip_serializing_if = "String::is_empty")]
17    pub kind: String,
18    /// The chart-relative path of the template that produced it.
19    #[serde(default, skip_serializing_if = "String::is_empty")]
20    pub path: String,
21    /// The hook's manifest text.
22    #[serde(default, skip_serializing_if = "String::is_empty")]
23    pub manifest: String,
24    /// The events the hook fires on (`helm.sh/hook`).
25    #[serde(
26        default,
27        deserialize_with = "null_default",
28        skip_serializing_if = "Vec::is_empty"
29    )]
30    pub events: Vec<HookEvent>,
31    /// The last execution; empty for a hook that never ran.
32    #[serde(default)]
33    pub last_run: HookExecution,
34    /// The execution order among hooks of the same event (`helm.sh/hook-weight`).
35    #[serde(default, skip_serializing_if = "is_zero")]
36    pub weight: i64,
37    /// When the hook resource is deleted (`helm.sh/hook-delete-policy`).
38    #[serde(
39        default,
40        deserialize_with = "null_default",
41        skip_serializing_if = "Vec::is_empty"
42    )]
43    pub delete_policies: Vec<DeletePolicy>,
44    /// When the hook's logs are copied back (`helm.sh/hook-output-log-policy`).
45    #[serde(
46        default,
47        deserialize_with = "null_default",
48        skip_serializing_if = "Vec::is_empty"
49    )]
50    pub output_log_policies: Vec<OutputLogPolicy>,
51}
52
53/// The last execution of a hook (`HookExecution`). Go's zero times read as `None`.
54#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
55pub struct HookExecution {
56    /// When the hook started.
57    #[serde(default, with = "omit_zero", skip_serializing_if = "Option::is_none")]
58    pub started_at: Option<Timestamp>,
59    /// When the hook completed.
60    #[serde(default, with = "omit_zero", skip_serializing_if = "Option::is_none")]
61    pub completed_at: Option<Timestamp>,
62    /// The outcome; the empty phase for a hook that never ran.
63    #[serde(default)]
64    pub phase: HookPhase,
65}
66
67/// Serde predicate for Go's `omitempty` on integers.
68#[allow(clippy::trivially_copy_pass_by_ref)]
69fn is_zero(value: &i64) -> bool {
70    *value == 0
71}