Skip to content

Commit 43e6d51

Browse files
Merge branch 'main' into remote-persistent-safe
2 parents b3e4746 + 0cd70ee commit 43e6d51

26 files changed

+413
-83
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nativelink-config/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rust_library(
1616
"src/schedulers.rs",
1717
"src/serde_utils.rs",
1818
"src/stores.rs",
19+
"src/warm_worker_pools.rs",
1920
],
2021
compile_data = [
2122
"README.md",

nativelink-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ version = "0.7.6"
1010
nativelink-error = { path = "../nativelink-error" }
1111

1212
byte-unit = { version = "5.1.6", default-features = false, features = ["byte"] }
13-
humantime = { version = "2.2.0", default-features = false }
13+
humantime = { version = "2.3.0", default-features = false }
1414
rand = { version = "0.9.0", default-features = false, features = [
1515
"thread_rng",
1616
] }

nativelink-config/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,4 @@ pub mod cas_server;
1717
pub mod schedulers;
1818
pub mod serde_utils;
1919
pub mod stores;
20-
21-
// Warm worker pools configuration (optional feature)
22-
#[cfg(feature = "warm-worker-pools")]
2320
pub mod warm_worker_pools;

nativelink-config/src/schedulers.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::serde_utils::{
2121
convert_numeric_with_shellexpand,
2222
};
2323
use crate::stores::{GrpcEndpoint, Retry, StoreRefName};
24-
2524
// Import warm worker pool configuration
2625
#[cfg(feature = "warm-worker-pools")]
2726
use crate::warm_worker_pools::WarmWorkerPoolsConfig;

nativelink-crio-worker-pool/BUILD.bazel

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,98 @@
1+
load("@bazel_skylib//lib:selects.bzl", "selects")
12
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
23

4+
# Platform configurations for protoc
5+
PLATFORM_OS_ARCH = [
6+
("linux", "aarch64"),
7+
("linux", "x86_64"),
8+
("macos", "aarch64"),
9+
("macos", "x86_64"),
10+
("windows", "aarch64"),
11+
("windows", "x86_64"),
12+
]
13+
14+
[
15+
selects.config_setting_group(
16+
name = "{}_{}".format(
17+
os.replace("macos", "osx"),
18+
arch.replace("aarch64", "aarch_64"),
19+
),
20+
match_all = [
21+
"@platforms//cpu:{}".format(arch),
22+
"@platforms//os:{}".format(os),
23+
],
24+
)
25+
for (os, arch) in PLATFORM_OS_ARCH
26+
]
27+
28+
PLATFORM_NAMES = [
29+
"{}_{}".format(
30+
os.replace("macos", "osx"),
31+
arch.replace("aarch64", "aarch_64"),
32+
)
33+
for (os, arch) in PLATFORM_OS_ARCH
34+
]
35+
36+
# Generate Rust code from CRI proto files
37+
genrule(
38+
name = "gen_cri_protos",
39+
srcs = ["proto/cri/api.proto"],
40+
outs = ["runtime.v1.pb.rs"],
41+
cmd = select({
42+
platform: '''
43+
set -e
44+
export PROTOC=$(execpath @@toolchains_protoc++protoc+toolchains_protoc_hub.{}//:bin/protoc)
45+
46+
$(execpath //nativelink-proto:gen_protos_tool) $(SRCS) -o $(RULEDIR)
47+
48+
for file in $(RULEDIR)/*.rs; do
49+
mv -- "$$file" "$${{file%.rs}}.pb.rs"
50+
done
51+
'''.format(platform)
52+
for platform in PLATFORM_NAMES
53+
}),
54+
tools = [
55+
"//nativelink-proto:gen_protos_tool",
56+
] + select({
57+
platform: ["@@toolchains_protoc++protoc+toolchains_protoc_hub.{}//:bin/protoc".format(platform)]
58+
for platform in PLATFORM_NAMES
59+
}),
60+
)
61+
362
rust_library(
463
name = "nativelink-crio-worker-pool",
564
srcs = [
665
"src/cache.rs",
766
"src/config.rs",
867
"src/cri_client.rs",
68+
"src/cri_client_grpc.rs",
69+
"src/isolation.rs",
970
"src/lib.rs",
1071
"src/lifecycle.rs",
1172
"src/pool_manager.rs",
1273
"src/warmup.rs",
1374
"src/worker.rs",
75+
":gen_cri_protos",
76+
],
77+
compile_data = [
78+
":gen_cri_protos",
1479
],
80+
tags = ["no-clippy"],
1581
visibility = ["//visibility:public"],
1682
deps = [
83+
"//nativelink-config",
1784
"//nativelink-error",
85+
"//nativelink-metric",
1886
"//nativelink-util",
87+
"@crates//:hyper-util",
88+
"@crates//:prost",
1989
"@crates//:serde",
2090
"@crates//:serde_json",
2191
"@crates//:serde_with",
2292
"@crates//:tempfile",
2393
"@crates//:tokio",
94+
"@crates//:tonic",
95+
"@crates//:tower",
2496
"@crates//:tracing",
2597
"@crates//:uuid",
2698
],
@@ -29,4 +101,5 @@ rust_library(
29101
rust_test(
30102
name = "unit_tests",
31103
crate = ":nativelink-crio-worker-pool",
104+
tags = ["no-clippy"],
32105
)

nativelink-crio-worker-pool/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ edition = "2024"
33
name = "nativelink-crio-worker-pool"
44
version = "0.1.0"
55

6+
[features]
7+
cargo-build = []
8+
default = ["cargo-build"]
9+
610
[package.metadata.cargo-machete]
711
ignored = ["prost", "tonic-build"]
812

nativelink-crio-worker-pool/src/cri_client_grpc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ use tower::service_fn;
2929

3030
// Generated from CRI protocol buffers
3131
pub mod runtime {
32+
#![allow(clippy::all)]
33+
// When building with Bazel, include the generated proto directly
34+
#[cfg(not(feature = "cargo-build"))]
35+
include!("../runtime.v1.pb.rs");
36+
37+
// When building with Cargo, use tonic's include_proto macro
38+
#[cfg(feature = "cargo-build")]
3239
tonic::include_proto!("runtime.v1");
3340
}
3441

nativelink-crio-worker-pool/src/pool_manager.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::collections::{HashMap, HashSet, VecDeque};
44
use std::path::PathBuf;
55
use std::sync::Arc;
66

7-
use nativelink_config::warm_worker_pools::IsolationStrategy;
7+
use nativelink_config::warm_worker_pools::{IsolationStrategy, WarmWorkerPoolsConfig};
88
use nativelink_error::{Code, Error, ResultExt, make_err};
99
use nativelink_metric::MetricsComponent;
1010
use nativelink_util::action_messages::WorkerId;
@@ -14,7 +14,6 @@ use uuid::Uuid;
1414

1515
use crate::cache::CachePrimingAgent;
1616
use crate::config::WorkerPoolConfig;
17-
use nativelink_config::warm_worker_pools::WarmWorkerPoolsConfig;
1817
use crate::cri_client::{
1918
ContainerConfig, ContainerMetadata, CriClient, ImageSpec, KeyValue, LinuxContainerConfig,
2019
LinuxContainerResources, LinuxPodSandboxConfig, LinuxSandboxSecurityContext, NamespaceOptions,
@@ -83,7 +82,11 @@ impl WarmWorkerPoolManager {
8382
///
8483
/// If the pool has isolation enabled, this will create an ephemeral COW clone
8584
/// of a warm template. Otherwise, it falls back to regular acquisition.
86-
pub async fn acquire_isolated(&self, pool: &str, job_id: &str) -> Result<WarmWorkerLease, Error> {
85+
pub async fn acquire_isolated(
86+
&self,
87+
pool: &str,
88+
job_id: &str,
89+
) -> Result<WarmWorkerLease, Error> {
8790
let worker_pool = self
8891
.pools
8992
.get(pool)
@@ -159,7 +162,8 @@ impl WorkerPool {
159162
let template = self.get_or_create_template().await?;
160163

161164
// Create isolated clone
162-
self.clone_from_template(&template, job_id, isolation_config).await
165+
self.clone_from_template(&template, job_id, isolation_config)
166+
.await
163167
}
164168

165169
/// Gets the existing template or creates a new one.
@@ -261,11 +265,7 @@ impl WorkerPool {
261265
job_id: &str,
262266
isolation_config: &nativelink_config::warm_worker_pools::IsolationConfig,
263267
) -> Result<WarmWorkerLease, Error> {
264-
let worker_id = WorkerId(format!(
265-
"crio:{}:isolated:{}",
266-
self.config.name,
267-
job_id
268-
));
268+
let worker_id = WorkerId(format!("crio:{}:isolated:{}", self.config.name, job_id));
269269

270270
// Create OverlayFS mount structure
271271
let mount = OverlayFsMount::new(
@@ -305,7 +305,12 @@ impl WorkerPool {
305305
.runtime
306306
.create_container(&sandbox_id, &container_config, &sandbox_config)
307307
.await
308-
.err_tip(|| format!("while creating container for isolated worker {}", worker_id.0))?;
308+
.err_tip(|| {
309+
format!(
310+
"while creating container for isolated worker {}",
311+
worker_id.0
312+
)
313+
})?;
309314

310315
self.runtime
311316
.start_container(&container_id)
@@ -844,7 +849,13 @@ impl WarmWorkerLease {
844849
// For isolated workers, we need different cleanup
845850
if let Some(mount) = self.isolation_mount.take() {
846851
self.pool
847-
.release_isolated_worker(worker_id, &self.container_id, &self.sandbox_id, mount, outcome)
852+
.release_isolated_worker(
853+
worker_id,
854+
&self.container_id,
855+
&self.sandbox_id,
856+
mount,
857+
outcome,
858+
)
848859
.await
849860
.err_tip(|| "while releasing isolated worker")
850861
} else {

nativelink-proto/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ PROTO_NAMES = [
3232
rust_binary(
3333
name = "gen_protos_tool",
3434
srcs = ["gen_protos_tool.rs"],
35+
visibility = ["//visibility:public"],
3536
deps = [
3637
"@crates//:clap",
3738
"@crates//:prost-build",

0 commit comments

Comments
 (0)