Skip to content

Commit 5d90332

Browse files
committed
fix: cleanup errors, constants, duplication
1 parent 88c2129 commit 5d90332

9 files changed

Lines changed: 46 additions & 72 deletions

File tree

rust/operator-binary/src/container.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ pub enum Error {
131131
source: ListenerOperatorVolumeSourceBuilderError,
132132
},
133133

134-
#[snafu(display("missing or invalid labels for the listener volume"))]
135-
ListenerVolumeLabels {
136-
source: ListenerOperatorVolumeSourceBuilderError,
137-
},
138-
139134
#[snafu(display("failed to configure logging"))]
140135
ConfigureLogging { source: LoggingError },
141136

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,11 @@ pub fn build(overrides: KeyValueConfigOverrides) -> String {
2020
#[cfg(test)]
2121
mod tests {
2222
use super::*;
23-
use crate::controller::build::properties::test_support::config_overrides;
23+
use crate::controller::build::properties::test_support::{EMPTY_HADOOP_XML, config_overrides};
2424

2525
#[test]
2626
fn empty_overrides_render_empty_configuration() {
27-
assert_eq!(
28-
build(config_overrides(&[])),
29-
concat!(
30-
"<?xml version=\"1.0\"?>\n",
31-
"<configuration>\n",
32-
"</configuration>"
33-
)
34-
);
27+
assert_eq!(build(config_overrides(&[])), EMPTY_HADOOP_XML);
3528
}
3629

3730
#[test]

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::collections::BTreeMap;
77

88
use stackable_operator::v2::config_overrides::KeyValueConfigOverrides;
99

10+
use crate::container::{TLS_STORE_DIR, TLS_STORE_PASSWORD};
11+
1012
pub mod core_site;
1113
pub mod hadoop_policy;
1214
pub mod hdfs_site;
@@ -32,6 +34,22 @@ fn resolved_overrides(
3234
defined_entries(overrides.overrides)
3335
}
3436

37+
/// The `<prefix>.truststore.*` entries (location, type, password) injected into
38+
/// `ssl-client.xml` / `ssl-server.xml` when HTTPS is enabled.
39+
fn truststore_entries(prefix: &str) -> [(String, String); 3] {
40+
[
41+
(
42+
format!("{prefix}.truststore.location"),
43+
format!("{TLS_STORE_DIR}/truststore.p12"),
44+
),
45+
(format!("{prefix}.truststore.type"), "pkcs12".to_string()),
46+
(
47+
format!("{prefix}.truststore.password"),
48+
TLS_STORE_PASSWORD.to_string(),
49+
),
50+
]
51+
}
52+
3553
/// The names of the HDFS config files assembled into the rolegroup `ConfigMap`.
3654
#[derive(Clone, Copy, Debug, strum::Display)]
3755
pub enum ConfigFileName {
@@ -79,6 +97,13 @@ pub(crate) mod test_support {
7997
crd::v1alpha1,
8098
};
8199

100+
/// The rendered output of an empty Hadoop-XML configuration (no entries).
101+
pub const EMPTY_HADOOP_XML: &str = concat!(
102+
"<?xml version=\"1.0\"?>\n",
103+
"<configuration>\n",
104+
"</configuration>"
105+
);
106+
82107
/// Builds a [`KeyValueConfigOverrides`] from `(key, value)` pairs for tests.
83108
pub fn config_overrides(pairs: &[(&str, &str)]) -> KeyValueConfigOverrides {
84109
KeyValueConfigOverrides {

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

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,13 @@ use stackable_operator::v2::{
99
config_file_writer::to_hadoop_xml, config_overrides::KeyValueConfigOverrides,
1010
};
1111

12-
use crate::{
13-
container::{TLS_STORE_DIR, TLS_STORE_PASSWORD},
14-
controller::build::properties::resolved_overrides,
15-
};
12+
use crate::controller::build::properties::{resolved_overrides, truststore_entries};
1613

1714
/// Renders `ssl-client.xml` for the given HTTPS state and user overrides.
1815
pub fn build(https_enabled: bool, overrides: KeyValueConfigOverrides) -> String {
1916
let mut config: BTreeMap<String, String> = BTreeMap::new();
2017
if https_enabled {
21-
config.extend([
22-
(
23-
"ssl.client.truststore.location".to_string(),
24-
format!("{TLS_STORE_DIR}/truststore.p12"),
25-
),
26-
(
27-
"ssl.client.truststore.type".to_string(),
28-
"pkcs12".to_string(),
29-
),
30-
(
31-
"ssl.client.truststore.password".to_string(),
32-
TLS_STORE_PASSWORD.to_string(),
33-
),
34-
]);
18+
config.extend(truststore_entries("ssl.client"));
3519
}
3620
// Overrides applied last so users win.
3721
config.extend(resolved_overrides(overrides));
@@ -41,18 +25,14 @@ pub fn build(https_enabled: bool, overrides: KeyValueConfigOverrides) -> String
4125
#[cfg(test)]
4226
mod tests {
4327
use super::*;
44-
use crate::controller::build::properties::test_support::config_overrides;
28+
use crate::{
29+
container::{TLS_STORE_DIR, TLS_STORE_PASSWORD},
30+
controller::build::properties::test_support::{EMPTY_HADOOP_XML, config_overrides},
31+
};
4532

4633
#[test]
4734
fn disabled_https_without_overrides_renders_empty_configuration() {
48-
assert_eq!(
49-
build(false, config_overrides(&[])),
50-
concat!(
51-
"<?xml version=\"1.0\"?>\n",
52-
"<configuration>\n",
53-
"</configuration>"
54-
)
55-
);
35+
assert_eq!(build(false, config_overrides(&[])), EMPTY_HADOOP_XML);
5636
}
5737

5838
#[test]

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,15 @@ use stackable_operator::v2::{
1111

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

1717
/// Renders `ssl-server.xml` for the given HTTPS state and user overrides.
1818
pub fn build(https_enabled: bool, overrides: KeyValueConfigOverrides) -> String {
1919
let mut config: BTreeMap<String, String> = BTreeMap::new();
2020
if https_enabled {
21+
config.extend(truststore_entries("ssl.server"));
2122
config.extend([
22-
(
23-
"ssl.server.truststore.location".to_string(),
24-
format!("{TLS_STORE_DIR}/truststore.p12"),
25-
),
26-
(
27-
"ssl.server.truststore.type".to_string(),
28-
"pkcs12".to_string(),
29-
),
30-
(
31-
"ssl.server.truststore.password".to_string(),
32-
TLS_STORE_PASSWORD.to_string(),
33-
),
3423
(
3524
"ssl.server.keystore.location".to_string(),
3625
format!("{TLS_STORE_DIR}/keystore.p12"),
@@ -50,18 +39,11 @@ pub fn build(https_enabled: bool, overrides: KeyValueConfigOverrides) -> String
5039
#[cfg(test)]
5140
mod tests {
5241
use super::*;
53-
use crate::controller::build::properties::test_support::config_overrides;
42+
use crate::controller::build::properties::test_support::{EMPTY_HADOOP_XML, config_overrides};
5443

5544
#[test]
5645
fn disabled_https_without_overrides_renders_empty_configuration() {
57-
assert_eq!(
58-
build(false, config_overrides(&[])),
59-
concat!(
60-
"<?xml version=\"1.0\"?>\n",
61-
"<configuration>\n",
62-
"</configuration>"
63-
)
64-
);
46+
assert_eq!(build(false, config_overrides(&[])), EMPTY_HADOOP_XML);
6547
}
6648

6749
#[test]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ use crate::{
2121
ValidatedCluster, ValidatedClusterConfig, ValidatedRoleConfig, ValidatedRoleGroupConfig,
2222
},
2323
crd::{HdfsNodeRole, v1alpha1},
24-
hdfs_controller::CONTAINER_IMAGE_BASE_NAME,
2524
security::opa::HdfsOpaConfig,
2625
};
2726

27+
const CONTAINER_IMAGE_BASE_NAME: &str = "hadoop";
28+
2829
#[derive(Snafu, Debug)]
2930
pub enum Error {
3031
#[snafu(display("failed to resolve product image"))]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl v1alpha1::HdfsCluster {
426426
///
427427
/// The `validated_config` is used to extract the ports exposed by the pods.
428428
///
429-
/// The pod refs returned by `pod_refs` will only be able to able to access HDFS
429+
/// The pod refs returned by `pod_refs` will only be able to access HDFS
430430
/// from inside the Kubernetes cluster. For configuring downstream clients,
431431
/// consider using [`Self::namenode_listener_refs`] instead.
432432
pub fn pod_refs(&self, role: &HdfsNodeRole) -> Result<Vec<HdfsPodRef>, Error> {
@@ -678,7 +678,7 @@ impl v1alpha1::HdfsCluster {
678678
}
679679
}
680680

681-
/// Deprecated required JMX metrics port name and metrics port number tuples depending on the role.
681+
/// Returns the deprecated JMX metrics port name and port number tuples for the given role.
682682
pub fn jmx_metrics_ports(&self, role: &HdfsNodeRole) -> Vec<(String, u16)> {
683683
match role {
684684
HdfsNodeRole::Name => vec![(

rust/operator-binary/src/hdfs_controller.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{collections::BTreeMap, sync::Arc};
22

3-
use const_format::concatcp;
43
use snafu::{ResultExt, Snafu};
54
use stackable_operator::{
65
builder::pod::{PodBuilder, security::PodSecurityContextBuilder},
@@ -59,9 +58,6 @@ use crate::{
5958

6059
pub const RESOURCE_MANAGER_HDFS_CONTROLLER: &str = "hdfs-operator-hdfs-controller";
6160
pub const HDFS_CONTROLLER_NAME: &str = "hdfs-controller";
62-
pub const HDFS_FULL_CONTROLLER_NAME: &str = concatcp!(HDFS_CONTROLLER_NAME, '.', OPERATOR_NAME);
63-
64-
pub const CONTAINER_IMAGE_BASE_NAME: &str = "hadoop";
6561

6662
#[derive(Snafu, Debug, EnumDiscriminants)]
6763
#[strum_discriminants(derive(IntoStaticStr))]
@@ -492,7 +488,7 @@ fn rolegroup_statefulset(
492488
// Adds all containers and volumes to the pod builder
493489
// We must use the selector labels ("rolegroup_selector_labels") and not the recommended labels
494490
// for the ephemeral listener volumes created by this function.
495-
// This is because the recommended set contains a "managed-by" label. This labels triggers
491+
// This is because the recommended set contains a "managed-by" label. This label triggers
496492
// the cluster resources to "manage" listeners which is wrong and leads to errors.
497493
// The listeners are managed by the listener-operator.
498494
ContainerConfig::add_containers_and_volumes(

rust/operator-binary/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use std::sync::Arc;
66

77
use anyhow::anyhow;
88
use clap::Parser;
9+
use const_format::concatcp;
910
use futures::{FutureExt, StreamExt, TryFutureExt};
10-
use hdfs_controller::HDFS_FULL_CONTROLLER_NAME;
11+
use hdfs_controller::HDFS_CONTROLLER_NAME;
1112
use stackable_operator::{
1213
YamlSchema,
1314
cli::{Command, RunArguments},
@@ -58,6 +59,7 @@ mod built_info {
5859
}
5960

6061
pub const OPERATOR_NAME: &str = "hdfs.stackable.tech";
62+
pub const HDFS_FULL_CONTROLLER_NAME: &str = concatcp!(HDFS_CONTROLLER_NAME, '.', OPERATOR_NAME);
6163

6264
#[derive(clap::Parser)]
6365
#[clap(about, author)]

0 commit comments

Comments
 (0)