feat: Initial helm score using helm-wrapper-rs #14
24
Cargo.lock
generated
24
Cargo.lock
generated
@ -1343,12 +1343,14 @@ dependencies = [
|
||||
"env_logger",
|
||||
"harmony_macros",
|
||||
"harmony_types",
|
||||
"helm-wrapper-rs",
|
||||
"http 1.3.1",
|
||||
"inquire",
|
||||
"k8s-openapi",
|
||||
"kube",
|
||||
"libredfish",
|
||||
"log",
|
||||
"non-blank-string-rs",
|
||||
"opnsense-config",
|
||||
"opnsense-config-xml",
|
||||
"reqwest 0.11.27",
|
||||
@ -1453,6 +1455,19 @@ version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "helm-wrapper-rs"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc9253a7bbf4ba8ff6052d5ab7ddc6e2ca17cd8481d15636fb9f64611653880c"
|
||||
dependencies = [
|
||||
"log",
|
||||
"non-blank-string-rs",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.9"
|
||||
@ -2328,6 +2343,15 @@ dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "non-blank-string-rs"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a05a02248b2e70f1943a59af287a28df78ef9adfc72ee5dc443381d3a1a1a5c"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.4.6"
|
||||
|
@ -19,6 +19,7 @@ async fn main() {
|
||||
harmony_cli::init(maestro, None).await.unwrap();
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
use assert_cmd::Command;
|
||||
|
||||
#[test]
|
||||
|
@ -31,3 +31,5 @@ serde_yaml = { workspace = true }
|
||||
http = { workspace = true }
|
||||
serde-value = { workspace = true }
|
||||
inquire.workspace = true
|
||||
helm-wrapper-rs = "0.4.0"
|
||||
non-blank-string-rs = "1.0.4"
|
||||
|
1
harmony/src/domain/topology/helm_command.rs
Normal file
1
harmony/src/domain/topology/helm_command.rs
Normal file
@ -0,0 +1 @@
|
||||
pub trait HelmCommand {}
|
@ -20,6 +20,9 @@ pub use network::*;
|
||||
use serde::Serialize;
|
||||
pub use tftp::*;
|
||||
|
||||
mod helm_command;
|
||||
pub use helm_command::*;
|
||||
|
||||
use std::net::IpAddr;
|
||||
|
||||
use super::interpret::{InterpretError, Outcome};
|
||||
|
@ -370,10 +370,13 @@ mod tests {
|
||||
let result = get_servers_for_backend(&backend, &haproxy);
|
||||
|
||||
// Check the result
|
||||
assert_eq!(result, vec![BackendServer {
|
||||
address: "192.168.1.1".to_string(),
|
||||
port: 80,
|
||||
},]);
|
||||
assert_eq!(
|
||||
result,
|
||||
vec![BackendServer {
|
||||
address: "192.168.1.1".to_string(),
|
||||
port: 80,
|
||||
},]
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn test_get_servers_for_backend_no_linked_servers() {
|
||||
@ -430,15 +433,18 @@ mod tests {
|
||||
// Call the function
|
||||
let result = get_servers_for_backend(&backend, &haproxy);
|
||||
// Check the result
|
||||
assert_eq!(result, vec![
|
||||
BackendServer {
|
||||
address: "some-hostname.test.mcd".to_string(),
|
||||
port: 80,
|
||||
},
|
||||
BackendServer {
|
||||
address: "192.168.1.2".to_string(),
|
||||
port: 8080,
|
||||
},
|
||||
]);
|
||||
assert_eq!(
|
||||
result,
|
||||
vec![
|
||||
BackendServer {
|
||||
address: "some-hostname.test.mcd".to_string(),
|
||||
port: 80,
|
||||
},
|
||||
BackendServer {
|
||||
address: "192.168.1.2".to_string(),
|
||||
port: 8080,
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
pub mod resource;
|
||||
pub mod resource;
|
||||
|
@ -2,51 +2,79 @@ use crate::data::{Id, Version};
|
||||
use crate::interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome};
|
||||
use crate::inventory::Inventory;
|
||||
use crate::score::Score;
|
||||
use crate::topology::Topology;
|
||||
use crate::topology::{HelmCommand, Topology};
|
||||
use async_trait::async_trait;
|
||||
use helm_wrapper_rs;
|
||||
use helm_wrapper_rs::blocking::{DefaultHelmExecutor, HelmExecutor};
|
||||
use non_blank_string_rs::NonBlankString;
|
||||
use serde::Serialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct HelmResourceScore {
|
||||
pub namespace: String,
|
||||
pub release_name: String,
|
||||
pub chart_name: String,
|
||||
pub chart_version: String,
|
||||
pub values_overrides: String,
|
||||
pub values_file: String,
|
||||
pub helm_options: String,
|
||||
pub struct HelmChartScore {
|
||||
pub namespace: NonBlankString,
|
||||
|
||||
pub release_name: NonBlankString,
|
||||
pub chart_name: NonBlankString,
|
||||
pub chart_version: NonBlankString,
|
||||
pub values_overrides: Option<HashMap<NonBlankString, String>>,
|
||||
}
|
||||
|
||||
impl<T: Topology + std::fmt::Debug + Sync + Default + serde::Serialize + 'static + Send + Clone>
|
||||
Score<T> for HelmResourceScore
|
||||
{
|
||||
impl<T: Topology> Score<T> for HelmChartScore {
|
||||
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
format!("{}, {}", self.release_name, self.chart_name)
|
||||
"HelmChartScore".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct HelmResourceInterpret {
|
||||
pub score: HelmResourceScore,
|
||||
pub struct HelmChartInterpret {
|
||||
pub score: HelmChartScore,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: Topology + Clone + std::fmt::Debug + serde::Serialize + Default + Send + Sync> Interpret<T>
|
||||
for HelmResourceInterpret
|
||||
{
|
||||
impl<T: Topology + HelmCommand> Interpret<T> for HelmChartInterpret {
|
||||
async fn execute(
|
||||
&self,
|
||||
_inventory: &Inventory,
|
||||
topology: &T,
|
||||
_topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
Ok(Outcome::success(
|
||||
"Successfully applied resource".to_string(),
|
||||
))
|
||||
let helm_executor = DefaultHelmExecutor::new();
|
||||
let res = helm_executor.install_or_upgrade(
|
||||
&self.score.namespace,
|
||||
&self.score.release_name,
|
||||
&self.score.chart_name,
|
||||
Some(&self.score.chart_version),
|
||||
self.score.values_overrides.as_ref(),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
let status = match res {
|
||||
Ok(status) => status,
|
||||
Err(err) => return Err(InterpretError::new(err.to_string())),
|
||||
};
|
||||
|
||||
match status {
|
||||
helm_wrapper_rs::HelmDeployStatus::Deployed => Ok(Outcome::new(
|
||||
InterpretStatus::SUCCESS,
|
||||
"Helm Chart deployed".to_string(),
|
||||
)),
|
||||
helm_wrapper_rs::HelmDeployStatus::PendingInstall => Ok(Outcome::new(
|
||||
InterpretStatus::RUNNING,
|
||||
"Helm Chart Pending install".to_string(),
|
||||
)),
|
||||
helm_wrapper_rs::HelmDeployStatus::PendingUpgrade => Ok(Outcome::new(
|
||||
InterpretStatus::RUNNING,
|
||||
"Helm Chart pending upgrade".to_string(),
|
||||
)),
|
||||
helm_wrapper_rs::HelmDeployStatus::Failed => Err(InterpretError::new(
|
||||
"Failed to install helm chart".to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
fn get_name(&self) -> InterpretName {
|
||||
todo!()
|
||||
|
Loading…
Reference in New Issue
Block a user
Needs to be optional here so we can decide at runtime which namespace we're deploying to. For example, when we're deploying a staging stack we should be able to specify "stack-staging" or "stack-prod" or "stack-pullrequestno435"