diff --git a/Cargo.lock b/Cargo.lock index 400a8ab9c5e79c9dbb0a174616c5f0aafa8f1b71..60880d49033b9069a44a746e1a551cd4b7064d8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,189 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "actix-codec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" +dependencies = [ + "bitflags 2.6.0", + "bytes", + "futures-core", + "futures-sink", + "memchr", + "pin-project-lite", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "actix-http" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d48f96fc3003717aeb9856ca3d02a8c7de502667ad76eeacd830b48d2e91fac4" +dependencies = [ + "actix-codec", + "actix-rt", + "actix-service", + "actix-utils", + "ahash 0.8.11", + "base64 0.22.1", + "bitflags 2.6.0", + "brotli", + "bytes", + "bytestring", + "derive_more", + "encoding_rs", + "flate2", + "futures-core", + "h2", + "http 0.2.12", + "httparse", + "httpdate", + "itoa", + "language-tags", + "local-channel", + "mime", + "percent-encoding", + "pin-project-lite", + "rand", + "sha1", + "smallvec", + "tokio", + "tokio-util", + "tracing", + "zstd", +] + +[[package]] +name = "actix-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" +dependencies = [ + "quote", + "syn 2.0.87", +] + +[[package]] +name = "actix-router" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8" +dependencies = [ + "bytestring", + "cfg-if", + "http 0.2.12", + "regex", + "regex-lite", + "serde", + "tracing", +] + +[[package]] +name = "actix-rt" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eda4e2a6e042aa4e55ac438a2ae052d3b5da0ecf83d7411e1a368946925208" +dependencies = [ + "futures-core", + "tokio", +] + +[[package]] +name = "actix-server" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ca2549781d8dd6d75c40cf6b6051260a2cc2f3c62343d761a969a0640646894" +dependencies = [ + "actix-rt", + "actix-service", + "actix-utils", + "futures-core", + "futures-util", + "mio 1.0.2", + "socket2 0.5.7", + "tokio", + "tracing", +] + +[[package]] +name = "actix-service" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b894941f818cfdc7ccc4b9e60fa7e53b5042a2e8567270f9147d5591893373a" +dependencies = [ + "futures-core", + "paste", + "pin-project-lite", +] + +[[package]] +name = "actix-utils" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88a1dcdff1466e3c2488e1cb5c36a71822750ad43839937f85d2f4d9f8b705d8" +dependencies = [ + "local-waker", + "pin-project-lite", +] + +[[package]] +name = "actix-web" +version = "4.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9180d76e5cc7ccbc4d60a506f2c727730b154010262df5b910eb17dbe4b8cb38" +dependencies = [ + "actix-codec", + "actix-http", + "actix-macros", + "actix-router", + "actix-rt", + "actix-server", + "actix-service", + "actix-utils", + "actix-web-codegen", + "ahash 0.8.11", + "bytes", + "bytestring", + "cfg-if", + "cookie", + "derive_more", + "encoding_rs", + "futures-core", + "futures-util", + "impl-more", + "itoa", + "language-tags", + "log", + "mime", + "once_cell", + "pin-project-lite", + "regex", + "regex-lite", + "serde", + "serde_json", + "serde_urlencoded", + "smallvec", + "socket2 0.5.7", + "time", + "url", +] + +[[package]] +name = "actix-web-codegen" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f591380e2e68490b5dfaf1dd1aa0ebe78d84ba7067078512b4ea6e4492d622b8" +dependencies = [ + "actix-router", + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "addr2line" version = "0.24.2" @@ -51,6 +234,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -229,6 +427,35 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-nats" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23f02c8b692d7eea2cfcdf58b43031b163efd93aa99c01d2a9e796168d37dcf1" +dependencies = [ + "base64-url", + "bytes", + "futures", + "http 0.2.12", + "itoa", + "nkeys", + "nuid", + "once_cell", + "regex", + "rustls-pemfile 0.3.0", + "serde", + "serde_json", + "serde_nanos", + "serde_repr", + "subslice", + "time", + "tokio", + "tokio-rustls 0.23.4", + "tokio-util", + "url", + "webpki-roots 0.22.6", +] + [[package]] name = "async-process" version = "2.3.0" @@ -256,7 +483,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -323,7 +550,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -340,7 +567,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -415,6 +642,12 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.7" @@ -427,6 +660,21 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64-url" +version = "1.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a99c239d0c7e77c85dddfa9cebce48704b3c49550fcd3b84dd637e4484899f" +dependencies = [ + "base64 0.13.1", +] + +[[package]] +name = "base64ct" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6b4d9b1225d28d360ec6a231d65af1fd99a2a095154c8040689617290569c5c" + [[package]] name = "bit-set" version = "0.5.3" @@ -460,6 +708,15 @@ version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d084b0137aaa901caf9f1e8b21daa6aa24d41cd806e111335541eff9683bd6" +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -530,6 +787,33 @@ dependencies = [ "utoipa", ] +[[package]] +name = "borrow-or-share" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eeab4423108c5d7c744f4d234de88d18d636100093ae04caf4825134b9c3a32" + +[[package]] +name = "brotli" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a45bd2e4095a8b518033b128020dd4a55aab1c0a381ba4404a472630f4bc362" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "buddy-alloc" version = "0.4.2" @@ -560,6 +844,15 @@ version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +[[package]] +name = "bytestring" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e465647ae23b2823b0753f50decb2d5a86d2bb2cac04788fafd1f80e45378e5f" +dependencies = [ + "bytes", +] + [[package]] name = "cache-padded" version = "1.3.0" @@ -572,6 +865,8 @@ version = "1.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -595,11 +890,35 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "wasm-bindgen", "windows-targets 0.52.6", ] +[[package]] +name = "chrono-tz" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c39203181991a7dd4343b8005bd804e7a9a37afb8ac070e43771e8c820bbde" +dependencies = [ + "chrono", + "chrono-tz-build", + "phf", +] + +[[package]] +name = "chrono-tz-build" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f509c3a87b33437b05e2458750a0700e5bdd6956176773e6c7d6dd15a283a0c" +dependencies = [ + "parse-zoneinfo", + "phf", + "phf_codegen", +] + [[package]] name = "clap" version = "4.5.20" @@ -631,7 +950,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -697,12 +1016,29 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "const-oid" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d6f2aa4d0537bcc1c74df8755072bd31c1ef1a3a1b85a68e8404a8c353b7b8b" + [[package]] name = "convert_case" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "cookie" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -815,6 +1151,19 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + [[package]] name = "darling" version = "0.20.10" @@ -836,7 +1185,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -847,7 +1196,22 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.79", + "syn 2.0.87", +] + +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + +[[package]] +name = "der" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79b71cca7d95d7681a4b3b9cdf63c8dbc3730d0584c2c74e31416d64a90493f4" +dependencies = [ + "const-oid", ] [[package]] @@ -868,7 +1232,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -881,7 +1245,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -903,11 +1267,15 @@ version = "2.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "158fe8e2e68695bd615d7e4f3227c0727b151330d3e253b525086c348d055d5e" dependencies = [ + "bitflags 2.6.0", + "byteorder", "chrono", "diesel_derives", "ipnet", + "itoa", "libc", "libsqlite3-sys", + "pq-sys", "r2d2", "serde_json", "time", @@ -924,7 +1292,7 @@ dependencies = [ "dsl_auto_type", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -944,7 +1312,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" dependencies = [ - "syn 2.0.79", + "syn 2.0.87", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", ] [[package]] @@ -953,7 +1330,7 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", + "block-buffer 0.10.4", "crypto-common", ] @@ -986,7 +1363,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -995,6 +1372,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dotenvy" version = "0.15.7" @@ -1012,7 +1395,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -1021,12 +1404,42 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" +[[package]] +name = "ed25519" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek", + "ed25519", + "sha2 0.9.9", + "zeroize", +] + [[package]] name = "either" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "email_address" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e079f19b08ca6239f47f8ba8509c11cf3ea30095831f7fed61441475edd8c449" +dependencies = [ + "serde", +] + [[package]] name = "enclose" version = "1.2.0" @@ -1152,6 +1565,42 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +[[package]] +name = "feventbus" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3c917e2bb003f3aebbf8bc1e51b661c94ed5a279b774529e190ecda21b8107" +dependencies = [ + "async-nats", + "async-trait", + "bytes", + "chrono", + "chrono-tz", + "futures", + "serde", + "serde_json", + "thiserror", + "tokio", +] + +[[package]] +name = "feventbus" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81b7cca7940f29e24592a89727028106825660bd8f9aae1d85283008fea92220" +dependencies = [ + "async-nats", + "async-trait", + "bytes", + "chrono", + "chrono-tz", + "futures", + "serde", + "serde_json", + "thiserror", + "tokio", +] + [[package]] name = "filetime" version = "0.2.25" @@ -1180,6 +1629,45 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "fleet_apiserver" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187d959f2ebd42774326f49203ec0710010d9a8aa4b46a80c77ee65a925be08b" +dependencies = [ + "actix-http", + "actix-service", + "actix-web", + "async-stream", + "async-trait", + "chrono", + "diesel", + "diesel_migrations", + "dotenv", + "env_logger", + "feventbus 0.3.0", + "jsonschema 0.23.0", + "k8s-openapi", + "lazy_static", + "once_cell", + "r2d2", + "schemars", + "serde", + "serde_json", + "tokio", +] + +[[package]] +name = "fluent-uri" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1918b65d96df47d3591bed19c5cca17e3fa5d0707318e4b5ef2eae01764df7e5" +dependencies = [ + "borrow-or-share", + "ref-cast", + "serde", +] + [[package]] name = "flume" version = "0.10.14" @@ -1190,7 +1678,7 @@ dependencies = [ "futures-sink", "nanorand", "pin-project", - "spin", + "spin 0.9.8", ] [[package]] @@ -1326,7 +1814,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -1681,81 +2169,199 @@ dependencies = [ "http 1.1.0", "hyper 1.5.0", "hyper-util", - "rustls", + "rustls 0.23.15", "rustls-pki-types", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.0", + "tower-service", + "webpki-roots 0.26.6", +] + +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper 0.14.31", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] + +[[package]] +name = "hyper-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "hyper 1.5.0", + "pin-project-lite", + "socket2 0.5.7", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "hyperlocal-next" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acf569d43fa9848e510358c07b80f4adf34084ddc28c6a4a651ee8474c070dcc" +dependencies = [ + "hex", + "http-body-util", + "hyper 1.5.0", + "hyper-util", + "pin-project-lite", + "tokio", "tower-service", - "webpki-roots", ] [[package]] -name = "hyper-timeout" -version = "0.4.1" +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" dependencies = [ - "hyper 0.14.31", - "pin-project-lite", - "tokio", - "tokio-io-timeout", + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", ] [[package]] -name = "hyper-util" -version = "0.1.9" +name = "icu_normalizer_data" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http 1.1.0", - "http-body 1.0.1", - "hyper 1.5.0", - "pin-project-lite", - "socket2 0.5.7", - "tokio", - "tower-service", - "tracing", -] +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" [[package]] -name = "hyperlocal-next" -version = "0.9.0" +name = "icu_properties" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acf569d43fa9848e510358c07b80f4adf34084ddc28c6a4a651ee8474c070dcc" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" dependencies = [ - "hex", - "http-body-util", - "hyper 1.5.0", - "hyper-util", - "pin-project-lite", - "tokio", - "tower-service", + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", ] [[package]] -name = "iana-time-zone" -version = "0.1.61" +name = "icu_properties_data" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", ] [[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" +name = "icu_provider_macros" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ - "cc", + "proc-macro2", + "quote", + "syn 2.0.87", ] [[package]] @@ -1774,6 +2380,33 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "impl-more" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae21c3177a27788957044151cc2800043d127acaa460a47ebb9b84dfa2c6aa0" + [[package]] name = "indexmap" version = "1.9.3" @@ -1895,6 +2528,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.72" @@ -1932,6 +2574,46 @@ dependencies = [ "uuid", ] +[[package]] +name = "jsonschema" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bea85509e7320309cc8be62d8badb46f9525157bdc748bf2ec089cd4083a3f7e" +dependencies = [ + "ahash 0.8.11", + "anyhow", + "base64 0.22.1", + "bytecount", + "email_address", + "fancy-regex", + "fraction", + "idna 1.0.3", + "itoa", + "num-cmp", + "once_cell", + "percent-encoding", + "referencing", + "regex-syntax", + "reqwest", + "serde", + "serde_json", + "url", + "uuid-simd", +] + +[[package]] +name = "k8s-openapi" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8847402328d8301354c94d605481f25a6bdc1ed65471fd96af8eca71141b13" +dependencies = [ + "base64 0.22.1", + "chrono", + "serde", + "serde-value", + "serde_json", +] + [[package]] name = "kqueue" version = "1.0.8" @@ -1971,6 +2653,12 @@ dependencies = [ "log", ] +[[package]] +name = "language-tags" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" + [[package]] name = "lazy_static" version = "1.5.0" @@ -2059,7 +2747,7 @@ checksum = "3b51f1d220e3fa869e24cfd75915efe3164bd09bb11b3165db3f37f57bf673e3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2077,6 +2765,29 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + +[[package]] +name = "local-channel" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8" +dependencies = [ + "futures-core", + "futures-sink", + "local-waker", +] + +[[package]] +name = "local-waker" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d873d7c67ce09b42110d801813efbc9364414e356be9935700d368351657487" + [[package]] name = "lock_api" version = "0.4.12" @@ -2221,6 +2932,7 @@ checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ "hermit-abi 0.3.9", "libc", + "log", "wasi", "windows-sys 0.52.0", ] @@ -2246,6 +2958,7 @@ dependencies = [ "dialoguer", "dirs", "dotenvy", + "feventbus 0.2.3", "futures", "gethostname", "indicatif", @@ -2257,7 +2970,7 @@ dependencies = [ "ntex", "openssl", "regex", - "ring", + "ring 0.17.8", "serde", "serde_json", "serde_yaml", @@ -2329,12 +3042,14 @@ dependencies = [ "diesel_migrations", "dirs", "env_logger", + "feventbus 0.3.0", + "fleet_apiserver", "futures", "futures-util", "gethostname", "http 1.1.0", "ipnet", - "jsonschema", + "jsonschema 0.18.3", "libc", "log", "metrsd_client", @@ -2476,6 +3191,21 @@ dependencies = [ "libc", ] +[[package]] +name = "nkeys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e66a7cd1358277b2a6f77078e70aea7315ff2f20db969cc61153103ec162594" +dependencies = [ + "byteorder", + "data-encoding", + "ed25519-dalek", + "getrandom", + "log", + "rand", + "signatory", +] + [[package]] name = "nom" version = "7.1.3" @@ -2800,6 +3530,16 @@ dependencies = [ "slab", ] +[[package]] +name = "nuid" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20c1bb65186718d348306bf1afdeb20d9ab45b2ab80fb793c0fdcf59ffbb4f38" +dependencies = [ + "lazy_static", + "rand", +] + [[package]] name = "num" version = "0.4.3" @@ -2913,7 +3653,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2966,6 +3706,12 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e296cf87e61c9cfc1a61c3c63a0f7f286ed4554e0e22be84e8a38e1d264a2a29" +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + [[package]] name = "openssl" version = "0.10.68" @@ -2989,7 +3735,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3020,6 +3766,21 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "ordered-float" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" +dependencies = [ + "num-traits", +] + +[[package]] +name = "outref" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4030760ffd992bef45b0ae3f10ce1aba99e33464c90d14dd7c039884963ddc7a" + [[package]] name = "owned-alloc" version = "0.2.0" @@ -3066,6 +3827,30 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "parse-zoneinfo" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24" +dependencies = [ + "regex", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pem-rfc7468" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84e93a3b1cc0510b03020f33f21e62acdde3dcaef432edc95bea377fbd4c2cd4" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -3103,7 +3888,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3114,7 +3899,7 @@ checksum = "b75da2a70cf4d9cb76833c990ac9cd3923c9a8905a8929789ce347c84564d03d" dependencies = [ "once_cell", "pest", - "sha2", + "sha2 0.10.8", ] [[package]] @@ -3127,6 +3912,45 @@ dependencies = [ "indexmap 2.6.0", ] +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", + "uncased", +] + [[package]] name = "pin-project" version = "1.1.6" @@ -3144,7 +3968,7 @@ checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3170,6 +3994,18 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pkcs8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee3ef9b64d26bad0536099c816c6734379e45bbd5f14798def6809e5cc350447" +dependencies = [ + "der", + "pem-rfc7468", + "spki", + "zeroize", +] + [[package]] name = "pkg-config" version = "0.3.31" @@ -3212,6 +4048,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "pq-sys" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6cc05d7ea95200187117196eee9edd0644424911821aeb28a18ce60ea0b8793" +dependencies = [ + "vcpkg", +] + [[package]] name = "prettyplease" version = "0.2.22" @@ -3219,7 +4064,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3291,7 +4136,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.79", + "syn 2.0.87", "tempfile", ] @@ -3305,7 +4150,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3328,7 +4173,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls", + "rustls 0.23.15", "socket2 0.5.7", "thiserror", "tokio", @@ -3343,9 +4188,9 @@ checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", "rand", - "ring", + "ring 0.17.8", "rustc-hash", - "rustls", + "rustls 0.23.15", "slab", "thiserror", "tinyvec", @@ -3393,7 +4238,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -3403,9 +4248,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", ] +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + [[package]] name = "rand_core" version = "0.6.4" @@ -3429,30 +4280,63 @@ dependencies = [ name = "rayon-core" version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags 2.6.0", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "ref-cast" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf0a6f84d5f1d581da8b41b47ec8600871962f2a528115b542b362d4b744931" dependencies = [ - "crossbeam-deque", - "crossbeam-utils", + "ref-cast-impl", ] [[package]] -name = "redox_syscall" -version = "0.5.7" +name = "ref-cast-impl" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ - "bitflags 2.6.0", + "proc-macro2", + "quote", + "syn 2.0.87", ] [[package]] -name = "redox_users" -version = "0.4.6" +name = "referencing" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +checksum = "35bdf02a06a0820fcb9ce064715b424f1cdd79e24f991990a92425afe11eaf4a" dependencies = [ - "getrandom", - "libredox", - "thiserror", + "ahash 0.8.11", + "fluent-uri", + "once_cell", + "percent-encoding", + "serde_json", ] [[package]] @@ -3478,6 +4362,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + [[package]] name = "regex-syntax" version = "0.8.5" @@ -3509,24 +4399,39 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn", - "rustls", - "rustls-pemfile", + "rustls 0.23.15", + "rustls-pemfile 2.2.0", "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper 1.0.1", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.0", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", + "webpki-roots 0.26.6", "windows-registry", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted 0.7.1", + "web-sys", + "winapi", +] + [[package]] name = "ring" version = "0.17.8" @@ -3537,8 +4442,8 @@ dependencies = [ "cfg-if", "getrandom", "libc", - "spin", - "untrusted", + "spin 0.9.8", + "untrusted 0.9.0", "windows-sys 0.52.0", ] @@ -3592,7 +4497,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.79", + "syn 2.0.87", "walkdir", ] @@ -3602,7 +4507,7 @@ version = "8.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e5347777e9aacb56039b0e1f28785929a8a3b709e87482e7442c72e7c12529d" dependencies = [ - "sha2", + "sha2 0.10.8", "walkdir", ] @@ -3640,6 +4545,18 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +dependencies = [ + "log", + "ring 0.16.20", + "sct", + "webpki", +] + [[package]] name = "rustls" version = "0.23.15" @@ -3647,13 +4564,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fbb44d7acc4e873d613422379f69f237a1b141928c02f6bc6ccfddddc2d7993" dependencies = [ "once_cell", - "ring", + "ring 0.17.8", "rustls-pki-types", "rustls-webpki", "subtle", "zeroize", ] +[[package]] +name = "rustls-pemfile" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360" +dependencies = [ + "base64 0.13.1", +] + [[package]] name = "rustls-pemfile" version = "2.2.0" @@ -3675,9 +4601,9 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ - "ring", + "ring 0.17.8", "rustls-pki-types", - "untrusted", + "untrusted 0.9.0", ] [[package]] @@ -3733,7 +4659,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3748,6 +4674,16 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] + [[package]] name = "semver" version = "1.0.23" @@ -3756,22 +4692,32 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] +[[package]] +name = "serde-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3782,14 +4728,14 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] name = "serde_json" -version = "1.0.129" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbcf9b78a125ee667ae19388837dd12294b858d101fdd393cb9d5501ef09eb2" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -3797,6 +4743,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_nanos" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a93142f0367a4cc53ae0fead1bcda39e85beccfad3dcd717656cacab94b12985" +dependencies = [ + "serde", +] + [[package]] name = "serde_repr" version = "0.1.19" @@ -3805,7 +4760,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3867,7 +4822,31 @@ checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", ] [[package]] @@ -3878,7 +4857,7 @@ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", ] [[package]] @@ -3912,6 +4891,30 @@ dependencies = [ "libc", ] +[[package]] +name = "signatory" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfecc059e81632eef1dd9b79e22fc28b8fe69b30d3357512a77a0ad8ee3c782" +dependencies = [ + "pkcs8", + "rand_core 0.6.4", + "signature", + "zeroize", +] + +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + [[package]] name = "sketches-ddsketch" version = "0.1.3" @@ -3953,6 +4956,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -3962,6 +4971,21 @@ dependencies = [ "lock_api", ] +[[package]] +name = "spki" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c01a0c15da1b0b0e1494112e7af814a678fec9bd157881b49beac661e9b6f32" +dependencies = [ + "der", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -3974,6 +4998,15 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subslice" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a8e4809a3bb02de01f1f7faf1ba01a83af9e8eabcd4d31dd6e413d14d56aae" +dependencies = [ + "memchr", +] + [[package]] name = "subtle" version = "2.6.1" @@ -3993,9 +5026,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -4017,6 +5050,17 @@ dependencies = [ "futures-core", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "sysinfo" version = "0.27.8" @@ -4079,22 +5123,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -4128,6 +5172,16 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -4153,6 +5207,7 @@ dependencies = [ "bytes", "libc", "mio 1.0.2", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2 0.5.7", @@ -4178,7 +5233,18 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", +] + +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls 0.20.9", + "tokio", + "webpki", ] [[package]] @@ -4187,7 +5253,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls", + "rustls 0.23.15", "rustls-pki-types", "tokio", ] @@ -4287,7 +5353,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -4342,7 +5408,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -4372,6 +5438,15 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" +[[package]] +name = "uncased" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1b88fcfe09e89d3866a5c11019378088af2d24c3fbd4f0543f96b479ec90697" +dependencies = [ + "version_check", +] + [[package]] name = "unicase" version = "2.7.0" @@ -4420,6 +5495,12 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "untrusted" version = "0.9.0" @@ -4433,11 +5514,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", - "idna", + "idna 0.5.0", "percent-encoding", "serde", ] +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -4466,7 +5559,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "uuid", ] @@ -4497,6 +5590,17 @@ dependencies = [ "serde", ] +[[package]] +name = "uuid-simd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b082222b4f6619906941c17eb2297fff4c2fb96cb60164170522942a200bd8" +dependencies = [ + "outref", + "uuid", + "vsimd", +] + [[package]] name = "value-bag" version = "1.9.0" @@ -4526,6 +5630,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "vsimd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" + [[package]] name = "waker-fn" version = "1.2.0" @@ -4579,7 +5689,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -4613,7 +5723,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4634,6 +5744,25 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] + +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki", +] + [[package]] name = "webpki-roots" version = "0.26.6" @@ -4879,7 +6008,43 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", +] + +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", ] [[package]] @@ -4900,7 +6065,28 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", +] + +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", ] [[package]] @@ -4908,6 +6094,42 @@ name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] [[package]] name = "zip" @@ -4924,3 +6146,31 @@ dependencies = [ "num_enum", "thiserror", ] + +[[package]] +name = "zstd" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf2b778a664581e31e389454a7072dab1647606d44f7feea22cd5abb9c9f3f9" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a3ab4db68cea366acc5c897c7b4d4d1b8994a9cd6e6f841f8964566a419059" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.13+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/README.md b/README.md index b33457e92db067b5329bd3ba51d642ce9b56d46e..15566780e984317454ae6575503d799a51cb8de5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ openeuler 24.03 gcc(版本 12.3.1) ( yum groupinstall "Development Tools" 或者 yum install gcc) protoc(版本 25.1) (yum install protobuf-compiler ) sqlite3(版本 3.42.0) (yum install sqlite-devel) - +libpq (dnf install postgresql-devel) ``` ## 快速安装与验证 diff --git a/bin/nanocl/Cargo.toml b/bin/nanocl/Cargo.toml index afd9a46b195e12ea10ada3e83254e7ff26caf95b..ea4dce2d000647b9984fe98f57f24d8398e827e1 100644 --- a/bin/nanocl/Cargo.toml +++ b/bin/nanocl/Cargo.toml @@ -79,3 +79,4 @@ url = "2.5" colored = "2.1.0" cri-api = "0.1.4" dirs = "5.0.1" +feventbus = "0.2.1" \ No newline at end of file diff --git a/bin/nanocl/src/commands/state.rs b/bin/nanocl/src/commands/state.rs index e928ae1561fbaf80b5390f2fcf7cf023799f083e..cb859499cc73772f26a42c371bba2eb03ac212b7 100644 --- a/bin/nanocl/src/commands/state.rs +++ b/bin/nanocl/src/commands/state.rs @@ -1,13 +1,10 @@ -use std::{ - collections::HashMap, - env::{consts, vars_os}, - fs, - path::{Path, PathBuf}, - time::Duration, -}; - +use std::{collections::HashMap, env::{consts, vars_os}, fs, path::{Path, PathBuf}, time, time::Duration}; +use std::fmt::Debug; +use std::sync::Arc; use async_recursion::async_recursion; use clap::{Arg, ArgAction, Command}; +use feventbus::impls::nats::nats::NatsCli; +use feventbus::message; use futures::{ join, stream::{FuturesOrdered, FuturesUnordered}, @@ -49,7 +46,11 @@ use crate::{ }, utils, }; - +use feventbus::message::Message; +use feventbus::traits::controller::EventBus; +use feventbus::traits::producer::Producer; +use serde::{Deserialize, Serialize}; +use crate::models::StateRequestOpts; use super::GenericCommandRm; /// Get Statefile from url and return a StateRef with the raw data and the format @@ -818,6 +819,52 @@ async fn state_apply( Ok(()) } +/// Process cargoes in Statefile and return updated Statefile +async fn process_statefile_cargoes( + mut state_file: StateRef, +) -> IoResult> { + let nanocl_group = get_nanocl_group(&state_file); + + if let Some(cargoes) = &mut state_file.data.cargoes { + let mut updated_cargoes = Vec::new(); + + for cargo in cargoes.iter() { + let mut cargo = cargo.to_owned(); + + // Update container metadata if not present + if let Some(container) = cargo.container.as_mut() { + if container.container_config_Partial.metadata.is_none() { + container.container_config_Partial.metadata = Some(ContainerMetadataPartial { + name: Some(format!( + "{}-{}.{}.c", + cargo.name.clone(), + generate_short_id(6), + "global" + )), + ..Default::default() + }); + } + } + + // Update cargo metadata with nanocl group + let cargo_meta: Option = cargo + .metadata + .as_ref() + .and_then(|m| serde_json::from_str(m).ok()); + + let updated_metadata = insert_nanocl_group(&cargo_meta, &nanocl_group); + cargo.metadata = Some(updated_metadata.to_string()); + + updated_cargoes.push(cargo); + } + + // Replace original cargoes with updated ones + state_file.data.cargoes = Some(updated_cargoes); + } + + Ok(state_file) +} + fn print_states(states: &[StateRef]) { let raw = states.iter().fold(String::new(), |init, state| { format!("{init}{}\n", state.raw.trim()) @@ -950,6 +997,92 @@ async fn exec_state_apply( Ok(()) } + + +/// Function called when running `nanocl state apply` +async fn request_state_apply( + cli_conf: &CliConfig, + opts: &StateRequestOpts, +) -> IoResult<()> { + let format = cli_conf.user_config.display_format.clone(); + let state_file = read_state_file(&opts.state_location, &format).await?; + let args = parse_build_args(&state_file.data, &opts.args)?; + let states = parse_state_file_recurr(cli_conf, &state_file, &args).await?; + if !opts.skip_confirm { + print_states(&states); + utils::dialog::confirm("Are you sure to apply this state ?") + .map_err(|err| err.map_err_context(|| "StateApply"))?; + } + + + + for state in &states { + if opts.remove_orphans { + remove_orphans(cli_conf, state).await?; + } + + // 初始化 metadata 并插入 MODEL 字段 + let mut metadata = HashMap::new(); + metadata.insert("MODEL".to_string(), opts.clone().model.unwrap()); + let sta =process_statefile_cargoes(state.clone()).await.unwrap(); + let json_data: Value = serde_json::to_value(sta.data.clone())?; + let request_message = Message::new( + opts.clone().topic.unwrap(), + message::NativeEventAction::Create, + Some(metadata), + Some(json_data), + None, + ); + + let nats_cli = Arc::new(NatsCli::new().await.unwrap()); + send_request::(request_message, Arc::clone(&nats_cli)).await; + } + if opts.follow { + states + .iter() + .map(|state| async { + state_logs( + cli_conf, + &StateLogsOpts { + state_location: Some(state.root.to_string()), + follow: true, + ..Default::default() + }, + state, + ) + .await; + }) + .collect::>() + .collect::>() + .await; + } + Ok(()) +} + +// 发送请求并等待响应 +async fn send_request(message: Message, nats_cli: Arc) -> Result<(), Box> +where + T: Serialize + for<'de> Deserialize<'de> + Debug + Clone + Send + Sync + 'static, +{ + match nats_cli + .request(message, time::Duration::from_secs(100)) + .await + { + Ok(response) => { + println!( + "Received response: {:?}", + response + ); + Ok(()) + } + Err(e) => { + println!("Failed to get response: {:?}", e); + Err(Box::new(e) as Box) + } + } +} + + async fn state_logs( cli_conf: &CliConfig, opts: &StateLogsOpts, @@ -1071,5 +1204,6 @@ pub async fn exec_state(cli_conf: &CliConfig, args: &StateArg) -> IoResult<()> { StateCommand::Apply(opts) => exec_state_apply(cli_conf, opts).await, StateCommand::Remove(opts) => exec_state_remove(cli_conf, opts).await, StateCommand::Logs(opts) => exec_state_logs(cli_conf, opts).await, + StateCommand::Request(opts) => request_state_apply(cli_conf, opts).await, } } diff --git a/bin/nanocl/src/models/state.rs b/bin/nanocl/src/models/state.rs index 2f9d176d0abaf91b52343a7e84c8c8ff73f7339c..d2261512a5bf1a8afb54c91a45272076a46fab92 100644 --- a/bin/nanocl/src/models/state.rs +++ b/bin/nanocl/src/models/state.rs @@ -7,6 +7,44 @@ use clap::{Parser, Subcommand}; use super::DisplayFormat; + + + + +/// `nanocl state request` available options +#[derive(Parser, Clone)] +pub struct StateRequestOpts { + /// Path or Url to the Statefile + #[clap(long, short = 's')] + pub state_location: Option, + /// topic + #[clap(long, short = 't',default_value = "CREATE")] + pub topic: Option, + /// model + #[clap(long, short = 'm',default_value = "CARGO")] + pub model: Option, + /// action + #[clap(long, short = 'a',default_value = "CREATE")] + pub action: Option, + /// Follow logs of the deployed cargo + #[clap(long, short = 'f')] + pub follow: bool, + /// Skip the confirmation prompt + #[clap(long = "yes", short = 'y')] + pub skip_confirm: bool, + /// Perform an apply even if state didn't changed + #[clap(long, short = 'r')] + pub reload: bool, + /// Additional arguments to pass to the file + #[clap(last = true, raw = true)] + pub args: Vec, + /// Remove orphaned elements + #[clap(long)] + pub remove_orphans: bool, + +} + + /// `nanocl state apply` available options #[derive(Parser, Clone)] pub struct StateApplyOpts { @@ -80,6 +118,8 @@ pub enum StateCommand { /// Remove elements from a Statefile #[clap(alias("rm"))] Remove(StateRemoveOpts), + /// request elements from a Statefile + Request(StateRequestOpts), } /// `nanocl state` available arguments diff --git a/bin/nanocld/Cargo.toml b/bin/nanocld/Cargo.toml index e499cd8856f62fd6b225245790d631248bf766c9..4e559e67afc1cd073bdc0bac15d18470dc0ea942 100644 --- a/bin/nanocld/Cargo.toml +++ b/bin/nanocld/Cargo.toml @@ -102,3 +102,5 @@ serde_urlencoded = "0.7.1" http = "1.1.0" dirs = "5.0.1" cri-api = "0.1.4" +feventbus = "0.3.0" +fleet_apiserver = "0.3.5" \ No newline at end of file diff --git a/bin/nanocld/src/apiserver/apiserver.rs b/bin/nanocld/src/apiserver/apiserver.rs new file mode 100644 index 0000000000000000000000000000000000000000..67b4828b4d92d970780a1c4766bf6320083c0fa1 --- /dev/null +++ b/bin/nanocld/src/apiserver/apiserver.rs @@ -0,0 +1,17 @@ +use ntex::rt; +use std::time; +pub fn start_apiserver() { + rt::Arbiter::new().exec_fn(move || { + rt::spawn(async move { + loop { + let database_url = "sqlite://./database.sqlite"; + let address = "0.0.0.0:8080"; + if let Err(e) = fleet_apiserver::start_server(database_url, address).await + { + eprintln!("Error starting server: {}", e); + } + ntex::time::sleep(time::Duration::from_secs(1)).await; + } + }); + }); +} diff --git a/bin/nanocld/src/apiserver/mod.rs b/bin/nanocld/src/apiserver/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..562c07b524d88805f279d747acfcef8a51a92721 --- /dev/null +++ b/bin/nanocld/src/apiserver/mod.rs @@ -0,0 +1 @@ +pub(crate) mod apiserver; \ No newline at end of file diff --git a/bin/nanocld/src/cli.rs b/bin/nanocld/src/cli.rs index e38a39d954d11422b8baadfbd6456c3689170a9d..076549a3d6b105cc1a964f88b6692ecbd6f36138 100644 --- a/bin/nanocld/src/cli.rs +++ b/bin/nanocld/src/cli.rs @@ -14,6 +14,9 @@ pub struct Cli { /// Docker daemon socket to connect [default: unix:///var/run/docker.sock] #[clap(long)] pub docker_host: Option, + /// cri daemon socket to connect [default: unix:///run/containerd/containerd.sock] + #[clap(long)] + pub runtime_endpoint: Option, /// Store address to connect to #[clap(long)] pub store_addr: Option, @@ -49,6 +52,7 @@ impl Default for Cli { Self { hosts: None, docker_host: None, + runtime_endpoint: None, store_addr: None, state_dir: None, conf_dir: String::from("/etc/nanocl"), diff --git a/bin/nanocld/src/config.rs b/bin/nanocld/src/config.rs index 414deb20b0303a5815b719b1e14ce99f0c52622f..6bf0c02dcc1dcdac036e0407f1a6bf2e11c91930 100644 --- a/bin/nanocld/src/config.rs +++ b/bin/nanocld/src/config.rs @@ -31,6 +31,13 @@ fn gen_daemon_conf( } else { String::from("/var/run/docker.sock") }; + let runtime_endpoint = if let Some(ref runtime_endpoint) = args.runtime_endpoint { + runtime_endpoint.to_owned() + } else if let Some(ref runtime_endpoint) = config.runtime_endpoint { + runtime_endpoint.to_owned() + } else { + String::from("/run/containerd/containerd.sock") + }; let gateway = if let Some(ref gateway) = args.gateway { gateway.to_owned() } else if let Some(ref gateway) = config.gateway { @@ -64,6 +71,7 @@ fn gen_daemon_conf( hostname, state_dir, docker_host, + runtime_endpoint, store_addr, gid: args.gid, advertise_addr, @@ -124,6 +132,7 @@ mod tests { store_addr: None, gateway: None, hostname: None, + runtime_endpoint: None, }; let merged = gen_daemon_conf(&args, &config).unwrap(); assert_eq!(merged.hosts, args.hosts.unwrap()); diff --git a/bin/nanocld/src/eventbus/create.rs b/bin/nanocld/src/eventbus/create.rs new file mode 100644 index 0000000000000000000000000000000000000000..6e80db14835e28c3de66e098f696ddcb965a6fac --- /dev/null +++ b/bin/nanocld/src/eventbus/create.rs @@ -0,0 +1,309 @@ +use crate::eventbus::eventbus; +use crate::eventbus::models::apiserver_cargo::apiservercargo; +use crate::models::{CargoDb, CargoObjCreateIn, SystemState}; +use crate::objects::generic::ObjCreate; +use crate::utils; +use diesel::serialize::IsNull::No; +use feventbus::impls::nats::nats::NatsCli; +use feventbus::message::Message; +use feventbus::traits::consumer::MessageHandler; +use feventbus::traits::controller::EventBus; +use nanocl_stubs::cargo::Cargo; +use nanocl_stubs::cargo_spec::CargoSpecPartial; +use nanocl_stubs::cargo_spec::ReplicationMode::Auto; +use nanocl_stubs::cri_spec::ContainerMetadataPartial; +use nanocl_stubs::process::ProcessKind; +use nanocl_stubs::statefile::Statefile; +use std::collections::HashMap; +use std::error::Error; +use std::fmt::Debug; +use std::sync::Arc; +use serde_json::Value; +use tokio::sync::oneshot; +use tokio::task::JoinHandle; + +fn log_and_return_error( + message: &str, + error: E, +) -> Result<(), Box> +where + E: Error + Debug + Send + Sync + 'static, +{ + log::error!("{}", message); + Err(Box::new(error)) +} + +async fn handle_create_cargo_from_nanocld( + system_state: Arc, + msg: Statefile, +) -> Result<(), Box> { + let namespace = msg.namespace.unwrap_or_else(|| "global".to_string()); + let version = msg.api_version; + + if let Some(cargoes) = msg.cargoes { + for item in cargoes.iter() { + let obj = CargoObjCreateIn { + namespace: namespace.clone(), + spec: item.clone(), + version: version.clone(), + }; + + match CargoDb::create_obj(&obj, &system_state).await { + Ok(cargo) => { + let system_pro = Arc::clone(&system_state); + let kind_key = utils::key::gen_kind_key( + &ProcessKind::Cargo, + &cargo.spec.name, + &Some(cargo.namespace_name), + ); + match utils::container::emit_starting( + &kind_key, + &ProcessKind::Cargo, + &system_pro, + ) + .await + { + Ok(_) => { + log::info!("cargo create successful: {:?}", cargo.spec.name); + } + Err(e) => { + return log_and_return_error("Cargo start failed", e); + } + } + } + Err(e) => { + return log_and_return_error("Cargo create failed", e); + } + } + } + } else { + return log_and_return_error( + "No cargoes found in statefile", + std::io::Error::new( + std::io::ErrorKind::InvalidData, + "No cargoes found in statefile", + ), + ); + } + + Ok(()) +} + + + +fn insert_nanocl_group( + metadata: &Option, + group: &str, +) -> Value { + match metadata { + Some(metadata) => { + let mut metadata = metadata.clone(); + metadata.as_object_mut().unwrap().insert( + "io.nanocl.group".to_owned(), + Value::String(group.to_owned()), + ); + metadata + } + None => serde_json::json!({ + "io.nanocl.group": group, + }), + } +} + +// The core logic for creating cargo +async fn handle_create_cargo_from_apiserver( + system_state: Arc, + msg: apiservercargo, +) -> Result<(), Box> { + if msg.content.kind != "Cargo" { + return log_and_return_error( + "Cargo start failed", + std::io::Error::new(std::io::ErrorKind::InvalidData, "kind is not Cargo"), + ); + } + + let mut cargo_partial = msg.content.spec.clone(); + let mut cri_config_partial = match cargo_partial.container { + Some(cri_config_partial) => cri_config_partial, + None => { + return log_and_return_error( + "Cargo start failed", + std::io::Error::new( + std::io::ErrorKind::InvalidData, + "container key not found", + ) + ); + } + }; + + let namespace = msg + .content + .metadata + .namespace + .unwrap_or_else(|| "global".to_string()); + let version = msg + .content + .apiVersion + .unwrap_or_else(|| "v0.15".to_string()); + let cargo_name = msg.content.spec.name; + + if cri_config_partial + .container_config_Partial + .metadata + .is_none() + { + let container_metadata_partial = Some(ContainerMetadataPartial { + name: Some(format!( + "{}-{}.{}.c", + cargo_name, + utils::key::generate_short_id(6), + namespace + )), + ..Default::default() + }); + cri_config_partial.container_config_Partial.metadata = container_metadata_partial; + } + cargo_partial.container=Some(cri_config_partial.clone()); + + let cargo_meta: Option = cargo_partial + .metadata + .as_ref() + .and_then(|m| serde_json::from_str(m).ok()); + let updated_metadata = insert_nanocl_group(&cargo_meta, ""); + cargo_partial.metadata = Some(updated_metadata.to_string()); + + let obj = CargoObjCreateIn { + namespace: namespace.clone(), + spec: cargo_partial.clone(), + version: version.clone(), + }; + + match CargoDb::create_obj(&obj, &system_state).await { + Ok(cargo) => { + let system_pro = Arc::clone(&system_state); + let kind_key = utils::key::gen_kind_key( + &ProcessKind::Cargo, + &cargo.spec.name, + &Some(cargo.namespace_name), + ); + match utils::container::emit_starting( + &kind_key, + &ProcessKind::Cargo, + &system_pro, + ) + .await + { + Ok(_) => { + log::info!("cargo create successful: {:?}", cargo.spec.name); + } + Err(e) => { + return log_and_return_error("Cargo create failed", e); + } + } + } + Err(e) => { + return log_and_return_error("Cargo create failed", e); + } + } + Ok(()) +} + +// The core logic for creating cargo +pub async fn setup_reply_to_create_resource_topic( + topic: String, + system_state: Arc, +) where + T: Send + + Sync + + serde::de::DeserializeOwned + + serde::Serialize + + Debug + + Clone + + 'static, +{ + let reply_handler: MessageHandler = + Arc::new(move |msg: Message| { + let system_state = Arc::clone(&system_state); + Box::pin(async move { + let metadata = match msg.metadata { + Some(ref meta) => meta, + None => { + return Err(feventbus::err::Error::MessageHandling( + "Message metadata is missing".to_string(), + )); + } + }; + + let model = match metadata.get("MODEL") { + Some(model) => model, + None => { + return Err(feventbus::err::Error::MessageHandling( + "MODEL key is missing in message metadata".to_string(), + )); + } + }; + + let uppercase_model = model.to_uppercase(); + // todo 只支持CARGO类型 + if uppercase_model != "CARGO" + && uppercase_model != "JOB" + && uppercase_model != "CRONJOB" + { + return Err(feventbus::err::Error::MessageHandling(format!( + "Unsupported MODEL type: {}", + model + ))); + } + + let body = msg.body.ok_or_else(|| { + feventbus::err::Error::MessageHandling( + "Message body is missing".to_string(), + ) + })?; + + // log::info!("{:#?}", body); + + if let Ok(apiserver_cargo) = + serde_json::from_value::(body.clone()) + { + handle_create_cargo_from_apiserver(system_state, apiserver_cargo) + .await + .map(|_| "Cargo created successfully".to_string()) + .map_err(|e| { + log::error!("Cargo created failed: {:?}", e); + feventbus::err::Error::MessageHandling(format!( + "Cargo created failed: {:?}", + e + )) + }) + } else if let Ok(statefile_msg) = + serde_json::from_value::(body.clone()) + { + handle_create_cargo_from_nanocld(system_state, statefile_msg) + .await + .map(|_| "Cargo created successfully".to_string()) + .map_err(|e| { + log::error!("Cargo created failed: {:?}", e); + feventbus::err::Error::MessageHandling(format!( + "Cargo created failed: {:?}", + e + )) + }) + } else { + return Err(feventbus::err::Error::MessageHandling( + "create body json unmarshl failed".to_string(), + )); + } + }) + }); + + let nats_cli = Arc::new(NatsCli::new().await.unwrap()); + match eventbus::reply_to_topic(topic.clone(), nats_cli, reply_handler).await { + Ok(_) => { + log::info!("Subscribed to topic: {}", topic); + } + Err(e) => { + log::error!("Failed to subscribe to topic: {}. Error: {:?}", topic, e); + } + } +} diff --git a/bin/nanocld/src/eventbus/delete.rs b/bin/nanocld/src/eventbus/delete.rs new file mode 100644 index 0000000000000000000000000000000000000000..881aa493495f7d9bed00070dadb847e28c0f1f54 --- /dev/null +++ b/bin/nanocld/src/eventbus/delete.rs @@ -0,0 +1,226 @@ +use crate::eventbus::eventbus; +use crate::eventbus::models::apiserver_cargo::apiservercargo; +use crate::eventbus::models::del_apiserver; +use crate::eventbus::models::del_apiserver::DelApiserverResources; +use crate::models::{CargoDb, CargoObjCreateIn, SystemState}; +use crate::objects::generic::{ObjCreate, ObjDelByPk}; +use crate::schema::vm_images::format; +use crate::utils; +use feventbus::impls::nats::nats::NatsCli; +use feventbus::message::Message; +use feventbus::traits::consumer::MessageHandler; +use feventbus::traits::controller::EventBus; +use futures_util::future::ok; +use nanocl_stubs::cargo::{Cargo, CargoDeleteQuery}; +use nanocl_stubs::cri_spec::ContainerMetadataPartial; +use nanocl_stubs::process::ProcessKind; +use nanocl_stubs::statefile::Statefile; +use serde_json::Value; +use std::collections::HashMap; +use std::error::Error; +use std::fmt::Debug; +use std::sync::Arc; +use tokio::sync::oneshot; +use tokio::task::JoinHandle; + +fn log_and_return_error( + message: &str, + error: E, +) -> Result<(), Box> +where + E: Error + Debug + Send + Sync + 'static, +{ + log::error!("{}", message); + Err(Box::new(error)) +} + +// The core logic for creating cargo +async fn handle_delete_cargo_from_apiserver( + system_state: Arc, + msg: DelApiserverResources, +) -> Result<(), Box> { + if msg.content.Plural == "cargos" { + let mut namespace = msg.content.Namespaces; + if namespace == "".to_string() { + namespace = "global".to_string() + } + + let mut cargo_name = msg.content.Name; + if cargo_name == "".to_string() { + return log_and_return_error( + "Cargo delete failed", + std::io::Error::new( + std::io::ErrorKind::InvalidData, + "No (name) key found in request", + ), + ); + } + let key = utils::key::gen_key(&namespace, &cargo_name); + // log::debug!("service::delete_cargo: {namespace},{cargo_name},{key}"); + log::debug!("service::delete_cargo: {namespace},{cargo_name},{key}"); + let qs = CargoDeleteQuery { + namespace: None, + force: None, + }; + match CargoDb::del_obj_by_pk(&key, &qs, &system_state).await { + Ok(cargo) => {} + Err(e) => { + return log_and_return_error("Cargo delete failed", e); + } + } + } + Ok(()) +} + +// The core logic for creating cargo +async fn handle_delete_cargo_from_nanocld( + system_state: Arc, + msg: Statefile, +) -> Result<(), Box> { + let namespace = msg.namespace.unwrap_or_else(|| "global".to_string()); + let version = msg.api_version; + + if let Some(cargoes) = msg.cargoes { + for item in cargoes.iter() { + let namespace = utils::key::resolve_nsp(&Some(namespace.clone())); + let name = &item.name; + let key = utils::key::gen_key(&namespace, &item.name); + log::debug!("service::delete_cargo: {namespace},{name},{key}"); + let qs = CargoDeleteQuery { + namespace: None, + force: None, + }; + match CargoDb::del_obj_by_pk(&key, &qs, &system_state).await { + Ok(cargo) => {} + Err(e) => { + return log_and_return_error("Cargo delete failed", e); + } + } + } + } else { + return log_and_return_error( + "No cargoes found in statefile", + std::io::Error::new( + std::io::ErrorKind::InvalidData, + "No cargoes found in statefile", + ), + ); + } + Ok(()) +} + +// The core logic for creating cargo +pub async fn setup_reply_to_delete_resource_topic( + topic: String, + system_state: Arc, +) where + T: Send + + Sync + + serde::de::DeserializeOwned + + serde::Serialize + + Debug + + Clone + + 'static, +{ + let reply_handler: MessageHandler = + Arc::new(move |msg: Message| { + let system_state = Arc::clone(&system_state); + Box::pin(async move { + let metadata = match msg.metadata { + Some(ref meta) => meta, + None => { + return Err(feventbus::err::Error::MessageHandling( + "Message metadata is missing".to_string(), + )); + } + }; + + let model = match metadata.get("MODEL") { + Some(model) => model, + None => { + return Err(feventbus::err::Error::MessageHandling( + "MODEL key is missing in message metadata".to_string(), + )); + } + }; + let uppercase_model = model.to_uppercase(); + if uppercase_model != "CARGO" + && uppercase_model != "JOB" + && uppercase_model != "CRONJOB" + { + return Err(feventbus::err::Error::MessageHandling(format!( + "Unsupported MODEL type: {}", + model + ))); + } + + let body = msg.body.ok_or_else(|| { + feventbus::err::Error::MessageHandling( + "Message body is missing".to_string(), + ) + })?; + + if let Ok(delete_apiserver_resources) = + serde_json::from_value::(body.clone()) + { + let rel =handle_delete_cargo_from_apiserver(system_state,delete_apiserver_resources).await; + match rel { + Ok(()) => return Ok("Cargo delete successfully".to_string()), + Err(e) => { + return Err(feventbus::err::Error::MessageHandling(format!( + "Cargo delete failed: {:?}", + e + ))) + } + } + } else if let Ok(statefile_msg) = + serde_json::from_value::(body.clone()) + { + let rel = + handle_delete_cargo_from_nanocld(system_state, statefile_msg).await; + match rel { + Ok(()) => return Ok("Cargo delete successfully".to_string()), + Err(e) => { + return Err(feventbus::err::Error::MessageHandling(format!( + "Cargo delete failed: {:?}", + e + ))) + } + } + } else { + return Err(feventbus::err::Error::MessageHandling( + "delete body json unmarshl failed".to_string(), + )); + } + + // let statefile_msg = serde_json::from_value::(body.clone()) + // .map_err(|e| { + // feventbus::err::Error::MessageHandling(format!( + // "Failed to parse message body to staefile: {:?}", + // e + // )) + // })?; + // + // handle_delete_cargo(system_state, statefile_msg) + // .await + // .map(|_| "Cargo delete successfully".to_string()) + // .map_err(|e| { + // log::error!("Cargo delete failed: {:?}", e); + // feventbus::err::Error::MessageHandling(format!( + // "Cargo delete failed: {:?}", + // e + // )) + // }) + }) + }); + + let nats_cli = Arc::new(NatsCli::new().await.unwrap()); + match eventbus::reply_to_topic(topic.clone(), nats_cli, reply_handler).await { + Ok(_) => { + log::info!("Subscribed to topic: {}", topic); + } + Err(e) => { + log::error!("Failed to subscribe to topic: {}. Error: {:?}", topic, e); + } + } +} diff --git a/bin/nanocld/src/eventbus/eventbus.rs b/bin/nanocld/src/eventbus/eventbus.rs new file mode 100644 index 0000000000000000000000000000000000000000..0061a3c52f54c2cd5ea96b35dc301136b9194ecc --- /dev/null +++ b/bin/nanocld/src/eventbus/eventbus.rs @@ -0,0 +1,132 @@ +use crate::eventbus::{create, delete}; +use crate::models::{CargoDb, CargoObjCreateIn, SystemState}; +use crate::objects::generic::ObjCreate; +use feventbus::impls::nats::nats::NatsCli; +use feventbus::message::Message; +use feventbus::traits::consumer::Consumer; +use feventbus::traits::consumer::MessageHandler; +use feventbus::traits::controller::EventBus; +use feventbus::traits::producer::Producer; +use nanocl_stubs::statefile::Statefile; +use ntex::rt; +use serde::{Deserialize, Serialize}; +use std::error::Error; +use std::fmt::Debug; +use std::sync::Arc; +use std::time; + +pub fn analyze(state: SystemState) { + rt::Arbiter::new().exec_fn(move || { + rt::spawn(async move { + loop { + if let Err(err) = handle_event_message(state.clone()).await { + log::warn!("event::handle_event_message: {:?}", err); + } + ntex::time::sleep(time::Duration::from_secs(1)).await; + } + }); + }); +} +pub async fn handle_event_message( + system_state: SystemState, +) -> Result<(), Box> { + let system_state = Arc::new(system_state); + + let create_task = + tokio::spawn(create::setup_reply_to_create_resource_topic::< + serde_json::Value, + >("CREATE".to_string(), Arc::clone(&system_state))); + + let delete_task = + tokio::spawn(delete::setup_reply_to_delete_resource_topic::< + serde_json::Value, + >("DELETE".to_string(), Arc::clone(&system_state))); + + let _ = delete_task + .await + .map_err(|e| Box::new(e) as Box)?; + let _ = create_task + .await + .map_err(|e| Box::new(e) as Box)?; + + Ok(()) +} + +// 其他辅助函数保持不变 +pub async fn subscribe_to_topic( + topic: &str, + nats_cli: Arc, + handler: MessageHandler, +) where + T: Serialize + + for<'de> Deserialize<'de> + + Debug + + Clone + + Send + + Sync + + 'static, +{ + nats_cli.subscribe(topic, handler).await; +} + +pub async fn publish_message( + message: Message, + nats_cli: Arc, +) -> Result<(), Box> +where + T: Serialize + + for<'de> Deserialize<'de> + + Debug + + Send + + Clone + + Sync + + 'static, +{ + if let Err(e) = nats_cli.publish(message).await { + return Err(Box::new(e) as Box); + } + Ok(()) +} + +pub async fn reply_to_topic( + topic: String, + nats_cli: Arc, + handler: MessageHandler, +) -> Result<(), Box> { + nats_cli + .reply(topic.as_str(), handler) + .await + .map_err(|e| Box::new(e) as Box)?; + Ok(()) +} + +pub async fn send_request( + message: Message, + nats_cli: Arc, +) -> Result<(), Box> +where + T: Serialize + + for<'de> Deserialize<'de> + + Debug + + Clone + + Send + + Sync + + 'static, +{ + match nats_cli + .request(message, time::Duration::from_secs(100)) + .await + { + Ok(response) => { + println!( + "===============Received response: {:?}==================", + response + ); + Ok(()) + } + Err(e) => { + println!("Failed to get response: {:?}", e); + Err(Box::new(e) as Box) + } + } +} diff --git a/bin/nanocld/src/eventbus/mod.rs b/bin/nanocld/src/eventbus/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..f1d8eabe4447b86438e01fede3b30febb5bb87c1 --- /dev/null +++ b/bin/nanocld/src/eventbus/mod.rs @@ -0,0 +1,4 @@ +pub mod eventbus; +pub mod create; +mod delete; +mod models; diff --git a/bin/nanocld/src/eventbus/models/apiserver_cargo.rs b/bin/nanocld/src/eventbus/models/apiserver_cargo.rs new file mode 100644 index 0000000000000000000000000000000000000000..e2fbb8756e2d3ef391a400e3d813adac2145892d --- /dev/null +++ b/bin/nanocld/src/eventbus/models/apiserver_cargo.rs @@ -0,0 +1,26 @@ +use nanocl_stubs::cargo_spec::CargoSpecPartial; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + + + + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct apiservercargo { + pub content: apiservercargomes, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct apiservercargomes { + pub apiVersion: Option, + pub kind: String, + pub metadata: Metadata, + pub spec: CargoSpecPartial, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct Metadata { + pub name: String, + pub namespace: Option, + pub annotations: Option>, +} diff --git a/bin/nanocld/src/eventbus/models/del_apiserver.rs b/bin/nanocld/src/eventbus/models/del_apiserver.rs new file mode 100644 index 0000000000000000000000000000000000000000..a2a0d9170bc79db10990bbae784141e5429d7027 --- /dev/null +++ b/bin/nanocld/src/eventbus/models/del_apiserver.rs @@ -0,0 +1,15 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct DelApiserverResources { + pub content: delresources, +} + + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct delresources { + pub Name: String, + pub Namespaces: String, + pub Plural: String, + pub apiVersion: String, +} diff --git a/bin/nanocld/src/eventbus/models/mod.rs b/bin/nanocld/src/eventbus/models/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..2c860455514a8dbeb917b6a426b55742005100a7 --- /dev/null +++ b/bin/nanocld/src/eventbus/models/mod.rs @@ -0,0 +1,2 @@ +pub mod apiserver_cargo; +pub mod del_apiserver; \ No newline at end of file diff --git a/bin/nanocld/src/main.rs b/bin/nanocld/src/main.rs index d3e3c8eae35d002c21aa18dd89dfe128574868f3..b58072867eaac65a2251cae7bdb24efbc2771994 100644 --- a/bin/nanocld/src/main.rs +++ b/bin/nanocld/src/main.rs @@ -27,6 +27,8 @@ mod tasks; mod utils; mod vars; mod k8scri; +mod eventbus; +mod apiserver; /// Provides an api to manage containers and virtual machines across physical hosts /// There are these advantages : diff --git a/bin/nanocld/src/services/process.rs b/bin/nanocld/src/services/process.rs index a80a9b62219928a30e6d26a47a8b0caa428b7cfe..91ac2f3e930229d8585f37b6aa485d2694d2545b 100644 --- a/bin/nanocld/src/services/process.rs +++ b/bin/nanocld/src/services/process.rs @@ -226,6 +226,7 @@ pub async fn start_processes( let (_, kind, name) = path.into_inner(); let kind = kind.parse().map_err(HttpError::bad_request)?; let kind_key = utils::key::gen_kind_key(&kind, &name, &qs.namespace); + println!("{},{}",kind_key,kind); utils::container::emit_starting(&kind_key, &kind, &state).await?; Ok(web::HttpResponse::Accepted().finish()) } diff --git a/bin/nanocld/src/system/init.rs b/bin/nanocld/src/system/init.rs index 31c779af05d08546c8dee37dca3f18c4cda42c23..cbebadbd696e93e625e220702e1f8d1a43336503 100644 --- a/bin/nanocld/src/system/init.rs +++ b/bin/nanocld/src/system/init.rs @@ -8,135 +8,132 @@ use tokio::fs; use nanocl_error::io::{FromIo, IoResult}; use nanocl_stubs::config::DaemonConfig; -use crate::{ - models::{NodeDb, SystemState}, - utils, -}; +use crate::{apiserver, eventbus, models::{NodeDb, SystemState}, utils}; /// Create a new thread and watch for change in the run directory /// and set the permission of the unix socket /// Then close the thread fn set_uds_perm() { - log::trace!("boot::set_uds_perm: start thread"); - rt::Arbiter::new().exec_fn(|| { - rt::spawn(async { - let path = Path::new("/run/nanocl"); - if !path.exists() { - log::warn!("boot::set_uds_perm: /run/nanocl not found"); - return; - } - let (tx, rx) = std::sync::mpsc::channel(); - // Automatically select the best implementation for your platform. - // You can also access each implementation directly e.g. INotifyWatcher. - let mut watcher = match RecommendedWatcher::new(tx, Config::default()) { - Ok(watcher) => watcher, - Err(e) => { - log::warn!("boot::set_uds_perm: {e}"); - return; - } - }; - // Add a path to be watched. All files and directories at that path and - // below will be monitored for changes. - watcher.watch(path, RecursiveMode::Recursive).unwrap(); - log::trace!("boot::set_uds_perm: watching /run/nanocl"); - for res in rx { - match res { - Ok(event) => { - if event.kind.is_modify() - || event.kind.is_create() - || event.kind.is_access() - || event.kind.is_other() - { - log::trace!("boot::set_uds_perm: /run/nanocl change detected",); - let mut perms = - match fs::metadata("/run/nanocl/nanocl.sock").await { - Err(err) => { - log::warn!( + log::trace!("boot::set_uds_perm: start thread"); + rt::Arbiter::new().exec_fn(|| { + rt::spawn(async { + let path = Path::new("/run/nanocl"); + if !path.exists() { + log::warn!("boot::set_uds_perm: /run/nanocl not found"); + return; + } + let (tx, rx) = std::sync::mpsc::channel(); + // Automatically select the best implementation for your platform. + // You can also access each implementation directly e.g. INotifyWatcher. + let mut watcher = match RecommendedWatcher::new(tx, Config::default()) { + Ok(watcher) => watcher, + Err(e) => { + log::warn!("boot::set_uds_perm: {e}"); + return; + } + }; + // Add a path to be watched. All files and directories at that path and + // below will be monitored for changes. + watcher.watch(path, RecursiveMode::Recursive).unwrap(); + log::trace!("boot::set_uds_perm: watching /run/nanocl"); + for res in rx { + match res { + Ok(event) => { + if event.kind.is_modify() + || event.kind.is_create() + || event.kind.is_access() + || event.kind.is_other() + { + log::trace!("boot::set_uds_perm: /run/nanocl change detected",); + let mut perms = + match fs::metadata("/run/nanocl/nanocl.sock").await { + Err(err) => { + log::warn!( "boot::set_uds_perm: /run/nanocl/nanocl.sock {err}" ); - break; - } - Ok(perms) => perms.permissions(), - }; - perms.set_mode(0o770); - if let Err(err) = - fs::set_permissions("/run/nanocl/nanocl.sock", perms).await - { - log::warn!("boot::set_uds_perm: /run/nanocl/nanocl.sock {err}"); - } - log::trace!( + break; + } + Ok(perms) => perms.permissions(), + }; + perms.set_mode(0o770); + if let Err(err) = + fs::set_permissions("/run/nanocl/nanocl.sock", perms).await + { + log::warn!("boot::set_uds_perm: /run/nanocl/nanocl.sock {err}"); + } + log::trace!( "boot::set_uds_perm: /run/nanocl/nanocl.sock permission set" ); - break; - } - } - Err(err) => { - log::warn!("boot::set_uds_perm: watcher {err}"); - break; - } - } + break; } - log::trace!("boot::set_uds_perm: stop thread"); - rt::Arbiter::current().stop(); - }); + } + Err(err) => { + log::warn!("boot::set_uds_perm: watcher {err}"); + break; + } + } + } + log::trace!("boot::set_uds_perm: stop thread"); + rt::Arbiter::current().stop(); }); + }); } /// Create a new thread and spawn and manage a crond instance to run cron jobs fn _spawn_crond() { - log::trace!("boot::spawn_crond: start thread"); - rt::Arbiter::new().exec_fn(|| { - rt::spawn(async { - let task = ntex::web::block(move || { - match Command::new("crond").args(["-f"]).spawn() { - Ok(mut child) => { - child.wait()?; - Ok(()) - } - Err(err) => Err(err), - } - }) - .await; - if let Err(err) = task { - log::error!("boot::spawn_crond: {err}"); - } - log::trace!("boot::spawn_crond: stop thread"); - rt::Arbiter::current().stop(); - }); + log::trace!("boot::spawn_crond: start thread"); + rt::Arbiter::new().exec_fn(|| { + rt::spawn(async { + let task = ntex::web::block(move || { + match Command::new("crond").args(["-f"]).spawn() { + Ok(mut child) => { + child.wait()?; + Ok(()) + } + Err(err) => Err(err), + } + }) + .await; + if let Err(err) = task { + log::error!("boot::spawn_crond: {err}"); + } + log::trace!("boot::spawn_crond: stop thread"); + rt::Arbiter::current().stop(); }); + }); } /// Ensure that the state dir exists and is ready to use async fn ensure_state_dir(state_dir: &str) -> IoResult<()> { - let vm_dir = format!("{state_dir}/vms/images"); - fs::create_dir_all(vm_dir).await.map_err(|err| { - err.map_err_context(|| format!("Unable to create {state_dir}/vms/images")) - })?; - Ok(()) + let vm_dir = format!("{state_dir}/vms/images"); + fs::create_dir_all(vm_dir).await.map_err(|err| { + err.map_err_context(|| format!("Unable to create {state_dir}/vms/images")) + })?; + Ok(()) } async fn ensure_state_dir_database(state_dir: &str) -> IoResult<()> { - let vm_dir = format!("{state_dir}/database"); - fs::create_dir_all(vm_dir).await.map_err(|err| { - err.map_err_context(|| format!("Unable to create {state_dir}/database")) - })?; - Ok(()) + let vm_dir = format!("{state_dir}/database"); + fs::create_dir_all(vm_dir).await.map_err(|err| { + err.map_err_context(|| format!("Unable to create {state_dir}/database")) + })?; + Ok(()) } async fn ensure_state_dir_etc() -> IoResult<()> { - // let vm_dir = format!("{state_dir}/database"); - fs::create_dir_all("/etc/nanocl").await.map_err(|err| { - err.map_err_context(|| format!("Unable to create /etc/nanocl")) - })?; - Ok(()) + // let vm_dir = format!("{state_dir}/database"); + fs::create_dir_all("/etc/nanocl").await.map_err(|err| { + err.map_err_context(|| format!("Unable to create /etc/nanocl")) + })?; + Ok(()) } async fn ensure_nanocl_sock_dir() -> IoResult<()> { - // let vm_dir = format!("{}/vms/images"); - fs::create_dir_all("/run/nanocl").await.map_err(|err| { - err.map_err_context(|| format!("Unable to create /run/nanocl")) - })?; - Ok(()) + // let vm_dir = format!("{}/vms/images"); + fs::create_dir_all("/run/nanocl").await.map_err(|err| { + err.map_err_context(|| format!("Unable to create /run/nanocl")) + })?; + Ok(()) } /// Init function called before http server start. @@ -144,7 +141,7 @@ async fn ensure_nanocl_sock_dir() -> IoResult<()> { pub async fn init(conf: &DaemonConfig) -> IoResult { // spawn_crond(); let mut count = 0; - while count < conf.hosts.len(){ + while count < conf.hosts.len() { if conf.hosts[count].starts_with("unix://") { set_uds_perm(); } @@ -154,7 +151,7 @@ pub async fn init(conf: &DaemonConfig) -> IoResult { ensure_state_dir(&conf.state_dir).await?; ensure_state_dir_database(&conf.state_dir).await?; let mut count = 0; - while count < conf.hosts.len(){ + while count < conf.hosts.len() { if conf.hosts[count].starts_with("unix://") { ensure_nanocl_sock_dir().await?; } @@ -162,86 +159,89 @@ pub async fn init(conf: &DaemonConfig) -> IoResult { } ensure_state_dir_etc().await?; - let system_state = SystemState::new(conf).await?; - let system_ptr = system_state.clone(); - NodeDb::register(&system_ptr).await?; - utils::system::register_namespace("global", &system_ptr).await?; - utils::system::register_namespace("system", &system_ptr).await?; - // todo 是否需要分析containerd event - // rt::spawn(async move { - // let fut = async move { - // utils::system::sync_processes(&system_ptr).await?; - // utils::system::sync_vm_images(&system_ptr).await?; - // Ok::<_, IoError>(()) - // }; - // if let Err(err) = fut.await { - // log::warn!("boot::init: {err}"); - // } - // Ok::<_, IoError>(()) - // }); - // super::docker_event::analyze(&system_state); - // super::metric::spawn(&system_state); - Ok(system_state) + let system_state = SystemState::new(conf).await?; + let system_state_cl = system_state.clone(); + let system_ptr = system_state.clone(); + NodeDb::register(&system_ptr).await?; + utils::system::register_namespace("global", &system_ptr).await?; + utils::system::register_namespace("system", &system_ptr).await?; + // todo 是否需要分析containerd event + // rt::spawn(async move { + // let fut = async move { + // utils::system::sync_processes(&system_ptr).await?; + // utils::system::sync_vm_images(&system_ptr).await?; + // Ok::<_, IoError>(()) + // }; + // if let Err(err) = fut.await { + // log::warn!("boot::init: {err}"); + // } + // Ok::<_, IoError>(()) + // }); + eventbus::eventbus::analyze(system_state_cl); + apiserver::apiserver::start_apiserver(); + // super::metric::spawn(&system_state); + + Ok(system_state) } /// Init unit test #[cfg(test)] mod tests { - use futures_util::StreamExt; - - use nanocl_stubs::resource::Resource; - - use super::*; - - use crate::{cli, config, utils::tests::*}; - - /// Test init - #[ntex::test] - async fn basic_init() { - // Init cli args - before(); - let home = std::env::var("HOME").expect("Failed to get home dir"); - let args = cli::Cli { - gid: 0, - state_dir: Some(format!("{home}/.nanocl_dev/state")), - store_addr: Some( - "postgresql://root:root@store.nanocl.internal:26258/defaultdb" - .to_owned(), - ), - hostname: Some("init-test.nanocl.io".to_owned()), - gateway: Some("127.0.0.1".to_owned()), - conf_dir: String::from("/etc/nanocl"), - nodes: Vec::default(), - ..Default::default() - }; - log::debug!("args: {args:?}"); - let config = config::init(&args).expect("Expect to init config"); - log::debug!("config: {config:?}"); - // Test state - let state = init(&config).await.unwrap(); - let state_ptr = state.clone(); - let mut raw_sub = state.subscribe_raw(None).await.unwrap(); - rt::spawn(async move { - ntex::time::sleep(std::time::Duration::from_secs(1)).await; - let actor = Resource::default(); - state_ptr - .emit_normal_native_action_sync( - &actor, - nanocl_stubs::system::NativeEventAction::Create, - ) - .await; - }); - raw_sub.next().await; - let state_ptr = state.clone(); - rt::spawn(async move { - ntex::time::sleep(std::time::Duration::from_secs(1)).await; - let actor = Resource::default(); - state_ptr - .emit_normal_native_action_sync( - &actor, - nanocl_stubs::system::NativeEventAction::Create, - ) - .await; - }); - } + use futures_util::StreamExt; + + use nanocl_stubs::resource::Resource; + + use super::*; + + use crate::{cli, config, utils::tests::*}; + + /// Test init + #[ntex::test] + async fn basic_init() { + // Init cli args + before(); + let home = std::env::var("HOME").expect("Failed to get home dir"); + let args = cli::Cli { + gid: 0, + state_dir: Some(format!("{home}/.nanocl_dev/state")), + store_addr: Some( + "postgresql://root:root@store.nanocl.internal:26258/defaultdb" + .to_owned(), + ), + hostname: Some("init-test.nanocl.io".to_owned()), + gateway: Some("127.0.0.1".to_owned()), + conf_dir: String::from("/etc/nanocl"), + nodes: Vec::default(), + ..Default::default() + }; + log::debug!("args: {args:?}"); + let config = config::init(&args).expect("Expect to init config"); + log::debug!("config: {config:?}"); + // Test state + let state = init(&config).await.unwrap(); + let state_ptr = state.clone(); + let mut raw_sub = state.subscribe_raw(None).await.unwrap(); + rt::spawn(async move { + ntex::time::sleep(std::time::Duration::from_secs(1)).await; + let actor = Resource::default(); + state_ptr + .emit_normal_native_action_sync( + &actor, + nanocl_stubs::system::NativeEventAction::Create, + ) + .await; + }); + raw_sub.next().await; + let state_ptr = state.clone(); + rt::spawn(async move { + ntex::time::sleep(std::time::Duration::from_secs(1)).await; + let actor = Resource::default(); + state_ptr + .emit_normal_native_action_sync( + &actor, + nanocl_stubs::system::NativeEventAction::Create, + ) + .await; + }); + } } diff --git a/bin/nanocld/src/system/system_state.rs b/bin/nanocld/src/system/system_state.rs index 8a3dcd2ba6631bcb7bf8ee32e0614c57424aecf5..935a0e51ad9000fa6937afee4252e845fd2e5140 100644 --- a/bin/nanocld/src/system/system_state.rs +++ b/bin/nanocld/src/system/system_state.rs @@ -15,11 +15,16 @@ use nanocl_stubs::{ }, }; -use crate::{k8scri, models::{ - EventDb, RawEventEmitter, RawEventReceiver, SystemState, SystemStateInner, - TaskManager, -}, repositories::generic::*, utils, vars}; use crate::k8scri::errors; +use crate::{ + k8scri, + models::{ + EventDb, RawEventEmitter, RawEventReceiver, SystemState, SystemStateInner, + TaskManager, + }, + repositories::generic::*, + utils, vars, +}; impl SystemState { /// Create a new instance of the system state @@ -33,10 +38,17 @@ impl SystemState { ) .map_err(|err| err.map_err_context(|| "Docker"))?; - let cri_cli = k8scri::cri::CriClient::connect_with_unix( - "/run/containerd/containerd.sock", - 10000, - ).await.map_err(|err| IoError::without_context(errors::box_to_io_error(err)))?; + log::info!( + "--------------->>get runtime endpoint{}", + &conf.runtime_endpoint + ); + + let cri_cli = + k8scri::cri::CriClient::connect_with_unix(&conf.runtime_endpoint, 10000) + .await + .map_err(|err| { + IoError::without_context(errors::box_to_io_error(err)) + })?; let pool = utils::store::init(conf).await?; let (sx, rx) = mpsc::unbounded(); diff --git a/bin/nanocld/src/tasks/cargo.rs b/bin/nanocld/src/tasks/cargo.rs index 35fb4e109b3282b9467bc2060d73b6141ad2acef..c5bf0b3cc59ec84b6fcd7de2c237dcf25d5b7344 100644 --- a/bin/nanocld/src/tasks/cargo.rs +++ b/bin/nanocld/src/tasks/cargo.rs @@ -42,6 +42,7 @@ impl ObjTaskStart for CargoDb { Some(ReplicationMode::Static(replication)) => replication.number, _ => 1, }; + // println!("{:#?}",cargo.clone()); utils::container::cargo::create(&cargo, number, &state).await?; } utils::container::start_instances( diff --git a/bin/nanocld/src/utils/container/process.rs b/bin/nanocld/src/utils/container/process.rs index b7c54d22af2df5f94adeaa20ca3504883f1dee0a..9021cb923fb8be04e43b49727bbd9694d7d2be3f 100644 --- a/bin/nanocld/src/utils/container/process.rs +++ b/bin/nanocld/src/utils/container/process.rs @@ -1,124 +1,129 @@ -use bollard_next::container::{Config}; -use bollard_next::models::{ NetworkSettings}; +use bollard_next::container::Config; +use bollard_next::models::NetworkSettings; use chrono::TimeZone; -use cri_api::v1::{ContainerConfig, ContainerStatusRequest, PodSandboxStatusRequest, StartContainerRequest}; +use cri_api::v1::{ + ContainerConfig, ContainerStatusRequest, PodSandboxStatusRequest, + StartContainerRequest, +}; use nanocl_error::{ - http::{HttpError, HttpResult}, - io::FromIo, + http::{HttpError, HttpResult}, + io::FromIo, }; use nanocl_stubs::cri_spec::CriConfig; use nanocl_stubs::process::{Process, ProcessKind, ProcessPartial}; use crate::{ - models::{ProcessDb, SystemState}, - repositories::generic::*, + models::{ProcessDb, SystemState}, + repositories::generic::*, }; /// Create a process (container) based on the kind and the item pub async fn create( - kind: &ProcessKind, - name: &str, - kind_key: &str, - item: &CriConfig, - state: &SystemState, + kind: &ProcessKind, + name: &str, + kind_key: &str, + item: &CriConfig, + state: &SystemState, ) -> HttpResult { - println!("---------------{}", "create pod".to_string()); - let mut config = item.clone(); - let mut container_config = config.container_config; - - let mut labels = container_config.labels.to_owned(); - labels.insert("io.nanocl".to_owned(), "enabled".to_owned()); - labels.insert("io.nanocl.kind".to_owned(), kind.to_string()); - container_config.labels = labels; - - //第一步:创建cri配置请求 - let (run_pod_req, create_container_req) = state. - inner. - cri_api. - clone(). - create_pod_and_container_req(name.to_string(), item.clone()) - .await; - - - // 第二步:创建container - let create_con_rep = state. - inner. - cri_api. - clone(). - create_container_with_sandbox_conf(Some(create_container_req), Some(run_pod_req)). - await.map_err(|e| HttpError::internal_server_error(e.to_string()))?; - - - // 第三步:start contaienr - state. - inner. - cri_api. - clone(). - start_container(Some(StartContainerRequest { - container_id: create_con_rep.create_container_rep.container_id.clone() - })) - .await - .map_err(|e| { - HttpError::internal_server_error(e.to_string()) - })?; - - - - // 第三步:inspect sandbox - let sandbox_inspect = state.inner.cri_api.clone(). - inspect_sandbox_container(Some(PodSandboxStatusRequest { - pod_sandbox_id: create_con_rep.create_sanbox_rep.pod_sandbox_id.clone(), - verbose: true, - })) - .await - .map_err(|e| HttpError::internal_server_error(e.to_string()))?; - - - - // 第四步:inspect container - let contaienr_inspect = state.inner.cri_api.clone(). - inspect_container(Some(ContainerStatusRequest { - container_id: create_con_rep.create_container_rep.container_id.clone(), - verbose: true, - })) - .await - .map_err(|e| HttpError::internal_server_error(e.to_string()))?; - - - - let created_at = if let Some(status) = contaienr_inspect.clone().status { - let created_at_str = status.created_at.to_string(); - log::info!("--------get create at {}--------",created_at_str.clone()); - let timestamp: u64 = created_at_str.parse().map_err(|err| { - HttpError::internal_server_error(format!("Unable to parse date {err}")) - })?; - let datetime = chrono::NaiveDateTime::from_timestamp((timestamp / 1_000_000_000) as i64, (timestamp % 1_000_000_000) as u32); - let local_datetime = chrono::Local.from_local_datetime(&datetime); - match local_datetime { - chrono::LocalResult::Single(dt) => dt.format("%Y-%m-%d %H:%M:%S").to_string(), - _ => chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string(), - } - } else { - chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string() - }; - - - - let new_instance = ProcessPartial { - key: create_con_rep.create_container_rep.container_id.clone(), - name: name.to_owned(), - kind: kind.clone(), - data: serde_json::to_string(&contaienr_inspect) - .map_err(|err| err.map_err_context(|| "CreateProcess"))?, - node_name: state.inner.config.hostname.clone(), - kind_key: kind_key.to_owned(), - created_at: Some(created_at.clone()), - cri_req: serde_json::to_string(&create_con_rep.create_container_req) - .map_err(|err| err.map_err_context(|| "CreateProcess"))?, - sand_box_data: serde_json::to_string(&sandbox_inspect) - .map_err(|err| err.map_err_context(|| "CreateProcess"))?, - }; - let insert = ProcessDb::from(&new_instance); - let process = ProcessDb::create_from(insert, &state.inner.pool).await?; - Process::try_from(process).map_err(HttpError::from) + let mut config = item.clone(); + let mut container_config = config.container_config; + + let mut labels = container_config.labels.to_owned(); + labels.insert("io.nanocl".to_owned(), "enabled".to_owned()); + labels.insert("io.nanocl.kind".to_owned(), kind.to_string()); + container_config.labels = labels; + + //第一步:创建cri配置请求 + let (run_pod_req, create_container_req) = state + .inner + .cri_api + .clone() + .create_pod_and_container_req(name.to_string(), item.clone()) + .await; + + // 第二步:创建container + let create_con_rep = state + .inner + .cri_api + .clone() + .create_container_with_sandbox_conf( + Some(create_container_req), + Some(run_pod_req), + ) + .await + .map_err(|e| HttpError::internal_server_error(e.to_string()))?; + + // 第三步:start contaienr + state + .inner + .cri_api + .clone() + .start_container(Some(StartContainerRequest { + container_id: create_con_rep.create_container_rep.container_id.clone(), + })) + .await + .map_err(|e| HttpError::internal_server_error(e.to_string()))?; + + // 第三步:inspect sandbox + let sandbox_inspect = state + .inner + .cri_api + .clone() + .inspect_sandbox_container(Some(PodSandboxStatusRequest { + pod_sandbox_id: create_con_rep.create_sanbox_rep.pod_sandbox_id.clone(), + verbose: true, + })) + .await + .map_err(|e| HttpError::internal_server_error(e.to_string()))?; + + // 第四步:inspect container + let contaienr_inspect = state + .inner + .cri_api + .clone() + .inspect_container(Some(ContainerStatusRequest { + container_id: create_con_rep.create_container_rep.container_id.clone(), + verbose: true, + })) + .await + .map_err(|e| HttpError::internal_server_error(e.to_string()))?; + + let created_at = if let Some(status) = contaienr_inspect.clone().status { + let created_at_str = status.created_at.to_string(); + log::info!("--------get create at {}--------", created_at_str.clone()); + let timestamp: u64 = created_at_str.parse().map_err(|err| { + HttpError::internal_server_error(format!("Unable to parse date {err}")) + })?; + let datetime = chrono::NaiveDateTime::from_timestamp( + (timestamp / 1_000_000_000) as i64, + (timestamp % 1_000_000_000) as u32, + ); + let local_datetime = chrono::Local.from_local_datetime(&datetime); + match local_datetime { + chrono::LocalResult::Single(dt) => { + dt.format("%Y-%m-%d %H:%M:%S").to_string() + } + _ => chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string(), + } + } else { + chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string() + }; + + let new_instance = ProcessPartial { + key: create_con_rep.create_container_rep.container_id.clone(), + name: name.to_owned(), + kind: kind.clone(), + data: serde_json::to_string(&contaienr_inspect) + .map_err(|err| err.map_err_context(|| "CreateProcess"))?, + node_name: state.inner.config.hostname.clone(), + kind_key: kind_key.to_owned(), + created_at: Some(created_at.clone()), + cri_req: serde_json::to_string(&create_con_rep.create_container_req) + .map_err(|err| err.map_err_context(|| "CreateProcess"))?, + sand_box_data: serde_json::to_string(&sandbox_inspect) + .map_err(|err| err.map_err_context(|| "CreateProcess"))?, + }; + let insert = ProcessDb::from(&new_instance); + let process = ProcessDb::create_from(insert, &state.inner.pool).await?; + Process::try_from(process).map_err(HttpError::from) } diff --git a/crates/nanocl_stubs/src/config.rs b/crates/nanocl_stubs/src/config.rs index 58e5b11f060736a9bb1ea3ad0b615f4c5613522a..452b6813754e721c348c26e01fc0785ca8f88ce1 100644 --- a/crates/nanocl_stubs/src/config.rs +++ b/crates/nanocl_stubs/src/config.rs @@ -17,6 +17,8 @@ pub struct DaemonConfig { /// Docker host to use #[cfg_attr(feature = "serde", serde(default = "default_host"))] pub docker_host: String, + #[cfg_attr(feature = "serde", serde(default = "default_runtime_endpoint"))] + pub runtime_endpoint: String, /// Store address to connect to pub store_addr: Option, /// Host gateway automatically detected to host default gateway if not set @@ -46,6 +48,8 @@ pub struct DaemonConfigFile { pub state_dir: Option, /// Docker host to use pub docker_host: Option, + /// Runtime endpoing to use + pub runtime_endpoint: Option, /// Store address to connect to pub store_addr: Option, /// Host gateway automatically detected to host default gateway if not set @@ -58,6 +62,7 @@ impl Default for DaemonConfig { fn default() -> Self { Self { docker_host: default_host(), + runtime_endpoint: default_runtime_endpoint(), conf_dir: "/etc/nanocl".into(), store_addr: None, gid: 0, @@ -75,3 +80,7 @@ impl Default for DaemonConfig { fn default_host() -> String { "/var/run/docker.sock".to_owned() } + +fn default_runtime_endpoint() -> String { + "/run/containerd/containerd.sock".to_owned() +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f92c249df98eedb00e0bbf948fc370cd65998e34..29171b0d779c7d41038c1db5c1b0ce2ea82633c4 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] profile = "default" -channel = "1.78.0" +channel = "stable"