Skip to content

Commit fcd5d3a

Browse files
committed
history: refactor to use listener::build_listener
1 parent 8b3ef2e commit fcd5d3a

File tree

3 files changed

+27
-44
lines changed

3 files changed

+27
-44
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,6 @@ pub mod versioned {
107107
}
108108

109109
impl v1alpha1::SparkHistoryServer {
110-
/// The name of the group-listener provided for a specific role-group.
111-
/// History servers will use this group listener so that only one load balancer
112-
/// is needed (per role group).
113-
pub fn group_listener_name(&self, rolegroup: &RoleGroupRef<Self>) -> String {
114-
format!("{}-group", rolegroup.object_name())
115-
}
116-
117110
/// Returns a reference to the role. Raises an error if the role is not defined.
118111
pub fn role(&self) -> &Role<HistoryConfigFragment, GenericRoleConfig, JavaCommonConfig> {
119112
&self.spec.nodes

rust/operator-binary/src/history/history_controller.rs

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use stackable_operator::{
2222
},
2323
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
2424
commons::{
25-
listener::{Listener, ListenerPort, ListenerSpec},
25+
listener::{Listener, ListenerPort},
2626
product_image_selection::ResolvedProductImage,
2727
},
2828
k8s_openapi::{
@@ -66,6 +66,7 @@ use crate::{
6666
VOLUME_MOUNT_PATH_LOG, VOLUME_MOUNT_PATH_LOG_CONFIG,
6767
},
6868
history::{self, HistoryConfig, SparkHistoryServerContainer, v1alpha1},
69+
listener,
6970
logdir::ResolvedLogDir,
7071
tlscerts, to_spark_env_sh_string,
7172
},
@@ -82,6 +83,9 @@ pub enum Error {
8283
source: stackable_operator::builder::meta::Error,
8384
},
8485

86+
#[snafu(display("failed to build spark history group listener"))]
87+
BuildListener { source: crate::crd::listener::Error },
88+
8589
#[snafu(display("failed to build listener volume"))]
8690
BuildListenerVolume {
8791
source: ListenerOperatorVolumeSourceBuilderError,
@@ -363,41 +367,27 @@ fn build_group_listener(
363367
rolegroup: &RoleGroupRef<v1alpha1::SparkHistoryServer>,
364368
listener_class: String,
365369
) -> Result<Listener, Error> {
366-
Ok(Listener {
367-
metadata: ObjectMetaBuilder::new()
368-
.name_and_namespace(shs)
369-
.name(shs.group_listener_name(rolegroup))
370-
.ownerreference_from_resource(shs, None, Some(true))
371-
.context(ObjectMissingMetadataForOwnerRefSnafu)?
372-
.with_recommended_labels(labels(
373-
shs,
374-
&resolved_product_image.app_version_label,
375-
&rolegroup.role_group,
376-
))
377-
.context(ObjectMetaSnafu)?
378-
.build(),
379-
spec: ListenerSpec {
380-
class_name: Some(listener_class),
381-
ports: Some(listener_ports()),
382-
..ListenerSpec::default()
383-
},
384-
status: None,
385-
})
386-
}
370+
let listener_name = rolegroup.object_name();
371+
let recommended_object_labels = labels(
372+
shs,
373+
&resolved_product_image.app_version_label,
374+
&rolegroup.role_group,
375+
);
387376

388-
fn listener_ports() -> Vec<ListenerPort> {
389-
vec![
390-
ListenerPort {
391-
name: "metrics".to_string(),
392-
port: METRICS_PORT.into(),
393-
protocol: Some("TCP".to_string()),
394-
},
395-
ListenerPort {
396-
name: "http".to_string(),
397-
port: HISTORY_UI_PORT.into(),
398-
protocol: Some("TCP".to_string()),
399-
},
400-
]
377+
let listener_ports = [ListenerPort {
378+
name: "http".to_string(),
379+
port: HISTORY_UI_PORT.into(),
380+
protocol: Some("TCP".to_string()),
381+
}];
382+
383+
listener::build_listener(
384+
shs,
385+
&listener_name,
386+
&listener_class,
387+
recommended_object_labels,
388+
&listener_ports,
389+
)
390+
.context(BuildListenerSnafu)
401391
}
402392

403393
pub fn error_policy(
@@ -607,7 +597,7 @@ fn build_stateful_set(
607597
// cluster-internal) as the address should still be consistent.
608598
let volume_claim_templates = Some(vec![
609599
ListenerOperatorVolumeSourceBuilder::new(
610-
&ListenerReference::ListenerName(shs.group_listener_name(rolegroupref)),
600+
&ListenerReference::ListenerName(rolegroupref.object_name()),
611601
&recommended_labels,
612602
)
613603
.context(BuildListenerVolumeSnafu)?

tests/templates/kuttl/spark-history-server/20-test-logs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ spec:
1616
"bash",
1717
"-x",
1818
"-c",
19-
"test 2 == $(curl http://spark-history-node-default-group:18080/api/v1/applications | jq length)",
19+
"test 2 == $(curl http://spark-history-node-default:18080/api/v1/applications | jq length)",
2020
]

0 commit comments

Comments
 (0)