@@ -345,15 +345,10 @@ fn role_data_ports(role: &HdfsNodeRole, https_enabled: bool) -> Vec<(String, Por
345345
346346#[ cfg( test) ]
347347mod tests {
348- use std:: collections:: BTreeMap ;
349-
350348 use stackable_operator:: kube:: Resource ;
351349
352350 use super :: build;
353- use crate :: {
354- controller:: build:: properties:: test_support:: { self , cluster_info, validated_cluster} ,
355- test_support:: deserialize_and_validate_cluster,
356- } ;
351+ use crate :: controller:: build:: properties:: test_support:: { cluster_info, validated_cluster} ;
357352
358353 /// The sorted `metadata.name`s of a resource collection.
359354 fn sorted_names ( resources : & [ impl Resource ] ) -> Vec < String > {
@@ -365,61 +360,6 @@ mod tests {
365360 names
366361 }
367362
368- /// Every metrics Service must carry the Prometheus scrape label and the
369- /// `prometheus.io/path|port|scheme|scrape` annotations, or Prometheus stops discovering the
370- /// endpoints (caught by the HDFS smoke test 2026-07-23 after the labels migration dropped
371- /// them).
372- #[ test]
373- fn metrics_services_carry_prometheus_label_and_annotations ( ) {
374- let cluster = validated_cluster ( ) ;
375- let resources = build ( & cluster, & cluster_info ( ) ) . expect ( "build succeeds" ) ;
376-
377- let metrics_services: Vec < _ > = resources
378- . services
379- . iter ( )
380- . filter ( |service| {
381- service
382- . metadata
383- . name
384- . as_deref ( )
385- . is_some_and ( |name| name. ends_with ( "-metrics" ) )
386- } )
387- . collect ( ) ;
388- assert ! ( !metrics_services. is_empty( ) , "no metrics Services built" ) ;
389-
390- for service in metrics_services {
391- let name = service. metadata . name . as_deref ( ) . unwrap_or_default ( ) ;
392- let labels = service. metadata . labels . as_ref ( ) . expect ( "labels are set" ) ;
393- assert_eq ! (
394- labels. get( "prometheus.io/scrape" ) . map( String :: as_str) ,
395- Some ( "true" ) ,
396- "{name} lacks the scrape label"
397- ) ;
398-
399- // The native metrics port of the role, as asserted by the smoke test.
400- let expected_port = match name {
401- n if n. contains ( "-namenode-" ) => "9870" ,
402- n if n. contains ( "-datanode-" ) => "9864" ,
403- n if n. contains ( "-journalnode-" ) => "8480" ,
404- other => panic ! ( "unexpected metrics Service {other}" ) ,
405- } ;
406- let expected_annotations = BTreeMap :: from (
407- [
408- ( "prometheus.io/path" , "/prom" ) ,
409- ( "prometheus.io/port" , expected_port) ,
410- ( "prometheus.io/scheme" , "http" ) ,
411- ( "prometheus.io/scrape" , "true" ) ,
412- ]
413- . map ( |( key, value) | ( key. to_string ( ) , value. to_string ( ) ) ) ,
414- ) ;
415- assert_eq ! (
416- service. metadata. annotations. as_ref( ) ,
417- Some ( & expected_annotations) ,
418- "{name} annotations mismatch"
419- ) ;
420- }
421- }
422-
423363 /// The aggregator emits, for the minimal three-role cluster (one `default` role group each):
424364 /// one StatefulSet and one ConfigMap per role group, one headless plus one metrics Service per
425365 /// role group, and one default PDB per role.
@@ -462,6 +402,12 @@ mod tests {
462402 sorted_names( & resources. pod_disruption_budgets) ,
463403 [ "hdfs-datanode" , "hdfs-journalnode" , "hdfs-namenode" ]
464404 ) ;
405+ // The cluster-shared RBAC pair.
406+ assert_eq ! (
407+ sorted_names( & resources. service_accounts) ,
408+ [ "hdfs-serviceaccount" ]
409+ ) ;
410+ assert_eq ! ( sorted_names( & resources. role_bindings) , [ "hdfs-rolebinding" ] ) ;
465411 }
466412
467413 /// Every StatefulSet's (immutable) `serviceName` must reference a headless Service that the
@@ -486,56 +432,4 @@ mod tests {
486432 ) ;
487433 }
488434 }
489-
490- /// Locks the RBAC resource names, the roleRef, and the recommended label set against
491- /// accidental drift. The cluster name deliberately differs from the product name so that
492- /// swapped `name`/`instance` label values cannot pass unnoticed (the shared fixture is named
493- /// `hdfs`, which would mask exactly that swap).
494- #[ test]
495- fn build_produces_rbac ( ) {
496- let cluster = deserialize_and_validate_cluster (
497- & test_support:: MINIMAL_HDFS_YAML . replace ( "name: hdfs" , "name: my-hdfs" ) ,
498- ) ;
499- let resources = build ( & cluster, & cluster_info ( ) ) . expect ( "build succeeds" ) ;
500-
501- assert_eq ! (
502- sorted_names( & resources. service_accounts) ,
503- [ "my-hdfs-serviceaccount" ]
504- ) ;
505- assert_eq ! (
506- sorted_names( & resources. role_bindings) ,
507- [ "my-hdfs-rolebinding" ]
508- ) ;
509-
510- let expected_labels = BTreeMap :: from (
511- [
512- ( "app.kubernetes.io/component" , "none" ) ,
513- ( "app.kubernetes.io/instance" , "my-hdfs" ) ,
514- (
515- "app.kubernetes.io/managed-by" ,
516- "hdfs.stackable.tech_hdfs-operator-hdfs-controller" ,
517- ) ,
518- ( "app.kubernetes.io/name" , "hdfs" ) ,
519- ( "app.kubernetes.io/role-group" , "none" ) ,
520- ( "app.kubernetes.io/version" , "3.4.0-stackable0.0.0-dev" ) ,
521- ( "stackable.tech/vendor" , "Stackable" ) ,
522- ]
523- . map ( |( key, value) | ( key. to_string ( ) , value. to_string ( ) ) ) ,
524- ) ;
525- let service_account = resources
526- . service_accounts
527- . first ( )
528- . expect ( "a ServiceAccount is built" ) ;
529- assert_eq ! (
530- service_account. metadata. labels,
531- Some ( expected_labels. clone( ) )
532- ) ;
533-
534- let role_binding = resources
535- . role_bindings
536- . first ( )
537- . expect ( "a RoleBinding is built" ) ;
538- assert_eq ! ( role_binding. metadata. labels, Some ( expected_labels) ) ;
539- assert_eq ! ( role_binding. role_ref. name, "hdfs-clusterrole" ) ;
540- }
541435}
0 commit comments