1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use super::{resources::parse_memory, Result};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum VolumeAccessMode {
ReadWriteOnce,
ReadOnlyMany,
ReadWriteMany,
}
impl Default for VolumeAccessMode {
fn default() -> Self {
Self::ReadWriteOnce
}
}
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct PersistentVolume {
pub name: String,
pub mountPath: String,
pub size: String,
#[serde(default)]
pub accessMode: VolumeAccessMode,
}
impl PersistentVolume {
pub fn verify(&self) -> Result<()> {
let size = parse_memory(&self.size)?;
if size > 16.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 {
bail!("Persistent Volume request more than 16 TB")
}
if !self.mountPath.starts_with('/') {
bail!("Mount path '{}' must start with a slash", self.mountPath);
}
if self.mountPath.ends_with('/') {
bail!("Mount path '{}' must not end with a slash", self.mountPath);
}
Ok(())
}
}