-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pub mod persistent_volume_claims; | ||
pub mod persistent_volume_claims_payload; | ||
|
||
#[cfg(test)] | ||
mod persistent_volume_claims_tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::k8s_ops::pvc::{ | ||
persistent_volume_claims::{get_pvcs_available, PVCOperator}, | ||
persistent_volume_claims_payload::PVCOperatorPayload, | ||
}; | ||
use k8s_openapi::{ | ||
api::core::v1::{ | ||
PersistentVolumeClaim, PersistentVolumeClaimSpec, TypedLocalObjectReference, | ||
TypedObjectReference, VolumeResourceRequirements, | ||
}, | ||
apimachinery::pkg::api::resource::Quantity, | ||
}; | ||
use kube::{api::ObjectMeta, Api, Client}; | ||
use pretty_assertions::assert_eq; | ||
use std::collections::BTreeMap; | ||
|
||
#[test] | ||
fn test_construct_persistent_volume_claim_resource() { | ||
let pvc_operator_payload = PVCOperatorPayload::new( | ||
"test-pvc".to_string(), | ||
"test-ns".to_string(), | ||
"gp3".to_string(), | ||
Some(vec!["ReadWriteOnce".to_string()]), | ||
"test-vs".to_string(), | ||
"1Gi".to_string(), | ||
); | ||
|
||
let pvc_operator = PVCOperator::new(pvc_operator_payload); | ||
|
||
let pvc = pvc_operator.construct_persistent_volume_claim_resource(); | ||
|
||
let mut labels = BTreeMap::new(); | ||
labels.insert( | ||
"pvc-snapshotter/volume-snapshot-name".to_string(), | ||
"test-pvc".to_string(), | ||
); | ||
|
||
let expected_pvc = PersistentVolumeClaim { | ||
metadata: ObjectMeta { | ||
name: Some("test-pvc".to_string()), | ||
namespace: Some("test-ns".to_string()), | ||
labels: Some(labels), | ||
..Default::default() | ||
}, | ||
spec: Some(PersistentVolumeClaimSpec { | ||
access_modes: Some(vec!["ReadWriteOnce".to_string()]), | ||
storage_class_name: Some("gp3".to_string()), | ||
data_source: Some(TypedLocalObjectReference { | ||
name: "test-vs".to_string(), | ||
kind: "VolumeSnapshot".to_string(), | ||
api_group: Some("snapshot.storage.k8s.io".to_string()), | ||
}), | ||
data_source_ref: Some(TypedObjectReference { | ||
name: "test-vs".to_string(), | ||
kind: "VolumeSnapshot".to_string(), | ||
api_group: Some("snapshot.storage.k8s.io".to_string()), | ||
namespace: Some("test-ns".to_string()), | ||
}), | ||
volume_mode: Some("Filesystem".to_string()), | ||
volume_name: Default::default(), | ||
resources: Some(VolumeResourceRequirements { | ||
requests: Some(BTreeMap::from([( | ||
"storage".to_string(), | ||
Quantity("1Gi".to_string()), | ||
)])), | ||
..Default::default() | ||
}), | ||
selector: Default::default(), | ||
volume_attributes_class_name: Default::default(), | ||
}), | ||
..Default::default() | ||
}; | ||
|
||
assert_eq!(pvc, expected_pvc); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_get_pvcs_available() { | ||
let client = Client::try_default().await.unwrap(); | ||
let api: Api<PersistentVolumeClaim> = Api::namespaced(client, "test-ns"); | ||
let pvcs = get_pvcs_available(&api).await.unwrap(); | ||
assert!(pvcs.is_empty()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_check_if_pvc_exists() { | ||
let client = Client::try_default().await.unwrap(); | ||
let api: Api<PersistentVolumeClaim> = Api::namespaced(client, "test-ns"); | ||
let pvc = api.get("test-pvc").await; | ||
assert!(pvc.is_err()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
pub mod volume_snapshots; | ||
|
||
#[cfg(test)] | ||
mod volume_snapshots_tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::k8s_ops::{ | ||
vs::volume_snapshots::VolumeSnapshotOperator, vsc::retain_policy::VSCRetainPolicy, | ||
}; | ||
use pretty_assertions::assert_eq; | ||
|
||
#[tokio::test] | ||
async fn test_construct_volume_snapshot_resource() { | ||
let vs_operator = VolumeSnapshotOperator::new( | ||
"test-volume-snapshot".to_string(), | ||
"default".to_string(), | ||
"ebs.csi.aws.com".to_string(), | ||
Some("test-pvc".to_string()), | ||
Some("test-volume-snapshot-content".to_string()), | ||
); | ||
let volume_snapshot = vs_operator.construct_volume_snapshot_resource( | ||
Some("test-snapshot-handle".to_string()), | ||
Some("1Gi".to_string()), | ||
VSCRetainPolicy::Delete, | ||
); | ||
assert_eq!( | ||
volume_snapshot.metadata.name.unwrap(), | ||
"test-volume-snapshot" | ||
); | ||
assert_eq!(volume_snapshot.metadata.namespace.unwrap(), "default"); | ||
assert_eq!( | ||
volume_snapshot | ||
.metadata | ||
.annotations | ||
.as_ref() | ||
.unwrap() | ||
.get("pvc-snapshotter/csi-driver-name"), | ||
Some(&"ebs.csi.aws.com".to_string()) | ||
); | ||
assert_eq!( | ||
volume_snapshot | ||
.metadata | ||
.annotations | ||
.as_ref() | ||
.unwrap() | ||
.get("pvc-snapshotter/csi-vsc-deletion-policy"), | ||
Some(&"Delete".to_string()) | ||
); | ||
assert_eq!( | ||
volume_snapshot | ||
.metadata | ||
.annotations | ||
.as_ref() | ||
.unwrap() | ||
.get("pvc-snapshotter/csi-volumesnapshot-handle"), | ||
Some(&"test-snapshot-handle".to_string()) | ||
); | ||
assert_eq!( | ||
volume_snapshot | ||
.metadata | ||
.annotations | ||
.unwrap() | ||
.get("pvc-snapshotter/csi-volumesnapshot-restore-size"), | ||
Some(&"1Gi".to_string()) | ||
); | ||
assert_eq!( | ||
volume_snapshot | ||
.metadata | ||
.labels | ||
.unwrap() | ||
.get("app.kubernetes.io/instance"), | ||
Some(&"default".to_string()) | ||
); | ||
assert_eq!( | ||
volume_snapshot.spec.volume_snapshot_class_name.unwrap(), | ||
"ebs.csi.aws.com" | ||
); | ||
assert_eq!( | ||
volume_snapshot | ||
.spec | ||
.source | ||
.persistent_volume_claim_name | ||
.unwrap(), | ||
"test-pvc" | ||
); | ||
assert_eq!( | ||
volume_snapshot | ||
.spec | ||
.source | ||
.volume_snapshot_content_name | ||
.unwrap(), | ||
"test-volume-snapshot-content" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pub mod retain_policy; | ||
pub mod volume_snapshot_contents; | ||
|
||
#[cfg(test)] | ||
mod volume_snapshot_contents_tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::k8s_ops::vsc::{ | ||
retain_policy::VSCRetainPolicy, volume_snapshot_contents::VolumeSnapshotContentOperator, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn test_construct_volume_snapshot_content_resource() { | ||
let vsc_operator = VolumeSnapshotContentOperator::new( | ||
"test-volume-snapshot-content".to_string(), | ||
"default".to_string(), | ||
"test-volume-snapshot".to_string(), | ||
Some("ebs.csi.aws.com".to_string()), | ||
Some("test-snapshot-handle".to_string()), | ||
VSCRetainPolicy::Delete, | ||
); | ||
let volume_snapshot_content = vsc_operator.construct_volume_snapshot_content_resource(); | ||
assert_eq!( | ||
volume_snapshot_content.metadata.name.unwrap(), | ||
"test-volume-snapshot-content" | ||
); | ||
assert_eq!( | ||
volume_snapshot_content.metadata.namespace.unwrap(), | ||
"default" | ||
); | ||
assert_eq!( | ||
volume_snapshot_content | ||
.spec | ||
.volume_snapshot_ref | ||
.name | ||
.unwrap(), | ||
"test-volume-snapshot" | ||
); | ||
assert_eq!( | ||
volume_snapshot_content | ||
.spec | ||
.volume_snapshot_class_name | ||
.unwrap(), | ||
"ebs.csi.aws.com" | ||
); | ||
assert_eq!( | ||
volume_snapshot_content.spec.source.snapshot_handle.unwrap(), | ||
"test-snapshot-handle" | ||
); | ||
assert_eq!( | ||
volume_snapshot_content.spec.source_volume_mode.unwrap(), | ||
"Filesystem" | ||
); | ||
assert_eq!( | ||
volume_snapshot_content | ||
.status | ||
.as_ref() | ||
.unwrap() | ||
.snapshot_handle | ||
.as_ref() | ||
.unwrap(), | ||
"test-snapshot-handle" | ||
); | ||
} | ||
} |