Skip to content

Commit 4978820

Browse files
maltesanderclaude
andcommitted
refactor: Non-optional config overrides + ConfigFileName for file names
Mirror trino-operator and hdfs-operator: - Switch ZookeeperConfigOverrides to stackable_operator::v2::config_overrides:: KeyValueConfigOverrides with non-optional fields and a derived Merge impl, replacing the manual Merge impl and the KeyValueOverridesProvider/ get_key_value_overrides indirection. The zoo.cfg/security.properties builders now read rg.config_overrides.<field> directly and resolve via resolved_overrides (None values are dropped). - Drop the hard-coded ZOOKEEPER_PROPERTIES_FILE / JVM_SECURITY_PROPERTIES_FILE crd constants. The ConfigMap file names now come solely from the ConfigFileName enum; jvm.rs keeps a local security.properties const for the JVM system property (as trino does). CRD regenerated: the configOverrides fields become non-nullable objects (default {}) with nullable string values, matching trino/hdfs. Backwards- compatible for existing string-valued overrides. All 16 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b8d6046 commit 4978820

6 files changed

Lines changed: 42 additions & 95 deletions

File tree

extra/crds.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,23 +653,25 @@ spec:
653653
properties:
654654
security.properties:
655655
additionalProperties:
656+
nullable: true
656657
type: string
658+
default: {}
657659
description: |-
658660
Flat key-value overrides for `*.properties`, Hadoop XML, etc.
659661
660662
This is backwards-compatible with the existing flat key-value YAML format
661663
used by `HashMap<String, String>`.
662-
nullable: true
663664
type: object
664665
zoo.cfg:
665666
additionalProperties:
667+
nullable: true
666668
type: string
669+
default: {}
667670
description: |-
668671
Flat key-value overrides for `*.properties`, Hadoop XML, etc.
669672
670673
This is backwards-compatible with the existing flat key-value YAML format
671674
used by `HashMap<String, String>`.
672-
nullable: true
673675
type: object
674676
type: object
675677
envOverrides:
@@ -1208,23 +1210,25 @@ spec:
12081210
properties:
12091211
security.properties:
12101212
additionalProperties:
1213+
nullable: true
12111214
type: string
1215+
default: {}
12121216
description: |-
12131217
Flat key-value overrides for `*.properties`, Hadoop XML, etc.
12141218
12151219
This is backwards-compatible with the existing flat key-value YAML format
12161220
used by `HashMap<String, String>`.
1217-
nullable: true
12181221
type: object
12191222
zoo.cfg:
12201223
additionalProperties:
1224+
nullable: true
12211225
type: string
1226+
default: {}
12221227
description: |-
12231228
Flat key-value overrides for `*.properties`, Hadoop XML, etc.
12241229
12251230
This is backwards-compatible with the existing flat key-value YAML format
12261231
used by `HashMap<String, String>`.
1227-
nullable: true
12281232
type: object
12291233
type: object
12301234
envOverrides:

rust/operator-binary/src/config/jvm.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ use stackable_operator::{
55
};
66

77
use crate::crd::{
8-
JMX_METRICS_PORT, JVM_SECURITY_PROPERTIES_FILE, LOG4J_CONFIG_FILE, LOGBACK_CONFIG_FILE,
9-
LoggingFramework, STACKABLE_CONFIG_DIR, STACKABLE_LOG_CONFIG_DIR, ZookeeperServerRoleType,
8+
JMX_METRICS_PORT, LOG4J_CONFIG_FILE, LOGBACK_CONFIG_FILE, LoggingFramework,
9+
STACKABLE_CONFIG_DIR, STACKABLE_LOG_CONFIG_DIR, ZookeeperServerRoleType,
1010
v1alpha1::{ZookeeperCluster, ZookeeperConfig},
1111
};
1212

1313
const JAVA_HEAP_FACTOR: f32 = 0.8;
1414

15+
/// The JVM security properties file the operator writes into the rolegroup
16+
/// ConfigMap (see `zk_controller::build::properties::ConfigFileName`).
17+
const JVM_SECURITY_PROPERTIES_FILE: &str = "security.properties";
18+
1519
#[derive(Snafu, Debug)]
1620
pub enum Error {
1721
#[snafu(display("invalid memory resource configuration - missing default or value in crd?"))]

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

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use stackable_operator::{
1616
fragment::{self, Fragment, ValidationError},
1717
merge::Merge,
1818
},
19-
config_overrides::{KeyValueConfigOverrides, KeyValueOverridesProvider},
2019
crd::ClusterRef,
2120
deep_merger::ObjectOverrides,
2221
k8s_openapi::{
@@ -31,6 +30,7 @@ use stackable_operator::{
3130
shared::time::Duration,
3231
status::condition::{ClusterCondition, HasStatusCondition},
3332
utils::cluster_info::KubernetesClusterInfo,
33+
v2::config_overrides::KeyValueConfigOverrides,
3434
versioned::versioned,
3535
};
3636
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
@@ -49,8 +49,6 @@ pub const APP_NAME: &str = "zookeeper";
4949
pub const OPERATOR_NAME: &str = "zookeeper.stackable.tech";
5050
pub const FIELD_MANAGER: &str = "zookeeper-operator";
5151

52-
pub const ZOOKEEPER_PROPERTIES_FILE: &str = "zoo.cfg";
53-
pub const JVM_SECURITY_PROPERTIES_FILE: &str = "security.properties";
5452

5553
pub const ZOOKEEPER_SERVER_PORT_NAME: &str = "zk";
5654
pub const ZOOKEEPER_LEADER_PORT_NAME: &str = "zk-leader";
@@ -281,17 +279,13 @@ pub mod versioned {
281279
Zookeeper,
282280
}
283281

284-
#[derive(Clone, Debug, Default, Deserialize, JsonSchema, PartialEq, Serialize)]
282+
#[derive(Clone, Debug, Default, Deserialize, Merge, JsonSchema, PartialEq, Serialize)]
285283
pub struct ZookeeperConfigOverrides {
286-
#[serde(default, rename = "zoo.cfg", skip_serializing_if = "Option::is_none")]
287-
pub zoo_cfg: Option<KeyValueConfigOverrides>,
284+
#[serde(default, rename = "zoo.cfg")]
285+
pub zoo_cfg: KeyValueConfigOverrides,
288286

289-
#[serde(
290-
default,
291-
rename = "security.properties",
292-
skip_serializing_if = "Option::is_none"
293-
)]
294-
pub security_properties: Option<KeyValueConfigOverrides>,
287+
#[serde(default, rename = "security.properties")]
288+
pub security_properties: KeyValueConfigOverrides,
295289
}
296290

297291
#[derive(Clone, Default, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
@@ -345,47 +339,6 @@ pub mod versioned {
345339
}
346340
}
347341

348-
impl Merge for v1alpha1::ZookeeperConfigOverrides {
349-
/// Merges `defaults` (role level) into `self` (role-group level). Keys present
350-
/// in `self` win; keys only in `defaults` are added. Mirrors how the previous
351-
/// product-config pipeline merged role and role-group `configOverrides`.
352-
fn merge(&mut self, defaults: &Self) {
353-
merge_key_value_overrides(&mut self.zoo_cfg, &defaults.zoo_cfg);
354-
merge_key_value_overrides(&mut self.security_properties, &defaults.security_properties);
355-
}
356-
}
357-
358-
/// Merges two optional [`KeyValueConfigOverrides`], with `this` taking precedence.
359-
fn merge_key_value_overrides(
360-
this: &mut Option<KeyValueConfigOverrides>,
361-
defaults: &Option<KeyValueConfigOverrides>,
362-
) {
363-
match (this.as_mut(), defaults) {
364-
(Some(this), Some(defaults)) => {
365-
for (key, value) in &defaults.overrides {
366-
this.overrides
367-
.entry(key.clone())
368-
.or_insert_with(|| value.clone());
369-
}
370-
}
371-
(None, Some(defaults)) => *this = Some(defaults.clone()),
372-
(Some(_), None) | (None, None) => {}
373-
}
374-
}
375-
376-
impl KeyValueOverridesProvider for v1alpha1::ZookeeperConfigOverrides {
377-
fn get_key_value_overrides(&self, file: &str) -> BTreeMap<String, Option<String>> {
378-
let field = match file {
379-
ZOOKEEPER_PROPERTIES_FILE => self.zoo_cfg.as_ref(),
380-
JVM_SECURITY_PROPERTIES_FILE => self.security_properties.as_ref(),
381-
_ => None,
382-
};
383-
field
384-
.map(KeyValueConfigOverrides::as_product_config_overrides)
385-
.unwrap_or_default()
386-
}
387-
}
388-
389342
#[derive(
390343
Clone,
391344
Debug,

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

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

10+
use stackable_operator::v2::config_overrides::KeyValueConfigOverrides;
11+
1012
pub mod logging;
1113
pub mod security_properties;
1214
pub mod zoo_cfg;
@@ -20,22 +22,16 @@ pub enum ConfigFileName {
2022
SecurityProperties,
2123
}
2224

23-
/// Applies user-provided key-value overrides to a property map: `Some(value)`
24-
/// sets the key, `None` removes it.
25-
pub(crate) fn apply_overrides(
26-
target: &mut BTreeMap<String, String>,
27-
overrides: BTreeMap<String, Option<String>>,
28-
) {
29-
for (key, value) in overrides {
30-
match value {
31-
Some(value) => {
32-
target.insert(key, value);
33-
}
34-
None => {
35-
target.remove(&key);
36-
}
37-
}
38-
}
25+
/// Resolves user-provided [`KeyValueConfigOverrides`] into the `(key, value)`
26+
/// pairs to merge into a config file, dropping entries whose value is unset
27+
/// (`None`).
28+
pub(crate) fn resolved_overrides(
29+
overrides: KeyValueConfigOverrides,
30+
) -> impl Iterator<Item = (String, String)> {
31+
overrides
32+
.overrides
33+
.into_iter()
34+
.filter_map(|(key, value)| value.map(|value| (key, value)))
3935
}
4036

4137
/// Converts a `key -> value` map into the `key -> Some(value)` shape expected by

rust/operator-binary/src/zk_controller/build/properties/security_properties.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
33
use std::collections::BTreeMap;
44

5-
use stackable_operator::config_overrides::KeyValueOverridesProvider;
5+
use crate::zk_controller::validate::ZookeeperRoleGroupConfig;
66

7-
use crate::{crd::JVM_SECURITY_PROPERTIES_FILE, zk_controller::validate::ZookeeperRoleGroupConfig};
8-
9-
use super::apply_overrides;
7+
use super::resolved_overrides;
108

119
const NETWORKADDRESS_CACHE_TTL: &str = "networkaddress.cache.ttl";
1210
const NETWORKADDRESS_CACHE_NEGATIVE_TTL: &str = "networkaddress.cache.negative.ttl";
@@ -32,12 +30,9 @@ pub fn build(rolegroup_config: &ZookeeperRoleGroupConfig) -> BTreeMap<String, St
3230
);
3331

3432
// configOverrides go last so they win.
35-
apply_overrides(
36-
&mut security_properties,
37-
rolegroup_config
38-
.config_overrides
39-
.get_key_value_overrides(JVM_SECURITY_PROPERTIES_FILE),
40-
);
33+
security_properties.extend(resolved_overrides(
34+
rolegroup_config.config_overrides.security_properties.clone(),
35+
));
4136

4237
security_properties
4338
}

rust/operator-binary/src/zk_controller/build/properties/zoo_cfg.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
88
use std::collections::BTreeMap;
99

10-
use stackable_operator::config_overrides::KeyValueOverridesProvider;
11-
1210
use crate::{
1311
crd::{
1412
METRICS_PROVIDER_HTTP_PORT, METRICS_PROVIDER_HTTP_PORT_KEY, STACKABLE_DATA_DIR,
15-
ZOOKEEPER_PROPERTIES_FILE, security::ZookeeperSecurity, v1alpha1::ZookeeperConfig,
13+
security::ZookeeperSecurity, v1alpha1::ZookeeperConfig,
1614
},
1715
zk_controller::validate::{ValidatedCluster, ZookeeperRoleGroupConfig},
1816
};
1917

20-
use super::apply_overrides;
18+
use super::resolved_overrides;
2119

2220
const ADMIN_SERVER_PORT_KEY: &str = "admin.serverPort";
2321
const DEFAULT_ADMIN_SERVER_PORT: &str = "8080";
@@ -102,12 +100,9 @@ pub fn build(
102100
}
103101

104102
// 5. configOverrides go last so they win.
105-
apply_overrides(
106-
&mut zoo_cfg,
107-
rolegroup_config
108-
.config_overrides
109-
.get_key_value_overrides(ZOOKEEPER_PROPERTIES_FILE),
110-
);
103+
zoo_cfg.extend(resolved_overrides(
104+
rolegroup_config.config_overrides.zoo_cfg.clone(),
105+
));
111106

112107
zoo_cfg
113108
}

0 commit comments

Comments
 (0)