41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
use kube::{
|
|
api::{Api, DeleteParams, PostParams},
|
|
Client,
|
|
};
|
|
use k8s_openapi::api::core::v1::Pod;
|
|
use rand::seq::SliceRandom;
|
|
|
|
pub struct ChaosTest {
|
|
client: Client,
|
|
namespace: String,
|
|
}
|
|
|
|
impl ChaosTest {
|
|
pub async fn new(namespace: String) -> anyhow::Result<Self> {
|
|
let client = Client::try_default().await?;
|
|
Ok(Self { client, namespace })
|
|
}
|
|
|
|
pub async fn kill_random_pod(&self) -> anyhow::Result<()> {
|
|
let pods: Api<Pod> = Api::namespaced(self.client.clone(), &self.namespace);
|
|
let pod_list = pods.list(&Default::default()).await?;
|
|
|
|
if let Some(pod) = pod_list.items.choose(&mut rand::thread_rng()) {
|
|
if let Some(name) = &pod.metadata.name {
|
|
pods.delete(name, &DeleteParams::default()).await?;
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn network_partition(&self) -> anyhow::Result<()> {
|
|
// Network partition test implementation
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn resource_exhaustion(&self) -> anyhow::Result<()> {
|
|
// Resource exhaustion test implementation
|
|
Ok(())
|
|
}
|
|
}
|