sherpack_core/
release.rs

1//! Release management types
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6use crate::pack::PackMetadata;
7use crate::values::Values;
8
9/// A deployed release of a pack
10#[derive(Debug, Clone, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct Release {
13    /// Release name
14    pub name: String,
15
16    /// Kubernetes namespace
17    pub namespace: String,
18
19    /// Revision number
20    pub revision: u32,
21
22    /// Current status
23    pub status: ReleaseStatus,
24
25    /// Pack metadata at deploy time
26    pub pack: PackMetadata,
27
28    /// Values used for this release
29    pub values: Values,
30
31    /// Rendered manifest
32    pub manifest: String,
33
34    /// Creation timestamp
35    pub created_at: DateTime<Utc>,
36
37    /// Last update timestamp
38    pub updated_at: DateTime<Utc>,
39}
40
41/// Release status
42///
43/// Note: This enum is non-exhaustive - new variants may be added in future versions.
44#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
45#[serde(rename_all = "kebab-case")]
46#[non_exhaustive]
47pub enum ReleaseStatus {
48    #[default]
49    Unknown,
50    Deployed,
51    Uninstalled,
52    Superseded,
53    Failed,
54    Uninstalling,
55    PendingInstall,
56    PendingUpgrade,
57    PendingRollback,
58}
59
60impl std::fmt::Display for ReleaseStatus {
61    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62        let s = match self {
63            Self::Unknown => "unknown",
64            Self::Deployed => "deployed",
65            Self::Uninstalled => "uninstalled",
66            Self::Superseded => "superseded",
67            Self::Failed => "failed",
68            Self::Uninstalling => "uninstalling",
69            Self::PendingInstall => "pending-install",
70            Self::PendingUpgrade => "pending-upgrade",
71            Self::PendingRollback => "pending-rollback",
72        };
73        write!(f, "{}", s)
74    }
75}
76
77/// Release information for templates
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(rename_all = "camelCase")]
80pub struct ReleaseInfo {
81    /// Release name
82    pub name: String,
83
84    /// Target namespace
85    pub namespace: String,
86
87    /// Revision number
88    pub revision: u32,
89
90    /// Is this an install operation?
91    pub is_install: bool,
92
93    /// Is this an upgrade operation?
94    pub is_upgrade: bool,
95
96    /// Service (always "Sherpack")
97    pub service: String,
98}
99
100impl ReleaseInfo {
101    /// Create release info for a new install
102    pub fn for_install(name: &str, namespace: &str) -> Self {
103        Self {
104            name: name.to_string(),
105            namespace: namespace.to_string(),
106            revision: 1,
107            is_install: true,
108            is_upgrade: false,
109            service: "Sherpack".to_string(),
110        }
111    }
112
113    /// Create release info for an upgrade
114    pub fn for_upgrade(name: &str, namespace: &str, revision: u32) -> Self {
115        Self {
116            name: name.to_string(),
117            namespace: namespace.to_string(),
118            revision,
119            is_install: false,
120            is_upgrade: true,
121            service: "Sherpack".to_string(),
122        }
123    }
124}