Skip to content

Commit 45a1859

Browse files
committed
refactor rbac (service account and role binding), added tests
1 parent bdb6aff commit 45a1859

10 files changed

Lines changed: 214 additions & 129 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,7 +31,7 @@ tokio-zookeeper = "0.4"
3131
tracing = "0.1"
3232

3333
[patch."https://github.com/stackabletech/operator-rs.git"]
34-
# stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "smooth-operator" }
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" }
3636

3737
[patch.crates-io]

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/zk_controller.rs

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ use snafu::{OptionExt, ResultExt, Snafu};
77
use stackable_operator::{
88
cli::OperatorEnvironmentOptions,
99
cluster_resources::ClusterResourceApplyStrategy,
10-
commons::rbac::build_rbac_resources,
1110
crd::listener::v1alpha1::Listener,
1211
k8s_openapi::api::{
1312
apps::v1::StatefulSet,
14-
core::v1::{ConfigMap, Service},
13+
core::v1::{ConfigMap, Service, ServiceAccount},
1514
policy::v1::PodDisruptionBudget,
15+
rbac::v1::RoleBinding,
1616
},
1717
kube::{
1818
api::DynamicObject,
1919
core::{DeserializeGuard, error_boundary},
2020
runtime::controller,
2121
},
22-
kvp::LabelError,
2322
logging::controller::ReconcilerError,
2423
shared::time::Duration,
2524
status::condition::{
@@ -31,7 +30,7 @@ use stackable_operator::{
3130
use strum::{EnumDiscriminants, IntoStaticStr};
3231

3332
use crate::{
34-
APP_NAME, OPERATOR_NAME, ObjectRef,
33+
OPERATOR_NAME, ObjectRef,
3534
crd::v1alpha1,
3635
zk_controller::{
3736
build::resource::discovery,
@@ -106,29 +105,11 @@ pub enum Error {
106105
source: stackable_operator::client::Error,
107106
},
108107

109-
#[snafu(display("failed to create RBAC service account"))]
110-
ApplyServiceAccount {
111-
source: stackable_operator::cluster_resources::Error,
112-
},
113-
114-
#[snafu(display("failed to create RBAC role binding"))]
115-
ApplyRoleBinding {
116-
source: stackable_operator::cluster_resources::Error,
117-
},
118-
119-
#[snafu(display("failed to build RBAC resources"))]
120-
BuildRbacResources {
121-
source: stackable_operator::commons::rbac::Error,
122-
},
123-
124108
#[snafu(display("failed to delete orphaned resources"))]
125109
DeleteOrphans {
126110
source: stackable_operator::cluster_resources::Error,
127111
},
128112

129-
#[snafu(display("failed to build label"))]
130-
BuildLabel { source: LabelError },
131-
132113
#[snafu(display("failed to build object meta data"))]
133114
ObjectMeta {
134115
source: stackable_operator::builder::meta::Error,
@@ -154,11 +135,7 @@ impl ReconcilerError for Error {
154135
Error::BuildDiscoveryConfig { .. } => None,
155136
Error::ApplyDiscoveryConfig { .. } => None,
156137
Error::ApplyStatus { .. } => None,
157-
Error::ApplyServiceAccount { .. } => None,
158-
Error::ApplyRoleBinding { .. } => None,
159-
Error::BuildRbacResources { .. } => None,
160138
Error::DeleteOrphans { .. } => None,
161-
Error::BuildLabel { .. } => None,
162139
Error::ObjectMeta { .. } => None,
163140
}
164141
}
@@ -173,6 +150,8 @@ pub struct KubernetesResources {
173150
pub listeners: Vec<Listener>,
174151
pub config_maps: Vec<ConfigMap>,
175152
pub pod_disruption_budgets: Vec<PodDisruptionBudget>,
153+
pub service_accounts: Vec<ServiceAccount>,
154+
pub role_bindings: Vec<RoleBinding>,
176155
}
177156

178157
pub async fn reconcile_zk(
@@ -209,30 +188,24 @@ pub async fn reconcile_zk(
209188
&validated_cluster.object_overrides,
210189
);
211190

212-
let (rbac_sa, rbac_rolebinding) = build_rbac_resources(
213-
zk,
214-
APP_NAME,
215-
cluster_resources
216-
.get_required_labels()
217-
.context(BuildLabelSnafu)?,
218-
)
219-
.context(BuildRbacResourcesSnafu)?;
220-
221-
cluster_resources
222-
.add(client, rbac_sa)
223-
.await
224-
.context(ApplyServiceAccountSnafu)?;
225-
226-
cluster_resources
227-
.add(client, rbac_rolebinding)
228-
.await
229-
.context(ApplyRoleBindingSnafu)?;
230-
231191
let resources = build::build(&validated_cluster, &client.kubernetes_cluster_info)
232192
.context(BuildResourcesSnafu)?;
233193

234194
let mut ss_cond_builder = StatefulSetConditionBuilder::default();
235195

196+
for service_account in resources.service_accounts {
197+
cluster_resources
198+
.add(client, service_account)
199+
.await
200+
.context(ApplyResourceSnafu)?;
201+
}
202+
for role_binding in resources.role_bindings {
203+
cluster_resources
204+
.add(client, role_binding)
205+
.await
206+
.context(ApplyResourceSnafu)?;
207+
}
208+
236209
for service in resources.services {
237210
cluster_resources
238211
.add(client, service)

0 commit comments

Comments
 (0)