Skip to content

Commit 8e773ee

Browse files
committed
Trace error details instead of including them in the error message
1 parent 5a4dd0e commit 8e773ee

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

crates/stackable-operator/src/builder/pod/container.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,15 @@ pub enum Error {
2828

2929
#[snafu(display(
3030
"The volumeMount is clashing with an already existing volumeMount with the same mountPath but a different content. \
31-
The shared mountPath is {mount_path:?}, \
32-
the existing mount's volume name is {existing_volume_name:?}, \
33-
the existing mount's subPath is {existing_sub_path:?}, \
34-
the new mount's volume name is {new_volume_name:?}, \
35-
the new mount's subPath is {new_sub_path:?}"
31+
The clashing mountPath is {clashing_mount_path:?}, \
32+
the existing mount's volume name is {existing_volume_name:?} \
33+
and the new mount's volume name is {new_volume_name:?}. \
34+
Please have a look at the log/traces for details"
3635
))]
3736
ClashingMountPath {
38-
// The VolumeMount structs where not added to avoid to many information for the users. Instead we pick the most
39-
// relevant information only.
40-
mount_path: String,
37+
clashing_mount_path: String,
4138
existing_volume_name: String,
42-
existing_sub_path: Option<String>,
4339
new_volume_name: String,
44-
new_sub_path: Option<String>,
4540
},
4641
}
4742

@@ -226,14 +221,21 @@ impl ContainerBuilder {
226221
/// two times, resulting in e.g. the s3 credentials being mounted twice as the same volumeMount.
227222
fn add_volume_mount_impl(&mut self, volume_mount: VolumeMount) -> Result<&mut Self> {
228223
if let Some(existing_volume_mount) = self.volume_mounts.get(&volume_mount.mount_path) {
224+
// We don't want to include the details in the error message, but instead trace them
225+
if existing_volume_mount != &volume_mount {
226+
tracing::error!(
227+
clashing_mount_path = &volume_mount.mount_path,
228+
?existing_volume_mount,
229+
new_volume_mount = ?volume_mount,
230+
"The volumeMount is clashing with an already existing volumeMount with the same mountPath but a different content"
231+
);
232+
}
229233
ensure!(
230234
existing_volume_mount == &volume_mount,
231235
ClashingMountPathSnafu {
232-
mount_path: volume_mount.mount_path,
236+
clashing_mount_path: volume_mount.mount_path,
233237
existing_volume_name: existing_volume_mount.name.clone(),
234-
existing_sub_path: existing_volume_mount.sub_path.clone(),
235238
new_volume_name: volume_mount.name,
236-
new_sub_path: volume_mount.sub_path,
237239
}
238240
);
239241
} else {

crates/stackable-operator/src/builder/pod/mod.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ pub enum Error {
5252
#[snafu(display("object is missing key {key:?}"))]
5353
MissingObjectKey { key: &'static str },
5454

55-
#[snafu(display("The volume {volume_name:?} clashes with an existing volume of the same name but with different content. \
56-
The existing volume is {existing_volume:?}, the new one is {new_volume:?}"))]
57-
ClashingVolumeName {
58-
volume_name: String,
59-
existing_volume: Box<Volume>,
60-
new_volume: Box<Volume>,
61-
},
55+
#[snafu(display("The volume {clashing_volume_name:?} clashes with an existing volume of the same name but with different content. \
56+
Please have a look at the log/traces for details."))]
57+
ClashingVolumeName { clashing_volume_name: String },
6258
}
6359

6460
/// A builder to build [`Pod`] or [`PodTemplateSpec`] objects.
@@ -292,12 +288,20 @@ impl PodBuilder {
292288
/// resulting in e.g. the s3 credentials being mounted twice as the sake volume.
293289
pub fn add_volume(&mut self, volume: Volume) -> Result<&mut Self> {
294290
if let Some(existing_volume) = self.volumes.get(&volume.name) {
291+
// We don't want to include the details in the error message, but instead trace them
292+
if existing_volume != &volume {
293+
let clashing_name = &volume.name;
294+
tracing::error!(
295+
clashing_name,
296+
?existing_volume,
297+
new_volume = ?volume,
298+
"The volume {clashing_name:?} clashes with an existing volume of the same name but with different content",
299+
);
300+
}
295301
ensure!(
296302
existing_volume == &volume,
297303
ClashingVolumeNameSnafu {
298-
volume_name: volume.name.clone(),
299-
existing_volume: existing_volume.clone(),
300-
new_volume: volume
304+
clashing_volume_name: volume.name.clone(),
301305
}
302306
);
303307
} else {

0 commit comments

Comments
 (0)