This commit introduces a new topology, `K8sAnywhereTopology`, designed to handle Kubernetes deployments more flexibly. Key changes include: - Introduced `K8sAnywhereTopology` to encapsulate Kubernetes client management and configuration. - Refactored existing Kubernetes-related code to utilize the new topology. - Updated `OcK8sclient` to `K8sclient` across modules (k8s, lamp, deployment, resource) for consistency. - Ensured all relevant modules now interface with Kubernetes through the `K8sclient` trait. This change promotes a more modular and maintainable codebase for Kubernetes integrations within Harmony.
60 lines
1.6 KiB
Rust
60 lines
1.6 KiB
Rust
use k8s_openapi::api::apps::v1::Deployment;
|
|
use serde::Serialize;
|
|
use serde_json::json;
|
|
|
|
use crate::{
|
|
interpret::Interpret,
|
|
score::Score,
|
|
topology::{K8sclient, Topology},
|
|
};
|
|
|
|
use super::resource::{K8sResourceInterpret, K8sResourceScore};
|
|
|
|
#[derive(Debug, Clone, Serialize)]
|
|
pub struct K8sDeploymentScore {
|
|
pub name: String,
|
|
pub image: String,
|
|
}
|
|
|
|
impl<T: Topology + K8sclient> Score<T> for K8sDeploymentScore {
|
|
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
|
let deployment: Deployment = serde_json::from_value(json!(
|
|
{
|
|
"metadata": {
|
|
"name": self.name
|
|
},
|
|
"spec": {
|
|
"selector": {
|
|
"matchLabels": {
|
|
"app": self.name
|
|
},
|
|
},
|
|
"template": {
|
|
"metadata": {
|
|
"labels": {
|
|
"app": self.name
|
|
},
|
|
},
|
|
"spec": {
|
|
"containers": [
|
|
{
|
|
"image": self.image,
|
|
"name": self.image
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
))
|
|
.unwrap();
|
|
Box::new(K8sResourceInterpret {
|
|
score: K8sResourceScore::single(deployment.clone()),
|
|
})
|
|
}
|
|
|
|
fn name(&self) -> String {
|
|
"K8sDeploymentScore".to_string()
|
|
}
|
|
}
|