diff --git a/crates/types/src/v1alpha1/wasmcloud_host_config.rs b/crates/types/src/v1alpha1/wasmcloud_host_config.rs index 39e1c7e..7bcb70d 100644 --- a/crates/types/src/v1alpha1/wasmcloud_host_config.rs +++ b/crates/types/src/v1alpha1/wasmcloud_host_config.rs @@ -238,10 +238,18 @@ pub struct WasmCloudHostConfigResources { #[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)] pub struct WasmCloudHostConfigStatus { + pub hosts: WasmCloudHostStatus, pub apps: Vec, pub app_count: u32, } +#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema, Default)] +pub struct WasmCloudHostStatus { + pub available_replicas: Option, + pub updated_replicas: Option, + pub replicas: Option, +} + #[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)] pub struct AppStatus { pub name: String, diff --git a/deploy/base/deployment.yaml b/deploy/base/deployment.yaml index 49c4f1d..3069737 100644 --- a/deploy/base/deployment.yaml +++ b/deploy/base/deployment.yaml @@ -71,6 +71,13 @@ rules: - delete - patch - update + - apiGroups: + - apps + resources: + - deployments/status + - daemonsets/status + verbs: + - get - apiGroups: - rbac.authorization.k8s.io resources: diff --git a/src/controller.rs b/src/controller.rs index dae1a1c..d8e112b 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -32,7 +32,7 @@ use std::sync::Arc; use tokio::{sync::RwLock, time::Duration}; use tracing::{debug, info, warn}; use wasmcloud_operator_types::v1alpha1::{ - AppStatus, WasmCloudHostConfig, WasmCloudHostConfigSpec, WasmCloudHostConfigStatus, + AppStatus, WasmCloudHostConfig, WasmCloudHostConfigSpec, WasmCloudHostConfigStatus, WasmCloudHostStatus, }; pub static CLUSTER_CONFIG_FINALIZER: &str = "operator.k8s.wasmcloud.dev/wasmcloud-host-config"; @@ -147,10 +147,10 @@ async fn reconcile_crd(config: &WasmCloudHostConfig, ctx: Arc) -> Resul return Err(e); }; - if let Err(e) = configure_hosts(&cfg, ctx.clone()).await { + let host_status = configure_hosts(&cfg, ctx.clone()).await.map_err(|e| { warn!("Failed to configure deployment: {}", e); - return Err(e); - }; + e + })?; if let Err(e) = configure_service(&cfg, ctx.clone()).await { warn!("Failed to configure service: {}", e); @@ -179,6 +179,7 @@ async fn reconcile_crd(config: &WasmCloudHostConfig, ctx: Arc) -> Resul .collect::>(); debug!(app_names=?app_names, "Found apps"); cfg.status = Some(WasmCloudHostConfigStatus { + hosts: host_status, apps: app_names.clone(), app_count: app_names.len() as u32, }); @@ -780,7 +781,7 @@ async fn daemonset_spec(config: &WasmCloudHostConfig, ctx: Arc) -> Resu }) } -async fn configure_hosts(config: &WasmCloudHostConfig, ctx: Arc) -> Result<()> { +async fn configure_hosts(config: &WasmCloudHostConfig, ctx: Arc) -> Result { let mut env_vars = vec![]; if let Some(registry_credentials) = &config.spec.registry_credentials_secret { let secrets_client = @@ -847,7 +848,7 @@ async fn configure_hosts(config: &WasmCloudHostConfig, ctx: Arc) -> Res ]; } - if config + let status = if config .spec .scheduling_options .as_ref() @@ -878,6 +879,13 @@ async fn configure_hosts(config: &WasmCloudHostConfig, ctx: Arc) -> Res &Patch::Apply(ds), ) .await?; + + let ds_status = api.get_status(&config.name_any()).await?.status.unwrap_or_default(); + WasmCloudHostStatus { + replicas: Some(ds_status.desired_number_scheduled), + available_replicas: ds_status.number_available, + updated_replicas: ds_status.updated_number_scheduled, + } } else { let mut spec = deployment_spec(config, ctx.clone()).await?; spec.template.spec.as_mut().unwrap().containers[1] @@ -904,9 +912,16 @@ async fn configure_hosts(config: &WasmCloudHostConfig, ctx: Arc) -> Res &Patch::Apply(deployment), ) .await?; + + let deploy_status = api.get_status(&config.name_any()).await?.status.unwrap_or_default(); + WasmCloudHostStatus { + replicas: deploy_status.replicas, + available_replicas: deploy_status.available_replicas, + updated_replicas: deploy_status.updated_replicas, + } }; - Ok(()) + Ok(status) } async fn configure_service(config: &WasmCloudHostConfig, ctx: Arc) -> Result<()> {