Skip to content

Commit 29f71f8

Browse files
committed
clean up
1 parent 68248a5 commit 29f71f8

4 files changed

Lines changed: 34 additions & 78 deletions

File tree

rust/operator-binary/src/crd/authentication.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,9 @@ impl DereferencedAuthenticationClasses {
132132
}
133133
}
134134

135-
/// USE ONLY IN TESTS! Builds a [`DereferencedAuthenticationClasses`] holding a single TLS
136-
/// `AuthenticationClass`, mirroring the `use-client-auth-tls` kuttl scenario. This exercises the
137-
/// client-mTLS branches of [`crate::crd::security::ZookeeperSecurity`] (secure client port and
138-
/// `ssl.clientAuth=need`), including the case where server TLS is otherwise disabled and the
135+
/// Builds a [`DereferencedAuthenticationClasses`] holding a single TLS `AuthenticationClass`.
136+
/// Exercises the client-mTLS branches of [`crate::crd::security::ZookeeperSecurity`] (secure
137+
/// client port and `ssl.clientAuth=need`), including the case where server TLS is off and the
139138
/// auth class alone turns TLS on.
140139
#[cfg(test)]
141140
pub fn new_for_tests_with_tls_client_auth() -> Self {

rust/operator-binary/src/zk_controller.rs

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,7 @@ pub(crate) mod test_support {
464464
try_validate(zk).expect("validate should succeed for the test fixture")
465465
}
466466

467-
/// Runs the real validate step with a single TLS client-auth `AuthenticationClass`, mirroring
468-
/// the `use-client-auth-tls` kuttl scenario.
467+
/// Runs the real validate step with a single TLS client-auth `AuthenticationClass`.
469468
pub fn validated_cluster_with_client_auth(zk: &v1alpha1::ZookeeperCluster) -> ValidatedCluster {
470469
try_validate_with_auth(
471470
zk,
@@ -778,43 +777,16 @@ mod tests {
778777
fn test_vector_config_absent_when_agent_disabled() {
779778
// Default logging has the Vector agent disabled, so no `vector.yaml` is added to the
780779
// ConfigMap. Pins the negative branch alongside `test_vector_agent_adds_vector_config`.
781-
let zookeeper_yaml = r#"
782-
apiVersion: zookeeper.stackable.tech/v1alpha1
783-
kind: ZookeeperCluster
784-
metadata:
785-
name: simple-zookeeper
786-
spec:
787-
image:
788-
productVersion: "3.9.5"
789-
servers:
790-
roleGroups:
791-
default:
792-
replicas: 3
793-
"#;
794-
let cm = build_config_map(zookeeper_yaml).data.unwrap();
780+
let cm = build_config_map(SERVER_TLS_YAML).data.unwrap();
795781
assert!(!cm.contains_key("vector.yaml"));
796782
}
797783

798784
#[test]
799785
fn test_logback_default_structure() {
800786
// Pins the structural parts of the rendered `logback.xml` that this operator controls (log
801-
// dir + file name, console conversion pattern, max file size, appender wiring). This is the
802-
// source of truth that used to live in the kuttl smoke `14-assert` heredoc; the levels are
803-
// covered separately by `test_logback_renders_zookeeper_container_log_levels`.
804-
let zookeeper_yaml = r#"
805-
apiVersion: zookeeper.stackable.tech/v1alpha1
806-
kind: ZookeeperCluster
807-
metadata:
808-
name: simple-zookeeper
809-
spec:
810-
image:
811-
productVersion: "3.9.5"
812-
servers:
813-
roleGroups:
814-
default:
815-
replicas: 3
816-
"#;
817-
let cm = build_config_map(zookeeper_yaml).data.unwrap();
787+
// dir + file name, console conversion pattern, max file size, appender wiring). The levels
788+
// are covered separately by `test_logback_renders_zookeeper_container_log_levels`.
789+
let cm = build_config_map(SERVER_TLS_YAML).data.unwrap();
818790
let logback = cm.get("logback.xml").unwrap();
819791

820792
// Console appender + the operator's conversion pattern.
@@ -928,18 +900,14 @@ mod tests {
928900
}
929901

930902
// ---------------------------------------------------------------------------------------------
931-
// TLS x client-auth matrix (candidate #1 in unit-tests.md).
903+
// TLS x client-auth matrix.
932904
//
933-
// These four tests own what the kuttl smoke `14-assert` `zoo.cfg` heredoc used to assert across
934-
// the `use-server-tls` x `use-client-auth-tls` scenario matrix: the exact set of `zoo.cfg`
935-
// properties and the ports/`ssl.*` lines that vary with TLS and client mTLS. They assert on the
936-
// structured key/value map produced by the pure `zoo_cfg::build` seam (via `zoo_cfg_map`) rather
937-
// than re-parsing rendered text, so key sets and values are compared exactly. Asserting the full
938-
// key set catches accidentally added *or* removed properties, and makes the negative cases
939-
// (`ssl.clientAuth` absent, etc.) fall out of the set equality instead of needing brittle
940-
// `!contains` checks. Only two fixtures are needed: server TLS on vs. off. Client mTLS is layered
941-
// on via `validated_cluster_with_client_auth`, which the previous `new_for_tests()` path could
942-
// not reach.
905+
// These four tests own the `zoo.cfg` TLS/client-mTLS matrix the kuttl smoke `14-assert` heredoc
906+
// used to check: the exact property key set plus the ports/`ssl.*` lines that vary with server
907+
// TLS and client mTLS. They assert on the structured map from the pure `zoo_cfg::build` seam
908+
// (via `zoo_cfg_map`), so the full key set compares exactly: a missing or extra property fails
909+
// set equality, with no brittle `!contains` checks. Server TLS is toggled by the two fixtures;
910+
// client mTLS is layered on via `validated_cluster_with_client_auth`.
943911
// ---------------------------------------------------------------------------------------------
944912

945913
/// Server role group with default TLS (server `AuthenticationClass` off, server TLS on).
@@ -1112,8 +1080,8 @@ mod tests {
11121080
}
11131081

11141082
/// `server.<myid>` quorum lines are rendered into the per-rolegroup `zoo.cfg` with
1115-
/// `myidOffset` applied and colons escaped, aggregated across *all* server role groups. Mirrors
1116-
/// the kuttl smoke `14-assert` `server.N` lines (primary offset 10, secondary offset 20).
1083+
/// `myidOffset` applied and colons escaped, aggregated across *all* server role groups
1084+
/// (primary offset 10, secondary offset 20).
11171085
#[test]
11181086
fn test_server_lines_use_myid_offset_across_rolegroups() {
11191087
let zk = minimal_zk(

rust/operator-binary/src/zk_controller/build/jvm.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,16 @@ fn is_heap_jvm_argument(jvm_argument: &str) -> bool {
8181

8282
#[cfg(test)]
8383
mod tests {
84-
use std::str::FromStr;
85-
86-
use stackable_operator::v2::types::operator::RoleGroupName;
87-
8884
use super::*;
8985
use crate::{
90-
crd::{ZookeeperRole, v1alpha1::ZookeeperCluster},
91-
zk_controller::test_support::{minimal_zk, validated_cluster},
86+
crd::v1alpha1::ZookeeperCluster,
87+
zk_controller::test_support::{minimal_zk, server_rolegroup_config, validated_cluster},
9288
};
9389

9490
/// The validated, merged config for the `default` server role group.
9591
fn server_default(zk: &ZookeeperCluster) -> ZookeeperRoleGroupConfig {
96-
let default_group = RoleGroupName::from_str("default").expect("valid role group name");
97-
validated_cluster(zk)
98-
.role_group_configs
99-
.get(&ZookeeperRole::Server)
100-
.and_then(|groups| groups.get(&default_group))
101-
.expect("server default role group should exist")
92+
server_rolegroup_config(&validated_cluster(zk), "default")
93+
.1
10294
.clone()
10395
}
10496

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,12 @@ mod tests {
530530
}
531531

532532
// ---------------------------------------------------------------------------------------------
533-
// StatefulSet resource shapes (candidate #2 in unit-tests.md).
533+
// StatefulSet resource shapes.
534534
//
535-
// These own what the kuttl smoke `13-assert` asserted on the StatefulSet spec/metadata:
536-
// replicas, `podManagementPolicy`, `serviceName`, graceful-shutdown period, container resources
537-
// (including the `podOverrides` merge), the `data`/`listener` PVC templates and the heap env var
538-
// (which also covers candidate #7's `test_heap.sh`). The `status:` stanza (`readyReplicas`) is a
539-
// runtime signal and stays in kuttl.
535+
// These own what the kuttl smoke `13-assert` checked on the StatefulSet spec/metadata: replicas,
536+
// `podManagementPolicy`, `serviceName`, graceful-shutdown period, container resources (incl. the
537+
// `podOverrides` merge), the `data`/`listener` PVC templates and the heap env var. The `status:`
538+
// stanza (`readyReplicas`) is a runtime signal and stays in kuttl.
540539
// ---------------------------------------------------------------------------------------------
541540

542541
fn build_sts(yaml: &str, role_group: &str) -> StatefulSet {
@@ -752,8 +751,8 @@ mod tests {
752751

753752
#[test]
754753
fn statefulset_sets_zk_server_heap_env() {
755-
// Candidate #7: the heap value computed in jvm.rs lands on the STS as `ZK_SERVER_HEAP`.
756-
// The 512Mi default memory limit x 0.8 -> 409 MiB (pinned by the jvm.rs unit tests).
754+
// The heap value computed in jvm.rs lands on the STS as `ZK_SERVER_HEAP`:
755+
// 512Mi default memory limit x 0.8 -> 409 MiB (calculation pinned by the jvm.rs tests).
757756
let sts = build_sts(
758757
r#"
759758
apiVersion: zookeeper.stackable.tech/v1alpha1
@@ -784,10 +783,9 @@ mod tests {
784783
#[test]
785784
fn vector_agent_adds_vector_container_to_statefulset() {
786785
// Enabling the Vector agent wires a `vector` sidecar onto the StatefulSet, mounting the
787-
// `config` (for `vector.yaml`) and `log` volumes. The env vars the sidecar carries are set
788-
// by the upstream `vector_container` helper, so this only pins the wiring seam this operator
789-
// owns: that the sidecar is added at all when the agent is enabled. Without the agent, no
790-
// such container exists.
786+
// `config` (for `vector.yaml`) and `log` volumes. Its env vars come from the upstream
787+
// `vector_container` helper, so this pins only the seam this operator owns: that the sidecar
788+
// is added when the agent is enabled.
791789
let sts = build_sts(
792790
r#"
793791
apiVersion: zookeeper.stackable.tech/v1alpha1
@@ -877,10 +875,9 @@ mod tests {
877875

878876
#[test]
879877
fn env_overrides_apply_with_role_group_precedence() {
880-
// Candidate #4: `envOverrides` land on the zookeeper container, with the rolegroup value
881-
// winning over the role value on conflict. Mirrors the kuttl smoke `11-assert` setup:
882-
// COMMON_VAR is set at both levels (group wins), ROLE_VAR only at the role, GROUP_VAR only
883-
// at the group.
878+
// `envOverrides` land on the zookeeper container, with the rolegroup value winning over the
879+
// role value on conflict: COMMON_VAR is set at both levels (group wins), ROLE_VAR only at
880+
// the role, GROUP_VAR only at the group.
884881
let sts = build_sts(
885882
r#"
886883
apiVersion: zookeeper.stackable.tech/v1alpha1

0 commit comments

Comments
 (0)