Skip to content

Commit d6102f9

Browse files
committed
refactor: make cluster resources for znode infailible
1 parent 6ecceab commit d6102f9

2 files changed

Lines changed: 12 additions & 24 deletions

File tree

rust/operator-binary/src/zk_controller/build/resource/service.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ pub(crate) fn build_server_rolegroup_headless_service(
6363
}
6464
}
6565

66-
/// The metrics [`Service`] name, `<cluster>-<role>-<rolegroup>-metrics`.
67-
///
68-
/// [`ResourceNames`](stackable_operator::v2::role_group_utils::ResourceNames) has no metrics
69-
/// service helper, so the `-metrics` suffix is appended to the qualified role-group name (which is
70-
/// also the StatefulSet name).
71-
fn metrics_service_name(cluster: &ValidatedCluster, role_group_name: &RoleGroupName) -> String {
72-
format!(
73-
"{qualified}-metrics",
74-
qualified = cluster.resource_names(role_group_name).stateful_set_name()
75-
)
76-
}
77-
7866
/// The rolegroup [`Service`] for exposing metrics
7967
pub(crate) fn build_server_rolegroup_metrics_service(
8068
cluster: &ValidatedCluster,
@@ -84,7 +72,11 @@ pub(crate) fn build_server_rolegroup_metrics_service(
8472
let metrics_port = cluster.metrics_http_port(rolegroup_config);
8573
let metadata = ObjectMetaBuilder::new()
8674
.name_and_namespace(cluster)
87-
.name(metrics_service_name(cluster, role_group_name))
75+
.name(
76+
cluster
77+
.resource_names(role_group_name)
78+
.metrics_service_name(),
79+
)
8880
.ownerreference(ownerreference_from_resource(cluster, None, Some(true)))
8981
.with_labels(cluster.recommended_labels(role_group_name))
9082
.with_labels(prometheus_labels())

rust/operator-binary/src/znode_controller.rs

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

112112
#[snafu(display("object has no namespace"))]
113113
ObjectHasNoNamespace,
114-
115-
#[snafu(display("Znode {znode:?} missing expected keys (name and/or namespace)"))]
116-
ZnodeMissingExpectedKeys {
117-
source: stackable_operator::cluster_resources::Error,
118-
znode: ObjectRef<v1alpha1::ZookeeperZnode>,
119-
},
120114
}
121115
type Result<T, E = Error> = std::result::Result<T, E>;
122116

@@ -162,7 +156,6 @@ impl ReconcilerError for Error {
162156
Error::Finalizer { .. } => None,
163157
Error::DeleteOrphans { .. } => None,
164158
Error::ObjectHasNoNamespace => None,
165-
Error::ZnodeMissingExpectedKeys { .. } => None,
166159
}
167160
}
168161
}
@@ -267,6 +260,9 @@ async fn reconcile_apply(
267260
zk: v1alpha1::ZookeeperCluster,
268261
znode_path: &str,
269262
) -> Result<controller::Action> {
263+
// Infallible: `ValidatedZnode`'s object reference always contains name, namespace and uid
264+
// (set unconditionally during the validate step), which is all `ClusterResources::new`
265+
// requires.
270266
let mut cluster_resources = ClusterResources::new(
271267
APP_NAME,
272268
OPERATOR_NAME,
@@ -275,10 +271,10 @@ async fn reconcile_apply(
275271
ClusterResourceApplyStrategy::from(&validated_znode.cluster_operation),
276272
&validated_znode.object_overrides,
277273
)
278-
.with_context(|_| ZnodeMissingExpectedKeysSnafu {
279-
znode: ObjectRef::<v1alpha1::ZookeeperZnode>::new(&validated_znode.name)
280-
.within(validated_znode.namespace.as_ref()),
281-
})?;
274+
.expect(
275+
"ClusterResources should be created because the ValidatedZnode's object reference \
276+
always contains name, namespace and uid",
277+
);
282278

283279
znode_mgmt::ensure_znode_exists(
284280
&zk_mgmt_addr(

0 commit comments

Comments
 (0)