Skip to content

Commit 397cf3b

Browse files
committed
refactor: use upstream v2 with_validated_config and v2 JVM apply_to
1 parent 6196b2e commit 397cf3b

5 files changed

Lines changed: 167 additions & 93 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.

rust/operator-binary/src/controller.rs

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,21 @@ impl ReconcilerError for Error {
294294
pub type RoleGroupName = String;
295295

296296
/// A validated, merged Hive metastore role-group config.
297-
pub type HiveRoleGroupConfig = crate::framework::role_utils::RoleGroupConfig<
298-
MetaStoreConfig,
299-
stackable_operator::role_utils::JavaCommonConfig,
300-
v1alpha1::HiveConfigOverrides,
301-
>;
297+
///
298+
/// Built by [`validate::validate_cluster`] from the upstream
299+
/// [`stackable_operator::v2::role_utils::with_validated_config`] result. Holds only the
300+
/// fields the build steps consume; `cli_overrides` and the product-specific common config
301+
/// are intentionally not carried (hive does not use them).
302+
#[derive(Clone, Debug, PartialEq)]
303+
pub struct HiveRoleGroupConfig {
304+
pub replicas: u16,
305+
pub config: MetaStoreConfig,
306+
pub config_overrides: v1alpha1::HiveConfigOverrides,
307+
pub env_overrides: stackable_operator::v2::builder::pod::container::EnvVarSet,
308+
pub pod_overrides: stackable_operator::k8s_openapi::api::core::v1::PodTemplateSpec,
309+
pub jvm_argument_overrides:
310+
stackable_operator::v2::jvm_argument_overrides::JvmArgumentOverrides,
311+
}
302312

303313
/// The validated cluster: the typed, merged result of the validate step. Subsequent
304314
/// build steps consume this struct instead of re-reading the raw CRD.
@@ -609,8 +619,6 @@ fn build_metastore_rolegroup_statefulset(
609619
let merged_config = &rg.config;
610620
let hive_opa_config = cluster.cluster_config.hive_opa_config.as_ref();
611621

612-
let role = hive.role(hive_role).context(InternalOperatorFailureSnafu)?;
613-
614622
let mut container_builder =
615623
ContainerBuilder::new(APP_NAME).context(FailedToCreateHiveContainerSnafu {
616624
name: APP_NAME.to_string(),
@@ -621,11 +629,7 @@ fn build_metastore_rolegroup_statefulset(
621629
"HADOOP_HEAPSIZE",
622630
construct_hadoop_heapsize_env(merged_config).context(ConstructJvmArgumentsSnafu)?,
623631
)
624-
.add_env_var(
625-
"HADOOP_OPTS",
626-
construct_non_heap_jvm_args(hive, role, &rolegroup_ref.role_group)
627-
.context(ConstructJvmArgumentsSnafu)?,
628-
)
632+
.add_env_var("HADOOP_OPTS", construct_non_heap_jvm_args(hive, rg))
629633
.add_env_var(
630634
"CONTAINERDEBUG_LOG_DIRECTORY",
631635
format!("{STACKABLE_LOG_DIR}/containerdebug"),
@@ -987,3 +991,38 @@ pub fn build_recommended_labels<'a, T>(
987991
role_group,
988992
}
989993
}
994+
995+
#[cfg(test)]
996+
pub(crate) mod test_support {
997+
use stackable_operator::{
998+
commons::networking::DomainName,
999+
utils::{cluster_info::KubernetesClusterInfo, yaml_from_str_singleton_map},
1000+
};
1001+
1002+
use super::{ValidatedCluster, dereference::DereferencedObjects, validate::validate_cluster};
1003+
use crate::crd::v1alpha1;
1004+
1005+
pub fn minimal_hive(yaml: &str) -> v1alpha1::HiveCluster {
1006+
yaml_from_str_singleton_map(yaml).expect("invalid test HiveCluster YAML")
1007+
}
1008+
1009+
pub fn cluster_info() -> KubernetesClusterInfo {
1010+
KubernetesClusterInfo {
1011+
cluster_domain: DomainName::try_from("cluster.local").expect("valid domain"),
1012+
}
1013+
}
1014+
1015+
/// Runs the real validate step against a minimal (S3/OPA-free) fixture.
1016+
pub fn validated_cluster(hive: &v1alpha1::HiveCluster) -> ValidatedCluster {
1017+
validate_cluster(
1018+
hive,
1019+
"oci.example.org",
1020+
&cluster_info(),
1021+
DereferencedObjects {
1022+
s3_connection_spec: None,
1023+
hive_opa_config: None,
1024+
},
1025+
)
1026+
.expect("validate should succeed for the test fixture")
1027+
}
1028+
}

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

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use snafu::{OptionExt, ResultExt, Snafu};
2-
use stackable_operator::{
3-
memory::{BinaryMultiple, MemoryQuantity},
4-
role_utils::{self, JvmArgumentOverrides},
5-
};
2+
use stackable_operator::memory::{BinaryMultiple, MemoryQuantity};
63

74
use super::properties::ConfigFileName;
8-
use crate::crd::{
9-
HiveRoleType, METRICS_PORT, MetaStoreConfig, STACKABLE_CONFIG_DIR, STACKABLE_TRUST_STORE,
10-
STACKABLE_TRUST_STORE_PASSWORD, v1alpha1::HiveCluster,
5+
use crate::{
6+
controller::HiveRoleGroupConfig,
7+
crd::{
8+
METRICS_PORT, MetaStoreConfig, STACKABLE_CONFIG_DIR, STACKABLE_TRUST_STORE,
9+
STACKABLE_TRUST_STORE_PASSWORD, v1alpha1::HiveCluster,
10+
},
1111
};
1212

1313
const JAVA_HEAP_FACTOR: f32 = 0.8;
@@ -21,17 +21,10 @@ pub enum Error {
2121
InvalidMemoryConfig {
2222
source: stackable_operator::memory::Error,
2323
},
24-
25-
#[snafu(display("failed to merge jvm argument overrides"))]
26-
MergeJvmArgumentOverrides { source: role_utils::Error },
2724
}
2825

2926
/// All JVM arguments.
30-
fn construct_jvm_args(
31-
hive: &HiveCluster,
32-
role: &HiveRoleType,
33-
role_group: &str,
34-
) -> Result<Vec<String>, Error> {
27+
fn construct_jvm_args(hive: &HiveCluster, rg: &HiveRoleGroupConfig) -> Vec<String> {
3528
let security_properties = ConfigFileName::Security;
3629
let mut jvm_args = vec![
3730
format!("-Djava.security.properties={STACKABLE_CONFIG_DIR}/{security_properties}"),
@@ -47,27 +40,18 @@ fn construct_jvm_args(
4740
jvm_args.push("-Djava.security.krb5.conf=/stackable/kerberos/krb5.conf".to_owned());
4841
}
4942

50-
let operator_generated = JvmArgumentOverrides::new_with_only_additions(jvm_args);
51-
let merged = role
52-
.get_merged_jvm_argument_overrides(role_group, &operator_generated)
53-
.context(MergeJvmArgumentOverridesSnafu)?;
54-
Ok(merged
55-
.effective_jvm_config_after_merging()
56-
// Sorry for the clone, that's how operator-rs is currently modelled :P
57-
.clone())
43+
// Apply the already-merged (role + role group) JVM argument overrides on top of the
44+
// operator-generated base arguments.
45+
rg.jvm_argument_overrides.apply_to(jvm_args)
5846
}
5947

6048
/// Arguments that go into `HADOOP_OPTS`, so *not* the heap settings (which you can get using
6149
/// [`construct_hadoop_heapsize_env`]).
62-
pub fn construct_non_heap_jvm_args(
63-
hive: &HiveCluster,
64-
role: &HiveRoleType,
65-
role_group: &str,
66-
) -> Result<String, Error> {
67-
let mut jvm_args = construct_jvm_args(hive, role, role_group)?;
50+
pub fn construct_non_heap_jvm_args(hive: &HiveCluster, rg: &HiveRoleGroupConfig) -> String {
51+
let mut jvm_args = construct_jvm_args(hive, rg);
6852
jvm_args.retain(|arg| !is_heap_jvm_argument(arg));
6953

70-
Ok(jvm_args.join(" "))
54+
jvm_args.join(" ")
7155
}
7256

7357
/// This will be put into `HADOOP_HEAPSIZE`, which is just the heap size in megabytes (*without* the `m`
@@ -96,10 +80,21 @@ fn is_heap_jvm_argument(jvm_argument: &str) -> bool {
9680

9781
#[cfg(test)]
9882
mod tests {
99-
use stackable_operator::utils::yaml_from_str_singleton_map;
100-
10183
use super::*;
102-
use crate::crd::HiveRole;
84+
use crate::{
85+
controller::test_support::{minimal_hive, validated_cluster},
86+
crd::HiveRole,
87+
};
88+
89+
fn metastore_default(hive: &crate::crd::v1alpha1::HiveCluster) -> HiveRoleGroupConfig {
90+
let validated = validated_cluster(hive);
91+
validated
92+
.role_group_configs
93+
.get(&HiveRole::MetaStore)
94+
.and_then(|groups| groups.get("default"))
95+
.expect("metastore default role group should exist")
96+
.clone()
97+
}
10398

10499
#[test]
105100
fn test_construct_jvm_arguments_defaults() {
@@ -108,6 +103,8 @@ mod tests {
108103
kind: HiveCluster
109104
metadata:
110105
name: simple-hive
106+
namespace: default
107+
uid: 12345678-1234-1234-1234-123456789012
111108
spec:
112109
image:
113110
productVersion: 4.2.0
@@ -119,9 +116,10 @@ mod tests {
119116
default:
120117
replicas: 1
121118
"#;
122-
let (hive, merged_config, role, rolegroup) = construct_boilerplate(input);
123-
let non_heap_jvm_args = construct_non_heap_jvm_args(&hive, &role, &rolegroup).unwrap();
124-
let hadoop_heapsize_env = construct_hadoop_heapsize_env(&merged_config).unwrap();
119+
let hive = minimal_hive(input);
120+
let rg = metastore_default(&hive);
121+
let non_heap_jvm_args = construct_non_heap_jvm_args(&hive, &rg);
122+
let hadoop_heapsize_env = construct_hadoop_heapsize_env(&rg.config).unwrap();
125123

126124
assert_eq!(
127125
non_heap_jvm_args,
@@ -141,6 +139,8 @@ mod tests {
141139
kind: HiveCluster
142140
metadata:
143141
name: simple-hive
142+
namespace: default
143+
uid: 12345678-1234-1234-1234-123456789012
144144
spec:
145145
image:
146146
productVersion: 4.2.0
@@ -169,9 +169,10 @@ mod tests {
169169
- -Xmx40000m
170170
- -Dhttps.proxyPort=1234
171171
"#;
172-
let (hive, merged_config, role, rolegroup) = construct_boilerplate(input);
173-
let non_heap_jvm_args = construct_non_heap_jvm_args(&hive, &role, &rolegroup).unwrap();
174-
let hadoop_heapsize_env = construct_hadoop_heapsize_env(&merged_config).unwrap();
172+
let hive = minimal_hive(input);
173+
let rg = metastore_default(&hive);
174+
let non_heap_jvm_args = construct_non_heap_jvm_args(&hive, &rg);
175+
let hadoop_heapsize_env = construct_hadoop_heapsize_env(&rg.config).unwrap();
175176

176177
assert_eq!(
177178
non_heap_jvm_args,
@@ -186,18 +187,4 @@ mod tests {
186187
);
187188
assert_eq!(hadoop_heapsize_env, "34406");
188189
}
189-
190-
fn construct_boilerplate(
191-
hive_cluster: &str,
192-
) -> (HiveCluster, MetaStoreConfig, HiveRoleType, String) {
193-
let hive: HiveCluster =
194-
yaml_from_str_singleton_map(hive_cluster).expect("invalid test input");
195-
196-
let hive_role = HiveRole::MetaStore;
197-
let rolegroup_ref = hive.metastore_rolegroup_ref("default");
198-
let merged_config = hive.merged_config(&hive_role, &rolegroup_ref).unwrap();
199-
let role = hive.spec.metastore.clone().unwrap();
200-
201-
(hive, merged_config, role, "default".to_owned())
202-
}
203190
}

0 commit comments

Comments
 (0)