Skip to content

Commit 8960923

Browse files
committed
Support path option on net up kubernetes
1 parent 03c7875 commit 8960923

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
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_client::client_options::ResourceControlPolicyConfig;
16-
use tempfile::{tempdir, TempDir};
1716
use tokio::process::Command;
1817
#[cfg(with_testing)]
1918
use {
@@ -71,6 +70,7 @@ pub struct LocalKubernetesNetConfig {
7170
pub docker_image_name: String,
7271
pub build_mode: BuildMode,
7372
pub policy_config: ResourceControlPolicyConfig,
73+
pub path_provider: PathProvider,
7474
}
7575

7676
/// A wrapper of [`LocalKubernetesNetConfig`] to create a shared local Kubernetes network
@@ -84,7 +84,6 @@ pub struct LocalKubernetesNet {
8484
network: Network,
8585
testing_prng_seed: Option<u64>,
8686
next_client_id: usize,
87-
tmp_dir: Arc<TempDir>,
8887
binaries: BuildArg,
8988
no_build: bool,
9089
docker_image_name: String,
@@ -93,6 +92,7 @@ pub struct LocalKubernetesNet {
9392
kind_clusters: Vec<KindCluster>,
9493
num_initial_validators: usize,
9594
num_shards: usize,
95+
path_provider: PathProvider,
9696
}
9797

9898
#[cfg(with_testing)]
@@ -115,6 +115,7 @@ impl SharedLocalKubernetesNetTestingConfig {
115115
binaries = BuildArg::Directory(binaries_dir);
116116
}
117117
}
118+
let path_provider = PathProvider::create_temporary_directory().unwrap();
118119
Self(LocalKubernetesNetConfig {
119120
network,
120121
testing_prng_seed: Some(37),
@@ -127,6 +128,7 @@ impl SharedLocalKubernetesNetTestingConfig {
127128
docker_image_name: String::from("linera:latest"),
128129
build_mode: BuildMode::Release,
129130
policy_config: ResourceControlPolicyConfig::Testnet,
131+
path_provider,
130132
})
131133
}
132134
}
@@ -159,6 +161,7 @@ impl LineraNetConfig for LocalKubernetesNetConfig {
159161
clusters,
160162
self.num_initial_validators,
161163
self.num_shards,
164+
self.path_provider,
162165
)?;
163166

164167
let client = net.make_client().await;
@@ -275,11 +278,8 @@ impl LineraNet for LocalKubernetesNet {
275278
}
276279

277280
async fn make_client(&mut self) -> ClientWrapper {
278-
let path_provider = PathProvider::TemporaryDirectory {
279-
tmp_dir: self.tmp_dir.clone(),
280-
};
281281
let client = ClientWrapper::new(
282-
path_provider,
282+
self.path_provider.clone(),
283283
self.network,
284284
self.testing_prng_seed,
285285
self.next_client_id,
@@ -338,12 +338,12 @@ impl LocalKubernetesNet {
338338
kind_clusters: Vec<KindCluster>,
339339
num_initial_validators: usize,
340340
num_shards: usize,
341+
path_provider: PathProvider,
341342
) -> Result<Self> {
342343
Ok(Self {
343344
network,
344345
testing_prng_seed,
345346
next_client_id: 0,
346-
tmp_dir: Arc::new(tempdir()?),
347347
binaries,
348348
no_build,
349349
docker_image_name,
@@ -352,19 +352,23 @@ impl LocalKubernetesNet {
352352
kind_clusters,
353353
num_initial_validators,
354354
num_shards,
355+
path_provider,
355356
})
356357
}
357358

358359
async fn command_for_binary(&self, name: &'static str) -> Result<Command> {
359360
let path = resolve_binary(name, env!("CARGO_PKG_NAME")).await?;
360361
let mut command = Command::new(path);
361-
command.current_dir(self.tmp_dir.path());
362+
command.current_dir(self.path_provider.path());
362363
Ok(command)
363364
}
364365

365366
fn configuration_string(&self, server_number: usize) -> Result<String> {
366367
let n = server_number;
367-
let path = self.tmp_dir.path().join(format!("validator_{n}.toml"));
368+
let path = self
369+
.path_provider
370+
.path()
371+
.join(format!("validator_{n}.toml"));
368372
let port = 19100 + server_number;
369373
let internal_port = 20100;
370374
let metrics_port = 21100;
@@ -442,13 +446,11 @@ impl LocalKubernetesNet {
442446
.join("kubernetes")
443447
.join("linera-validator")
444448
.join("working");
445-
fs_err::copy(
446-
self.tmp_dir.path().join("genesis.json"),
447-
base_dir.join("genesis.json"),
448-
)?;
449+
let path = self.path_provider.path();
450+
fs_err::copy(path.join("genesis.json"), base_dir.join("genesis.json"))?;
449451

450452
let kubectl_instance_clone = self.kubectl_instance.clone();
451-
let tmp_dir_path_clone = self.tmp_dir.path().to_path_buf();
453+
let tmp_dir_path_clone = path.to_path_buf();
452454
let num_shards = self.num_shards;
453455

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

linera-service/src/linera/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,7 @@ async fn run(options: &ClientOptions) -> Result<i32, Error> {
19961996
no_build,
19971997
docker_image_name,
19981998
build_mode,
1999+
path,
19992000
with_faucet,
20002001
faucet_chain,
20012002
faucet_port,
@@ -2017,6 +2018,7 @@ async fn run(options: &ClientOptions) -> Result<i32, Error> {
20172018
*faucet_chain,
20182019
*faucet_port,
20192020
*faucet_amount,
2021+
path,
20202022
)
20212023
.boxed()
20222024
.await?;

linera-service/src/linera/net_up_utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub async fn handle_net_up_kubernetes(
119119
faucet_chain: Option<u32>,
120120
faucet_port: NonZeroU16,
121121
faucet_amount: Amount,
122+
path: &Option<String>,
122123
) -> anyhow::Result<()> {
123124
if num_initial_validators < 1 {
124125
panic!("The local test network must have at least one validator.");
@@ -136,6 +137,7 @@ pub async fn handle_net_up_kubernetes(
136137
let shutdown_notifier = CancellationToken::new();
137138
tokio::spawn(listen_for_shutdown_signals(shutdown_notifier.clone()));
138139

140+
let path_provider = PathProvider::new(path)?;
139141
let config = LocalKubernetesNetConfig {
140142
network: Network::Grpc,
141143
testing_prng_seed,
@@ -148,6 +150,7 @@ pub async fn handle_net_up_kubernetes(
148150
docker_image_name,
149151
build_mode,
150152
policy_config,
153+
path_provider,
151154
};
152155
let (mut net, client) = config.instantiate().await?;
153156
let faucet_service = print_messages_and_create_faucet(

0 commit comments

Comments
 (0)