Skip to content

Commit 889daf3

Browse files
committed
refactor: remove calulcated properties from Validated* structs
1 parent f5e2676 commit 889daf3

9 files changed

Lines changed: 81 additions & 82 deletions

File tree

rust/operator-binary/src/controller/build/jvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ mod tests {
129129
let region_server = &validated_cluster.role_group_configs[&HbaseRole::RegionServer]
130130
[&test_utils::role_group_name("default")];
131131

132-
let global_jvm_args = construct_global_jvm_args(hbase.has_kerberos_enabled());
132+
let global_jvm_args = construct_global_jvm_args(validated_cluster.has_kerberos_enabled());
133133
let hbase_heapsize_env =
134134
construct_hbase_heapsize_env(&region_server.config.config).unwrap();
135135

@@ -189,7 +189,7 @@ mod tests {
189189
let region_server = &validated_cluster.role_group_configs[&HbaseRole::RegionServer]
190190
[&test_utils::role_group_name("default")];
191191

192-
let global_jvm_args = construct_global_jvm_args(hbase.has_kerberos_enabled());
192+
let global_jvm_args = construct_global_jvm_args(validated_cluster.has_kerberos_enabled());
193193
let hbase_heapsize_env =
194194
construct_hbase_heapsize_env(&region_server.config.config).unwrap();
195195

rust/operator-binary/src/controller/build/kerberos.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,58 @@ pub enum Error {
5151
},
5252
}
5353

54+
/// The `hbase-site.xml` Kerberos properties for `cluster`, gated on Kerberos being enabled
55+
/// (empty when disabled). Derived in the build step from the validated cluster.
56+
pub fn hbase_site_kerberos_config(
57+
cluster: &ValidatedCluster,
58+
cluster_info: &KubernetesClusterInfo,
59+
) -> BTreeMap<String, String> {
60+
if cluster.has_kerberos_enabled() {
61+
kerberos_config_properties(
62+
cluster.name.as_ref(),
63+
cluster.namespace.as_ref(),
64+
cluster_info,
65+
)
66+
} else {
67+
BTreeMap::new()
68+
}
69+
}
70+
71+
/// The Kerberos properties for the discovery `hbase-site.xml` exposed to clients, gated on
72+
/// Kerberos being enabled (empty when disabled).
73+
pub fn discovery_kerberos_config(
74+
cluster: &ValidatedCluster,
75+
cluster_info: &KubernetesClusterInfo,
76+
) -> BTreeMap<String, String> {
77+
if cluster.has_kerberos_enabled() {
78+
kerberos_discovery_config_properties(
79+
cluster.name.as_ref(),
80+
cluster.namespace.as_ref(),
81+
cluster_info,
82+
)
83+
} else {
84+
BTreeMap::new()
85+
}
86+
}
87+
88+
/// The `ssl-server.xml` settings for `cluster`, gated on HTTPS being enabled (empty when disabled).
89+
pub fn ssl_server_settings(cluster: &ValidatedCluster) -> BTreeMap<String, String> {
90+
if cluster.has_https_enabled() {
91+
kerberos_ssl_server_settings()
92+
} else {
93+
BTreeMap::new()
94+
}
95+
}
96+
97+
/// The `ssl-client.xml` settings for `cluster`, gated on HTTPS being enabled (empty when disabled).
98+
pub fn ssl_client_settings(cluster: &ValidatedCluster) -> BTreeMap<String, String> {
99+
if cluster.has_https_enabled() {
100+
kerberos_ssl_client_settings()
101+
} else {
102+
BTreeMap::new()
103+
}
104+
}
105+
54106
pub fn kerberos_config_properties(
55107
hbase_name: &str,
56108
hbase_namespace: &str,

rust/operator-binary/src/controller/build/resource/config_map.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use stackable_operator::{
55
builder::configmap::ConfigMapBuilder,
66
k8s_openapi::api::core::v1::ConfigMap,
77
product_logging::framework::VECTOR_CONFIG_FILE,
8+
utils::cluster_info::KubernetesClusterInfo,
89
v2::{config_file_writer::PropertiesWriterError, types::operator::RoleGroupName},
910
};
1011

@@ -13,6 +14,7 @@ use crate::{
1314
ValidatedCluster,
1415
build::{
1516
jvm::construct_role_specific_non_heap_jvm_args,
17+
kerberos,
1618
properties::{
1719
ConfigFileName, hbase_env, hbase_site, logging, security_properties, ssl_client,
1820
ssl_server,
@@ -48,6 +50,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;
4850

4951
pub fn build_rolegroup_config_map(
5052
cluster: &ValidatedCluster,
53+
cluster_info: &KubernetesClusterInfo,
5154
role: &HbaseRole,
5255
role_group_name: &RoleGroupName,
5356
) -> Result<ConfigMap> {
@@ -75,7 +78,7 @@ pub fn build_rolegroup_config_map(
7578
cluster_config
7679
.zookeeper_connection_information
7780
.as_hbase_settings(),
78-
cluster_config.hbase_site_kerberos_config.clone(),
81+
kerberos::hbase_site_kerberos_config(cluster, cluster_info),
7982
cluster_config.hbase_opa_config.as_ref(),
8083
overrides.hbase_site_xml.clone(),
8184
);
@@ -90,11 +93,11 @@ pub fn build_rolegroup_config_map(
9093
.context(BuildHbaseEnvSnafu)?;
9194

9295
let ssl_server_xml = ssl_server::build(
93-
cluster_config.ssl_server_settings.clone(),
96+
kerberos::ssl_server_settings(cluster),
9497
overrides.ssl_server_xml.clone(),
9598
);
9699
let ssl_client_xml = ssl_client::build(
97-
cluster_config.ssl_client_settings.clone(),
100+
kerberos::ssl_client_settings(cluster),
98101
overrides.ssl_client_xml.clone(),
99102
);
100103

rust/operator-binary/src/controller/build/resource/discovery.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ use stackable_operator::{
66
k8s_openapi::api::core::v1::ConfigMap,
77
kube::Resource,
88
kvp::ObjectLabels,
9+
utils::cluster_info::KubernetesClusterInfo,
910
v2::{builder::meta::ownerreference_from_resource, config_file_writer::to_hadoop_xml},
1011
};
1112

1213
use crate::{
13-
controller::{ValidatedCluster, build::properties::ConfigFileName},
14+
controller::{
15+
ValidatedCluster,
16+
build::{kerberos, properties::ConfigFileName},
17+
},
1418
crd::{APP_NAME, HbaseRole, OPERATOR_NAME},
1519
};
1620

@@ -34,13 +38,16 @@ pub enum Error {
3438
}
3539

3640
/// Creates a discovery config map containing the `hbase-site.xml` for clients.
37-
pub fn build_discovery_config_map(cluster: &ValidatedCluster) -> Result<ConfigMap> {
41+
pub fn build_discovery_config_map(
42+
cluster: &ValidatedCluster,
43+
cluster_info: &KubernetesClusterInfo,
44+
) -> Result<ConfigMap> {
3845
let cluster_config = &cluster.cluster_config;
3946

4047
let mut hbase_site = cluster_config
4148
.zookeeper_connection_information
4249
.as_hbase_settings();
43-
hbase_site.extend(cluster_config.discovery_kerberos_config.clone());
50+
hbase_site.extend(kerberos::discovery_kerberos_config(cluster, cluster_info));
4451

4552
ConfigMapBuilder::new()
4653
.metadata(

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ impl ValidatedCluster {
179179
}
180180

181181
/// Whether Kerberos is enabled for this cluster.
182-
///
183-
/// Mirrors [`v1alpha1::HbaseCluster::has_kerberos_enabled`], derived here from the validated
184-
/// config so build steps don't have to re-read the raw cluster.
185182
pub fn has_kerberos_enabled(&self) -> bool {
186183
self.cluster_config.kerberos_secret_class.is_some()
187184
}
@@ -252,15 +249,6 @@ pub struct ValidatedClusterConfig {
252249
pub https_secret_class: Option<SecretClassName>,
253250
/// The HDFS discovery ConfigMap name the cluster connects to.
254251
pub hdfs_config_map_name: ConfigMapName,
255-
// Pre-resolved kerberos properties for hbase-site.xml (empty when kerberos is disabled).
256-
pub hbase_site_kerberos_config: BTreeMap<String, String>,
257-
// Pre-resolved kerberos properties for the discovery `hbase-site.xml` exposed to clients
258-
// (empty when kerberos is disabled).
259-
pub discovery_kerberos_config: BTreeMap<String, String>,
260-
// Pre-resolved ssl-server.xml settings (empty when HTTPS is disabled).
261-
pub ssl_server_settings: BTreeMap<String, String>,
262-
// Pre-resolved ssl-client.xml settings (empty when HTTPS is disabled).
263-
pub ssl_client_settings: BTreeMap<String, String>,
264252
// Pre-resolved zookeeper connection settings.
265253
pub zookeeper_connection_information: ZookeeperConnectionInformation,
266254
}

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

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use stackable_operator::{
1010
kube::ResourceExt,
1111
product_logging::spec::Logging,
1212
role_utils::{CommonConfiguration, GenericRoleConfig, Role},
13-
utils::cluster_info::KubernetesClusterInfo,
1413
v2::{
1514
builder::pod::container::{self, EnvVarName, EnvVarSet},
1615
controller_utils::{get_cluster_name, get_namespace, get_uid},
@@ -27,12 +26,7 @@ use strum::IntoEnumIterator;
2726
use crate::{
2827
controller::{
2928
HbaseRoleGroupConfig, ValidatedCluster, ValidatedClusterConfig, ValidatedHbaseConfig,
30-
ValidatedRoleConfig,
31-
build::kerberos::{
32-
kerberos_config_properties, kerberos_discovery_config_properties,
33-
kerberos_ssl_client_settings, kerberos_ssl_server_settings,
34-
},
35-
dereference::DereferencedObjects,
29+
ValidatedRoleConfig, dereference::DereferencedObjects,
3630
},
3731
crd::{
3832
AnyServiceConfig, Container, HbaseConfigFragment, HbaseRole, RegionServerConfigFragment,
@@ -122,7 +116,6 @@ fn validate_logging(
122116
pub fn validate_cluster(
123117
hbase: &v1alpha1::HbaseCluster,
124118
image_repository: &str,
125-
cluster_info: &KubernetesClusterInfo,
126119
dereferenced_objects: DereferencedObjects,
127120
) -> Result<ValidatedCluster, Error> {
128121
let resolved_product_image = hbase
@@ -211,32 +204,6 @@ pub fn validate_cluster(
211204
let namespace = get_namespace(hbase).context(GetClusterIdentitySnafu)?;
212205
let uid = get_uid(hbase).context(GetClusterIdentitySnafu)?;
213206

214-
let kerberos_enabled = hbase.has_kerberos_enabled();
215-
let https_enabled = hbase.has_https_enabled();
216-
217-
// Kerberos- and TLS-related properties, pre-resolved here so the build step stays a pure
218-
// function of `ValidatedCluster` (empty when the respective feature is disabled).
219-
let hbase_site_kerberos_config = if kerberos_enabled {
220-
kerberos_config_properties(name.as_ref(), namespace.as_ref(), cluster_info)
221-
} else {
222-
BTreeMap::new()
223-
};
224-
let discovery_kerberos_config = if kerberos_enabled {
225-
kerberos_discovery_config_properties(name.as_ref(), namespace.as_ref(), cluster_info)
226-
} else {
227-
BTreeMap::new()
228-
};
229-
let ssl_server_settings = if https_enabled {
230-
kerberos_ssl_server_settings()
231-
} else {
232-
BTreeMap::new()
233-
};
234-
let ssl_client_settings = if https_enabled {
235-
kerberos_ssl_client_settings()
236-
} else {
237-
BTreeMap::new()
238-
};
239-
240207
Ok(ValidatedCluster::new(
241208
name,
242209
namespace,
@@ -248,10 +215,6 @@ pub fn validate_cluster(
248215
kerberos_secret_class: hbase.kerberos_secret_class(),
249216
https_secret_class: hbase.https_secret_class(),
250217
hdfs_config_map_name: hbase.spec.cluster_config.hdfs_config_map_name.clone(),
251-
hbase_site_kerberos_config,
252-
discovery_kerberos_config,
253-
ssl_server_settings,
254-
ssl_client_settings,
255218
},
256219
role_groups,
257220
role_configs,

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,6 @@ impl v1alpha1::HbaseCluster {
214214
}
215215
}
216216

217-
pub fn has_kerberos_enabled(&self) -> bool {
218-
self.kerberos_secret_class().is_some()
219-
}
220-
221217
pub fn kerberos_secret_class(&self) -> Option<SecretClassName> {
222218
self.spec
223219
.cluster_config
@@ -227,10 +223,6 @@ impl v1alpha1::HbaseCluster {
227223
.map(|k| k.secret_class.clone())
228224
}
229225

230-
pub fn has_https_enabled(&self) -> bool {
231-
self.https_secret_class().is_some()
232-
}
233-
234226
pub fn https_secret_class(&self) -> Option<SecretClassName> {
235227
self.spec
236228
.cluster_config

rust/operator-binary/src/hbase_controller.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ pub async fn reconcile_hbase(
167167
let validated_cluster = crate::controller::validate::validate_cluster(
168168
hbase,
169169
&ctx.operator_environment.image_repository,
170-
&client.kubernetes_cluster_info,
171170
dereferenced_objects,
172171
)
173172
.context(ValidateSnafu)?;
@@ -210,9 +209,13 @@ pub async fn reconcile_hbase(
210209
let rg_metrics_service =
211210
build_rolegroup_metrics_service(&validated_cluster, hbase_role, role_group_name);
212211

213-
let rg_configmap =
214-
build_rolegroup_config_map(&validated_cluster, hbase_role, role_group_name)
215-
.context(BuildRolegroupConfigMapSnafu)?;
212+
let rg_configmap = build_rolegroup_config_map(
213+
&validated_cluster,
214+
&client.kubernetes_cluster_info,
215+
hbase_role,
216+
role_group_name,
217+
)
218+
.context(BuildRolegroupConfigMapSnafu)?;
216219
let rg_statefulset = build_rolegroup_statefulset(
217220
&validated_cluster,
218221
hbase_role,
@@ -268,7 +271,8 @@ pub async fn reconcile_hbase(
268271
// Discovery CM will fail to build until the rest of the cluster has been deployed, so do it last
269272
// so that failure won't inhibit the rest of the cluster from booting up.
270273
let discovery_cm =
271-
build_discovery_config_map(&validated_cluster).context(BuildDiscoveryConfigMapSnafu)?;
274+
build_discovery_config_map(&validated_cluster, &client.kubernetes_cluster_info)
275+
.context(BuildDiscoveryConfigMapSnafu)?;
272276
cluster_resources
273277
.add(client, discovery_cm)
274278
.await

rust/operator-binary/src/test_utils.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
88
use std::str::FromStr;
99

10-
use stackable_operator::{
11-
commons::networking::DomainName, utils::cluster_info::KubernetesClusterInfo,
12-
v2::types::operator::RoleGroupName,
13-
};
10+
use stackable_operator::v2::types::operator::RoleGroupName;
1411

1512
use crate::{
1613
controller::{
@@ -59,19 +56,12 @@ pub fn minimal_hbase() -> v1alpha1::HbaseCluster {
5956
hbase_from_yaml(MINIMAL_HBASE_YAML)
6057
}
6158

62-
pub fn cluster_info() -> KubernetesClusterInfo {
63-
KubernetesClusterInfo {
64-
cluster_domain: DomainName::try_from("cluster.local").expect("valid domain"),
65-
}
66-
}
67-
6859
/// Runs the real validation pipeline over `hbase`, with a fixed dereferenced ZooKeeper connection
6960
/// and no OPA.
7061
pub fn validated_cluster_from(hbase: &v1alpha1::HbaseCluster) -> ValidatedCluster {
7162
validate_cluster(
7263
hbase,
7364
"oci.example.org",
74-
&cluster_info(),
7565
DereferencedObjects {
7666
zookeeper_connection_information: ZookeeperConnectionInformation::for_tests(),
7767
hbase_opa_config: None,

0 commit comments

Comments
 (0)