feat/ceph-osd-score #116

Merged
wjro merged 4 commits from feat/ceph-osd-score into master 2025-08-20 18:19:48 +00:00
5 changed files with 115 additions and 0 deletions
Showing only changes of commit b43ca7c740 - Show all commits

View File

@ -17,6 +17,7 @@ use kube::{
};
use log::{debug, error, trace};
use serde::{Serialize, de::DeserializeOwned};
use serde_json::json;
use similar::TextDiff;
#[derive(new, Clone)]
@ -51,6 +52,38 @@ impl K8sClient {
})
}
pub async fn get_pod(&self, name: &str, namespace: Option<&str>) -> Result<Option<Pod>, Error> {
let pods: Api<Pod> = if let Some(ns) = namespace {
Api::namespaced(self.client.clone(), ns)
} else {
Api::default_namespaced(self.client.clone())
};
Ok(pods.get_opt(name).await?)
}
pub async fn scale_deployment(
&self,
name: &str,
namespace: Option<&str>,
replicas: u32,
) -> Result<(), Error> {
let deployments: Api<Deployment> = if let Some(ns) = namespace {
Api::namespaced(self.client.clone(), ns)
} else {
Api::default_namespaced(self.client.clone())
};
let patch = json!({
"spec": {
"replicas": replicas
}
});
let pp = PatchParams::default();
let scale = Patch::Apply(&patch);
deployments.patch_scale(name, &pp, &scale).await?;
Ok(())
}
pub async fn wait_until_deployment_ready(
&self,
name: String,

View File

@ -14,5 +14,6 @@ pub mod monitoring;
pub mod okd;
pub mod opnsense;
pub mod prometheus;
pub mod storage;
pub mod tenant;
pub mod tftp;

View File

@ -0,0 +1,79 @@
use std::process::Command;
use async_trait::async_trait;
use serde::Serialize;
use crate::{
data::{Id, Version},
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
inventory::Inventory,
score::Score,
topology::{K8sclient, Topology},
};
#[derive(Debug, Clone, Serialize)]
pub struct PrepCephOsdReplacement {
osd_name: String,
rook_ceph_namespace: String,
}
impl<T: Topology + K8sclient> Score<T> for PrepCephOsdReplacement {
fn name(&self) -> String {
format!("CephOsdReplacementScore")
}
#[doc(hidden)]
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
Box::new(PrepCephOsdReplacementInterpret {
score: self.clone(),
})
}
}
#[derive(Debug, Clone)]
pub struct PrepCephOsdReplacementInterpret {
score: PrepCephOsdReplacement,
}
#[async_trait]
impl<T: Topology + K8sclient> Interpret<T> for PrepCephOsdReplacementInterpret {
async fn execute(
&self,
_inventory: &Inventory,
topology: &T,
) -> Result<Outcome, InterpretError> {
let client = topology.k8s_client().await.unwrap();
client
.scale_deployment(
&self.score.osd_name,
Some(&self.score.rook_ceph_namespace),
0,
)
.await?;
Review

Nice, super lisible.

Eventuellement plusieurs de ces helper functions pourront aller dans un module ceph management ou quelque chose comme ca.

Nice, super lisible. Eventuellement plusieurs de ces helper functions pourront aller dans un module ceph management ou quelque chose comme ca.
client
.get_pod(&self.score.osd_name, Some(&self.score.rook_ceph_namespace))
.await?;
Ok(Outcome::success(
"Successfully prepared rook-ceph-cluster for disk replacement".to_string(),
))
}
fn get_name(&self) -> InterpretName {
todo!()
}
fn get_version(&self) -> Version {
todo!()
}
fn get_status(&self) -> InterpretStatus {
todo!()
}
fn get_children(&self) -> Vec<Id> {
todo!()
}
}
impl PrepCephOsdReplacementInterpret {}

View File

@ -0,0 +1 @@
pub mod ceph_osd_replacement_score;

View File

@ -0,0 +1 @@
pub mod ceph;