Skip to content

Commit 86fc9ae

Browse files
committed
fix: use builder pattern for discovery configmap
1 parent 90dfbcd commit 86fc9ae

6 files changed

Lines changed: 38 additions & 41 deletions

File tree

rust/operator-binary/src/discovery.rs renamed to rust/operator-binary/src/controller/build/discovery.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
//! Build the discovery `ConfigMap` for the HbaseCluster.
2+
13
use std::collections::BTreeMap;
24

35
use snafu::{ResultExt, Snafu};
46
use stackable_operator::{
57
builder::{configmap::ConfigMapBuilder, meta::ObjectMetaBuilder},
6-
commons::product_image_selection::ResolvedProductImage,
78
k8s_openapi::api::core::v1::ConfigMap,
89
kube::runtime::reflector::ObjectRef,
9-
utils::cluster_info::KubernetesClusterInfo,
1010
};
1111

1212
use crate::{
1313
config::writer::to_hadoop_xml,
14-
crd::{HBASE_SITE_XML, HbaseRole, v1alpha1},
15-
hbase_controller::build_recommended_labels,
16-
kerberos::{self, kerberos_discovery_config_properties},
17-
zookeeper::ZookeeperConnectionInformation,
14+
controller::build::properties::ConfigFileName,
15+
crd::{HbaseRole, v1alpha1},
16+
hbase_controller::{ValidatedCluster, build_recommended_labels},
1817
};
1918

2019
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -36,43 +35,42 @@ pub enum Error {
3635
ObjectMeta {
3736
source: stackable_operator::builder::meta::Error,
3837
},
39-
40-
#[snafu(display("failed to add Kerberos discovery"))]
41-
AddKerberosDiscovery { source: kerberos::Error },
4238
}
4339

4440
/// Creates a discovery config map containing the `hbase-site.xml` for clients.
45-
pub fn build_discovery_configmap(
46-
hbase: &v1alpha1::HbaseCluster,
47-
cluster_info: &KubernetesClusterInfo,
48-
zookeeper_connection_information: &ZookeeperConnectionInformation,
49-
resolved_product_image: &ResolvedProductImage,
41+
///
42+
/// The rendered content comes entirely from `cluster`; `owner_ref` is retained only for the
43+
/// ConfigMap ObjectMeta / owner reference.
44+
pub fn build_discovery_config_map(
45+
cluster: &ValidatedCluster,
46+
owner_ref: &v1alpha1::HbaseCluster,
5047
) -> Result<ConfigMap> {
51-
let mut hbase_site = zookeeper_connection_information.as_hbase_settings();
52-
hbase_site.extend(
53-
kerberos_discovery_config_properties(hbase, cluster_info)
54-
.context(AddKerberosDiscoverySnafu)?,
55-
);
48+
let cluster_config = &cluster.cluster_config;
49+
50+
let mut hbase_site = cluster_config
51+
.zookeeper_connection_information
52+
.as_hbase_settings();
53+
hbase_site.extend(cluster_config.discovery_kerberos_config.clone());
5654

5755
ConfigMapBuilder::new()
5856
.metadata(
5957
ObjectMetaBuilder::new()
60-
.name_and_namespace(hbase)
61-
.ownerreference_from_resource(hbase, None, Some(true))
58+
.name_and_namespace(owner_ref)
59+
.ownerreference_from_resource(owner_ref, None, Some(true))
6260
.with_context(|_| ObjectMissingMetadataForOwnerRefSnafu {
63-
hbase: ObjectRef::from_obj(hbase),
61+
hbase: ObjectRef::from_obj(owner_ref),
6462
})?
6563
.with_recommended_labels(&build_recommended_labels(
66-
hbase,
67-
&resolved_product_image.app_version_label_value,
64+
owner_ref,
65+
&cluster.image.app_version_label_value,
6866
&HbaseRole::RegionServer.to_string(),
6967
"discovery",
7068
))
7169
.context(ObjectMetaSnafu)?
7270
.build(),
7371
)
7472
.add_data(
75-
HBASE_SITE_XML,
73+
ConfigFileName::HbaseSite.to_string(),
7674
to_hadoop_xml(
7775
hbase_site
7876
.into_iter()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod config_map;
2+
pub mod discovery;
23
pub mod properties;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use crate::{
2020
ValidatedRoleGroupConfig,
2121
},
2222
kerberos::{
23-
self, kerberos_config_properties, kerberos_ssl_client_settings,
24-
kerberos_ssl_server_settings,
23+
self, kerberos_config_properties, kerberos_discovery_config_properties,
24+
kerberos_ssl_client_settings, kerberos_ssl_server_settings,
2525
},
2626
};
2727

@@ -124,6 +124,8 @@ pub fn validate_cluster(
124124

125125
let hbase_site_kerberos_config =
126126
kerberos_config_properties(hbase, cluster_info).context(AddKerberosConfigSnafu)?;
127+
let discovery_kerberos_config = kerberos_discovery_config_properties(hbase, cluster_info)
128+
.context(AddKerberosConfigSnafu)?;
127129
let ssl_server_settings = kerberos_ssl_server_settings(hbase);
128130
let ssl_client_settings = kerberos_ssl_client_settings(hbase);
129131

@@ -135,6 +137,7 @@ pub fn validate_cluster(
135137
hbase_opa_config: dereferenced_objects.hbase_opa_config,
136138
kerberos_enabled: hbase.has_kerberos_enabled(),
137139
hbase_site_kerberos_config,
140+
discovery_kerberos_config,
138141
ssl_server_settings,
139142
ssl_client_settings,
140143
},

rust/operator-binary/src/crd/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ pub const TLS_STORE_PASSWORD: &str = "changeit";
5858

5959
pub const JVM_SECURITY_PROPERTIES_FILE: &str = "security.properties";
6060

61-
pub const HBASE_SITE_XML: &str = "hbase-site.xml";
62-
6361
pub const HBASE_CLUSTER_DISTRIBUTED: &str = "hbase.cluster.distributed";
6462
pub const HBASE_ROOTDIR: &str = "hbase.rootdir";
6563

rust/operator-binary/src/hbase_controller.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ use strum::{EnumDiscriminants, IntoStaticStr};
5656

5757
use crate::{
5858
OPERATOR_NAME,
59+
controller::build::discovery::build_discovery_config_map,
5960
crd::{
6061
APP_NAME, AnyServiceConfig, CONFIG_DIR_NAME, Container, HbaseClusterStatus, HbaseRole,
6162
LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME, merged_env, v1alpha1,
6263
},
63-
discovery::build_discovery_configmap,
6464
kerberos::{self, add_kerberos_pod_config},
6565
operations::{graceful_shutdown::add_graceful_shutdown_config, pdb::add_pdbs},
6666
product_logging::{CONTAINERDEBUG_LOG_DIRECTORY, STACKABLE_LOG_DIR},
@@ -110,6 +110,9 @@ pub struct ValidatedClusterConfig {
110110
pub kerberos_enabled: bool,
111111
/// Pre-resolved kerberos properties for hbase-site.xml (empty when kerberos is disabled).
112112
pub hbase_site_kerberos_config: BTreeMap<String, String>,
113+
/// Pre-resolved kerberos properties for the discovery `hbase-site.xml` exposed to clients
114+
/// (empty when kerberos is disabled).
115+
pub discovery_kerberos_config: BTreeMap<String, String>,
113116
/// Pre-resolved ssl-server.xml settings (empty when HTTPS is disabled).
114117
pub ssl_server_settings: BTreeMap<String, String>,
115118
/// Pre-resolved ssl-client.xml settings (empty when HTTPS is disabled).
@@ -161,7 +164,9 @@ pub enum Error {
161164
},
162165

163166
#[snafu(display("failed to build discovery configmap"))]
164-
BuildDiscoveryConfigMap { source: super::discovery::Error },
167+
BuildDiscoveryConfigMap {
168+
source: crate::controller::build::discovery::Error,
169+
},
165170

166171
#[snafu(display("failed to build rolegroup ConfigMap"))]
167172
BuildRolegroupConfigMap {
@@ -406,15 +411,8 @@ pub async fn reconcile_hbase(
406411

407412
// Discovery CM will fail to build until the rest of the cluster has been deployed, so do it last
408413
// so that failure won't inhibit the rest of the cluster from booting up.
409-
let discovery_cm = build_discovery_configmap(
410-
hbase,
411-
&client.kubernetes_cluster_info,
412-
&validated_cluster
413-
.cluster_config
414-
.zookeeper_connection_information,
415-
&validated_cluster.image,
416-
)
417-
.context(BuildDiscoveryConfigMapSnafu)?;
414+
let discovery_cm = build_discovery_config_map(&validated_cluster, hbase)
415+
.context(BuildDiscoveryConfigMapSnafu)?;
418416
cluster_resources
419417
.add(client, discovery_cm)
420418
.await

rust/operator-binary/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use crate::{
4040
mod config;
4141
mod controller;
4242
mod crd;
43-
mod discovery;
4443
mod hbase_controller;
4544
mod kerberos;
4645
mod operations;

0 commit comments

Comments
 (0)