diff --git a/harmony/src/domain/topology/k8s.rs b/harmony/src/domain/topology/k8s.rs index fccf0d1..682efb0 100644 --- a/harmony/src/domain/topology/k8s.rs +++ b/harmony/src/domain/topology/k8s.rs @@ -27,7 +27,7 @@ use kube::{ }; use log::{debug, error, trace, warn}; use serde::{Serialize, de::DeserializeOwned}; -use serde_json::json; +use serde_json::{json, Value}; use similar::TextDiff; use tokio::{io::AsyncReadExt, time::sleep}; use url::Url; @@ -64,6 +64,10 @@ impl K8sClient { }) } + pub async fn patch_resource(&self, patch: Value, gvk: &GroupVersionKind) -> Result<(), Error> { + + } + pub async fn service_account_api(&self, namespace: &str) -> Api { let api: Api = Api::namespaced(self.client.clone(), namespace); api diff --git a/harmony/src/modules/okd/control_plane.rs b/harmony/src/modules/okd/control_plane.rs new file mode 100644 index 0000000..785810d --- /dev/null +++ b/harmony/src/modules/okd/control_plane.rs @@ -0,0 +1,87 @@ +use std::sync::Arc; + +use async_trait::async_trait; +use harmony_types::id::Id; +use kube::api::GroupVersionKind; +use serde::Serialize; +use serde_json::json; + +use crate::{ + data::Version, + interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, + inventory::Inventory, + score::Score, + topology::{K8sclient, Topology, k8s::K8sClient}, +}; + +#[derive(Debug, Clone, Serialize)] +pub struct ControlPlaneConfig {} + +impl Score for ControlPlaneConfig { + fn name(&self) -> String { + "ControlPlaneConfig".to_string() + } + + #[doc(hidden)] + fn create_interpret(&self) -> Box> { + todo!() + } +} + +#[derive(Debug, Clone, Serialize)] +pub struct ControlPlaneConfigInterpret { + score: ControlPlaneConfig, +} + +#[async_trait] +impl Interpret for ControlPlaneConfigInterpret { + async fn execute( + &self, + inventory: &Inventory, + topology: &T, + ) -> Result { + let client = topology.k8s_client().await.unwrap(); + self.control_plane_unschedulable(&client).await + } + + fn get_name(&self) -> InterpretName { + todo!() + } + + fn get_version(&self) -> Version { + todo!() + } + + fn get_status(&self) -> InterpretStatus { + todo!() + } + + fn get_children(&self) -> Vec { + todo!() + } +} + +impl ControlPlaneConfigInterpret { + async fn control_plane_unschedulable( + &self, + client: &Arc, + ) -> Result { + let patch = json!({ + "spec": { + "mastersSchedulable": false + } + }); + + let resource = GroupVersionKind { + group: "config.openshift.io".to_string(), + version: "v1".to_string(), + kind: "Scheduler".to_string(), + }; + + client.patch_resource(patch, &resource).await?; + + Ok(Outcome::success( + "control planes are no longer schedulable".to_string(), + )) + } +}