@@ -34,15 +34,13 @@ use stackable_operator::{
3434 security:: PodSecurityContextBuilder , volume:: SecretFormat ,
3535 } ,
3636 } ,
37- commons:: product_image_selection:: ResolvedProductImage ,
3837 k8s_openapi:: {
3938 DeepMerge ,
4039 api:: {
4140 batch:: v1:: { Job , JobSpec } ,
4241 core:: v1:: { Service , ServicePort , ServiceSpec } ,
4342 } ,
4443 } ,
45- kube:: ResourceExt ,
4644 shared:: time:: Duration ,
4745 utils:: cluster_info:: KubernetesClusterInfo ,
4846 v2:: {
@@ -56,11 +54,8 @@ use stackable_operator::{
5654
5755use crate :: {
5856 controller:: ValidatedCluster ,
59- crd:: { HTTPS_PORT , HTTPS_PORT_NAME , METRICS_PORT , NifiRole , v1alpha1} ,
60- security:: {
61- authentication:: { NifiAuthenticationConfig , STACKABLE_ADMIN_USERNAME } ,
62- build_tls_volume,
63- } ,
57+ crd:: { HTTPS_PORT , HTTPS_PORT_NAME , METRICS_PORT , NifiRole } ,
58+ security:: { authentication:: STACKABLE_ADMIN_USERNAME , build_tls_volume} ,
6459} ;
6560
6661const REPORTING_TASK_CERT_VOLUME_NAME : & str = "tls" ;
@@ -108,28 +103,15 @@ type Result<T, E = Error> = std::result::Result<T, E>;
108103///
109104/// NiFi 2.x and above automatically server Prometheus metrics via the API, but as of 2024-11-08
110105/// requires authentication.
111- #[ allow( clippy:: too_many_arguments) ]
112106pub fn build_maybe_reporting_task (
113- nifi : & v1alpha1:: NifiCluster ,
114107 cluster : & ValidatedCluster ,
115- resolved_product_image : & ResolvedProductImage ,
116108 cluster_info : & KubernetesClusterInfo ,
117- namespace : & NamespaceName ,
118- authentication_config : & NifiAuthenticationConfig ,
119109 sa_name : & str ,
120110) -> Result < Option < ( Job , Service ) > > {
121- if resolved_product_image . product_version . starts_with ( "1." ) {
111+ if cluster . image . product_version . starts_with ( "1." ) {
122112 Ok ( Some ( (
123- build_reporting_task_job (
124- nifi,
125- cluster,
126- resolved_product_image,
127- cluster_info,
128- namespace,
129- authentication_config,
130- sa_name,
131- ) ?,
132- build_reporting_task_service ( nifi, cluster) ?,
113+ build_reporting_task_job ( cluster, cluster_info, sa_name) ?,
114+ build_reporting_task_service ( cluster) ?,
133115 ) ) )
134116 } else {
135117 Ok ( None )
@@ -162,51 +144,48 @@ pub fn build_reporting_task_fqdn_service_name(
162144}
163145
164146/// Return the name of the first pod belonging to the first role group that contains more than 0 replicas.
165- /// If no replicas are set in any rolegroup (e.g. HPA, see <https://docs.stackable.tech/home/stable/concepts/operations/#_performance>)
147+ /// If no role group has replicas set (e.g. HPA, see <https://docs.stackable.tech/home/stable/concepts/operations/#_performance>)
166148/// return the first rolegroup just in case.
167149/// This is required to only select a single node in the Reporting Task Service.
168- fn get_reporting_task_service_selector_pod ( nifi : & v1alpha1:: NifiCluster ) -> Result < String > {
169- let cluster_name = nifi. name_any ( ) ;
150+ ///
151+ /// Note: the validated replicas default to `1` (see [`ValidatedRoleGroupConfig`]), so an
152+ /// HPA-managed role group (raw `replicas: null`) is treated as having a single replica here.
153+ fn get_reporting_task_service_selector_pod ( cluster : & ValidatedCluster ) -> Result < String > {
170154 let node_name = NifiRole :: Node . to_string ( ) ;
171155
172- // sort the rolegroups to avoid random sorting and therefore unnecessary reconciles
173- let sorted_role_groups = nifi
174- . spec
175- . nodes
176- . iter ( )
177- . flat_map ( |role| & role. role_groups )
178- . collect :: < BTreeMap < _ , _ > > ( ) ;
156+ // The role groups are already sorted by name (`BTreeMap`), avoiding random ordering and
157+ // therefore unnecessary reconciles.
158+ let role_groups = cluster
159+ . role_group_configs
160+ . get ( & NifiRole :: Node )
161+ . context ( FailedBuildReportingTaskServiceSnafu ) ?;
179162
180163 let mut selector_role_group = None ;
181- for ( role_group_name, role_group) in sorted_role_groups {
182- // just pick the first rolegroup in case no replicas are set
164+ for ( role_group_name, role_group) in role_groups {
165+ // just pick the first rolegroup in case none has replicas set
183166 if selector_role_group. is_none ( ) {
184167 selector_role_group = Some ( role_group_name) ;
185168 }
186169
187- if let Some ( replicas) = role_group. replicas {
188- if replicas > 0 {
189- selector_role_group = Some ( role_group_name) ;
190- break ;
191- }
170+ if role_group. replicas > 0 {
171+ selector_role_group = Some ( role_group_name) ;
172+ break ;
192173 }
193174 }
194175
195176 Ok ( format ! (
196177 "{cluster_name}-{node_name}-{role_group_name}-0" ,
178+ cluster_name = cluster. name,
197179 role_group_name = selector_role_group. context( FailedBuildReportingTaskServiceSnafu ) ?
198180 ) )
199181}
200182
201183/// Build the internal Reporting Task Service in order to communicate with a single NiFi node.
202- fn build_reporting_task_service (
203- nifi : & v1alpha1:: NifiCluster ,
204- cluster : & ValidatedCluster ,
205- ) -> Result < Service > {
206- let nifi_cluster_name = nifi. name_any ( ) ;
184+ fn build_reporting_task_service ( cluster : & ValidatedCluster ) -> Result < Service > {
185+ let nifi_cluster_name = cluster. name . to_string ( ) ;
207186 let mut selector: BTreeMap < String , String > = cluster. role_selector ( ) . into ( ) ;
208187
209- let service_selector_pod = get_reporting_task_service_selector_pod ( nifi ) ?;
188+ let service_selector_pod = get_reporting_task_service_selector_pod ( cluster ) ?;
210189 selector. insert (
211190 "statefulset.kubernetes.io/pod-name" . to_string ( ) ,
212191 service_selector_pod,
@@ -247,18 +226,18 @@ fn build_reporting_task_service(
247226/// as well as a public certificate provided by the Stackable
248227/// [`secret-operator`](https://github.com/stackabletech/secret-operator)
249228///
250- #[ allow( clippy:: too_many_arguments) ]
251229fn build_reporting_task_job (
252- nifi : & v1alpha1:: NifiCluster ,
253230 cluster : & ValidatedCluster ,
254- resolved_product_image : & ResolvedProductImage ,
255231 cluster_info : & KubernetesClusterInfo ,
256- namespace : & NamespaceName ,
257- nifi_auth_config : & NifiAuthenticationConfig ,
258232 sa_name : & str ,
259233) -> Result < Job > {
260- let reporting_task_fqdn_service_name =
261- build_reporting_task_fqdn_service_name ( & nifi. name_any ( ) , namespace, cluster_info) ;
234+ let resolved_product_image = & cluster. image ;
235+ let nifi_auth_config = & cluster. cluster_config . authentication ;
236+ let reporting_task_fqdn_service_name = build_reporting_task_fqdn_service_name (
237+ cluster. name . as_ref ( ) ,
238+ & cluster. namespace ,
239+ cluster_info,
240+ ) ;
262241 let product_version = & resolved_product_image. product_version ;
263242 let nifi_connect_url =
264243 format ! ( "https://{reporting_task_fqdn_service_name}:{HTTPS_PORT}/nifi-api" , ) ;
@@ -305,7 +284,7 @@ fn build_reporting_task_job(
305284
306285 let job_name = format ! (
307286 "{}-create-reporting-task-{}" ,
308- nifi . name_any ( ) ,
287+ cluster . name ,
309288 product_version. replace( '.' , "-" ) . to_ascii_lowercase( )
310289 ) ;
311290
@@ -329,7 +308,7 @@ fn build_reporting_task_job(
329308 . add_container ( cb. build ( ) )
330309 . add_volume (
331310 build_tls_volume (
332- nifi ,
311+ & cluster . cluster_config . server_tls_secret_class ,
333312 REPORTING_TASK_CERT_VOLUME_NAME ,
334313 Vec :: < String > :: new ( ) ,
335314 SecretFormat :: TlsPem ,
@@ -345,13 +324,7 @@ fn build_reporting_task_job(
345324 . context ( AddVolumeSnafu ) ?
346325 . build_template ( ) ;
347326
348- pod_template. merge_from (
349- nifi. spec
350- . cluster_config
351- . create_reporting_task_job
352- . pod_overrides
353- . clone ( ) ,
354- ) ;
327+ pod_template. merge_from ( cluster. cluster_config . reporting_task_pod_overrides . clone ( ) ) ;
355328
356329 let job = Job {
357330 metadata : ObjectMetaBuilder :: new ( )
0 commit comments