Skip to content

Commit 7da182f

Browse files
committed
refactor: move constants and use Port type
1 parent f000b9f commit 7da182f

7 files changed

Lines changed: 43 additions & 35 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
//!
33
//! `properties` renders the Trino `.properties` files; `resource` builds the individual
44
//! Kubernetes resources (ConfigMap, Service, Listener, PDB, …); `graceful_shutdown`
5-
//! contributes graceful-shutdown `config.properties` entries and Pod lifecycle configuration.
5+
//! contributes graceful-shutdown `config.properties` entries and Pod lifecycle configuration;
6+
//! `ports` derives the client-facing port from the validated TLS configuration.
67
78
pub mod graceful_shutdown;
9+
pub mod ports;
810
pub mod properties;
911
pub mod resource;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ pub fn add_graceful_shutdown_config(
125125
echo 'Successfully sent graceful shutdown command' >> /proc/1/fd/1 2>&1
126126
echo 'Sleeping {termination_grace_period_seconds} seconds' >> /proc/1/fd/1 2>&1
127127
sleep {termination_grace_period_seconds}",
128-
protocol = cluster.exposed_protocol(),
128+
protocol = super::ports::exposed_protocol(cluster),
129129
host = "127.0.0.1",
130-
port = cluster.exposed_port(),
130+
port = super::ports::exposed_port(cluster),
131131
),
132132
]),
133133
}),
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! The client-facing port Trino exposes, derived from the validated TLS configuration.
2+
//!
3+
//! Mapping the server-TLS flag onto a concrete port number / name is a resource-shaping decision,
4+
//! so it lives in the build step rather than on [`ValidatedCluster`].
5+
6+
use crate::{
7+
controller::ValidatedCluster,
8+
crd::{HTTP_PORT, HTTP_PORT_NAME, HTTPS_PORT, HTTPS_PORT_NAME},
9+
};
10+
11+
/// The client-facing port Trino exposes: HTTPS when server TLS is enabled, otherwise HTTP.
12+
pub(crate) fn exposed_port(cluster: &ValidatedCluster) -> u16 {
13+
if cluster.server_tls_enabled() {
14+
HTTPS_PORT
15+
} else {
16+
HTTP_PORT
17+
}
18+
}
19+
20+
/// The name of the client-facing port (see [`exposed_port`]).
21+
pub(crate) fn exposed_protocol(cluster: &ValidatedCluster) -> &'static str {
22+
if cluster.server_tls_enabled() {
23+
HTTPS_PORT_NAME
24+
} else {
25+
HTTP_PORT_NAME
26+
}
27+
}

rust/operator-binary/src/controller/build/resource/listener.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use stackable_operator::{
66
kvp::Labels,
77
};
88

9-
use crate::{controller::ValidatedCluster, crd::TrinoRole};
9+
use crate::{
10+
controller::{ValidatedCluster, build::ports},
11+
crd::TrinoRole,
12+
};
1013

1114
pub const LISTENER_VOLUME_NAME: &str = "listener";
1215
pub const LISTENER_VOLUME_DIR: &str = "/stackable/listener";
@@ -73,8 +76,8 @@ pub fn secret_volume_listener_scope(role: &TrinoRole) -> Option<String> {
7376

7477
/// We only use the http/https port here and intentionally omit the metrics one.
7578
fn listener_ports(cluster: &ValidatedCluster) -> Vec<ListenerPort> {
76-
let name = cluster.exposed_protocol().to_string();
77-
let port = cluster.exposed_port().into();
79+
let name = ports::exposed_protocol(cluster).to_string();
80+
let port = ports::exposed_port(cluster).into();
7881

7982
vec![ListenerPort {
8083
name,

rust/operator-binary/src/controller/build/resource/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use stackable_operator::{
66
};
77

88
use crate::{
9-
controller::ValidatedCluster,
9+
controller::{ValidatedCluster, build::ports},
1010
crd::{METRICS_PORT, METRICS_PORT_NAME, TrinoRole},
1111
};
1212

@@ -77,8 +77,8 @@ pub fn build_rolegroup_metrics_service(
7777
}
7878

7979
pub(crate) fn headless_service_ports(cluster: &ValidatedCluster) -> Vec<ServicePort> {
80-
let name = cluster.exposed_protocol().to_string();
81-
let port = cluster.exposed_port().into();
80+
let name = ports::exposed_protocol(cluster).to_string();
81+
let port = ports::exposed_port(cluster).into();
8282

8383
vec![ServicePort {
8484
name: Some(name),

rust/operator-binary/src/controller/build/resource/statefulset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ fn http_get_probe(cluster: &ValidatedCluster) -> HTTPGetAction {
582582
///
583583
/// This probe works on coordinators and workers.
584584
fn finished_starting_probe(cluster: &ValidatedCluster) -> ExecAction {
585-
let port = cluster.exposed_port();
585+
let port = build::ports::exposed_port(cluster);
586586
let schema = if cluster.server_tls_enabled() {
587587
"https"
588588
} else {

rust/operator-binary/src/controller/mod.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ use crate::{
3636
client_protocol::ResolvedClientProtocolConfig,
3737
fault_tolerant_execution::ResolvedFaultTolerantExecutionConfig,
3838
},
39-
crd::{
40-
APP_NAME, HTTP_PORT, HTTP_PORT_NAME, HTTPS_PORT, HTTPS_PORT_NAME, TrinoRole,
41-
discovery::TrinoPodRef, v1alpha1,
42-
},
39+
crd::{APP_NAME, TrinoRole, discovery::TrinoPodRef, v1alpha1},
4340
trino_controller::{CONTROLLER_NAME, OPERATOR_NAME},
4441
};
4542

@@ -193,27 +190,6 @@ impl ValidatedCluster {
193190
self.cluster_config.authentication_enabled() || self.server_tls_enabled()
194191
}
195192

196-
/// The client-facing port Trino exposes: HTTPS when server TLS is enabled, otherwise HTTP.
197-
///
198-
/// Replaces `v1alpha1::TrinoCluster::exposed_port`, derived here from the validated TLS config
199-
/// so build steps don't re-read the raw cluster.
200-
pub fn exposed_port(&self) -> u16 {
201-
if self.server_tls_enabled() {
202-
HTTPS_PORT
203-
} else {
204-
HTTP_PORT
205-
}
206-
}
207-
208-
/// The name of the client-facing port (see [`Self::exposed_port`]).
209-
pub fn exposed_protocol(&self) -> &'static str {
210-
if self.server_tls_enabled() {
211-
HTTPS_PORT_NAME
212-
} else {
213-
HTTP_PORT_NAME
214-
}
215-
}
216-
217193
/// Type-safe names for the resources of a given role group.
218194
pub(crate) fn resource_names(&self, role: &TrinoRole, role_group_name: &str) -> ResourceNames {
219195
ResourceNames {

0 commit comments

Comments
 (0)