Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions metrics-cache/src/section/pvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ mod tests {
.or_default()
.insert(pvc.metadata.name.clone().unwrap(), pvc.into());
}
let pv = pv("test-local-pv");
indexes
.pvs
.insert(pv.metadata.name.clone().unwrap(), pv.into());
indexes
}

Expand Down Expand Up @@ -382,6 +386,37 @@ mod tests {
);
}

#[test]
fn kube_pvc_pvs_v1() {
let mut indexes = pvc_indexes();

// Both claims resolve to their backing PV, section renders
insta::assert_json_snapshot!(KubePvcPvsV1::from_claim_names(
&indexes,
"really-cool-namespace",
["pvc-1", "pvc-2"]
));

// No claim resolves to a PVC at all -> no section
assert_matches!(
KubePvcPvsV1::from_claim_names(&indexes, "really-cool-namespace", ["bad", "worse"]),
None
);

// A claim whose PVC exists but isn't bound to a PV is skipped
let mut unbound = pvc("pvc-unbound");
unbound.spec.as_mut().unwrap().volume_name = None;
indexes
.pvcs
.entry(s("really-cool-namespace"))
.or_default()
.insert(s("pvc-unbound"), unbound.into());
assert_matches!(
KubePvcPvsV1::from_claim_names(&indexes, "really-cool-namespace", ["pvc-unbound"]),
None
);
}

#[test]
fn workload_pvc_claim_names_are_deduplicated() {
let mut first = pod("first", None);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: metrics-cache/src/section/pvc.rs
expression: "KubePvcPvsV1::from_claim_names(&indexes, \"really-cool-namespace\",\n[\"pvc-1\", \"pvc-2\"])"
---
{
"volumes": {
"test-local-pv": {
"name": "test-local-pv",
"spec": {
"access_modes": [
"ReadWriteOnce"
],
"storage_class_name": "manual",
"volume_mode": "Filesystem"
}
}
}
}
20 changes: 18 additions & 2 deletions metrics-cache/src/test_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use k8s_openapi::api::apps::v1::{
use k8s_openapi::api::batch::v1::{CronJob, CronJobSpec, Job};
use k8s_openapi::api::core::v1::{
Container, ContainerStatus, Namespace, Node, NodeAddress, NodeStatus, NodeSystemInfo,
PersistentVolumeClaim, PersistentVolumeClaimSpec, PersistentVolumeClaimStatus, Pod, PodSpec,
VolumeResourceRequirements,
PersistentVolume, PersistentVolumeClaim, PersistentVolumeClaimSpec,
PersistentVolumeClaimStatus, PersistentVolumeSpec, Pod, PodSpec, VolumeResourceRequirements,
};
use k8s_openapi::apimachinery::pkg::api::resource::Quantity;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::{
Expand Down Expand Up @@ -382,3 +382,19 @@ pub fn pvc(name: &str) -> PersistentVolumeClaim {
}),
}
}

pub fn pv(name: &str) -> PersistentVolume {
PersistentVolume {
metadata: ObjectMeta {
name: Some(name.to_string()),
..Default::default()
},
spec: Some(PersistentVolumeSpec {
access_modes: Some(vec![s("ReadWriteOnce")]),
storage_class_name: Some(s("manual")),
volume_mode: Some(s("Filesystem")),
..Default::default()
}),
..Default::default()
}
}
Loading