-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update controller and agent to kube-rs 0.91.0
Signed-off-by: Kate Goldenring <[email protected]>
- Loading branch information
1 parent
3050186
commit e10c0ca
Showing
22 changed files
with
2,277 additions
and
4,546 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
use akri_shared::akri::configuration::Configuration; | ||
use akri_shared::akri::instance::Instance; | ||
use akri_shared::k8s::api::IntoApi; | ||
|
||
use k8s_openapi::api::batch::v1::Job; | ||
use k8s_openapi::api::core::v1::{Node, Pod, Service}; | ||
|
||
use tokio::sync::RwLock; | ||
|
||
// Identifier for the controller to be set as the field manager for server-side apply | ||
pub const CONTROLLER_FIELD_MANAGER_ID: &str = "akri.sh/controller"; | ||
|
||
/// Pod states that BrokerPodWatcher is interested in | ||
/// | ||
/// PodState describes the various states that the controller can | ||
/// react to for Pods. | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum PodState { | ||
/// Pod is in Pending state and no action is needed. | ||
Pending, | ||
/// Pod is in Running state and needs to ensure that | ||
/// instance and configuration services are running | ||
Running, | ||
/// Pod is in Failed/Completed/Succeeded state and | ||
/// needs to remove any instance and configuration | ||
/// services that are not supported by other Running | ||
/// Pods. Also, at this point, if an Instance still | ||
/// exists, instance_action::handle_instance_change | ||
/// needs to be called to ensure that Pods are | ||
/// restarted | ||
Ended, | ||
/// Pod is in Deleted state and needs to remove any | ||
/// instance and configuration services that are not | ||
/// supported by other Running Pods. Also, at this | ||
/// point, if an Instance still exists, and the Pod is | ||
/// owned by the Instance, | ||
/// instance_action::handle_instance_change needs to be | ||
/// called to ensure that Pods are restarted. Akri | ||
/// places an Instance OwnerReference on all the Pods it | ||
/// deploys. This declares that the Instance owns that | ||
/// Pod and Akri's Controller explicitly manages its | ||
/// deployment. However, if the Pod is not owned by the | ||
/// Instance, Akri should not assume retry logic and | ||
/// should cease action. The owning object (ie Job) will | ||
/// handle retries as necessary. | ||
Deleted, | ||
} | ||
|
||
/// Node states that NodeWatcher is interested in | ||
/// | ||
/// NodeState describes the various states that the controller can | ||
/// react to for Nodes. | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum NodeState { | ||
/// Node has been seen, but not Running yet | ||
Known, | ||
/// Node has been seen Running | ||
Running, | ||
/// A previously Running Node has been seen as not Running | ||
/// and the Instances have been cleaned of references to that | ||
/// vanished Node | ||
InstancesCleaned, | ||
} | ||
|
||
pub trait ControllerKubeClient: | ||
IntoApi<Instance> | ||
+ IntoApi<Configuration> | ||
+ IntoApi<Pod> | ||
+ IntoApi<Job> | ||
+ IntoApi<Service> | ||
+ IntoApi<Node> | ||
{ | ||
} | ||
|
||
impl< | ||
T: IntoApi<Instance> | ||
+ IntoApi<Configuration> | ||
+ IntoApi<Pod> | ||
+ IntoApi<Job> | ||
+ IntoApi<Service> | ||
+ IntoApi<Node>, | ||
> ControllerKubeClient for T | ||
{ | ||
} | ||
|
||
pub struct ControllerContext { | ||
/// Kubernetes client | ||
pub client: Arc<dyn ControllerKubeClient>, | ||
pub known_pods: Arc<RwLock<HashMap<String, PodState>>>, | ||
pub known_nodes: Arc<RwLock<HashMap<String, NodeState>>>, | ||
pub identifier: String, | ||
} | ||
|
||
impl ControllerContext { | ||
pub fn new(client: Arc<dyn ControllerKubeClient>, identifier: &str) -> Self { | ||
ControllerContext { | ||
client, | ||
known_pods: Arc::new(RwLock::new(HashMap::new())), | ||
known_nodes: Arc::new(RwLock::new(HashMap::new())), | ||
identifier: identifier.to_string(), | ||
} | ||
} | ||
} |
Oops, something went wrong.