diff --git a/rust/operator-binary/src/discovery.rs b/rust/operator-binary/src/discovery.rs index 358d6953..d3590117 100644 --- a/rust/operator-binary/src/discovery.rs +++ b/rust/operator-binary/src/discovery.rs @@ -1,37 +1,61 @@ use std::collections::BTreeMap; use product_config::writer::to_hadoop_xml; +use snafu::{ResultExt, Snafu}; use stackable_hbase_crd::{HbaseCluster, HbaseRole, HBASE_SITE_XML}; use stackable_operator::{ - builder::{ConfigMapBuilder, ObjectMetaBuilder}, + builder::{ConfigMapBuilder, ObjectMetaBuilder, ObjectMetaBuilderError}, commons::product_image_selection::ResolvedProductImage, - error::OperatorResult, k8s_openapi::api::core::v1::ConfigMap, + kube::runtime::reflector::ObjectRef, }; use crate::{ hbase_controller::build_recommended_labels, zookeeper::ZookeeperConnectionInformation, }; +type Result = std::result::Result; + +#[derive(Snafu, Debug)] +pub enum Error { + #[snafu(display("object {hbase} is missing metadata to build owner reference"))] + ObjectMissingMetadataForOwnerRef { + source: stackable_operator::error::Error, + hbase: ObjectRef, + }, + + #[snafu(display("failed to build ConfigMap"))] + BuildConfigMap { + source: stackable_operator::error::Error, + }, + + #[snafu(display("failed to build object meta data"))] + ObjectMeta { source: ObjectMetaBuilderError }, +} + /// Creates a discovery config map containing the `hbase-site.xml` for clients. pub fn build_discovery_configmap( hbase: &HbaseCluster, zookeeper_connection_information: &ZookeeperConnectionInformation, resolved_product_image: &ResolvedProductImage, -) -> OperatorResult { +) -> Result { let hbase_site = zookeeper_connection_information.as_hbase_settings(); ConfigMapBuilder::new() .metadata( ObjectMetaBuilder::new() .name_and_namespace(hbase) - .ownerreference_from_resource(hbase, None, Some(true))? + .ownerreference_from_resource(hbase, None, Some(true)) + .with_context(|_| ObjectMissingMetadataForOwnerRefSnafu { + hbase: ObjectRef::from_obj(hbase), + })? .with_recommended_labels(build_recommended_labels( hbase, &resolved_product_image.app_version_label, &HbaseRole::RegionServer.to_string(), "discovery", )) + .context(ObjectMetaSnafu)? .build(), ) .add_data( @@ -45,4 +69,5 @@ pub fn build_discovery_configmap( ), ) .build() + .context(BuildConfigMapSnafu) }