@@ -846,6 +846,23 @@ fn build_node_rolegroup_service(
846
846
resolved_product_image : & ResolvedProductImage ,
847
847
rolegroup : & RoleGroupRef < v1alpha1:: NifiCluster > ,
848
848
) -> Result < Service > {
849
+ let mut enabled_ports = vec ! [ ServicePort {
850
+ name: Some ( HTTPS_PORT_NAME . to_string( ) ) ,
851
+ port: HTTPS_PORT . into( ) ,
852
+ protocol: Some ( "TCP" . to_string( ) ) ,
853
+ ..ServicePort :: default ( )
854
+ } ] ;
855
+
856
+ // NiFi 2.x.x offers nifi-api/flow/metrics/prometheus at the HTTPS_PORT, therefore METRICS_PORT is only required for NiFi 1.x.x...
857
+ if resolved_product_image. product_version . starts_with ( "1." ) {
858
+ enabled_ports. push ( ServicePort {
859
+ name : Some ( METRICS_PORT_NAME . to_string ( ) ) ,
860
+ port : METRICS_PORT . into ( ) ,
861
+ protocol : Some ( "TCP" . to_string ( ) ) ,
862
+ ..ServicePort :: default ( )
863
+ } )
864
+ }
865
+
849
866
Ok ( Service {
850
867
metadata : ObjectMetaBuilder :: new ( )
851
868
. name_and_namespace ( nifi)
@@ -865,20 +882,7 @@ fn build_node_rolegroup_service(
865
882
// Internal communication does not need to be exposed
866
883
type_ : Some ( "ClusterIP" . to_string ( ) ) ,
867
884
cluster_ip : Some ( "None" . to_string ( ) ) ,
868
- ports : Some ( vec ! [
869
- ServicePort {
870
- name: Some ( HTTPS_PORT_NAME . to_string( ) ) ,
871
- port: HTTPS_PORT . into( ) ,
872
- protocol: Some ( "TCP" . to_string( ) ) ,
873
- ..ServicePort :: default ( )
874
- } ,
875
- ServicePort {
876
- name: Some ( METRICS_PORT_NAME . to_string( ) ) ,
877
- port: METRICS_PORT . into( ) ,
878
- protocol: Some ( "TCP" . to_string( ) ) ,
879
- ..ServicePort :: default ( )
880
- } ,
881
- ] ) ,
885
+ ports : Some ( enabled_ports) ,
882
886
selector : Some (
883
887
Labels :: role_group_selector ( nifi, APP_NAME , & rolegroup. role , & rolegroup. role_group )
884
888
. context ( LabelBuildSnafu ) ?
@@ -1187,7 +1191,6 @@ async fn build_node_rolegroup_statefulset(
1187
1191
. add_container_port ( HTTPS_PORT_NAME , HTTPS_PORT . into ( ) )
1188
1192
. add_container_port ( PROTOCOL_PORT_NAME , PROTOCOL_PORT . into ( ) )
1189
1193
. add_container_port ( BALANCE_PORT_NAME , BALANCE_PORT . into ( ) )
1190
- . add_container_port ( METRICS_PORT_NAME , METRICS_PORT . into ( ) )
1191
1194
. liveness_probe ( Probe {
1192
1195
initial_delay_seconds : Some ( 10 ) ,
1193
1196
period_seconds : Some ( 10 ) ,
@@ -1209,6 +1212,11 @@ async fn build_node_rolegroup_statefulset(
1209
1212
} )
1210
1213
. resources ( merged_config. resources . clone ( ) . into ( ) ) ;
1211
1214
1215
+ // NiFi 2.x.x offers nifi-api/flow/metrics/prometheus at the HTTPS_PORT, therefore METRICS_PORT is only required for NiFi 1.x.x.
1216
+ if resolved_product_image. product_version . starts_with ( "1." ) {
1217
+ container_nifi. add_container_port ( METRICS_PORT_NAME , METRICS_PORT . into ( ) ) ;
1218
+ }
1219
+
1212
1220
let mut pod_builder = PodBuilder :: new ( ) ;
1213
1221
add_graceful_shutdown_config ( merged_config, & mut pod_builder) . context ( GracefulShutdownSnafu ) ?;
1214
1222
0 commit comments