Skip to content

Commit e43638b

Browse files
committed
refactor connect server service account and role binding
1 parent 8a5057d commit e43638b

9 files changed

Lines changed: 152 additions & 125 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ indoc = "2"
3131
regex = "1.12"
3232

3333
[patch."https://github.com/stackabletech/operator-rs.git"]
34-
# stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch="main" }
34+
stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch="feat/smooth-operator/build-rbac" }
3535
# stackable-operator = { path = "../operator-rs/crates/stackable-operator" }

crate-hashes.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::sync::Arc;
33
use snafu::{ResultExt, Snafu};
44
use stackable_operator::{
55
cluster_resources::ClusterResourceApplyStrategy,
6-
commons::rbac::build_rbac_resources,
76
crd::listener,
87
k8s_openapi::api::{
98
apps::v1::StatefulSet,
@@ -25,7 +24,7 @@ use stackable_operator::{
2524
};
2625
use strum::{EnumDiscriminants, IntoStaticStr};
2726

28-
use super::crd::{CONNECT_APP_NAME, v1alpha1};
27+
use super::crd::v1alpha1;
2928
use crate::{Ctx, connect::crd::SparkConnectServerStatus, crd::constants::OPERATOR_NAME};
3029

3130
pub mod build;
@@ -44,16 +43,6 @@ pub enum Error {
4443
source: stackable_operator::cluster_resources::Error,
4544
},
4645

47-
#[snafu(display("failed to apply role ServiceAccount"))]
48-
ApplyServiceAccount {
49-
source: stackable_operator::cluster_resources::Error,
50-
},
51-
52-
#[snafu(display("failed to apply global RoleBinding"))]
53-
ApplyRoleBinding {
54-
source: stackable_operator::cluster_resources::Error,
55-
},
56-
5746
#[snafu(display("failed to update status of spark connect server {name}"))]
5847
ApplyStatus {
5948
source: stackable_operator::client::Error,
@@ -150,32 +139,19 @@ pub async fn reconcile(
150139
&scs.spec.object_overrides,
151140
);
152141

153-
// Use a dedicated service account for connect server pods. Building the RBAC resources needs
154-
// the cluster-resource labels, so it stays in the reconcile step; the built objects (whose
155-
// names are deterministic) are handed to the client-free build step.
156-
let (service_account, role_binding) = build_rbac_resources(
157-
scs,
158-
CONNECT_APP_NAME,
159-
cluster_resources
160-
.get_required_labels()
161-
.context(GetRequiredLabelsSnafu)?,
162-
)
163-
.context(BuildRbacResourcesSnafu)?;
164-
165-
let resources = build::build(&validated, service_account, role_binding, &scs.spec.args)
166-
.context(BuildResourcesSnafu)?;
142+
let resources = build::build(&validated, &scs.spec.args).context(BuildResourcesSnafu)?;
167143

168144
// Apply order: ServiceAccount and RoleBinding first, then the Services, ConfigMaps and
169145
// Listener, and finally the StatefulSet (it mounts the ConfigMaps and runs under the SA, so
170146
// they must exist first).
171147
cluster_resources
172148
.add(client, resources.service_account)
173149
.await
174-
.context(ApplyServiceAccountSnafu)?;
150+
.context(ApplyResourceSnafu)?;
175151
cluster_resources
176152
.add(client, resources.role_binding)
177153
.await
178-
.context(ApplyRoleBindingSnafu)?;
154+
.context(ApplyResourceSnafu)?;
179155
for service in resources.services {
180156
cluster_resources
181157
.add(client, service)

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
//! together in one module is clearer than scattering them across per-kind modules.
77
88
pub(crate) mod executor;
9+
pub(crate) mod rbac;
910
pub(crate) mod server;
1011
pub(crate) mod service;
1112

1213
use snafu::{ResultExt, Snafu};
13-
use stackable_operator::{
14-
k8s_openapi::api::{core::v1::ServiceAccount, rbac::v1::RoleBinding},
15-
kube::ResourceExt,
16-
};
14+
use stackable_operator::kube::ResourceExt;
1715

1816
use crate::connect::{
1917
common,
20-
controller::{SparkConnectResources, validate::ValidatedSparkConnectServer},
18+
controller::{
19+
SparkConnectResources,
20+
build::rbac::{build_role_binding, build_service_account},
21+
validate::ValidatedSparkConnectServer,
22+
},
2123
};
2224

2325
#[derive(Snafu, Debug)]
@@ -56,8 +58,6 @@ pub enum Error {
5658
/// Builds every Kubernetes resource for the given validated SparkConnectServer.
5759
pub(crate) fn build(
5860
validated: &ValidatedSparkConnectServer,
59-
service_account: ServiceAccount,
60-
role_binding: RoleBinding,
6161
user_args: &[String],
6262
) -> Result<SparkConnectResources, Error> {
6363
let resolved_s3 = &validated.cluster_config.resolved_s3;
@@ -70,8 +70,7 @@ pub(crate) fn build(
7070
resolved_s3
7171
.spark_properties()
7272
.context(S3SparkPropertiesSnafu)?,
73-
server::server_properties(validated, &headless_service, &service_account)
74-
.context(ServerPropertiesSnafu)?,
73+
server::server_properties(validated, &headless_service).context(ServerPropertiesSnafu)?,
7574
executor::executor_properties(validated).context(ExecutorPropertiesSnafu)?,
7675
])
7776
.context(SerializePropertiesSnafu)?;
@@ -97,18 +96,13 @@ pub(crate) fn build(
9796
let listener = server::build_listener(validated);
9897

9998
let args = server::command_args(user_args);
100-
let stateful_set = server::build_stateful_set(
101-
validated,
102-
&service_account,
103-
&server_config_map,
104-
&listener.name_any(),
105-
args,
106-
)
107-
.context(BuildServerStatefulSetSnafu)?;
99+
let stateful_set =
100+
server::build_stateful_set(validated, &server_config_map, &listener.name_any(), args)
101+
.context(BuildServerStatefulSetSnafu)?;
108102

109103
Ok(SparkConnectResources {
110-
service_account,
111-
role_binding,
104+
service_account: build_service_account(validated),
105+
role_binding: build_role_binding(validated),
112106
services: vec![headless_service, metrics_service],
113107
config_maps: vec![executor_config_map, server_config_map],
114108
listener,

0 commit comments

Comments
 (0)