Skip to content

Commit df6b63b

Browse files
committed
refactor: improve discovery configmap
1 parent a21075c commit df6b63b

4 files changed

Lines changed: 56 additions & 16 deletions

File tree

rust/operator-binary/src/zk_controller.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,6 @@ pub async fn reconcile_zk(
454454
&validated_cluster,
455455
ZK_CONTROLLER_NAME,
456456
applied_listener,
457-
None,
458-
resolved_product_image,
459-
zookeeper_security,
460457
)
461458
.context(BuildDiscoveryConfigSnafu)?;
462459

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

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use stackable_operator::{
1010
};
1111

1212
use crate::{
13-
crd::{ZOOKEEPER_SERVER_PORT_NAME, ZookeeperRole, security::ZookeeperSecurity},
13+
crd::{ZOOKEEPER_SERVER_PORT_NAME, ZookeeperRole, security::ZookeeperSecurity, v1alpha1},
1414
utils::build_recommended_labels,
15+
zk_controller::validate::ValidatedCluster,
1516
};
1617

1718
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -60,22 +61,68 @@ pub enum Error {
6061
},
6162
}
6263

64+
/// Build the discovery [`ConfigMap`] for the cluster controller from the
65+
/// [`ValidatedCluster`].
66+
///
67+
/// The ConfigMap is owned by, and placed in the namespace of, the cluster. The image and security
68+
/// settings are taken from the [`ValidatedCluster`] rather than being passed in separately.
69+
pub fn build_discovery_configmap(
70+
validated_cluster: &ValidatedCluster,
71+
controller_name: &str,
72+
listener: listener::v1alpha1::Listener,
73+
) -> Result<ConfigMap> {
74+
build_discovery_configmap_for_owner(
75+
validated_cluster,
76+
&validated_cluster.namespace,
77+
controller_name,
78+
listener,
79+
None,
80+
&validated_cluster.image,
81+
&validated_cluster.cluster_config.zookeeper_security,
82+
)
83+
}
84+
85+
/// Build the discovery [`ConfigMap`] for the znode controller.
86+
///
87+
/// The ConfigMap is owned by, and placed in the namespace of, the
88+
/// [`ZookeeperZnode`](v1alpha1::ZookeeperZnode). The `image` and `zookeeper_security` originate from
89+
/// the referenced cluster, while `chroot` isolates the znode within the shared ZooKeeper ensemble.
90+
pub fn build_znode_discovery_configmap(
91+
znode: &v1alpha1::ZookeeperZnode,
92+
controller_name: &str,
93+
listener: listener::v1alpha1::Listener,
94+
chroot: &str,
95+
image: &ResolvedProductImage,
96+
zookeeper_security: &ZookeeperSecurity,
97+
) -> Result<ConfigMap> {
98+
let namespace = znode.namespace().context(NoNamespaceSnafu)?;
99+
build_discovery_configmap_for_owner(
100+
znode,
101+
namespace,
102+
controller_name,
103+
listener,
104+
Some(chroot),
105+
image,
106+
zookeeper_security,
107+
)
108+
}
109+
63110
/// Build a discovery [`ConfigMap`] containing ZooKeeper connection details from a
64111
/// [`listener::v1alpha1::Listener`].
65112
///
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).
69-
pub fn build_discovery_configmap(
113+
/// `owner` owns the ConfigMap (the [`ZookeeperCluster`](v1alpha1::ZookeeperCluster) for the cluster
114+
/// controller, or the [`ZookeeperZnode`](v1alpha1::ZookeeperZnode) for the znode controller) and
115+
/// `namespace` is where the ConfigMap is placed.
116+
fn build_discovery_configmap_for_owner(
70117
owner: &impl Resource<DynamicType = ()>,
118+
namespace: impl Into<String>,
71119
controller_name: &str,
72120
listener: listener::v1alpha1::Listener,
73121
chroot: Option<&str>,
74122
image: &ResolvedProductImage,
75123
zookeeper_security: &ZookeeperSecurity,
76124
) -> Result<ConfigMap> {
77125
let name = owner.name_unchecked();
78-
let namespace = owner.namespace().context(NoNamespaceSnafu)?;
79126

80127
let listener_addresses = listener_addresses(&listener, ZOOKEEPER_SERVER_PORT_NAME)?;
81128

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ pub struct ValidatedCluster {
9898
/// into the raw [`v1alpha1::ZookeeperCluster`].
9999
metadata: ObjectMeta,
100100
pub name: ClusterName,
101-
/// The cluster namespace. Part of the `ValidatedCluster` contract; consumed by
102-
/// the statefulset/service build steps that move off the raw CRD in a
103-
/// follow-up PR.
104-
#[allow(dead_code)]
105101
pub namespace: NamespaceName,
106102
pub uid: Uid,
107103
pub image: ResolvedProductImage,

rust/operator-binary/src/znode_controller.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::{
2828
APP_NAME, OPERATOR_NAME,
2929
crd::{ZookeeperRole, security::ZookeeperSecurity, v1alpha1},
3030
listener::role_listener_name,
31-
zk_controller::build::discovery::{self, build_discovery_configmap},
31+
zk_controller::build::discovery::{self, build_znode_discovery_configmap},
3232
};
3333

3434
mod dereference;
@@ -320,11 +320,11 @@ async fn reconcile_apply(
320320
zk: ObjectRef::from_obj(&zk),
321321
})?;
322322

323-
let discovery_cm = build_discovery_configmap(
323+
let discovery_cm = build_znode_discovery_configmap(
324324
znode,
325325
ZNODE_CONTROLLER_NAME,
326326
listener,
327-
Some(znode_path),
327+
znode_path,
328328
image,
329329
zookeeper_security,
330330
)

0 commit comments

Comments
 (0)