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    WaitingForMachines,
20    ProvisioningFailed,
21    Running,
22    RefreshFailed,
23    UpdatePending,
24    Updating,
25    UpdateFailed,
26    DeletePending,
27    Deleting,
28    DeleteFailed,
29    TeardownRequired,
30    TeardownFailed,
31    Deleted,
32    Error,
33}
34
35impl DeploymentStatus {
36    /// Check if deployment is synced (current state matches desired state).
37    ///
38    /// When synced, no more deployment steps are needed *for the current operation*.
39    /// Note: This doesn't mean the deployment is "done forever":
40    /// - `Running` → heartbeats continue, updates can come
41    /// - `*Failed` → can be retried
42    /// - `Deleted` → can be recreated
43    ///
44    /// "Synced" means: "we've reached the goal of the current deployment phase"
45    pub fn is_synced(&self) -> bool {
46        matches!(
47            self,
48            DeploymentStatus::Running
49                | DeploymentStatus::PreflightsFailed
50                | DeploymentStatus::InitialSetupFailed
51                | DeploymentStatus::ProvisioningFailed
52                | DeploymentStatus::UpdateFailed
53                | DeploymentStatus::DeleteFailed
54                | DeploymentStatus::TeardownRequired
55                | DeploymentStatus::TeardownFailed
56                | DeploymentStatus::RefreshFailed
57                | DeploymentStatus::Deleted
58                | DeploymentStatus::Error
59        )
60    }
61
62    /// Check if deployment is in a failed state that requires retry to proceed.
63    pub fn is_failed(&self) -> bool {
64        matches!(
65            self,
66            DeploymentStatus::PreflightsFailed
67                | DeploymentStatus::InitialSetupFailed
68                | DeploymentStatus::ProvisioningFailed
69                | DeploymentStatus::UpdateFailed
70                | DeploymentStatus::DeleteFailed
71                | DeploymentStatus::TeardownFailed
72                | DeploymentStatus::RefreshFailed
73                | DeploymentStatus::Error
74        )
75    }
76}