Skip to content

Commit 5e6cdba

Browse files
committed
storage: support external config merge
Signed-off-by: Yan Song <[email protected]>
1 parent 5ad8112 commit 5e6cdba

File tree

15 files changed

+198
-54
lines changed

15 files changed

+198
-54
lines changed

Cargo.lock

+42-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ default = [
9595
"backend-s3",
9696
"backend-http-proxy",
9797
"backend-localdisk",
98+
"backend-external",
9899
]
99100
virtiofs = [
100101
"nydus-service/virtiofs",
@@ -115,6 +116,7 @@ backend-localdisk = [
115116
backend-oss = ["nydus-storage/backend-oss"]
116117
backend-registry = ["nydus-storage/backend-registry"]
117118
backend-s3 = ["nydus-storage/backend-s3"]
119+
backend-external = ["nydus-storage/backend-external"]
118120

119121
[workspace]
120122
members = [

api/src/config.rs

+30
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub struct ConfigV2 {
2525
pub id: String,
2626
/// Configuration information for storage backend.
2727
pub backend: Option<BackendConfigV2>,
28+
/// Configuration for external storage backends, order insensitivity.
29+
#[serde(default)]
30+
pub external_backends: Vec<ExternalBackendConfig>,
2831
/// Configuration information for local cache system.
2932
pub cache: Option<CacheConfigV2>,
3033
/// Configuration information for RAFS filesystem.
@@ -40,6 +43,7 @@ impl Default for ConfigV2 {
4043
version: 2,
4144
id: String::new(),
4245
backend: None,
46+
external_backends: Vec::new(),
4347
cache: None,
4448
rafs: None,
4549
internal: ConfigV2Internal::default(),
@@ -54,6 +58,7 @@ impl ConfigV2 {
5458
version: 2,
5559
id: id.to_string(),
5660
backend: None,
61+
external_backends: Vec::new(),
5762
cache: None,
5863
rafs: None,
5964
internal: ConfigV2Internal::default(),
@@ -959,6 +964,9 @@ pub struct BlobCacheEntryConfigV2 {
959964
/// Configuration information for storage backend.
960965
#[serde(default)]
961966
pub backend: BackendConfigV2,
967+
/// Configuration for external storage backends, order insensitivity.
968+
#[serde(default)]
969+
pub external_backends: Vec<ExternalBackendConfig>,
962970
/// Configuration information for local cache system.
963971
#[serde(default)]
964972
pub cache: CacheConfigV2,
@@ -1022,6 +1030,7 @@ impl From<&BlobCacheEntryConfigV2> for ConfigV2 {
10221030
version: c.version,
10231031
id: c.id.clone(),
10241032
backend: Some(c.backend.clone()),
1033+
external_backends: c.external_backends.clone(),
10251034
cache: Some(c.cache.clone()),
10261035
rafs: None,
10271036
internal: ConfigV2Internal::default(),
@@ -1292,6 +1301,19 @@ struct CacheConfig {
12921301
pub prefetch_config: BlobPrefetchConfig,
12931302
}
12941303

1304+
/// Additional configuration information for external backend, its items
1305+
/// will be merged to the configuration from image.
1306+
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
1307+
pub struct ExternalBackendConfig {
1308+
/// External backend identifier to merge.
1309+
pub patch: HashMap<String, String>,
1310+
/// External backend type.
1311+
#[serde(rename = "type")]
1312+
pub kind: String,
1313+
/// External backend config items to merge.
1314+
pub config: HashMap<String, String>,
1315+
}
1316+
12951317
impl TryFrom<&CacheConfig> for CacheConfigV2 {
12961318
type Error = std::io::Error;
12971319

@@ -1333,6 +1355,9 @@ struct FactoryConfig {
13331355
pub id: String,
13341356
/// Configuration for storage backend.
13351357
pub backend: BackendConfig,
1358+
/// Configuration for external storage backends, order insensitivity.
1359+
#[serde(default)]
1360+
pub external_backends: Vec<ExternalBackendConfig>,
13361361
/// Configuration for blob cache manager.
13371362
#[serde(default)]
13381363
pub cache: CacheConfig,
@@ -1393,6 +1418,7 @@ impl TryFrom<RafsConfig> for ConfigV2 {
13931418
version: 2,
13941419
id: v.device.id,
13951420
backend: Some(backend),
1421+
external_backends: v.device.external_backends,
13961422
cache: Some(cache),
13971423
rafs: Some(rafs),
13981424
internal: ConfigV2Internal::default(),
@@ -1482,6 +1508,9 @@ pub(crate) struct BlobCacheEntryConfig {
14821508
///
14831509
/// Possible value: `LocalFsConfig`, `RegistryConfig`, `OssConfig`, `LocalDiskConfig`.
14841510
backend_config: Value,
1511+
/// Configuration for external storage backends, order insensitivity.
1512+
#[serde(default)]
1513+
external_backends: Vec<ExternalBackendConfig>,
14851514
/// Type of blob cache, corresponding to `FactoryConfig::CacheConfig::cache_type`.
14861515
///
14871516
/// Possible value: "fscache", "filecache".
@@ -1517,6 +1546,7 @@ impl TryFrom<&BlobCacheEntryConfig> for BlobCacheEntryConfigV2 {
15171546
version: 2,
15181547
id: v.id.clone(),
15191548
backend: (&backend_config).try_into()?,
1549+
external_backends: v.external_backends.clone(),
15201550
cache: (&cache_config).try_into()?,
15211551
metadata_path: v.metadata_path.clone(),
15221552
})

builder/src/core/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,7 @@ mod tests {
15791579
registry: None,
15801580
http_proxy: None,
15811581
}),
1582+
external_backends: Vec::new(),
15821583
id: "id".to_owned(),
15831584
cache: None,
15841585
rafs: None,

clib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ backend-oss = ["nydus-storage/backend-oss"]
2626
backend-registry = ["nydus-storage/backend-registry"]
2727
backend-http-proxy = ["nydus-storage/backend-http-proxy"]
2828
backend-localdisk = ["nydus-storage/backend-localdisk"]
29+
backend-external = ["nydus-storage/backend-external"]

storage/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ url = { version = "2.1.1", optional = true }
4444
vm-memory = "0.10"
4545
fuse-backend-rs = "^0.11.0"
4646
gpt = { version = "3.1.0", optional = true }
47+
chrono = { version = "0.4", features = ["serde"] }
48+
serde_bytes = "0.11"
4749

4850
nydus-api = { version = "0.3", path = "../api" }
4951
nydus-utils = { version = "0.4", path = "../utils", features = [
@@ -67,6 +69,7 @@ backend-oss = ["base64", "httpdate", "hmac", "sha1", "reqwest", "url"]
6769
backend-registry = ["base64", "reqwest", "url"]
6870
backend-s3 = ["base64", "hmac", "http", "reqwest", "sha2", "time", "url"]
6971
backend-http-proxy = ["hyper", "hyperlocal", "http", "reqwest", "url"]
72+
backend-external = ["base64", "reqwest", "url"]
7073
dedup = ["rusqlite", "r2d2", "r2d2_sqlite"]
7174
prefetch-rate-limit = ["leaky-bucket"]
7275

storage/src/backend/connection.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub(crate) struct ConnectionConfig {
7474
pub timeout: u32,
7575
pub connect_timeout: u32,
7676
pub retry_limit: u8,
77+
pub redirect: bool,
7778
}
7879

7980
impl Default for ConnectionConfig {
@@ -85,6 +86,7 @@ impl Default for ConnectionConfig {
8586
timeout: 5,
8687
connect_timeout: 5,
8788
retry_limit: 0,
89+
redirect: false,
8890
}
8991
}
9092
}
@@ -98,6 +100,7 @@ impl From<OssConfig> for ConnectionConfig {
98100
timeout: c.timeout,
99101
connect_timeout: c.connect_timeout,
100102
retry_limit: c.retry_limit,
103+
redirect: false,
101104
}
102105
}
103106
}
@@ -111,6 +114,7 @@ impl From<S3Config> for ConnectionConfig {
111114
timeout: c.timeout,
112115
connect_timeout: c.connect_timeout,
113116
retry_limit: c.retry_limit,
117+
redirect: false,
114118
}
115119
}
116120
}
@@ -124,6 +128,7 @@ impl From<RegistryConfig> for ConnectionConfig {
124128
timeout: c.timeout,
125129
connect_timeout: c.connect_timeout,
126130
retry_limit: c.retry_limit,
131+
redirect: false,
127132
}
128133
}
129134
}
@@ -137,6 +142,7 @@ impl From<HttpProxyConfig> for ConnectionConfig {
137142
timeout: c.timeout,
138143
connect_timeout: c.connect_timeout,
139144
retry_limit: c.retry_limit,
145+
redirect: false,
140146
}
141147
}
142148
}
@@ -610,8 +616,12 @@ impl Connection {
610616

611617
let mut cb = Client::builder()
612618
.timeout(timeout)
613-
.connect_timeout(connect_timeout)
614-
.redirect(Policy::none());
619+
.connect_timeout(connect_timeout);
620+
if config.redirect {
621+
cb = cb.redirect(Policy::default());
622+
} else {
623+
cb = cb.redirect(Policy::none());
624+
}
615625

616626
if config.skip_verify {
617627
cb = cb.danger_accept_invalid_certs(true);

0 commit comments

Comments
 (0)