-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcommons.rs
More file actions
147 lines (130 loc) · 5.07 KB
/
Copy pathcommons.rs
File metadata and controls
147 lines (130 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
use async_trait::async_trait;
use snafu::{OptionExt, ResultExt, ensure};
use stackable_operator::{
builder::pod::volume::{VolumeBuilder, VolumeMountBuilder},
client::Client,
crd::s3,
k8s_openapi::api::core::v1::ConfigMap,
v2::types::kubernetes::NamespaceName,
};
use super::{
ExtendCatalogConfig, FromTrinoCatalogError,
config::CatalogConfig,
from_trino_catalog_error::{
ConfigureS3Snafu, FailedToGetDiscoveryConfigMapDataKeySnafu,
FailedToGetDiscoveryConfigMapDataSnafu, FailedToGetDiscoveryConfigMapSnafu,
S3TlsNoVerificationNotSupportedSnafu, S3TlsRequiredSnafu,
},
};
use crate::{
config,
controller::dereference::TrinoCatalogName,
crd::{
CONFIG_DIR_NAME,
catalog::commons::{HdfsConnection, MetastoreConnection},
},
};
#[async_trait]
impl ExtendCatalogConfig for MetastoreConnection {
async fn extend_catalog_config(
&self,
catalog_config: &mut CatalogConfig,
catalog_name: &TrinoCatalogName,
catalog_namespace: &NamespaceName,
client: &Client,
_trino_version: u16,
) -> Result<(), FromTrinoCatalogError> {
let hive_cm: ConfigMap = client
.get(self.config_map.as_ref(), catalog_namespace.as_ref())
.await
.with_context(|_| FailedToGetDiscoveryConfigMapSnafu {
catalog: catalog_name.to_string(),
cm_name: self.config_map.to_string(),
})?;
let data_key = "HIVE";
let hive_connection = hive_cm
.data
.as_ref()
.with_context(|| FailedToGetDiscoveryConfigMapDataSnafu {
catalog: catalog_name.to_string(),
cm_name: self.config_map.to_string(),
})?
.get(data_key)
.with_context(|| FailedToGetDiscoveryConfigMapDataKeySnafu {
catalog: catalog_name.to_string(),
cm_name: self.config_map.to_string(),
data_key: data_key.to_string(),
})?;
// This is tightly coupled with the hive discovery config map data layout now
let transformed_hive_connection = hive_connection.replace('\n', ",");
catalog_config.add_property("hive.metastore.uri", transformed_hive_connection);
Ok(())
}
}
#[async_trait]
impl ExtendCatalogConfig for s3::v1alpha1::InlineConnectionOrReference {
async fn extend_catalog_config(
&self,
catalog_config: &mut CatalogConfig,
_catalog_name: &TrinoCatalogName,
catalog_namespace: &NamespaceName,
client: &Client,
_trino_version: u16,
) -> Result<(), FromTrinoCatalogError> {
let s3 = self
.clone()
.resolve(client, catalog_namespace.as_ref())
.await
.context(ConfigureS3Snafu)?;
let (volumes, mounts) = s3.volumes_and_mounts().context(ConfigureS3Snafu)?;
catalog_config.volumes.extend(volumes);
catalog_config.volume_mounts.extend(mounts);
catalog_config.add_property("fs.native-s3.enabled", "true");
catalog_config.add_property("s3.endpoint", s3.endpoint().context(ConfigureS3Snafu)?);
catalog_config.add_property("s3.region", &s3.region.name);
catalog_config.add_property(
"s3.path-style-access",
(s3.access_style == s3::v1alpha1::S3AccessStyle::Path).to_string(),
);
if let Some((access_key, secret_key)) = s3.credentials_mount_paths() {
catalog_config.add_env_property_from_file("s3.aws-access-key", access_key);
catalog_config.add_env_property_from_file("s3.aws-secret-key", secret_key);
}
// TLS is required when using native S3 implementation.
ensure!(s3.tls.uses_tls(), S3TlsRequiredSnafu);
catalog_config.init_container_extra_start_commands.extend(
config::s3::s3_tls_truststore_commands(&s3.tls)
.map_err(|_| S3TlsNoVerificationNotSupportedSnafu.build())?,
);
Ok(())
}
}
#[async_trait]
impl ExtendCatalogConfig for HdfsConnection {
async fn extend_catalog_config(
&self,
catalog_config: &mut CatalogConfig,
catalog_name: &TrinoCatalogName,
_catalog_namespace: &NamespaceName,
_client: &Client,
_trino_version: u16,
) -> Result<(), FromTrinoCatalogError> {
// Since Trino 458, fs.hadoop.enabled defaults to false.
catalog_config.add_property("fs.hadoop.enabled", "true");
let hdfs_site_dir = format!("{CONFIG_DIR_NAME}/catalog/{catalog_name}/hdfs-config",);
catalog_config.add_property(
"hive.config.resources",
format!("{hdfs_site_dir}/core-site.xml,{hdfs_site_dir}/hdfs-site.xml"),
);
let volume_name = format!("{catalog_name}-hdfs");
catalog_config.volumes.push(
VolumeBuilder::new(&volume_name)
.with_config_map(&self.config_map)
.build(),
);
catalog_config
.volume_mounts
.push(VolumeMountBuilder::new(&volume_name, &hdfs_site_dir).build());
Ok(())
}
}