feat: add ingress score #32
| @ -3,13 +3,12 @@ use harmony::{ | |||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     maestro::Maestro, |     maestro::Maestro, | ||||||
|     modules::{ |     modules::{ | ||||||
|         k8s::{self, ingress::K8sIngressScore, resource::K8sResourceScore}, |  | ||||||
|         { |         { | ||||||
|         lamp::{LAMPConfig, LAMPScore}, |         lamp::{LAMPConfig, LAMPScore}, | ||||||
|     }, |     }, | ||||||
|         monitoring::monitoring_alerting::MonitoringAlertingStackScore, |         monitoring::monitoring_alerting::MonitoringAlertingStackScore, | ||||||
|     }, |     }, | ||||||
|     topology::{K8sAnywhereTopology, Url, k8s::K8sClient}, |     topology::{K8sAnywhereTopology, Url}, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
|  | |||||||
| @ -1,3 +1,4 @@ | |||||||
|  | use harmony_macros::k8s_ingress_path; | ||||||
| use k8s_openapi::api::networking::v1::Ingress; | use k8s_openapi::api::networking::v1::Ingress; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| use serde_json::json; | use serde_json::json; | ||||||
| @ -27,13 +28,15 @@ impl PathType { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | type K8sIngressPath = String; | ||||||
|  | 
 | ||||||
| #[derive(Debug, Clone, Serialize)] | #[derive(Debug, Clone, Serialize)] | ||||||
| pub struct K8sIngressScore { | pub struct K8sIngressScore { | ||||||
|     pub name: fqdn::FQDN, |     pub name: fqdn::FQDN, | ||||||
|     pub host: fqdn::FQDN, |     pub host: fqdn::FQDN, | ||||||
|     pub backend_service: fqdn::FQDN, |     pub backend_service: fqdn::FQDN, | ||||||
|     pub port: u16, |     pub port: u16, | ||||||
|     pub path: Option<String>, |     pub path: Option<K8sIngressPath>, | ||||||
|     pub path_type: Option<PathType>, |     pub path_type: Option<PathType>, | ||||||
|     pub namespace: Option<fqdn::FQDN>, |     pub namespace: Option<fqdn::FQDN>, | ||||||
| } | } | ||||||
| @ -42,8 +45,9 @@ impl<T: Topology + K8sclient> Score<T> for K8sIngressScore { | |||||||
|     fn create_interpret(&self) -> Box<dyn Interpret<T>> { |     fn create_interpret(&self) -> Box<dyn Interpret<T>> { | ||||||
|         let path = match self.path.clone() { |         let path = match self.path.clone() { | ||||||
|             Some(p) => p, |             Some(p) => p, | ||||||
|             None => "/".to_string(), |             None => k8s_ingress_path!("/"), | ||||||
|         }; |         }; | ||||||
|  | 
 | ||||||
|         let path_type = match self.path_type.clone() { |         let path_type = match self.path_type.clone() { | ||||||
|             Some(p) => p, |             Some(p) => p, | ||||||
|             None => PathType::Prefix, |             None => PathType::Prefix, | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ use convert_case::{Case, Casing}; | |||||||
| use dockerfile_builder::instruction::{CMD, COPY, ENV, EXPOSE, FROM, RUN, WORKDIR}; | use dockerfile_builder::instruction::{CMD, COPY, ENV, EXPOSE, FROM, RUN, WORKDIR}; | ||||||
| use dockerfile_builder::{Dockerfile, instruction_builder::EnvBuilder}; | use dockerfile_builder::{Dockerfile, instruction_builder::EnvBuilder}; | ||||||
| use fqdn::fqdn; | use fqdn::fqdn; | ||||||
|  | use harmony_macros::k8s_ingress_path; | ||||||
| use non_blank_string_rs::NonBlankString; | use non_blank_string_rs::NonBlankString; | ||||||
| use serde_json::json; | use serde_json::json; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| @ -143,7 +144,7 @@ impl<T: Topology + K8sclient + HelmCommand> Interpret<T> for LAMPInterpret { | |||||||
|                     .as_str() |                     .as_str() | ||||||
|             ), |             ), | ||||||
|             port: 8080, |             port: 8080, | ||||||
|             path: None, |             path: Some(k8s_ingress_path!("/")), | ||||||
|             path_type: None, |             path_type: None, | ||||||
|             namespace: self |             namespace: self | ||||||
|                 .get_namespace() |                 .get_namespace() | ||||||
|  | |||||||
| @ -116,3 +116,19 @@ pub fn yaml(input: TokenStream) -> TokenStream { | |||||||
|     } |     } | ||||||
|     .into() |     .into() | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | /// Verify that a string is a valid(ish) kubernetes path
 | ||||||
|  | /// Panics if path does not start with `/`
 | ||||||
|  | #[proc_macro] | ||||||
|  | pub fn k8s_ingress_path(input: TokenStream) -> TokenStream { | ||||||
|  |     let input = parse_macro_input!(input as LitStr); | ||||||
|  |     let path_str = input.value(); | ||||||
|  | 
 | ||||||
|  |     match path_str.starts_with("/") { | ||||||
|  |         true => { | ||||||
|  |             let expanded = quote! {(#path_str.to_string()) }; | ||||||
|  |             return TokenStream::from(expanded); | ||||||
|  |         } | ||||||
|  |         false => panic!("Invalid k8s path"), | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user