Skip to content

Commit 0957779

Browse files
committed
fix: move hardcoded envs to constants, cleanup
1 parent ab35dac commit 0957779

7 files changed

Lines changed: 48 additions & 20 deletions

File tree

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ constant!(VECTOR_CONFIG_VOLUME_NAME: VolumeName = "hdfs-config");
106106
// The volume holding the product logs that Vector tails.
107107
constant!(VECTOR_LOG_VOLUME_NAME: VolumeName = "log");
108108

109+
// Names of the environment variables set on the HDFS containers. Each is used both as the
110+
// map key and the `EnvVar.name`, so keep them in one place to avoid the two drifting apart.
111+
const ENV_TOPOLOGY_LABELS: &str = "TOPOLOGY_LABELS";
112+
const ENV_HADOOP_OPTS: &str = "HADOOP_OPTS";
113+
const ENV_KRB5_CONFIG: &str = "KRB5_CONFIG";
114+
const ENV_KRB5_CLIENT_KTNAME: &str = "KRB5_CLIENT_KTNAME";
115+
const ENV_CONTAINERDEBUG_LOG_DIRECTORY: &str = "CONTAINERDEBUG_LOG_DIRECTORY";
116+
109117
type Result<T, E = Error> = std::result::Result<T, E>;
110118

111119
#[derive(Snafu, Debug, EnumDiscriminants)]
@@ -900,36 +908,36 @@ impl ContainerConfig {
900908
&& let Some(rack_awareness) = cluster.rackawareness_config()
901909
{
902910
env.insert(
903-
"TOPOLOGY_LABELS".to_string(),
911+
ENV_TOPOLOGY_LABELS.to_string(),
904912
EnvVar {
905-
name: "TOPOLOGY_LABELS".to_string(),
913+
name: ENV_TOPOLOGY_LABELS.to_string(),
906914
value: Some(rack_awareness),
907915
..EnvVar::default()
908916
},
909917
);
910918
}
911919

912920
env.insert(
913-
"HADOOP_OPTS".to_string(),
921+
ENV_HADOOP_OPTS.to_string(),
914922
EnvVar {
915-
name: "HADOOP_OPTS".to_string(),
923+
name: ENV_HADOOP_OPTS.to_string(),
916924
value: Some(construct_global_jvm_args(cluster.has_kerberos_enabled())),
917925
..EnvVar::default()
918926
},
919927
);
920928
if cluster.has_kerberos_enabled() {
921929
env.insert(
922-
"KRB5_CONFIG".to_string(),
930+
ENV_KRB5_CONFIG.to_string(),
923931
EnvVar {
924-
name: "KRB5_CONFIG".to_string(),
932+
name: ENV_KRB5_CONFIG.to_string(),
925933
value: Some(format!("{KERBEROS_CONTAINER_PATH}/krb5.conf")),
926934
..EnvVar::default()
927935
},
928936
);
929937
env.insert(
930-
"KRB5_CLIENT_KTNAME".to_string(),
938+
ENV_KRB5_CLIENT_KTNAME.to_string(),
931939
EnvVar {
932-
name: "KRB5_CLIENT_KTNAME".to_string(),
940+
name: ENV_KRB5_CLIENT_KTNAME.to_string(),
933941
value: Some(format!("{KERBEROS_CONTAINER_PATH}/keytab")),
934942
..EnvVar::default()
935943
},
@@ -938,9 +946,9 @@ impl ContainerConfig {
938946

939947
// Needed for the `containerdebug` process to log it's tracing information to.
940948
env.insert(
941-
"CONTAINERDEBUG_LOG_DIRECTORY".to_string(),
949+
ENV_CONTAINERDEBUG_LOG_DIRECTORY.to_string(),
942950
EnvVar {
943-
name: "CONTAINERDEBUG_LOG_DIRECTORY".to_string(),
951+
name: ENV_CONTAINERDEBUG_LOG_DIRECTORY.to_string(),
944952
value: Some(format!("{STACKABLE_LOG_DIR}/containerdebug")),
945953
value_from: None,
946954
},

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use crate::controller::build::properties::{
66

77
pub const KERBEROS_CONTAINER_PATH: &str = "/stackable/kerberos";
88

9+
/// Hadoop wire-encryption protection level requiring authentication, integrity and
10+
/// confidentiality. Used for both `dfs.data.transfer.protection` and `hadoop.rpc.protection`.
11+
const WIRE_ENCRYPTION_PRIVACY: &str = "privacy";
12+
913
/// The cluster-wide security settings the `security_config` builders need,
1014
/// resolved from the `HdfsCluster` so the builders don't depend on the raw CRD.
1115
pub struct KerberosConfig<'a> {
@@ -48,7 +52,7 @@ impl HdfsSiteConfigBuilder {
4852
}
4953

5054
fn add_wire_encryption_settings(&mut self) -> &mut Self {
51-
self.add("dfs.data.transfer.protection", "privacy");
55+
self.add("dfs.data.transfer.protection", WIRE_ENCRYPTION_PRIVACY);
5256
self.add("dfs.encrypt.data.transfer", "true");
5357
self.add(
5458
"dfs.encrypt.data.transfer.cipher.suite",
@@ -163,7 +167,7 @@ impl CoreSiteConfigBuilder {
163167
}
164168

165169
fn add_wire_encryption_settings(&mut self) -> &mut Self {
166-
self.add("hadoop.rpc.protection", "privacy");
170+
self.add("hadoop.rpc.protection", WIRE_ENCRYPTION_PRIVACY);
167171
self
168172
}
169173
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ impl HdfsSiteConfigBuilder {
231231
jnid.fqdn(cluster_info),
232232
jnid.ports
233233
.get(&String::from(DFS_JOURNALNODE_RPC_ADDRESS))
234-
.map_or(DEFAULT_JOURNAL_NODE_RPC_PORT, |p| p.clone())
234+
.cloned()
235+
.unwrap_or(DEFAULT_JOURNAL_NODE_RPC_PORT)
235236
))
236237
.collect::<Vec<_>>()
237238
.join(";"),
@@ -316,7 +317,8 @@ impl HdfsSiteConfigBuilder {
316317
port = nn
317318
.ports
318319
.get(port_name)
319-
.map_or(default_port.clone(), |p| p.clone())
320+
.cloned()
321+
.unwrap_or_else(|| default_port.clone())
320322
),
321323
);
322324
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pub mod security_properties;
1313
pub mod ssl_client;
1414
pub mod ssl_server;
1515

16+
/// The keystore/truststore type used for the TLS stores provisioned by secret-operator.
17+
pub(crate) const KEYSTORE_TYPE_PKCS12: &str = "pkcs12";
18+
1619
/// The `<prefix>.truststore.*` entries (location, type, password) injected into
1720
/// `ssl-client.xml` / `ssl-server.xml` when HTTPS is enabled.
1821
fn truststore_entries(prefix: &str) -> [(String, String); 3] {
@@ -21,7 +24,10 @@ fn truststore_entries(prefix: &str) -> [(String, String); 3] {
2124
format!("{prefix}.truststore.location"),
2225
format!("{TLS_STORE_DIR}/truststore.p12"),
2326
),
24-
(format!("{prefix}.truststore.type"), "pkcs12".to_string()),
27+
(
28+
format!("{prefix}.truststore.type"),
29+
KEYSTORE_TYPE_PKCS12.to_string(),
30+
),
2531
(
2632
format!("{prefix}.truststore.password"),
2733
TLS_STORE_PASSWORD.to_string(),

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use stackable_operator::v2::{
1111

1212
use crate::controller::build::{
1313
container::{TLS_STORE_DIR, TLS_STORE_PASSWORD},
14-
properties::truststore_entries,
14+
properties::{KEYSTORE_TYPE_PKCS12, truststore_entries},
1515
};
1616

1717
/// Renders `ssl-server.xml` for the given HTTPS state and user overrides.
@@ -24,7 +24,10 @@ pub fn build(https_enabled: bool, overrides: KeyValueConfigOverrides) -> String
2424
"ssl.server.keystore.location".to_string(),
2525
format!("{TLS_STORE_DIR}/keystore.p12"),
2626
),
27-
("ssl.server.keystore.type".to_string(), "pkcs12".to_string()),
27+
(
28+
"ssl.server.keystore.type".to_string(),
29+
KEYSTORE_TYPE_PKCS12.to_string(),
30+
),
2831
(
2932
"ssl.server.keystore.password".to_string(),
3033
TLS_STORE_PASSWORD.to_string(),

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Builds the per-rolegroup `Service`s for the HdfsCluster: a headless `Service`
2+
//! backing the `StatefulSet` pod DNS, and a metrics `Service` carrying the
3+
//! Prometheus scrape labels/annotations.
14
use snafu::{ResultExt, Snafu};
25
use stackable_operator::{
36
builder::meta::ObjectMetaBuilder,
@@ -30,11 +33,13 @@ pub enum Error {
3033
RoleGroupSelectorLabels { source: LabelError },
3134
}
3235

36+
type Result<T, E = Error> = std::result::Result<T, E>;
37+
3338
pub(crate) fn rolegroup_headless_service(
3439
cluster: &ValidatedCluster,
3540
role: &HdfsNodeRole,
3641
role_group_name: &RoleGroupName,
37-
) -> Result<Service, Error> {
42+
) -> Result<Service> {
3843
tracing::info!("Setting up headless Service for role {role} role group {role_group_name}");
3944

4045
let resource_names = cluster.resource_names(role, role_group_name);
@@ -92,7 +97,7 @@ pub(crate) fn rolegroup_metrics_service(
9297
cluster: &ValidatedCluster,
9398
role: &HdfsNodeRole,
9499
role_group_name: &RoleGroupName,
95-
) -> Result<Service, Error> {
100+
) -> Result<Service> {
96101
tracing::info!("Setting up metrics Service for role {role} role group {role_group_name}");
97102

98103
let resource_names = cluster.resource_names(role, role_group_name);

rust/operator-binary/src/hdfs_controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub enum Error {
139139
source: error_boundary::InvalidObject,
140140
},
141141

142-
#[snafu(display("failed to builds service"))]
142+
#[snafu(display("failed to build service"))]
143143
BuildService { source: service::Error },
144144
}
145145

0 commit comments

Comments
 (0)