|
|
@@ -204,23 +204,32 @@ pub async fn stop_cluster(
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
-/// Find the cluster that has running containers for a recipe by querying
|
|
|
-/// the `sm121.cluster` label. Used by stop/logs when `--cluster auto`.
|
|
|
+/// Find the cluster that has running containers for a recipe by reading
|
|
|
+/// the `sm121.cluster` label from live containers. Used by stop/logs
|
|
|
+/// when `--cluster auto`.
|
|
|
pub async fn resolve_cluster_by_container_label<'c>(
|
|
|
config: &'c Config,
|
|
|
recipe_name: &str,
|
|
|
) -> Result<&'c Cluster> {
|
|
|
- for cluster in &config.clusters {
|
|
|
- for node in &cluster.nodes {
|
|
|
- let cmd = format!(
|
|
|
- "docker ps -q --filter \"label=sm121.recipe={}\" \
|
|
|
- --format '{{{{.Names}}}}' | head -1",
|
|
|
- recipe_name
|
|
|
- );
|
|
|
- if let Ok(output) = run_ssh(config, node, cmd, false).await
|
|
|
- && !output.trim().is_empty()
|
|
|
- {
|
|
|
- return Ok(cluster);
|
|
|
+ // Scan all nodes for containers matching this recipe.
|
|
|
+ for node in config.clusters.iter().flat_map(|c| &c.nodes) {
|
|
|
+ let cmd = format!(
|
|
|
+ "docker ps -q --filter \"label=sm121.recipe={}\" \
|
|
|
+ --format '{{{{.Label \"sm121.cluster\"}}}}' | head -1",
|
|
|
+ recipe_name
|
|
|
+ );
|
|
|
+ if let Ok(output) = run_ssh(config, node, cmd, false).await {
|
|
|
+ let cluster_label = output.trim();
|
|
|
+ if !cluster_label.is_empty() {
|
|
|
+ // Found a container — match its cluster label against config.
|
|
|
+ return config
|
|
|
+ .clusters
|
|
|
+ .iter()
|
|
|
+ .find(|c| c.name == cluster_label)
|
|
|
+ .context(format!(
|
|
|
+ "Container label says cluster '{}', but no such cluster in config",
|
|
|
+ cluster_label
|
|
|
+ ));
|
|
|
}
|
|
|
}
|
|
|
}
|