fix(test-cluster): manage containers via testcontainers' Docker client so start/stop share one runtime#624
Conversation
…t so start/stop share one runtime
leekeiabstraction
left a comment
There was a problem hiding this comment.
Thank you for the improvements. Left some small comments.
| for name in self.container_names() { | ||
| // Anchored exact-name match; `all(false)` = running only, so a stopped | ||
| // leftover counts as absent and gets recreated. | ||
| let mut filters = HashMap::new(); | ||
| filters.insert("name".to_string(), vec![format!("^{name}$")]); | ||
| let options = ListContainersOptionsBuilder::default() | ||
| .all(false) | ||
| .filters(&filters) | ||
| .build(); | ||
| match docker.list_containers(Some(options)).await { | ||
| Ok(list) if !list.is_empty() => continue, | ||
| _ => return false, | ||
| } | ||
| } |
There was a problem hiding this comment.
nit: Seems like we're making a list_containers per-container. Anyway to make this more efficient?
There was a problem hiding this comment.
Sorry for the late reply, +1. I've already addressed it in a follow-up PR (#627).
| let mut filters = HashMap::new(); | ||
| filters.insert( | ||
| "name".to_string(), | ||
| vec![ | ||
| format!("zookeeper-{name}"), | ||
| format!("coordinator-server-{name}"), | ||
| format!("tablet-server-{name}-"), | ||
| ], | ||
| ); | ||
| let options = ListContainersOptionsBuilder::default() | ||
| .all(true) | ||
| .filters(&filters) | ||
| .build(); | ||
|
|
||
| let containers = match docker.list_containers(Some(options)).await { | ||
| Ok(containers) => containers, | ||
| Err(e) => { | ||
| eprintln!("warning: failed to list cluster containers: {e}"); | ||
| return; | ||
| } | ||
| }; |
There was a problem hiding this comment.
nit: This looks similar to parts of all_containers_exist, can these be refactored?
There was a problem hiding this comment.
I left it inline for now since the error handling differs slightly.
charlesdong1991
left a comment
There was a problem hiding this comment.
Great improvement! 👍
| let mut filters = HashMap::new(); | ||
| filters.insert( | ||
| "name".to_string(), | ||
| vec![ |
There was a problem hiding this comment.
not a concern, nor it will cause any issues here
but just add a note: when using prefix here, if two different clusters share the prefix of name (e.g. one cluster has name of test and there other has test2 or something), i think when stopping, it can accidentally stop both of them although purpose might be only stopping containers of test cluster
There was a problem hiding this comment.
Thanks for review, good catch — fixed in a follow-up PR (#627). The prefix is only used for narrowing, and removal is guarded by an exact local name check, so test and test2 won't interfere.
leekeiabstraction
left a comment
There was a problem hiding this comment.
Approving to get this improvement merged. The earlier comments from me were nits.
TY for your contribution!
Purpose
Linked issue: close #623
Brief change log
Tests
Verified against a live Podman cluster:
cargo build / cargo clippy clean for the crate (the 3 pre-existing main.rs readiness-poll lints are untouched and out of scope).
API and Format
Documentation