Skip to content

Commit bb1f171

Browse files
maltesanderclaude
andcommitted
refactor: Simplify build_discovery_configmap params; rename znode validated struct
- build_discovery_configmap drops the redundant `zk` parameter (it was only used for an error ObjectRef; the owner reference comes from `owner`) and renames `resolved_product_image` to `image`. It keeps `image` + `zookeeper_security` as explicit shared params, so both controllers can call it without a shared trait or a full ValidatedCluster. - Rename the znode controller's ValidatedInputs to ValidatedZnode and its resolved_product_image field to image, for naming consistency with ValidatedCluster. No behavior change. Build, clippy, the 16 unit tests, and the generated CRD are all unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent fc445ca commit bb1f171

4 files changed

Lines changed: 23 additions & 25 deletions

File tree

rust/operator-binary/src/zk_controller.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ pub async fn reconcile_zk(
449449
// We don't /need/ stability, but it's still nice to avoid spurious changes where possible.
450450
let mut discovery_hash = FnvHasher::with_key(0);
451451
let discovery_cm = build::discovery::build_discovery_configmap(
452-
zk,
453452
zk,
454453
ZK_CONTROLLER_NAME,
455454
applied_listener,

rust/operator-binary/src/zk_controller/build/discovery.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ use stackable_operator::{
1010
};
1111

1212
use crate::{
13-
crd::{ZOOKEEPER_SERVER_PORT_NAME, ZookeeperRole, security::ZookeeperSecurity, v1alpha1},
13+
crd::{ZOOKEEPER_SERVER_PORT_NAME, ZookeeperRole, security::ZookeeperSecurity},
1414
utils::build_recommended_labels,
1515
};
1616

1717
type Result<T, E = Error> = std::result::Result<T, E>;
1818

1919
#[derive(Snafu, Debug)]
2020
pub enum Error {
21-
#[snafu(display("object {} is missing metadata to build owner reference", zk))]
21+
#[snafu(display("object is missing metadata to build owner reference"))]
2222
ObjectMissingMetadataForOwnerRef {
2323
source: stackable_operator::builder::meta::Error,
24-
zk: ObjectRef<v1alpha1::ZookeeperCluster>,
2524
},
2625

2726
#[snafu(display("chroot path {} was relative (must be absolute)", chroot))]
@@ -61,15 +60,18 @@ pub enum Error {
6160
},
6261
}
6362

64-
/// Build a discovery [`ConfigMap`] containing connection details for a [`v1alpha1::ZookeeperCluster`] from a [`listener::v1alpha1::Listener`].
65-
#[allow(clippy::too_many_arguments)]
63+
/// Build a discovery [`ConfigMap`] containing ZooKeeper connection details from a
64+
/// [`listener::v1alpha1::Listener`].
65+
///
66+
/// `owner` owns the ConfigMap (the [`ZookeeperCluster`](crate::crd::v1alpha1::ZookeeperCluster)
67+
/// for the cluster controller, or the [`ZookeeperZnode`](crate::crd::v1alpha1::ZookeeperZnode)
68+
/// for the znode controller).
6669
pub fn build_discovery_configmap(
67-
zk: &v1alpha1::ZookeeperCluster,
6870
owner: &impl Resource<DynamicType = ()>,
6971
controller_name: &str,
7072
listener: listener::v1alpha1::Listener,
7173
chroot: Option<&str>,
72-
resolved_product_image: &ResolvedProductImage,
74+
image: &ResolvedProductImage,
7375
zookeeper_security: &ZookeeperSecurity,
7476
) -> Result<ConfigMap> {
7577
let name = owner.name_unchecked();
@@ -98,13 +100,11 @@ pub fn build_discovery_configmap(
98100
.name(name)
99101
.namespace(namespace)
100102
.ownerreference_from_resource(owner, None, Some(true))
101-
.with_context(|_| ObjectMissingMetadataForOwnerRefSnafu {
102-
zk: ObjectRef::from_obj(zk),
103-
})?
103+
.context(ObjectMissingMetadataForOwnerRefSnafu)?
104104
.with_recommended_labels(&build_recommended_labels(
105105
owner,
106106
controller_name,
107-
&resolved_product_image.app_version_label_value,
107+
&image.app_version_label_value,
108108
&ZookeeperRole::Server.to_string(),
109109
"discovery",
110110
))

rust/operator-binary/src/znode_controller.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ pub async fn reconcile_znode(
238238
match ev {
239239
finalizer::Event::Apply(znode) => {
240240
let dereferenced = dereferenced_objects.context(DereferenceSnafu)?;
241-
let validate::ValidatedInputs {
242-
resolved_product_image,
241+
let validate::ValidatedZnode {
242+
image,
243243
zookeeper_security,
244244
} = validate::validate(&znode, &dereferenced, &ctx.operator_environment)
245245
.context(ValidateClusterSnafu)?;
@@ -249,7 +249,7 @@ pub async fn reconcile_znode(
249249
dereferenced.zk,
250250
&zookeeper_security,
251251
&znode_path,
252-
&resolved_product_image,
252+
&image,
253253
)
254254
.await
255255
}
@@ -285,7 +285,7 @@ async fn reconcile_apply(
285285
zk: v1alpha1::ZookeeperCluster,
286286
zookeeper_security: &ZookeeperSecurity,
287287
znode_path: &str,
288-
resolved_product_image: &ResolvedProductImage,
288+
image: &ResolvedProductImage,
289289
) -> Result<controller::Action> {
290290
let mut cluster_resources = ClusterResources::new(
291291
APP_NAME,
@@ -321,12 +321,11 @@ async fn reconcile_apply(
321321
})?;
322322

323323
let discovery_cm = build_discovery_configmap(
324-
&zk,
325324
znode,
326325
ZNODE_CONTROLLER_NAME,
327326
listener,
328327
Some(znode_path),
329-
resolved_product_image,
328+
image,
330329
zookeeper_security,
331330
)
332331
.context(BuildDiscoveryConfigMapSnafu)?;

rust/operator-binary/src/znode_controller/validate.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! The validate step in the ZookeeperZnode controller.
22
//!
33
//! Synchronously validates inputs that don't require a Kubernetes client. Produces
4-
//! [`ValidatedInputs`], consumed by the rest of `reconcile_znode`.
4+
//! [`ValidatedZnode`], consumed by the rest of `reconcile_znode`.
55
66
use snafu::{ResultExt, Snafu};
77
use stackable_operator::{
@@ -28,8 +28,8 @@ pub enum Error {
2828
type Result<T, E = Error> = std::result::Result<T, E>;
2929

3030
/// Synchronous inputs the rest of `reconcile_znode` needs after dereferencing.
31-
pub struct ValidatedInputs {
32-
pub resolved_product_image: ResolvedProductImage,
31+
pub struct ValidatedZnode {
32+
pub image: ResolvedProductImage,
3333
pub zookeeper_security: ZookeeperSecurity,
3434
}
3535

@@ -38,8 +38,8 @@ pub fn validate(
3838
_znode: &v1alpha1::ZookeeperZnode,
3939
dereferenced_objects: &DereferencedObjects,
4040
operator_environment: &OperatorEnvironmentOptions,
41-
) -> Result<ValidatedInputs> {
42-
let resolved_product_image = dereferenced_objects
41+
) -> Result<ValidatedZnode> {
42+
let image = dereferenced_objects
4343
.zk
4444
.spec
4545
.image
@@ -58,8 +58,8 @@ pub fn validate(
5858
let zookeeper_security =
5959
ZookeeperSecurity::new(&dereferenced_objects.zk, resolved_authentication_classes);
6060

61-
Ok(ValidatedInputs {
62-
resolved_product_image,
61+
Ok(ValidatedZnode {
62+
image,
6363
zookeeper_security,
6464
})
6565
}

0 commit comments

Comments
 (0)