Skip to content

Commit 3945cd3

Browse files
committed
refactor: split auth class resolve to fetch & validate
1 parent 66ff80b commit 3945cd3

3 files changed

Lines changed: 111 additions & 180 deletions

File tree

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
//! The dereference step in the DruidCluster controller
22
//!
33
//! Fetches all Kubernetes objects referenced by the DruidCluster spec and returns them in
4-
//! [`DereferencedObjects`]. The helpers called here (`AuthenticationClassesResolved::from`,
5-
//! `DruidCluster::get_s3_connection`, `S3Bucket::resolve`,
6-
//! `OpaConfig::full_document_url_from_config_map`) currently mix fetching and validation;
7-
//! their outputs are treated as "dereferenced" for now. Splitting those helpers is a
8-
//! follow-up.
4+
//! [`DereferencedObjects`]. AuthenticationClasses are fetched raw here
5+
//! ([`fetch_authentication_classes`]) and validated later in the validate step. The remaining
6+
//! helpers (`DruidCluster::get_s3_connection`, `S3Bucket::resolve`,
7+
//! `OpaConfig::full_document_url_from_config_map`) still mix fetching and validation; their
8+
//! outputs are treated as "dereferenced" for now. Splitting those is a follow-up.
99
1010
use snafu::{OptionExt, ResultExt, Snafu};
1111
use stackable_operator::{
12-
client::Client, commons::opa::OpaApiVersion, crd::s3, k8s_openapi::api::core::v1::ConfigMap,
12+
client::Client,
13+
commons::opa::OpaApiVersion,
14+
crd::{authentication::core, s3},
15+
k8s_openapi::api::core::v1::ConfigMap,
1316
};
1417

1518
use crate::crd::{
16-
DeepStorageSpec, authentication::AuthenticationClassesResolved,
19+
DeepStorageSpec, authentication::fetch_authentication_classes,
1720
authorization::DruidAuthorization, v1alpha1,
1821
};
1922

@@ -70,7 +73,9 @@ pub struct DereferencedObjects {
7073
pub opa_connection_string: Option<String>,
7174
pub s3_connection: Option<s3::v1alpha1::ConnectionSpec>,
7275
pub deep_storage_bucket_name: Option<String>,
73-
pub resolved_authentication_classes: AuthenticationClassesResolved,
76+
/// The raw, fetched `AuthenticationClass` objects (in spec order). Validation of these happens
77+
/// in the validate step via [`AuthenticationClassesResolved::from_fetched`].
78+
pub authentication_classes: Vec<core::v1alpha1::AuthenticationClass>,
7479
}
7580

7681
/// Fetches all Kubernetes objects referenced from the [`v1alpha1::DruidCluster`] spec.
@@ -134,16 +139,15 @@ pub async fn dereference(
134139
_ => None,
135140
};
136141

137-
let resolved_authentication_classes =
138-
AuthenticationClassesResolved::from(&druid.spec.cluster_config, client)
139-
.await
140-
.context(AuthenticationClassRetrievalSnafu)?;
142+
let authentication_classes = fetch_authentication_classes(&druid.spec.cluster_config, client)
143+
.await
144+
.context(AuthenticationClassRetrievalSnafu)?;
141145

142146
Ok(DereferencedObjects {
143147
zookeeper_connection_string,
144148
opa_connection_string,
145149
s3_connection,
146150
deep_storage_bucket_name,
147-
resolved_authentication_classes,
151+
authentication_classes,
148152
})
149153
}

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ use crate::{
4040
authentication::DruidAuthenticationConfig,
4141
controller::{controller_name, dereference::DereferencedObjects, operator_name, product_name},
4242
crd::{
43-
DeepStorageSpec, DruidRole, database::MetadataDatabaseConnection,
44-
security::DruidTlsSecurity, v1alpha1,
43+
DeepStorageSpec, DruidRole, authentication::AuthenticationClassesResolved,
44+
database::MetadataDatabaseConnection, security::DruidTlsSecurity, v1alpha1,
4545
},
4646
};
4747

@@ -65,6 +65,11 @@ pub enum Error {
6565
InvalidMetadataDatabaseConnection {
6666
source: stackable_operator::database_connections::Error,
6767
},
68+
69+
#[snafu(display("failed to resolve authentication classes"))]
70+
ResolveAuthenticationClasses {
71+
source: crate::crd::authentication::Error,
72+
},
6873
}
6974

7075
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -323,14 +328,17 @@ pub fn validate(
323328
)
324329
.context(ResolveProductImageSnafu)?;
325330

326-
let druid_tls_security = DruidTlsSecurity::new_from_druid_cluster(
327-
druid,
328-
&dereferenced_objects.resolved_authentication_classes,
329-
);
331+
let resolved_authentication_classes = AuthenticationClassesResolved::from_fetched(
332+
&druid.spec.cluster_config,
333+
&dereferenced_objects.authentication_classes,
334+
)
335+
.context(ResolveAuthenticationClassesSnafu)?;
336+
337+
let druid_tls_security =
338+
DruidTlsSecurity::new_from_druid_cluster(druid, &resolved_authentication_classes);
330339

331-
let druid_auth_config = DruidAuthenticationConfig::from_auth_classes(
332-
dereferenced_objects.resolved_authentication_classes.clone(),
333-
);
340+
let druid_auth_config =
341+
DruidAuthenticationConfig::from_auth_classes(resolved_authentication_classes);
334342

335343
let mut role_group_configs: BTreeMap<DruidRole, BTreeMap<RoleGroupName, DruidRoleGroupConfig>> =
336344
BTreeMap::new();
@@ -539,10 +547,7 @@ mod tests {
539547
test_support::{MINIMAL_DRUID_YAML, druid_from_yaml},
540548
validate,
541549
};
542-
use crate::{
543-
controller::dereference::DereferencedObjects,
544-
crd::{DruidRole, authentication::AuthenticationClassesResolved},
545-
};
550+
use crate::{controller::dereference::DereferencedObjects, crd::DruidRole};
546551

547552
/// Dereferenced inputs with test defaults: no S3, no OPA, no auth, a fixed ZooKeeper string.
548553
fn dereferenced_objects() -> DereferencedObjects {
@@ -551,9 +556,7 @@ mod tests {
551556
opa_connection_string: None,
552557
s3_connection: None,
553558
deep_storage_bucket_name: None,
554-
resolved_authentication_classes: AuthenticationClassesResolved {
555-
auth_classes: Vec::new(),
556-
},
559+
authentication_classes: Vec::new(),
557560
}
558561
}
559562

0 commit comments

Comments
 (0)