-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommand.rs
More file actions
74 lines (64 loc) · 3.62 KB
/
Copy pathcommand.rs
File metadata and controls
74 lines (64 loc) · 3.62 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
use stackable_hive_crd::{
HiveCluster, DB_PASSWORD_ENV, DB_PASSWORD_PLACEHOLDER, DB_USERNAME_ENV,
DB_USERNAME_PLACEHOLDER, HIVE_METASTORE_LOG4J2_PROPERTIES, HIVE_SITE_XML, STACKABLE_CONFIG_DIR,
STACKABLE_CONFIG_MOUNT_DIR, STACKABLE_LOG_CONFIG_MOUNT_DIR, STACKABLE_TRUST_STORE,
STACKABLE_TRUST_STORE_PASSWORD, SYSTEM_TRUST_STORE, SYSTEM_TRUST_STORE_PASSWORD,
};
use stackable_operator::commons::{
authentication::tls::{CaCert, Tls, TlsServerVerification, TlsVerification},
s3::S3ConnectionSpec,
};
pub const S3_SECRET_DIR: &str = "/stackable/secrets";
pub const S3_ACCESS_KEY: &str = "accessKey";
pub const S3_SECRET_KEY: &str = "secretKey";
pub const ACCESS_KEY_PLACEHOLDER: &str = "xxx_access_key_xxx";
pub const SECRET_KEY_PLACEHOLDER: &str = "xxx_secret_key_xxx";
pub fn build_container_command_args(
hive: &HiveCluster,
start_command: String,
s3_connection_spec: Option<&S3ConnectionSpec>,
) -> Vec<String> {
let mut args = vec![
// copy config files to a writeable empty folder in order to set s3 access and secret keys
format!("echo copying {STACKABLE_CONFIG_MOUNT_DIR} to {STACKABLE_CONFIG_DIR}"),
format!("cp -RL {STACKABLE_CONFIG_MOUNT_DIR}/* {STACKABLE_CONFIG_DIR}"),
// Copy log4j2 properties
format!("echo copying {STACKABLE_LOG_CONFIG_MOUNT_DIR}/{HIVE_METASTORE_LOG4J2_PROPERTIES} to {STACKABLE_CONFIG_DIR}/{HIVE_METASTORE_LOG4J2_PROPERTIES}"),
format!("cp -RL {STACKABLE_LOG_CONFIG_MOUNT_DIR}/{HIVE_METASTORE_LOG4J2_PROPERTIES} {STACKABLE_CONFIG_DIR}/{HIVE_METASTORE_LOG4J2_PROPERTIES}"),
// Copy system truststore to stackable truststore
format!("keytool -importkeystore -srckeystore {SYSTEM_TRUST_STORE} -srcstoretype jks -srcstorepass {SYSTEM_TRUST_STORE_PASSWORD} -destkeystore {STACKABLE_TRUST_STORE} -deststoretype pkcs12 -deststorepass {STACKABLE_TRUST_STORE_PASSWORD} -noprompt")
];
if hive.spec.cluster_config.hdfs.is_some() {
args.extend([
format!("echo copying /stackable/mount/hdfs-config to {STACKABLE_CONFIG_DIR}"),
format!("cp -RL /stackable/mount/hdfs-config/* {STACKABLE_CONFIG_DIR}"),
]);
}
if let Some(s3) = s3_connection_spec {
if s3.credentials.is_some() {
args.extend([
format!("echo replacing {ACCESS_KEY_PLACEHOLDER} and {SECRET_KEY_PLACEHOLDER} with secret values."),
format!("sed -i \"s|{ACCESS_KEY_PLACEHOLDER}|$(cat {S3_SECRET_DIR}/{S3_ACCESS_KEY})|g\" {STACKABLE_CONFIG_DIR}/{HIVE_SITE_XML}"),
format!("sed -i \"s|{SECRET_KEY_PLACEHOLDER}|$(cat {S3_SECRET_DIR}/{S3_SECRET_KEY})|g\" {STACKABLE_CONFIG_DIR}/{HIVE_SITE_XML}"),
]);
}
if let Some(Tls {
verification:
TlsVerification::Server(TlsServerVerification {
ca_cert: CaCert::SecretClass(secret_class),
}),
}) = &s3.tls
{
args.push(format!("keytool -importcert -file /stackable/certificates/{secret_class}-tls-certificate/ca.crt -alias stackable-{secret_class} -keystore {STACKABLE_TRUST_STORE} -storepass {STACKABLE_TRUST_STORE_PASSWORD} -noprompt"));
}
}
// db credentials
args.extend([
format!("echo replacing {DB_USERNAME_PLACEHOLDER} and {DB_PASSWORD_PLACEHOLDER} with secret values."),
format!("sed -i \"s|{DB_USERNAME_PLACEHOLDER}|${DB_USERNAME_ENV}|g\" {STACKABLE_CONFIG_DIR}/{HIVE_SITE_XML}"),
format!("sed -i \"s|{DB_PASSWORD_PLACEHOLDER}|${DB_PASSWORD_ENV}|g\" {STACKABLE_CONFIG_DIR}/{HIVE_SITE_XML}"),
]);
// metastore start command
args.push(start_command);
vec![args.join("\n")]
}