@@ -10,8 +10,9 @@ use stackable_operator::{
1010} ;
1111
1212use 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
1718type 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
0 commit comments