use crate::plugin_watcher::PluginRegistry;
use crate::pod::state::prelude::PodStatus;
use crate::pod::Pod;
use krator::{ObjectState, State};
use std::collections::HashMap;
pub mod crash_loop_backoff;
pub mod error;
pub mod image_pull;
pub mod image_pull_backoff;
pub mod registered;
pub mod terminated;
pub mod volume_mount;
pub enum BackoffSequence {
ImagePull,
CrashLoop,
}
pub enum ThresholdTrigger {
Triggered,
Untriggered,
}
#[async_trait::async_trait]
pub trait GenericProviderState: 'static + Send + Sync {
fn client(&self) -> kube::Client;
fn store(&self) -> std::sync::Arc<dyn crate::store::Store + Sync + Send>;
fn volume_path(&self) -> std::path::PathBuf;
fn plugin_registry(&self) -> Option<std::sync::Arc<PluginRegistry>> {
None
}
async fn stop(&self, pod: &crate::pod::Pod) -> anyhow::Result<()>;
}
#[async_trait::async_trait]
pub trait GenericPodState: ObjectState<Manifest = Pod, Status = PodStatus> {
async fn set_modules(&mut self, modules: HashMap<String, Vec<u8>>);
async fn set_volumes(&mut self, volumes: HashMap<String, crate::volume::Ref>);
async fn backoff(&mut self, sequence: BackoffSequence);
async fn reset_backoff(&mut self, sequence: BackoffSequence);
async fn record_error(&mut self) -> ThresholdTrigger;
}
pub trait GenericProvider: 'static + Send + Sync {
type ProviderState: GenericProviderState;
type PodState: GenericPodState + ObjectState<SharedState = Self::ProviderState>;
type RunState: Default + State<Self::PodState>;
fn validate_pod_runnable(pod: &crate::pod::Pod) -> anyhow::Result<()>;
fn validate_container_runnable(container: &crate::container::Container) -> anyhow::Result<()>;
fn validate_pod_and_containers_runnable(pod: &crate::pod::Pod) -> anyhow::Result<()> {
Self::validate_pod_runnable(pod)?;
for container in pod.containers() {
Self::validate_container_runnable(&container)?;
}
Ok(())
}
}