Compare commits

..

1 Commits

Author SHA1 Message Date
f87e223d75 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
2025-11-24 15:56:55 -05:00
3 changed files with 92 additions and 8 deletions

View File

@@ -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

View File

@@ -17,12 +17,6 @@ use crate::{
topology::{HostNetworkConfig, NetworkError, NetworkManager, k8s::K8sClient},
};
/// TODO document properly the non-intuitive behavior or "roll forward only" of nmstate in general
/// It is documented in nmstate official doc, but worth mentionning here :
///
/// - You create a bond, nmstate will apply it
/// - You delete de bond from nmstate, it will NOT delete it
/// - To delete it you have to update it with configuration set to null
pub struct OpenShiftNmStateNetworkManager {
k8s_client: Arc<K8sClient>,
}
@@ -37,7 +31,6 @@ impl std::fmt::Debug for OpenShiftNmStateNetworkManager {
impl NetworkManager for OpenShiftNmStateNetworkManager {
async fn ensure_network_manager_installed(&self) -> Result<(), NetworkError> {
debug!("Installing NMState controller...");
// TODO use operatorhub maybe?
self.k8s_client.apply_url(url::Url::parse("https://github.com/nmstate/kubernetes-nmstate/releases/download/v0.84.0/nmstate.io_nmstates.yaml
").unwrap(), Some("nmstate"))
.await?;

View 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(),
))
}
}