Skip to content

Commit 707fc8f

Browse files
committed
recfactor: OPA tls mount helper method
1 parent 2f9083c commit 707fc8f

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
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: 29 additions & 25 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,32 @@ 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}");
18121807

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

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();
1822+
let opa_tls_volume = VolumeBuilder::new(OPA_TLS_VOLUME_NAME)
1823+
.ephemeral(
1824+
SecretOperatorVolumeSourceBuilder::new(tls_secret_class)
1825+
.build()
1826+
.context(TlsCertSecretClassVolumeBuildSnafu)?,
1827+
)
1828+
.build();
18241829

1825-
pod_builder
1826-
.add_volume(opa_tls_volume)
1827-
.context(AddVolumeSnafu)?;
1828-
}
1830+
pod_builder
1831+
.add_volume(opa_tls_volume)
1832+
.context(AddVolumeSnafu)?;
18291833
}
18301834

18311835
// fault tolerant execution S3 credentials and other resources

0 commit comments

Comments
 (0)