Skip to content

Commit 09476f3

Browse files
committed
fix: Handle unlikely error instead of crashing
1 parent c288063 commit 09476f3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

rust/operator-binary/src/znode_controller.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ pub enum Error {
124124

125125
#[snafu(display("failed to initialize security context"))]
126126
FailedToInitializeSecurityContext { source: crate::crd::security::Error },
127+
128+
#[snafu(display("OwnerRef missing expected keys (name and/or namespace)"))]
129+
OwnerRefMissingExpectedKeys {
130+
source: stackable_operator::cluster_resources::Error,
131+
},
127132
}
128133
type Result<T, E = Error> = std::result::Result<T, E>;
129134

@@ -155,7 +160,7 @@ impl ReconcilerError for Error {
155160

156161
fn secondary_object(&self) -> Option<ObjectRef<DynamicObject>> {
157162
match self {
158-
Error::InvalidZookeeperZnode { source: _ } => None,
163+
Error::InvalidZookeeperZnode { .. } => None,
159164
Error::ObjectMissingMetadata => None,
160165
Error::InvalidZkReference => None,
161166
Error::FindZk { zk, .. } => Some(zk.clone().erase()),
@@ -165,13 +170,14 @@ impl ReconcilerError for Error {
165170
Error::NoZkFqdn { zk } => Some(zk.clone().erase()),
166171
Error::EnsureZnode { zk, .. } => Some(zk.clone().erase()),
167172
Error::EnsureZnodeMissing { zk, .. } => Some(zk.clone().erase()),
168-
Error::BuildDiscoveryConfigMap { source: _ } => None,
173+
Error::BuildDiscoveryConfigMap { .. } => None,
169174
Error::ApplyDiscoveryConfigMap { cm, .. } => Some(cm.clone().erase()),
170175
Error::ApplyStatus { .. } => None,
171-
Error::Finalizer { source: _ } => None,
172-
Error::DeleteOrphans { source: _ } => None,
176+
Error::Finalizer { .. } => None,
177+
Error::DeleteOrphans { .. } => None,
173178
Error::ObjectHasNoNamespace => None,
174-
Error::FailedToInitializeSecurityContext { source: _ } => None,
179+
Error::FailedToInitializeSecurityContext { .. } => None,
180+
Error::OwnerRefMissingExpectedKeys { .. } => None,
175181
}
176182
}
177183
}
@@ -274,8 +280,7 @@ async fn reconcile_apply(
274280
&znode.object_ref(&()),
275281
ClusterResourceApplyStrategy::from(&zk.spec.cluster_operation),
276282
)
277-
// TODO (@NickLarsenNZ): Handle this error properly. znode should contain namespace/name, but there is no guarantee
278-
.unwrap();
283+
.context(OwnerRefMissingExpectedKeysSnafu)?;
279284

280285
znode_mgmt::ensure_znode_exists(
281286
&zk_mgmt_addr(&zk, &zookeeper_security, &client.kubernetes_cluster_info)?,

0 commit comments

Comments
 (0)