Skip to content

Commit 4b4da1c

Browse files
committed
Support path option on net up kubernetes
1 parent d158401 commit 4b4da1c

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

linera-service/src/cli_wrappers/local_kubernetes_net.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use linera_base::{
1313
data_types::Amount,
1414
};
1515
use linera_execution::ResourceControlPolicy;
16-
use tempfile::{tempdir, TempDir};
1716
use tokio::process::Command;
1817
#[cfg(with_testing)]
1918
use {
@@ -49,6 +48,7 @@ pub struct LocalKubernetesNetConfig {
4948
pub no_build: bool,
5049
pub docker_image_name: String,
5150
pub policy: ResourceControlPolicy,
51+
pub path_provider: PathProvider,
5252
}
5353

5454
/// A wrapper of [`LocalKubernetesNetConfig`] to create a shared local Kubernetes network
@@ -62,14 +62,14 @@ pub struct LocalKubernetesNet {
6262
network: Network,
6363
testing_prng_seed: Option<u64>,
6464
next_client_id: usize,
65-
tmp_dir: Arc<TempDir>,
6665
binaries: BuildArg,
6766
no_build: bool,
6867
docker_image_name: String,
6968
kubectl_instance: Arc<Mutex<KubectlInstance>>,
7069
kind_clusters: Vec<KindCluster>,
7170
num_initial_validators: usize,
7271
num_shards: usize,
72+
path_provider: PathProvider,
7373
}
7474

7575
#[cfg(with_testing)]
@@ -92,6 +92,7 @@ impl SharedLocalKubernetesNetTestingConfig {
9292
binaries = BuildArg::Directory(binaries_dir);
9393
}
9494
}
95+
let path_provider = PathProvider::create_temporary_directory().unwrap();
9596
Self(LocalKubernetesNetConfig {
9697
network,
9798
testing_prng_seed: Some(37),
@@ -103,6 +104,7 @@ impl SharedLocalKubernetesNetTestingConfig {
103104
no_build: false,
104105
docker_image_name: String::from("linera:latest"),
105106
policy: ResourceControlPolicy::devnet(),
107+
path_provider,
106108
})
107109
}
108110
}
@@ -134,6 +136,7 @@ impl LineraNetConfig for LocalKubernetesNetConfig {
134136
clusters,
135137
self.num_initial_validators,
136138
self.num_shards,
139+
self.path_provider,
137140
)?;
138141

139142
let client = net.make_client().await;
@@ -257,11 +260,8 @@ impl LineraNet for LocalKubernetesNet {
257260
}
258261

259262
async fn make_client(&mut self) -> ClientWrapper {
260-
let path_provider = PathProvider::TemporaryDirectory {
261-
tmp_dir: self.tmp_dir.clone(),
262-
};
263263
let client = ClientWrapper::new(
264-
path_provider,
264+
self.path_provider.clone(),
265265
self.network,
266266
self.testing_prng_seed,
267267
self.next_client_id,
@@ -319,32 +319,36 @@ impl LocalKubernetesNet {
319319
kind_clusters: Vec<KindCluster>,
320320
num_initial_validators: usize,
321321
num_shards: usize,
322+
path_provider: PathProvider,
322323
) -> Result<Self> {
323324
Ok(Self {
324325
network,
325326
testing_prng_seed,
326327
next_client_id: 0,
327-
tmp_dir: Arc::new(tempdir()?),
328328
binaries,
329329
no_build,
330330
docker_image_name,
331331
kubectl_instance: Arc::new(Mutex::new(kubectl_instance)),
332332
kind_clusters,
333333
num_initial_validators,
334334
num_shards,
335+
path_provider,
335336
})
336337
}
337338

338339
async fn command_for_binary(&self, name: &'static str) -> Result<Command> {
339340
let path = resolve_binary(name, env!("CARGO_PKG_NAME")).await?;
340341
let mut command = Command::new(path);
341-
command.current_dir(self.tmp_dir.path());
342+
command.current_dir(self.path_provider.path());
342343
Ok(command)
343344
}
344345

345346
fn configuration_string(&self, server_number: usize) -> Result<String> {
346347
let n = server_number;
347-
let path = self.tmp_dir.path().join(format!("validator_{n}.toml"));
348+
let path = self
349+
.path_provider
350+
.path()
351+
.join(format!("validator_{n}.toml"));
348352
let port = 19100 + server_number;
349353
let internal_port = 20100;
350354
let metrics_port = 21100;
@@ -418,13 +422,11 @@ impl LocalKubernetesNet {
418422
.join("kubernetes")
419423
.join("linera-validator")
420424
.join("working");
421-
fs_err::copy(
422-
self.tmp_dir.path().join("genesis.json"),
423-
base_dir.join("genesis.json"),
424-
)?;
425+
let path = self.path_provider.path();
426+
fs_err::copy(path.join("genesis.json"), base_dir.join("genesis.json"))?;
425427

426428
let kubectl_instance_clone = self.kubectl_instance.clone();
427-
let tmp_dir_path_clone = self.tmp_dir.path().to_path_buf();
429+
let tmp_dir_path_clone = path.to_path_buf();
428430
let num_shards = self.num_shards;
429431

430432
let mut validators_initialization_futures = Vec::new();

linera-service/src/linera/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
16151615
binaries,
16161616
no_build,
16171617
docker_image_name,
1618-
path: _,
1618+
path,
16191619
storage: _,
16201620
external_protocol: _,
16211621
} => {
@@ -1630,6 +1630,7 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
16301630
*no_build,
16311631
docker_image_name.clone(),
16321632
policy_config.into_policy(),
1633+
path,
16331634
)
16341635
.boxed()
16351636
.await?;

linera-service/src/linera/net_up_utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ pub async fn handle_net_up_kubernetes(
113113
no_build: bool,
114114
docker_image_name: String,
115115
policy: ResourceControlPolicy,
116+
path: &Option<String>,
116117
) -> anyhow::Result<()> {
117118
if num_initial_validators < 1 {
118119
panic!("The local test network must have at least one validator.");
@@ -124,6 +125,7 @@ pub async fn handle_net_up_kubernetes(
124125
let shutdown_notifier = CancellationToken::new();
125126
tokio::spawn(listen_for_shutdown_signals(shutdown_notifier.clone()));
126127

128+
let path_provider = PathProvider::new(path)?;
127129
let config = LocalKubernetesNetConfig {
128130
network: Network::Grpc,
129131
testing_prng_seed,
@@ -135,6 +137,7 @@ pub async fn handle_net_up_kubernetes(
135137
no_build,
136138
docker_image_name,
137139
policy,
140+
path_provider,
138141
};
139142
let (mut net, client1) = config.instantiate().await?;
140143
net_up(extra_wallets, &mut net, client1).await?;

0 commit comments

Comments
 (0)