Skip to content

Commit 0c24393

Browse files
committed
use role level listener
1 parent fcc2286 commit 0c24393

7 files changed

Lines changed: 91 additions & 144 deletions

File tree

deploy/helm/trino-operator/crds/crds.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ spec:
190190
description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details.
191191
nullable: true
192192
type: string
193-
listenerClass:
194-
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose the coordinator.
195-
nullable: true
196-
type: string
197193
logging:
198194
default:
199195
containers: {}
@@ -423,11 +419,15 @@ spec:
423419
x-kubernetes-preserve-unknown-fields: true
424420
roleConfig:
425421
default:
422+
listenerClass: cluster-internal
426423
podDisruptionBudget:
427424
enabled: true
428425
maxUnavailable: null
429426
description: This is a product-agnostic RoleConfig, which is sufficient for most of the products.
430427
properties:
428+
listenerClass:
429+
default: cluster-internal
430+
type: string
431431
podDisruptionBudget:
432432
default:
433433
enabled: true
@@ -496,10 +496,6 @@ spec:
496496
description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details.
497497
nullable: true
498498
type: string
499-
listenerClass:
500-
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose the coordinator.
501-
nullable: true
502-
type: string
503499
logging:
504500
default:
505501
containers: {}

rust/operator-binary/src/controller.rs

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ use crate::{
9292
},
9393
listener::{
9494
LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME, build_group_listener, build_group_listener_pvc,
95-
group_listener_name, merged_listener_class,
95+
group_listener_name,
9696
},
9797
operations::{
9898
add_graceful_shutdown_config, graceful_shutdown_config_properties, pdb::add_pdbs,
@@ -543,34 +543,26 @@ pub async fn reconcile_trino(
543543
rolegroup: role_group_ref.clone(),
544544
})?,
545545
);
546+
}
546547

547-
if let Some(listener_class) =
548-
merged_listener_class(trino, &trino_role, &role_group_ref.role_group)
549-
{
550-
if let Some(listener_group_name) = group_listener_name(&trino_role, &role_group_ref)
551-
{
552-
let role_group_listener = build_group_listener(
553-
trino,
554-
build_recommended_labels(
555-
trino,
556-
CONTROLLER_NAME,
557-
&role_group_ref.role,
558-
&role_group_ref.role_group,
559-
),
560-
listener_class.to_string(),
561-
listener_group_name,
562-
)
563-
.context(ListenerConfigurationSnafu)?;
548+
if let Some(listener_class) = trino_role.listener_class_name(trino) {
549+
if let Some(listener_group_name) = group_listener_name(trino, &trino_role) {
550+
let role_group_listener = build_group_listener(
551+
trino,
552+
build_recommended_labels(trino, CONTROLLER_NAME, &trino_role_str, "none"),
553+
listener_class.to_string(),
554+
listener_group_name,
555+
)
556+
.context(ListenerConfigurationSnafu)?;
564557

565-
cluster_resources
566-
.add(client, role_group_listener)
567-
.await
568-
.context(ApplyGroupListenerSnafu)?;
569-
}
558+
cluster_resources
559+
.add(client, role_group_listener)
560+
.await
561+
.context(ApplyGroupListenerSnafu)?;
570562
}
571563
}
572564

573-
let role_config = trino.role_config(&trino_role);
565+
let role_config = trino.generic_role_config(&trino_role);
574566
if let Some(GenericRoleConfig {
575567
pod_disruption_budget: pdb,
576568
}) = role_config
@@ -998,7 +990,7 @@ fn build_rolegroup_statefulset(
998990
.build_pvc("data", Some(vec!["ReadWriteOnce"])),
999991
];
1000992
// Add listener
1001-
if let Some(group_listener_name) = group_listener_name(trino_role, role_group_ref) {
993+
if let Some(group_listener_name) = group_listener_name(trino, trino_role) {
1002994
cb_trino
1003995
.add_volume_mount(LISTENER_VOLUME_NAME, LISTENER_VOLUME_DIR)
1004996
.context(AddVolumeMountSnafu)?;
@@ -1009,7 +1001,7 @@ fn build_rolegroup_statefulset(
10091001
// A version value is required, and we do want to use the "recommended" format for the other desired labels
10101002
"none",
10111003
&role_group_ref.role,
1012-
&role_group_ref.role_group,
1004+
"none",
10131005
))
10141006
.context(LabelBuildSnafu)?;
10151007

@@ -1196,7 +1188,7 @@ fn build_rolegroup_statefulset(
11961188
),
11971189
..LabelSelector::default()
11981190
},
1199-
service_name: Some(v1alpha1::TrinoCluster::rolegroup_headless_service_name(
1191+
service_name: Some(v1alpha1::TrinoCluster::rolegroup_metrics_service_name(
12001192
&role_group_ref.object_name(),
12011193
)),
12021194
template: pod_template,
@@ -1218,7 +1210,7 @@ fn build_rolegroup_service(
12181210
Ok(Service {
12191211
metadata: ObjectMetaBuilder::new()
12201212
.name_and_namespace(trino)
1221-
.name(v1alpha1::TrinoCluster::rolegroup_headless_service_name(
1213+
.name(v1alpha1::TrinoCluster::rolegroup_metrics_service_name(
12221214
&role_group_ref.object_name(),
12231215
))
12241216
.ownerreference_from_resource(trino, None, Some(true))
@@ -1236,7 +1228,7 @@ fn build_rolegroup_service(
12361228
// Internal communication does not need to be exposed
12371229
type_: Some("ClusterIP".to_string()),
12381230
cluster_ip: Some("None".to_string()),
1239-
ports: Some(service_ports(trino)),
1231+
ports: Some(service_ports()),
12401232
selector: Some(
12411233
Labels::role_group_selector(
12421234
trino,
@@ -1412,33 +1404,13 @@ fn get_random_base64() -> String {
14121404
openssl::base64::encode_block(&buf)
14131405
}
14141406

1415-
fn service_ports(trino: &v1alpha1::TrinoCluster) -> Vec<ServicePort> {
1416-
let mut ports = vec![ServicePort {
1407+
fn service_ports() -> Vec<ServicePort> {
1408+
vec![ServicePort {
14171409
name: Some(METRICS_PORT_NAME.to_string()),
14181410
port: METRICS_PORT.into(),
14191411
protocol: Some("TCP".to_string()),
14201412
..ServicePort::default()
1421-
}];
1422-
1423-
if trino.expose_http_port() {
1424-
ports.push(ServicePort {
1425-
name: Some(HTTP_PORT_NAME.to_string()),
1426-
port: HTTP_PORT.into(),
1427-
protocol: Some("TCP".to_string()),
1428-
..ServicePort::default()
1429-
});
1430-
}
1431-
1432-
if trino.expose_https_port() {
1433-
ports.push(ServicePort {
1434-
name: Some(HTTPS_PORT_NAME.to_string()),
1435-
port: HTTPS_PORT.into(),
1436-
protocol: Some("TCP".to_string()),
1437-
..ServicePort::default()
1438-
});
1439-
}
1440-
1441-
ports
1413+
}]
14421414
}
14431415

14441416
fn container_ports(trino: &v1alpha1::TrinoCluster) -> Vec<ContainerPort> {

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

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ use stackable_operator::{
3939
versioned::versioned,
4040
};
4141
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
42-
use v1alpha1::{TrinoConfigFragment, TrinoCoordinatorConfigFragment};
42+
use v1alpha1::TrinoConfigFragment;
4343

44-
use crate::crd::discovery::TrinoPodRef;
44+
use crate::crd::{discovery::TrinoPodRef, v1alpha1::TrinoCoordinatorRoleConfig};
4545

4646
pub const APP_NAME: &str = "trino";
4747
// ports
@@ -117,10 +117,8 @@ pub const MAX_TRINO_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
117117
value: 10.0,
118118
unit: BinaryMultiple::Mebi,
119119
};
120-
// Headless service suffix
121-
// TODO(malte): Imho this should be "headless". Its metrics for consistency for now.
122-
// See: https://github.com/stackabletech/decisions/issues/54
123-
pub const HEADLESS_SERVICE_SUFFIX: &str = "metrics";
120+
121+
pub const METRICS_SERVICE_SUFFIX: &str = "metrics";
124122

125123
pub const JVM_HEAP_FACTOR: f32 = 0.8;
126124

@@ -197,13 +195,24 @@ pub mod versioned {
197195
// no doc - it's in the struct.
198196
#[serde(default, skip_serializing_if = "Option::is_none")]
199197
pub coordinators:
200-
Option<Role<TrinoCoordinatorConfigFragment, GenericRoleConfig, JavaCommonConfig>>,
198+
Option<Role<TrinoConfigFragment, TrinoCoordinatorRoleConfig, JavaCommonConfig>>,
201199

202200
// no doc - it's in the struct.
203201
#[serde(default, skip_serializing_if = "Option::is_none")]
204202
pub workers: Option<Role<TrinoConfigFragment, GenericRoleConfig, JavaCommonConfig>>,
205203
}
206204

205+
// TODO: move generic version to op-rs?
206+
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
207+
#[serde(rename_all = "camelCase")]
208+
pub struct TrinoCoordinatorRoleConfig {
209+
#[serde(flatten)]
210+
pub common: GenericRoleConfig,
211+
212+
#[serde(default = "coordinator_default_listener_class")]
213+
pub listener_class: String,
214+
}
215+
207216
#[derive(Clone, Debug, Default, Fragment, JsonSchema, PartialEq)]
208217
#[fragment_attrs(
209218
derive(
@@ -242,29 +251,6 @@ pub mod versioned {
242251
pub requested_secret_lifetime: Option<Duration>,
243252
}
244253

245-
#[derive(Clone, Debug, Default, Fragment, JsonSchema, PartialEq)]
246-
#[fragment_attrs(
247-
derive(
248-
Clone,
249-
Debug,
250-
Default,
251-
Deserialize,
252-
Merge,
253-
JsonSchema,
254-
PartialEq,
255-
Serialize
256-
),
257-
serde(rename_all = "camelCase")
258-
)]
259-
pub struct TrinoCoordinatorConfig {
260-
#[fragment_attrs(serde(default, flatten))]
261-
pub trino_config: TrinoConfig,
262-
263-
/// This field controls which [ListenerClass](DOCS_BASE_URL_PLACEHOLDER/listener-operator/listenerclass.html) is used to expose the coordinator.
264-
#[serde(default)]
265-
pub listener_class: String,
266-
}
267-
268254
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
269255
#[serde(rename_all = "camelCase")]
270256
pub struct TrinoClusterConfig {
@@ -352,6 +338,19 @@ pub mod versioned {
352338
}
353339
}
354340

341+
impl Default for v1alpha1::TrinoCoordinatorRoleConfig {
342+
fn default() -> Self {
343+
v1alpha1::TrinoCoordinatorRoleConfig {
344+
listener_class: coordinator_default_listener_class(),
345+
common: Default::default(),
346+
}
347+
}
348+
}
349+
350+
fn coordinator_default_listener_class() -> String {
351+
"cluster-internal".to_string()
352+
}
353+
355354
impl Default for v1alpha1::TrinoTls {
356355
fn default() -> Self {
357356
v1alpha1::TrinoTls {
@@ -415,6 +414,17 @@ impl TrinoRole {
415414
}
416415
roles
417416
}
417+
418+
pub fn listener_class_name(&self, trino: &v1alpha1::TrinoCluster) -> Option<String> {
419+
match self {
420+
Self::Coordinator => trino
421+
.spec
422+
.coordinators
423+
.to_owned()
424+
.map(|coordinator| coordinator.role_config.listener_class),
425+
Self::Worker => None,
426+
}
427+
}
418428
}
419429

420430
#[derive(
@@ -764,9 +774,13 @@ impl v1alpha1::TrinoCluster {
764774
})
765775
}
766776

767-
pub fn role_config(&self, role: &TrinoRole) -> Option<&GenericRoleConfig> {
777+
pub fn generic_role_config(&self, role: &TrinoRole) -> Option<&GenericRoleConfig> {
768778
match role {
769-
TrinoRole::Coordinator => self.spec.coordinators.as_ref().map(|c| &c.role_config),
779+
TrinoRole::Coordinator => self
780+
.spec
781+
.coordinators
782+
.as_ref()
783+
.map(|c| &c.role_config.common),
770784
TrinoRole::Worker => self.spec.workers.as_ref().map(|w| &w.role_config),
771785
}
772786
}
@@ -822,7 +836,7 @@ impl v1alpha1::TrinoCluster {
822836
let ns = ns.clone();
823837
(0..rolegroup.replicas.unwrap_or(0)).map(move |i| TrinoPodRef {
824838
namespace: ns.clone(),
825-
role_group_service_name: Self::rolegroup_headless_service_name(
839+
role_group_service_name: Self::rolegroup_metrics_service_name(
826840
&role_group_ref.object_name(),
827841
),
828842
pod_name: format!("{}-{}", role_group_ref.object_name(), i),
@@ -831,8 +845,8 @@ impl v1alpha1::TrinoCluster {
831845
}
832846

833847
/// Returns the headless rolegroup service name `simple-trino-coordinator-default-<HEADLESS_SERVICE_SUFFIX>`.
834-
pub fn rolegroup_headless_service_name(role_group_ref_object_name: &str) -> String {
835-
format!("{}-{}", role_group_ref_object_name, HEADLESS_SERVICE_SUFFIX)
848+
pub fn rolegroup_metrics_service_name(role_group_ref_object_name: &str) -> String {
849+
format!("{}-{}", role_group_ref_object_name, METRICS_SERVICE_SUFFIX)
836850
}
837851

838852
/// Returns user provided authentication settings
@@ -928,18 +942,18 @@ impl v1alpha1::TrinoCluster {
928942
}
929943

930944
fn extract_role_from_coordinator_config(
931-
fragment: Role<TrinoCoordinatorConfigFragment, GenericRoleConfig, JavaCommonConfig>,
945+
fragment: Role<TrinoConfigFragment, TrinoCoordinatorRoleConfig, JavaCommonConfig>,
932946
) -> Role<TrinoConfigFragment, GenericRoleConfig, JavaCommonConfig> {
933947
Role {
934948
config: CommonConfiguration {
935-
config: fragment.config.config.trino_config,
949+
config: fragment.config.config,
936950
config_overrides: fragment.config.config_overrides,
937951
env_overrides: fragment.config.env_overrides,
938952
cli_overrides: fragment.config.cli_overrides,
939953
pod_overrides: fragment.config.pod_overrides,
940954
product_specific_common_config: fragment.config.product_specific_common_config,
941955
},
942-
role_config: fragment.role_config,
956+
role_config: fragment.role_config.common,
943957
role_groups: fragment
944958
.role_groups
945959
.into_iter()
@@ -948,7 +962,7 @@ fn extract_role_from_coordinator_config(
948962
k,
949963
RoleGroup {
950964
config: CommonConfiguration {
951-
config: v.config.config.trino_config,
965+
config: v.config.config,
952966
config_overrides: v.config.config_overrides,
953967
env_overrides: v.config.env_overrides,
954968
cli_overrides: v.config.cli_overrides,

0 commit comments

Comments
 (0)