Skip to content

Commit 026367c

Browse files
committed
refactor: remove raw cluster references
1 parent dbe2095 commit 026367c

7 files changed

Lines changed: 58 additions & 35 deletions

File tree

rust/operator-binary/src/controller/build/properties.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ pub(crate) mod test_support {
8383

8484
use crate::{
8585
controller::{
86-
ValidatedCluster, ValidatedClusterConfig, ValidatedRoleGroupConfig,
87-
validate::build_role_group_configs,
86+
ValidatedCluster, ValidatedClusterConfig, ValidatedRoleConfig,
87+
ValidatedRoleGroupConfig, validate::build_role_group_configs,
8888
},
8989
crd::{NifiRole, v1alpha1},
9090
security::{
@@ -141,6 +141,14 @@ pub(crate) mod test_support {
141141
let role_group_configs = build_role_group_configs(&nifi, &image, &None)
142142
.expect("role group configs should merge for minimal fixture");
143143

144+
let role_config = nifi
145+
.role_config(&NifiRole::Node)
146+
.map(|role_config| ValidatedRoleConfig {
147+
pdb: role_config.common.pod_disruption_budget.clone(),
148+
listener_class: role_config.listener_class.clone(),
149+
})
150+
.expect("the minimal fixture defines the nodes role");
151+
144152
let name = ClusterName::from_str("simple-nifi").expect("valid cluster name");
145153
let namespace = NamespaceName::from_str("default").expect("valid namespace");
146154
let uid = Uid::from_str("e6ac237d-a6d4-43a1-8135-f36506110912").expect("valid uid");
@@ -153,6 +161,7 @@ pub(crate) mod test_support {
153161
uid,
154162
image,
155163
product_version,
164+
role_config,
156165
role_group_configs,
157166
ValidatedClusterConfig {
158167
authentication: NifiAuthenticationConfig::SingleUser {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ pub fn validate(
115115
)
116116
.context(ResolveProductImageSnafu)?;
117117

118+
let name = get_cluster_name(nifi).context(GetClusterNameSnafu)?;
119+
118120
let authentication_config =
119-
NifiAuthenticationConfig::validate(nifi, &dereferenced_objects.authentication_classes)
121+
NifiAuthenticationConfig::validate(&name, &dereferenced_objects.authentication_classes)
120122
.context(InvalidAuthenticationConfigSnafu)?;
121123

122124
let authorization_config = ResolvedNifiAuthorizationConfig::validate(
@@ -157,7 +159,6 @@ pub fn validate(
157159
})
158160
.context(NoNodesDefinedSnafu)?;
159161

160-
let name = get_cluster_name(nifi).context(GetClusterNameSnafu)?;
161162
let namespace = dereferenced_objects.namespace.clone();
162163
let uid = get_uid(nifi).context(GetUidSnafu)?;
163164

rust/operator-binary/src/nifi_controller.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,13 @@ pub async fn reconcile_nifi(
204204
let authentication_config = &validated_cluster.cluster_config.authentication;
205205

206206
tracing::info!("Checking for sensitive key configuration");
207-
check_or_generate_sensitive_key(client, nifi, &validated_cluster.namespace)
208-
.await
209-
.context(SecuritySnafu)?;
207+
check_or_generate_sensitive_key(
208+
client,
209+
&nifi.spec.cluster_config.sensitive_properties,
210+
&validated_cluster.namespace,
211+
)
212+
.await
213+
.context(SecuritySnafu)?;
210214

211215
// If rolling upgrade is supported, kubernetes takes care of the cluster scaling automatically
212216
// otherwise the operator handles it
@@ -244,9 +248,13 @@ pub async fn reconcile_nifi(
244248
);
245249

246250
if let NifiAuthenticationConfig::Oidc { .. } = authentication_config {
247-
check_or_generate_oidc_admin_password(client, nifi, &validated_cluster.namespace)
248-
.await
249-
.context(SecuritySnafu)?;
251+
check_or_generate_oidc_admin_password(
252+
client,
253+
&validated_cluster.name,
254+
&validated_cluster.namespace,
255+
)
256+
.await
257+
.context(SecuritySnafu)?;
250258
}
251259

252260
let (rbac_sa, rbac_rolebinding) = build_rbac_resources(

rust/operator-binary/src/security/authentication.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use stackable_operator::{
99
crd::authentication::{core as auth_core, ldap, oidc, r#static},
1010
k8s_openapi::api::core::v1::{KeyToPath, SecretVolumeSource, Volume},
1111
kube::{ResourceExt, runtime::reflector::ObjectRef},
12+
v2::types::operator::ClusterName,
1213
};
1314

1415
use crate::{crd::v1alpha1, security::oidc::build_oidc_admin_password_secret_name};
@@ -115,7 +116,6 @@ impl DereferencedAuthenticationClasses {
115116
}
116117
}
117118

118-
#[allow(clippy::large_enum_variant)]
119119
#[derive(Clone)]
120120
pub enum NifiAuthenticationConfig {
121121
SingleUser {
@@ -127,7 +127,7 @@ pub enum NifiAuthenticationConfig {
127127
Oidc {
128128
provider: oidc::v1alpha1::AuthenticationProvider,
129129
oidc: oidc::v1alpha1::ClientAuthenticationOptions,
130-
nifi: v1alpha1::NifiCluster,
130+
cluster_name: ClusterName,
131131
},
132132
}
133133

@@ -243,11 +243,15 @@ impl NifiAuthenticationConfig {
243243
.add_volumes_and_mounts(pod_builder, container_builders)
244244
.context(AddLdapVolumesSnafu)?;
245245
}
246-
Self::Oidc { provider, nifi, .. } => {
246+
Self::Oidc {
247+
provider,
248+
cluster_name,
249+
..
250+
} => {
247251
let admin_volume = Volume {
248252
name: STACKABLE_ADMIN_USERNAME.to_string(),
249253
secret: Some(SecretVolumeSource {
250-
secret_name: Some(build_oidc_admin_password_secret_name(nifi)),
254+
secret_name: Some(build_oidc_admin_password_secret_name(cluster_name)),
251255
optional: Some(false),
252256
items: Some(vec![KeyToPath {
253257
key: STACKABLE_ADMIN_USERNAME.to_string(),
@@ -285,7 +289,7 @@ impl NifiAuthenticationConfig {
285289
/// * LDAP TLS verification is enabled if TLS is used
286290
/// * an OIDC client spec is present when the provider is OIDC
287291
pub fn validate(
288-
nifi: &v1alpha1::NifiCluster,
292+
cluster_name: &ClusterName,
289293
dereferenced: &DereferencedAuthenticationClasses,
290294
) -> Result<Self> {
291295
let (entry, auth_class) = match dereferenced.entries.as_slice() {
@@ -321,7 +325,7 @@ impl NifiAuthenticationConfig {
321325
.oidc_or_error(&auth_class_name)
322326
.context(OidcConfigurationInvalidSnafu)?
323327
.clone(),
324-
nifi: nifi.clone(),
328+
cluster_name: cluster_name.clone(),
325329
}),
326330
_ => AuthenticationClassProviderNotSupportedSnafu {
327331
authentication_class_provider: auth_class.spec.provider.to_string(),

rust/operator-binary/src/security/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use snafu::{ResultExt, Snafu};
22
use stackable_operator::{
3-
builder::pod::volume::SecretFormat, client::Client, k8s_openapi::api::core::v1::Volume,
4-
shared::time::Duration, v2::types::kubernetes::NamespaceName,
3+
builder::pod::volume::SecretFormat,
4+
client::Client,
5+
k8s_openapi::api::core::v1::Volume,
6+
shared::time::Duration,
7+
v2::types::{kubernetes::NamespaceName, operator::ClusterName},
58
};
69

7-
use crate::crd::v1alpha1;
10+
use crate::crd::sensitive_properties::NifiSensitivePropertiesConfig;
811

912
pub mod authentication;
1013
pub mod authorization;
@@ -28,20 +31,20 @@ pub enum Error {
2831

2932
pub async fn check_or_generate_sensitive_key(
3033
client: &Client,
31-
nifi: &v1alpha1::NifiCluster,
34+
sensitive_config: &NifiSensitivePropertiesConfig,
3235
namespace: &NamespaceName,
3336
) -> Result<bool> {
34-
sensitive_key::check_or_generate_sensitive_key(client, nifi, namespace)
37+
sensitive_key::check_or_generate_sensitive_key(client, sensitive_config, namespace)
3538
.await
3639
.context(SensitiveKeySnafu)
3740
}
3841

3942
pub async fn check_or_generate_oidc_admin_password(
4043
client: &Client,
41-
nifi: &v1alpha1::NifiCluster,
44+
cluster_name: &ClusterName,
4245
namespace: &NamespaceName,
4346
) -> Result<bool> {
44-
oidc::check_or_generate_oidc_admin_password(client, nifi, namespace)
47+
oidc::check_or_generate_oidc_admin_password(client, cluster_name, namespace)
4548
.await
4649
.context(OidcAdminPasswordSnafu)
4750
}

rust/operator-binary/src/security/oidc.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use stackable_operator::{
88
commons::tls_verification::{CaCert, TlsServerVerification, TlsVerification},
99
crd::authentication::oidc,
1010
k8s_openapi::api::core::v1::Secret,
11-
kube::{ResourceExt, runtime::reflector::ObjectRef},
12-
v2::types::kubernetes::NamespaceName,
11+
kube::runtime::reflector::ObjectRef,
12+
v2::types::{kubernetes::NamespaceName, operator::ClusterName},
1313
};
1414

15-
use crate::{crd::v1alpha1, security::authentication::STACKABLE_ADMIN_USERNAME};
15+
use crate::security::authentication::STACKABLE_ADMIN_USERNAME;
1616

1717
type Result<T, E = Error> = std::result::Result<T, E>;
1818

@@ -42,13 +42,13 @@ pub enum Error {
4242
/// This admin user is the same as for SingleUser authentication.
4343
pub(crate) async fn check_or_generate_oidc_admin_password(
4444
client: &Client,
45-
nifi: &v1alpha1::NifiCluster,
45+
cluster_name: &ClusterName,
4646
namespace: &NamespaceName,
4747
) -> Result<bool, Error> {
4848
tracing::debug!("Checking for OIDC admin password configuration");
4949
match client
5050
.get_opt::<Secret>(
51-
&build_oidc_admin_password_secret_name(nifi),
51+
&build_oidc_admin_password_secret_name(cluster_name),
5252
namespace.as_ref(),
5353
)
5454
.await
@@ -84,7 +84,7 @@ pub(crate) async fn check_or_generate_oidc_admin_password(
8484
let new_secret = Secret {
8585
metadata: ObjectMetaBuilder::new()
8686
.namespace(namespace)
87-
.name(build_oidc_admin_password_secret_name(nifi))
87+
.name(build_oidc_admin_password_secret_name(cluster_name))
8888
.build(),
8989
string_data: Some(secret_data),
9090
..Secret::default()
@@ -98,8 +98,8 @@ pub(crate) async fn check_or_generate_oidc_admin_password(
9898
}
9999
}
100100

101-
pub fn build_oidc_admin_password_secret_name(nifi: &v1alpha1::NifiCluster) -> String {
102-
format!("{}-oidc-admin-password", nifi.name_any())
101+
pub fn build_oidc_admin_password_secret_name(cluster_name: &ClusterName) -> String {
102+
format!("{cluster_name}-oidc-admin-password")
103103
}
104104

105105
/// Adds all the required configuration properties to enable OIDC authentication.

rust/operator-binary/src/security/sensitive_key.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use stackable_operator::{
77
v2::types::kubernetes::NamespaceName,
88
};
99

10-
use crate::crd::v1alpha1;
10+
use crate::crd::sensitive_properties::NifiSensitivePropertiesConfig;
1111

1212
type Result<T, E = Error> = std::result::Result<T, E>;
1313

@@ -28,11 +28,9 @@ pub enum Error {
2828

2929
pub(crate) async fn check_or_generate_sensitive_key(
3030
client: &Client,
31-
nifi: &v1alpha1::NifiCluster,
31+
sensitive_config: &NifiSensitivePropertiesConfig,
3232
namespace: &NamespaceName,
3333
) -> Result<bool, Error> {
34-
let sensitive_config = &nifi.spec.cluster_config.sensitive_properties;
35-
3634
match client
3735
.get_opt::<Secret>(sensitive_config.key_secret.as_ref(), namespace.as_ref())
3836
.await

0 commit comments

Comments
 (0)