Skip to content

Commit ae25463

Browse files
committed
refactor: adopt upstream RoleGroupConfig, carry optional replicas
1 parent aaa2ca9 commit ae25463

9 files changed

Lines changed: 145 additions & 123 deletions

File tree

Cargo.lock

Lines changed: 51 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/operator-binary/src/zk_controller/build/graceful_shutdown.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use snafu::{ResultExt, Snafu};
22
use stackable_operator::builder::pod::PodBuilder;
33

4-
use crate::crd::v1alpha1;
4+
use crate::zk_controller::validate::ValidatedZookeeperConfig;
55

66
#[derive(Debug, Snafu)]
77
pub enum Error {
@@ -12,7 +12,7 @@ pub enum Error {
1212
}
1313

1414
pub fn add_graceful_shutdown_config(
15-
merged_config: &v1alpha1::ZookeeperConfig,
15+
merged_config: &ValidatedZookeeperConfig,
1616
pod_builder: &mut PodBuilder,
1717
) -> Result<(), Error> {
1818
// This must be always set by the merge mechanism, as we provide a default value,

rust/operator-binary/src/zk_controller/build/jvm.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ use stackable_operator::memory::{BinaryMultiple, MemoryQuantity};
33

44
use super::properties::ConfigFileName;
55
use crate::{
6-
crd::{
7-
JMX_METRICS_PORT, STACKABLE_CONFIG_DIR, STACKABLE_LOG_CONFIG_DIR, v1alpha1::ZookeeperConfig,
8-
},
9-
zk_controller::validate::ValidatedRoleGroupConfig,
6+
crd::{JMX_METRICS_PORT, STACKABLE_CONFIG_DIR, STACKABLE_LOG_CONFIG_DIR},
7+
zk_controller::validate::{ValidatedZookeeperConfig, ZookeeperRoleGroupConfig},
108
};
119

1210
const JAVA_HEAP_FACTOR: f32 = 0.8;
@@ -23,7 +21,7 @@ pub enum Error {
2321
}
2422

2523
/// All JVM arguments.
26-
fn construct_jvm_args(rolegroup_config: &ValidatedRoleGroupConfig) -> Vec<String> {
24+
fn construct_jvm_args(rolegroup_config: &ZookeeperRoleGroupConfig) -> Vec<String> {
2725
let jvm_args = vec![
2826
format!(
2927
"-Djava.security.properties={STACKABLE_CONFIG_DIR}/{}",
@@ -40,12 +38,15 @@ fn construct_jvm_args(rolegroup_config: &ValidatedRoleGroupConfig) -> Vec<String
4038

4139
// Apply the already-merged (role + role group) JVM argument overrides on top of the
4240
// operator-generated base arguments.
43-
rolegroup_config.jvm_argument_overrides.apply_to(jvm_args)
41+
rolegroup_config
42+
.product_specific_common_config
43+
.jvm_argument_overrides
44+
.apply_to(jvm_args)
4445
}
4546

4647
/// Arguments that go into `SERVER_JVMFLAGS`, so *not* the heap settings (which you can get using
4748
/// [`construct_zk_server_heap_env`]).
48-
pub fn construct_non_heap_jvm_args(rolegroup_config: &ValidatedRoleGroupConfig) -> String {
49+
pub fn construct_non_heap_jvm_args(rolegroup_config: &ZookeeperRoleGroupConfig) -> String {
4950
let mut jvm_args = construct_jvm_args(rolegroup_config);
5051
jvm_args.retain(|arg| !is_heap_jvm_argument(arg));
5152

@@ -54,7 +55,9 @@ pub fn construct_non_heap_jvm_args(rolegroup_config: &ValidatedRoleGroupConfig)
5455

5556
/// This will be put into `ZK_SERVER_HEAP`, which is just the heap size in megabytes (*without* the `m`
5657
/// unit prepended).
57-
pub fn construct_zk_server_heap_env(merged_config: &ZookeeperConfig) -> Result<String, Error> {
58+
pub fn construct_zk_server_heap_env(
59+
merged_config: &ValidatedZookeeperConfig,
60+
) -> Result<String, Error> {
5861
let heap_size_in_mb = (MemoryQuantity::try_from(
5962
merged_config
6063
.resources
@@ -89,7 +92,7 @@ mod tests {
8992
};
9093

9194
/// The validated, merged config for the `default` server role group.
92-
fn server_default(zk: &ZookeeperCluster) -> ValidatedRoleGroupConfig {
95+
fn server_default(zk: &ZookeeperCluster) -> ZookeeperRoleGroupConfig {
9396
let default_group = RoleGroupName::from_str("default").expect("valid role group name");
9497
validated_cluster(zk)
9598
.role_group_configs

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

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

5-
use crate::zk_controller::validate::ValidatedRoleGroupConfig;
5+
use crate::zk_controller::validate::ZookeeperRoleGroupConfig;
66

77
const NETWORKADDRESS_CACHE_TTL: &str = "networkaddress.cache.ttl";
88
const NETWORKADDRESS_CACHE_NEGATIVE_TTL: &str = "networkaddress.cache.negative.ttl";
@@ -14,7 +14,7 @@ const DEFAULT_NETWORKADDRESS_CACHE_NEGATIVE_TTL: &str = "0";
1414
///
1515
/// The entire file is operator-injected (the values formerly came from
1616
/// `product-config`'s `properties.yaml`), plus any user `configOverrides`.
17-
pub fn build(rolegroup_config: &ValidatedRoleGroupConfig) -> BTreeMap<String, String> {
17+
pub fn build(rolegroup_config: &ZookeeperRoleGroupConfig) -> BTreeMap<String, String> {
1818
let mut security_properties = BTreeMap::new();
1919

2020
// Operator-injected defaults (former properties.yaml recommended values).

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
//! Builder for `zoo.cfg` (the main ZooKeeper properties file).
2-
//!
3-
//! The operator-injected defaults seeded here used to live in
4-
//! `deploy/config-spec/properties.yaml` and were injected by the `product-config`
5-
//! crate during validation. They are reproduced here so the rendered config is
6-
//! byte-identical to the previous implementation.
72
83
use std::collections::BTreeMap;
94

@@ -14,7 +9,7 @@ use crate::{
149
METRICS_PROVIDER_HTTP_PORT, METRICS_PROVIDER_HTTP_PORT_KEY, STACKABLE_DATA_DIR,
1510
security::ZookeeperSecurity, v1alpha1::ZookeeperConfig,
1611
},
17-
zk_controller::validate::{ValidatedCluster, ValidatedRoleGroupConfig},
12+
zk_controller::validate::{ValidatedCluster, ZookeeperRoleGroupConfig},
1813
};
1914

2015
const ADMIN_SERVER_PORT_KEY: &str = "admin.serverPort";
@@ -36,7 +31,7 @@ const DEFAULT_TICK_TIME: &str = "3000";
3631
/// 5. `configOverrides` for `zoo.cfg`
3732
pub fn build(
3833
cluster: &ValidatedCluster,
39-
rolegroup_config: &ValidatedRoleGroupConfig,
34+
rolegroup_config: &ZookeeperRoleGroupConfig,
4035
) -> BTreeMap<String, String> {
4136
let security = &cluster.cluster_config.zookeeper_security;
4237
let config = &rolegroup_config.config;
@@ -115,7 +110,7 @@ impl ValidatedCluster {
115110
/// Defined here (in the build layer) rather than in `validate` so that resolving the port —
116111
/// which renders the full `zoo.cfg` via [`build`] — does not invert the validate → build
117112
/// dependency direction.
118-
pub fn metrics_http_port(&self, rolegroup_config: &ValidatedRoleGroupConfig) -> Port {
113+
pub fn metrics_http_port(&self, rolegroup_config: &ZookeeperRoleGroupConfig) -> Port {
119114
build(self, rolegroup_config)
120115
.get(METRICS_PROVIDER_HTTP_PORT_KEY)
121116
.and_then(|port| port.parse::<u16>().ok())

rust/operator-binary/src/zk_controller/build/resource/config_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use stackable_operator::{
2020

2121
use crate::zk_controller::{
2222
build::properties::{ConfigFileName, product_logging, security_properties, zoo_cfg},
23-
validate::{ValidatedCluster, ValidatedRoleGroupConfig},
23+
validate::{ValidatedCluster, ZookeeperRoleGroupConfig},
2424
};
2525

2626
#[derive(Snafu, Debug)]
@@ -51,7 +51,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;
5151
pub fn build_server_rolegroup_config_map(
5252
cluster: &ValidatedCluster,
5353
role_group_name: &RoleGroupName,
54-
rolegroup_config: &ValidatedRoleGroupConfig,
54+
rolegroup_config: &ZookeeperRoleGroupConfig,
5555
) -> Result<ConfigMap> {
5656
let mut data: BTreeMap<String, String> = BTreeMap::new();
5757

@@ -78,7 +78,7 @@ pub fn build_server_rolegroup_config_map(
7878

7979
// logback.xml
8080
if let Some(logback) =
81-
product_logging::build_logback_config(&rolegroup_config.logging.zookeeper_container)
81+
product_logging::build_logback_config(&rolegroup_config.config.logging.zookeeper_container)
8282
{
8383
data.insert(ConfigFileName::LogbackXml.to_string(), logback);
8484
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
ZOOKEEPER_ELECTION_PORT, ZOOKEEPER_ELECTION_PORT_NAME, ZOOKEEPER_LEADER_PORT,
1111
ZOOKEEPER_LEADER_PORT_NAME,
1212
},
13-
zk_controller::validate::{ValidatedCluster, ValidatedRoleGroupConfig},
13+
zk_controller::validate::{ValidatedCluster, ZookeeperRoleGroupConfig},
1414
};
1515

1616
/// The rolegroup [`Service`] is a headless service that allows internal access to the instances of a certain rolegroup
@@ -64,7 +64,7 @@ pub(crate) fn build_server_rolegroup_headless_service(
6464
pub(crate) fn build_server_rolegroup_metrics_service(
6565
cluster: &ValidatedCluster,
6666
role_group_name: &RoleGroupName,
67-
rolegroup_config: &ValidatedRoleGroupConfig,
67+
rolegroup_config: &ZookeeperRoleGroupConfig,
6868
) -> Service {
6969
let metrics_port = cluster.metrics_http_port(rolegroup_config);
7070
let metadata = cluster

rust/operator-binary/src/zk_controller/build/resource/statefulset.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use stackable_operator::{
3333
product_logging::{
3434
self,
3535
framework::{create_vector_shutdown_file_command, remove_vector_shutdown_file_command},
36-
spec::{ContainerLogConfig, ContainerLogConfigChoice},
3736
},
3837
utils::COMMON_BASH_TRAP_FUNCTIONS,
3938
v2::{
@@ -64,7 +63,7 @@ use crate::{
6463
jvm::{construct_non_heap_jvm_args, construct_zk_server_heap_env},
6564
properties::{self, ConfigFileName},
6665
},
67-
validate::{ValidatedCluster, ValidatedRoleGroupConfig},
66+
validate::{ValidatedCluster, ZookeeperRoleGroupConfig},
6867
},
6968
};
7069

@@ -154,10 +153,9 @@ fn build_role_listener_pvc(
154153
pub fn build_server_rolegroup_statefulset(
155154
cluster: &ValidatedCluster,
156155
role_group_name: &RoleGroupName,
157-
rolegroup_config: &ValidatedRoleGroupConfig,
156+
rolegroup_config: &ZookeeperRoleGroupConfig,
158157
) -> Result<StatefulSet> {
159158
let merged_config = &rolegroup_config.config;
160-
let logging = &merged_config.logging;
161159
let resource_names = cluster.resource_names(role_group_name);
162160
let resolved_product_image = &cluster.image;
163161
let zookeeper_security = &cluster.cluster_config.zookeeper_security;
@@ -226,9 +224,8 @@ pub fn build_server_rolegroup_statefulset(
226224

227225
let mut args = Vec::new();
228226

229-
if let Some(ContainerLogConfig {
230-
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
231-
}) = logging.containers.get(&v1alpha1::Container::Prepare)
227+
if let ValidatedContainerLogConfigChoice::Automatic(log_config) =
228+
&rolegroup_config.config.logging.prepare_container
232229
{
233230
args.push(product_logging::framework::capture_shell_output(
234231
STACKABLE_LOG_DIR,
@@ -391,7 +388,7 @@ pub fn build_server_rolegroup_statefulset(
391388

392389
// Use the user-provided custom log ConfigMap if one is configured, otherwise fall back to the
393390
// rolegroup's own ConfigMap. This branches on the *validated* logging choice.
394-
let log_config_map = match &rolegroup_config.logging.zookeeper_container {
391+
let log_config_map = match &rolegroup_config.config.logging.zookeeper_container {
395392
ValidatedContainerLogConfigChoice::Custom(config_map) => config_map.to_string(),
396393
ValidatedContainerLogConfigChoice::Automatic(_) => {
397394
resource_names.role_group_config_map().to_string()
@@ -411,7 +408,7 @@ pub fn build_server_rolegroup_statefulset(
411408
// The static `vector.yaml` (in the rolegroup ConfigMap, mounted as the `config` volume) is
412409
// parameterised at runtime via env vars that the v2 `vector_container` injects. The validated
413410
// Vector log config is built up-front in the validate step.
414-
if let Some(vector_log_config) = &rolegroup_config.logging.vector_container {
411+
if let Some(vector_log_config) = &rolegroup_config.config.logging.vector_container {
415412
let config_volume_name = VolumeName::from_str(CONFIG_VOLUME_NAME)
416413
.expect("CONFIG_VOLUME_NAME is a valid volume name");
417414
let log_volume_name =
@@ -442,7 +439,9 @@ pub fn build_server_rolegroup_statefulset(
442439

443440
let statefulset_spec = StatefulSetSpec {
444441
pod_management_policy: Some("Parallel".to_string()),
445-
replicas: Some(i32::from(rolegroup_config.replicas)),
442+
// `None` (no replica count specified) leaves `.spec.replicas` unset so a
443+
// HorizontalPodAutoscaler can manage the replica count.
444+
replicas: rolegroup_config.replicas.map(i32::from),
446445
selector: LabelSelector {
447446
match_labels: Some(cluster.role_group_selector(role_group_name).into()),
448447
..LabelSelector::default()

0 commit comments

Comments
 (0)