Skip to content

Commit 5a68359

Browse files
committed
refactor: Source cluster domain from ValidatedCluster
1 parent 1c53f74 commit 5a68359

6 files changed

Lines changed: 18 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(crate) mod test_support {
8181
use std::str::FromStr as _;
8282

8383
use stackable_operator::{
84-
commons::product_image_selection::ResolvedProductImage,
84+
commons::{networking::DomainName, product_image_selection::ResolvedProductImage},
8585
crd::authentication::r#static::v1alpha1::{
8686
AuthenticationProvider as StaticAuthProvider, UserCredentialsSecretRef,
8787
},
@@ -168,6 +168,7 @@ pub(crate) mod test_support {
168168
ValidatedCluster::new(
169169
name,
170170
namespace,
171+
DomainName::from_str("cluster.local").expect("valid cluster domain"),
171172
uid,
172173
image,
173174
product_version,

rust/operator-binary/src/controller/build/resource/statefulset.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use stackable_operator::{
3232
self,
3333
framework::{create_vector_shutdown_file_command, remove_vector_shutdown_file_command},
3434
},
35-
utils::{COMMON_BASH_TRAP_FUNCTIONS, cluster_info::KubernetesClusterInfo},
35+
utils::COMMON_BASH_TRAP_FUNCTIONS,
3636
v2::{
3737
builder::pod::container::{EnvVarSet, new_container_builder},
3838
product_logging::framework::{
@@ -164,10 +164,8 @@ pub(crate) const LISTENER_DEFAULT_PORT_HTTPS_ENV: &str = "LISTENER_DEFAULT_PORT_
164164
///
165165
/// The [`Pod`](`stackable_operator::k8s_openapi::api::core::v1::Pod`)s are accessible through the
166166
/// corresponding [`stackable_operator::k8s_openapi::api::core::v1::Service`] (from `build_rolegroup_headless_service`).
167-
#[allow(clippy::too_many_arguments)]
168-
pub(crate) async fn build_node_rolegroup_statefulset(
167+
pub(crate) fn build_node_rolegroup_statefulset(
169168
cluster: &ValidatedCluster,
170-
cluster_info: &KubernetesClusterInfo,
171169
role_group_name: &RoleGroupName,
172170
rg: &NifiRoleGroupConfig,
173171
effective_replicas: Option<i32>,
@@ -251,7 +249,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
251249
"$POD_NAME.{service_name}.{namespace}.svc.{cluster_domain}",
252250
service_name = resource_names.headless_service_name(),
253251
namespace = cluster.namespace,
254-
cluster_domain = cluster_info.cluster_domain,
252+
cluster_domain = cluster.cluster_domain,
255253
);
256254

257255
let sensitive_key_secret = &cluster.cluster_config.sensitive_properties.key_secret;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use snafu::{ResultExt, Snafu};
77
use stackable_operator::{
88
client::Client,
9+
commons::networking::DomainName,
910
v2::{
1011
controller_utils::{self, get_namespace},
1112
types::kubernetes::NamespaceName,
@@ -38,6 +39,9 @@ type Result<T, E = Error> = std::result::Result<T, E>;
3839
pub struct DereferencedObjects {
3940
/// The namespace of the [`v1alpha1::NifiCluster`], parsed once here and reused everywhere.
4041
pub namespace: NamespaceName,
42+
/// The Kubernetes cluster domain, captured from the client here so the build step needs no
43+
/// client to assemble in-cluster DNS names.
44+
pub cluster_domain: DomainName,
4145
pub authentication_classes: DereferencedAuthenticationClasses,
4246
pub authorization: DereferencedAuthorization,
4347
}
@@ -63,6 +67,7 @@ pub async fn dereference(
6367

6468
Ok(DereferencedObjects {
6569
namespace,
70+
cluster_domain: client.kubernetes_cluster_info.cluster_domain.clone(),
6671
authentication_classes,
6772
authorization,
6873
})

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{collections::BTreeMap, str::FromStr as _};
77
use stackable_operator::{
88
commons::{
99
affinity::StackableAffinity,
10+
networking::DomainName,
1011
product_image_selection::ResolvedProductImage,
1112
resources::{NoRuntimeLimits, Resources},
1213
},
@@ -140,6 +141,9 @@ pub struct ValidatedCluster {
140141
pub name: ClusterName,
141142
/// The namespace of the NifiCluster, parsed once in the dereference step and reused everywhere.
142143
pub namespace: NamespaceName,
144+
/// The Kubernetes cluster domain, captured from the client in the dereference step so the
145+
/// build step needs no client to assemble in-cluster DNS names.
146+
pub cluster_domain: DomainName,
143147
/// The UID of the NifiCluster, used to build OwnerReferences downstream.
144148
pub uid: Uid,
145149
/// The product image.
@@ -198,6 +202,7 @@ impl ValidatedCluster {
198202
pub fn new(
199203
name: ClusterName,
200204
namespace: NamespaceName,
205+
cluster_domain: DomainName,
201206
uid: Uid,
202207
image: ResolvedProductImage,
203208
product_version: ProductVersion,
@@ -216,6 +221,7 @@ impl ValidatedCluster {
216221
metadata,
217222
name,
218223
namespace,
224+
cluster_domain,
219225
uid,
220226
image,
221227
product_version,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ pub fn validate(
156156
.context(NoNodesDefinedSnafu)?;
157157

158158
let namespace = dereferenced_objects.namespace.clone();
159+
let cluster_domain = dereferenced_objects.cluster_domain.clone();
159160
let uid = get_uid(nifi).context(GetUidSnafu)?;
160161

161162
// `app_version_label_value` is constructed to be a valid label value, so it is always a valid
@@ -166,6 +167,7 @@ pub fn validate(
166167
Ok(ValidatedCluster::new(
167168
name,
168169
namespace,
170+
cluster_domain,
169171
uid,
170172
image,
171173
product_version,

rust/operator-binary/src/nifi_controller.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,11 @@ pub async fn reconcile_nifi(
259259

260260
let rg_statefulset = build_node_rolegroup_statefulset(
261261
&validated_cluster,
262-
&client.kubernetes_cluster_info,
263262
role_group_name,
264263
rg,
265264
effective_replicas,
266265
&rbac_sa.name_any(),
267266
)
268-
.await
269267
.with_context(|_| BuildStatefulSetSnafu {
270268
rolegroup: role_group_name.clone(),
271269
})?;

0 commit comments

Comments
 (0)