Skip to content

Commit aa5f20a

Browse files
committed
refactor: use v2 types
1 parent 4a66071 commit aa5f20a

21 files changed

Lines changed: 179 additions & 109 deletions

rust/operator-binary/src/authentication/password/file.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::BTreeMap;
1+
use std::{collections::BTreeMap, str::FromStr};
22

33
use snafu::{ResultExt, Snafu};
44
use stackable_operator::{
@@ -15,6 +15,7 @@ use stackable_operator::{
1515
k8s_openapi::api::core::v1::{Container, Volume, VolumeMount},
1616
product_logging::{self, spec::AutomaticContainerLogConfig},
1717
utils::COMMON_BASH_TRAP_FUNCTIONS,
18+
v2::types::kubernetes::{SecretName, VolumeName},
1819
};
1920

2021
use crate::{
@@ -23,7 +24,7 @@ use crate::{
2324
};
2425

2526
// mounts
26-
const PASSWORD_DB_VOLUME_NAME: &str = "users";
27+
stackable_operator::constant!(PASSWORD_DB_VOLUME_NAME: VolumeName = "users");
2728
pub const PASSWORD_DB_VOLUME_MOUNT_PATH: &str = "/stackable/users";
2829
pub const PASSWORD_AUTHENTICATOR_SECRET_MOUNT_PATH: &str = "/stackable/auth-secrets";
2930
// trino properties
@@ -36,6 +37,11 @@ pub enum Error {
3637
AddVolumeMounts {
3738
source: builder::pod::container::Error,
3839
},
40+
41+
#[snafu(display("failed to parse user credentials Secret name"))]
42+
ParseSecretName {
43+
source: stackable_operator::v2::macros::attributed_string_type::Error,
44+
},
3945
}
4046

4147
#[derive(Clone, Debug)]
@@ -69,15 +75,15 @@ impl FileAuthenticator {
6975
}
7076

7177
/// Return the name of the Secret providing the usernames and passwords
72-
pub fn secret_name(&self) -> String {
73-
self.file.user_credentials_secret.name.clone()
78+
pub fn secret_name(&self) -> Result<SecretName, Error> {
79+
SecretName::from_str(&self.file.user_credentials_secret.name).context(ParseSecretNameSnafu)
7480
}
7581

7682
/// Build the volume for the user secret
77-
pub fn secret_volume(&self) -> Volume {
78-
VolumeBuilder::new(self.secret_volume_name())
79-
.with_secret(self.secret_name(), false)
80-
.build()
83+
pub fn secret_volume(&self) -> Result<Volume, Error> {
84+
Ok(VolumeBuilder::new(self.secret_volume_name())
85+
.with_secret(self.secret_name()?, false)
86+
.build())
8187
}
8288

8389
/// Build the volume mount for the user secret
@@ -87,14 +93,14 @@ impl FileAuthenticator {
8793

8894
/// Build the volume for the user password db
8995
pub fn password_db_volume() -> Volume {
90-
VolumeBuilder::new(PASSWORD_DB_VOLUME_NAME)
96+
VolumeBuilder::new(&*PASSWORD_DB_VOLUME_NAME)
9197
.with_empty_dir(None::<String>, None)
9298
.build()
9399
}
94100

95101
/// Build the volume mount for the user password db
96102
pub fn password_db_volume_mount() -> VolumeMount {
97-
VolumeMountBuilder::new(PASSWORD_DB_VOLUME_NAME, PASSWORD_DB_VOLUME_MOUNT_PATH).build()
103+
VolumeMountBuilder::new(&*PASSWORD_DB_VOLUME_NAME, PASSWORD_DB_VOLUME_MOUNT_PATH).build()
98104
}
99105

100106
fn password_file_name(&self) -> String {

rust/operator-binary/src/authentication/password/mod.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88
//! - volume and volume mounts
99
//! - extra containers and commands
1010
//!
11-
use std::str::FromStr;
12-
1311
use snafu::{ResultExt, Snafu};
14-
use stackable_operator::{
15-
commons::product_image_selection::ResolvedProductImage, v2::types::kubernetes::SecretName,
16-
};
12+
use stackable_operator::commons::product_image_selection::ResolvedProductImage;
1713
use tracing::trace;
1814

1915
use crate::{
@@ -42,10 +38,8 @@ pub enum Error {
4238
#[snafu(display("failed to create LDAP Volumes and VolumeMounts"))]
4339
BuildPasswordFileUpdateContainer { source: file::Error },
4440

45-
#[snafu(display("failed to parse user credentials Secret name"))]
46-
ParseSecretName {
47-
source: stackable_operator::v2::macros::attributed_string_type::Error,
48-
},
41+
#[snafu(display("failed to resolve password file authenticator Secret"))]
42+
FileAuthenticatorSecret { source: file::Error },
4943
}
5044

5145
#[derive(Clone, Debug, Default)]
@@ -98,7 +92,11 @@ impl TrinoPasswordAuthentication {
9892
file_authenticator.config_file_data(),
9993
);
10094
// required volumes
101-
password_authentication_config.add_volume(file_authenticator.secret_volume());
95+
password_authentication_config.add_volume(
96+
file_authenticator
97+
.secret_volume()
98+
.context(FileAuthenticatorSecretSnafu)?,
99+
);
102100
password_authentication_config
103101
.add_volume(FileAuthenticator::password_db_volume());
104102

@@ -115,8 +113,9 @@ impl TrinoPasswordAuthentication {
115113
);
116114

117115
password_authentication_config.add_hot_reloaded_secret(
118-
SecretName::from_str(&file_authenticator.secret_name())
119-
.context(ParseSecretNameSnafu)?,
116+
file_authenticator
117+
.secret_name()
118+
.context(FileAuthenticatorSecretSnafu)?,
120119
);
121120
}
122121
TrinoPasswordAuthenticator::Ldap(ldap_authenticator) => {

rust/operator-binary/src/authorization/opa.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use stackable_operator::{
44
client::Client,
55
commons::opa::OpaApiVersion,
66
k8s_openapi::api::core::v1::ConfigMap,
7-
v2::types::kubernetes::{NamespaceName, SecretClassName},
7+
v2::types::kubernetes::{NamespaceName, SecretClassName, VolumeName},
88
};
99

1010
use crate::crd::v1alpha1;
1111

12-
pub const OPA_TLS_VOLUME_NAME: &str = "opa-tls";
12+
stackable_operator::constant!(pub OPA_TLS_VOLUME_NAME: VolumeName = "opa-tls");
1313

1414
#[derive(Clone, Debug)]
1515
pub struct TrinoOpaConfig {
@@ -142,8 +142,11 @@ impl TrinoOpaConfig {
142142
}
143143

144144
pub fn tls_mount_path(&self) -> Option<String> {
145-
self.tls_secret_class
146-
.as_ref()
147-
.map(|_| format!("/stackable/secrets/{OPA_TLS_VOLUME_NAME}"))
145+
self.tls_secret_class.as_ref().map(|_| {
146+
format!(
147+
"/stackable/secrets/{opa_tls_volume_name}",
148+
opa_tls_volume_name = &*OPA_TLS_VOLUME_NAME
149+
)
150+
})
148151
}
149152
}
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
//! Builders that turn a `ValidatedCluster` into Kubernetes resource contents.
22
3+
use std::str::FromStr;
4+
5+
use stackable_operator::v2::types::operator::RoleGroupName;
6+
37
pub mod command;
48
pub mod graceful_shutdown;
59
pub mod ports;
610
pub mod properties;
711
pub mod resource;
812

9-
/// Placeholder role-group name used for the recommended labels of a role's group listener.
10-
///
11-
/// The group listener is owned by the role (not a single role-group), so there is no real
12-
/// role-group to attribute it to.
13-
pub(crate) const PLACEHOLDER_LISTENER_ROLE_GROUP: &str = "none";
13+
// Placeholder role-group name used for the recommended labels of a role's group listener.
14+
// The group listener is owned by the role (not a single role-group), so there is no real
15+
// role-group to attribute it to.
16+
stackable_operator::constant!(pub(crate) PLACEHOLDER_LISTENER_ROLE_GROUP: RoleGroupName = "none");

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
//! Mapping the server-TLS flag onto a concrete port number / name is a resource-shaping decision,
44
//! so it lives in the build step rather than on [`ValidatedCluster`].
55
6+
use stackable_operator::v2::types::common::Port;
7+
68
use crate::{
79
controller::ValidatedCluster,
810
crd::{HTTP_PORT, HTTP_PORT_NAME, HTTPS_PORT, HTTPS_PORT_NAME},
911
};
1012

1113
/// The client-facing port Trino exposes: HTTPS when server TLS is enabled, otherwise HTTP.
12-
pub(crate) fn exposed_port(cluster: &ValidatedCluster) -> u16 {
14+
pub(crate) fn exposed_port(cluster: &ValidatedCluster) -> Port {
1315
if cluster.server_tls_enabled() {
1416
HTTPS_PORT
1517
} else {

rust/operator-binary/src/controller/build/properties/access_control_properties.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ mod tests {
3737
#[test]
3838
fn default_renders_empty_when_no_opa() {
3939
let cluster = validated_cluster_from_yaml(MINIMAL_TRINO_YAML);
40-
let rg = cluster.role_group_configs[&TrinoRole::Coordinator]["default"].clone();
40+
let rg = cluster.role_group_configs[&TrinoRole::Coordinator]
41+
.values()
42+
.next()
43+
.unwrap()
44+
.clone();
4145
let props = build(&cluster, &rg);
4246
assert!(props.is_empty());
4347
}

rust/operator-binary/src/controller/build/properties/config_properties.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ mod tests {
256256
#[test]
257257
fn default_renders_includes_coordinator_default_and_query_max_memory_default() {
258258
let cluster = validated_cluster_from_yaml(MINIMAL_TRINO_YAML);
259-
let rg = cluster.role_group_configs[&TrinoRole::Coordinator]["default"].clone();
259+
let rg = cluster.role_group_configs[&TrinoRole::Coordinator]
260+
.values()
261+
.next()
262+
.unwrap()
263+
.clone();
260264
let cluster_info = stackable_operator::utils::cluster_info::KubernetesClusterInfo {
261265
cluster_domain: stackable_operator::commons::networking::DomainName::try_from(
262266
"cluster.local",

rust/operator-binary/src/controller/build/properties/exchange_manager_properties.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ mod tests {
3737
#[test]
3838
fn default_renders_empty_when_no_fte() {
3939
let cluster = validated_cluster_from_yaml(MINIMAL_TRINO_YAML);
40-
let rg = cluster.role_group_configs[&TrinoRole::Coordinator]["default"].clone();
40+
let rg = cluster.role_group_configs[&TrinoRole::Coordinator]
41+
.values()
42+
.next()
43+
.unwrap()
44+
.clone();
4145
let props = build(&cluster, &rg);
4246
assert!(props.is_empty());
4347
}

rust/operator-binary/src/controller/build/properties/log_properties.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ mod tests {
3939
#[test]
4040
fn default_renders_root_logger_only() {
4141
let cluster = validated_cluster_from_yaml(MINIMAL_TRINO_YAML);
42-
let rg = cluster.role_group_configs[&TrinoRole::Coordinator]["default"].clone();
42+
let rg = cluster.role_group_configs[&TrinoRole::Coordinator]
43+
.values()
44+
.next()
45+
.unwrap()
46+
.clone();
4347
let props = build(&rg);
4448
assert_eq!(props.get("").map(String::as_str), Some("info"));
4549
assert!(!props.contains_key("io.trino"));

rust/operator-binary/src/controller/build/properties/node_properties.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ mod tests {
3636
#[test]
3737
fn default_renders_node_environment_from_cluster_name() {
3838
let cluster = validated_cluster_from_yaml(MINIMAL_TRINO_YAML);
39-
let rg = cluster.role_group_configs[&crate::crd::TrinoRole::Coordinator]["default"].clone();
39+
let rg = cluster.role_group_configs[&crate::crd::TrinoRole::Coordinator]
40+
.values()
41+
.next()
42+
.unwrap()
43+
.clone();
4044
let props = build(&cluster, &rg);
4145
assert_eq!(
4246
props.get("node.environment").map(String::as_str),

0 commit comments

Comments
 (0)