Skip to content

Commit 5c309a2

Browse files
committed
fix: use Option<T> instead of calculated redundant booleans in ValidatedClusterConfig
1 parent b16ef8b commit 5c309a2

5 files changed

Lines changed: 22 additions & 25 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ pub fn build_rolegroup_config_map(
8787
);
8888
let hadoop_policy_xml = hadoop_policy::build(config_overrides.hadoop_policy_xml.clone());
8989
let ssl_server_xml = ssl_server::build(
90-
cluster_config.https_enabled,
90+
cluster_config.authentication.is_some(),
9191
config_overrides.ssl_server_xml.clone(),
9292
);
9393
let ssl_client_xml = ssl_client::build(
94-
cluster_config.https_enabled,
94+
cluster_config.authentication.is_some(),
9595
config_overrides.ssl_client_xml.clone(),
9696
);
9797

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ fn build_discovery_hdfs_site_xml(
9191
.dfs_ha_namenodes(namenode_podrefs)
9292
.dfs_namenode_rpc_address_ha(cluster_info, namenode_podrefs)
9393
.dfs_namenode_http_address_ha(
94-
cluster.cluster_config.https_enabled,
94+
cluster.cluster_config.authentication.is_some(),
9595
cluster_info,
9696
namenode_podrefs,
9797
)
9898
.dfs_client_failover_proxy_provider()
99-
.security_discovery_config(cluster.cluster_config.kerberos_enabled)
99+
.security_discovery_config(cluster.cluster_config.authentication.is_some())
100100
.build_as_xml()
101101
}
102102

@@ -108,9 +108,9 @@ fn build_discovery_core_site_xml(
108108
let kerberos = KerberosConfig {
109109
cluster_name: cluster.name.as_ref(),
110110
cluster_namespace: cluster.namespace.as_ref(),
111-
authentication_enabled: cluster_config.authentication_enabled,
112-
kerberos_enabled: cluster_config.kerberos_enabled,
113-
authorization_enabled: cluster_config.authorization_enabled,
111+
authentication_enabled: cluster_config.authentication.is_some(),
112+
kerberos_enabled: cluster_config.authentication.is_some(),
113+
authorization_enabled: cluster_config.authorization.is_some(),
114114
};
115115
CoreSiteConfigBuilder::new(cluster.name.as_ref().to_owned())
116116
.fs_default_fs()

rust/operator-binary/src/controller/build/properties/core_site.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub fn build(
2323
let kerberos = KerberosConfig {
2424
cluster_name: cluster.name.as_ref(),
2525
cluster_namespace: cluster.namespace.as_ref(),
26-
authentication_enabled: cluster_config.authentication_enabled,
27-
kerberos_enabled: cluster_config.kerberos_enabled,
28-
authorization_enabled: cluster_config.authorization_enabled,
26+
authentication_enabled: cluster_config.authentication.is_some(),
27+
kerberos_enabled: cluster_config.authentication.is_some(),
28+
authorization_enabled: cluster_config.authorization.is_some(),
2929
};
3030

3131
let mut core_site = CoreSiteConfigBuilder::new(cluster.name.as_ref().to_owned());

rust/operator-binary/src/controller/build/properties/hdfs_site.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ pub fn build(
5151
.dfs_namenode_name_dir_ha(&namenode_podrefs)
5252
.dfs_namenode_rpc_address_ha(cluster_info, &namenode_podrefs)
5353
.dfs_namenode_http_address_ha(
54-
cluster_config.https_enabled,
54+
cluster_config.authentication.is_some(),
5555
cluster_info,
5656
&namenode_podrefs,
5757
)
5858
.dfs_client_failover_proxy_provider()
59-
.security_config(cluster_config.kerberos_enabled)
59+
.security_config(cluster_config.authentication.is_some())
6060
.add("dfs.ha.fencing.methods", "shell(/bin/true)")
6161
.add("dfs.ha.automatic-failover.enabled", "true")
6262
.add("dfs.ha.namenode.id", "${env.POD_NAME}")
@@ -101,7 +101,7 @@ pub fn build(
101101
// But today's Java and IO should be able to handle more, so bump it to 8192 for
102102
// better performance/concurrency.
103103
.add("dfs.datanode.max.transfer.threads", "8192");
104-
if cluster_config.https_enabled {
104+
if cluster_config.authentication.is_some() {
105105
hdfs_site.add("dfs.datanode.registered.https.port", "${env.HTTPS_PORT}");
106106
} else {
107107
hdfs_site.add("dfs.datanode.registered.http.port", "${env.HTTP_PORT}");

rust/operator-binary/src/hdfs_controller.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use crate::{
5151
controller::build::discovery::{self, build_discovery_config_map},
5252
crd::{
5353
AnyNodeConfig, HdfsClusterStatus, HdfsNodeRole, HdfsPodRef, UpgradeState,
54-
UpgradeStateError, constants::*, v1alpha1,
54+
UpgradeStateError, constants::*, security::AuthenticationConfig, v1alpha1,
5555
},
5656
event::{build_invalid_replica_message, publish_warning_event},
5757
operations::{
@@ -96,7 +96,7 @@ impl ValidatedCluster {
9696
/// is already resolved on `self` during validation.
9797
pub fn pod_refs(&self, role: &HdfsNodeRole) -> Vec<HdfsPodRef> {
9898
let ports: HashMap<String, u16> =
99-
crate::crd::role_data_ports(role, self.cluster_config.https_enabled)
99+
crate::crd::role_data_ports(role, self.cluster_config.authentication.is_some())
100100
.into_iter()
101101
.collect();
102102

@@ -124,12 +124,12 @@ impl ValidatedCluster {
124124
#[derive(Clone, Debug)]
125125
pub struct ValidatedClusterConfig {
126126
pub dfs_replication: u8,
127-
pub https_enabled: bool,
128-
pub kerberos_enabled: bool,
129-
pub authentication_enabled: bool,
130-
pub authorization_enabled: bool,
131-
pub rack_awareness: Option<String>,
127+
/// The authentication config, if configured. Its presence enables both Kerberos
128+
/// and HTTPS; it also carries the TLS and Kerberos secret class names.
129+
pub authentication: Option<AuthenticationConfig>,
130+
/// The resolved OPA authorization config, if authorization is configured.
132131
pub authorization: Option<HdfsOpaConfig>,
132+
pub rack_awareness: Option<String>,
133133
}
134134

135135
impl ValidatedClusterConfig {
@@ -139,12 +139,9 @@ impl ValidatedClusterConfig {
139139
) -> ValidatedClusterConfig {
140140
ValidatedClusterConfig {
141141
dfs_replication: hdfs.spec.cluster_config.dfs_replication,
142-
https_enabled: hdfs.has_https_enabled(),
143-
kerberos_enabled: hdfs.has_kerberos_enabled(),
144-
authentication_enabled: hdfs.authentication_config().is_some(),
145-
authorization_enabled: hdfs.has_authorization_enabled(),
146-
rack_awareness: hdfs.rackawareness_config(),
142+
authentication: hdfs.authentication_config().cloned(),
147143
authorization,
144+
rack_awareness: hdfs.rackawareness_config(),
148145
}
149146
}
150147
}

0 commit comments

Comments
 (0)