Skip to content

Commit a125271

Browse files
maltesanderclaude
andcommitted
feat: Add core-site.xml builder
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7c07062 commit a125271

1 file changed

Lines changed: 117 additions & 1 deletion

File tree

  • rust/operator-binary/src/controller/build/properties
Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,117 @@
1-
//! placeholder — implemented in a later task
1+
//! Builder for `core-site.xml`.
2+
//!
3+
//! Only emitted when Kerberos is enabled and there is no HDFS backend (i.e. S3),
4+
//! in which case `hadoop.security.authentication=kerberos` is required.
5+
6+
use std::collections::BTreeMap;
7+
8+
use crate::crd::v1alpha1;
9+
10+
const HADOOP_SECURITY_AUTHENTICATION: &str = "hadoop.security.authentication";
11+
12+
/// Returns the `core-site.xml` properties, or `None` if the file should be omitted.
13+
pub fn build(hive: &v1alpha1::HiveCluster) -> Option<BTreeMap<String, Option<String>>> {
14+
if hive.has_kerberos_enabled() && hive.spec.cluster_config.hdfs.is_none() {
15+
let mut data = BTreeMap::new();
16+
data.insert(
17+
HADOOP_SECURITY_AUTHENTICATION.to_string(),
18+
Some("kerberos".to_string()),
19+
);
20+
Some(data)
21+
} else {
22+
None
23+
}
24+
}
25+
26+
#[cfg(test)]
27+
mod tests {
28+
use super::*;
29+
30+
fn hive_cluster(yaml: &str) -> v1alpha1::HiveCluster {
31+
stackable_operator::utils::yaml_from_str_singleton_map(yaml).expect("valid HiveCluster YAML")
32+
}
33+
34+
const NO_KERBEROS_YAML: &str = r#"
35+
apiVersion: hive.stackable.tech/v1alpha1
36+
kind: HiveCluster
37+
metadata:
38+
name: simple-hive
39+
namespace: default
40+
spec:
41+
image:
42+
productVersion: "4.0.0"
43+
clusterConfig:
44+
metadataDatabase:
45+
derby: {}
46+
metastore:
47+
roleGroups:
48+
default:
49+
replicas: 1
50+
"#;
51+
52+
const KERBEROS_S3_YAML: &str = r#"
53+
apiVersion: hive.stackable.tech/v1alpha1
54+
kind: HiveCluster
55+
metadata:
56+
name: simple-hive
57+
namespace: default
58+
spec:
59+
image:
60+
productVersion: "4.0.0"
61+
clusterConfig:
62+
authentication:
63+
kerberos:
64+
secretClass: kerberos
65+
metadataDatabase:
66+
derby: {}
67+
metastore:
68+
roleGroups:
69+
default:
70+
replicas: 1
71+
"#;
72+
73+
const KERBEROS_HDFS_YAML: &str = r#"
74+
apiVersion: hive.stackable.tech/v1alpha1
75+
kind: HiveCluster
76+
metadata:
77+
name: simple-hive
78+
namespace: default
79+
spec:
80+
image:
81+
productVersion: "4.0.0"
82+
clusterConfig:
83+
authentication:
84+
kerberos:
85+
secretClass: kerberos
86+
metadataDatabase:
87+
derby: {}
88+
hdfs:
89+
configMap: hdfs
90+
metastore:
91+
roleGroups:
92+
default:
93+
replicas: 1
94+
"#;
95+
96+
#[test]
97+
fn omitted_without_kerberos() {
98+
let hive = hive_cluster(NO_KERBEROS_YAML);
99+
assert!(build(&hive).is_none());
100+
}
101+
102+
#[test]
103+
fn emitted_with_kerberos_and_no_hdfs() {
104+
let hive = hive_cluster(KERBEROS_S3_YAML);
105+
let data = build(&hive).expect("core-site present");
106+
assert_eq!(
107+
data.get("hadoop.security.authentication"),
108+
Some(&Some("kerberos".to_string()))
109+
);
110+
}
111+
112+
#[test]
113+
fn omitted_with_kerberos_but_hdfs_backend() {
114+
let hive = hive_cluster(KERBEROS_HDFS_YAML);
115+
assert!(build(&hive).is_none());
116+
}
117+
}

0 commit comments

Comments
 (0)