Skip to main content

alien_core/deployment/
status.rs

1//! Deployment status enum and lifecycle phase checks.
2
3use serde::{Deserialize, Serialize};
4
5/// Deployment status in the deployment lifecycle.
6///
7/// For observe-only deployments with no release or stack state, `Running`
8/// means the Operator is attached. Connectivity comes from `lastHeartbeatAt`;
9/// resource health comes from inventory and resource heartbeat data.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
12#[serde(rename_all = "kebab-case")]
13pub enum DeploymentStatus {
14    Pending,
15    PreflightsFailed,
16    InitialSetup,
17    InitialSetupFailed,
18    Provisioning,
19    ProvisioningFailed,
20    Running,
21    RefreshFailed,
22    UpdatePending,
23    Updating,
24    UpdateFailed,
25    DeletePending,
26    Deleting,
27    DeleteFailed,
28    TeardownRequired,
29    TeardownFailed,
30    Deleted,
31    Error,
32}
33
34impl DeploymentStatus {
35    /// Check if deployment is synced (current state matches desired state).
36    ///
37    /// When synced, no more deployment steps are needed *for the current operation*.
38    /// Note: This doesn't mean the deployment is "done forever":
39    /// - `Running` → heartbeats continue, updates can come
40    /// - `*Failed` → can be retried
41    /// - `Deleted` → can be recreated
42    ///
43    /// "Synced" means: "we've reached the goal of the current deployment phase"
44    pub fn is_synced(&self) -> bool {
45        matches!(
46            self,
47            DeploymentStatus::Running
48                | DeploymentStatus::PreflightsFailed
49                | DeploymentStatus::InitialSetupFailed
50                | DeploymentStatus::ProvisioningFailed
51                | DeploymentStatus::UpdateFailed
52                | DeploymentStatus::DeleteFailed
53                | DeploymentStatus::TeardownRequired
54                | DeploymentStatus::TeardownFailed
55                | DeploymentStatus::RefreshFailed
56                | DeploymentStatus::Deleted
57                | DeploymentStatus::Error
58        )
59    }
60
61    /// Check if deployment is in a failed state that requires retry to proceed.
62    pub fn is_failed(&self) -> bool {
63        matches!(
64            self,
65            DeploymentStatus::PreflightsFailed
66                | DeploymentStatus::InitialSetupFailed
67                | DeploymentStatus::ProvisioningFailed
68                | DeploymentStatus::UpdateFailed
69                | DeploymentStatus::DeleteFailed
70                | DeploymentStatus::TeardownFailed
71                | DeploymentStatus::RefreshFailed
72                | DeploymentStatus::Error
73        )
74    }
75}