Coverage Report

Created: 2026-05-19 10:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
crates/flotilla-resources/src/environment.rs
Line
Count
Source
1
use std::collections::BTreeMap;
2
3
use serde::{Deserialize, Serialize};
4
5
use crate::{resource::define_resource, status_patch::StatusPatch};
6
7
define_resource!(Environment, "environments", EnvironmentSpec, EnvironmentStatus, EnvironmentStatusPatch);
8
9
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10
pub struct EnvironmentSpec {
11
    #[serde(default, skip_serializing_if = "Option::is_none")]
12
    pub host_direct: Option<HostDirectEnvironmentSpec>,
13
    #[serde(default, skip_serializing_if = "Option::is_none")]
14
    pub docker: Option<DockerEnvironmentSpec>,
15
}
16
17
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
18
pub struct HostDirectEnvironmentSpec {
19
    pub host_ref: String,
20
    pub repo_default_dir: String,
21
}
22
23
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
24
pub struct DockerEnvironmentSpec {
25
    pub host_ref: String,
26
    pub image: String,
27
    #[serde(default)]
28
    pub mounts: Vec<EnvironmentMount>,
29
    #[serde(default)]
30
    pub env: BTreeMap<String, String>,
31
}
32
33
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
34
pub struct EnvironmentMount {
35
    pub source_path: String,
36
    pub target_path: String,
37
    pub mode: EnvironmentMountMode,
38
}
39
40
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
41
#[serde(rename_all = "lowercase")]
42
pub enum EnvironmentMountMode {
43
    Ro,
44
    Rw,
45
}
46
47
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
48
pub enum EnvironmentPhase {
49
    #[default]
50
    Pending,
51
    Ready,
52
    Terminating,
53
    Failed,
54
}
55
56
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
57
pub struct EnvironmentStatus {
58
    pub phase: EnvironmentPhase,
59
    #[serde(default)]
60
    pub ready: bool,
61
    #[serde(default, skip_serializing_if = "Option::is_none")]
62
    pub docker_container_id: Option<String>,
63
    #[serde(default, skip_serializing_if = "Option::is_none")]
64
    pub message: Option<String>,
65
}
66
67
#[derive(Debug, Clone, PartialEq, Eq)]
68
pub enum EnvironmentStatusPatch {
69
    MarkReady { docker_container_id: Option<String> },
70
    MarkFailed { message: String },
71
    MarkTerminating,
72
}
73
74
impl StatusPatch<EnvironmentStatus> for EnvironmentStatusPatch {
75
14
    fn apply(&self, status: &mut EnvironmentStatus) {
76
14
        match self {
77
13
            Self::MarkReady { docker_container_id } => {
78
13
                status.phase = EnvironmentPhase::Ready;
79
13
                status.ready = true;
80
13
                status.docker_container_id = docker_container_id.clone();
81
13
                status.message = None;
82
13
            }
83
1
            Self::MarkFailed { message } => {
84
1
                status.phase = EnvironmentPhase::Failed;
85
1
                status.ready = false;
86
1
                status.message = Some(message.clone());
87
1
            }
88
0
            Self::MarkTerminating => {
89
0
                status.phase = EnvironmentPhase::Terminating;
90
0
                status.ready = false;
91
0
            }
92
        }
93
14
    }
94
}