From a34c2a589bfd72311c84b5803890b5158bbabf30 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 17 Dec 2024 14:58:38 +0100 Subject: [PATCH 01/25] feat: Add interu tool --- .gitignore | 1 + Cargo.lock | 978 ++++++++++++++++++++++++ Cargo.toml | 16 + run-integration-test/README.md | 6 + run-integration-test/config.example.yml | 65 ++ tools/interu/Cargo.toml | 20 + tools/interu/src/cli.rs | 39 + tools/interu/src/config/mod.rs | 179 +++++ tools/interu/src/config/profile.rs | 153 ++++ tools/interu/src/config/runner.rs | 174 +++++ tools/interu/src/instances.rs | 57 ++ tools/interu/src/main.rs | 51 ++ 12 files changed, 1739 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 run-integration-test/config.example.yml create mode 100644 tools/interu/Cargo.toml create mode 100644 tools/interu/src/cli.rs create mode 100644 tools/interu/src/config/mod.rs create mode 100644 tools/interu/src/config/profile.rs create mode 100644 tools/interu/src/config/runner.rs create mode 100644 tools/interu/src/instances.rs create mode 100644 tools/interu/src/main.rs diff --git a/.gitignore b/.gitignore index bee8a64..691f494 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..3586f8c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,978 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "argh" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7af5ba06967ff7214ce4c7419c7d185be7ecd6cc4965a8f6e1d8ce0398aad219" +dependencies = [ + "argh_derive", + "argh_shared", +] + +[[package]] +name = "argh_derive" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56df0aeedf6b7a2fc67d06db35b09684c3e8da0c95f8f27685cb17e08413d87a" +dependencies = [ + "argh_shared", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "argh_shared" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5693f39141bda5760ecc4111ab08da40565d1771038c4a0250f03457ec707531" +dependencies = [ + "serde", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +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 = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +dependencies = [ + "equivalent", + "hashbrown 0.15.2", + "serde", +] + +[[package]] +name = "interu" +version = "0.1.0" +dependencies = [ + "argh", + "rand", + "rstest", + "serde", + "serde_with", + "serde_yaml", + "snafu", + "strum", +] + +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + +[[package]] +name = "js-sys" +version = "0.3.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.168" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "pin-project-lite" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "relative-path" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" + +[[package]] +name = "rstest" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a2c585be59b6b5dd66a9d2084aa1d8bd52fbdb806eafdeffb52791147862035" +dependencies = [ + "futures", + "futures-timer", + "rstest_macros", + "rustc_version", +] + +[[package]] +name = "rstest_macros" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "825ea780781b15345a146be27eaefb05085e337e869bff01b4306a4fd4a9ad5a" +dependencies = [ + "cfg-if", + "glob", + "proc-macro-crate", + "proc-macro2", + "quote", + "regex", + "relative-path", + "rustc_version", + "syn", + "unicode-ident", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "semver" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" + +[[package]] +name = "serde" +version = "1.0.216" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.216" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.7.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.7.0", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "snafu" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "223891c85e2a29c3fe8fb900c1fae5e69c2e42415e3177752e8718475efa5019" +dependencies = [ + "snafu-derive", +] + +[[package]] +name = "snafu-derive" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c3c6b7927ffe7ecaa769ee0e3994da3b8cafc8f444578982c83ecb161af917" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "time" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap 2.7.0", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..613c8ca --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[workspace] +members = ["tools/*"] +resolver = "2" + +[workspace.package] +edition = "2021" + +[workspace.dependencies] +argh = "0.1.12" +rand = "0.8.5" +rstest = "0.23.0" +serde = { version = "1.0.216", features = ["derive"] } +serde_with = "3.11.0" +serde_yaml = "0.9.34+deprecated" +snafu = "0.8.5" +strum = { version = "0.26.3", features = ["derive"] } diff --git a/run-integration-test/README.md b/run-integration-test/README.md index 744f991..43d37e0 100644 --- a/run-integration-test/README.md +++ b/run-integration-test/README.md @@ -23,6 +23,12 @@ There is no mapping for `oke` yet. Supported Kubernetes version can be inspected on the official Replicated documentation [page][supported-clusters]. Supported architectures are `amd64` and `arm64`. +## Integration Test Configuration File + +Each downstream repository needs a configuration file. This allows customization of various +parameters based on the needs of the operator / the particular tests. The config file needs to be +placed here: `tests/integration-tests.yml`. + ## Inputs and Outputs > [!TIP] diff --git a/run-integration-test/config.example.yml b/run-integration-test/config.example.yml new file mode 100644 index 0000000..c0464be --- /dev/null +++ b/run-integration-test/config.example.yml @@ -0,0 +1,65 @@ +runners: + # Runners can have more than one name. This is useful when the same runner is + # used for different tests + default-amd64: + platform: rke2-1.31.2 + ttl: 4h + node-groups: + - name: default + arch: amd64 + size: large + disk: 50 + nodes: 3 + + default-arm64: + platform: aks-1.31 + ttl: 4h + node-groups: + - name: default + arch: arm64 + size: large + disk: 50 + nodes: 3 + + default-mixed: + platform: aks-1.31 + ttl: 4h + node-groups: + - name: amd64-nodes + arch: amd64 + size: large + disk: 50 + nodes: 3 + - name: arm64-nodes + arch: arm64 + size: large + disk: 50 + nodes: 3 + +profiles: + schedule: + strategy: weighted + weights: + # 80%, 10% and 10% of the time + # Ideally we want: - 80: default-amd64 but that's hard to (de)serialize + # using serde + - weight: 80 + runner: default-amd64 + - weight: 10 + runner: default-arm64 + - weight: 10 + runner: default-mixed + options: + # Not explicitly setting 'test-run' and 'test-parameter' will run all + # tests + parallelism: 1 + + workflow_dispatch: + strategy: use-runner + runner: default-amd64 + options: + # Defaults to `--test-suite smoke` but can be overridden using + # workflow_dispatch inputs + test-run: test-suite + test-parameter: smoke + parallelism: 2 diff --git a/tools/interu/Cargo.toml b/tools/interu/Cargo.toml new file mode 100644 index 0000000..11b5e8e --- /dev/null +++ b/tools/interu/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "interu" +version = "0.1.0" +edition.workspace = true + +[profile.release] +codegen-units = 1 +opt-level = "z" +panic = "abort" +lto = true + +[dependencies] +argh.workspace = true +rand.workspace = true +rstest.workspace = true +serde.workspace = true +serde_with.workspace = true +serde_yaml.workspace = true +snafu.workspace = true +strum.workspace = true diff --git a/tools/interu/src/cli.rs b/tools/interu/src/cli.rs new file mode 100644 index 0000000..4b8f4e2 --- /dev/null +++ b/tools/interu/src/cli.rs @@ -0,0 +1,39 @@ +use std::path::PathBuf; + +use argh::FromArgs; + +#[derive(Debug, FromArgs)] +/// Expand configuration into key-value pairs used by the run-integration-test action +pub struct Cli { + /// path to integration test config file + #[argh( + option, + short = 'c', + long = "config", + default = "PathBuf::from(\"tests/interu.yaml\")" + )] + pub config: PathBuf, + + /// path to instances file + #[argh(option, short = 'i', long = "instances")] + pub instances: PathBuf, + + /// output key=value pairs separated by newlines to file + #[argh( + option, + short = 'o', + long = "output", + description = "output key=value pairs separated by newlines to file. + Useful for CI tools which give a file to write env vars and outputs to which are used in subsequent steps" + )] + pub output: Option, + + /// run without producing output on stdout + // #[arg(short, long, visible_short_alias('s'), visible_alias("silent"))] + #[argh(switch, short = 'q', long = "quiet")] + pub quiet: bool, + + /// which test profile to use + #[argh(positional)] + pub profile: String, +} diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs new file mode 100644 index 0000000..45686dc --- /dev/null +++ b/tools/interu/src/config/mod.rs @@ -0,0 +1,179 @@ +use std::{collections::BTreeMap, fmt::Display, path::Path}; + +use rand::{distributions::WeightedIndex, prelude::Distribution as _, thread_rng}; +use serde::{Deserialize, Serialize}; +use snafu::{OptionExt, ResultExt, Snafu}; + +use crate::{ + config::{ + profile::{Profile, StrategyValidationError, TestRun}, + runner::{ConvertNodeGroupError, Distribution, ReplicatedNodeGroup, Runner}, + }, + instances::Instances, +}; + +pub mod profile; +pub mod runner; + +#[derive(Debug, Snafu)] +pub enum Error { + #[snafu(display("failed to read file"))] + ReadFile { source: std::io::Error }, + + #[snafu(display("failed to deserialize file"))] + Deserialize { source: serde_yaml::Error }, + + #[snafu(display("failed to validate file"))] + Validate { source: ValidationError }, + + #[snafu(display("failed to find profile named {profile_name:?}"))] + UnknownProfileName { profile_name: String }, + + #[snafu(display("failed to convert node-group to Replicated format"))] + ConvertNodeGroup { source: ConvertNodeGroupError }, +} + +#[derive(Debug, Snafu)] +pub enum ValidationError { + #[snafu(display("invalid profile config"))] + InvalidProfileConfig { source: StrategyValidationError }, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct Config { + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub runners: BTreeMap, + + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub profiles: BTreeMap, +} + +impl Config { + pub fn from_file

(path: P) -> Result + where + P: AsRef, + { + let contents = std::fs::read_to_string(path).context(ReadFileSnafu)?; + let config: Config = serde_yaml::from_str(&contents).context(DeserializeSnafu)?; + config.validate().context(ValidateSnafu)?; + + Ok(config) + } + + fn validate(&self) -> Result<(), ValidationError> { + for (profile_name, profile) in &self.profiles { + profile + .validate(profile_name, &self.runners) + .context(InvalidProfileConfigSnafu)?; + } + + Ok(()) + } + + pub fn determine_parameters( + &self, + profile_name: &String, + instances: Instances, + ) -> Result { + // First, lookup the profile by name. Error if the profile does't exist. + let profile = self + .profiles + .get(profile_name) + .context(UnknownProfileNameSnafu { profile_name })?; + + // Next, lookup the runner ref based on the profile strategy + let runner_ref = match &profile.strategy { + profile::Strategy::Weighted(options) => { + let weights: Vec<_> = options.weights.iter().map(|w| w.weight).collect(); + let random_distribution = WeightedIndex::new(weights).unwrap(); + let mut rng = thread_rng(); + + let index = random_distribution.sample(&mut rng); + let weight = options.weights.get(index).expect("always valid index"); + + &weight.runner + } + profile::Strategy::UseRunner(options) => &options.runner, + }; + + // Get the runner based on the runner ref + let runner = self.runners.get(runner_ref).unwrap(); + + // Get test options + let (test_parallelism, test_run, test_parameter) = profile.strategy.get_test_options(); + + // Convert our node groups to replicated node groups + let node_groups = runner + .node_groups + .clone() + .into_iter() + .map(|ng| ReplicatedNodeGroup::try_from(ng, &instances, &runner.platform.distribution)) + .collect::, ConvertNodeGroupError>>() + .context(ConvertNodeGroupSnafu)?; + + Ok(Parameters { + kubernetes_distribution: runner.platform.distribution.clone(), + kubernetes_version: runner.platform.version.clone(), + test_parameter: test_parameter.to_owned(), + test_run: test_run.clone(), + test_parallelism, + node_groups, + }) + } +} + +#[derive(Debug)] +pub struct Parameters { + kubernetes_distribution: Distribution, + kubernetes_version: String, + + node_groups: Vec, + + test_parallelism: usize, + test_parameter: String, + test_run: TestRun, +} + +impl Display for Parameters { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { + kubernetes_distribution, + kubernetes_version, + node_groups, + test_parallelism, + test_parameter, + test_run, + } = self; + + write!(f, "KUBERNETES_DISTRIBUTION={kubernetes_distribution}\n")?; + write!(f, "KUBERNETES_VERSION={kubernetes_version}\n")?; + + // See: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#multiline-strings + write!( + f, + "NODE_GROUPS<, + ) -> Result<(), StrategyValidationError> { + self.strategy.validate(profile_name, runners) + } +} + +#[derive(Debug, Snafu)] +pub enum StrategyValidationError { + #[snafu(display("runner {runner_ref:?} referenced in {at} is not defined"))] + InvalidRunnerReference { at: String, runner_ref: String }, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(tag = "strategy", rename_all = "kebab-case")] +pub enum Strategy { + Weighted(WeightedOptions), + UseRunner(UseRunnerOptions), +} + +impl Strategy { + pub fn validate( + &self, + profile_name: &str, + runners: &BTreeMap, + ) -> Result<(), StrategyValidationError> { + match &self { + Strategy::Weighted(weighted_options) => { + weighted_options.validate(profile_name, runners) + } + Strategy::UseRunner(use_runner_options) => { + use_runner_options.validate(profile_name, runners) + } + } + } + + pub fn get_test_options(&self) -> (usize, &TestRun, &str) { + match self { + Strategy::Weighted(options) => ( + options.options.parallelism, + &options.options.test_run, + options.options.test_parameter.as_str(), + ), + Strategy::UseRunner(options) => ( + options.options.parallelism, + &options.options.test_run, + options.options.test_parameter.as_str(), + ), + } + } +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct WeightedOptions { + pub weights: Vec, + pub options: TestOptions, +} + +impl WeightedOptions { + pub fn validate( + &self, + profile_name: &str, + runners: &BTreeMap, + ) -> Result<(), StrategyValidationError> { + for weight in &self.weights { + if !runners.contains_key(&weight.runner) { + return InvalidRunnerReferenceSnafu { + at: format!( + "profile.{profile_name}.weights.{weight}", + weight = weight.weight + ), + runner_ref: weight.runner.clone(), + } + .fail(); + } + } + + Ok(()) + } +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct Weight { + pub weight: usize, + pub runner: String, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct UseRunnerOptions { + pub runner: String, + pub options: TestOptions, +} + +impl UseRunnerOptions { + pub fn validate( + &self, + profile_name: &str, + runners: &BTreeMap, + ) -> Result<(), StrategyValidationError> { + if !runners.contains_key(&self.runner) { + return InvalidRunnerReferenceSnafu { + at: format!("profile.{profile_name}.runner"), + runner_ref: self.runner.clone(), + } + .fail(); + } + + Ok(()) + } +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct TestOptions { + pub parallelism: usize, + + #[serde(default, with = "serde_yaml::with::singleton_map")] + pub test_run: TestRun, + + #[serde(default)] + pub test_parameter: String, +} + +#[derive(Clone, Debug, Default, Deserialize, Serialize, strum::Display)] +#[strum(serialize_all = "kebab-case")] +#[serde(rename_all = "kebab-case")] +pub enum TestRun { + TestSuite, + Test, + + #[default] + All, +} diff --git a/tools/interu/src/config/runner.rs b/tools/interu/src/config/runner.rs new file mode 100644 index 0000000..e5ce360 --- /dev/null +++ b/tools/interu/src/config/runner.rs @@ -0,0 +1,174 @@ +use std::{fmt::Display, str::FromStr}; + +use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, DisplayFromStr}; +use snafu::{OptionExt, ResultExt as _, Snafu}; + +use crate::instances::Instances; + +#[serde_as] +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct Runner { + #[serde_as(as = "DisplayFromStr")] + pub platform: PlatformPair, + + // TODO (@Techassi): Allow some kind of inheritance here + // /// The size of cluster nodes. Can be `small`, `medium`, or `large`. + // pub size: Size, + + // /// The size of the disk in GB per cluster node. + // pub disk: usize, + /// The time-to-live of the cluster. + pub ttl: String, + + /// Optionally define node groups. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub node_groups: Vec, +} + +#[derive(Debug, Snafu)] +pub enum ParsePlatformTripleError { + #[snafu(display("invalid format, expected pair separated by dashes"))] + InvalidFormat, + + #[snafu(display("failed to parse distribution"))] + ParseDistribution { source: strum::ParseError }, +} + +#[derive(Debug)] +pub struct PlatformPair { + pub distribution: Distribution, + // Ideally we want to use SemVer here, but cloud vendors make stupid + // decisions and just use major.minor. + pub version: String, +} + +impl FromStr for PlatformPair { + type Err = ParsePlatformTripleError; + + fn from_str(s: &str) -> Result { + let parts: Vec<&str> = s.split('-').collect(); + + match parts[..] { + [distribution, version] => { + let distribution = + Distribution::from_str(distribution).context(ParseDistributionSnafu)?; + + Ok(PlatformPair { + version: version.to_owned(), + distribution, + }) + } + _ => InvalidFormatSnafu.fail(), + } + } +} + +impl Display for PlatformPair { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{distribution}-{version}", + distribution = self.distribution, + version = self.version, + ) + } +} + +#[derive( + Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize, strum::Display, strum::EnumString, +)] +#[strum(serialize_all = "lowercase")] +#[serde(rename_all = "lowercase")] +pub enum Distribution { + Eks, + Gke, + Aks, + Kind, + K3s, + Rke2, +} + +#[derive( + Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize, strum::Display, strum::EnumString, +)] +#[strum(serialize_all = "kebab-case")] +#[serde(rename_all = "kebab-case")] +pub enum Architecture { + Amd64, + Arm64, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub enum Size { + Small, + Medium, + Large, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct NodeGroup { + name: String, + + #[serde(rename = "arch")] + architecture: Architecture, + + nodes: usize, + size: Size, + disk: usize, +} + +#[derive(Debug, Snafu)] +pub enum ConvertNodeGroupError { + #[snafu(display("unknown distribution {distribution}"))] + UnknownDistribution { distribution: Distribution }, + + #[snafu(display("unknown architecture {architecture}"))] + UnknownArchitecture { architecture: Architecture }, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct ReplicatedNodeGroup { + instance_type: String, + name: String, + nodes: usize, + disk: usize, +} + +impl ReplicatedNodeGroup { + pub fn try_from( + node_group: NodeGroup, + instances: &Instances, + distribution: &Distribution, + ) -> Result { + let architectures = + instances + .get(distribution) + .with_context(|| UnknownDistributionSnafu { + distribution: distribution.clone(), + })?; + + let sizes = architectures + .get(&node_group.architecture) + .with_context(|| UnknownArchitectureSnafu { + architecture: node_group.architecture.clone(), + })?; + + let instance_type = match node_group.size { + Size::Small => sizes.small.clone(), + Size::Medium => sizes.medium.clone(), + Size::Large => sizes.large.clone(), + }; + + Ok(Self { + instance_type, + name: node_group.name, + nodes: node_group.nodes, + disk: node_group.disk, + }) + } +} diff --git a/tools/interu/src/instances.rs b/tools/interu/src/instances.rs new file mode 100644 index 0000000..5dba124 --- /dev/null +++ b/tools/interu/src/instances.rs @@ -0,0 +1,57 @@ +use std::{collections::HashMap, ops::Deref, path::Path}; + +use serde::Deserialize; +use snafu::{ResultExt as _, Snafu}; + +use crate::config::runner::{Architecture, Distribution}; + +#[derive(Debug, Snafu)] +pub enum Error { + #[snafu(display("failed to read file"))] + ReadFile { source: std::io::Error }, + + #[snafu(display("failed to deserialize file"))] + Deserialize { source: serde_yaml::Error }, +} + +#[derive(Debug, Deserialize)] +pub struct Instances(HashMap); + +impl Deref for Instances { + type Target = HashMap; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +#[derive(Debug, Deserialize)] +pub struct Architectures(HashMap); + +impl Deref for Architectures { + type Target = HashMap; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl Instances { + pub fn from_file

(path: P) -> Result + where + P: AsRef, + { + let contents = std::fs::read_to_string(path).context(ReadFileSnafu)?; + let config: Instances = serde_yaml::from_str(&contents).context(DeserializeSnafu)?; + + Ok(config) + } +} + +// NOTE (@Techassi): Can we somehow re-use the size enum here? +#[derive(Debug, Deserialize)] +pub struct Sizes { + pub small: String, + pub medium: String, + pub large: String, +} diff --git a/tools/interu/src/main.rs b/tools/interu/src/main.rs new file mode 100644 index 0000000..83aafa7 --- /dev/null +++ b/tools/interu/src/main.rs @@ -0,0 +1,51 @@ +use std::{fs::OpenOptions, io::Write as _}; + +use snafu::{report, ResultExt, Snafu}; + +use crate::{cli::Cli, config::Config, instances::Instances}; + +mod cli; +mod config; +mod instances; + +#[derive(Debug, Snafu)] +enum Error { + #[snafu(display("failed to read config"))] + ReadConfig { source: config::Error }, + + #[snafu(display("failed to read instances file"))] + ReadInstances { source: instances::Error }, + + #[snafu(display("failed to write to output file"))] + WriteOutputFile { source: std::io::Error }, +} + +#[report] +fn main() -> Result<(), Error> { + let cli: Cli = argh::from_env(); + + let config = Config::from_file(&cli.config).context(ReadConfigSnafu)?; + let instances = Instances::from_file(&cli.instances).context(ReadInstancesSnafu)?; + + let parameters = config + .determine_parameters(&cli.profile, instances) + .unwrap(); + + let parameters = parameters.to_string(); + + if let Some(output_path) = cli.output { + let mut file = OpenOptions::new() + .append(true) + .open(output_path) + .context(WriteOutputFileSnafu)?; + + file.write(parameters.as_bytes()) + .context(WriteOutputFileSnafu)?; + } + + if !cli.quiet { + print!("{parameters}"); + } + + Ok(()) +} From b85d124b27567868f281cd161a6aad48e24e396a Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 17 Dec 2024 16:17:42 +0100 Subject: [PATCH 02/25] chore: Reduce binary size --- Cargo.toml | 7 +++++++ rust-toolchain.toml | 1 + tools/interu/Cargo.toml | 6 ------ 3 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/Cargo.toml b/Cargo.toml index 613c8ca..56372c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,10 @@ serde_with = "3.11.0" serde_yaml = "0.9.34+deprecated" snafu = "0.8.5" strum = { version = "0.26.3", features = ["derive"] } + +[profile.release] +opt-level = "z" # Optimize for size. +lto = true # Enable Link Time Optimization +codegen-units = 1 # Reduce number of codegen units to increase optimizations. +panic = "abort" # Abort on panic +strip = true # Automatically strip symbols from the binary. diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..2ceee0d --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1 @@ +toolchain.channel = "1.83.0" diff --git a/tools/interu/Cargo.toml b/tools/interu/Cargo.toml index 11b5e8e..49c128d 100644 --- a/tools/interu/Cargo.toml +++ b/tools/interu/Cargo.toml @@ -3,12 +3,6 @@ name = "interu" version = "0.1.0" edition.workspace = true -[profile.release] -codegen-units = 1 -opt-level = "z" -panic = "abort" -lto = true - [dependencies] argh.workspace = true rand.workspace = true From 21465df3102bc23a3755d95ef769b7ada9229955 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 17 Dec 2024 16:18:23 +0100 Subject: [PATCH 03/25] ci: Add interu workflows --- .github/workflows/interu_build.yml | 35 ++++++++++++++++++++++++++++ .github/workflows/interu_release.yml | 28 ++++++++++++++++++++++ .github/workflows/pr_interu.yml | 28 ++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 .github/workflows/interu_build.yml create mode 100644 .github/workflows/interu_release.yml create mode 100644 .github/workflows/pr_interu.yml diff --git a/.github/workflows/interu_build.yml b/.github/workflows/interu_build.yml new file mode 100644 index 0000000..71bd963 --- /dev/null +++ b/.github/workflows/interu_build.yml @@ -0,0 +1,35 @@ +name: Build interu + +on: + workflow_call: + inputs: + os: + required: true + type: string + target: + required: true + type: string + +env: + RUST_VERSION: 1.83.0 + +jobs: + build: + name: Release interu-${{ inputs.target }} + runs-on: ${{ inputs.os }} + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + + - uses: dtolnay/rust-toolchain@0e66bd3e6b38ec0ad5312288c83e47c143e6b09e # v1 + with: + toolchain: ${{ env.RUST_VERSION }} + targets: ${{ inputs.target }} + + - name: Build Binary + run: cargo build --target ${{ inputs.target }} --release --package interu + + - name: Rename Binary + run: mv target/${{ inputs.target }}/release/interu interu-${{ inputs.target }} diff --git a/.github/workflows/interu_release.yml b/.github/workflows/interu_release.yml new file mode 100644 index 0000000..78115e6 --- /dev/null +++ b/.github/workflows/interu_release.yml @@ -0,0 +1,28 @@ +name: Release interu + +on: + push: + tags: + - "interu-[0-9]+.[0-9]+.[0-9]+**" + +jobs: + release: + name: Release interu-${{ matrix.target }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + steps: + - name: Build interu + uses: ./.github/workflows/interu_build.yml + with: + target: ${{ matrix.target }} + os: ${{ matrix.os }} + + - name: Upload Release Binary + uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # v2.0.5 + with: + files: interu-${{ matrix.target }} diff --git a/.github/workflows/pr_interu.yml b/.github/workflows/pr_interu.yml new file mode 100644 index 0000000..5160e8c --- /dev/null +++ b/.github/workflows/pr_interu.yml @@ -0,0 +1,28 @@ +name: Release interu + +on: + pull_request: + paths: + - .github/workflows/interu_build.yml + - .github/workflows/interu_build.yml + - .github/workflows/pr_interu.yml + - rust-toolchain.toml + - tools/interu/** + - Cargo.toml + +jobs: + release: + name: Release interu-${{ matrix.target }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + steps: + - name: Build interu + uses: ./.github/workflows/interu_build.yml + with: + target: ${{ matrix.target }} + os: ${{ matrix.os }} From d1954d5c4b24427c72a1d32518ba46fa4bccbe9a Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 17 Dec 2024 16:20:18 +0100 Subject: [PATCH 04/25] ci: Add checkout to workflows --- .github/workflows/interu_build.yml | 5 ----- .github/workflows/interu_release.yml | 5 +++++ .github/workflows/pr_interu.yml | 9 +++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/interu_build.yml b/.github/workflows/interu_build.yml index 71bd963..7c2c0ba 100644 --- a/.github/workflows/interu_build.yml +++ b/.github/workflows/interu_build.yml @@ -18,11 +18,6 @@ jobs: name: Release interu-${{ inputs.target }} runs-on: ${{ inputs.os }} steps: - - name: Checkout - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - persist-credentials: false - - uses: dtolnay/rust-toolchain@0e66bd3e6b38ec0ad5312288c83e47c143e6b09e # v1 with: toolchain: ${{ env.RUST_VERSION }} diff --git a/.github/workflows/interu_release.yml b/.github/workflows/interu_release.yml index 78115e6..133b034 100644 --- a/.github/workflows/interu_release.yml +++ b/.github/workflows/interu_release.yml @@ -16,6 +16,11 @@ jobs: - target: x86_64-unknown-linux-gnu os: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + - name: Build interu uses: ./.github/workflows/interu_build.yml with: diff --git a/.github/workflows/pr_interu.yml b/.github/workflows/pr_interu.yml index 5160e8c..ff3e93c 100644 --- a/.github/workflows/pr_interu.yml +++ b/.github/workflows/pr_interu.yml @@ -1,4 +1,4 @@ -name: Release interu +name: Build interu on: pull_request: @@ -12,7 +12,7 @@ on: jobs: release: - name: Release interu-${{ matrix.target }} + name: Build interu-${{ matrix.target }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -21,6 +21,11 @@ jobs: - target: x86_64-unknown-linux-gnu os: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + - name: Build interu uses: ./.github/workflows/interu_build.yml with: From e8783a81cc35b8d4dd84337a5379c5aecccbeb6b Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 17 Dec 2024 16:42:33 +0100 Subject: [PATCH 05/25] ci: Up and download artifacts --- .github/workflows/interu_build.yml | 14 ++++++++++++++ .github/workflows/interu_release.yml | 28 ++++++++++++++-------------- .github/workflows/pr_interu.yml | 20 ++++++-------------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/.github/workflows/interu_build.yml b/.github/workflows/interu_build.yml index 7c2c0ba..d2353ad 100644 --- a/.github/workflows/interu_build.yml +++ b/.github/workflows/interu_build.yml @@ -9,6 +9,9 @@ on: target: required: true type: string + upload: + default: false + type: boolean env: RUST_VERSION: 1.83.0 @@ -18,6 +21,11 @@ jobs: name: Release interu-${{ inputs.target }} runs-on: ${{ inputs.os }} steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@0e66bd3e6b38ec0ad5312288c83e47c143e6b09e # v1 with: toolchain: ${{ env.RUST_VERSION }} @@ -28,3 +36,9 @@ jobs: - name: Rename Binary run: mv target/${{ inputs.target }}/release/interu interu-${{ inputs.target }} + + - name: Upload Artifact + if: inputs.upload + uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 + with: + path: interu-${{ inputs.target }} diff --git a/.github/workflows/interu_release.yml b/.github/workflows/interu_release.yml index 133b034..f9652f4 100644 --- a/.github/workflows/interu_release.yml +++ b/.github/workflows/interu_release.yml @@ -6,28 +6,28 @@ on: - "interu-[0-9]+.[0-9]+.[0-9]+**" jobs: - release: - name: Release interu-${{ matrix.target }} - runs-on: ${{ matrix.os }} + build: + uses: ./.github/workflows/interu_build.yml + with: + upload: true + target: ${{ matrix.target }} + os: ${{ matrix.os }} + strategy: fail-fast: false matrix: include: - target: x86_64-unknown-linux-gnu os: ubuntu-latest + release: + runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - persist-credentials: false - - - name: Build interu - uses: ./.github/workflows/interu_build.yml + - name: Download Artifacts + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 with: - target: ${{ matrix.target }} - os: ${{ matrix.os }} + path: artifacts - name: Upload Release Binary - uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # v2.0.5 + uses: softprops/action-gh-release@7b4da11513bf3f43f9999e90eabced41ab8bb048 # v2.2.0 with: - files: interu-${{ matrix.target }} + files: artifacts/* diff --git a/.github/workflows/pr_interu.yml b/.github/workflows/pr_interu.yml index ff3e93c..5fc2215 100644 --- a/.github/workflows/pr_interu.yml +++ b/.github/workflows/pr_interu.yml @@ -11,23 +11,15 @@ on: - Cargo.toml jobs: - release: - name: Build interu-${{ matrix.target }} - runs-on: ${{ matrix.os }} + build: + uses: ./.github/workflows/interu_build.yml + with: + target: ${{ matrix.target }} + os: ${{ matrix.os }} + strategy: fail-fast: false matrix: include: - target: x86_64-unknown-linux-gnu os: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - persist-credentials: false - - - name: Build interu - uses: ./.github/workflows/interu_build.yml - with: - target: ${{ matrix.target }} - os: ${{ matrix.os }} From 2539147394f55b8b1f360542a229fc9cba515c55 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 17 Dec 2024 17:14:16 +0100 Subject: [PATCH 06/25] feat: Add tracing --- Cargo.lock | 32 ++++++++++++++++++++++++++++++++ Cargo.toml | 1 + tools/interu/Cargo.toml | 1 + tools/interu/src/config/mod.rs | 9 ++++++++- tools/interu/src/instances.rs | 4 ++++ tools/interu/src/main.rs | 5 +++++ 6 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 3586f8c..fa6f07f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -371,6 +371,7 @@ dependencies = [ "serde_yaml", "snafu", "strum", + "tracing", ] [[package]] @@ -802,6 +803,37 @@ dependencies = [ "winnow", ] +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + [[package]] name = "unicode-ident" version = "1.0.14" diff --git a/Cargo.toml b/Cargo.toml index 56372c3..f4259cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ serde_with = "3.11.0" serde_yaml = "0.9.34+deprecated" snafu = "0.8.5" strum = { version = "0.26.3", features = ["derive"] } +tracing = "0.1.41" [profile.release] opt-level = "z" # Optimize for size. diff --git a/tools/interu/Cargo.toml b/tools/interu/Cargo.toml index 49c128d..4525038 100644 --- a/tools/interu/Cargo.toml +++ b/tools/interu/Cargo.toml @@ -12,3 +12,4 @@ serde_with.workspace = true serde_yaml.workspace = true snafu.workspace = true strum.workspace = true +tracing.workspace = true diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index 45686dc..64bff13 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -3,6 +3,7 @@ use std::{collections::BTreeMap, fmt::Display, path::Path}; use rand::{distributions::WeightedIndex, prelude::Distribution as _, thread_rng}; use serde::{Deserialize, Serialize}; use snafu::{OptionExt, ResultExt, Snafu}; +use tracing::instrument; use crate::{ config::{ @@ -50,19 +51,25 @@ pub struct Config { } impl Config { + #[instrument(name = "load_config_from_file", skip(path), fields(path = %path.as_ref().display()))] pub fn from_file

(path: P) -> Result where P: AsRef, { let contents = std::fs::read_to_string(path).context(ReadFileSnafu)?; + + tracing::debug!("deserialize file contents"); let config: Config = serde_yaml::from_str(&contents).context(DeserializeSnafu)?; - config.validate().context(ValidateSnafu)?; + config.validate().context(ValidateSnafu)?; Ok(config) } + #[instrument(name = "validate_config", skip(self))] fn validate(&self) -> Result<(), ValidationError> { for (profile_name, profile) in &self.profiles { + tracing::debug!(profile_name, "validate profile"); + profile .validate(profile_name, &self.runners) .context(InvalidProfileConfigSnafu)?; diff --git a/tools/interu/src/instances.rs b/tools/interu/src/instances.rs index 5dba124..c7d07c5 100644 --- a/tools/interu/src/instances.rs +++ b/tools/interu/src/instances.rs @@ -2,6 +2,7 @@ use std::{collections::HashMap, ops::Deref, path::Path}; use serde::Deserialize; use snafu::{ResultExt as _, Snafu}; +use tracing::instrument; use crate::config::runner::{Architecture, Distribution}; @@ -37,11 +38,14 @@ impl Deref for Architectures { } impl Instances { + #[instrument(name = "load_instance_mappings_from_file", skip(path), fields(path = %path.as_ref().display()))] pub fn from_file

(path: P) -> Result where P: AsRef, { let contents = std::fs::read_to_string(path).context(ReadFileSnafu)?; + + tracing::debug!("deserialize file contents"); let config: Instances = serde_yaml::from_str(&contents).context(DeserializeSnafu)?; Ok(config) diff --git a/tools/interu/src/main.rs b/tools/interu/src/main.rs index 83aafa7..31c62c9 100644 --- a/tools/interu/src/main.rs +++ b/tools/interu/src/main.rs @@ -22,11 +22,14 @@ enum Error { #[report] fn main() -> Result<(), Error> { + tracing::debug!("setup cli from env"); let cli: Cli = argh::from_env(); + tracing::info!("load config and instance mappings file"); let config = Config::from_file(&cli.config).context(ReadConfigSnafu)?; let instances = Instances::from_file(&cli.instances).context(ReadInstancesSnafu)?; + tracing::info!("determine parameters"); let parameters = config .determine_parameters(&cli.profile, instances) .unwrap(); @@ -34,6 +37,8 @@ fn main() -> Result<(), Error> { let parameters = parameters.to_string(); if let Some(output_path) = cli.output { + tracing::info!(output_path = %output_path.display(), "write parameters to output file"); + let mut file = OpenOptions::new() .append(true) .open(output_path) From 7d124b24d23c333f694dd768726b14797c3afb8f Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 17 Dec 2024 17:15:05 +0100 Subject: [PATCH 07/25] ci: Rename workflows --- .github/workflows/{interu_build.yml => build_interu.yml} | 2 +- .github/workflows/pr_interu.yml | 6 +++--- .../workflows/{interu_release.yml => release_interu.yml} | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename .github/workflows/{interu_build.yml => build_interu.yml} (95%) rename .github/workflows/{interu_release.yml => release_interu.yml} (93%) diff --git a/.github/workflows/interu_build.yml b/.github/workflows/build_interu.yml similarity index 95% rename from .github/workflows/interu_build.yml rename to .github/workflows/build_interu.yml index d2353ad..9377421 100644 --- a/.github/workflows/interu_build.yml +++ b/.github/workflows/build_interu.yml @@ -18,7 +18,7 @@ env: jobs: build: - name: Release interu-${{ inputs.target }} + name: Build interu-${{ inputs.target }} runs-on: ${{ inputs.os }} steps: - name: Checkout diff --git a/.github/workflows/pr_interu.yml b/.github/workflows/pr_interu.yml index 5fc2215..bd6d1ec 100644 --- a/.github/workflows/pr_interu.yml +++ b/.github/workflows/pr_interu.yml @@ -3,8 +3,8 @@ name: Build interu on: pull_request: paths: - - .github/workflows/interu_build.yml - - .github/workflows/interu_build.yml + - .github/workflows/release_interu.yml + - .github/workflows/build_interu.yml - .github/workflows/pr_interu.yml - rust-toolchain.toml - tools/interu/** @@ -12,7 +12,7 @@ on: jobs: build: - uses: ./.github/workflows/interu_build.yml + uses: ./.github/workflows/build_interu.yml with: target: ${{ matrix.target }} os: ${{ matrix.os }} diff --git a/.github/workflows/interu_release.yml b/.github/workflows/release_interu.yml similarity index 93% rename from .github/workflows/interu_release.yml rename to .github/workflows/release_interu.yml index f9652f4..d43e6e6 100644 --- a/.github/workflows/interu_release.yml +++ b/.github/workflows/release_interu.yml @@ -7,7 +7,7 @@ on: jobs: build: - uses: ./.github/workflows/interu_build.yml + uses: ./.github/workflows/build_interu.yml with: upload: true target: ${{ matrix.target }} From bca15cacc0fa0d8e10424cbb0d8dc623c0e1e9fa Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 18 Dec 2024 14:11:20 +0100 Subject: [PATCH 08/25] chore: Apply suggestions Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --- run-integration-test/README.md | 4 ++-- run-integration-test/config.example.yml | 9 +++++++-- tools/interu/src/cli.rs | 6 +++--- tools/interu/src/config/mod.rs | 15 ++++++++------- tools/interu/src/config/runner.rs | 16 ++++++---------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/run-integration-test/README.md b/run-integration-test/README.md index 43d37e0..02687e3 100644 --- a/run-integration-test/README.md +++ b/run-integration-test/README.md @@ -26,8 +26,8 @@ Supported Kubernetes version can be inspected on the official Replicated documen ## Integration Test Configuration File Each downstream repository needs a configuration file. This allows customization of various -parameters based on the needs of the operator / the particular tests. The config file needs to be -placed here: `tests/integration-tests.yml`. +parameters based on the needs of the operator, or the particular tests. The config file needs to be +placed here: `tests/interu.yaml` to be picked up automatically. ## Inputs and Outputs diff --git a/run-integration-test/config.example.yml b/run-integration-test/config.example.yml index c0464be..59de80d 100644 --- a/run-integration-test/config.example.yml +++ b/run-integration-test/config.example.yml @@ -1,6 +1,7 @@ +# Runners can be defined here, to select from the available Kubernetes versions +# and distributions along with node groups of desired instance size, +# architecture, disk size. runners: - # Runners can have more than one name. This is useful when the same runner is - # used for different tests default-amd64: platform: rke2-1.31.2 ttl: 4h @@ -36,6 +37,10 @@ runners: disk: 50 nodes: 3 +# Profiles allow for a variety of pre-configured runners and strategies. A +# profile can be chosen when calling interu. +# For example, the `schedule` profile could be used in CI on the `schedule` +# event. profiles: schedule: strategy: weighted diff --git a/tools/interu/src/cli.rs b/tools/interu/src/cli.rs index 4b8f4e2..5d1f3ad 100644 --- a/tools/interu/src/cli.rs +++ b/tools/interu/src/cli.rs @@ -10,7 +10,7 @@ pub struct Cli { option, short = 'c', long = "config", - default = "PathBuf::from(\"tests/interu.yaml\")" + default = r#"PathBuf::from("tests/interu.yaml")"# )] pub config: PathBuf, @@ -18,12 +18,12 @@ pub struct Cli { #[argh(option, short = 'i', long = "instances")] pub instances: PathBuf, - /// output key=value pairs separated by newlines to file + /// write configuration key=value pairs separated by newlines to file #[argh( option, short = 'o', long = "output", - description = "output key=value pairs separated by newlines to file. + description = "write configuration key=value pairs separated by newlines to file Useful for CI tools which give a file to write env vars and outputs to which are used in subsequent steps" )] pub output: Option, diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index 64bff13..9ecd8b6 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -59,7 +59,7 @@ impl Config { let contents = std::fs::read_to_string(path).context(ReadFileSnafu)?; tracing::debug!("deserialize file contents"); - let config: Config = serde_yaml::from_str(&contents).context(DeserializeSnafu)?; + let config: Self = serde_yaml::from_str(&contents).context(DeserializeSnafu)?; config.validate().context(ValidateSnafu)?; Ok(config) @@ -144,6 +144,8 @@ pub struct Parameters { impl Display for Parameters { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // Destructure all fields so that any additional parameters are handled here. + // DO NOT USE `..`. let Self { kubernetes_distribution, kubernetes_version, @@ -155,17 +157,16 @@ impl Display for Parameters { write!(f, "KUBERNETES_DISTRIBUTION={kubernetes_distribution}\n")?; write!(f, "KUBERNETES_VERSION={kubernetes_version}\n")?; - + write!(f, "TEST_PARALLELISM={test_parallelism}\n")?; + write!(f, "TEST_PARAMETER={test_parameter}\n")?; + write!(f, "TEST_RUN={test_run}\n")?; + // See: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#multiline-strings write!( f, "NODE_GROUPS< Result { - let parts: Vec<&str> = s.split('-').collect(); + let (distribution, version) = s.split_once('-').context(InvalidFormatSnafu)?; - match parts[..] { - [distribution, version] => { - let distribution = + let distribution = Distribution::from_str(distribution).context(ParseDistributionSnafu)?; - Ok(PlatformPair { - version: version.to_owned(), - distribution, - }) - } - _ => InvalidFormatSnafu.fail(), + Ok(PlatformPair { + version: version.to_owned(), + distribution, + }) } } } From 4250ed32fcdc704095dbc402959a9801f4871be1 Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 18 Dec 2024 14:27:40 +0100 Subject: [PATCH 09/25] fix: Remove faulty brace from suggestion --- tools/interu/src/config/runner.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tools/interu/src/config/runner.rs b/tools/interu/src/config/runner.rs index eeb20e5..a37aae8 100644 --- a/tools/interu/src/config/runner.rs +++ b/tools/interu/src/config/runner.rs @@ -49,15 +49,12 @@ impl FromStr for PlatformPair { fn from_str(s: &str) -> Result { let (distribution, version) = s.split_once('-').context(InvalidFormatSnafu)?; + let distribution = Distribution::from_str(distribution).context(ParseDistributionSnafu)?; - let distribution = - Distribution::from_str(distribution).context(ParseDistributionSnafu)?; - - Ok(PlatformPair { - version: version.to_owned(), - distribution, - }) - } + Ok(PlatformPair { + version: version.to_owned(), + distribution, + }) } } From 0a8f1e04b4575b92e98766dacc593034a94a5c63 Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 18 Dec 2024 14:28:45 +0100 Subject: [PATCH 10/25] chore: Prefix output variables --- tools/interu/src/config/mod.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index 9ecd8b6..8aa6ee9 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -155,18 +155,16 @@ impl Display for Parameters { test_run, } = self; - write!(f, "KUBERNETES_DISTRIBUTION={kubernetes_distribution}\n")?; - write!(f, "KUBERNETES_VERSION={kubernetes_version}\n")?; - write!(f, "TEST_PARALLELISM={test_parallelism}\n")?; - write!(f, "TEST_PARAMETER={test_parameter}\n")?; - write!(f, "TEST_RUN={test_run}\n")?; - + #[rustfmt::skip] // Skip formatting because otherwise the next line would be split into three lines. + write!(f, "INTERU_KUBERNETES_DISTRIBUTION={kubernetes_distribution}\n")?; + write!(f, "INTERU_KUBERNETES_VERSION={kubernetes_version}\n")?; + write!(f, "INTERU_TEST_PARALLELISM={test_parallelism}\n")?; + write!(f, "INTERU_TEST_PARAMETER={test_parameter}\n")?; + write!(f, "INTERU_TEST_RUN={test_run}\n")?; + // See: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#multiline-strings - write!( - f, - "NODE_GROUPS< Date: Wed, 18 Dec 2024 17:12:00 +0100 Subject: [PATCH 11/25] chore: Move fixture config file --- .../interu/fixtures/interu.yaml | 14 -------------- 1 file changed, 14 deletions(-) rename run-integration-test/config.example.yml => tools/interu/fixtures/interu.yaml (58%) diff --git a/run-integration-test/config.example.yml b/tools/interu/fixtures/interu.yaml similarity index 58% rename from run-integration-test/config.example.yml rename to tools/interu/fixtures/interu.yaml index 59de80d..279ee08 100644 --- a/run-integration-test/config.example.yml +++ b/tools/interu/fixtures/interu.yaml @@ -1,6 +1,3 @@ -# Runners can be defined here, to select from the available Kubernetes versions -# and distributions along with node groups of desired instance size, -# architecture, disk size. runners: default-amd64: platform: rke2-1.31.2 @@ -37,17 +34,10 @@ runners: disk: 50 nodes: 3 -# Profiles allow for a variety of pre-configured runners and strategies. A -# profile can be chosen when calling interu. -# For example, the `schedule` profile could be used in CI on the `schedule` -# event. profiles: schedule: strategy: weighted weights: - # 80%, 10% and 10% of the time - # Ideally we want: - 80: default-amd64 but that's hard to (de)serialize - # using serde - weight: 80 runner: default-amd64 - weight: 10 @@ -55,16 +45,12 @@ profiles: - weight: 10 runner: default-mixed options: - # Not explicitly setting 'test-run' and 'test-parameter' will run all - # tests parallelism: 1 workflow_dispatch: strategy: use-runner runner: default-amd64 options: - # Defaults to `--test-suite smoke` but can be overridden using - # workflow_dispatch inputs test-run: test-suite test-parameter: smoke parallelism: 2 From 8c80583fd375e77ae03a7a6bc3d6dc518dee45d5 Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 18 Dec 2024 17:13:28 +0100 Subject: [PATCH 12/25] feat: Add more runner and profile validation --- tools/interu/src/config/mod.rs | 15 +++++++++++- tools/interu/src/config/profile.rs | 37 ++++++++++++++++++++++++++---- tools/interu/src/config/runner.rs | 24 ++++++++++++++++--- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index 8aa6ee9..0a8cad8 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -8,7 +8,9 @@ use tracing::instrument; use crate::{ config::{ profile::{Profile, StrategyValidationError, TestRun}, - runner::{ConvertNodeGroupError, Distribution, ReplicatedNodeGroup, Runner}, + runner::{ + ConvertNodeGroupError, Distribution, ReplicatedNodeGroup, Runner, RunnerValidationError, + }, }, instances::Instances, }; @@ -36,6 +38,9 @@ pub enum Error { #[derive(Debug, Snafu)] pub enum ValidationError { + #[snafu(display("invalid runner config"))] + InvalidRunnerConfig { source: RunnerValidationError }, + #[snafu(display("invalid profile config"))] InvalidProfileConfig { source: StrategyValidationError }, } @@ -67,6 +72,14 @@ impl Config { #[instrument(name = "validate_config", skip(self))] fn validate(&self) -> Result<(), ValidationError> { + for (runner_name, runner) in &self.runners { + tracing::debug!(runner_name, "validate runner"); + + runner + .validate(runner_name) + .context(InvalidRunnerConfigSnafu)?; + } + for (profile_name, profile) in &self.profiles { tracing::debug!(profile_name, "validate profile"); diff --git a/tools/interu/src/config/profile.rs b/tools/interu/src/config/profile.rs index a829e68..807326c 100644 --- a/tools/interu/src/config/profile.rs +++ b/tools/interu/src/config/profile.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use serde::{Deserialize, Serialize}; -use snafu::Snafu; +use snafu::{ensure, Snafu}; use crate::config::runner::Runner; @@ -26,6 +26,14 @@ impl Profile { pub enum StrategyValidationError { #[snafu(display("runner {runner_ref:?} referenced in {at} is not defined"))] InvalidRunnerReference { at: String, runner_ref: String }, + + #[snafu(display( + r#"strategy {at} must define two or more weights, or use the "use-runner" strategy instead"# + ))] + WeightsCount { at: String }, + + #[snafu(display("strategy {at} references a runner already referenced by another weight"))] + NonUniqueWeightRunner { at: String }, } #[derive(Debug, Deserialize, Serialize)] @@ -80,15 +88,34 @@ impl WeightedOptions { profile_name: &str, runners: &BTreeMap, ) -> Result<(), StrategyValidationError> { - for weight in &self.weights { - if !runners.contains_key(&weight.runner) { - return InvalidRunnerReferenceSnafu { + ensure!( + self.weights.len() > 1, + WeightsCountSnafu { + at: format!("profiles.{profile_name}.weights") + } + ); + + for (i, weight) in self.weights.iter().enumerate() { + ensure!( + runners.contains_key(&weight.runner), + InvalidRunnerReferenceSnafu { at: format!( - "profile.{profile_name}.weights.{weight}", + "profiles.{profile_name}.weights.{weight}", weight = weight.weight ), runner_ref: weight.runner.clone(), } + ); + + // Ensure that all weights use unique runners + let before = &mut self.weights[..i].iter().map(|w| w.runner.as_str()); + if before.len() > 0 && before.any(|n| n == weight.runner) { + return NonUniqueWeightRunnerSnafu { + at: format!( + "profiles.{profile_name}.weights[{index}].runner", + index = i - 1 + ), + } .fail(); } } diff --git a/tools/interu/src/config/runner.rs b/tools/interu/src/config/runner.rs index a37aae8..6feb150 100644 --- a/tools/interu/src/config/runner.rs +++ b/tools/interu/src/config/runner.rs @@ -2,10 +2,16 @@ use std::{fmt::Display, str::FromStr}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; -use snafu::{OptionExt, ResultExt as _, Snafu}; +use snafu::{ensure, OptionExt, ResultExt as _, Snafu}; use crate::instances::Instances; +#[derive(Debug, Snafu)] +pub enum RunnerValidationError { + #[snafu(display("{at} must contain at least one node group"))] + ZeroNodeGroups { at: String }, +} + #[serde_as] #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] @@ -22,11 +28,23 @@ pub struct Runner { /// The time-to-live of the cluster. pub ttl: String, - /// Optionally define node groups. - #[serde(default, skip_serializing_if = "Vec::is_empty")] + /// Define one or more node groups. pub node_groups: Vec, } +impl Runner { + pub fn validate(&self, runner_name: &str) -> Result<(), RunnerValidationError> { + ensure!( + !self.node_groups.is_empty(), + ZeroNodeGroupsSnafu { + at: format!("runners.{runner_name}") + } + ); + + Ok(()) + } +} + #[derive(Debug, Snafu)] pub enum ParsePlatformTripleError { #[snafu(display("invalid format, expected pair separated by dashes"))] From 825c1665731477f582841184c02e92a9f7e0b3fd Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 18 Dec 2024 17:13:41 +0100 Subject: [PATCH 13/25] docs: Update action README --- run-integration-test/README.md | 57 +++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/run-integration-test/README.md b/run-integration-test/README.md index 02687e3..cc7d607 100644 --- a/run-integration-test/README.md +++ b/run-integration-test/README.md @@ -27,7 +27,62 @@ Supported Kubernetes version can be inspected on the official Replicated documen Each downstream repository needs a configuration file. This allows customization of various parameters based on the needs of the operator, or the particular tests. The config file needs to be -placed here: `tests/interu.yaml` to be picked up automatically. +placed here: `tests/interu.yaml` to be picked up automatically. There are two major components in +the config file: the definition of runners and test profiles. + +### Runners + +The runner configuration selects from the available Kubernetes versions and distributions along with +node groups of desired instance size, architecture, disk size. + +```yaml +runners: + default-amd64: + platform: rke2-1.31.2 + ttl: 4h + node-groups: + - name: default + arch: amd64 + size: large + disk: 50 + nodes: 3 +``` + +### Profiles + +Profiles allow for a variety of pre-configured runners and strategies. A profile can be chosen when +calling interu. For example, the `schedule` profile could be used in CI on the `schedule` event. The +following strategies are currently available: `weighted` and `use-runner`. + +- The `weighted` strategy allows defining two or more weights. Each weight defines how often the + runner specified is used when this profile is used. It should be noted that the weights *don't* + need to add up to 100, but it is recommended to more easily gauge the probability. +- The `use-runner` strategy just uses the specified runner. + +Each profile can additionally specify test options, like parallelism, test-run and test-parameter. + +```yaml +profiles: + schedule: + strategy: weighted + weights: + - weight: 80 + runner: default-amd64 + - weight: 10 + runner: default-arm64 + - weight: 10 + runner: default-mixed + options: + parallelism: 1 + + workflow_dispatch: + strategy: use-runner + runner: default-amd64 + options: + test-run: test-suite + test-parameter: smoke + parallelism: 2 +``` ## Inputs and Outputs From b2a911eafaab9fd780807b3d9635fac5c0cab596 Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 18 Dec 2024 19:59:05 +0100 Subject: [PATCH 14/25] test: Fix fixture file path --- tools/interu/src/config/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index 0a8cad8..2645583 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -189,7 +189,7 @@ mod test { use rstest::rstest; #[rstest] - fn serde(#[files("../../run-integration-test/config.example.yml")] path: PathBuf) { + fn serde(#[files("fixtures/interu.yaml")] path: PathBuf) { let content = std::fs::read_to_string(path).unwrap(); let config: Config = serde_yaml::from_str(&content).unwrap(); let yaml = serde_yaml::to_string(&config).unwrap(); From 4077bf5142685962b9b075eff4ee581cd92ba74a Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 18 Dec 2024 20:00:15 +0100 Subject: [PATCH 15/25] chore: Remove superfluous serde_yaml::with::singleton_map --- tools/interu/src/config/profile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/interu/src/config/profile.rs b/tools/interu/src/config/profile.rs index 807326c..14bb98a 100644 --- a/tools/interu/src/config/profile.rs +++ b/tools/interu/src/config/profile.rs @@ -161,7 +161,7 @@ impl UseRunnerOptions { pub struct TestOptions { pub parallelism: usize, - #[serde(default, with = "serde_yaml::with::singleton_map")] + #[serde(default)] pub test_run: TestRun, #[serde(default)] From c8089a0eb4edaf96f5e4e255a6f9a88764d37471 Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 18 Dec 2024 20:20:23 +0100 Subject: [PATCH 16/25] refactor: Add lifetimes, removed clones --- tools/interu/src/config/mod.rs | 32 +++++++++++++++---------------- tools/interu/src/config/runner.rs | 14 +++++++------- tools/interu/src/main.rs | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index 2645583..0c028a7 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -91,11 +91,11 @@ impl Config { Ok(()) } - pub fn determine_parameters( - &self, + pub fn determine_parameters<'a>( + &'a self, profile_name: &String, - instances: Instances, - ) -> Result { + instances: &'a Instances, + ) -> Result, Error> { // First, lookup the profile by name. Error if the profile does't exist. let profile = self .profiles @@ -128,34 +128,34 @@ impl Config { .node_groups .clone() .into_iter() - .map(|ng| ReplicatedNodeGroup::try_from(ng, &instances, &runner.platform.distribution)) + .map(|ng| ReplicatedNodeGroup::try_from(ng, instances, &runner.platform.distribution)) .collect::, ConvertNodeGroupError>>() .context(ConvertNodeGroupSnafu)?; Ok(Parameters { - kubernetes_distribution: runner.platform.distribution.clone(), - kubernetes_version: runner.platform.version.clone(), - test_parameter: test_parameter.to_owned(), - test_run: test_run.clone(), + kubernetes_distribution: &runner.platform.distribution, + kubernetes_version: runner.platform.version.as_str(), test_parallelism, + test_parameter, node_groups, + test_run, }) } } #[derive(Debug)] -pub struct Parameters { - kubernetes_distribution: Distribution, - kubernetes_version: String, +pub struct Parameters<'a> { + kubernetes_distribution: &'a Distribution, + kubernetes_version: &'a str, - node_groups: Vec, + node_groups: Vec>, test_parallelism: usize, - test_parameter: String, - test_run: TestRun, + test_parameter: &'a str, + test_run: &'a TestRun, } -impl Display for Parameters { +impl<'a> Display for Parameters<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { // Destructure all fields so that any additional parameters are handled here. // DO NOT USE `..`. diff --git a/tools/interu/src/config/runner.rs b/tools/interu/src/config/runner.rs index 6feb150..485162a 100644 --- a/tools/interu/src/config/runner.rs +++ b/tools/interu/src/config/runner.rs @@ -143,17 +143,17 @@ pub enum ConvertNodeGroupError { #[derive(Debug, Serialize)] #[serde(rename_all = "kebab-case")] -pub struct ReplicatedNodeGroup { - instance_type: String, +pub struct ReplicatedNodeGroup<'a> { + instance_type: &'a str, name: String, nodes: usize, disk: usize, } -impl ReplicatedNodeGroup { +impl<'a> ReplicatedNodeGroup<'a> { pub fn try_from( node_group: NodeGroup, - instances: &Instances, + instances: &'a Instances, distribution: &Distribution, ) -> Result { let architectures = @@ -170,9 +170,9 @@ impl ReplicatedNodeGroup { })?; let instance_type = match node_group.size { - Size::Small => sizes.small.clone(), - Size::Medium => sizes.medium.clone(), - Size::Large => sizes.large.clone(), + Size::Small => sizes.small.as_str(), + Size::Medium => sizes.medium.as_str(), + Size::Large => sizes.large.as_str(), }; Ok(Self { diff --git a/tools/interu/src/main.rs b/tools/interu/src/main.rs index 31c62c9..4c55233 100644 --- a/tools/interu/src/main.rs +++ b/tools/interu/src/main.rs @@ -31,7 +31,7 @@ fn main() -> Result<(), Error> { tracing::info!("determine parameters"); let parameters = config - .determine_parameters(&cli.profile, instances) + .determine_parameters(&cli.profile, &instances) .unwrap(); let parameters = parameters.to_string(); From f8e963122efa023c97845b63370aa7e2c1e0b3fd Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 18 Dec 2024 20:36:49 +0100 Subject: [PATCH 17/25] refactor: Improve error messages --- tools/interu/src/config/mod.rs | 43 ++++++++++++++++++++++++---------- tools/interu/src/main.rs | 6 ++--- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index 0c028a7..6054faa 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -1,4 +1,8 @@ -use std::{collections::BTreeMap, fmt::Display, path::Path}; +use std::{ + collections::BTreeMap, + fmt::Display, + path::{Path, PathBuf}, +}; use rand::{distributions::WeightedIndex, prelude::Distribution as _, thread_rng}; use serde::{Deserialize, Serialize}; @@ -20,14 +24,23 @@ pub mod runner; #[derive(Debug, Snafu)] pub enum Error { - #[snafu(display("failed to read file"))] - ReadFile { source: std::io::Error }, + #[snafu(display("failed to read config file at {path}", path = path.display()))] + ReadFile { + source: std::io::Error, + path: PathBuf, + }, - #[snafu(display("failed to deserialize file"))] - Deserialize { source: serde_yaml::Error }, + #[snafu(display("failed to deserialize config file at {path} as yaml", path = path.display()))] + Deserialize { + source: serde_yaml::Error, + path: PathBuf, + }, - #[snafu(display("failed to validate file"))] - Validate { source: ValidationError }, + #[snafu(display("failed to validate config file at {path}", path = path.display()))] + Validate { + source: ValidationError, + path: PathBuf, + }, #[snafu(display("failed to find profile named {profile_name:?}"))] UnknownProfileName { profile_name: String }, @@ -38,10 +51,10 @@ pub enum Error { #[derive(Debug, Snafu)] pub enum ValidationError { - #[snafu(display("invalid runner config"))] + #[snafu(display("encountered invalid runner config"))] InvalidRunnerConfig { source: RunnerValidationError }, - #[snafu(display("invalid profile config"))] + #[snafu(display("encountered invalid profile config"))] InvalidProfileConfig { source: StrategyValidationError }, } @@ -61,12 +74,18 @@ impl Config { where P: AsRef, { - let contents = std::fs::read_to_string(path).context(ReadFileSnafu)?; + let contents = std::fs::read_to_string(&path).context(ReadFileSnafu { + path: path.as_ref(), + })?; tracing::debug!("deserialize file contents"); - let config: Self = serde_yaml::from_str(&contents).context(DeserializeSnafu)?; + let config: Self = serde_yaml::from_str(&contents).context(DeserializeSnafu { + path: path.as_ref(), + })?; - config.validate().context(ValidateSnafu)?; + config.validate().context(ValidateSnafu { + path: path.as_ref(), + })?; Ok(config) } diff --git a/tools/interu/src/main.rs b/tools/interu/src/main.rs index 4c55233..dab28ec 100644 --- a/tools/interu/src/main.rs +++ b/tools/interu/src/main.rs @@ -10,8 +10,8 @@ mod instances; #[derive(Debug, Snafu)] enum Error { - #[snafu(display("failed to read config"))] - ReadConfig { source: config::Error }, + #[snafu(display("failed to load config"))] + LoadConfig { source: config::Error }, #[snafu(display("failed to read instances file"))] ReadInstances { source: instances::Error }, @@ -26,7 +26,7 @@ fn main() -> Result<(), Error> { let cli: Cli = argh::from_env(); tracing::info!("load config and instance mappings file"); - let config = Config::from_file(&cli.config).context(ReadConfigSnafu)?; + let config = Config::from_file(&cli.config).context(LoadConfigSnafu)?; let instances = Instances::from_file(&cli.instances).context(ReadInstancesSnafu)?; tracing::info!("determine parameters"); From 9a269b29d622c032a4875d4c12fd8441504ca7cb Mon Sep 17 00:00:00 2001 From: Techassi Date: Sun, 5 Jan 2025 14:05:46 +0100 Subject: [PATCH 18/25] chore: Add interu README --- tools/interu/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tools/interu/README.md diff --git a/tools/interu/README.md b/tools/interu/README.md new file mode 100644 index 0000000..78e6a0c --- /dev/null +++ b/tools/interu/README.md @@ -0,0 +1,6 @@ +# interu + +interu is a small utility to read, validate and expand integration test config files. For more +information on what it can do, consult the `run-integration-test` action [README][action-readme]. + +[action-readme]: ../../run-integration-test/README.md From 6b34590a0322f82620c2aa80e2ec477993a9e9f5 Mon Sep 17 00:00:00 2001 From: Techassi Date: Sun, 5 Jan 2025 14:16:19 +0100 Subject: [PATCH 19/25] fix: Emit cluster TTL --- tools/interu/src/config/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index 6054faa..f4e07c4 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -153,7 +153,8 @@ impl Config { Ok(Parameters { kubernetes_distribution: &runner.platform.distribution, - kubernetes_version: runner.platform.version.as_str(), + kubernetes_version: &runner.platform.version, + cluster_ttl: &runner.ttl, test_parallelism, test_parameter, node_groups, @@ -167,6 +168,7 @@ pub struct Parameters<'a> { kubernetes_distribution: &'a Distribution, kubernetes_version: &'a str, + cluster_ttl: &'a str, node_groups: Vec>, test_parallelism: usize, @@ -181,6 +183,7 @@ impl<'a> Display for Parameters<'a> { let Self { kubernetes_distribution, kubernetes_version, + cluster_ttl, node_groups, test_parallelism, test_parameter, @@ -192,6 +195,7 @@ impl<'a> Display for Parameters<'a> { write!(f, "INTERU_KUBERNETES_VERSION={kubernetes_version}\n")?; write!(f, "INTERU_TEST_PARALLELISM={test_parallelism}\n")?; write!(f, "INTERU_TEST_PARAMETER={test_parameter}\n")?; + write!(f, "INTERU_CLUSTER_TTL={cluster_ttl}\n")?; write!(f, "INTERU_TEST_RUN={test_run}\n")?; // See: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#multiline-strings From 0ef671b80b94540e52ba70ee2a1be674fd99cf0a Mon Sep 17 00:00:00 2001 From: Techassi Date: Sun, 5 Jan 2025 14:18:08 +0100 Subject: [PATCH 20/25] test: Add unit test for instance deserialization --- tools/interu/fixtures/instances.yaml | 47 ++++++++++++++++++++++++++++ tools/interu/src/instances.rs | 13 ++++++++ 2 files changed, 60 insertions(+) create mode 100644 tools/interu/fixtures/instances.yaml diff --git a/tools/interu/fixtures/instances.yaml b/tools/interu/fixtures/instances.yaml new file mode 100644 index 0000000..0a38232 --- /dev/null +++ b/tools/interu/fixtures/instances.yaml @@ -0,0 +1,47 @@ +eks: + arm64: + small: m7g.large + medium: m7g.2xlarge + large: m7g.4xlarge + amd64: + small: m6i.large + medium: m6i.2xlarge + large: m6i.4xlarge + +gke: + arm64: + small: t2a-standard-2 + medium: t2a-standard-8 + large: t2a-standard-16 + amd64: + small: e2-standard-2 + medium: e2-standard-8 + large: e2-standard-16 + +aks: + arm64: + small: Standard_D2ps_v5 + medium: Standard_D8ps_v5 + large: Standard_D16ps_v5 + amd64: + small: Standard_DS1_v2 + medium: Standard_DS3_v2 + large: Standard_DS5_v2 + +kind: + amd64: + small: r1.small + medium: r1.medium + large: r1.large + +k3s: + amd64: + small: r1.small + medium: r1.medium + large: r1.large + +rke2: + amd64: + small: r1.small + medium: r1.medium + large: r1.large diff --git a/tools/interu/src/instances.rs b/tools/interu/src/instances.rs index c7d07c5..cac14d4 100644 --- a/tools/interu/src/instances.rs +++ b/tools/interu/src/instances.rs @@ -59,3 +59,16 @@ pub struct Sizes { pub medium: String, pub large: String, } + +#[cfg(test)] +mod test { + use std::path::PathBuf; + + use super::*; + use rstest::rstest; + + #[rstest] + fn deserialize(#[files("fixtures/instances.yaml")] path: PathBuf) { + let _ = Instances::from_file(path).unwrap(); + } +} From ba1c73b2ccad2bf26ce536ced26c99e642845311 Mon Sep 17 00:00:00 2001 From: Techassi Date: Sun, 5 Jan 2025 14:19:52 +0100 Subject: [PATCH 21/25] refactor: Remove unused Serialize derives --- tools/interu/src/config/mod.rs | 11 ++++------- tools/interu/src/config/runner.rs | 21 ++++++--------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index f4e07c4..e923dae 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -5,7 +5,7 @@ use std::{ }; use rand::{distributions::WeightedIndex, prelude::Distribution as _, thread_rng}; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use snafu::{OptionExt, ResultExt, Snafu}; use tracing::instrument; @@ -58,7 +58,7 @@ pub enum ValidationError { InvalidProfileConfig { source: StrategyValidationError }, } -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct Config { #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] @@ -212,10 +212,7 @@ mod test { use rstest::rstest; #[rstest] - fn serde(#[files("fixtures/interu.yaml")] path: PathBuf) { - let content = std::fs::read_to_string(path).unwrap(); - let config: Config = serde_yaml::from_str(&content).unwrap(); - let yaml = serde_yaml::to_string(&config).unwrap(); - println!("{yaml}"); + fn deserialize(#[files("fixtures/interu.yaml")] path: PathBuf) { + let _ = Config::from_file(path).unwrap(); } } diff --git a/tools/interu/src/config/runner.rs b/tools/interu/src/config/runner.rs index 485162a..86fe693 100644 --- a/tools/interu/src/config/runner.rs +++ b/tools/interu/src/config/runner.rs @@ -13,18 +13,13 @@ pub enum RunnerValidationError { } #[serde_as] -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct Runner { #[serde_as(as = "DisplayFromStr")] pub platform: PlatformPair, - // TODO (@Techassi): Allow some kind of inheritance here - // /// The size of cluster nodes. Can be `small`, `medium`, or `large`. - // pub size: Size, - - // /// The size of the disk in GB per cluster node. - // pub disk: usize, + // TODO (@Techassi): Allow some kind of inheritance here (size, disk, ttl, etc...) /// The time-to-live of the cluster. pub ttl: String, @@ -87,9 +82,7 @@ impl Display for PlatformPair { } } -#[derive( - Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize, strum::Display, strum::EnumString, -)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, strum::Display, strum::EnumString)] #[strum(serialize_all = "lowercase")] #[serde(rename_all = "lowercase")] pub enum Distribution { @@ -101,9 +94,7 @@ pub enum Distribution { Rke2, } -#[derive( - Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize, strum::Display, strum::EnumString, -)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, strum::Display, strum::EnumString)] #[strum(serialize_all = "kebab-case")] #[serde(rename_all = "kebab-case")] pub enum Architecture { @@ -111,7 +102,7 @@ pub enum Architecture { Arm64, } -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "kebab-case")] pub enum Size { Small, @@ -119,7 +110,7 @@ pub enum Size { Large, } -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct NodeGroup { name: String, From 123a52b57b1920f7888447f3282ac74bcbe9f0ec Mon Sep 17 00:00:00 2001 From: Techassi Date: Sun, 5 Jan 2025 14:20:22 +0100 Subject: [PATCH 22/25] chore: Add doc comments, improve error handling --- tools/interu/src/config/mod.rs | 16 ++++++++++++++++ tools/interu/src/instances.rs | 8 ++++++++ tools/interu/src/main.rs | 13 +++++++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/tools/interu/src/config/mod.rs b/tools/interu/src/config/mod.rs index e923dae..fbcb5fd 100644 --- a/tools/interu/src/config/mod.rs +++ b/tools/interu/src/config/mod.rs @@ -22,6 +22,7 @@ use crate::{ pub mod profile; pub mod runner; +/// Errors which can be encountered when reading and validating the config file. #[derive(Debug, Snafu)] pub enum Error { #[snafu(display("failed to read config file at {path}", path = path.display()))] @@ -49,6 +50,7 @@ pub enum Error { ConvertNodeGroup { source: ConvertNodeGroupError }, } +/// Errors which can be encountered during config file validation. #[derive(Debug, Snafu)] pub enum ValidationError { #[snafu(display("encountered invalid runner config"))] @@ -69,6 +71,7 @@ pub struct Config { } impl Config { + /// Read, deserialize and validate a config from a file located at `path`. #[instrument(name = "load_config_from_file", skip(path), fields(path = %path.as_ref().display()))] pub fn from_file

(path: P) -> Result where @@ -110,6 +113,7 @@ impl Config { Ok(()) } + /// Determines the final expanded parameters based on the provided profile. pub fn determine_parameters<'a>( &'a self, profile_name: &String, @@ -163,16 +167,28 @@ impl Config { } } +/// Parameters which will be expanded into environment variables via the [`Display`] implementation. #[derive(Debug)] pub struct Parameters<'a> { + /// Selected Kubernetes distribution available on Replicated. kubernetes_distribution: &'a Distribution, + + /// Kubernetes version used for the cluster. kubernetes_version: &'a str, + /// Maximum TTL of the cluster. cluster_ttl: &'a str, + + /// Node groups which will be created in the cluster. node_groups: Vec>, + /// Number of tests which get run in parallel. test_parallelism: usize, + + /// Optional test parameter passed to `test_run`. test_parameter: &'a str, + + /// Set of tests to run. test_run: &'a TestRun, } diff --git a/tools/interu/src/instances.rs b/tools/interu/src/instances.rs index cac14d4..f129864 100644 --- a/tools/interu/src/instances.rs +++ b/tools/interu/src/instances.rs @@ -15,6 +15,7 @@ pub enum Error { Deserialize { source: serde_yaml::Error }, } +/// Contains distribution to architecture mappings. #[derive(Debug, Deserialize)] pub struct Instances(HashMap); @@ -26,6 +27,7 @@ impl Deref for Instances { } } +/// Contains architecture to size mappings. #[derive(Debug, Deserialize)] pub struct Architectures(HashMap); @@ -38,6 +40,7 @@ impl Deref for Architectures { } impl Instances { + /// Reads and deserializes the mappings from a file located at `path`. #[instrument(name = "load_instance_mappings_from_file", skip(path), fields(path = %path.as_ref().display()))] pub fn from_file

(path: P) -> Result where @@ -53,6 +56,11 @@ impl Instances { } // NOTE (@Techassi): Can we somehow re-use the size enum here? +/// Contains size to instance name mappings. +/// +/// This mapping translates our sizes into instance names. Every cloud vendor uses a different +/// scheme to name their instances. It removes the need to specify the exact name and instead +/// enables the use of a simple size: small, medium, and large. #[derive(Debug, Deserialize)] pub struct Sizes { pub small: String, diff --git a/tools/interu/src/main.rs b/tools/interu/src/main.rs index dab28ec..0ccc6be 100644 --- a/tools/interu/src/main.rs +++ b/tools/interu/src/main.rs @@ -13,8 +13,11 @@ enum Error { #[snafu(display("failed to load config"))] LoadConfig { source: config::Error }, - #[snafu(display("failed to read instances file"))] - ReadInstances { source: instances::Error }, + #[snafu(display("failed to determine expanded parameters"))] + DetermineParameters { source: config::Error }, + + #[snafu(display("failed to load instances file"))] + LoadInstances { source: instances::Error }, #[snafu(display("failed to write to output file"))] WriteOutputFile { source: std::io::Error }, @@ -27,15 +30,16 @@ fn main() -> Result<(), Error> { tracing::info!("load config and instance mappings file"); let config = Config::from_file(&cli.config).context(LoadConfigSnafu)?; - let instances = Instances::from_file(&cli.instances).context(ReadInstancesSnafu)?; + let instances = Instances::from_file(&cli.instances).context(LoadInstancesSnafu)?; tracing::info!("determine parameters"); let parameters = config .determine_parameters(&cli.profile, &instances) - .unwrap(); + .context(DetermineParametersSnafu)?; let parameters = parameters.to_string(); + // Optionally write the expanded parameters into an output file if let Some(output_path) = cli.output { tracing::info!(output_path = %output_path.display(), "write parameters to output file"); @@ -48,6 +52,7 @@ fn main() -> Result<(), Error> { .context(WriteOutputFileSnafu)?; } + // Output the expanded parameters to stdout if no --quiet flag was passed if !cli.quiet { print!("{parameters}"); } From 989bb9d24e3740f75894875cb86764600f85b7f2 Mon Sep 17 00:00:00 2001 From: Techassi Date: Fri, 10 Jan 2025 13:46:02 +0100 Subject: [PATCH 23/25] chore: Apply suggestions Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --- run-integration-test/README.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/run-integration-test/README.md b/run-integration-test/README.md index cc7d607..61b87c4 100644 --- a/run-integration-test/README.md +++ b/run-integration-test/README.md @@ -27,8 +27,12 @@ Supported Kubernetes version can be inspected on the official Replicated documen Each downstream repository needs a configuration file. This allows customization of various parameters based on the needs of the operator, or the particular tests. The config file needs to be -placed here: `tests/interu.yaml` to be picked up automatically. There are two major components in -the config file: the definition of runners and test profiles. +placed here: `tests/interu.yaml` to be picked up automatically. + +There are two major components in the config file: + +- Definition of `runners`. +- Test `profiles`. ### Runners @@ -51,15 +55,19 @@ runners: ### Profiles Profiles allow for a variety of pre-configured runners and strategies. A profile can be chosen when -calling interu. For example, the `schedule` profile could be used in CI on the `schedule` event. The -following strategies are currently available: `weighted` and `use-runner`. +calling interu. For example, the `schedule` profile could be used in CI on the `schedule` event. + +The following strategies are currently available: + +- `weighted`. +- `use-runner`. -- The `weighted` strategy allows defining two or more weights. Each weight defines how often the +- The `weighted` strategy allows defining two or more `weights`. Each `weight` defines how often the runner specified is used when this profile is used. It should be noted that the weights *don't* need to add up to 100, but it is recommended to more easily gauge the probability. -- The `use-runner` strategy just uses the specified runner. +- The `use-runner` strategy just uses the specified `runner`. -Each profile can additionally specify test options, like parallelism, test-run and test-parameter. +Each profile can additionally specify test `options`, like `parallelism`, `test-run` and `test-parameter`. ```yaml profiles: From 21089edf5f31062460ceb496c319b4ce0ea05d87 Mon Sep 17 00:00:00 2001 From: Techassi Date: Fri, 10 Jan 2025 13:50:08 +0100 Subject: [PATCH 24/25] chore: Change key-value to key=value --- tools/interu/src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/interu/src/cli.rs b/tools/interu/src/cli.rs index 5d1f3ad..7ce6577 100644 --- a/tools/interu/src/cli.rs +++ b/tools/interu/src/cli.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use argh::FromArgs; #[derive(Debug, FromArgs)] -/// Expand configuration into key-value pairs used by the run-integration-test action +/// Expand configuration into key=value pairs used by the run-integration-test action pub struct Cli { /// path to integration test config file #[argh( From 94f3574e6c153a5f5759f6d4efda154b00f3925b Mon Sep 17 00:00:00 2001 From: Techassi Date: Fri, 10 Jan 2025 13:51:08 +0100 Subject: [PATCH 25/25] chore: Change disk option to disk-gb --- tools/interu/src/config/runner.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/interu/src/config/runner.rs b/tools/interu/src/config/runner.rs index 86fe693..016e932 100644 --- a/tools/interu/src/config/runner.rs +++ b/tools/interu/src/config/runner.rs @@ -120,7 +120,9 @@ pub struct NodeGroup { nodes: usize, size: Size, - disk: usize, + + #[serde(rename = "disk-gb")] + disk_size: usize, } #[derive(Debug, Snafu)] @@ -170,7 +172,7 @@ impl<'a> ReplicatedNodeGroup<'a> { instance_type, name: node_group.name, nodes: node_group.nodes, - disk: node_group.disk, + disk: node_group.disk_size, }) } }