add ingress score
This commit is contained in:
parent
861f266c4e
commit
f66533aa89
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1032,6 +1032,7 @@ dependencies = [
|
||||
"harmony_cli",
|
||||
"harmony_macros",
|
||||
"harmony_types",
|
||||
"k8s-openapi",
|
||||
"log",
|
||||
"tokio",
|
||||
"url",
|
||||
|
||||
@ -16,3 +16,4 @@ harmony_macros = { path = "../../harmony_macros" }
|
||||
log = { workspace = true }
|
||||
env_logger = { workspace = true }
|
||||
url = { workspace = true }
|
||||
k8s-openapi = { version = "0.24.0", features = ["v1_30"] }
|
||||
|
||||
@ -3,12 +3,19 @@ use harmony::{
|
||||
inventory::Inventory,
|
||||
maestro::Maestro,
|
||||
modules::{
|
||||
k8s::{self, ingress::K8sIngressScore, resource::K8sResourceScore},
|
||||
{
|
||||
lamp::{LAMPConfig, LAMPScore},
|
||||
},
|
||||
monitoring::monitoring_alerting::MonitoringAlertingStackScore,
|
||||
},
|
||||
topology::{K8sAnywhereTopology, Url},
|
||||
topology::{K8sAnywhereTopology, Url, k8s::K8sClient},
|
||||
};
|
||||
|
||||
use k8s_openapi::{
|
||||
api::networking::v1::{Ingress, IngressRule, IngressSpec, IngressStatus},
|
||||
apimachinery::pkg::apis::meta::v1::ObjectMeta,
|
||||
};
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// This here is the whole configuration to
|
||||
|
||||
72
harmony/src/modules/k8s/ingress.rs
Normal file
72
harmony/src/modules/k8s/ingress.rs
Normal file
@ -0,0 +1,72 @@
|
||||
use k8s_openapi::api::networking::v1::Ingress;
|
||||
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 K8sIngressScore {
|
||||
pub name: String,
|
||||
pub host: String,
|
||||
pub backend_service: String,
|
||||
pub port: String,
|
||||
pub path: Option<String>,
|
||||
pub path_type: Option<String>,
|
||||
pub namespace: Option<String>,
|
||||
}
|
||||
|
||||
impl<T: Topology + K8sclient> Score<T> for K8sIngressScore {
|
||||
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||
let path = match self.path.clone() {
|
||||
Some(p) => p,
|
||||
None => "/".to_string(),
|
||||
};
|
||||
let path_type = match self.path_type.clone() {
|
||||
Some(p) => p,
|
||||
None => "Prefix".to_string(),
|
||||
};
|
||||
|
||||
let ingress = json!(
|
||||
{
|
||||
"metadata": {
|
||||
"name": self.name
|
||||
},
|
||||
"spec": {
|
||||
"rules": [
|
||||
{ "host": self.host,
|
||||
"http": {
|
||||
"paths": [
|
||||
{
|
||||
"path": path,
|
||||
"pathType": path_type,
|
||||
"backend": [
|
||||
{
|
||||
"service": self.backend_service,
|
||||
"port": self.port
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let ingress: Ingress = serde_json::from_value(ingress).unwrap();
|
||||
Box::new(K8sResourceInterpret {
|
||||
score: K8sResourceScore::single(ingress.clone(), self.namespace.clone()),
|
||||
})
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
"K8sIngressScore".to_string()
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
pub mod deployment;
|
||||
pub mod ingress;
|
||||
pub mod namespace;
|
||||
pub mod resource;
|
||||
|
||||
@ -13,6 +13,7 @@ use log::{debug, info};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::config::{REGISTRY_PROJECT, REGISTRY_URL};
|
||||
use crate::modules::k8s::ingress::K8sIngressScore;
|
||||
use crate::topology::HelmCommand;
|
||||
use crate::{
|
||||
data::{Id, Version},
|
||||
@ -132,6 +133,23 @@ impl<T: Topology + K8sclient + HelmCommand> Interpret<T> for LAMPInterpret {
|
||||
|
||||
info!("LAMP deployment_score {deployment_score:?}");
|
||||
|
||||
let lamp_ingress = K8sIngressScore {
|
||||
name: "lamp-ingress".to_string(),
|
||||
host: "test".to_string(),
|
||||
backend_service: "test".to_string(),
|
||||
port: "8080".to_string(),
|
||||
path: None,
|
||||
path_type: None,
|
||||
namespace: self.get_namespace().map(|nbs| nbs.to_string()),
|
||||
};
|
||||
|
||||
lamp_ingress
|
||||
.create_interpret()
|
||||
.execute(inventory, topology)
|
||||
.await?;
|
||||
|
||||
info!("LAMP deployment_score {deployment_score:?}");
|
||||
|
||||
Ok(Outcome::success(
|
||||
"Successfully deployed LAMP Stack!".to_string(),
|
||||
))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user