use k8s_openapi::api::core::v1::{Volume, VolumeMount};
pub trait VolumeMountLike {
fn volume_name(&self) -> &str;
fn mount_path(&self) -> &str;
fn read_only(&self) -> bool;
fn sub_path(&self) -> Option<&str>;
fn as_volume_mount(&self) -> VolumeMount;
fn as_volume(&self) -> Volume;
}
pub trait VolumeSourceLike {
fn volume_type(&self) -> &str;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_trait_bounds() {
fn accepts_volume_mount(_: Box<dyn VolumeMountLike>) {}
fn accepts_volume_source(_: Box<dyn VolumeSourceLike>) {}
accepts_volume_mount(Box::new(TestVolume));
accepts_volume_source(Box::new(TestVolume));
}
struct TestVolume;
impl VolumeMountLike for TestVolume {
fn volume_name(&self) -> &str {
"test"
}
fn mount_path(&self) -> &str {
"/test"
}
fn read_only(&self) -> bool {
false
}
fn sub_path(&self) -> Option<&str> {
None
}
fn as_volume_mount(&self) -> VolumeMount {
VolumeMount {
name: "test".to_string(),
mount_path: "/test".to_string(),
read_only: Some(false),
sub_path: None,
mount_propagation: None,
sub_path_expr: None,
}
}
fn as_volume(&self) -> Volume {
Volume {
name: "test".to_string(),
empty_dir: None,
host_path: None,
persistent_volume_claim: None,
config_map: None,
secret: None,
..Default::default()
}
}
}
impl VolumeSourceLike for TestVolume {
fn volume_type(&self) -> &str {
"test"
}
}
}