Skip to content

Commit 97337fc

Browse files
committed
refactor: additional kuttl checks and fixture consolidation
1 parent 596a46a commit 97337fc

4 files changed

Lines changed: 52 additions & 18 deletions

File tree

rust/operator-binary/src/test_support.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn cluster_info() -> KubernetesClusterInfo {
6666
}
6767
}
6868

69-
fn operator_environment() -> OperatorEnvironmentOptions {
69+
pub(crate) fn operator_environment() -> OperatorEnvironmentOptions {
7070
OperatorEnvironmentOptions {
7171
operator_namespace: "stackable-operators".to_owned(),
7272
operator_service_name: "zookeeper-operator".to_owned(),

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,10 @@ mod tests {
754754
#[test]
755755
fn vector_agent_adds_vector_container_to_statefulset() {
756756
// Enabling the Vector agent wires a `vector` sidecar onto the StatefulSet, mounting the
757-
// `config` (for `vector.yaml`) and `log` volumes. Its env vars come from the upstream
758-
// `vector_container` helper, so this pins only the seam this operator owns: that the sidecar
759-
// is added when the agent is enabled.
757+
// `config` (for `vector.yaml`) and `log` volumes. The env var format comes from the
758+
// upstream `vector_container` helper, but the identity values (cluster/role/role-group) and
759+
// the aggregator ConfigMap reference are wiring this operator supplies, so those are pinned
760+
// here (they were previously only checked by the kuttl smoke `14-assert` heredoc).
760761
let sts = build_sts(
761762
r#"
762763
apiVersion: zookeeper.stackable.tech/v1alpha1
@@ -807,6 +808,31 @@ mod tests {
807808
mount_names.contains(&LOG_VOLUME_NAME.as_ref()),
808809
"vector container missing `log` volume mount: {mount_names:?}"
809810
);
811+
812+
// Identity wiring this operator passes into the upstream `vector_container` helper.
813+
let env = vector.env.as_ref().expect("vector container env");
814+
let env_value = |name: &str| {
815+
env.iter()
816+
.find(|e| e.name == name)
817+
.unwrap_or_else(|| panic!("vector env {name} missing"))
818+
.value
819+
.as_deref()
820+
};
821+
assert_eq!(env_value("CLUSTER_NAME"), Some("simple-zookeeper"));
822+
assert_eq!(env_value("ROLE_NAME"), Some("server"));
823+
assert_eq!(env_value("ROLE_GROUP_NAME"), Some("default"));
824+
825+
// The aggregator address resolves from the discovery ConfigMap named in `clusterConfig`.
826+
let aggregator = env
827+
.iter()
828+
.find(|e| e.name == "VECTOR_AGGREGATOR_ADDRESS")
829+
.expect("VECTOR_AGGREGATOR_ADDRESS env var")
830+
.value_from
831+
.as_ref()
832+
.and_then(|source| source.config_map_key_ref.as_ref())
833+
.expect("VECTOR_AGGREGATOR_ADDRESS resolved from a ConfigMap key");
834+
assert_eq!(aggregator.name, "vector-aggregator-discovery");
835+
assert_eq!(aggregator.key, "ADDRESS");
810836
}
811837

812838
#[test]

rust/operator-binary/src/znode_controller/validate.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,10 @@ pub fn validate(
208208
/// (product version, `zookeeper_security`, identity) matches production.
209209
#[cfg(test)]
210210
pub(crate) mod test_support {
211-
use stackable_operator::cli::OperatorEnvironmentOptions;
212-
213211
use super::{ValidatedZnode, validate};
214212
use crate::{
215213
crd::{authentication::DereferencedAuthenticationClasses, v1alpha1},
216-
test_support::minimal_zk,
214+
test_support::{minimal_zk, operator_environment},
217215
znode_controller::dereference::DereferencedObjects,
218216
};
219217

@@ -233,14 +231,6 @@ pub(crate) mod test_support {
233231
znode
234232
}
235233

236-
fn operator_environment() -> OperatorEnvironmentOptions {
237-
OperatorEnvironmentOptions {
238-
operator_namespace: "stackable-operators".to_owned(),
239-
operator_service_name: "zookeeper-operator".to_owned(),
240-
image_repository: "oci.example.org".to_owned(),
241-
}
242-
}
243-
244234
/// Runs the real znode validate step against a minimal znode fixture and the given
245235
/// `ZookeeperCluster` YAML (which controls product version and `zookeeper_security`).
246236
pub fn validated_znode(znode: &v1alpha1::ZookeeperZnode, zk_yaml: &str) -> ValidatedZnode {

tests/templates/kuttl/smoke/13-assert.yaml.j2

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
#
88
# * the StatefulSets actually reconciled to a running state (status.readyReplicas)
99
# * the data PVCs were provisioned and bound (status.phase: Bound)
10-
# * the PDB this operator builds is actually applied (bare existence)
10+
# * the PDB this operator builds is applied and matched the running server pods
11+
# (status.expectedPods)
12+
# * the metrics Services this operator builds actually reconciled (bare existence
13+
# per role group): readiness does not depend on them, so a unit test alone would
14+
# not catch a reconcile that stopped emitting them
1115
# * the resources this operator does NOT build itself exist at runtime:
1216
# - the cluster-internal `test-zk-server` Service (created by the
1317
# listener-operator from the Listener object)
@@ -33,12 +37,26 @@ status:
3337
readyReplicas: 1
3438
replicas: 1
3539
---
36-
# Built by this operator; its shape is unit-tested in pdb.rs. Kept here as a bare
37-
# existence check so the smoke test still proves the PDB is actually applied.
40+
# Built by this operator; its shape is unit-tested in pdb.rs. Kept here to prove the
41+
# PDB is applied and that k8s matched it against the 3 running server pods.
3842
apiVersion: policy/v1
3943
kind: PodDisruptionBudget
4044
metadata:
4145
name: test-zk-server
46+
status:
47+
expectedPods: 3
48+
---
49+
# Metrics Services built by this operator (shape unit-tested in service.rs); one bare
50+
# existence check per role group so a reconcile that stopped emitting them fails here.
51+
apiVersion: v1
52+
kind: Service
53+
metadata:
54+
name: test-zk-server-primary-metrics
55+
---
56+
apiVersion: v1
57+
kind: Service
58+
metadata:
59+
name: test-zk-server-secondary-metrics
4260
---
4361
# Created at runtime by the listener-operator, not by this operator's build code.
4462
apiVersion: v1

0 commit comments

Comments
 (0)