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