Skip to content

Commit bf76757

Browse files
committed
Support path option on net up kubernetes
1 parent c792495 commit bf76757

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
@@ -1633,7 +1633,7 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
16331633
binaries,
16341634
no_build,
16351635
docker_image_name,
1636-
path: _,
1636+
path,
16371637
storage: _,
16381638
external_protocol: _,
16391639
with_faucet_chain,
@@ -1654,6 +1654,7 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
16541654
*with_faucet_chain,
16551655
*faucet_port,
16561656
*faucet_amount,
1657+
path,
16571658
)
16581659
.boxed()
16591660
.await?;

linera-service/src/linera/net_up_utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub async fn handle_net_up_kubernetes(
117117
with_faucet_chain: Option<u32>,
118118
faucet_port: NonZeroU16,
119119
faucet_amount: Amount,
120+
path: &Option<String>,
120121
) -> anyhow::Result<()> {
121122
if num_initial_validators < 1 {
122123
panic!("The local test network must have at least one validator.");
@@ -128,6 +129,7 @@ pub async fn handle_net_up_kubernetes(
128129
let shutdown_notifier = CancellationToken::new();
129130
tokio::spawn(listen_for_shutdown_signals(shutdown_notifier.clone()));
130131

132+
let path_provider = PathProvider::new(path)?;
131133
let config = LocalKubernetesNetConfig {
132134
network: Network::Grpc,
133135
testing_prng_seed,
@@ -139,6 +141,7 @@ pub async fn handle_net_up_kubernetes(
139141
no_build,
140142
docker_image_name,
141143
policy,
144+
path_provider,
142145
};
143146
let (mut net, client) = config.instantiate().await?;
144147
let faucet_service = create_wallets_and_faucets(

0 commit comments

Comments
 (0)