Skip to content

Commit 59e2ea9

Browse files
committed
improve error handling
1 parent 6f43e7e commit 59e2ea9

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

rust/operator-binary/src/zk_controller.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ use stackable_operator::{
4545
product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config},
4646
product_logging::{
4747
self,
48-
framework::{create_vector_shutdown_file_command, remove_vector_shutdown_file_command},
48+
framework::{
49+
create_vector_shutdown_file_command, remove_vector_shutdown_file_command, LoggingError,
50+
},
4951
spec::{
5052
ConfigMapLogConfig, ContainerLogConfig, ContainerLogConfigChoice,
5153
CustomContainerLogConfig,
@@ -247,13 +249,21 @@ pub enum Error {
247249
#[snafu(display("failed to add TLS volume mounts"))]
248250
AddTlsVolumeMounts { source: security::Error },
249251

252+
#[snafu(display("failed to configure logging"))]
253+
ConfigureLogging { source: LoggingError },
254+
250255
#[snafu(display("failed to add needed volume"))]
251256
AddVolume { source: builder::pod::Error },
252257

253258
#[snafu(display("failed to add needed volumeMount"))]
254259
AddVolumeMount {
255260
source: builder::pod::container::Error,
256261
},
262+
263+
#[snafu(display("failed to create cluster resources"))]
264+
CreateClusterResources {
265+
source: stackable_operator::cluster_resources::Error,
266+
},
257267
}
258268

259269
impl ReconcilerError for Error {
@@ -294,8 +304,10 @@ impl ReconcilerError for Error {
294304
Error::BuildLabel { .. } => None,
295305
Error::ObjectMeta { .. } => None,
296306
Error::AddTlsVolumeMounts { .. } => None,
307+
Error::ConfigureLogging { .. } => None,
297308
Error::AddVolume { .. } => None,
298309
Error::AddVolumeMount { .. } => None,
310+
Error::CreateClusterResources { .. } => None,
299311
}
300312
}
301313
}
@@ -316,7 +328,7 @@ pub async fn reconcile_zk(zk: Arc<ZookeeperCluster>, ctx: Arc<Ctx>) -> Result<co
316328
&zk.object_ref(&()),
317329
ClusterResourceApplyStrategy::from(&zk.spec.cluster_operation),
318330
)
319-
.unwrap();
331+
.context(CreateClusterResourcesSnafu)?;
320332

321333
let validated_config = validate_all_roles_and_groups_config(
322334
&resolved_product_image.app_version_label,
@@ -812,13 +824,13 @@ fn build_server_rolegroup_statefulset(
812824
..EnvVar::default()
813825
}])
814826
.add_volume_mount("data", STACKABLE_DATA_DIR)
815-
.unwrap()
827+
.context(AddVolumeMountSnafu)?
816828
.add_volume_mount("config", STACKABLE_CONFIG_DIR)
817-
.unwrap()
829+
.context(AddVolumeMountSnafu)?
818830
.add_volume_mount("rwconfig", STACKABLE_RW_CONFIG_DIR)
819-
.unwrap()
831+
.context(AddVolumeMountSnafu)?
820832
.add_volume_mount("log", STACKABLE_LOG_DIR)
821-
.unwrap()
833+
.context(AddVolumeMountSnafu)?
822834
.resources(
823835
ResourceRequirementsBuilder::new()
824836
.with_cpu_request("200m")
@@ -875,15 +887,15 @@ fn build_server_rolegroup_statefulset(
875887
.add_container_port("zk-election", 3888)
876888
.add_container_port("metrics", 9505)
877889
.add_volume_mount("data", STACKABLE_DATA_DIR)
878-
.unwrap()
890+
.context(AddVolumeMountSnafu)?
879891
.add_volume_mount("config", STACKABLE_CONFIG_DIR)
880-
.unwrap()
892+
.context(AddVolumeMountSnafu)?
881893
.add_volume_mount("log-config", STACKABLE_LOG_CONFIG_DIR)
882-
.unwrap()
894+
.context(AddVolumeMountSnafu)?
883895
.add_volume_mount("rwconfig", STACKABLE_RW_CONFIG_DIR)
884-
.unwrap()
896+
.context(AddVolumeMountSnafu)?
885897
.add_volume_mount("log", STACKABLE_LOG_DIR)
886-
.unwrap()
898+
.context(AddVolumeMountSnafu)?
887899
.resources(resources)
888900
.build();
889901

@@ -981,7 +993,7 @@ fn build_server_rolegroup_statefulset(
981993
.with_memory_limit("128Mi")
982994
.build(),
983995
)
984-
.unwrap(),
996+
.context(ConfigureLoggingSnafu)?,
985997
);
986998
}
987999

0 commit comments

Comments
 (0)