Skip to content

Commit 11b2d88

Browse files
committed
refactor: switch to v2 JavaCommonConfig
1 parent 1c0193e commit 11b2d88

11 files changed

Lines changed: 192 additions & 373 deletions

File tree

Cargo.lock

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

Cargo.nix

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

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

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use snafu::{OptionExt, ResultExt, Snafu};
44
use stackable_operator::{
55
memory::{BinaryMultiple, MemoryQuantity},
6-
role_utils::{self, JvmArgumentOverrides},
6+
v2::jvm_argument_overrides::JvmArgumentOverrides,
77
};
88

99
use crate::crd::{
@@ -36,18 +36,14 @@ pub enum Error {
3636
"Trino version {version} is not supported. Only specific versions are handled due to version specific JVM configuration generation"
3737
))]
3838
TrinoVersionNotSupported { version: u16 },
39-
40-
#[snafu(display("failed to merge jvm argument overrides"))]
41-
MergeJvmArgumentOverrides { source: role_utils::Error },
4239
}
4340

4441
// Currently works for all supported versions (as of 2024-09-04) but maybe be changed
4542
// in the future depending on the role and version.
4643
pub fn jvm_config(
4744
product_version: u16,
4845
merged_config: &v1alpha1::TrinoConfig,
49-
role_jvm_argument_overrides: &JvmArgumentOverrides,
50-
role_group_jvm_argument_overrides: &JvmArgumentOverrides,
46+
jvm_argument_overrides: &JvmArgumentOverrides,
5147
) -> Result<String, Error> {
5248
let memory_unit = BinaryMultiple::Mebi;
5349
let heap_size = MemoryQuantity::try_from(
@@ -92,24 +88,10 @@ pub fn jvm_config(
9288

9389
jvm_args.push("# Arguments from jvmArgumentOverrides".to_owned());
9490

95-
let operator_generated = JvmArgumentOverrides::new_with_only_additions(jvm_args);
96-
97-
// Merge order mirrors `Role::get_merged_jvm_argument_overrides`:
98-
// 1. operator-generated args are layered on top of the role-level overrides,
99-
// 2. the role-group-level overrides are applied last.
100-
// Note that this is not a purely additive merge, hence the unusual order.
101-
let mut from_role = role_jvm_argument_overrides.clone();
102-
from_role
103-
.try_merge(&operator_generated)
104-
.context(MergeJvmArgumentOverridesSnafu)?;
105-
let mut merged_jvm_argument_overrides = role_group_jvm_argument_overrides.clone();
106-
merged_jvm_argument_overrides
107-
.try_merge(&from_role)
108-
.context(MergeJvmArgumentOverridesSnafu)?;
109-
110-
Ok(merged_jvm_argument_overrides
111-
.effective_jvm_config_after_merging()
112-
.join("\n"))
91+
// `jvm_argument_overrides` already carries the merged role + role-group overrides (merged by
92+
// `with_validated_config` in the validate step). Applying them to the operator-generated args
93+
// layers the overrides on top, in the order: operator-generated <- role <- role group.
94+
Ok(jvm_argument_overrides.apply_to(jvm_args).join("\n"))
11395
}
11496

11597
/// For tests we don't actually look at the Trino version, and return a single "representative"
@@ -269,29 +251,22 @@ mod tests {
269251
let trino: v1alpha1::TrinoCluster =
270252
serde_yaml::from_str(trino_cluster).expect("illegal test input");
271253

272-
let role = TrinoRole::Coordinator;
273-
let rolegroup_ref = role.rolegroup_ref(&trino, "default");
274-
let merged_config = trino.merged_config(&role, &rolegroup_ref, &[]).unwrap();
275-
let coordinators = trino.role(&role).unwrap();
276-
277-
let role_jvm_argument_overrides = coordinators
278-
.config
279-
.product_specific_common_config
280-
.jvm_argument_overrides
281-
.clone();
282-
let role_group_jvm_argument_overrides = coordinators.role_groups["default"]
283-
.config
284-
.product_specific_common_config
285-
.jvm_argument_overrides
286-
.clone();
254+
// Merge + validate via the shared production path; the role + role-group
255+
// `jvmArgumentOverrides` end up merged in `product_specific_common_config`.
256+
let rg = crate::controller::validate::merged_role_group_config(
257+
&trino,
258+
&TrinoRole::Coordinator,
259+
"default",
260+
&[],
261+
);
287262

288-
let product_version = trino.spec.image.product_version();
263+
let product_version =
264+
u16::from_str(trino.spec.image.product_version()).expect("trino version as u16");
289265

290266
jvm_config(
291-
u16::from_str(product_version).expect("trino version as u16"),
292-
&merged_config,
293-
&role_jvm_argument_overrides,
294-
&role_group_jvm_argument_overrides,
267+
product_version,
268+
&rg.config,
269+
&rg.product_specific_common_config.jvm_argument_overrides,
295270
)
296271
.unwrap()
297272
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ pub enum Error {
5454
source: stackable_operator::builder::meta::Error,
5555
},
5656

57-
#[snafu(display("missing JVM argument overrides for role {role}"))]
58-
MissingRoleJvmArgumentOverrides { role: String },
59-
6057
#[snafu(display("failed to build jvm.config"))]
6158
BuildJvmConfig { source: crate::config::jvm::Error },
6259
}
@@ -169,18 +166,11 @@ pub fn build_rolegroup_config_map(
169166
);
170167
}
171168

172-
// 8. jvm.config.
173-
let role_jvm_argument_overrides =
174-
cluster
175-
.role_jvm_argument_overrides
176-
.get(role)
177-
.with_context(|| MissingRoleJvmArgumentOverridesSnafu {
178-
role: role.to_string(),
179-
})?;
169+
// 8. jvm.config. The role + role-group `jvmArgumentOverrides` were already merged in the
170+
// validate step and are carried by `product_specific_common_config`.
180171
let jvm_config = jvm::jvm_config(
181172
cluster.product_version,
182173
&rg.config,
183-
role_jvm_argument_overrides,
184174
&rg.product_specific_common_config.jvm_argument_overrides,
185175
)
186176
.context(BuildJvmConfigSnafu)?;

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

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::collections::BTreeMap;
66
use stackable_operator::{
77
commons::product_image_selection::ResolvedProductImage,
88
kube::{Resource, api::ObjectMeta},
9-
role_utils::JvmArgumentOverrides,
109
v2::types::{
1110
kubernetes::{NamespaceName, Uid},
1211
operator::ClusterName,
@@ -65,10 +64,6 @@ pub struct ValidatedCluster {
6564
pub product_version: u16,
6665
pub cluster_config: ValidatedClusterConfig,
6766
pub role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>>,
68-
/// Role-level JVM argument overrides per role. Required to render `jvm.config` in the build
69-
/// step without access to the raw [`v1alpha1::TrinoCluster`] (the role-group level overrides
70-
/// are carried by [`TrinoRoleGroupConfig::product_specific_common_config`]).
71-
pub role_jvm_argument_overrides: BTreeMap<TrinoRole, JvmArgumentOverrides>,
7267
}
7368

7469
impl ValidatedCluster {
@@ -81,7 +76,6 @@ impl ValidatedCluster {
8176
product_version: u16,
8277
cluster_config: ValidatedClusterConfig,
8378
role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>>,
84-
role_jvm_argument_overrides: BTreeMap<TrinoRole, JvmArgumentOverrides>,
8579
) -> Self {
8680
Self {
8781
metadata: ObjectMeta {
@@ -97,7 +91,6 @@ impl ValidatedCluster {
9791
product_version,
9892
cluster_config,
9993
role_group_configs,
100-
role_jvm_argument_overrides,
10194
}
10295
}
10396
}
@@ -130,3 +123,58 @@ impl Resource for ValidatedCluster {
130123
&mut self.metadata
131124
}
132125
}
126+
127+
/// A minimal, valid TrinoCluster spec shared across unit tests.
128+
#[cfg(test)]
129+
pub(crate) const MINIMAL_TRINO_YAML: &str = r#"
130+
apiVersion: trino.stackable.tech/v1alpha1
131+
kind: TrinoCluster
132+
metadata:
133+
name: simple-trino
134+
namespace: default
135+
uid: "e6ac237d-a6d4-43a1-8135-f36506110912"
136+
spec:
137+
image:
138+
productVersion: "479"
139+
clusterConfig:
140+
catalogLabelSelector: {}
141+
coordinators:
142+
roleGroups:
143+
default:
144+
replicas: 1
145+
workers:
146+
roleGroups:
147+
default:
148+
replicas: 1
149+
"#;
150+
151+
/// Parses [`MINIMAL_TRINO_YAML`] into a [`v1alpha1::TrinoCluster`].
152+
#[cfg(test)]
153+
pub(crate) fn minimal_trino() -> v1alpha1::TrinoCluster {
154+
serde_yaml::from_str(MINIMAL_TRINO_YAML).expect("invalid test TrinoCluster YAML")
155+
}
156+
157+
/// The validated [`MINIMAL_TRINO_YAML`] cluster with empty dereferenced inputs. The common test
158+
/// fixture for build-step unit tests.
159+
#[cfg(test)]
160+
pub(crate) fn validated_cluster() -> ValidatedCluster {
161+
use stackable_operator::cli::OperatorEnvironmentOptions;
162+
163+
use crate::controller::dereference::DereferencedObjects;
164+
165+
let derefs = DereferencedObjects {
166+
resolved_authentication_classes: Vec::new(),
167+
catalog_definitions: Vec::new(),
168+
catalogs: Vec::new(),
169+
trino_opa_config: None,
170+
resolved_fte_config: None,
171+
resolved_client_protocol_config: None,
172+
};
173+
let operator_env = OperatorEnvironmentOptions {
174+
operator_namespace: "stackable-operators".to_string(),
175+
operator_service_name: "trino-operator".to_string(),
176+
image_repository: "oci.example.org".to_string(),
177+
};
178+
179+
validate::validate(&minimal_trino(), &derefs, &operator_env).expect("validate should succeed")
180+
}

0 commit comments

Comments
 (0)