feat: Improve concurrency
This commit is contained in:
+17
-4
@@ -8,6 +8,7 @@ use crete::cluster::Cluster;
|
||||
use crete::environment::PathEnvironment;
|
||||
use crete::{get_configs_path, get_repo_path, set_repo_path};
|
||||
use futures::StreamExt;
|
||||
use futures::future::join_all;
|
||||
use minijinja::context;
|
||||
use thiserror::Error;
|
||||
use tokio::process::Command;
|
||||
@@ -69,13 +70,25 @@ async fn generate(opts: &GlobalOpts) -> Result<(), Error> {
|
||||
tokio::fs::create_dir_all(&path).await.unwrap();
|
||||
|
||||
// Generate config files
|
||||
for cluster in clusters {
|
||||
for node in cluster.nodes() {
|
||||
run_command(node.talosctl_gen_config_command(&cluster)).await;
|
||||
}
|
||||
join_all(clusters.iter().map(|cluster| async move {
|
||||
join_all(cluster.nodes().iter().map(|node| {
|
||||
let cluster = cluster.clone();
|
||||
async move {
|
||||
run_command(node.talosctl_gen_config_command(&cluster)).await;
|
||||
}
|
||||
}))
|
||||
.await;
|
||||
|
||||
// Run these commands in parallel with the the node commands
|
||||
// NOTE: These do need to happen in the correct order
|
||||
run_command(cluster.talosctl_gen_config_command()).await;
|
||||
run_command(cluster.talosctl_add_endpoint_command()).await;
|
||||
}))
|
||||
.await;
|
||||
|
||||
// Merge all the cluster talosconfig files into a single file
|
||||
// Since this all modifies the same output file this has to happen sequentially
|
||||
for cluster in clusters {
|
||||
run_command(cluster.talosctl_merge_command()).await;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user