Skip to content

Commit 34459d4

Browse files
committed
refactor: move hardcoded properties to constants
1 parent d8e960a commit 34459d4

4 files changed

Lines changed: 57 additions & 30 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ pub fn add_kerberos_pod_config(
230230
pb: &mut PodBuilder,
231231
requested_secret_lifetime: Duration,
232232
) -> Result<(), Error> {
233-
if let Some(kerberos_secret_class) = cluster.cluster_config.kerberos_secret_class.clone() {
233+
if let Some(kerberos_secret_class) = &cluster.cluster_config.kerberos_secret_class {
234234
// Mount keytab
235235
let kerberos_secret_operator_volume = SecretOperatorVolumeSourceBuilder::new(
236-
kerberos_secret_class,
236+
kerberos_secret_class.clone(),
237237
// We need both public (krb5.conf) and private (keytab) parts.
238238
SecretClassVolumeProvisionParts::PublicPrivate,
239239
)
@@ -255,13 +255,13 @@ pub fn add_kerberos_pod_config(
255255
cb.add_env_var("KRB5_CONFIG", KRB5_CONFIG_PATH);
256256
}
257257

258-
if let Some(https_secret_class) = cluster.cluster_config.https_secret_class.clone() {
258+
if let Some(https_secret_class) = &cluster.cluster_config.https_secret_class {
259259
// Mount TLS keystore
260260
pb.add_volume(
261261
VolumeBuilder::new(&*TLS_STORE_VOLUME_NAME)
262262
.ephemeral(
263263
SecretOperatorVolumeSourceBuilder::new(
264-
https_secret_class,
264+
https_secret_class.clone(),
265265
// HBase serves its own TLS endpoints, so the Pod needs both the public
266266
// certificate and the private key.
267267
SecretClassVolumeProvisionParts::PublicPrivate,

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

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ use crate::{
1414
},
1515
};
1616

17+
// `hbase-site.xml` property keys (the `port` keys carry a `_KEY` suffix to avoid clashing with the
18+
// `Port`-typed `HBASE_*_PORT` constants imported from the `crd` module).
19+
const HBASE_CLIENT_RPC_BIND_ADDRESS: &str = "hbase.client.rpc.bind.address";
20+
const HBASE_MASTER_IPC_ADDRESS: &str = "hbase.master.ipc.address";
21+
const HBASE_MASTER_IPC_PORT: &str = "hbase.master.ipc.port";
22+
const HBASE_MASTER_HOSTNAME: &str = "hbase.master.hostname";
23+
const HBASE_MASTER_PORT_KEY: &str = "hbase.master.port";
24+
const HBASE_MASTER_INFO_PORT: &str = "hbase.master.info.port";
25+
const HBASE_MASTER_BOUND_INFO_PORT: &str = "hbase.master.bound.info.port";
26+
const HBASE_REGIONSERVER_IPC_ADDRESS: &str = "hbase.regionserver.ipc.address";
27+
const HBASE_REGIONSERVER_IPC_PORT: &str = "hbase.regionserver.ipc.port";
28+
const HBASE_UNSAFE_REGIONSERVER_HOSTNAME: &str = "hbase.unsafe.regionserver.hostname";
29+
const HBASE_REGIONSERVER_PORT_KEY: &str = "hbase.regionserver.port";
30+
const HBASE_REGIONSERVER_INFO_PORT: &str = "hbase.regionserver.info.port";
31+
const HBASE_REGIONSERVER_BOUND_INFO_PORT: &str = "hbase.regionserver.bound.info.port";
32+
const HBASE_REST_ENDPOINT: &str = "hbase.rest.endpoint";
33+
34+
// `hbase-site.xml` property values that recur across roles. The `${env:...}` placeholders are
35+
// resolved by HBase at runtime from the Pod's environment.
36+
const BIND_ALL_ADDRESSES: &str = "0.0.0.0";
37+
const ENV_HBASE_SERVICE_HOST: &str = "${env:HBASE_SERVICE_HOST}";
38+
const ENV_HBASE_SERVICE_PORT: &str = "${env:HBASE_SERVICE_PORT}";
39+
const ENV_HBASE_INFO_PORT: &str = "${env:HBASE_INFO_PORT}";
40+
1741
/// Renders `hbase-site.xml`.
1842
pub fn build(
1943
role: &HbaseRole,
@@ -38,69 +62,69 @@ pub fn build(
3862
// RPC traffic to happen from the same network interface that
3963
// the RPC server is bound on).
4064
config.insert(
41-
"hbase.client.rpc.bind.address".to_string(),
65+
HBASE_CLIENT_RPC_BIND_ADDRESS.to_string(),
4266
"false".to_string(),
4367
);
4468

4569
match role {
4670
HbaseRole::Master => {
4771
config.insert(
48-
"hbase.master.ipc.address".to_string(),
49-
"0.0.0.0".to_string(),
72+
HBASE_MASTER_IPC_ADDRESS.to_string(),
73+
BIND_ALL_ADDRESSES.to_string(),
5074
);
5175
config.insert(
52-
"hbase.master.ipc.port".to_string(),
76+
HBASE_MASTER_IPC_PORT.to_string(),
5377
HBASE_MASTER_PORT.to_string(),
5478
);
5579
config.insert(
56-
"hbase.master.hostname".to_string(),
57-
"${env:HBASE_SERVICE_HOST}".to_string(),
80+
HBASE_MASTER_HOSTNAME.to_string(),
81+
ENV_HBASE_SERVICE_HOST.to_string(),
5882
);
5983
config.insert(
60-
"hbase.master.port".to_string(),
61-
"${env:HBASE_SERVICE_PORT}".to_string(),
84+
HBASE_MASTER_PORT_KEY.to_string(),
85+
ENV_HBASE_SERVICE_PORT.to_string(),
6286
);
6387
config.insert(
64-
"hbase.master.info.port".to_string(),
65-
"${env:HBASE_INFO_PORT}".to_string(),
88+
HBASE_MASTER_INFO_PORT.to_string(),
89+
ENV_HBASE_INFO_PORT.to_string(),
6690
);
6791
config.insert(
68-
"hbase.master.bound.info.port".to_string(),
92+
HBASE_MASTER_BOUND_INFO_PORT.to_string(),
6993
HBASE_MASTER_UI_PORT.to_string(),
7094
);
7195
}
7296
HbaseRole::RegionServer => {
7397
config.insert(
74-
"hbase.regionserver.ipc.address".to_string(),
75-
"0.0.0.0".to_string(),
98+
HBASE_REGIONSERVER_IPC_ADDRESS.to_string(),
99+
BIND_ALL_ADDRESSES.to_string(),
76100
);
77101
config.insert(
78-
"hbase.regionserver.ipc.port".to_string(),
102+
HBASE_REGIONSERVER_IPC_PORT.to_string(),
79103
HBASE_REGIONSERVER_PORT.to_string(),
80104
);
81105
config.insert(
82-
"hbase.unsafe.regionserver.hostname".to_string(),
83-
"${env:HBASE_SERVICE_HOST}".to_string(),
106+
HBASE_UNSAFE_REGIONSERVER_HOSTNAME.to_string(),
107+
ENV_HBASE_SERVICE_HOST.to_string(),
84108
);
85109
config.insert(
86-
"hbase.regionserver.port".to_string(),
87-
"${env:HBASE_SERVICE_PORT}".to_string(),
110+
HBASE_REGIONSERVER_PORT_KEY.to_string(),
111+
ENV_HBASE_SERVICE_PORT.to_string(),
88112
);
89113
config.insert(
90-
"hbase.regionserver.info.port".to_string(),
91-
"${env:HBASE_INFO_PORT}".to_string(),
114+
HBASE_REGIONSERVER_INFO_PORT.to_string(),
115+
ENV_HBASE_INFO_PORT.to_string(),
92116
);
93117
config.insert(
94-
"hbase.regionserver.bound.info.port".to_string(),
118+
HBASE_REGIONSERVER_BOUND_INFO_PORT.to_string(),
95119
HBASE_REGIONSERVER_UI_PORT.to_string(),
96120
);
97121
}
98122
HbaseRole::RestServer => {
99123
config.insert(
100124
// N.B. a custom tag, so as not to interfere with HBase internals.
101125
// The other roles use a patch to correctly resolve host/port.
102-
"hbase.rest.endpoint".to_string(),
103-
"${env:HBASE_SERVICE_HOST}:${env:HBASE_SERVICE_PORT}".to_string(),
126+
HBASE_REST_ENDPOINT.to_string(),
127+
format!("{ENV_HBASE_SERVICE_HOST}:{ENV_HBASE_SERVICE_PORT}"),
104128
);
105129
}
106130
};

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,10 @@ pub struct ValidatedRoleConfig {
259259
pub pdb: stackable_operator::commons::pdb::PdbConfig,
260260
}
261261

262-
/// Per-rolegroup configuration: the merged CRD config plus the merged
263-
/// (role <- role group) `configOverrides`, `envOverrides` and `podOverrides`.
262+
/// The validated per-rolegroup product configuration: the merged CRD config and the resolved
263+
/// logging settings. The merged (role <- role group) `configOverrides`, `envOverrides` and
264+
/// `podOverrides` live on the enclosing [`HbaseRoleGroupConfig`] (the `RoleGroupConfig` wrapper),
265+
/// not here.
264266
#[derive(Clone, Debug)]
265267
pub struct ValidatedHbaseConfig {
266268
/// The merged, role-specific product config.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ fn default_resources(role: &HbaseRole) -> ResourcesFragment<HbaseStorageConfig,
312312
}
313313

314314
impl HbaseConfigFragment {
315-
/// The operator defaults for a `masters` or `restServers` role group.
315+
/// The operator defaults for the `masters` and `restServers` roles, which share this config
316+
/// fragment (`regionServers` use [`RegionServerConfigFragment::default_config`]).
316317
pub fn default_config(
317318
role: &HbaseRole,
318319
cluster_name: &str,

0 commit comments

Comments
 (0)