wip: added score to make control planes unschedulable on UPI, started setting up path_resource function for K8sClient
Some checks failed
Run Check Script / check (pull_request) Failing after 27s
Some checks failed
Run Check Script / check (pull_request) Failing after 27s
This commit is contained in:
parent
83c1cc82b6
commit
f87e223d75
@ -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<ServiceAccount> {
|
||||
let api: Api<ServiceAccount> = Api::namespaced(self.client.clone(), namespace);
|
||||
api
|
||||
|
||||
87
harmony/src/modules/okd/control_plane.rs
Normal file
87
harmony/src/modules/okd/control_plane.rs
Normal file
@ -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<T: Topology + K8sclient> Score<T> for ControlPlaneConfig {
|
||||
fn name(&self) -> String {
|
||||
"ControlPlaneConfig".to_string()
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ControlPlaneConfigInterpret {
|
||||
score: ControlPlaneConfig,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: Topology + K8sclient> Interpret<T> for ControlPlaneConfigInterpret {
|
||||
async fn execute(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
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<Id> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl ControlPlaneConfigInterpret {
|
||||
async fn control_plane_unschedulable(
|
||||
&self,
|
||||
client: &Arc<K8sClient>,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
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(),
|
||||
))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user