@@ -45,7 +45,7 @@ use crate::{
4545} ;
4646
4747pub ( crate ) mod build;
48- mod dereference;
48+ pub ( crate ) mod dereference;
4949pub ( crate ) mod validate;
5050
5151pub const ZK_CONTROLLER_NAME : & str = "zookeepercluster" ;
@@ -390,138 +390,24 @@ pub fn error_policy(
390390 }
391391}
392392
393- /// Shared helpers for building validated test clusters from minimal YAML fixtures.
394- #[ cfg( test) ]
395- pub ( crate ) mod test_support {
396- use std:: str:: FromStr ;
397-
398- use stackable_operator:: {
399- cli:: OperatorEnvironmentOptions , commons:: networking:: DomainName ,
400- utils:: cluster_info:: KubernetesClusterInfo , v2:: types:: operator:: RoleGroupName ,
401- } ;
402-
403- use crate :: {
404- crd:: { ZookeeperRole , authentication:: DereferencedAuthenticationClasses , v1alpha1} ,
405- zk_controller:: {
406- dereference:: DereferencedObjects ,
407- validate:: { ValidatedCluster , ZookeeperRoleGroupConfig , validate} ,
408- } ,
409- } ;
410-
411- /// Parses a minimal `ZookeeperCluster` test fixture, defaulting `namespace`/`uid` so the
412- /// validate step can build a [`ValidatedCluster`].
413- pub fn minimal_zk ( yaml : & str ) -> v1alpha1:: ZookeeperCluster {
414- let mut zk: v1alpha1:: ZookeeperCluster =
415- serde_yaml:: from_str ( yaml) . expect ( "invalid test ZookeeperCluster YAML" ) ;
416- zk. metadata
417- . namespace
418- . get_or_insert_with ( || "default" . to_owned ( ) ) ;
419- zk. metadata
420- . uid
421- . get_or_insert_with ( || "c27b3971-ca72-42c1-80a4-abdfc1db0ddd" . to_owned ( ) ) ;
422- zk
423- }
424-
425- pub fn cluster_info ( ) -> KubernetesClusterInfo {
426- KubernetesClusterInfo {
427- cluster_domain : DomainName :: try_from ( "cluster.local" ) . expect ( "valid domain" ) ,
428- }
429- }
430-
431- fn operator_environment ( ) -> OperatorEnvironmentOptions {
432- OperatorEnvironmentOptions {
433- operator_namespace : "stackable-operators" . to_owned ( ) ,
434- operator_service_name : "zookeeper-operator" . to_owned ( ) ,
435- image_repository : "oci.example.org" . to_owned ( ) ,
436- }
437- }
438-
439- /// Runs the real validate step against a minimal (auth-free) fixture, returning the result so
440- /// tests can assert on validation errors.
441- pub fn try_validate (
442- zk : & v1alpha1:: ZookeeperCluster ,
443- ) -> Result < ValidatedCluster , super :: validate:: Error > {
444- try_validate_with_auth ( zk, DereferencedAuthenticationClasses :: new_for_tests ( ) )
445- }
446-
447- /// Runs the real validate step with caller-supplied (dereferenced) AuthenticationClasses, so
448- /// tests can exercise the client-mTLS matrix.
449- pub fn try_validate_with_auth (
450- zk : & v1alpha1:: ZookeeperCluster ,
451- authentication_classes : DereferencedAuthenticationClasses ,
452- ) -> Result < ValidatedCluster , super :: validate:: Error > {
453- validate (
454- zk,
455- & DereferencedObjects {
456- authentication_classes,
457- } ,
458- & operator_environment ( ) ,
459- )
460- }
461-
462- /// Runs the real validate step against a minimal (auth-free) fixture.
463- pub fn validated_cluster ( zk : & v1alpha1:: ZookeeperCluster ) -> ValidatedCluster {
464- try_validate ( zk) . expect ( "validate should succeed for the test fixture" )
465- }
466-
467- /// Runs the real validate step with a single TLS client-auth `AuthenticationClass`.
468- pub fn validated_cluster_with_client_auth ( zk : & v1alpha1:: ZookeeperCluster ) -> ValidatedCluster {
469- try_validate_with_auth (
470- zk,
471- DereferencedAuthenticationClasses :: new_for_tests_with_tls_client_auth ( ) ,
472- )
473- . expect ( "validate should succeed for the test fixture" )
474- }
475-
476- /// Looks up the validated, merged config of the named `server` role group together with its
477- /// parsed [`RoleGroupName`] — the standard `(name, config)` inputs to the
478- /// `build_server_rolegroup_*` functions. Panics if the group does not exist.
479- pub fn server_rolegroup_config < ' a > (
480- validated : & ' a ValidatedCluster ,
481- role_group : & str ,
482- ) -> ( RoleGroupName , & ' a ZookeeperRoleGroupConfig ) {
483- let role_group_name = RoleGroupName :: from_str ( role_group) . expect ( "valid role group name" ) ;
484- let config = validated
485- . role_group_configs
486- . get ( & ZookeeperRole :: Server )
487- . and_then ( |groups| groups. get ( & role_group_name) )
488- . unwrap_or_else ( || panic ! ( "server role group {role_group:?} should exist" ) ) ;
489- ( role_group_name, config)
490- }
491- }
492-
493393#[ cfg( test) ]
494394mod tests {
495395 use std:: collections:: { BTreeMap , BTreeSet } ;
496396
497397 use stackable_operator:: k8s_openapi:: api:: core:: v1:: ConfigMap ;
498398
499399 use super :: * ;
500- use crate :: zk_controller:: {
501- build:: properties:: zoo_cfg,
400+ use crate :: {
502401 test_support:: {
503- cluster_info, minimal_zk, server_rolegroup_config, validated_cluster,
402+ cluster_info, minimal_zk, minimal_zk_yaml , server_rolegroup_config, validated_cluster,
504403 validated_cluster_with_client_auth,
505404 } ,
506- validate:: ValidatedCluster ,
405+ zk_controller :: { build :: properties :: zoo_cfg , validate:: ValidatedCluster } ,
507406 } ;
508407
509408 #[ test]
510409 fn test_default_config ( ) {
511- let zookeeper_yaml = r#"
512- apiVersion: zookeeper.stackable.tech/v1alpha1
513- kind: ZookeeperCluster
514- metadata:
515- name: simple-zookeeper
516- spec:
517- image:
518- productVersion: "3.9.5"
519- servers:
520- roleGroups:
521- default:
522- replicas: 3
523- "# ;
524- let cm = build_config_map ( zookeeper_yaml) . data . unwrap ( ) ;
410+ let cm = build_config_map ( & minimal_zk_yaml ( 3 ) ) . data . unwrap ( ) ;
525411 let config = cm. get ( "zoo.cfg" ) . unwrap ( ) ;
526412 assert ! ( config. contains(
527413 "authProvider.x509=org.apache.zookeeper.server.auth.X509AuthenticationProvider"
@@ -581,20 +467,7 @@ mod tests {
581467 // This test (together with the TLS x client-auth matrix tests below) is the source of truth
582468 // for the rendered `zoo.cfg` / `security.properties`; the kuttl smoke keeps only the
583469 // live-cluster readiness/status checks.
584- let zookeeper_yaml = r#"
585- apiVersion: zookeeper.stackable.tech/v1alpha1
586- kind: ZookeeperCluster
587- metadata:
588- name: simple-zookeeper
589- spec:
590- image:
591- productVersion: "3.9.5"
592- servers:
593- roleGroups:
594- default:
595- replicas: 3
596- "# ;
597- let cm = build_config_map ( zookeeper_yaml) . data . unwrap ( ) ;
470+ let cm = build_config_map ( & minimal_zk_yaml ( 3 ) ) . data . unwrap ( ) ;
598471
599472 // `security.properties` is fully operator-injected; assert it byte-for-byte.
600473 assert_eq ! (
@@ -708,20 +581,7 @@ mod tests {
708581 fn test_custom_log_config_omits_logback ( ) {
709582 // Automatic logging renders `logback.xml` into the ConfigMap; a custom log ConfigMap
710583 // suppresses it (the `Custom` arm of `build_logback_config`).
711- let automatic_yaml = r#"
712- apiVersion: zookeeper.stackable.tech/v1alpha1
713- kind: ZookeeperCluster
714- metadata:
715- name: simple-zookeeper
716- spec:
717- image:
718- productVersion: "3.9.5"
719- servers:
720- roleGroups:
721- default:
722- replicas: 3
723- "# ;
724- let automatic = build_config_map ( automatic_yaml) . data . unwrap ( ) ;
584+ let automatic = build_config_map ( & minimal_zk_yaml ( 3 ) ) . data . unwrap ( ) ;
725585 assert ! ( automatic. contains_key( "logback.xml" ) ) ;
726586
727587 let custom_yaml = r#"
0 commit comments