helm-rs 0.1.2

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
//! Hook records (`pkg/release/v1/hook.go`).

use jiff::Timestamp;
use serde::{Deserialize, Serialize};

use super::kinds::{DeletePolicy, HookEvent, HookPhase, OutputLogPolicy};
use crate::go_json::{null_default, omit_zero};

/// A hook of a release as Helm records it (`Hook`): the manifest plus how and when it runs.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct Hook {
    /// The resource name (`metadata.name`).
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub name: String,
    /// The Kubernetes kind.
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub kind: String,
    /// The chart-relative path of the template that produced it.
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub path: String,
    /// The hook's manifest text.
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub manifest: String,
    /// The events the hook fires on (`helm.sh/hook`).
    #[serde(
        default,
        deserialize_with = "null_default",
        skip_serializing_if = "Vec::is_empty"
    )]
    pub events: Vec<HookEvent>,
    /// The last execution; empty for a hook that never ran.
    #[serde(default)]
    pub last_run: HookExecution,
    /// The execution order among hooks of the same event (`helm.sh/hook-weight`).
    #[serde(default, skip_serializing_if = "is_zero")]
    pub weight: i64,
    /// When the hook resource is deleted (`helm.sh/hook-delete-policy`).
    #[serde(
        default,
        deserialize_with = "null_default",
        skip_serializing_if = "Vec::is_empty"
    )]
    pub delete_policies: Vec<DeletePolicy>,
    /// When the hook's logs are copied back (`helm.sh/hook-output-log-policy`).
    #[serde(
        default,
        deserialize_with = "null_default",
        skip_serializing_if = "Vec::is_empty"
    )]
    pub output_log_policies: Vec<OutputLogPolicy>,
}

/// The last execution of a hook (`HookExecution`). Go's zero times read as `None`.
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct HookExecution {
    /// When the hook started.
    #[serde(default, with = "omit_zero", skip_serializing_if = "Option::is_none")]
    pub started_at: Option<Timestamp>,
    /// When the hook completed.
    #[serde(default, with = "omit_zero", skip_serializing_if = "Option::is_none")]
    pub completed_at: Option<Timestamp>,
    /// The outcome; the empty phase for a hook that never ran.
    #[serde(default)]
    pub phase: HookPhase,
}

/// Serde predicate for Go's `omitempty` on integers.
#[allow(clippy::trivially_copy_pass_by_ref)]
fn is_zero(value: &i64) -> bool {
    *value == 0
}