Skip to content

Commit c2d8415

Browse files
authored
Revert "Remove mirrors configuration" (#17)
This reverts commit f7d5138.
1 parent e969948 commit c2d8415

9 files changed

Lines changed: 427 additions & 10 deletions

File tree

.github/copilot-instructions.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ pub enum NydusError {
7474
## Development Guidelines
7575

7676
### Storage Backend Development
77-
- When implementing new storage backends:
78-
- - Implement the `BlobBackend` trait
79-
- - Support timeout, retry, and connection management
80-
- - Add configuration in the backend config structure
81-
- - Consider proxy support for high availability
82-
- - Implement proper error handling and logging
77+
When implementing new storage backends:
78+
- Implement the `BlobBackend` trait
79+
- Support timeout, retry, and connection management
80+
- Add configuration in the backend config structure
81+
- Consider mirror/proxy support for high availability
82+
- Implement proper error handling and logging
8383

8484
### Daemon Service Development
8585
- Use the `NydusDaemon` trait for service implementations

api/src/config.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ pub struct OssConfig {
519519
/// Enable HTTP proxy for the read request.
520520
#[serde(default)]
521521
pub proxy: ProxyConfig,
522+
/// Enable mirrors for the read request.
523+
#[serde(default)]
524+
pub mirrors: Vec<MirrorConfig>,
522525
}
523526

524527
/// S3 configuration information to access blobs.
@@ -560,6 +563,9 @@ pub struct S3Config {
560563
/// Enable HTTP proxy for the read request.
561564
#[serde(default)]
562565
pub proxy: ProxyConfig,
566+
/// Enable mirrors for the read request.
567+
#[serde(default)]
568+
pub mirrors: Vec<MirrorConfig>,
563569
}
564570

565571
/// Http proxy configuration information to access blobs.
@@ -586,6 +592,9 @@ pub struct HttpProxyConfig {
586592
/// Enable HTTP proxy for the read request.
587593
#[serde(default)]
588594
pub proxy: ProxyConfig,
595+
/// Enable mirrors for the read request.
596+
#[serde(default)]
597+
pub mirrors: Vec<MirrorConfig>,
589598
}
590599

591600
/// Container registry configuration information to access blobs.
@@ -629,6 +638,9 @@ pub struct RegistryConfig {
629638
/// Disable background token refresh thread. Defaults to false.
630639
#[serde(skip_deserializing)]
631640
pub disable_token_refresh: bool,
641+
/// Enable mirrors for the read request.
642+
#[serde(default)]
643+
pub mirrors: Vec<MirrorConfig>,
632644
}
633645

634646
/// Configuration information for blob cache manager.
@@ -921,6 +933,41 @@ impl Default for ProxyConfig {
921933
}
922934
}
923935

936+
/// Configuration for registry mirror.
937+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
938+
pub struct MirrorConfig {
939+
/// Mirror server URL, for example http://127.0.0.1:65001.
940+
pub host: String,
941+
/// Ping URL to check mirror server health.
942+
#[serde(default)]
943+
pub ping_url: String,
944+
/// HTTP request headers to be passed to mirror server.
945+
#[serde(default)]
946+
pub headers: HashMap<String, String>,
947+
/// Interval for mirror health checking, in seconds.
948+
#[serde(default = "default_check_interval")]
949+
pub health_check_interval: u64,
950+
/// Maximum number of failures before marking a mirror as unusable.
951+
#[serde(default = "default_failure_limit")]
952+
pub failure_limit: u8,
953+
/// Elapsed time to pause mirror health check when the request is inactive, in seconds.
954+
#[serde(default = "default_check_pause_elapsed")]
955+
pub health_check_pause_elapsed: u64,
956+
}
957+
958+
impl Default for MirrorConfig {
959+
fn default() -> Self {
960+
Self {
961+
host: String::new(),
962+
headers: HashMap::new(),
963+
health_check_interval: 5,
964+
failure_limit: 5,
965+
ping_url: String::new(),
966+
health_check_pause_elapsed: 300,
967+
}
968+
}
969+
}
970+
924971
/// Configuration information for a cached blob`.
925972
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
926973
pub struct BlobCacheEntryConfigV2 {
@@ -1168,6 +1215,10 @@ fn default_check_pause_elapsed() -> u64 {
11681215
300
11691216
}
11701217

1218+
fn default_failure_limit() -> u8 {
1219+
5
1220+
}
1221+
11711222
fn default_work_dir() -> String {
11721223
".".to_string()
11731224
}
@@ -1854,6 +1905,11 @@ mod tests {
18541905
fallback = true
18551906
check_interval = 10
18561907
use_http = true
1908+
[[backend.oss.mirrors]]
1909+
host = "http://127.0.0.1:65001"
1910+
ping_url = "http://127.0.0.1:65001/ping"
1911+
health_check_interval = 10
1912+
failure_limit = 10
18571913
"#;
18581914
let config: ConfigV2 = toml::from_str(content).unwrap();
18591915
assert_eq!(config.version, 2);
@@ -1880,6 +1936,14 @@ mod tests {
18801936
assert_eq!(oss.proxy.check_interval, 10);
18811937
assert!(oss.proxy.fallback);
18821938
assert!(oss.proxy.use_http);
1939+
1940+
assert_eq!(oss.mirrors.len(), 1);
1941+
let mirror = &oss.mirrors[0];
1942+
assert_eq!(mirror.host, "http://127.0.0.1:65001");
1943+
assert_eq!(mirror.ping_url, "http://127.0.0.1:65001/ping");
1944+
assert!(mirror.headers.is_empty());
1945+
assert_eq!(mirror.health_check_interval, 10);
1946+
assert_eq!(mirror.failure_limit, 10);
18831947
}
18841948

18851949
#[test]
@@ -1905,6 +1969,11 @@ mod tests {
19051969
fallback = true
19061970
check_interval = 10
19071971
use_http = true
1972+
[[backend.registry.mirrors]]
1973+
host = "http://127.0.0.1:65001"
1974+
ping_url = "http://127.0.0.1:65001/ping"
1975+
health_check_interval = 10
1976+
failure_limit = 10
19081977
"#;
19091978
let config: ConfigV2 = toml::from_str(content).unwrap();
19101979
assert_eq!(config.version, 2);
@@ -1933,6 +2002,14 @@ mod tests {
19332002
assert_eq!(registry.proxy.check_interval, 10);
19342003
assert!(registry.proxy.fallback);
19352004
assert!(registry.proxy.use_http);
2005+
2006+
assert_eq!(registry.mirrors.len(), 1);
2007+
let mirror = &registry.mirrors[0];
2008+
assert_eq!(mirror.host, "http://127.0.0.1:65001");
2009+
assert_eq!(mirror.ping_url, "http://127.0.0.1:65001/ping");
2010+
assert!(mirror.headers.is_empty());
2011+
assert_eq!(mirror.health_check_interval, 10);
2012+
assert_eq!(mirror.failure_limit, 10);
19362013
}
19372014

19382015
#[test]
@@ -2348,6 +2425,15 @@ mod tests {
23482425
assert!(res);
23492426
}
23502427

2428+
#[test]
2429+
fn test_default_mirror_config() {
2430+
let cfg = MirrorConfig::default();
2431+
assert_eq!(cfg.host, "");
2432+
assert_eq!(cfg.health_check_interval, 5);
2433+
assert_eq!(cfg.failure_limit, 5);
2434+
assert_eq!(cfg.ping_url, "");
2435+
}
2436+
23512437
#[test]
23522438
fn test_config_v2_from_file() {
23532439
let content = r#"version=2
@@ -2557,6 +2643,7 @@ mod tests {
25572643
#[test]
25582644
fn test_default_value() {
25592645
assert!(default_true());
2646+
assert_eq!(default_failure_limit(), 5);
25602647
assert_eq!(default_prefetch_batch_size(), 1024 * 1024);
25612648
assert_eq!(default_prefetch_threads_count(), 8);
25622649
}

docs/nydusd.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,64 @@ or
319319
}
320320
}
321321
```
322-
-
323-
- The `HttpProxy` backend also supports the `Proxy` configuration for remote usage like the `Registry backend` described above.
322+
323+
The `HttpProxy` backend also supports the `Proxy` and `Mirrors` configurations for remote usage like the `Registry backend` described above.
324+
325+
##### Enable Mirrors for Storage Backend (Recommend)
326+
327+
Nydus is deeply integrated with [Dragonfly](https://d7y.io/) P2P mirror mode, please refer the [doc](https://d7y.io/docs/next/operations/integrations/container-runtime/nydus/) to learn how configuring Nydus to use Dragonfly.
328+
329+
Add `device.backend.config.mirrors` field to enable mirrors for storage backend. The mirror can be a P2P distribution server or registry. If the request to mirror server failed, it will fall back to the original registry.
330+
Currently, the mirror mode is only tested in the registry backend, and in theory, the OSS backend also supports it.
331+
332+
<font color='red'>!!</font> The `mirrors` field conflicts with `proxy` field.
333+
334+
```
335+
{
336+
"device": {
337+
"backend": {
338+
"type": "registry",
339+
"config": {
340+
"mirrors": [
341+
{
342+
// Mirror server URL (including scheme), e.g. Dragonfly dfdaemon server URL
343+
"host": "http://dragonfly1.io:65001",
344+
// Headers for mirror server
345+
"headers": {
346+
// For Dragonfly dfdaemon server URL, we need to specify "X-Dragonfly-Registry" (including scheme).
347+
// When Dragonfly does not cache data, nydusd will pull it from "X-Dragonfly-Registry".
348+
// If not set "X-Dragonfly-Registry", Dragonfly will pull data from proxy.registryMirror.url.
349+
"X-Dragonfly-Registry": "https://index.docker.io"
350+
},
351+
// This URL endpoint is used to check the health of mirror server, and if the mirror is unhealthy,
352+
// the request will fallback to the next mirror or the original registry server.
353+
// Use $host/v2 as default if left empty.
354+
"ping_url": "http://127.0.0.1:40901/server/ping",
355+
// Interval time (s) to check and recover unavailable mirror. Use 5 as default if left empty.
356+
"health_check_interval": 5,
357+
// Failure counts before disabling this mirror. Use 5 as default if left empty.
358+
"failure_limit": 5,
359+
// Elapsed time to pause mirror health check when the request is inactive, in seconds.
360+
// Use 300 as default if left empty.
361+
"health_check_pause_elapsed": 300,
362+
},
363+
{
364+
"host": "http://dragonfly2.io:65001",
365+
"headers": {
366+
"X-Dragonfly-Registry": "https://index.docker.io"
367+
},
368+
}
369+
],
370+
...
371+
}
372+
},
373+
...
374+
},
375+
...
376+
}
377+
```
378+
379+
324380
##### Enable P2P Proxy for Storage Backend
325381

326382
Add `device.backend.config.proxy` field to enable HTTP proxy for storage backend. For example, use P2P distribution service to reduce network workload and latency in large scale container cluster using [Dragonfly](https://d7y.io/) (enable centralized dfdaemon mode).

misc/configs/nydusd-blob-cache-entry-configuration-v2.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ check_interval = 5
5050
# Replace URL to http to request source registry with proxy, and allow fallback to https if the proxy is unhealthy.
5151
use_http = false
5252

53+
[[backend.oss.mirrors]]
54+
# Mirror server URL, for example http://127.0.0.1:65001.
55+
host = "http://127.0.0.1:65001"
56+
# Ping URL to check mirror server health.
57+
ping_url = "http://127.0.0.1:65001/ping"
58+
# HTTP request headers to be passed to mirror server.
59+
# headers =
60+
# Interval for mirror health checking, in seconds.
61+
health_check_interval = 5
62+
# Maximum number of failures before marking a mirror as unusable.
63+
failure_limit = 5
64+
5365
[backend.registy]
5466
# Registry http scheme, either 'http' or 'https'
5567
scheme = "https"
@@ -87,6 +99,18 @@ check_interval = 5
8799
# Replace URL to http to request source registry with proxy, and allow fallback to https if the proxy is unhealthy.
88100
use_http = false
89101

102+
[[backend.registry.mirrors]]
103+
# Mirror server URL, for example http://127.0.0.1:65001.
104+
host = "http://127.0.0.1:65001"
105+
# Ping URL to check mirror server health.
106+
ping_url = "http://127.0.0.1:65001/ping"
107+
# HTTP request headers to be passed to mirror server.
108+
# headers =
109+
# Interval for mirror health checking, in seconds.
110+
health_check_interval = 5
111+
# Maximum number of failures before marking a mirror as unusable.
112+
failure_limit = 5
113+
90114
[cache]
91115
# Type of blob cache: "blobcache", "filecache", "fscache", "dummycache" or ""
92116
type = "filecache"

misc/configs/nydusd-blob-cache-entry.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ check_interval = 5
5555
# Replace URL to http to request source registry with proxy, and allow fallback to https if the proxy is unhealthy.
5656
use_http = false
5757

58+
[[config_v2.backend.oss.mirrors]]
59+
# Mirror server URL, for example http://127.0.0.1:65001.
60+
host = "http://127.0.0.1:65001"
61+
# Ping URL to check mirror server health.
62+
ping_url = "http://127.0.0.1:65001/ping"
63+
# HTTP request headers to be passed to mirror server.
64+
# headers =
65+
# Interval for mirror health checking, in seconds.
66+
health_check_interval = 5
67+
# Maximum number of failures before marking a mirror as unusable.
68+
failure_limit = 5
69+
5870
[config_v2.backend.registry]
5971
# Registry http scheme, either 'http' or 'https'
6072
scheme = "https"
@@ -92,6 +104,18 @@ check_interval = 5
92104
# Replace URL to http to request source registry with proxy, and allow fallback to https if the proxy is unhealthy.
93105
use_http = false
94106

107+
[[config_v2.backend.registry.mirrors]]
108+
# Mirror server URL, for example http://127.0.0.1:65001.
109+
host = "http://127.0.0.1:65001"
110+
# Ping URL to check mirror server health.
111+
ping_url = "http://127.0.0.1:65001/ping"
112+
# HTTP request headers to be passed to mirror server.
113+
# headers =
114+
# Interval for mirror health checking, in seconds.
115+
health_check_interval = 5
116+
# Maximum number of failures before marking a mirror as unusable.
117+
failure_limit = 5
118+
95119
[config_v2.cache]
96120
# Type of blob cache: "blobcache", "filecache", "fscache", "dummycache" or ""
97121
type = "filecache"

misc/configs/nydusd-config-v2.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ check_interval = 5
4848
# Replace URL to http to request source registry with proxy, and allow fallback to https if the proxy is unhealthy.
4949
use_http = false
5050

51+
[[backend.oss.mirrors]]
52+
# Mirror server URL, for example http://127.0.0.1:65001.
53+
host = "http://127.0.0.1:65001"
54+
# Ping URL to check mirror server health.
55+
ping_url = "http://127.0.0.1:65001/ping"
56+
# HTTP request headers to be passed to mirror server.
57+
# headers =
58+
# Interval for mirror health checking, in seconds.
59+
health_check_interval = 5
60+
# Maximum number of failures before marking a mirror as unusable.
61+
failure_limit = 5
62+
5163
[backend.registy]
5264
# Registry http scheme, either 'http' or 'https'
5365
scheme = "https"
@@ -85,6 +97,17 @@ check_interval = 5
8597
# Replace URL to http to request source registry with proxy, and allow fallback to https if the proxy is unhealthy.
8698
use_http = false
8799

100+
[[backend.registry.mirrors]]
101+
# Mirror server URL, for example http://127.0.0.1:65001.
102+
host = "http://127.0.0.1:65001"
103+
# Ping URL to check mirror server health.
104+
ping_url = "http://127.0.0.1:65001/ping"
105+
# HTTP request headers to be passed to mirror server.
106+
# headers =
107+
# Interval for mirror health checking, in seconds.
108+
health_check_interval = 5
109+
# Maximum number of failures before marking a mirror as unusable.
110+
failure_limit = 5
88111

89112
[cache]
90113
# Type of blob cache: "blobcache", "filecache", "fscache", "dummycache" or ""

misc/performance/snapshotter_config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ address = ":9110"
6363
[remote]
6464
convert_vpc_registry = false
6565

66+
[remote.mirrors_config]
67+
# Snapshotter will overwrite daemon's mirrors configuration
68+
# if the values loaded from this driectory are not null before starting a daemon.
69+
# Set to "" or an empty directory to disable it.
70+
#dir = "/etc/nydus/certs.d"
71+
6672
[remote.auth]
6773
# Fetch the private registry auth by listening to K8s API server
6874
enable_kubeconfig_keychain = false

0 commit comments

Comments
 (0)