Skip to content

Commit fd8e931

Browse files
committed
Support specifying Service type (#228)
# Description For stackabletech/issues#360
1 parent bd19c4a commit fd8e931

File tree

9 files changed

+88
-11
lines changed

9 files changed

+88
-11
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ All notable changes to this project will be documented in this file.
77
### Added
88

99
- Deploy default and support custom affinities ([#217])
10-
- BREAKING: Dropped support for old spec.{driver,executor}.nodeSelector field. Use spec.{driver,executor}.affinity.nodeSelector instead ([#217])
1110
- Log aggregation added ([#226]).
1211

1312
### Changed
1413

14+
- [BREAKING] Support specifying Service type for HistoryServer.
15+
This enables us to later switch non-breaking to using `ListenerClasses` for the exposure of Services.
16+
This change is breaking, because - for security reasons - we default to the `cluster-internal` `ListenerClass`.
17+
If you need your cluster to be accessible from outside of Kubernetes you need to set `clusterConfig.listenerClass`
18+
to `external-unstable` or `external-stable` ([#228]).
19+
- [BREAKING]: Dropped support for old `spec.{driver,executor}.nodeSelector` field. Use `spec.{driver,executor}.affinity.nodeSelector` instead ([#217])
1520
- Revert openshift settings ([#207])
1621
- BUGFIX: assign service account to history pods ([#207])
1722
- Merging and validation of the configuration refactored ([#223])
@@ -21,6 +26,7 @@ All notable changes to this project will be documented in this file.
2126
[#217]: https://github.com/stackabletech/spark-k8s-operator/pull/217
2227
[#223]: https://github.com/stackabletech/spark-k8s-operator/pull/223
2328
[#226]: https://github.com/stackabletech/spark-k8s-operator/pull/226
29+
[#228]: https://github.com/stackabletech/spark-k8s-operator/pull/228
2430

2531
## [23.1.0] - 2023-01-23
2632

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,6 +2933,27 @@ spec:
29332933
properties:
29342934
spec:
29352935
properties:
2936+
clusterConfig:
2937+
default:
2938+
listenerClass: cluster-internal
2939+
description: Global Spark history server configuration that applies to all roles and role groups
2940+
properties:
2941+
listenerClass:
2942+
default: cluster-internal
2943+
description: |-
2944+
In the future this setting will control, which ListenerClass <https://docs.stackable.tech/home/stable/listener-operator/listenerclass.html> will be used to expose the service. Currently only a subset of the ListenerClasses are supported by choosing the type of the created Services by looking at the ListenerClass name specified, In a future release support for custom ListenerClasses will be introduced without a breaking change:
2945+
2946+
* cluster-internal: Use a ClusterIP service
2947+
2948+
* external-unstable: Use a NodePort service
2949+
2950+
* external-stable: Use a LoadBalancer service
2951+
enum:
2952+
- cluster-internal
2953+
- external-unstable
2954+
- external-stable
2955+
type: string
2956+
type: object
29362957
image:
29372958
anyOf:
29382959
- required:

docs/modules/spark-k8s/examples/example-history-server.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
sparkConf: # <4>
2424
nodes:
2525
roleGroups:
26-
cleaner:
26+
default:
2727
replicas: 1 # <5>
2828
config:
2929
cleaner: true # <6>

rust/crd/src/affinity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mod test {
5656
reference: spark-history-s3-bucket
5757
nodes:
5858
roleGroups:
59-
cleaner:
59+
default:
6060
replicas: 1
6161
config:
6262
cleaner: true
@@ -102,7 +102,7 @@ mod test {
102102
let rolegroup_ref = RoleGroupRef {
103103
cluster: ObjectRef::from_obj(&history),
104104
role: HISTORY_ROLE_NAME.to_string(),
105-
role_group: "cleaner".to_string(),
105+
role_group: "default".to_string(),
106106
};
107107

108108
let affinity = history.merged_config(&rolegroup_ref).unwrap().affinity;

rust/crd/src/history.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ pub enum Error {
6363
#[serde(rename_all = "camelCase")]
6464
pub struct SparkHistoryServerSpec {
6565
pub image: ProductImage,
66+
/// Global Spark history server configuration that applies to all roles and role groups
67+
#[serde(default)]
68+
pub cluster_config: SparkHistoryServerClusterConfig,
6669
/// Name of the Vector aggregator discovery ConfigMap.
6770
/// It must contain the key `ADDRESS` with the address of the Vector aggregator.
6871
#[serde(skip_serializing_if = "Option::is_none")]
@@ -73,6 +76,47 @@ pub struct SparkHistoryServerSpec {
7376
pub nodes: Role<HistoryConfigFragment>,
7477
}
7578

79+
#[derive(Clone, Deserialize, Debug, Default, Eq, JsonSchema, PartialEq, Serialize)]
80+
#[serde(rename_all = "camelCase")]
81+
pub struct SparkHistoryServerClusterConfig {
82+
/// In the future this setting will control, which ListenerClass <https://docs.stackable.tech/home/stable/listener-operator/listenerclass.html>
83+
/// will be used to expose the service.
84+
/// Currently only a subset of the ListenerClasses are supported by choosing the type of the created Services
85+
/// by looking at the ListenerClass name specified,
86+
/// In a future release support for custom ListenerClasses will be introduced without a breaking change:
87+
///
88+
/// * cluster-internal: Use a ClusterIP service
89+
///
90+
/// * external-unstable: Use a NodePort service
91+
///
92+
/// * external-stable: Use a LoadBalancer service
93+
#[serde(default)]
94+
pub listener_class: CurrentlySupportedListenerClasses,
95+
}
96+
97+
// TODO: Temporary solution until listener-operator is finished
98+
#[derive(Clone, Debug, Default, Display, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
99+
#[serde(rename_all = "PascalCase")]
100+
pub enum CurrentlySupportedListenerClasses {
101+
#[default]
102+
#[serde(rename = "cluster-internal")]
103+
ClusterInternal,
104+
#[serde(rename = "external-unstable")]
105+
ExternalUnstable,
106+
#[serde(rename = "external-stable")]
107+
ExternalStable,
108+
}
109+
110+
impl CurrentlySupportedListenerClasses {
111+
pub fn k8s_service_type(&self) -> String {
112+
match self {
113+
CurrentlySupportedListenerClasses::ClusterInternal => "ClusterIP".to_string(),
114+
CurrentlySupportedListenerClasses::ExternalUnstable => "NodePort".to_string(),
115+
CurrentlySupportedListenerClasses::ExternalStable => "LoadBalancer".to_string(),
116+
}
117+
}
118+
}
119+
76120
impl SparkHistoryServer {
77121
pub fn merged_config(
78122
&self,

rust/operator-binary/src/history_controller.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,16 @@ fn build_service(
430430
None => "global".to_owned(),
431431
};
432432

433-
let (service_name, service_type) = match group {
434-
Some(rgr) => (rgr.object_name(), "ClusterIP".to_string()),
433+
let (service_name, service_type, service_cluster_ip) = match group {
434+
Some(rgr) => (
435+
rgr.object_name(),
436+
"ClusterIP".to_string(),
437+
Some("None".to_string()),
438+
),
435439
None => (
436440
format!("{}-{}", shs.metadata.name.as_ref().unwrap(), role),
437-
"NodePort".to_string(),
441+
shs.spec.cluster_config.listener_class.k8s_service_type(),
442+
None,
438443
),
439444
};
440445

@@ -452,13 +457,14 @@ fn build_service(
452457
.with_recommended_labels(labels(shs, app_version_label, &group_name))
453458
.build(),
454459
spec: Some(ServiceSpec {
460+
type_: Some(service_type),
461+
cluster_ip: service_cluster_ip,
455462
ports: Some(vec![ServicePort {
456463
name: Some(String::from("http")),
457464
port: 18080,
458465
..ServicePort::default()
459466
}]),
460467
selector: Some(selector),
461-
type_: Some(service_type),
462468
..ServiceSpec::default()
463469
}),
464470
status: None,

tests/templates/kuttl/spark-history-server/06-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ timeout: 900
66
apiVersion: apps/v1
77
kind: StatefulSet
88
metadata:
9-
name: spark-history-node-cleaner
9+
name: spark-history-node-default
1010
status:
1111
readyReplicas: 1

tests/templates/kuttl/spark-history-server/06-deploy-history-server.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ spec:
2222
logging:
2323
enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }}
2424
roleGroups:
25-
cleaner:
25+
default:
2626
replicas: 1
2727
config:
2828
cleaner: true

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-cleaner: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)