Skip to content

Commit 261b602

Browse files
committed
recfactor: OPA tls mount helper method
1 parent 2f9083c commit 261b602

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use stackable_operator::{
99

1010
use crate::crd::v1alpha1::TrinoCluster;
1111

12+
pub const OPA_TLS_VOLUME_NAME: &str = "opa-tls";
13+
1214
pub struct TrinoOpaConfig {
1315
/// URI for OPA policies, e.g.
1416
/// `http://localhost:8081/v1/data/trino/allow`
@@ -125,4 +127,10 @@ impl TrinoOpaConfig {
125127
}
126128
config
127129
}
130+
131+
pub fn tls_mount_path(&self) -> Option<String> {
132+
self.tls_secret_class
133+
.as_ref()
134+
.map(|_| format!("/stackable/secrets/{OPA_TLS_VOLUME_NAME}"))
135+
}
128136
}

rust/operator-binary/src/controller.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ use strum::{EnumDiscriminants, IntoStaticStr};
7676

7777
use crate::{
7878
authentication::{TrinoAuthenticationConfig, TrinoAuthenticationTypes},
79-
authorization::opa::TrinoOpaConfig,
79+
authorization::opa::{OPA_TLS_VOLUME_NAME, TrinoOpaConfig},
8080
catalog::{FromTrinoCatalogError, config::CatalogConfig},
81-
command, config,
82-
config::{client_protocol, fault_tolerant_execution},
81+
command,
82+
config::{self, client_protocol, fault_tolerant_execution},
8383
crd::{
8484
ACCESS_CONTROL_PROPERTIES, APP_NAME, CONFIG_DIR_NAME, CONFIG_PROPERTIES, Container,
8585
DISCOVERY_URI, ENV_INTERNAL_SECRET, ENV_SPOOLING_SECRET, EXCHANGE_MANAGER_PROPERTIES,
@@ -123,7 +123,6 @@ pub const MAX_PREPARE_LOG_FILE_SIZE: MemoryQuantity = MemoryQuantity {
123123
};
124124

125125
const DOCKER_IMAGE_BASE_NAME: &str = "trino";
126-
const OPA_TLS_VOLUME_NAME: &str = "opa-tls";
127126

128127
#[derive(Snafu, Debug, EnumDiscriminants)]
129128
#[strum_discriminants(derive(IntoStaticStr))]
@@ -1170,13 +1169,12 @@ fn build_rolegroup_statefulset(
11701169
.extend(trino_authentication_config.commands(&TrinoRole::Coordinator, &Container::Prepare));
11711170

11721171
// Add OPA TLS certificate to truststore if configured
1173-
if trino_opa_config
1172+
if let Some(tls_mount_path) = trino_opa_config
11741173
.as_ref()
1175-
.and_then(|c| c.tls_secret_class.as_ref())
1176-
.is_some()
1174+
.and_then(|opa_config| opa_config.tls_mount_path())
11771175
{
11781176
prepare_args.extend(command::add_cert_to_truststore(
1179-
&format!("/stackable/secrets/{OPA_TLS_VOLUME_NAME}/ca.crt"),
1177+
format!("{}/ca.crt", tls_mount_path).as_str(),
11801178
STACKABLE_CLIENT_TLS_DIR,
11811179
));
11821180
}
@@ -1806,26 +1804,30 @@ fn tls_volume_mounts(
18061804
.context(AddVolumeSnafu)?;
18071805
}
18081806

1809-
if let Some(opa_config) = trino_opa_config {
1810-
if let Some(opa_tls_secret_class) = &opa_config.tls_secret_class {
1811-
let opa_tls_mount_path = format!("/stackable/secrets/{OPA_TLS_VOLUME_NAME}");
1812-
1813-
cb_prepare
1814-
.add_volume_mount(OPA_TLS_VOLUME_NAME, &opa_tls_mount_path)
1815-
.context(AddVolumeMountSnafu)?;
1807+
// Add OPA TLS certs if configured
1808+
if let Some((tls_secret_class, tls_mount_path)) =
1809+
trino_opa_config.as_ref().and_then(|opa_config| {
1810+
opa_config
1811+
.tls_secret_class
1812+
.as_ref()
1813+
.zip(opa_config.tls_mount_path())
1814+
})
1815+
{
1816+
cb_prepare
1817+
.add_volume_mount(OPA_TLS_VOLUME_NAME, &tls_mount_path)
1818+
.context(AddVolumeMountSnafu)?;
18161819

1817-
let opa_tls_volume = VolumeBuilder::new(OPA_TLS_VOLUME_NAME)
1818-
.ephemeral(
1819-
SecretOperatorVolumeSourceBuilder::new(opa_tls_secret_class)
1820-
.build()
1821-
.context(TlsCertSecretClassVolumeBuildSnafu)?,
1822-
)
1823-
.build();
1820+
let opa_tls_volume = VolumeBuilder::new(OPA_TLS_VOLUME_NAME)
1821+
.ephemeral(
1822+
SecretOperatorVolumeSourceBuilder::new(tls_secret_class)
1823+
.build()
1824+
.context(TlsCertSecretClassVolumeBuildSnafu)?,
1825+
)
1826+
.build();
18241827

1825-
pod_builder
1826-
.add_volume(opa_tls_volume)
1827-
.context(AddVolumeSnafu)?;
1828-
}
1828+
pod_builder
1829+
.add_volume(opa_tls_volume)
1830+
.context(AddVolumeSnafu)?;
18291831
}
18301832

18311833
// fault tolerant execution S3 credentials and other resources

0 commit comments

Comments
 (0)