Skip to content

Commit 3915f61

Browse files
committed
Support path option on net up kubernetes
1 parent 47f336f commit 3915f61

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

linera-service/src/cli/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,7 @@ async fn run(options: &ClientOptions) -> Result<i32, Error> {
18931893
no_build,
18941894
docker_image_name,
18951895
build_mode,
1896+
path,
18961897
with_faucet,
18971898
faucet_chain,
18981899
faucet_port,
@@ -1916,6 +1917,7 @@ async fn run(options: &ClientOptions) -> Result<i32, Error> {
19161917
*faucet_port,
19171918
*faucet_amount,
19181919
*dual_store,
1920+
path,
19191921
)
19201922
.boxed()
19211923
.await?;

linera-service/src/cli/net_up_utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pub async fn handle_net_up_kubernetes(
123123
faucet_port: NonZeroU16,
124124
faucet_amount: Amount,
125125
dual_store: bool,
126+
path: &Option<String>,
126127
) -> anyhow::Result<()> {
127128
if num_initial_validators < 1 {
128129
panic!("The local test network must have at least one validator.");
@@ -140,6 +141,7 @@ pub async fn handle_net_up_kubernetes(
140141
let shutdown_notifier = CancellationToken::new();
141142
tokio::spawn(listen_for_shutdown_signals(shutdown_notifier.clone()));
142143

144+
let path_provider = PathProvider::new(path)?;
143145
let config = LocalKubernetesNetConfig {
144146
network: Network::Grpc,
145147
testing_prng_seed,
@@ -153,6 +155,7 @@ pub async fn handle_net_up_kubernetes(
153155
build_mode,
154156
policy_config,
155157
dual_store,
158+
path_provider,
156159
};
157160
let (mut net, client) = config.instantiate().await?;
158161
let faucet_service = print_messages_and_create_faucet(

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 {linera_base::command::current_binary_parent, tokio::sync::OnceCell};
@@ -69,6 +68,7 @@ pub struct LocalKubernetesNetConfig {
6968
pub build_mode: BuildMode,
7069
pub policy_config: ResourceControlPolicyConfig,
7170
pub dual_store: bool,
71+
pub path_provider: PathProvider,
7272
}
7373

7474
/// A wrapper of [`LocalKubernetesNetConfig`] to create a shared local Kubernetes network
@@ -82,7 +82,6 @@ pub struct LocalKubernetesNet {
8282
network: Network,
8383
testing_prng_seed: Option<u64>,
8484
next_client_id: usize,
85-
tmp_dir: Arc<TempDir>,
8685
binaries: BuildArg,
8786
no_build: bool,
8887
docker_image_name: String,
@@ -92,6 +91,7 @@ pub struct LocalKubernetesNet {
9291
num_initial_validators: usize,
9392
num_shards: usize,
9493
dual_store: bool,
94+
path_provider: PathProvider,
9595
}
9696

9797
#[cfg(with_testing)]
@@ -114,6 +114,7 @@ impl SharedLocalKubernetesNetTestingConfig {
114114
binaries = BuildArg::Directory(binaries_dir);
115115
}
116116
}
117+
let path_provider = PathProvider::create_temporary_directory().unwrap();
117118
Self(LocalKubernetesNetConfig {
118119
network,
119120
testing_prng_seed: Some(37),
@@ -127,6 +128,7 @@ impl SharedLocalKubernetesNetTestingConfig {
127128
build_mode: BuildMode::Release,
128129
policy_config: ResourceControlPolicyConfig::Testnet,
129130
dual_store: false,
131+
path_provider,
130132
})
131133
}
132134
}
@@ -160,6 +162,7 @@ impl LineraNetConfig for LocalKubernetesNetConfig {
160162
self.num_initial_validators,
161163
self.num_shards,
162164
self.dual_store,
165+
self.path_provider,
163166
)?;
164167

165168
let client = net.make_client().await;
@@ -276,11 +279,8 @@ impl LineraNet for LocalKubernetesNet {
276279
}
277280

278281
async fn make_client(&mut self) -> ClientWrapper {
279-
let path_provider = PathProvider::TemporaryDirectory {
280-
tmp_dir: self.tmp_dir.clone(),
281-
};
282282
let client = ClientWrapper::new(
283-
path_provider,
283+
self.path_provider.clone(),
284284
self.network,
285285
self.testing_prng_seed,
286286
self.next_client_id,
@@ -340,12 +340,12 @@ impl LocalKubernetesNet {
340340
num_initial_validators: usize,
341341
num_shards: usize,
342342
dual_store: bool,
343+
path_provider: PathProvider,
343344
) -> Result<Self> {
344345
Ok(Self {
345346
network,
346347
testing_prng_seed,
347348
next_client_id: 0,
348-
tmp_dir: Arc::new(tempdir()?),
349349
binaries,
350350
no_build,
351351
docker_image_name,
@@ -355,19 +355,23 @@ impl LocalKubernetesNet {
355355
num_initial_validators,
356356
num_shards,
357357
dual_store,
358+
path_provider,
358359
})
359360
}
360361

361362
async fn command_for_binary(&self, name: &'static str) -> Result<Command> {
362363
let path = resolve_binary(name, env!("CARGO_PKG_NAME")).await?;
363364
let mut command = Command::new(path);
364-
command.current_dir(self.tmp_dir.path());
365+
command.current_dir(self.path_provider.path());
365366
Ok(command)
366367
}
367368

368369
fn configuration_string(&self, server_number: usize) -> Result<String> {
369370
let n = server_number;
370-
let path = self.tmp_dir.path().join(format!("validator_{n}.toml"));
371+
let path = self
372+
.path_provider
373+
.path()
374+
.join(format!("validator_{n}.toml"));
371375
let port = 19100 + server_number;
372376
let internal_port = 20100;
373377
let metrics_port = 21100;
@@ -450,13 +454,11 @@ impl LocalKubernetesNet {
450454
.join("kubernetes")
451455
.join("linera-validator")
452456
.join("working");
453-
fs_err::copy(
454-
self.tmp_dir.path().join("genesis.json"),
455-
base_dir.join("genesis.json"),
456-
)?;
457+
let path = self.path_provider.path();
458+
fs_err::copy(path.join("genesis.json"), base_dir.join("genesis.json"))?;
457459

458460
let kubectl_instance_clone = self.kubectl_instance.clone();
459-
let tmp_dir_path_clone = self.tmp_dir.path().to_path_buf();
461+
let tmp_dir_path_clone = path.to_path_buf();
460462
let num_shards = self.num_shards;
461463

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

0 commit comments

Comments
 (0)