Skip to content

Commit a3212bb

Browse files
committed
history: move listenerclass to role config
1 parent c16d0e5 commit a3212bb

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

deploy/helm/spark-k8s-operator/crds/crds.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,9 +1379,6 @@ spec:
13791379
cleaner:
13801380
nullable: true
13811381
type: boolean
1382-
listenerClass:
1383-
nullable: true
1384-
type: string
13851382
logging:
13861383
default:
13871384
containers: {}
@@ -1556,11 +1553,16 @@ spec:
15561553
x-kubernetes-preserve-unknown-fields: true
15571554
roleConfig:
15581555
default:
1556+
listenerClass: cluster-internal
15591557
podDisruptionBudget:
15601558
enabled: true
15611559
maxUnavailable: null
15621560
description: This is a product-agnostic RoleConfig, which is sufficient for most of the products.
15631561
properties:
1562+
listenerClass:
1563+
default: cluster-internal
1564+
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose the history server.
1565+
type: string
15641566
podDisruptionBudget:
15651567
default:
15661568
enabled: true
@@ -1628,9 +1630,6 @@ spec:
16281630
cleaner:
16291631
nullable: true
16301632
type: boolean
1631-
listenerClass:
1632-
nullable: true
1633-
type: string
16341633
logging:
16351634
default:
16361635
containers: {}

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

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ use stackable_operator::{
3232
use strum::{Display, EnumIter};
3333

3434
use crate::{
35-
crd::{affinity::history_affinity, constants::*, logdir::ResolvedLogDir},
35+
crd::{
36+
affinity::history_affinity, constants::*, history::v1alpha1::SparkHistoryServerRoleConfig,
37+
logdir::ResolvedLogDir,
38+
},
3639
history::config::jvm::construct_history_jvm_args,
3740
};
3841

@@ -62,7 +65,6 @@ pub enum Error {
6265

6366
#[versioned(version(name = "v1alpha1"))]
6467
pub mod versioned {
65-
6668
/// A Spark cluster history server component. This resource is managed by the Stackable operator
6769
/// for Apache Spark. Find more information on how to use it in the
6870
/// [operator documentation](DOCS_BASE_URL_PLACEHOLDER/spark-k8s/usage-guide/history-server).
@@ -85,6 +87,7 @@ pub mod versioned {
8587
///
8688
/// This was previously used to hold the listener configuration, which has since moved
8789
/// to the role configuration.
90+
// TODO: remove?
8891
#[serde(default)]
8992
pub cluster_config: v1alpha1::SparkHistoryServerClusterConfig,
9093

@@ -101,17 +104,32 @@ pub mod versioned {
101104
pub spark_conf: BTreeMap<String, String>,
102105

103106
/// A history server node role definition.
104-
pub nodes: Role<HistoryConfigFragment, GenericRoleConfig, JavaCommonConfig>,
107+
pub nodes: Role<HistoryConfigFragment, SparkHistoryServerRoleConfig, JavaCommonConfig>,
105108
}
106109

107110
#[derive(Clone, Deserialize, Debug, Default, Eq, JsonSchema, PartialEq, Serialize)]
108111
#[serde(rename_all = "camelCase")]
109112
pub struct SparkHistoryServerClusterConfig {}
113+
114+
// TODO: move generic version to op-rs?
115+
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
116+
#[serde(rename_all = "camelCase")]
117+
pub struct SparkHistoryServerRoleConfig {
118+
#[serde(flatten)]
119+
pub common: GenericRoleConfig,
120+
121+
/// This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html)
122+
/// is used to expose the history server.
123+
#[serde(default = "default_listener_class")]
124+
pub listener_class: String,
125+
}
110126
}
111127

112128
impl v1alpha1::SparkHistoryServer {
113129
/// Returns a reference to the role. Raises an error if the role is not defined.
114-
pub fn role(&self) -> &Role<HistoryConfigFragment, GenericRoleConfig, JavaCommonConfig> {
130+
pub fn role(
131+
&self,
132+
) -> &Role<HistoryConfigFragment, SparkHistoryServerRoleConfig, JavaCommonConfig> {
115133
&self.spec.nodes
116134
}
117135

@@ -130,6 +148,11 @@ impl v1alpha1::SparkHistoryServer {
130148
.cloned()
131149
}
132150

151+
/// Return the listener class of the role config.
152+
pub fn node_listener_class(&self) -> &str {
153+
self.spec.nodes.role_config.listener_class.as_str()
154+
}
155+
133156
pub fn merged_config(
134157
&self,
135158
rolegroup_ref: &RoleGroupRef<Self>,
@@ -188,7 +211,7 @@ impl v1alpha1::SparkHistoryServer {
188211
String,
189212
(
190213
Vec<PropertyNameKind>,
191-
Role<HistoryConfigFragment, GenericRoleConfig, JavaCommonConfig>,
214+
Role<HistoryConfigFragment, SparkHistoryServerRoleConfig, JavaCommonConfig>,
192215
),
193216
> = vec![(
194217
HISTORY_ROLE_NAME.to_string(),
@@ -340,9 +363,6 @@ pub struct HistoryConfig {
340363
/// This can be shortened by the `maxCertificateLifetime` setting on the SecretClass issuing the TLS certificate.
341364
#[fragment_attrs(serde(default))]
342365
pub requested_secret_lifetime: Option<Duration>,
343-
344-
#[serde(default)]
345-
pub listener_class: String,
346366
}
347367

348368
impl HistoryConfig {
@@ -366,7 +386,6 @@ impl HistoryConfig {
366386
logging: product_logging::spec::default_logging(),
367387
affinity: history_affinity(cluster_name),
368388
requested_secret_lifetime: Some(Self::DEFAULT_HISTORY_SECRET_LIFETIME),
369-
listener_class: Some(default_listener_class()),
370389
}
371390
}
372391
}
@@ -403,6 +422,15 @@ impl Configuration for HistoryConfigFragment {
403422
}
404423
}
405424

425+
impl Default for v1alpha1::SparkHistoryServerRoleConfig {
426+
fn default() -> Self {
427+
v1alpha1::SparkHistoryServerRoleConfig {
428+
listener_class: default_listener_class(),
429+
common: Default::default(),
430+
}
431+
}
432+
}
433+
406434
fn default_listener_class() -> String {
407435
"cluster-internal".to_owned()
408436
}

rust/operator-binary/src/history/config/jvm.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use snafu::{ResultExt, Snafu};
2-
use stackable_operator::role_utils::{
3-
self, GenericRoleConfig, JavaCommonConfig, JvmArgumentOverrides, Role,
4-
};
2+
use stackable_operator::role_utils::{self, JavaCommonConfig, JvmArgumentOverrides, Role};
53

64
use crate::crd::{
75
constants::{
86
JVM_SECURITY_PROPERTIES_FILE, LOG4J2_CONFIG_FILE, METRICS_PORT,
97
STACKABLE_TLS_STORE_PASSWORD, STACKABLE_TRUST_STORE, VOLUME_MOUNT_PATH_CONFIG,
108
VOLUME_MOUNT_PATH_LOG_CONFIG,
119
},
12-
history::HistoryConfigFragment,
10+
history::{HistoryConfigFragment, v1alpha1::SparkHistoryServerRoleConfig},
1311
logdir::ResolvedLogDir,
1412
};
1513

@@ -21,7 +19,7 @@ pub enum Error {
2119

2220
/// JVM arguments that go into `SPARK_HISTORY_OPTS`
2321
pub fn construct_history_jvm_args(
24-
role: &Role<HistoryConfigFragment, GenericRoleConfig, JavaCommonConfig>,
22+
role: &Role<HistoryConfigFragment, SparkHistoryServerRoleConfig, JavaCommonConfig>,
2523
role_group: &str,
2624
logdir: &ResolvedLogDir,
2725
) -> Result<String, Error> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub async fn reconcile(
333333
shs,
334334
&resolved_product_image,
335335
&rgr,
336-
merged_config.listener_class.to_string(),
336+
shs.node_listener_class().to_string(),
337337
)?;
338338
cluster_resources
339339
.add(client, rg_group_listener)
@@ -343,7 +343,7 @@ pub async fn reconcile(
343343

344344
let role_config = &shs.spec.nodes.role_config;
345345
add_pdbs(
346-
&role_config.pod_disruption_budget,
346+
&role_config.common.pod_disruption_budget,
347347
shs,
348348
client,
349349
&mut cluster_resources,

0 commit comments

Comments
 (0)