diff --git a/CHANGELOG.md b/CHANGELOG.md index 068b7b9d..95a91abb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,10 +18,12 @@ All notable changes to this project will be documented in this file. ### Fixed - BREAKING: The fields `connection` and `host` on `S3Connection` as well as `bucketName` on `S3Bucket`are now mandatory ([#518]). +- An invalid `HiveCluster` doesn't cause the operator to stop functioning ([#523]). [#505]: https://github.com/stackabletech/hive-operator/pull/505 [#508]: https://github.com/stackabletech/hive-operator/pull/508 [#518]: https://github.com/stackabletech/hive-operator/pull/518 +[#523]: https://github.com/stackabletech/hive-operator/pull/523 ## [24.7.0] - 2024-07-24 diff --git a/rust/operator-binary/src/controller.rs b/rust/operator-binary/src/controller.rs index 20ef79fc..cdc9ed77 100644 --- a/rust/operator-binary/src/controller.rs +++ b/rust/operator-binary/src/controller.rs @@ -54,6 +54,7 @@ use stackable_operator::{ }, DeepMerge, }, + kube::core::{error_boundary, DeserializeGuard}, kube::{runtime::controller::Action, Resource, ResourceExt}, kvp::{Label, Labels, ObjectLabels}, logging::controller::ReconcilerError, @@ -323,6 +324,11 @@ pub enum Error { AddVolumeMount { source: builder::pod::container::Error, }, + + #[snafu(display("HiveCluster object is invalid"))] + InvalidHiveCluster { + source: error_boundary::InvalidObject, + }, } type Result = std::result::Result; @@ -332,8 +338,16 @@ impl ReconcilerError for Error { } } -pub async fn reconcile_hive(hive: Arc, ctx: Arc) -> Result { +pub async fn reconcile_hive( + hive: Arc>, + ctx: Arc, +) -> Result { tracing::info!("Starting reconcile"); + let hive = hive + .0 + .as_ref() + .map_err(error_boundary::InvalidObject::clone) + .context(InvalidHiveClusterSnafu)?; let client = &ctx.client; let hive_namespace = hive.namespace().context(ObjectHasNoNamespaceSnafu)?; @@ -361,7 +375,7 @@ pub async fn reconcile_hive(hive: Arc, ctx: Arc) -> Result, ctx: Arc) -> Result, ctx: Arc) -> Result, ctx: Arc) -> Result, ctx: Arc) -> Result, ctx: Arc) -> Result, ctx: Arc) -> Result, ctx: Arc) -> Result, ctx: Arc) -> Result EnvVar } } -pub fn error_policy(_obj: Arc, _error: &Error, _ctx: Arc) -> Action { - Action::requeue(*Duration::from_secs(5)) +pub fn error_policy( + _obj: Arc>, + error: &Error, + _ctx: Arc, +) -> Action { + match error { + // An invalid HBaseCluster was deserialized. Await for it to change. + Error::InvalidHiveCluster { .. } => Action::await_change(), + _ => Action::requeue(*Duration::from_secs(5)), + } } pub fn service_ports() -> Vec { diff --git a/rust/operator-binary/src/main.rs b/rust/operator-binary/src/main.rs index b4b02bea..ac0357c2 100644 --- a/rust/operator-binary/src/main.rs +++ b/rust/operator-binary/src/main.rs @@ -17,6 +17,7 @@ use stackable_operator::{ apps::v1::StatefulSet, core::v1::{ConfigMap, Service}, }, + kube::core::DeserializeGuard, kube::runtime::{watcher, Controller}, logging::controller::report_controller_reconciled, CustomResourceExt, @@ -69,7 +70,7 @@ async fn main() -> anyhow::Result<()> { stackable_operator::client::create_client(Some(OPERATOR_NAME.to_string())).await?; Controller::new( - watch_namespace.get_api::(&client), + watch_namespace.get_api::>(&client), watcher::Config::default(), ) .owns(