Skip to content

Commit f415bad

Browse files
razvansbernauer
andauthored
fix: history and connect object labels (#573)
* fix: watch StatefulSets instead of Deployments * use label app.kubernetes.io/name=spark-connect instead of app.kubernetes.io/name=spark-k8s * use label app.kubernetes.io/name=spark-history instead of app.kubernetes.io/name=spark-k8s * update changelog * add cluster roles for connect and history apps and update more labels * Apply suggestions from code review Co-authored-by: Sebastian Bernauer <[email protected]> * update changelog * Update CHANGELOG.md Co-authored-by: Sebastian Bernauer <[email protected]> --------- Co-authored-by: Sebastian Bernauer <[email protected]>
1 parent f2548d6 commit f415bad

File tree

12 files changed

+129
-30
lines changed

12 files changed

+129
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ All notable changes to this project will be documented in this file.
2626
- Document that Spark Connect doesn't integrate with the history server ([#559])
2727
- test: Bump to Vector `0.46.1` ([#565]).
2828
- Use versioned common structs ([#572]).
29+
- BREAKING: Change the label `app.kubernetes.io/name` for Spark history and connect objects to use `spark-history` and `spark-connect` instead of `spark-k8s` ([#573]).
30+
- BREAKING: The history Pods now have their own ClusterRole named `spark-history-clusterrole` ([#573]).
2931

3032
### Fixed
3133

3234
- Use `json` file extension for log files ([#553]).
35+
- The Spark connect controller now watches StatefulSets instead of Deployments (again) ([#573]).
3336

3437
### Removed
3538

@@ -46,6 +49,7 @@ All notable changes to this project will be documented in this file.
4649
[#565]: https://github.com/stackabletech/spark-k8s-operator/pull/565
4750
[#570]: https://github.com/stackabletech/spark-k8s-operator/pull/570
4851
[#572]: https://github.com/stackabletech/spark-k8s-operator/pull/572
52+
[#573]: https://github.com/stackabletech/spark-k8s-operator/pull/573
4953

5054
## [25.3.0] - 2025-03-21
5155

deploy/helm/spark-k8s-operator/templates/roles.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ rules:
1818
resources:
1919
- persistentvolumeclaims
2020
verbs:
21+
- create
22+
- delete
23+
- deletecollection
24+
- get
2125
- list
26+
- patch
27+
- update
28+
- watch
2229
- apiGroups:
2330
- ""
2431
resources:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: spark-connect-clusterrole
6+
labels:
7+
{{- include "operator.labels" . | nindent 4 }}
8+
rules:
9+
- apiGroups:
10+
- ""
11+
resources:
12+
- configmaps
13+
- persistentvolumeclaims
14+
- pods
15+
- secrets
16+
- serviceaccounts
17+
- services
18+
verbs:
19+
- create
20+
- delete
21+
- deletecollection
22+
- get
23+
- list
24+
- patch
25+
- update
26+
- watch
27+
- apiGroups:
28+
- events.k8s.io
29+
resources:
30+
- events
31+
verbs:
32+
- create
33+
{{ if .Capabilities.APIVersions.Has "security.openshift.io/v1" }}
34+
- apiGroups:
35+
- security.openshift.io
36+
resources:
37+
- securitycontextconstraints
38+
resourceNames:
39+
- nonroot-v2
40+
verbs:
41+
- use
42+
{{ end }}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: spark-history-clusterrole
6+
labels:
7+
{{- include "operator.labels" . | nindent 4 }}
8+
rules:
9+
- apiGroups:
10+
- ""
11+
resources:
12+
- configmaps
13+
- persistentvolumeclaims
14+
- pods
15+
- secrets
16+
- serviceaccounts
17+
- services
18+
verbs:
19+
- create
20+
- delete
21+
- deletecollection
22+
- get
23+
- list
24+
- patch
25+
- update
26+
- watch
27+
- apiGroups:
28+
- events.k8s.io
29+
resources:
30+
- events
31+
verbs:
32+
- create
33+
{{ if .Capabilities.APIVersions.Has "security.openshift.io/v1" }}
34+
- apiGroups:
35+
- security.openshift.io
36+
resources:
37+
- securitycontextconstraints
38+
resourceNames:
39+
- nonroot-v2
40+
verbs:
41+
- use
42+
{{ end }}

rust/operator-binary/src/connect/common.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use strum::Display;
1111
use super::crd::CONNECT_EXECUTOR_ROLE_NAME;
1212
use crate::{
1313
connect::crd::{
14-
CONNECT_CONTROLLER_NAME, CONNECT_SERVER_ROLE_NAME, DUMMY_SPARK_CONNECT_GROUP_NAME,
14+
CONNECT_APP_NAME, CONNECT_CONTROLLER_NAME, CONNECT_SERVER_ROLE_NAME,
15+
DUMMY_SPARK_CONNECT_GROUP_NAME,
1516
},
16-
crd::constants::{APP_NAME, OPERATOR_NAME},
17+
crd::constants::OPERATOR_NAME,
1718
};
1819

1920
#[derive(Snafu, Debug)]
@@ -42,7 +43,7 @@ pub(crate) fn labels<'a, T>(
4243
) -> ObjectLabels<'a, T> {
4344
ObjectLabels {
4445
owner: scs,
45-
app_name: APP_NAME,
46+
app_name: CONNECT_APP_NAME,
4647
app_version: app_version_label,
4748
operator_name: OPERATOR_NAME,
4849
controller_name: CONNECT_CONTROLLER_NAME,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use stackable_operator::{
1818
};
1919
use strum::{EnumDiscriminants, IntoStaticStr};
2020

21-
use super::crd::{CONNECT_CONTROLLER_NAME, v1alpha1};
21+
use super::crd::{CONNECT_APP_NAME, CONNECT_CONTROLLER_NAME, v1alpha1};
2222
use crate::{
2323
Ctx,
2424
connect::{common, crd::SparkConnectServerStatus, executor, server},
25-
crd::constants::{APP_NAME, OPERATOR_NAME, SPARK_IMAGE_BASE_NAME},
25+
crd::constants::{OPERATOR_NAME, SPARK_IMAGE_BASE_NAME},
2626
};
2727

2828
#[derive(Snafu, Debug, EnumDiscriminants)]
@@ -168,7 +168,7 @@ pub async fn reconcile(
168168
let client = &ctx.client;
169169

170170
let mut cluster_resources = ClusterResources::new(
171-
APP_NAME,
171+
CONNECT_APP_NAME,
172172
OPERATOR_NAME,
173173
CONNECT_CONTROLLER_NAME,
174174
&scs.object_ref(&()),
@@ -184,7 +184,7 @@ pub async fn reconcile(
184184
// Use a dedicated service account for connect server pods.
185185
let (service_account, role_binding) = build_rbac_resources(
186186
scs,
187-
APP_NAME,
187+
CONNECT_APP_NAME,
188188
cluster_resources
189189
.get_required_labels()
190190
.context(GetRequiredLabelsSnafu)?,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use stackable_operator::{
3333
use strum::{Display, EnumIter};
3434

3535
use super::common::SparkConnectRole;
36-
use crate::crd::constants::APP_NAME;
3736

3837
pub const CONNECT_CONTROLLER_NAME: &str = "connect";
3938
pub const CONNECT_FULL_CONTROLLER_NAME: &str = concatcp!(
@@ -48,6 +47,8 @@ pub const CONNECT_UI_PORT: i32 = 4040;
4847

4948
pub const DUMMY_SPARK_CONNECT_GROUP_NAME: &str = "default";
5049

50+
pub const CONNECT_APP_NAME: &str = "spark-connect";
51+
5152
#[derive(Snafu, Debug)]
5253
pub enum Error {
5354
#[snafu(display("fragment validation failure"))]
@@ -346,7 +347,7 @@ impl v1alpha1::ExecutorConfig {
346347

347348
fn affinity(cluster_name: &str) -> StackableAffinityFragment {
348349
let affinity_between_role_pods = affinity_between_role_pods(
349-
APP_NAME,
350+
CONNECT_APP_NAME,
350351
cluster_name,
351352
&SparkConnectRole::Executor.to_string(),
352353
70,

rust/operator-binary/src/connect/server.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use stackable_operator::{
3535
role_utils::RoleGroupRef,
3636
};
3737

38+
use super::crd::CONNECT_APP_NAME;
3839
use crate::{
3940
connect::{
4041
common::{self, SparkConnectRole, object_name},
@@ -45,7 +46,7 @@ use crate::{
4546
},
4647
crd::{
4748
constants::{
48-
APP_NAME, JVM_SECURITY_PROPERTIES_FILE, LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME,
49+
JVM_SECURITY_PROPERTIES_FILE, LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME,
4950
LOG4J2_CONFIG_FILE, MAX_SPARK_LOG_FILES_SIZE, METRICS_PROPERTIES_FILE,
5051
POD_TEMPLATE_FILE, SPARK_DEFAULTS_FILE_NAME, SPARK_UID, VOLUME_MOUNT_NAME_CONFIG,
5152
VOLUME_MOUNT_NAME_LOG, VOLUME_MOUNT_NAME_LOG_CONFIG, VOLUME_MOUNT_PATH_CONFIG,
@@ -370,7 +371,7 @@ pub(crate) fn build_stateful_set(
370371
match_labels: Some(
371372
Labels::role_group_selector(
372373
scs,
373-
APP_NAME,
374+
CONNECT_APP_NAME,
374375
&SparkConnectRole::Server.to_string(),
375376
DUMMY_SPARK_CONNECT_GROUP_NAME,
376377
)
@@ -393,9 +394,10 @@ pub(crate) fn build_internal_service(
393394
) -> Result<Service, Error> {
394395
let service_name = object_name(&scs.name_any(), SparkConnectRole::Server);
395396

396-
let selector = Labels::role_selector(scs, APP_NAME, &SparkConnectRole::Server.to_string())
397-
.context(LabelBuildSnafu)?
398-
.into();
397+
let selector =
398+
Labels::role_selector(scs, CONNECT_APP_NAME, &SparkConnectRole::Server.to_string())
399+
.context(LabelBuildSnafu)?
400+
.into();
399401

400402
Ok(Service {
401403
metadata: ObjectMetaBuilder::new()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub const POD_DRIVER_FULL_CONTROLLER_NAME: &str =
7777
pub const HISTORY_CONTROLLER_NAME: &str = "history";
7878
pub const HISTORY_FULL_CONTROLLER_NAME: &str =
7979
concatcp!(HISTORY_CONTROLLER_NAME, '.', OPERATOR_NAME);
80-
80+
pub const HISTORY_APP_NAME: &str = "spark-history";
8181
pub const HISTORY_ROLE_NAME: &str = "node";
8282

8383
pub const SPARK_IMAGE_BASE_NAME: &str = "spark-k8s";

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ use crate::{
5454
Ctx,
5555
crd::{
5656
constants::{
57-
ACCESS_KEY_ID, APP_NAME, HISTORY_CONTROLLER_NAME, HISTORY_ROLE_NAME, HISTORY_UI_PORT,
58-
JVM_SECURITY_PROPERTIES_FILE, LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME,
59-
MAX_SPARK_LOG_FILES_SIZE, METRICS_PORT, OPERATOR_NAME, SECRET_ACCESS_KEY,
60-
SPARK_DEFAULTS_FILE_NAME, SPARK_ENV_SH_FILE_NAME, SPARK_IMAGE_BASE_NAME, SPARK_UID,
61-
STACKABLE_TRUST_STORE, VOLUME_MOUNT_NAME_CONFIG, VOLUME_MOUNT_NAME_LOG,
62-
VOLUME_MOUNT_NAME_LOG_CONFIG, VOLUME_MOUNT_PATH_CONFIG, VOLUME_MOUNT_PATH_LOG,
63-
VOLUME_MOUNT_PATH_LOG_CONFIG,
57+
ACCESS_KEY_ID, HISTORY_APP_NAME, HISTORY_CONTROLLER_NAME, HISTORY_ROLE_NAME,
58+
HISTORY_UI_PORT, JVM_SECURITY_PROPERTIES_FILE, LISTENER_VOLUME_DIR,
59+
LISTENER_VOLUME_NAME, MAX_SPARK_LOG_FILES_SIZE, METRICS_PORT, OPERATOR_NAME,
60+
SECRET_ACCESS_KEY, SPARK_DEFAULTS_FILE_NAME, SPARK_ENV_SH_FILE_NAME,
61+
SPARK_IMAGE_BASE_NAME, SPARK_UID, STACKABLE_TRUST_STORE, VOLUME_MOUNT_NAME_CONFIG,
62+
VOLUME_MOUNT_NAME_LOG, VOLUME_MOUNT_NAME_LOG_CONFIG, VOLUME_MOUNT_PATH_CONFIG,
63+
VOLUME_MOUNT_PATH_LOG, VOLUME_MOUNT_PATH_LOG_CONFIG,
6464
},
6565
history::{self, HistoryConfig, SparkHistoryServerContainer, v1alpha1},
6666
listener_ext,
@@ -248,7 +248,7 @@ pub async fn reconcile(
248248
let client = &ctx.client;
249249

250250
let mut cluster_resources = ClusterResources::new(
251-
APP_NAME,
251+
HISTORY_APP_NAME,
252252
OPERATOR_NAME,
253253
HISTORY_CONTROLLER_NAME,
254254
&shs.object_ref(&()),
@@ -271,7 +271,7 @@ pub async fn reconcile(
271271
// Use a dedicated service account for history server pods.
272272
let (service_account, role_binding) = build_rbac_resources(
273273
shs,
274-
APP_NAME,
274+
HISTORY_APP_NAME,
275275
cluster_resources
276276
.get_required_labels()
277277
.context(GetRequiredLabelsSnafu)?,
@@ -659,7 +659,7 @@ fn build_stateful_set(
659659
match_labels: Some(
660660
Labels::role_group_selector(
661661
shs,
662-
APP_NAME,
662+
HISTORY_APP_NAME,
663663
&rolegroupref.role,
664664
&rolegroupref.role_group,
665665
)
@@ -726,7 +726,7 @@ fn labels<'a, T>(
726726
) -> ObjectLabels<'a, T> {
727727
ObjectLabels {
728728
owner: shs,
729-
app_name: APP_NAME,
729+
app_name: HISTORY_APP_NAME,
730730
app_version: app_version_label,
731731
operator_name: OPERATOR_NAME,
732732
controller_name: HISTORY_CONTROLLER_NAME,

0 commit comments

Comments
 (0)