Skip to content

Commit bd40849

Browse files
committed
Stores: Default impl
Mostly this makes testing nicer; now a new field doesn't have to be added to state.rs's test fixture every time a new reflector is added.
1 parent 152ff9a commit bd40849

2 files changed

Lines changed: 12 additions & 21 deletions

File tree

metrics-cache/src/ingest/reflectors.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ macro_rules! define_reflectors {
7070
}
7171
}
7272

73+
impl Default for Stores {
74+
fn default() -> Self {
75+
Self {
76+
healths: Default::default(),
77+
$(
78+
$field: kube::runtime::reflector::store().0,
79+
)*
80+
}
81+
}
82+
}
83+
7384
#[derive(Debug)]
7485
pub struct FrozenStores {
7586
$(

metrics-cache/src/state.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,9 @@ pub mod tests {
9292
}
9393

9494
pub fn test_app_state_with_validator(client: MockValidator) -> AppState<MockValidator> {
95-
let (pod_store, _) = kube::runtime::reflector::store();
96-
let (node_store, _) = kube::runtime::reflector::store();
97-
let (deployment_store, _) = kube::runtime::reflector::store();
98-
let (daemonset_store, _) = kube::runtime::reflector::store();
99-
let (namespace_store, _) = kube::runtime::reflector::store();
100-
let (replicaset_store, _) = kube::runtime::reflector::store();
101-
let (persistent_volume_store, _) = kube::runtime::reflector::store();
102-
let (persistent_volume_claim_store, _) = kube::runtime::reflector::store();
103-
let (statefulset_store, _) = kube::runtime::reflector::store();
10495
AppState {
10596
client,
106-
stores: Stores {
107-
pods: pod_store,
108-
nodes: node_store,
109-
deployments: deployment_store,
110-
daemonsets: daemonset_store,
111-
namespaces: namespace_store,
112-
replicasets: replicaset_store,
113-
persistent_volumes: persistent_volume_store,
114-
persistent_volume_claims: persistent_volume_claim_store,
115-
statefulsets: statefulset_store,
116-
healths: Default::default(),
117-
},
97+
stores: Default::default(),
11898
reader_allowlist: vec!["test-ns:test-reader".to_string()],
11999
writer_allowlist: vec!["test-ns:test-writer".to_string()],
120100
kubelet_stats_summary_cache: Cache::builder()

0 commit comments

Comments
 (0)