forked from NationTech/harmony
Implement ScoreListWidget to manage score list rendering and execution confirmation flow. This includes methods for scrolling through scores, launching an execution, confirming/denying the execution, and rendering a popup for user confirmation.
59 lines
1.6 KiB
Rust
59 lines
1.6 KiB
Rust
use k8s_openapi::api::apps::v1::Deployment;
|
|
use serde_json::json;
|
|
|
|
use crate::{interpret::Interpret, score::Score};
|
|
|
|
use super::resource::{K8sResourceInterpret, K8sResourceScore};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct K8sDeploymentScore {
|
|
pub name: String,
|
|
pub image: String,
|
|
}
|
|
|
|
impl Score for K8sDeploymentScore {
|
|
fn create_interpret(&self) -> Box<dyn Interpret> {
|
|
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()
|
|
}
|
|
|
|
fn clone_box(&self) -> Box<dyn Score> {
|
|
Box::new(self.clone())
|
|
}
|
|
}
|