From 21ca93abfa6442b362a0acc421e2fa2246c0af93 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Fri, 6 Jun 2025 19:03:19 +0100 Subject: [PATCH 01/16] Reducing common struct types Signed-off-by: Dawid Nowak --- Cargo.lock | 491 ++++-- Cargo.toml | 2 +- gateway-api/Cargo.toml | 4 +- gateway-api/src/apis/mod.rs | 1 + .../src/apis/processed/common_types.rs | 78 + gateway-api/src/apis/processed/constants.rs | 90 ++ .../src/apis/processed/enum_defaults.rs | 50 + .../src/apis/processed/gatewayclasses.rs | 111 ++ gateway-api/src/apis/processed/gateways.rs | 644 ++++++++ gateway-api/src/apis/processed/grpcroutes.rs | 688 +++++++++ gateway-api/src/apis/processed/httproutes.rs | 1376 +++++++++++++++++ gateway-api/src/apis/processed/mod.rs | 10 + .../src/apis/processed/referencegrants.rs | 96 ++ gateway-api/src/lib.rs | 11 +- type-reducer/Cargo.toml | 21 + .../customized_mapped_names_pass_1.txt | 6 + .../customized_mapped_names_pass_2.txt | 3 + type-reducer/reduced_types_pass_1.txt | 7 + type-reducer/src/main.rs | 613 ++++++++ update.sh | 11 + 20 files changed, 4219 insertions(+), 94 deletions(-) create mode 100644 gateway-api/src/apis/processed/common_types.rs create mode 100644 gateway-api/src/apis/processed/constants.rs create mode 100644 gateway-api/src/apis/processed/enum_defaults.rs create mode 100644 gateway-api/src/apis/processed/gatewayclasses.rs create mode 100644 gateway-api/src/apis/processed/gateways.rs create mode 100644 gateway-api/src/apis/processed/grpcroutes.rs create mode 100644 gateway-api/src/apis/processed/httproutes.rs create mode 100644 gateway-api/src/apis/processed/mod.rs create mode 100644 gateway-api/src/apis/processed/referencegrants.rs create mode 100644 type-reducer/Cargo.toml create mode 100644 type-reducer/customized_mapped_names_pass_1.txt create mode 100644 type-reducer/customized_mapped_names_pass_2.txt create mode 100644 type-reducer/reduced_types_pass_1.txt create mode 100644 type-reducer/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 070aaac..8670e11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,56 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.6.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.59.0", +] + [[package]] name = "anyhow" version = "1.0.98" @@ -40,9 +90,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" -version = "0.3.74" +version = "0.3.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" dependencies = [ "addr2line", "cfg-if", @@ -50,15 +100,9 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets", + "windows-targets 0.52.6", ] -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64" version = "0.22.1" @@ -67,9 +111,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "block-buffer" @@ -82,9 +126,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.17.0" +version = "3.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" [[package]] name = "bytes" @@ -94,9 +138,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "cc" -version = "1.2.19" +version = "1.2.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362" +checksum = "956a5e21988b87f372569b66183b78babf23ebc2e744b733e4350a752c4dafac" dependencies = [ "shlex", ] @@ -109,14 +153,54 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "num-traits", "serde", ] +[[package]] +name = "clap" +version = "4.5.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + [[package]] name = "codegen" version = "0.2.0" @@ -126,6 +210,22 @@ dependencies = [ "indexmap 1.9.3", ] +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys 0.59.0", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -138,9 +238,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" dependencies = [ "core-foundation-sys", "libc", @@ -217,6 +317,15 @@ dependencies = [ "syn", ] +[[package]] +name = "deranged" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +dependencies = [ + "powerfmt", +] + [[package]] name = "digest" version = "0.10.7" @@ -381,9 +490,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", @@ -392,9 +501,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "libc", @@ -416,17 +525,17 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.15.2" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" [[package]] name = "headers" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322106e6bd0cba2d5ead589ddb8150a13d7c4217cf80d7c4f682ca994ccc6aa9" +checksum = "b3314d5adb5d94bcdf56771f2e50dbbc80bb4bdf88967526706205ac9eff24eb" dependencies = [ - "base64 0.21.7", + "base64", "bytes", "headers-core", "http", @@ -444,6 +553,12 @@ dependencies = [ "http", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "home" version = "0.5.11" @@ -540,11 +655,10 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.5" +version = "0.27.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" dependencies = [ - "futures-util", "http", "hyper", "hyper-util", @@ -572,12 +686,13 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9f1e950e0d9d1d3c47184416723cf29c0d1f93bd8cccf37e4beb6b44f31710" +checksum = "dc2fdfdbff08affe55bb779f33b053aa1fe5dd5b54c257343c17edfa55711bdb" dependencies = [ "bytes", "futures-channel", + "futures-core", "futures-util", "http", "http-body", @@ -613,7 +728,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", - "hashbrown 0.15.2", + "hashbrown 0.15.3", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", ] [[package]] @@ -651,7 +781,7 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c75b990324f09bef15e791606b7b7a296d02fc88a344f6eba9390970a870ad5" dependencies = [ - "base64 0.22.1", + "base64", "chrono", "schemars", "serde", @@ -677,7 +807,7 @@ version = "0.99.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fc2ed952042df20d15ac2fe9614d0ec14b6118eab89633985d4b36e688dccf1" dependencies = [ - "base64 0.22.1", + "base64", "bytes", "chrono", "either", @@ -753,9 +883,9 @@ checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "lock_api" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" dependencies = [ "autocfg", "scopeguard", @@ -766,6 +896,9 @@ name = "log" version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +dependencies = [ + "serde", +] [[package]] name = "memchr" @@ -790,13 +923,22 @@ dependencies = [ [[package]] name = "mio" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.52.0", + "windows-sys 0.59.0", +] + +[[package]] +name = "multimap" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" +dependencies = [ + "serde", ] [[package]] @@ -809,6 +951,12 @@ dependencies = [ "winapi", ] +[[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" @@ -818,6 +966,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "object" version = "0.36.7" @@ -833,6 +990,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "once_cell_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" + [[package]] name = "openssl-probe" version = "0.1.6" @@ -856,9 +1019,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parking_lot" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" dependencies = [ "lock_api", "parking_lot_core", @@ -866,15 +1029,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.10" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -883,7 +1046,7 @@ version = "3.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38af38e8470ac9dee3ce1bae1af9c1671fffc44ddfd8bd1d0a3445bf349a8ef3" dependencies = [ - "base64 0.22.1", + "base64", "serde", ] @@ -950,6 +1113,12 @@ 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.21" @@ -959,6 +1128,16 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "prettyplease" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dee91521343f4c5c6a63edd65e54f31f5c92fe8978c40a4282f8372194c6a7d" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.95" @@ -1009,14 +1188,14 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom 0.3.2", + "getrandom 0.3.3", ] [[package]] name = "redox_syscall" -version = "0.5.11" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" +checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" dependencies = [ "bitflags", ] @@ -1064,7 +1243,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.15", + "getrandom 0.2.16", "libc", "untrusted", "windows-sys 0.52.0", @@ -1078,9 +1257,9 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustls" -version = "0.23.26" +version = "0.23.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df51b5869f3a441595eac5e8ff14d486ff285f7b8c0df8770e49c3b56351f0f0" +checksum = "730944ca083c1c233a75c09f199e973ca499344a2b7ba9e755c457e86fb4a321" dependencies = [ "log", "once_cell", @@ -1127,15 +1306,18 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" +checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" +dependencies = [ + "zeroize", +] [[package]] name = "rustls-webpki" -version = "0.103.1" +version = "0.103.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03" +checksum = "e4a72fe2bcf7a6ac6fd7d0b9e5cb68aeb7d4c0a0271730218b3e92d43b4eb435" dependencies = [ "ring", "rustls-pki-types", @@ -1222,7 +1404,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" dependencies = [ "bitflags", - "core-foundation 0.10.0", + "core-foundation 0.10.1", "core-foundation-sys", "libc", "security-framework-sys", @@ -1317,9 +1499,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.8" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures", @@ -1343,13 +1525,25 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" -version = "1.4.4" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ee1aca2bc74ef9589efa7ccaa0f3752751399940356209b3fd80c078149b5e" +checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" dependencies = [ "libc", ] +[[package]] +name = "simple_logger" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c5dfa5e08767553704aa0ffd9d9794d527103c736aba9854773851fd7497eb" +dependencies = [ + "colored", + "log", + "time", + "windows-sys 0.48.0", +] + [[package]] name = "slab" version = "0.4.9" @@ -1367,9 +1561,9 @@ checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" [[package]] name = "socket2" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" dependencies = [ "libc", "windows-sys 0.52.0", @@ -1389,9 +1583,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.100" +version = "2.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" dependencies = [ "proc-macro2", "quote", @@ -1434,6 +1628,39 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +dependencies = [ + "deranged", + "itoa", + "libc", + "num-conv", + "num_threads", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" + +[[package]] +name = "time-macros" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tokio" version = "1.45.1" @@ -1475,9 +1702,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.14" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" +checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" dependencies = [ "bytes", "futures-core", @@ -1505,11 +1732,11 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.2" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" +checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" dependencies = [ - "base64 0.22.1", + "base64", "bitflags", "bytes", "http", @@ -1547,9 +1774,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +checksum = "1b1ffbcf9c6f6b99d386e7444eb608ba646ae452a36b39737deb9663b610f662" dependencies = [ "proc-macro2", "quote", @@ -1558,9 +1785,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" dependencies = [ "once_cell", "valuable", @@ -1597,6 +1824,20 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "type-reducer" +version = "0.1.0" +dependencies = [ + "clap", + "itertools", + "log", + "multimap", + "prettyplease", + "proc-macro2", + "simple_logger", + "syn", +] + [[package]] name = "typenum" version = "1.18.0" @@ -1627,13 +1868,19 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" dependencies = [ - "getrandom 0.3.2", + "getrandom 0.3.3", "js-sys", "rand", "wasm-bindgen", @@ -1755,13 +2002,22 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1770,7 +2026,22 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -1779,28 +2050,46 @@ 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_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1813,24 +2102,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -1848,18 +2161,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 4048149..503b8c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["gateway-api", "gateway-api/examples", "xtask"] +members = ["gateway-api", "gateway-api/examples", "xtask", "type-reducer"] resolver = "2" [workspace.package] diff --git a/gateway-api/Cargo.toml b/gateway-api/Cargo.toml index 81cef86..70286e8 100644 --- a/gateway-api/Cargo.toml +++ b/gateway-api/Cargo.toml @@ -38,5 +38,7 @@ uuid.workspace = true features = ["k8s-openapi/v1_32"] [features] -default = [] +default = ["processed"] +standard = [] experimental = [] +processed=[] \ No newline at end of file diff --git a/gateway-api/src/apis/mod.rs b/gateway-api/src/apis/mod.rs index 7651e9f..70353fa 100644 --- a/gateway-api/src/apis/mod.rs +++ b/gateway-api/src/apis/mod.rs @@ -1,2 +1,3 @@ pub mod experimental; pub mod standard; +pub mod processed; diff --git a/gateway-api/src/apis/processed/common_types.rs b/gateway-api/src/apis/processed/common_types.rs new file mode 100644 index 0000000..19c5c1b --- /dev/null +++ b/gateway-api/src/apis/processed/common_types.rs @@ -0,0 +1,78 @@ +// WARNING! generated file do not edit + +#[allow(unused_imports)] +mod prelude { + pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; + pub use kube::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Deserialize, Serialize}; + pub use std::collections::BTreeMap; +} +use self::prelude::*; +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HeaderModifierRules { + pub name: String, + pub value: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct Kind { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + pub kind: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct MirrorBackendRef { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RouteRef { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")] + pub section_name: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayAddress { + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + pub value: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct ExtensionBackendRef { + pub group: String, + pub kind: String, + pub name: String, +} + + +// Next attempt + +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct FilterMirrorRouteRules { + #[serde(rename = "backendRef")] + pub backend_ref: MirrorBackendRef, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct FilterHeaderRouteRules { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub add: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub remove: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub set: Option>, +} diff --git a/gateway-api/src/apis/processed/constants.rs b/gateway-api/src/apis/processed/constants.rs new file mode 100644 index 0000000..ef75c43 --- /dev/null +++ b/gateway-api/src/apis/processed/constants.rs @@ -0,0 +1,90 @@ +// WARNING! generated file do not edit + +#[derive(Debug, PartialEq, Eq)] +pub enum GatewayClassConditionType { + Accepted, +} +impl std::fmt::Display for GatewayClassConditionType { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} +#[derive(Debug, PartialEq, Eq)] +pub enum GatewayClassConditionReason { + Accepted, + InvalidParameters, + Pending, + Unsupported, + Waiting, +} +impl std::fmt::Display for GatewayClassConditionReason { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} +#[derive(Debug, PartialEq, Eq)] +pub enum GatewayConditionType { + Programmed, + Accepted, + Ready, +} +impl std::fmt::Display for GatewayConditionType { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} +#[derive(Debug, PartialEq, Eq)] +pub enum GatewayConditionReason { + Programmed, + Invalid, + NoResources, + AddressNotAssigned, + AddressNotUsable, + Accepted, + ListenersNotValid, + Pending, + UnsupportedAddress, + InvalidParameters, + Ready, + ListenersNotReady, +} +impl std::fmt::Display for GatewayConditionReason { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} +#[derive(Debug, PartialEq, Eq)] +pub enum ListenerConditionType { + Conflicted, + Accepted, + ResolvedRefs, + Programmed, + Ready, +} +impl std::fmt::Display for ListenerConditionType { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} +#[derive(Debug, PartialEq, Eq)] +pub enum ListenerConditionReason { + HostnameConflict, + ProtocolConflict, + NoConflicts, + Accepted, + PortUnavailable, + UnsupportedProtocol, + ResolvedRefs, + InvalidCertificateRef, + InvalidRouteKinds, + RefNotPermitted, + Programmed, + Invalid, + Pending, + Ready, +} +impl std::fmt::Display for ListenerConditionReason { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} diff --git a/gateway-api/src/apis/processed/enum_defaults.rs b/gateway-api/src/apis/processed/enum_defaults.rs new file mode 100644 index 0000000..1fee271 --- /dev/null +++ b/gateway-api/src/apis/processed/enum_defaults.rs @@ -0,0 +1,50 @@ +// WARNING! generated file do not edit + +use super::httproutes::{ + HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType, + HTTPRouteRulesBackendRefsFiltersType, + HTTPRouteRulesBackendRefsFiltersUrlRewritePathType, + HTTPRouteRulesFiltersRequestRedirectPathType, HTTPRouteRulesFiltersType, + HTTPRouteRulesFiltersUrlRewritePathType, +}; +use super::grpcroutes::{GRPCRouteRulesBackendRefsFiltersType, GRPCRouteRulesFiltersType}; +impl Default for GRPCRouteRulesBackendRefsFiltersType { + fn default() -> Self { + GRPCRouteRulesBackendRefsFiltersType::RequestHeaderModifier + } +} +impl Default for GRPCRouteRulesFiltersType { + fn default() -> Self { + GRPCRouteRulesFiltersType::RequestHeaderModifier + } +} +impl Default for HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType { + fn default() -> Self { + HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType::ReplaceFullPath + } +} +impl Default for HTTPRouteRulesBackendRefsFiltersType { + fn default() -> Self { + HTTPRouteRulesBackendRefsFiltersType::RequestHeaderModifier + } +} +impl Default for HTTPRouteRulesBackendRefsFiltersUrlRewritePathType { + fn default() -> Self { + HTTPRouteRulesBackendRefsFiltersUrlRewritePathType::ReplaceFullPath + } +} +impl Default for HTTPRouteRulesFiltersRequestRedirectPathType { + fn default() -> Self { + HTTPRouteRulesFiltersRequestRedirectPathType::ReplaceFullPath + } +} +impl Default for HTTPRouteRulesFiltersType { + fn default() -> Self { + HTTPRouteRulesFiltersType::RequestHeaderModifier + } +} +impl Default for HTTPRouteRulesFiltersUrlRewritePathType { + fn default() -> Self { + HTTPRouteRulesFiltersUrlRewritePathType::ReplaceFullPath + } +} diff --git a/gateway-api/src/apis/processed/gatewayclasses.rs b/gateway-api/src/apis/processed/gatewayclasses.rs new file mode 100644 index 0000000..7efa74c --- /dev/null +++ b/gateway-api/src/apis/processed/gatewayclasses.rs @@ -0,0 +1,111 @@ +// WARNING! generated file do not edit + +#[allow(unused_imports)] +mod prelude { + pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; + pub use kube::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Deserialize, Serialize}; +} +use self::prelude::*; +/// Spec defines the desired state of GatewayClass. +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] +#[kube( + group = "gateway.networking.k8s.io", + version = "v1", + kind = "GatewayClass", + plural = "gatewayclasses" +)] +#[kube(status = "GatewayClassStatus")] +#[kube(derive = "Default")] +#[kube(derive = "PartialEq")] +pub struct GatewayClassSpec { + /// ControllerName is the name of the controller that is managing Gateways of + /// this class. The value of this field MUST be a domain prefixed path. + /// + /// Example: "example.net/gateway-controller". + /// + /// This field is not mutable and cannot be empty. + /// + /// Support: Core + #[serde(rename = "controllerName")] + pub controller_name: String, + /// Description helps describe a GatewayClass with more details. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub description: Option, + /// ParametersRef is a reference to a resource that contains the configuration + /// parameters corresponding to the GatewayClass. This is optional if the + /// controller does not require any additional configuration. + /// + /// ParametersRef can reference a standard Kubernetes resource, i.e. ConfigMap, + /// or an implementation-specific custom resource. The resource can be + /// cluster-scoped or namespace-scoped. + /// + /// If the referent cannot be found, refers to an unsupported kind, or when + /// the data within that resource is malformed, the GatewayClass SHOULD be + /// rejected with the "Accepted" status condition set to "False" and an + /// "InvalidParameters" reason. + /// + /// A Gateway for this GatewayClass may provide its own `parametersRef`. When both are specified, + /// the merging behavior is implementation specific. + /// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. + /// + /// Support: Implementation-specific + #[serde(default, skip_serializing_if = "Option::is_none", rename = "parametersRef")] + pub parameters_ref: Option, +} +/// ParametersRef is a reference to a resource that contains the configuration +/// parameters corresponding to the GatewayClass. This is optional if the +/// controller does not require any additional configuration. +/// +/// ParametersRef can reference a standard Kubernetes resource, i.e. ConfigMap, +/// or an implementation-specific custom resource. The resource can be +/// cluster-scoped or namespace-scoped. +/// +/// If the referent cannot be found, refers to an unsupported kind, or when +/// the data within that resource is malformed, the GatewayClass SHOULD be +/// rejected with the "Accepted" status condition set to "False" and an +/// "InvalidParameters" reason. +/// +/// A Gateway for this GatewayClass may provide its own `parametersRef`. When both are specified, +/// the merging behavior is implementation specific. +/// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. +/// +/// Support: Implementation-specific +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayClassParametersRef { + /// Group is the group of the referent. + pub group: String, + /// Kind is kind of the referent. + pub kind: String, + /// Name is the name of the referent. + pub name: String, + /// Namespace is the namespace of the referent. + /// This field is required when referring to a Namespace-scoped resource and + /// MUST be unset when referring to a Cluster-scoped resource. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, +} +/// Status defines the current state of GatewayClass. +/// +/// Implementations MUST populate status on all GatewayClass resources which +/// specify their controller name. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayClassStatus { + /// Conditions is the current status from the controller for + /// this GatewayClass. + /// + /// Controllers should prefer to publish conditions using values + /// of GatewayClassConditionType for the type of each Condition. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub conditions: Option>, +} diff --git a/gateway-api/src/apis/processed/gateways.rs b/gateway-api/src/apis/processed/gateways.rs new file mode 100644 index 0000000..eb51a9d --- /dev/null +++ b/gateway-api/src/apis/processed/gateways.rs @@ -0,0 +1,644 @@ +// WARNING! generated file do not edit + +use super::common_types::*; +#[allow(unused_imports)] +mod prelude { + pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; + pub use kube::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Deserialize, Serialize}; + pub use std::collections::BTreeMap; +} +use self::prelude::*; +/// Spec defines the desired state of Gateway. +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] +#[kube( + group = "gateway.networking.k8s.io", + version = "v1", + kind = "Gateway", + plural = "gateways" +)] +#[kube(namespaced)] +#[kube(status = "GatewayStatus")] +#[kube(derive = "Default")] +#[kube(derive = "PartialEq")] +pub struct GatewaySpec { + /// Addresses requested for this Gateway. This is optional and behavior can + /// depend on the implementation. If a value is set in the spec and the + /// requested address is invalid or unavailable, the implementation MUST + /// indicate this in the associated entry in GatewayStatus.Addresses. + /// + /// The Addresses field represents a request for the address(es) on the + /// "outside of the Gateway", that traffic bound for this Gateway will use. + /// This could be the IP address or hostname of an external load balancer or + /// other networking infrastructure, or some other address that traffic will + /// be sent to. + /// + /// If no Addresses are specified, the implementation MAY schedule the + /// Gateway in an implementation-specific manner, assigning an appropriate + /// set of Addresses. + /// + /// The implementation MUST bind all Listeners to every GatewayAddress that + /// it assigns to the Gateway and add a corresponding entry in + /// GatewayStatus.Addresses. + /// + /// Support: Extended + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none")] + pub addresses: Option>, + /// GatewayClassName used for this Gateway. This is the name of a + /// GatewayClass resource. + #[serde(rename = "gatewayClassName")] + pub gateway_class_name: String, + /// Infrastructure defines infrastructure level attributes about this Gateway instance. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub infrastructure: Option, + /// Listeners associated with this Gateway. Listeners define + /// logical endpoints that are bound on this Gateway's addresses. + /// At least one Listener MUST be specified. + /// + /// Each Listener in a set of Listeners (for example, in a single Gateway) + /// MUST be _distinct_, in that a traffic flow MUST be able to be assigned to + /// exactly one listener. (This section uses "set of Listeners" rather than + /// "Listeners in a single Gateway" because implementations MAY merge configuration + /// from multiple Gateways onto a single data plane, and these rules _also_ + /// apply in that case). + /// + /// Practically, this means that each listener in a set MUST have a unique + /// combination of Port, Protocol, and, if supported by the protocol, Hostname. + /// + /// Some combinations of port, protocol, and TLS settings are considered + /// Core support and MUST be supported by implementations based on their + /// targeted conformance profile: + /// + /// HTTP Profile + /// + /// 1. HTTPRoute, Port: 80, Protocol: HTTP + /// 2. HTTPRoute, Port: 443, Protocol: HTTPS, TLS Mode: Terminate, TLS keypair provided + /// + /// TLS Profile + /// + /// 1. TLSRoute, Port: 443, Protocol: TLS, TLS Mode: Passthrough + /// + /// "Distinct" Listeners have the following property: + /// + /// The implementation can match inbound requests to a single distinct + /// Listener. When multiple Listeners share values for fields (for + /// example, two Listeners with the same Port value), the implementation + /// can match requests to only one of the Listeners using other + /// Listener fields. + /// + /// For example, the following Listener scenarios are distinct: + /// + /// 1. Multiple Listeners with the same Port that all use the "HTTP" + /// Protocol that all have unique Hostname values. + /// 2. Multiple Listeners with the same Port that use either the "HTTPS" or + /// "TLS" Protocol that all have unique Hostname values. + /// 3. A mixture of "TCP" and "UDP" Protocol Listeners, where no Listener + /// with the same Protocol has the same Port value. + /// + /// Some fields in the Listener struct have possible values that affect + /// whether the Listener is distinct. Hostname is particularly relevant + /// for HTTP or HTTPS protocols. + /// + /// When using the Hostname value to select between same-Port, same-Protocol + /// Listeners, the Hostname value must be different on each Listener for the + /// Listener to be distinct. + /// + /// When the Listeners are distinct based on Hostname, inbound request + /// hostnames MUST match from the most specific to least specific Hostname + /// values to choose the correct Listener and its associated set of Routes. + /// + /// Exact matches must be processed before wildcard matches, and wildcard + /// matches must be processed before fallback (empty Hostname value) + /// matches. For example, `"foo.example.com"` takes precedence over + /// `"*.example.com"`, and `"*.example.com"` takes precedence over `""`. + /// + /// Additionally, if there are multiple wildcard entries, more specific + /// wildcard entries must be processed before less specific wildcard entries. + /// For example, `"*.foo.example.com"` takes precedence over `"*.example.com"`. + /// The precise definition here is that the higher the number of dots in the + /// hostname to the right of the wildcard character, the higher the precedence. + /// + /// The wildcard character will match any number of characters _and dots_ to + /// the left, however, so `"*.example.com"` will match both + /// `"foo.bar.example.com"` _and_ `"bar.example.com"`. + /// + /// If a set of Listeners contains Listeners that are not distinct, then those + /// Listeners are Conflicted, and the implementation MUST set the "Conflicted" + /// condition in the Listener Status to "True". + /// + /// Implementations MAY choose to accept a Gateway with some Conflicted + /// Listeners only if they only accept the partial Listener set that contains + /// no Conflicted Listeners. To put this another way, implementations may + /// accept a partial Listener set only if they throw out *all* the conflicting + /// Listeners. No picking one of the conflicting listeners as the winner. + /// This also means that the Gateway must have at least one non-conflicting + /// Listener in this case, otherwise it violates the requirement that at + /// least one Listener must be present. + /// + /// The implementation MUST set a "ListenersNotValid" condition on the + /// Gateway Status when the Gateway contains Conflicted Listeners whether or + /// not they accept the Gateway. That Condition SHOULD clearly + /// indicate in the Message which Listeners are conflicted, and which are + /// Accepted. Additionally, the Listener status for those listeners SHOULD + /// indicate which Listeners are conflicted and not Accepted. + /// + /// A Gateway's Listeners are considered "compatible" if: + /// + /// 1. They are distinct. + /// 2. The implementation can serve them in compliance with the Addresses + /// requirement that all Listeners are available on all assigned + /// addresses. + /// + /// Compatible combinations in Extended support are expected to vary across + /// implementations. A combination that is compatible for one implementation + /// may not be compatible for another. + /// + /// For example, an implementation that cannot serve both TCP and UDP listeners + /// on the same address, or cannot mix HTTPS and generic TLS listens on the same port + /// would not consider those cases compatible, even though they are distinct. + /// + /// Note that requests SHOULD match at most one Listener. For example, if + /// Listeners are defined for "foo.example.com" and "*.example.com", a + /// request to "foo.example.com" SHOULD only be routed using routes attached + /// to the "foo.example.com" Listener (and not the "*.example.com" Listener). + /// This concept is known as "Listener Isolation". Implementations that do + /// not support Listener Isolation MUST clearly document this. + /// + /// Implementations MAY merge separate Gateways onto a single set of + /// Addresses if all Listeners across all Gateways are compatible. + /// + /// Support: Core + pub listeners: Vec, +} +/// Infrastructure defines infrastructure level attributes about this Gateway instance. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayInfrastructure { + /// Annotations that SHOULD be applied to any resources created in response to this Gateway. + /// + /// For implementations creating other Kubernetes objects, this should be the `metadata.annotations` field on resources. + /// For other implementations, this refers to any relevant (implementation specific) "annotations" concepts. + /// + /// An implementation may chose to add additional implementation-specific annotations as they see fit. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub annotations: Option>, + /// Labels that SHOULD be applied to any resources created in response to this Gateway. + /// + /// For implementations creating other Kubernetes objects, this should be the `metadata.labels` field on resources. + /// For other implementations, this refers to any relevant (implementation specific) "labels" concepts. + /// + /// An implementation may chose to add additional implementation-specific labels as they see fit. + /// + /// If an implementation maps these labels to Pods, or any other resource that would need to be recreated when labels + /// change, it SHOULD clearly warn about this behavior in documentation. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub labels: Option>, + /// ParametersRef is a reference to a resource that contains the configuration + /// parameters corresponding to the Gateway. This is optional if the + /// controller does not require any additional configuration. + /// + /// This follows the same semantics as GatewayClass's `parametersRef`, but on a per-Gateway basis + /// + /// The Gateway's GatewayClass may provide its own `parametersRef`. When both are specified, + /// the merging behavior is implementation specific. + /// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. + /// + /// Support: Implementation-specific + #[serde(default, skip_serializing_if = "Option::is_none", rename = "parametersRef")] + pub parameters_ref: Option, +} +/// ParametersRef is a reference to a resource that contains the configuration +/// parameters corresponding to the Gateway. This is optional if the +/// controller does not require any additional configuration. +/// +/// This follows the same semantics as GatewayClass's `parametersRef`, but on a per-Gateway basis +/// +/// The Gateway's GatewayClass may provide its own `parametersRef`. When both are specified, +/// the merging behavior is implementation specific. +/// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. +/// +/// Support: Implementation-specific +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayInfrastructureParametersRef { + /// Group is the group of the referent. + pub group: String, + /// Kind is kind of the referent. + pub kind: String, + /// Name is the name of the referent. + pub name: String, +} +/// Listener embodies the concept of a logical endpoint where a Gateway accepts +/// network connections. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayListeners { + /// AllowedRoutes defines the types of routes that MAY be attached to a + /// Listener and the trusted namespaces where those Route resources MAY be + /// present. + /// + /// Although a client request may match multiple route rules, only one rule + /// may ultimately receive the request. Matching precedence MUST be + /// determined in order of the following criteria: + /// + /// * The most specific match as defined by the Route type. + /// * The oldest Route based on creation timestamp. For example, a Route with + /// a creation timestamp of "2020-09-08 01:02:03" is given precedence over + /// a Route with a creation timestamp of "2020-09-08 01:02:04". + /// * If everything else is equivalent, the Route appearing first in + /// alphabetical order (namespace/name) should be given precedence. For + /// example, foo/bar is given precedence over foo/baz. + /// + /// All valid rules within a Route attached to this Listener should be + /// implemented. Invalid Route rules can be ignored (sometimes that will mean + /// the full Route). If a Route rule transitions from valid to invalid, + /// support for that Route rule should be dropped to ensure consistency. For + /// example, even if a filter specified by a Route rule is invalid, the rest + /// of the rules within that Route should still be supported. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none", rename = "allowedRoutes")] + pub allowed_routes: Option, + /// Hostname specifies the virtual hostname to match for protocol types that + /// define this concept. When unspecified, all hostnames are matched. This + /// field is ignored for protocols that don't require hostname based + /// matching. + /// + /// Implementations MUST apply Hostname matching appropriately for each of + /// the following protocols: + /// + /// * TLS: The Listener Hostname MUST match the SNI. + /// * HTTP: The Listener Hostname MUST match the Host header of the request. + /// * HTTPS: The Listener Hostname SHOULD match at both the TLS and HTTP + /// protocol layers as described above. If an implementation does not + /// ensure that both the SNI and Host header match the Listener hostname, + /// it MUST clearly document that. + /// + /// For HTTPRoute and TLSRoute resources, there is an interaction with the + /// `spec.hostnames` array. When both listener and route specify hostnames, + /// there MUST be an intersection between the values for a Route to be + /// accepted. For more information, refer to the Route specific Hostnames + /// documentation. + /// + /// Hostnames that are prefixed with a wildcard label (`*.`) are interpreted + /// as a suffix match. That means that a match for `*.example.com` would match + /// both `test.example.com`, and `foo.test.example.com`, but not `example.com`. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + /// Name is the name of the Listener. This name MUST be unique within a + /// Gateway. + /// + /// Support: Core + pub name: String, + /// Port is the network port. Multiple listeners may use the + /// same port, subject to the Listener compatibility rules. + /// + /// Support: Core + pub port: i32, + /// Protocol specifies the network protocol this listener expects to receive. + /// + /// Support: Core + pub protocol: String, + /// TLS is the TLS configuration for the Listener. This field is required if + /// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field + /// if the Protocol field is "HTTP", "TCP", or "UDP". + /// + /// The association of SNIs to Certificate defined in GatewayTLSConfig is + /// defined based on the Hostname field for this listener. + /// + /// The GatewayClass MUST use the longest matching SNI out of all + /// available certificates for any TLS handshake. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub tls: Option, +} +/// AllowedRoutes defines the types of routes that MAY be attached to a +/// Listener and the trusted namespaces where those Route resources MAY be +/// present. +/// +/// Although a client request may match multiple route rules, only one rule +/// may ultimately receive the request. Matching precedence MUST be +/// determined in order of the following criteria: +/// +/// * The most specific match as defined by the Route type. +/// * The oldest Route based on creation timestamp. For example, a Route with +/// a creation timestamp of "2020-09-08 01:02:03" is given precedence over +/// a Route with a creation timestamp of "2020-09-08 01:02:04". +/// * If everything else is equivalent, the Route appearing first in +/// alphabetical order (namespace/name) should be given precedence. For +/// example, foo/bar is given precedence over foo/baz. +/// +/// All valid rules within a Route attached to this Listener should be +/// implemented. Invalid Route rules can be ignored (sometimes that will mean +/// the full Route). If a Route rule transitions from valid to invalid, +/// support for that Route rule should be dropped to ensure consistency. For +/// example, even if a filter specified by a Route rule is invalid, the rest +/// of the rules within that Route should still be supported. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayListenersAllowedRoutes { + /// Kinds specifies the groups and kinds of Routes that are allowed to bind + /// to this Gateway Listener. When unspecified or empty, the kinds of Routes + /// selected are determined using the Listener protocol. + /// + /// A RouteGroupKind MUST correspond to kinds of Routes that are compatible + /// with the application protocol specified in the Listener's Protocol field. + /// If an implementation does not support or recognize this resource type, it + /// MUST set the "ResolvedRefs" condition to False for this Listener with the + /// "InvalidRouteKinds" reason. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kinds: Option>, + /// Namespaces indicates namespaces from which Routes may be attached to this + /// Listener. This is restricted to the namespace of this Gateway by default. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespaces: Option, +} +/// Namespaces indicates namespaces from which Routes may be attached to this +/// Listener. This is restricted to the namespace of this Gateway by default. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayListenersAllowedRoutesNamespaces { + /// From indicates where Routes will be selected for this Gateway. Possible + /// values are: + /// + /// * All: Routes in all namespaces may be used by this Gateway. + /// * Selector: Routes in namespaces selected by the selector may be used by + /// this Gateway. + /// * Same: Only Routes in the same namespace may be used by this Gateway. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub from: Option, + /// Selector must be specified when From is set to "Selector". In that case, + /// only Routes in Namespaces matching this Selector will be selected by this + /// Gateway. This field is ignored for other values of "From". + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub selector: Option, +} +/// Namespaces indicates namespaces from which Routes may be attached to this +/// Listener. This is restricted to the namespace of this Gateway by default. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum GatewayListenersAllowedRoutesNamespacesFrom { + All, + Selector, + Same, +} +/// Selector must be specified when From is set to "Selector". In that case, +/// only Routes in Namespaces matching this Selector will be selected by this +/// Gateway. This field is ignored for other values of "From". +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayListenersAllowedRoutesNamespacesSelector { + /// matchExpressions is a list of label selector requirements. The requirements are ANDed. + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "matchExpressions" + )] + pub match_expressions: Option< + Vec, + >, + /// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + /// map is equivalent to an element of matchExpressions, whose key field is "key", the + /// operator is "In", and the values array contains only "value". The requirements are ANDed. + #[serde(default, skip_serializing_if = "Option::is_none", rename = "matchLabels")] + pub match_labels: Option>, +} +/// A label selector requirement is a selector that contains values, a key, and an operator that +/// relates the key and values. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayListenersAllowedRoutesNamespacesSelectorMatchExpressions { + /// key is the label key that the selector applies to. + pub key: String, + /// operator represents a key's relationship to a set of values. + /// Valid operators are In, NotIn, Exists and DoesNotExist. + pub operator: String, + /// values is an array of string values. If the operator is In or NotIn, + /// the values array must be non-empty. If the operator is Exists or DoesNotExist, + /// the values array must be empty. This array is replaced during a strategic + /// merge patch. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub values: Option>, +} +/// TLS is the TLS configuration for the Listener. This field is required if +/// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field +/// if the Protocol field is "HTTP", "TCP", or "UDP". +/// +/// The association of SNIs to Certificate defined in GatewayTLSConfig is +/// defined based on the Hostname field for this listener. +/// +/// The GatewayClass MUST use the longest matching SNI out of all +/// available certificates for any TLS handshake. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayListenersTls { + /// CertificateRefs contains a series of references to Kubernetes objects that + /// contains TLS certificates and private keys. These certificates are used to + /// establish a TLS handshake for requests that match the hostname of the + /// associated listener. + /// + /// A single CertificateRef to a Kubernetes Secret has "Core" support. + /// Implementations MAY choose to support attaching multiple certificates to + /// a Listener, but this behavior is implementation-specific. + /// + /// References to a resource in different namespace are invalid UNLESS there + /// is a ReferenceGrant in the target namespace that allows the certificate + /// to be attached. If a ReferenceGrant does not allow this reference, the + /// "ResolvedRefs" condition MUST be set to False for this listener with the + /// "RefNotPermitted" reason. + /// + /// This field is required to have at least one element when the mode is set + /// to "Terminate" (default) and is optional otherwise. + /// + /// CertificateRefs can reference to standard Kubernetes resources, i.e. + /// Secret, or implementation-specific custom resources. + /// + /// Support: Core - A single reference to a Kubernetes Secret of type kubernetes.io/tls + /// + /// Support: Implementation-specific (More than one reference or other resource types) + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "certificateRefs" + )] + pub certificate_refs: Option>, + /// Mode defines the TLS behavior for the TLS session initiated by the client. + /// There are two possible modes: + /// + /// - Terminate: The TLS session between the downstream client and the + /// Gateway is terminated at the Gateway. This mode requires certificates + /// to be specified in some way, such as populating the certificateRefs + /// field. + /// - Passthrough: The TLS session is NOT terminated by the Gateway. This + /// implies that the Gateway can't decipher the TLS stream except for + /// the ClientHello message of the TLS protocol. The certificateRefs field + /// is ignored in this mode. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub mode: Option, + /// Options are a list of key/value pairs to enable extended TLS + /// configuration for each implementation. For example, configuring the + /// minimum TLS version or supported cipher suites. + /// + /// A set of common keys MAY be defined by the API in the future. To avoid + /// any ambiguity, implementation-specific definitions MUST use + /// domain-prefixed names, such as `example.com/my-custom-option`. + /// Un-prefixed names are reserved for key names defined by Gateway API. + /// + /// Support: Implementation-specific + #[serde(default, skip_serializing_if = "Option::is_none")] + pub options: Option>, +} +/// SecretObjectReference identifies an API object including its namespace, +/// defaulting to Secret. +/// +/// The API object must be valid in the cluster; the Group and Kind must +/// be registered in the cluster for this reference to be valid. +/// +/// References to objects with invalid Group and Kind are not valid, and must +/// be rejected by the implementation, with appropriate Conditions set +/// on the containing object. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayListenersTlsCertificateRefs { + /// Group is the group of the referent. For example, "gateway.networking.k8s.io". + /// When unspecified or empty string, core API group is inferred. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + /// Kind is kind of the referent. For example "Secret". + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + /// Name is the name of the referent. + pub name: String, + /// Namespace is the namespace of the referenced object. When unspecified, the local + /// namespace is inferred. + /// + /// Note that when a namespace different than the local namespace is specified, + /// a ReferenceGrant object is required in the referent namespace to allow that + /// namespace's owner to accept the reference. See the ReferenceGrant + /// documentation for details. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, +} +/// TLS is the TLS configuration for the Listener. This field is required if +/// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field +/// if the Protocol field is "HTTP", "TCP", or "UDP". +/// +/// The association of SNIs to Certificate defined in GatewayTLSConfig is +/// defined based on the Hostname field for this listener. +/// +/// The GatewayClass MUST use the longest matching SNI out of all +/// available certificates for any TLS handshake. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum GatewayListenersTlsMode { + Terminate, + Passthrough, +} +/// Status defines the current state of Gateway. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayStatus { + /// Addresses lists the network addresses that have been bound to the + /// Gateway. + /// + /// This list may differ from the addresses provided in the spec under some + /// conditions: + /// + /// * no addresses are specified, all addresses are dynamically assigned + /// * a combination of specified and dynamic addresses are assigned + /// * a specified address was unusable (e.g. already in use) + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none")] + pub addresses: Option>, + /// Conditions describe the current conditions of the Gateway. + /// + /// Implementations should prefer to express Gateway conditions + /// using the `GatewayConditionType` and `GatewayConditionReason` + /// constants so that operators and tools can converge on a common + /// vocabulary to describe Gateway state. + /// + /// Known condition types are: + /// + /// * "Accepted" + /// * "Programmed" + /// * "Ready" + #[serde(default, skip_serializing_if = "Option::is_none")] + pub conditions: Option>, + /// Listeners provide status for each unique listener port defined in the Spec. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub listeners: Option>, +} +/// ListenerStatus is the status associated with a Listener. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayStatusListeners { + /// AttachedRoutes represents the total number of Routes that have been + /// successfully attached to this Listener. + /// + /// Successful attachment of a Route to a Listener is based solely on the + /// combination of the AllowedRoutes field on the corresponding Listener + /// and the Route's ParentRefs field. A Route is successfully attached to + /// a Listener when it is selected by the Listener's AllowedRoutes field + /// AND the Route has a valid ParentRef selecting the whole Gateway + /// resource or a specific Listener as a parent resource (more detail on + /// attachment semantics can be found in the documentation on the various + /// Route kinds ParentRefs fields). Listener or Route status does not impact + /// successful attachment, i.e. the AttachedRoutes field count MUST be set + /// for Listeners with condition Accepted: false and MUST count successfully + /// attached Routes that may themselves have Accepted: false conditions. + /// + /// Uses for this field include troubleshooting Route attachment and + /// measuring blast radius/impact of changes to a Listener. + #[serde(rename = "attachedRoutes")] + pub attached_routes: i32, + /// Conditions describe the current condition of this listener. + pub conditions: Vec, + /// Name is the name of the Listener that this status corresponds to. + pub name: String, + /// SupportedKinds is the list indicating the Kinds supported by this + /// listener. This MUST represent the kinds an implementation supports for + /// that Listener configuration. + /// + /// If kinds are specified in Spec that are not supported, they MUST NOT + /// appear in this list and an implementation MUST set the "ResolvedRefs" + /// condition to "False" with the "InvalidRouteKinds" reason. If both valid + /// and invalid Route kinds are specified, the implementation MUST + /// reference the valid Route kinds that have been specified. + #[serde(rename = "supportedKinds")] + pub supported_kinds: Vec, +} diff --git a/gateway-api/src/apis/processed/grpcroutes.rs b/gateway-api/src/apis/processed/grpcroutes.rs new file mode 100644 index 0000000..8c517f8 --- /dev/null +++ b/gateway-api/src/apis/processed/grpcroutes.rs @@ -0,0 +1,688 @@ +// WARNING! generated file do not edit + +use super::common_types::*; +#[allow(unused_imports)] +mod prelude { + pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; + pub use kube::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Deserialize, Serialize}; +} +use self::prelude::*; +/// Spec defines the desired state of GRPCRoute. +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] +#[kube( + group = "gateway.networking.k8s.io", + version = "v1", + kind = "GRPCRoute", + plural = "grpcroutes" +)] +#[kube(namespaced)] +#[kube(status = "GRPCRouteStatus")] +#[kube(derive = "Default")] +#[kube(derive = "PartialEq")] +pub struct GRPCRouteSpec { + /// Hostnames defines a set of hostnames to match against the GRPC + /// Host header to select a GRPCRoute to process the request. This matches + /// the RFC 1123 definition of a hostname with 2 notable exceptions: + /// + /// 1. IPs are not allowed. + /// 2. A hostname may be prefixed with a wildcard label (`*.`). The wildcard + /// label MUST appear by itself as the first label. + /// + /// If a hostname is specified by both the Listener and GRPCRoute, there + /// MUST be at least one intersecting hostname for the GRPCRoute to be + /// attached to the Listener. For example: + /// + /// * A Listener with `test.example.com` as the hostname matches GRPCRoutes + /// that have either not specified any hostnames, or have specified at + /// least one of `test.example.com` or `*.example.com`. + /// * A Listener with `*.example.com` as the hostname matches GRPCRoutes + /// that have either not specified any hostnames or have specified at least + /// one hostname that matches the Listener hostname. For example, + /// `test.example.com` and `*.example.com` would both match. On the other + /// hand, `example.com` and `test.example.net` would not match. + /// + /// Hostnames that are prefixed with a wildcard label (`*.`) are interpreted + /// as a suffix match. That means that a match for `*.example.com` would match + /// both `test.example.com`, and `foo.test.example.com`, but not `example.com`. + /// + /// If both the Listener and GRPCRoute have specified hostnames, any + /// GRPCRoute hostnames that do not match the Listener hostname MUST be + /// ignored. For example, if a Listener specified `*.example.com`, and the + /// GRPCRoute specified `test.example.com` and `test.example.net`, + /// `test.example.net` MUST NOT be considered for a match. + /// + /// If both the Listener and GRPCRoute have specified hostnames, and none + /// match with the criteria above, then the GRPCRoute MUST NOT be accepted by + /// the implementation. The implementation MUST raise an 'Accepted' Condition + /// with a status of `False` in the corresponding RouteParentStatus. + /// + /// If a Route (A) of type HTTPRoute or GRPCRoute is attached to a + /// Listener and that listener already has another Route (B) of the other + /// type attached and the intersection of the hostnames of A and B is + /// non-empty, then the implementation MUST accept exactly one of these two + /// routes, determined by the following criteria, in order: + /// + /// * The oldest Route based on creation timestamp. + /// * The Route appearing first in alphabetical order by + /// "{namespace}/{name}". + /// + /// The rejected Route MUST raise an 'Accepted' condition with a status of + /// 'False' in the corresponding RouteParentStatus. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostnames: Option>, + /// ParentRefs references the resources (usually Gateways) that a Route wants + /// to be attached to. Note that the referenced parent resource needs to + /// allow this for the attachment to be complete. For Gateways, that means + /// the Gateway needs to allow attachment from Routes of this kind and + /// namespace. For Services, that means the Service must either be in the same + /// namespace for a "producer" route, or the mesh implementation must support + /// and allow "consumer" routes for the referenced Service. ReferenceGrant is + /// not applicable for governing ParentRefs to Services - it is not possible to + /// create a "producer" route for a Service in a different namespace from the + /// Route. + /// + /// There are two kinds of parent resources with "Core" support: + /// + /// * Gateway (Gateway conformance profile) + /// * Service (Mesh conformance profile, ClusterIP Services only) + /// + /// This API may be extended in the future to support additional kinds of parent + /// resources. + /// + /// ParentRefs must be _distinct_. This means either that: + /// + /// * They select different objects. If this is the case, then parentRef + /// entries are distinct. In terms of fields, this means that the + /// multi-part key defined by `group`, `kind`, `namespace`, and `name` must + /// be unique across all parentRef entries in the Route. + /// * They do not select different objects, but for each optional field used, + /// each ParentRef that selects the same object must set the same set of + /// optional fields to different values. If one ParentRef sets a + /// combination of optional fields, all must set the same combination. + /// + /// Some examples: + /// + /// * If one ParentRef sets `sectionName`, all ParentRefs referencing the + /// same object must also set `sectionName`. + /// * If one ParentRef sets `port`, all ParentRefs referencing the same + /// object must also set `port`. + /// * If one ParentRef sets `sectionName` and `port`, all ParentRefs + /// referencing the same object must also set `sectionName` and `port`. + /// + /// It is possible to separately reference multiple distinct objects that may + /// be collapsed by an implementation. For example, some implementations may + /// choose to merge compatible Gateway Listeners together. If that is the + /// case, the list of routes attached to those resources should also be + /// merged. + /// + /// Note that for ParentRefs that cross namespace boundaries, there are specific + /// rules. Cross-namespace references are only valid if they are explicitly + /// allowed by something in the namespace they are referring to. For example, + /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a + /// generic way to enable other kinds of cross-namespace reference. + /// + /// + /// + /// + /// + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none", rename = "parentRefs")] + pub parent_refs: Option>, + /// Rules are a list of GRPC matchers, filters and actions. + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none")] + pub rules: Option>, +} +/// GRPCRouteRule defines the semantics for matching a gRPC request based on +/// conditions (matches), processing it (filters), and forwarding the request to +/// an API object (backendRefs). +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteRules { + /// BackendRefs defines the backend(s) where matching requests should be + /// sent. + /// + /// Failure behavior here depends on how many BackendRefs are specified and + /// how many are invalid. + /// + /// If *all* entries in BackendRefs are invalid, and there are also no filters + /// specified in this route rule, *all* traffic which matches this rule MUST + /// receive an `UNAVAILABLE` status. + /// + /// See the GRPCBackendRef definition for the rules about what makes a single + /// GRPCBackendRef invalid. + /// + /// When a GRPCBackendRef is invalid, `UNAVAILABLE` statuses MUST be returned for + /// requests that would have otherwise been routed to an invalid backend. If + /// multiple backends are specified, and some are invalid, the proportion of + /// requests that would otherwise have been routed to an invalid backend + /// MUST receive an `UNAVAILABLE` status. + /// + /// For example, if two backends are specified with equal weights, and one is + /// invalid, 50 percent of traffic MUST receive an `UNAVAILABLE` status. + /// Implementations may choose how that 50 percent is determined. + /// + /// Support: Core for Kubernetes Service + /// + /// Support: Implementation-specific for any other resource + /// + /// Support for weight: Core + #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRefs")] + pub backend_refs: Option>, + /// Filters define the filters that are applied to requests that match + /// this rule. + /// + /// The effects of ordering of multiple behaviors are currently unspecified. + /// This can change in the future based on feedback during the alpha stage. + /// + /// Conformance-levels at this level are defined based on the type of filter: + /// + /// - ALL core filters MUST be supported by all implementations that support + /// GRPCRoute. + /// - Implementers are encouraged to support extended filters. + /// - Implementation-specific custom filters have no API guarantees across + /// implementations. + /// + /// Specifying the same filter multiple times is not supported unless explicitly + /// indicated in the filter. + /// + /// If an implementation can not support a combination of filters, it must clearly + /// document that limitation. In cases where incompatible or unsupported + /// filters are specified and cause the `Accepted` condition to be set to status + /// `False`, implementations may use the `IncompatibleFilters` reason to specify + /// this configuration error. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub filters: Option>, + /// Matches define conditions used for matching the rule against incoming + /// gRPC requests. Each match is independent, i.e. this rule will be matched + /// if **any** one of the matches is satisfied. + /// + /// For example, take the following matches configuration: + /// + /// ```text + /// matches: + /// - method: + /// service: foo.bar + /// headers: + /// values: + /// version: 2 + /// - method: + /// service: foo.bar.v2 + /// ``` + /// + /// For a request to match against this rule, it MUST satisfy + /// EITHER of the two conditions: + /// + /// - service of foo.bar AND contains the header `version: 2` + /// - service of foo.bar.v2 + /// + /// See the documentation for GRPCRouteMatch on how to specify multiple + /// match conditions to be ANDed together. + /// + /// If no matches are specified, the implementation MUST match every gRPC request. + /// + /// Proxy or Load Balancer routing configuration generated from GRPCRoutes + /// MUST prioritize rules based on the following criteria, continuing on + /// ties. Merging MUST not be done between GRPCRoutes and HTTPRoutes. + /// Precedence MUST be given to the rule with the largest number of: + /// + /// * Characters in a matching non-wildcard hostname. + /// * Characters in a matching hostname. + /// * Characters in a matching service. + /// * Characters in a matching method. + /// * Header matches. + /// + /// If ties still exist across multiple Routes, matching precedence MUST be + /// determined in order of the following criteria, continuing on ties: + /// + /// * The oldest Route based on creation timestamp. + /// * The Route appearing first in alphabetical order by + /// "{namespace}/{name}". + /// + /// If ties still exist within the Route that has been given precedence, + /// matching precedence MUST be granted to the first matching rule meeting + /// the above criteria. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub matches: Option>, +} +/// GRPCBackendRef defines how a GRPCRoute forwards a gRPC request. +/// +/// Note that when a namespace different than the local namespace is specified, a +/// ReferenceGrant object is required in the referent namespace to allow that +/// namespace's owner to accept the reference. See the ReferenceGrant +/// documentation for details. +/// +/// +/// +/// When the BackendRef points to a Kubernetes Service, implementations SHOULD +/// honor the appProtocol field if it is set for the target Service Port. +/// +/// Implementations supporting appProtocol SHOULD recognize the Kubernetes +/// Standard Application Protocols defined in KEP-3726. +/// +/// If a Service appProtocol isn't specified, an implementation MAY infer the +/// backend protocol through its own means. Implementations MAY infer the +/// protocol from the Route type referring to the backend Service. +/// +/// If a Route is not able to send traffic to the backend using the specified +/// protocol then the backend is considered invalid. Implementations MUST set the +/// "ResolvedRefs" condition to "False" with the "UnsupportedProtocol" reason. +/// +/// +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteRulesBackendRefs { + /// Filters defined at this level MUST be executed if and only if the + /// request is being forwarded to the backend defined here. + /// + /// Support: Implementation-specific (For broader support of filters, use the + /// Filters field in GRPCRouteRule.) + #[serde(default, skip_serializing_if = "Option::is_none")] + pub filters: Option>, + /// Group is the group of the referent. For example, "gateway.networking.k8s.io". + /// When unspecified or empty string, core API group is inferred. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + /// Kind is the Kubernetes resource kind of the referent. For example + /// "Service". + /// + /// Defaults to "Service" when not specified. + /// + /// ExternalName services can refer to CNAME DNS records that may live + /// outside of the cluster and as such are difficult to reason about in + /// terms of conformance. They also may not be safe to forward to (see + /// CVE-2021-25740 for more information). Implementations SHOULD NOT + /// support ExternalName Services. + /// + /// Support: Core (Services with a type other than ExternalName) + /// + /// Support: Implementation-specific (Services with type ExternalName) + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + /// Name is the name of the referent. + pub name: String, + /// Namespace is the namespace of the backend. When unspecified, the local + /// namespace is inferred. + /// + /// Note that when a namespace different than the local namespace is specified, + /// a ReferenceGrant object is required in the referent namespace to allow that + /// namespace's owner to accept the reference. See the ReferenceGrant + /// documentation for details. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, + /// Port specifies the destination port number to use for this resource. + /// Port is required when the referent is a Kubernetes Service. In this + /// case, the port number is the service port number, not the target port. + /// For other resources, destination port might be derived from the referent + /// resource or this field. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + /// Weight specifies the proportion of requests forwarded to the referenced + /// backend. This is computed as weight/(sum of all weights in this + /// BackendRefs list). For non-zero values, there may be some epsilon from + /// the exact proportion defined here depending on the precision an + /// implementation supports. Weight is not a percentage and the sum of + /// weights does not need to equal 100. + /// + /// If only one backend is specified and it has a weight greater than 0, 100% + /// of the traffic is forwarded to that backend. If weight is set to 0, no + /// traffic should be forwarded for this entry. If unspecified, weight + /// defaults to 1. + /// + /// Support for this field varies based on the context where used. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub weight: Option, +} +/// GRPCRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. GRPCRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteRulesBackendRefsFilters { + /// ExtensionRef is an optional, implementation-specific extension to the + /// "filter" behavior. For example, resource "myroutefilter" in group + /// "networking.example.net"). ExtensionRef MUST NOT be used for core and + /// extended filters. + /// + /// Support: Implementation-specific + /// + /// This filter can be used multiple times within the same rule. + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, + /// RequestHeaderModifier defines a schema for a filter that modifies request + /// headers. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + /// RequestMirror defines a schema for a filter that mirrors requests. + /// Requests are sent to the specified destination, but responses from + /// that destination are ignored. + /// + /// This filter can be used multiple times within the same rule. Note that + /// not all implementations will be able to support mirroring to multiple + /// backends. + /// + /// Support: Extended + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, + /// ResponseHeaderModifier defines a schema for a filter that modifies response + /// headers. + /// + /// Support: Extended + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + /// Type identifies the type of filter to apply. As with other API fields, + /// types are classified into three conformance levels: + /// + /// - Core: Filter types and their corresponding configuration defined by + /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All + /// implementations supporting GRPCRoute MUST support core filters. + /// + /// - Extended: Filter types and their corresponding configuration defined by + /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers + /// are encouraged to support extended filters. + /// + /// - Implementation-specific: Filters that are defined and supported by specific vendors. + /// In the future, filters showing convergence in behavior across multiple + /// implementations will be considered for inclusion in extended or core + /// conformance levels. Filter-specific configuration for such filters + /// is specified using the ExtensionRef field. `Type` MUST be set to + /// "ExtensionRef" for custom filters. + /// + /// Implementers are encouraged to define custom implementation types to + /// extend the core API with implementation-specific behavior. + /// + /// If a reference to a custom filter type cannot be resolved, the filter + /// MUST NOT be skipped. Instead, requests that would have been processed by + /// that filter MUST receive a HTTP error response. + /// + /// + #[serde(rename = "type")] + pub r#type: GRPCRouteRulesBackendRefsFiltersType, +} +/// GRPCRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. GRPCRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum GRPCRouteRulesBackendRefsFiltersType { + ResponseHeaderModifier, + RequestHeaderModifier, + RequestMirror, + ExtensionRef, +} +/// GRPCRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. GRPCRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteRulesFilters { + /// ExtensionRef is an optional, implementation-specific extension to the + /// "filter" behavior. For example, resource "myroutefilter" in group + /// "networking.example.net"). ExtensionRef MUST NOT be used for core and + /// extended filters. + /// + /// Support: Implementation-specific + /// + /// This filter can be used multiple times within the same rule. + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, + /// RequestHeaderModifier defines a schema for a filter that modifies request + /// headers. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + /// RequestMirror defines a schema for a filter that mirrors requests. + /// Requests are sent to the specified destination, but responses from + /// that destination are ignored. + /// + /// This filter can be used multiple times within the same rule. Note that + /// not all implementations will be able to support mirroring to multiple + /// backends. + /// + /// Support: Extended + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, + /// ResponseHeaderModifier defines a schema for a filter that modifies response + /// headers. + /// + /// Support: Extended + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + /// Type identifies the type of filter to apply. As with other API fields, + /// types are classified into three conformance levels: + /// + /// - Core: Filter types and their corresponding configuration defined by + /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All + /// implementations supporting GRPCRoute MUST support core filters. + /// + /// - Extended: Filter types and their corresponding configuration defined by + /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers + /// are encouraged to support extended filters. + /// + /// - Implementation-specific: Filters that are defined and supported by specific vendors. + /// In the future, filters showing convergence in behavior across multiple + /// implementations will be considered for inclusion in extended or core + /// conformance levels. Filter-specific configuration for such filters + /// is specified using the ExtensionRef field. `Type` MUST be set to + /// "ExtensionRef" for custom filters. + /// + /// Implementers are encouraged to define custom implementation types to + /// extend the core API with implementation-specific behavior. + /// + /// If a reference to a custom filter type cannot be resolved, the filter + /// MUST NOT be skipped. Instead, requests that would have been processed by + /// that filter MUST receive a HTTP error response. + /// + /// + #[serde(rename = "type")] + pub r#type: GRPCRouteRulesFiltersType, +} +/// GRPCRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. GRPCRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum GRPCRouteRulesFiltersType { + ResponseHeaderModifier, + RequestHeaderModifier, + RequestMirror, + ExtensionRef, +} +/// GRPCRouteMatch defines the predicate used to match requests to a given +/// action. Multiple match types are ANDed together, i.e. the match will +/// evaluate to true only if all conditions are satisfied. +/// +/// For example, the match below will match a gRPC request only if its service +/// is `foo` AND it contains the `version: v1` header: +/// +/// ```text +/// matches: +/// - method: +/// type: Exact +/// service: "foo" +/// headers: +/// - name: "version" +/// value "v1" +/// +/// ``` +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteRulesMatches { + /// Headers specifies gRPC request header matchers. Multiple match values are + /// ANDed together, meaning, a request MUST match all the specified headers + /// to select the route. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub headers: Option>, + /// Method specifies a gRPC request service/method matcher. If this field is + /// not specified, all services and methods will match. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub method: Option, +} +/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request +/// headers. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteRulesMatchesHeaders { + /// Name is the name of the gRPC Header to be matched. + /// + /// If multiple entries specify equivalent header names, only the first + /// entry with an equivalent name MUST be considered for a match. Subsequent + /// entries with an equivalent header name MUST be ignored. Due to the + /// case-insensitivity of header names, "foo" and "Foo" are considered + /// equivalent. + pub name: String, + /// Type specifies how to match against the value of the header. + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + /// Value is the value of the gRPC Header to be matched. + pub value: String, +} +/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request +/// headers. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum GRPCRouteRulesMatchesHeadersType { + Exact, + RegularExpression, +} +/// Method specifies a gRPC request service/method matcher. If this field is +/// not specified, all services and methods will match. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteRulesMatchesMethod { + /// Value of the method to match against. If left empty or omitted, will + /// match all services. + /// + /// At least one of Service and Method MUST be a non-empty string. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub method: Option, + /// Value of the service to match against. If left empty or omitted, will + /// match any service. + /// + /// At least one of Service and Method MUST be a non-empty string. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub service: Option, + /// Type specifies how to match against the service and/or method. + /// Support: Core (Exact with service and method specified) + /// + /// Support: Implementation-specific (Exact with method specified but no service specified) + /// + /// Support: Implementation-specific (RegularExpression) + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, +} +/// Method specifies a gRPC request service/method matcher. If this field is +/// not specified, all services and methods will match. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum GRPCRouteRulesMatchesMethodType { + Exact, + RegularExpression, +} +/// Status defines the current state of GRPCRoute. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteStatus { + /// Parents is a list of parent resources (usually Gateways) that are + /// associated with the route, and the status of the route with respect to + /// each parent. When this route attaches to a parent, the controller that + /// manages the parent must add an entry to this list when the controller + /// first sees the route and should update the entry as appropriate when the + /// route or gateway is modified. + /// + /// Note that parent references that cannot be resolved by an implementation + /// of this API will not be added to this list. Implementations of this API + /// can only populate Route status for the Gateways/parent resources they are + /// responsible for. + /// + /// A maximum of 32 Gateways will be represented in this list. An empty list + /// means the route has not been attached to any Gateway. + pub parents: Vec, +} +/// RouteParentStatus describes the status of a route with respect to an +/// associated Parent. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteStatusParents { + /// Conditions describes the status of the route with respect to the Gateway. + /// Note that the route's availability is also subject to the Gateway's own + /// status conditions and listener status. + /// + /// If the Route's ParentRef specifies an existing Gateway that supports + /// Routes of this kind AND that Gateway's controller has sufficient access, + /// then that Gateway's controller MUST set the "Accepted" condition on the + /// Route, to indicate whether the route has been accepted or rejected by the + /// Gateway, and why. + /// + /// A Route MUST be considered "Accepted" if at least one of the Route's + /// rules is implemented by the Gateway. + /// + /// There are a number of cases where the "Accepted" condition may not be set + /// due to lack of controller visibility, that includes when: + /// + /// * The Route refers to a non-existent parent. + /// * The Route is of a type that the controller does not support. + /// * The Route is in a namespace the controller does not have access to. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub conditions: Option>, + /// ControllerName is a domain/path string that indicates the name of the + /// controller that wrote this status. This corresponds with the + /// controllerName field on GatewayClass. + /// + /// Example: "example.net/gateway-controller". + /// + /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are + /// valid Kubernetes names + /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). + /// + /// Controllers MUST populate this field when writing status. Controllers should ensure that + /// entries to status populated with their ControllerName are cleaned up when they are no + /// longer necessary. + #[serde(rename = "controllerName")] + pub controller_name: String, + /// ParentRef corresponds with a ParentRef in the spec that this + /// RouteParentStatus struct describes the status of. + #[serde(rename = "parentRef")] + pub parent_ref: RouteRef, +} diff --git a/gateway-api/src/apis/processed/httproutes.rs b/gateway-api/src/apis/processed/httproutes.rs new file mode 100644 index 0000000..18944ba --- /dev/null +++ b/gateway-api/src/apis/processed/httproutes.rs @@ -0,0 +1,1376 @@ +// WARNING! generated file do not edit + +use super::common_types::*; +#[allow(unused_imports)] +mod prelude { + pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; + pub use kube::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Deserialize, Serialize}; +} +use self::prelude::*; +/// Spec defines the desired state of HTTPRoute. +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] +#[kube( + group = "gateway.networking.k8s.io", + version = "v1", + kind = "HTTPRoute", + plural = "httproutes" +)] +#[kube(namespaced)] +#[kube(status = "HTTPRouteStatus")] +#[kube(derive = "Default")] +#[kube(derive = "PartialEq")] +pub struct HTTPRouteSpec { + /// Hostnames defines a set of hostnames that should match against the HTTP Host + /// header to select a HTTPRoute used to process the request. Implementations + /// MUST ignore any port value specified in the HTTP Host header while + /// performing a match and (absent of any applicable header modification + /// configuration) MUST forward this header unmodified to the backend. + /// + /// Valid values for Hostnames are determined by RFC 1123 definition of a + /// hostname with 2 notable exceptions: + /// + /// 1. IPs are not allowed. + /// 2. A hostname may be prefixed with a wildcard label (`*.`). The wildcard + /// label must appear by itself as the first label. + /// + /// If a hostname is specified by both the Listener and HTTPRoute, there + /// must be at least one intersecting hostname for the HTTPRoute to be + /// attached to the Listener. For example: + /// + /// * A Listener with `test.example.com` as the hostname matches HTTPRoutes + /// that have either not specified any hostnames, or have specified at + /// least one of `test.example.com` or `*.example.com`. + /// * A Listener with `*.example.com` as the hostname matches HTTPRoutes + /// that have either not specified any hostnames or have specified at least + /// one hostname that matches the Listener hostname. For example, + /// `*.example.com`, `test.example.com`, and `foo.test.example.com` would + /// all match. On the other hand, `example.com` and `test.example.net` would + /// not match. + /// + /// Hostnames that are prefixed with a wildcard label (`*.`) are interpreted + /// as a suffix match. That means that a match for `*.example.com` would match + /// both `test.example.com`, and `foo.test.example.com`, but not `example.com`. + /// + /// If both the Listener and HTTPRoute have specified hostnames, any + /// HTTPRoute hostnames that do not match the Listener hostname MUST be + /// ignored. For example, if a Listener specified `*.example.com`, and the + /// HTTPRoute specified `test.example.com` and `test.example.net`, + /// `test.example.net` must not be considered for a match. + /// + /// If both the Listener and HTTPRoute have specified hostnames, and none + /// match with the criteria above, then the HTTPRoute is not accepted. The + /// implementation must raise an 'Accepted' Condition with a status of + /// `False` in the corresponding RouteParentStatus. + /// + /// In the event that multiple HTTPRoutes specify intersecting hostnames (e.g. + /// overlapping wildcard matching and exact matching hostnames), precedence must + /// be given to rules from the HTTPRoute with the largest number of: + /// + /// * Characters in a matching non-wildcard hostname. + /// * Characters in a matching hostname. + /// + /// If ties exist across multiple Routes, the matching precedence rules for + /// HTTPRouteMatches takes over. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostnames: Option>, + /// ParentRefs references the resources (usually Gateways) that a Route wants + /// to be attached to. Note that the referenced parent resource needs to + /// allow this for the attachment to be complete. For Gateways, that means + /// the Gateway needs to allow attachment from Routes of this kind and + /// namespace. For Services, that means the Service must either be in the same + /// namespace for a "producer" route, or the mesh implementation must support + /// and allow "consumer" routes for the referenced Service. ReferenceGrant is + /// not applicable for governing ParentRefs to Services - it is not possible to + /// create a "producer" route for a Service in a different namespace from the + /// Route. + /// + /// There are two kinds of parent resources with "Core" support: + /// + /// * Gateway (Gateway conformance profile) + /// * Service (Mesh conformance profile, ClusterIP Services only) + /// + /// This API may be extended in the future to support additional kinds of parent + /// resources. + /// + /// ParentRefs must be _distinct_. This means either that: + /// + /// * They select different objects. If this is the case, then parentRef + /// entries are distinct. In terms of fields, this means that the + /// multi-part key defined by `group`, `kind`, `namespace`, and `name` must + /// be unique across all parentRef entries in the Route. + /// * They do not select different objects, but for each optional field used, + /// each ParentRef that selects the same object must set the same set of + /// optional fields to different values. If one ParentRef sets a + /// combination of optional fields, all must set the same combination. + /// + /// Some examples: + /// + /// * If one ParentRef sets `sectionName`, all ParentRefs referencing the + /// same object must also set `sectionName`. + /// * If one ParentRef sets `port`, all ParentRefs referencing the same + /// object must also set `port`. + /// * If one ParentRef sets `sectionName` and `port`, all ParentRefs + /// referencing the same object must also set `sectionName` and `port`. + /// + /// It is possible to separately reference multiple distinct objects that may + /// be collapsed by an implementation. For example, some implementations may + /// choose to merge compatible Gateway Listeners together. If that is the + /// case, the list of routes attached to those resources should also be + /// merged. + /// + /// Note that for ParentRefs that cross namespace boundaries, there are specific + /// rules. Cross-namespace references are only valid if they are explicitly + /// allowed by something in the namespace they are referring to. For example, + /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a + /// generic way to enable other kinds of cross-namespace reference. + /// + /// + /// + /// + /// + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none", rename = "parentRefs")] + pub parent_refs: Option>, + /// Rules are a list of HTTP matchers, filters and actions. + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none")] + pub rules: Option>, +} +/// HTTPRouteRule defines semantics for matching an HTTP request based on +/// conditions (matches), processing it (filters), and forwarding the request to +/// an API object (backendRefs). +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRules { + /// BackendRefs defines the backend(s) where matching requests should be + /// sent. + /// + /// Failure behavior here depends on how many BackendRefs are specified and + /// how many are invalid. + /// + /// If *all* entries in BackendRefs are invalid, and there are also no filters + /// specified in this route rule, *all* traffic which matches this rule MUST + /// receive a 500 status code. + /// + /// See the HTTPBackendRef definition for the rules about what makes a single + /// HTTPBackendRef invalid. + /// + /// When a HTTPBackendRef is invalid, 500 status codes MUST be returned for + /// requests that would have otherwise been routed to an invalid backend. If + /// multiple backends are specified, and some are invalid, the proportion of + /// requests that would otherwise have been routed to an invalid backend + /// MUST receive a 500 status code. + /// + /// For example, if two backends are specified with equal weights, and one is + /// invalid, 50 percent of traffic must receive a 500. Implementations may + /// choose how that 50 percent is determined. + /// + /// When a HTTPBackendRef refers to a Service that has no ready endpoints, + /// implementations SHOULD return a 503 for requests to that backend instead. + /// If an implementation chooses to do this, all of the above rules for 500 responses + /// MUST also apply for responses that return a 503. + /// + /// Support: Core for Kubernetes Service + /// + /// Support: Extended for Kubernetes ServiceImport + /// + /// Support: Implementation-specific for any other resource + /// + /// Support for weight: Core + #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRefs")] + pub backend_refs: Option>, + /// Filters define the filters that are applied to requests that match + /// this rule. + /// + /// Wherever possible, implementations SHOULD implement filters in the order + /// they are specified. + /// + /// Implementations MAY choose to implement this ordering strictly, rejecting + /// any combination or order of filters that can not be supported. If implementations + /// choose a strict interpretation of filter ordering, they MUST clearly document + /// that behavior. + /// + /// To reject an invalid combination or order of filters, implementations SHOULD + /// consider the Route Rules with this configuration invalid. If all Route Rules + /// in a Route are invalid, the entire Route would be considered invalid. If only + /// a portion of Route Rules are invalid, implementations MUST set the + /// "PartiallyInvalid" condition for the Route. + /// + /// Conformance-levels at this level are defined based on the type of filter: + /// + /// - ALL core filters MUST be supported by all implementations. + /// - Implementers are encouraged to support extended filters. + /// - Implementation-specific custom filters have no API guarantees across + /// implementations. + /// + /// Specifying the same filter multiple times is not supported unless explicitly + /// indicated in the filter. + /// + /// All filters are expected to be compatible with each other except for the + /// URLRewrite and RequestRedirect filters, which may not be combined. If an + /// implementation can not support other combinations of filters, they must clearly + /// document that limitation. In cases where incompatible or unsupported + /// filters are specified and cause the `Accepted` condition to be set to status + /// `False`, implementations may use the `IncompatibleFilters` reason to specify + /// this configuration error. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub filters: Option>, + /// Matches define conditions used for matching the rule against incoming + /// HTTP requests. Each match is independent, i.e. this rule will be matched + /// if **any** one of the matches is satisfied. + /// + /// For example, take the following matches configuration: + /// + /// ```text + /// matches: + /// - path: + /// value: "/foo" + /// headers: + /// - name: "version" + /// value: "v2" + /// - path: + /// value: "/v2/foo" + /// ``` + /// + /// For a request to match against this rule, a request must satisfy + /// EITHER of the two conditions: + /// + /// - path prefixed with `/foo` AND contains the header `version: v2` + /// - path prefix of `/v2/foo` + /// + /// See the documentation for HTTPRouteMatch on how to specify multiple + /// match conditions that should be ANDed together. + /// + /// If no matches are specified, the default is a prefix + /// path match on "/", which has the effect of matching every + /// HTTP request. + /// + /// Proxy or Load Balancer routing configuration generated from HTTPRoutes + /// MUST prioritize matches based on the following criteria, continuing on + /// ties. Across all rules specified on applicable Routes, precedence must be + /// given to the match having: + /// + /// * "Exact" path match. + /// * "Prefix" path match with largest number of characters. + /// * Method match. + /// * Largest number of header matches. + /// * Largest number of query param matches. + /// + /// Note: The precedence of RegularExpression path matches are implementation-specific. + /// + /// If ties still exist across multiple Routes, matching precedence MUST be + /// determined in order of the following criteria, continuing on ties: + /// + /// * The oldest Route based on creation timestamp. + /// * The Route appearing first in alphabetical order by + /// "{namespace}/{name}". + /// + /// If ties still exist within an HTTPRoute, matching precedence MUST be granted + /// to the FIRST matching rule (in list order) with a match meeting the above + /// criteria. + /// + /// When no rules matching a request have been successfully attached to the + /// parent a request is coming from, a HTTP 404 status code MUST be returned. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub matches: Option>, + /// Timeouts defines the timeouts that can be configured for an HTTP request. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub timeouts: Option, +} +/// HTTPBackendRef defines how a HTTPRoute forwards a HTTP request. +/// +/// Note that when a namespace different than the local namespace is specified, a +/// ReferenceGrant object is required in the referent namespace to allow that +/// namespace's owner to accept the reference. See the ReferenceGrant +/// documentation for details. +/// +/// +/// +/// When the BackendRef points to a Kubernetes Service, implementations SHOULD +/// honor the appProtocol field if it is set for the target Service Port. +/// +/// Implementations supporting appProtocol SHOULD recognize the Kubernetes +/// Standard Application Protocols defined in KEP-3726. +/// +/// If a Service appProtocol isn't specified, an implementation MAY infer the +/// backend protocol through its own means. Implementations MAY infer the +/// protocol from the Route type referring to the backend Service. +/// +/// If a Route is not able to send traffic to the backend using the specified +/// protocol then the backend is considered invalid. Implementations MUST set the +/// "ResolvedRefs" condition to "False" with the "UnsupportedProtocol" reason. +/// +/// +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesBackendRefs { + /// Filters defined at this level should be executed if and only if the + /// request is being forwarded to the backend defined here. + /// + /// Support: Implementation-specific (For broader support of filters, use the + /// Filters field in HTTPRouteRule.) + #[serde(default, skip_serializing_if = "Option::is_none")] + pub filters: Option>, + /// Group is the group of the referent. For example, "gateway.networking.k8s.io". + /// When unspecified or empty string, core API group is inferred. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + /// Kind is the Kubernetes resource kind of the referent. For example + /// "Service". + /// + /// Defaults to "Service" when not specified. + /// + /// ExternalName services can refer to CNAME DNS records that may live + /// outside of the cluster and as such are difficult to reason about in + /// terms of conformance. They also may not be safe to forward to (see + /// CVE-2021-25740 for more information). Implementations SHOULD NOT + /// support ExternalName Services. + /// + /// Support: Core (Services with a type other than ExternalName) + /// + /// Support: Implementation-specific (Services with type ExternalName) + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + /// Name is the name of the referent. + pub name: String, + /// Namespace is the namespace of the backend. When unspecified, the local + /// namespace is inferred. + /// + /// Note that when a namespace different than the local namespace is specified, + /// a ReferenceGrant object is required in the referent namespace to allow that + /// namespace's owner to accept the reference. See the ReferenceGrant + /// documentation for details. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, + /// Port specifies the destination port number to use for this resource. + /// Port is required when the referent is a Kubernetes Service. In this + /// case, the port number is the service port number, not the target port. + /// For other resources, destination port might be derived from the referent + /// resource or this field. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + /// Weight specifies the proportion of requests forwarded to the referenced + /// backend. This is computed as weight/(sum of all weights in this + /// BackendRefs list). For non-zero values, there may be some epsilon from + /// the exact proportion defined here depending on the precision an + /// implementation supports. Weight is not a percentage and the sum of + /// weights does not need to equal 100. + /// + /// If only one backend is specified and it has a weight greater than 0, 100% + /// of the traffic is forwarded to that backend. If weight is set to 0, no + /// traffic should be forwarded for this entry. If unspecified, weight + /// defaults to 1. + /// + /// Support for this field varies based on the context where used. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub weight: Option, +} +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesBackendRefsFilters { + /// ExtensionRef is an optional, implementation-specific extension to the + /// "filter" behavior. For example, resource "myroutefilter" in group + /// "networking.example.net"). ExtensionRef MUST NOT be used for core and + /// extended filters. + /// + /// This filter can be used multiple times within the same rule. + /// + /// Support: Implementation-specific + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, + /// RequestHeaderModifier defines a schema for a filter that modifies request + /// headers. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + /// RequestMirror defines a schema for a filter that mirrors requests. + /// Requests are sent to the specified destination, but responses from + /// that destination are ignored. + /// + /// This filter can be used multiple times within the same rule. Note that + /// not all implementations will be able to support mirroring to multiple + /// backends. + /// + /// Support: Extended + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, + /// RequestRedirect defines a schema for a filter that responds to the + /// request with an HTTP redirection. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestRedirect" + )] + pub request_redirect: Option, + /// ResponseHeaderModifier defines a schema for a filter that modifies response + /// headers. + /// + /// Support: Extended + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + /// Type identifies the type of filter to apply. As with other API fields, + /// types are classified into three conformance levels: + /// + /// - Core: Filter types and their corresponding configuration defined by + /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All + /// implementations must support core filters. + /// + /// - Extended: Filter types and their corresponding configuration defined by + /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers + /// are encouraged to support extended filters. + /// + /// - Implementation-specific: Filters that are defined and supported by + /// specific vendors. + /// In the future, filters showing convergence in behavior across multiple + /// implementations will be considered for inclusion in extended or core + /// conformance levels. Filter-specific configuration for such filters + /// is specified using the ExtensionRef field. `Type` should be set to + /// "ExtensionRef" for custom filters. + /// + /// Implementers are encouraged to define custom implementation types to + /// extend the core API with implementation-specific behavior. + /// + /// If a reference to a custom filter type cannot be resolved, the filter + /// MUST NOT be skipped. Instead, requests that would have been processed by + /// that filter MUST receive a HTTP error response. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + #[serde(rename = "type")] + pub r#type: HTTPRouteRulesBackendRefsFiltersType, + /// URLRewrite defines a schema for a filter that modifies a request during forwarding. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] + pub url_rewrite: Option, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirect { + /// Hostname is the hostname to be used in the value of the `Location` + /// header in the response. + /// When empty, the hostname in the `Host` header of the request is used. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + /// Path defines parameters used to modify the path of the incoming request. + /// The modified path is then used to construct the `Location` header. When + /// empty, the request path is used as-is. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, + /// Port is the port to be used in the value of the `Location` + /// header in the response. + /// + /// If no port is specified, the redirect port MUST be derived using the + /// following rules: + /// + /// * If redirect scheme is not-empty, the redirect port MUST be the well-known + /// port associated with the redirect scheme. Specifically "http" to port 80 + /// and "https" to port 443. If the redirect scheme does not have a + /// well-known port, the listener port of the Gateway SHOULD be used. + /// * If redirect scheme is empty, the redirect port MUST be the Gateway + /// Listener port. + /// + /// Implementations SHOULD NOT add the port number in the 'Location' + /// header in the following cases: + /// + /// * A Location header that will use HTTP (whether that is determined via + /// the Listener protocol or the Scheme field) _and_ use port 80. + /// * A Location header that will use HTTPS (whether that is determined via + /// the Listener protocol or the Scheme field) _and_ use port 443. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + /// Scheme is the scheme to be used in the value of the `Location` header in + /// the response. When empty, the scheme of the request is used. + /// + /// Scheme redirects can affect the port of the redirect, for more information, + /// refer to the documentation for the port field of this filter. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub scheme: Option, + /// StatusCode is the HTTP status code to be used in response. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none", rename = "statusCode")] + pub status_code: Option, +} +/// Path defines parameters used to modify the path of the incoming request. +/// The modified path is then used to construct the `Location` header. When +/// empty, the request path is used as-is. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirectPath { + /// ReplaceFullPath specifies the value with which to replace the full path + /// of a request during a rewrite or redirect. + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replaceFullPath" + )] + pub replace_full_path: Option, + /// ReplacePrefixMatch specifies the value with which to replace the prefix + /// match of a request during a rewrite or redirect. For example, a request + /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch + /// of "/xyz" would be modified to "/xyz/bar". + /// + /// Note that this matches the behavior of the PathPrefix match type. This + /// matches full path elements. A path element refers to the list of labels + /// in the path split by the `/` separator. When specified, a trailing `/` is + /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all + /// match the prefix `/abc`, but the path `/abcd` would not. + /// + /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. + /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in + /// the implementation setting the Accepted Condition for the Route to `status: False`. + /// + /// Request Path | Prefix Match | Replace Prefix | Modified Path + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replacePrefixMatch" + )] + pub replace_prefix_match: Option, + /// Type defines the type of path modifier. Additional types may be + /// added in a future release of the API. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + #[serde(rename = "type")] + pub r#type: HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType, +} +/// Path defines parameters used to modify the path of the incoming request. +/// The modified path is then used to construct the `Location` header. When +/// empty, the request path is used as-is. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType { + ReplaceFullPath, + ReplacePrefixMatch, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectScheme { + #[serde(rename = "http")] + Http, + #[serde(rename = "https")] + Https, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectStatusCode { + #[serde(rename = "301")] + r#_301, + #[serde(rename = "302")] + r#_302, +} +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesBackendRefsFiltersType { + RequestHeaderModifier, + ResponseHeaderModifier, + RequestMirror, + RequestRedirect, + #[serde(rename = "URLRewrite")] + UrlRewrite, + ExtensionRef, +} +/// URLRewrite defines a schema for a filter that modifies a request during forwarding. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesBackendRefsFiltersUrlRewrite { + /// Hostname is the value to be used to replace the Host header value during + /// forwarding. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + /// Path defines a path rewrite. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, +} +/// Path defines a path rewrite. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesBackendRefsFiltersUrlRewritePath { + /// ReplaceFullPath specifies the value with which to replace the full path + /// of a request during a rewrite or redirect. + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replaceFullPath" + )] + pub replace_full_path: Option, + /// ReplacePrefixMatch specifies the value with which to replace the prefix + /// match of a request during a rewrite or redirect. For example, a request + /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch + /// of "/xyz" would be modified to "/xyz/bar". + /// + /// Note that this matches the behavior of the PathPrefix match type. This + /// matches full path elements. A path element refers to the list of labels + /// in the path split by the `/` separator. When specified, a trailing `/` is + /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all + /// match the prefix `/abc`, but the path `/abcd` would not. + /// + /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. + /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in + /// the implementation setting the Accepted Condition for the Route to `status: False`. + /// + /// Request Path | Prefix Match | Replace Prefix | Modified Path + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replacePrefixMatch" + )] + pub replace_prefix_match: Option, + /// Type defines the type of path modifier. Additional types may be + /// added in a future release of the API. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + #[serde(rename = "type")] + pub r#type: HTTPRouteRulesBackendRefsFiltersUrlRewritePathType, +} +/// Path defines a path rewrite. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesBackendRefsFiltersUrlRewritePathType { + ReplaceFullPath, + ReplacePrefixMatch, +} +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesFilters { + /// ExtensionRef is an optional, implementation-specific extension to the + /// "filter" behavior. For example, resource "myroutefilter" in group + /// "networking.example.net"). ExtensionRef MUST NOT be used for core and + /// extended filters. + /// + /// This filter can be used multiple times within the same rule. + /// + /// Support: Implementation-specific + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, + /// RequestHeaderModifier defines a schema for a filter that modifies request + /// headers. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + /// RequestMirror defines a schema for a filter that mirrors requests. + /// Requests are sent to the specified destination, but responses from + /// that destination are ignored. + /// + /// This filter can be used multiple times within the same rule. Note that + /// not all implementations will be able to support mirroring to multiple + /// backends. + /// + /// Support: Extended + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, + /// RequestRedirect defines a schema for a filter that responds to the + /// request with an HTTP redirection. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestRedirect" + )] + pub request_redirect: Option, + /// ResponseHeaderModifier defines a schema for a filter that modifies response + /// headers. + /// + /// Support: Extended + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + /// Type identifies the type of filter to apply. As with other API fields, + /// types are classified into three conformance levels: + /// + /// - Core: Filter types and their corresponding configuration defined by + /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All + /// implementations must support core filters. + /// + /// - Extended: Filter types and their corresponding configuration defined by + /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers + /// are encouraged to support extended filters. + /// + /// - Implementation-specific: Filters that are defined and supported by + /// specific vendors. + /// In the future, filters showing convergence in behavior across multiple + /// implementations will be considered for inclusion in extended or core + /// conformance levels. Filter-specific configuration for such filters + /// is specified using the ExtensionRef field. `Type` should be set to + /// "ExtensionRef" for custom filters. + /// + /// Implementers are encouraged to define custom implementation types to + /// extend the core API with implementation-specific behavior. + /// + /// If a reference to a custom filter type cannot be resolved, the filter + /// MUST NOT be skipped. Instead, requests that would have been processed by + /// that filter MUST receive a HTTP error response. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + #[serde(rename = "type")] + pub r#type: HTTPRouteRulesFiltersType, + /// URLRewrite defines a schema for a filter that modifies a request during forwarding. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] + pub url_rewrite: Option, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesFiltersRequestRedirect { + /// Hostname is the hostname to be used in the value of the `Location` + /// header in the response. + /// When empty, the hostname in the `Host` header of the request is used. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + /// Path defines parameters used to modify the path of the incoming request. + /// The modified path is then used to construct the `Location` header. When + /// empty, the request path is used as-is. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, + /// Port is the port to be used in the value of the `Location` + /// header in the response. + /// + /// If no port is specified, the redirect port MUST be derived using the + /// following rules: + /// + /// * If redirect scheme is not-empty, the redirect port MUST be the well-known + /// port associated with the redirect scheme. Specifically "http" to port 80 + /// and "https" to port 443. If the redirect scheme does not have a + /// well-known port, the listener port of the Gateway SHOULD be used. + /// * If redirect scheme is empty, the redirect port MUST be the Gateway + /// Listener port. + /// + /// Implementations SHOULD NOT add the port number in the 'Location' + /// header in the following cases: + /// + /// * A Location header that will use HTTP (whether that is determined via + /// the Listener protocol or the Scheme field) _and_ use port 80. + /// * A Location header that will use HTTPS (whether that is determined via + /// the Listener protocol or the Scheme field) _and_ use port 443. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + /// Scheme is the scheme to be used in the value of the `Location` header in + /// the response. When empty, the scheme of the request is used. + /// + /// Scheme redirects can affect the port of the redirect, for more information, + /// refer to the documentation for the port field of this filter. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub scheme: Option, + /// StatusCode is the HTTP status code to be used in response. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + /// + /// Support: Core + #[serde(default, skip_serializing_if = "Option::is_none", rename = "statusCode")] + pub status_code: Option, +} +/// Path defines parameters used to modify the path of the incoming request. +/// The modified path is then used to construct the `Location` header. When +/// empty, the request path is used as-is. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesFiltersRequestRedirectPath { + /// ReplaceFullPath specifies the value with which to replace the full path + /// of a request during a rewrite or redirect. + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replaceFullPath" + )] + pub replace_full_path: Option, + /// ReplacePrefixMatch specifies the value with which to replace the prefix + /// match of a request during a rewrite or redirect. For example, a request + /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch + /// of "/xyz" would be modified to "/xyz/bar". + /// + /// Note that this matches the behavior of the PathPrefix match type. This + /// matches full path elements. A path element refers to the list of labels + /// in the path split by the `/` separator. When specified, a trailing `/` is + /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all + /// match the prefix `/abc`, but the path `/abcd` would not. + /// + /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. + /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in + /// the implementation setting the Accepted Condition for the Route to `status: False`. + /// + /// Request Path | Prefix Match | Replace Prefix | Modified Path + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replacePrefixMatch" + )] + pub replace_prefix_match: Option, + /// Type defines the type of path modifier. Additional types may be + /// added in a future release of the API. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + #[serde(rename = "type")] + pub r#type: HTTPRouteRulesFiltersRequestRedirectPathType, +} +/// Path defines parameters used to modify the path of the incoming request. +/// The modified path is then used to construct the `Location` header. When +/// empty, the request path is used as-is. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesFiltersRequestRedirectPathType { + ReplaceFullPath, + ReplacePrefixMatch, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesFiltersRequestRedirectScheme { + #[serde(rename = "http")] + Http, + #[serde(rename = "https")] + Https, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesFiltersRequestRedirectStatusCode { + #[serde(rename = "301")] + r#_301, + #[serde(rename = "302")] + r#_302, +} +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesFiltersType { + RequestHeaderModifier, + ResponseHeaderModifier, + RequestMirror, + RequestRedirect, + #[serde(rename = "URLRewrite")] + UrlRewrite, + ExtensionRef, +} +/// URLRewrite defines a schema for a filter that modifies a request during forwarding. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesFiltersUrlRewrite { + /// Hostname is the value to be used to replace the Host header value during + /// forwarding. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + /// Path defines a path rewrite. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, +} +/// Path defines a path rewrite. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesFiltersUrlRewritePath { + /// ReplaceFullPath specifies the value with which to replace the full path + /// of a request during a rewrite or redirect. + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replaceFullPath" + )] + pub replace_full_path: Option, + /// ReplacePrefixMatch specifies the value with which to replace the prefix + /// match of a request during a rewrite or redirect. For example, a request + /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch + /// of "/xyz" would be modified to "/xyz/bar". + /// + /// Note that this matches the behavior of the PathPrefix match type. This + /// matches full path elements. A path element refers to the list of labels + /// in the path split by the `/` separator. When specified, a trailing `/` is + /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all + /// match the prefix `/abc`, but the path `/abcd` would not. + /// + /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. + /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in + /// the implementation setting the Accepted Condition for the Route to `status: False`. + /// + /// Request Path | Prefix Match | Replace Prefix | Modified Path + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replacePrefixMatch" + )] + pub replace_prefix_match: Option, + /// Type defines the type of path modifier. Additional types may be + /// added in a future release of the API. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + #[serde(rename = "type")] + pub r#type: HTTPRouteRulesFiltersUrlRewritePathType, +} +/// Path defines a path rewrite. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesFiltersUrlRewritePathType { + ReplaceFullPath, + ReplacePrefixMatch, +} +/// HTTPRouteMatch defines the predicate used to match requests to a given +/// action. Multiple match types are ANDed together, i.e. the match will +/// evaluate to true only if all conditions are satisfied. +/// +/// For example, the match below will match a HTTP request only if its path +/// starts with `/foo` AND it contains the `version: v1` header: +/// +/// ```text +/// match: +/// +/// path: +/// value: "/foo" +/// headers: +/// - name: "version" +/// value "v1" +/// +/// ``` +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesMatches { + /// Headers specifies HTTP request header matchers. Multiple match values are + /// ANDed together, meaning, a request must match all the specified headers + /// to select the route. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub headers: Option>, + /// Method specifies HTTP method matcher. + /// When specified, this route will be matched only if the request has the + /// specified method. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub method: Option, + /// Path specifies a HTTP request path matcher. If this field is not + /// specified, a default prefix match on the "/" path is provided. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, + /// QueryParams specifies HTTP query parameter matchers. Multiple match + /// values are ANDed together, meaning, a request must match all the + /// specified query parameters to select the route. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none", rename = "queryParams")] + pub query_params: Option>, +} +/// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request +/// headers. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesMatchesHeaders { + /// Name is the name of the HTTP Header to be matched. Name matching MUST be + /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). + /// + /// If multiple entries specify equivalent header names, only the first + /// entry with an equivalent name MUST be considered for a match. Subsequent + /// entries with an equivalent header name MUST be ignored. Due to the + /// case-insensitivity of header names, "foo" and "Foo" are considered + /// equivalent. + /// + /// When a header is repeated in an HTTP request, it is + /// implementation-specific behavior as to how this is represented. + /// Generally, proxies should follow the guidance from the RFC: + /// https://www.rfc-editor.org/rfc/rfc7230.html#section-3.2.2 regarding + /// processing a repeated header, with special handling for "Set-Cookie". + pub name: String, + /// Type specifies how to match against the value of the header. + /// + /// Support: Core (Exact) + /// + /// Support: Implementation-specific (RegularExpression) + /// + /// Since RegularExpression HeaderMatchType has implementation-specific + /// conformance, implementations can support POSIX, PCRE or any other dialects + /// of regular expressions. Please read the implementation's documentation to + /// determine the supported dialect. + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + /// Value is the value of HTTP Header to be matched. + pub value: String, +} +/// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request +/// headers. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesMatchesHeadersType { + Exact, + RegularExpression, +} +/// HTTPRouteMatch defines the predicate used to match requests to a given +/// action. Multiple match types are ANDed together, i.e. the match will +/// evaluate to true only if all conditions are satisfied. +/// +/// For example, the match below will match a HTTP request only if its path +/// starts with `/foo` AND it contains the `version: v1` header: +/// +/// ```text +/// match: +/// +/// path: +/// value: "/foo" +/// headers: +/// - name: "version" +/// value "v1" +/// +/// ``` +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesMatchesMethod { + #[serde(rename = "GET")] + Get, + #[serde(rename = "HEAD")] + Head, + #[serde(rename = "POST")] + Post, + #[serde(rename = "PUT")] + Put, + #[serde(rename = "DELETE")] + Delete, + #[serde(rename = "CONNECT")] + Connect, + #[serde(rename = "OPTIONS")] + Options, + #[serde(rename = "TRACE")] + Trace, + #[serde(rename = "PATCH")] + Patch, +} +/// Path specifies a HTTP request path matcher. If this field is not +/// specified, a default prefix match on the "/" path is provided. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesMatchesPath { + /// Type specifies how to match against the path Value. + /// + /// Support: Core (Exact, PathPrefix) + /// + /// Support: Implementation-specific (RegularExpression) + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + /// Value of the HTTP path to match against. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub value: Option, +} +/// Path specifies a HTTP request path matcher. If this field is not +/// specified, a default prefix match on the "/" path is provided. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesMatchesPathType { + Exact, + PathPrefix, + RegularExpression, +} +/// HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP +/// query parameters. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesMatchesQueryParams { + /// Name is the name of the HTTP query param to be matched. This must be an + /// exact string match. (See + /// https://tools.ietf.org/html/rfc7230#section-2.7.3). + /// + /// If multiple entries specify equivalent query param names, only the first + /// entry with an equivalent name MUST be considered for a match. Subsequent + /// entries with an equivalent query param name MUST be ignored. + /// + /// If a query param is repeated in an HTTP request, the behavior is + /// purposely left undefined, since different data planes have different + /// capabilities. However, it is *recommended* that implementations should + /// match against the first value of the param if the data plane supports it, + /// as this behavior is expected in other load balancing contexts outside of + /// the Gateway API. + /// + /// Users SHOULD NOT route traffic based on repeated query params to guard + /// themselves against potential differences in the implementations. + pub name: String, + /// Type specifies how to match against the value of the query parameter. + /// + /// Support: Extended (Exact) + /// + /// Support: Implementation-specific (RegularExpression) + /// + /// Since RegularExpression QueryParamMatchType has Implementation-specific + /// conformance, implementations can support POSIX, PCRE or any other + /// dialects of regular expressions. Please read the implementation's + /// documentation to determine the supported dialect. + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + /// Value is the value of HTTP query param to be matched. + pub value: String, +} +/// HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP +/// query parameters. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesMatchesQueryParamsType { + Exact, + RegularExpression, +} +/// Timeouts defines the timeouts that can be configured for an HTTP request. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesTimeouts { + /// BackendRequest specifies a timeout for an individual request from the gateway + /// to a backend. This covers the time from when the request first starts being + /// sent from the gateway to when the full response has been received from the backend. + /// + /// Setting a timeout to the zero duration (e.g. "0s") SHOULD disable the timeout + /// completely. Implementations that cannot completely disable the timeout MUST + /// instead interpret the zero duration as the longest possible value to which + /// the timeout can be set. + /// + /// An entire client HTTP transaction with a gateway, covered by the Request timeout, + /// may result in more than one call from the gateway to the destination backend, + /// for example, if automatic retries are supported. + /// + /// The value of BackendRequest must be a Gateway API Duration string as defined by + /// GEP-2257. When this field is unspecified, its behavior is implementation-specific; + /// when specified, the value of BackendRequest must be no more than the value of the + /// Request timeout (since the Request timeout encompasses the BackendRequest timeout). + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRequest")] + pub backend_request: Option, + /// Request specifies the maximum duration for a gateway to respond to an HTTP request. + /// If the gateway has not been able to respond before this deadline is met, the gateway + /// MUST return a timeout error. + /// + /// For example, setting the `rules.timeouts.request` field to the value `10s` in an + /// `HTTPRoute` will cause a timeout if a client request is taking longer than 10 seconds + /// to complete. + /// + /// Setting a timeout to the zero duration (e.g. "0s") SHOULD disable the timeout + /// completely. Implementations that cannot completely disable the timeout MUST + /// instead interpret the zero duration as the longest possible value to which + /// the timeout can be set. + /// + /// This timeout is intended to cover as close to the whole request-response transaction + /// as possible although an implementation MAY choose to start the timeout after the entire + /// request stream has been received instead of immediately after the transaction is + /// initiated by the client. + /// + /// The value of Request is a Gateway API Duration string as defined by GEP-2257. When this + /// field is unspecified, request timeout behavior is implementation-specific. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub request: Option, +} +/// Status defines the current state of HTTPRoute. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteStatus { + /// Parents is a list of parent resources (usually Gateways) that are + /// associated with the route, and the status of the route with respect to + /// each parent. When this route attaches to a parent, the controller that + /// manages the parent must add an entry to this list when the controller + /// first sees the route and should update the entry as appropriate when the + /// route or gateway is modified. + /// + /// Note that parent references that cannot be resolved by an implementation + /// of this API will not be added to this list. Implementations of this API + /// can only populate Route status for the Gateways/parent resources they are + /// responsible for. + /// + /// A maximum of 32 Gateways will be represented in this list. An empty list + /// means the route has not been attached to any Gateway. + pub parents: Vec, +} +/// RouteParentStatus describes the status of a route with respect to an +/// associated Parent. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteStatusParents { + /// Conditions describes the status of the route with respect to the Gateway. + /// Note that the route's availability is also subject to the Gateway's own + /// status conditions and listener status. + /// + /// If the Route's ParentRef specifies an existing Gateway that supports + /// Routes of this kind AND that Gateway's controller has sufficient access, + /// then that Gateway's controller MUST set the "Accepted" condition on the + /// Route, to indicate whether the route has been accepted or rejected by the + /// Gateway, and why. + /// + /// A Route MUST be considered "Accepted" if at least one of the Route's + /// rules is implemented by the Gateway. + /// + /// There are a number of cases where the "Accepted" condition may not be set + /// due to lack of controller visibility, that includes when: + /// + /// * The Route refers to a non-existent parent. + /// * The Route is of a type that the controller does not support. + /// * The Route is in a namespace the controller does not have access to. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub conditions: Option>, + /// ControllerName is a domain/path string that indicates the name of the + /// controller that wrote this status. This corresponds with the + /// controllerName field on GatewayClass. + /// + /// Example: "example.net/gateway-controller". + /// + /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are + /// valid Kubernetes names + /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). + /// + /// Controllers MUST populate this field when writing status. Controllers should ensure that + /// entries to status populated with their ControllerName are cleaned up when they are no + /// longer necessary. + #[serde(rename = "controllerName")] + pub controller_name: String, + /// ParentRef corresponds with a ParentRef in the spec that this + /// RouteParentStatus struct describes the status of. + #[serde(rename = "parentRef")] + pub parent_ref: RouteRef, +} diff --git a/gateway-api/src/apis/processed/mod.rs b/gateway-api/src/apis/processed/mod.rs new file mode 100644 index 0000000..937b77b --- /dev/null +++ b/gateway-api/src/apis/processed/mod.rs @@ -0,0 +1,10 @@ +// WARNING! generated file do not edit + +pub mod common_types; +pub mod constants; +pub mod enum_defaults; +pub mod gatewayclasses; +pub mod gateways; +pub mod grpcroutes; +pub mod httproutes; +pub mod referencegrants; diff --git a/gateway-api/src/apis/processed/referencegrants.rs b/gateway-api/src/apis/processed/referencegrants.rs new file mode 100644 index 0000000..c785978 --- /dev/null +++ b/gateway-api/src/apis/processed/referencegrants.rs @@ -0,0 +1,96 @@ +// WARNING! generated file do not edit + +#[allow(unused_imports)] +mod prelude { + pub use kube::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Deserialize, Serialize}; +} +use self::prelude::*; +/// Spec defines the desired state of ReferenceGrant. +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] +#[kube( + group = "gateway.networking.k8s.io", + version = "v1beta1", + kind = "ReferenceGrant", + plural = "referencegrants" +)] +#[kube(namespaced)] +#[kube(derive = "Default")] +#[kube(derive = "PartialEq")] +pub struct ReferenceGrantSpec { + /// From describes the trusted namespaces and kinds that can reference the + /// resources described in "To". Each entry in this list MUST be considered + /// to be an additional place that references can be valid from, or to put + /// this another way, entries MUST be combined using OR. + /// + /// Support: Core + pub from: Vec, + /// To describes the resources that may be referenced by the resources + /// described in "From". Each entry in this list MUST be considered to be an + /// additional place that references can be valid to, or to put this another + /// way, entries MUST be combined using OR. + /// + /// Support: Core + pub to: Vec, +} +/// ReferenceGrantFrom describes trusted namespaces and kinds. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct ReferenceGrantFrom { + /// Group is the group of the referent. + /// When empty, the Kubernetes core API group is inferred. + /// + /// Support: Core + pub group: String, + /// Kind is the kind of the referent. Although implementations may support + /// additional resources, the following types are part of the "Core" + /// support level for this field. + /// + /// When used to permit a SecretObjectReference: + /// + /// * Gateway + /// + /// When used to permit a BackendObjectReference: + /// + /// * GRPCRoute + /// * HTTPRoute + /// * TCPRoute + /// * TLSRoute + /// * UDPRoute + pub kind: String, + /// Namespace is the namespace of the referent. + /// + /// Support: Core + pub namespace: String, +} +/// ReferenceGrantTo describes what Kinds are allowed as targets of the +/// references. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct ReferenceGrantTo { + /// Group is the group of the referent. + /// When empty, the Kubernetes core API group is inferred. + /// + /// Support: Core + pub group: String, + /// Kind is the kind of the referent. Although implementations may support + /// additional resources, the following types are part of the "Core" + /// support level for this field: + /// + /// * Secret when used to permit a SecretObjectReference + /// * Service when used to permit a BackendObjectReference + pub kind: String, + /// Name is the name of the referent. When unspecified, this policy + /// refers to all resources of the specified Group and Kind in the local + /// namespace. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub name: Option, +} diff --git a/gateway-api/src/lib.rs b/gateway-api/src/lib.rs index e3fc72e..f5a5e44 100644 --- a/gateway-api/src/lib.rs +++ b/gateway-api/src/lib.rs @@ -1,11 +1,16 @@ pub mod duration; pub use duration::Duration; pub mod apis; + +#[cfg(feature = "standard")] pub use apis::standard::*; #[cfg(feature = "experimental")] pub use apis::experimental; +#[cfg(feature = "processed")] +pub use apis::processed::*; + #[cfg(test)] mod tests { use std::process::Command; @@ -26,12 +31,12 @@ mod tests { use uuid::Uuid; use crate::{ - constants::{ + apis::standard::constants::{ GatewayConditionReason, GatewayConditionType, ListenerConditionReason, ListenerConditionType, }, - gatewayclasses::{GatewayClass, GatewayClassSpec}, - gateways::{ + apis::standard::gatewayclasses::{GatewayClass, GatewayClassSpec}, + apis::standard::gateways::{ Gateway, GatewaySpec, GatewayStatus, GatewayStatusAddresses, GatewayStatusListeners, }, }; diff --git a/type-reducer/Cargo.toml b/type-reducer/Cargo.toml new file mode 100644 index 0000000..c10d5de --- /dev/null +++ b/type-reducer/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "type-reducer" +version = "0.1.0" +edition = "2024" +author = "Dawid Nowak nowakd@gmail.com" + +[dependencies] +syn = { version = "2", features = [ + "full", + "extra-traits", + "visit", + "visit-mut", + "proc-macro", +] } +proc-macro2 = "1" +prettyplease = "0.2" +itertools = "0.14" +multimap = "0.10" +clap = { version = "4.5", features = ["derive"] } +log = { version = "0.4", features = ["std", "serde"] } +simple_logger = "5" diff --git a/type-reducer/customized_mapped_names_pass_1.txt b/type-reducer/customized_mapped_names_pass_1.txt new file mode 100644 index 0000000..661940f --- /dev/null +++ b/type-reducer/customized_mapped_names_pass_1.txt @@ -0,0 +1,6 @@ +AddressesGateway->GatewayAddress +BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef +ExtensionFiltersRefRouteRules->ExtensionBackendRef +FiltersHeaderModifierRouteRules->HeaderModifierRules +GatewayKindsListeners->Kind +ParentRoute->RouteRef diff --git a/type-reducer/customized_mapped_names_pass_2.txt b/type-reducer/customized_mapped_names_pass_2.txt new file mode 100644 index 0000000..af1d7aa --- /dev/null +++ b/type-reducer/customized_mapped_names_pass_2.txt @@ -0,0 +1,3 @@ +FiltersHeaderModifierRouteRules->FilterHeaderRouteRules +FiltersMirrorRequestRouteRules->FilterMirrorRouteRules + diff --git a/type-reducer/reduced_types_pass_1.txt b/type-reducer/reduced_types_pass_1.txt new file mode 100644 index 0000000..ed5258e --- /dev/null +++ b/type-reducer/reduced_types_pass_1.txt @@ -0,0 +1,7 @@ +GatewayAddress +MirrorBackendRef +ExtensionBackendRef +HeaderModifierRules +Kind +ParentRouteRef + diff --git a/type-reducer/src/main.rs b/type-reducer/src/main.rs new file mode 100644 index 0000000..c54cf6f --- /dev/null +++ b/type-reducer/src/main.rs @@ -0,0 +1,613 @@ +use std::collections::BTreeMap; +use std::collections::BTreeSet; +use std::fs; +use std::fs::OpenOptions; +use std::io; +use std::io::Seek; +use std::io::Write; +use std::path::Path; +use std::path::PathBuf; + +use clap::Parser; +use clap::command; +use itertools::Itertools; +use log::debug; +use log::info; +use log::trace; +use multimap::MultiMap; +use proc_macro2::{Ident, Span}; +use std::io::BufRead; +use syn::Fields; +use syn::File; +use syn::Item; +use syn::ItemStruct; +use syn::PathSegment; +use syn::Type; +use syn::visit::{self, Visit}; +use syn::visit_mut; +use syn::visit_mut::VisitMut; + +const COMMON_TYPES_FILE_PREAMBLE: &str = "#[allow(unused_imports)] +mod prelude { + pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; + pub use kube::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Deserialize, Serialize}; + pub use std::collections::BTreeMap; +} +use self::prelude::*;"; + +const COMMON_TYPES_USE_PREAMBLE: &str = "use super::common_types::*;"; +const GENERATED_PREAMBLE: &str = "// WARNING! generated file do not edit\n\n"; + +fn main() -> Result<(), Box> { + simple_logger::init_with_env().unwrap(); + let Args { + apis_dir, + out_dir, + current_pass_substitute_names, + previous_pass_derived_type_names, + } = Args::parse(); + + let Ok(_) = fs::exists(out_dir.clone()) else { + return Err("our dir doesn't exist".into()); + }; + + let current_pass_type_name_substitutes = + if let Some(mapped_names) = current_pass_substitute_names.as_ref() { + read_type_mappings_from_file(mapped_names.as_path())? + } else { + BTreeMap::new() + }; + + let previous_pass_derived_type_names = + if let Some(mapped_names) = previous_pass_derived_type_names.as_ref() { + read_type_names_from_file(mapped_names.as_path())? + } else { + BTreeSet::new() + }; + + let mut visitors = vec![]; + + for dir_entry in fs::read_dir(apis_dir).unwrap() { + let Ok(dir_entry) = dir_entry else { + continue; + }; + + if let Ok(name) = dir_entry.file_name().into_string() { + if name.ends_with(".rs") && name != "mod.rs" { + info!("Adding file {:?}", dir_entry.path()); + if let Ok(api_file) = fs::read_to_string(dir_entry.path()) { + if let Ok(syntaxt_file) = syn::parse_file(&api_file) { + let visitor = StructVisitor { + name, + structs: Vec::new(), + derived_type_names: &previous_pass_derived_type_names, + }; + visitors.push((visitor, syntaxt_file)); + } + } + } + } + } + + let FindSimilarTypesResult { + visitors, + similar_items, + } = find_similar_types(visitors); + + let items: Vec<_> = similar_items + .iter_all() + .filter(|(_k, v)| v.len() > 1) + .filter_map(|(_k, v)| { + info!( + "Potentially similar structs {:#?}", + v.iter().map(|(i, _)| i.to_string()).collect::>() + ); + let mapped_type_names = v.iter().map(|v| v.0.to_string()).collect::>(); + + let type_new_name = create_type_name_substitute(¤t_pass_type_name_substitutes, v); + + if let Some((_i, s)) = v.first() { + let new_struct = create_common_type_struct(s, &type_new_name); + + let mut mapped = BTreeMap::new(); + for mapped_type_name in mapped_type_names { + mapped.insert(mapped_type_name, new_struct.ident.to_string().to_owned()); + } + + info!("Mapped types = {:#?}", &mapped); + if mapped.keys().len() < 2 { + None + } else { + Some((mapped, Item::Struct(new_struct))) + } + } else { + None + } + }) + .collect(); + + let (mapped_types, items): (Vec>, Vec) = + items.into_iter().unzip(); + + let mut renaming_visitor = StructRenamer { + changed: false, + names: mapped_types.into_iter().flatten().collect(), + }; + + if current_pass_substitute_names.is_none() { + write_type_names_to_file(&renaming_visitor.names)? + }; + + let unparsed_files = prune_replaced_structs(&mut renaming_visitor, visitors); + + recreate_project_files(&out_dir, unparsed_files, items) +} + +struct StructVisitor<'ast, 'b> { + name: String, + structs: Vec<&'ast ItemStruct>, + derived_type_names: &'b BTreeSet, +} + +struct StructRenamer { + changed: bool, + names: BTreeMap, +} + +fn rewrite_ident(path: &mut PathSegment, names: &BTreeMap) -> bool { + let mut file_changed = false; + if path.arguments.is_empty() { + let ident = &path.ident; + if let Some(new_name) = names.get(&ident.to_string()) { + path.ident = Ident::new(new_name, Span::call_site()); + file_changed = true; + } + } else { + match path.arguments { + syn::PathArguments::None => {} + syn::PathArguments::AngleBracketed(ref mut angle_bracketed_generic_arguments) => { + for a in angle_bracketed_generic_arguments.args.iter_mut() { + if let syn::GenericArgument::Type(Type::Path(path)) = a { + for s in path.path.segments.iter_mut() { + file_changed |= rewrite_ident(s, names); + } + } + } + } + syn::PathArguments::Parenthesized(_) => {} + } + } + file_changed +} + +fn check_simple_type( + path: &PathSegment, + is_simple: &mut bool, + derived_type_names: &BTreeSet, +) { + if path.arguments.is_empty() { + let ident = &path.ident; + if ident == &Ident::new("String", Span::call_site()) + || ident == &Ident::new("i32", Span::call_site()) + || ident == &Ident::new("i64", Span::call_site()) + || derived_type_names.contains(&ident.to_string()) + { + } else { + *is_simple = false; + } + } else { + match &path.arguments { + syn::PathArguments::None => *is_simple = false, + syn::PathArguments::AngleBracketed(angle_bracketed_generic_arguments) => { + for a in &angle_bracketed_generic_arguments.args { + match a { + syn::GenericArgument::Type(Type::Path(path)) => { + for s in &path.path.segments { + check_simple_type(s, is_simple, derived_type_names); + } + } + _ => *is_simple = false, + } + } + } + syn::PathArguments::Parenthesized(_) => *is_simple = false, + } + } +} + +impl<'ast, 'b> Visit<'ast> for StructVisitor<'ast, 'b> { + fn visit_item_struct(&mut self, node: &'ast ItemStruct) { + debug!("Visiting Struct name == {}", node.ident); + //debug!("Visiting Struct name == {:#?}", node); + let mut is_simple_leaf = true; + node.fields.iter().for_each(|f| match &f.ty { + Type::Path(path_type) => { + trace!( + "\twith field name = {:?} \n\t\tfield type = {:?}", + f.ident, f.ty + ); + + for segment in &path_type.path.segments { + check_simple_type(segment, &mut is_simple_leaf, self.derived_type_names); + } + } + + _ => { + is_simple_leaf = false; + } + }); + debug!( + "Visiting Struct name == {} is leaf {is_simple_leaf}", + node.ident + ); + if is_simple_leaf { + self.structs.push(node); + } + visit::visit_item_struct(self, node); + } +} + +impl VisitMut for StructRenamer { + fn visit_item_struct_mut(&mut self, node: &mut ItemStruct) { + debug!( + "Visiting and changing fields in struct name == {}", + node.ident + ); + + node.fields.iter_mut().for_each(|f| { + let ty = f.ty.clone(); + if let Type::Path(path_type) = &mut f.ty { + trace!( + "\twith field name = {:?} \n\t\tfield type = {:?}", + f.ident, ty + ); + + for segment in &mut path_type.path.segments { + self.changed |= rewrite_ident(segment, &self.names); + } + } + }); + + visit_mut::visit_item_struct_mut(self, node); + } +} + +fn break_into_words(type_name: &str) -> Vec { + let mut words = vec![]; + let mut current_word = String::new(); + + for t in type_name.chars().tuple_windows() { + let (current, next, next_next) = t; + if current.is_uppercase() { + if next.is_uppercase() { + current_word.push(current); + if !next_next.is_uppercase() { + words.push(current_word); + current_word = String::new(); + } + } else { + current_word.push(current); + } + } else { + current_word.push(current); + if next.is_uppercase() { + words.push(current_word); + current_word = String::new(); + } + } + } + let len = type_name.len() - 2; + if len > 0 { + current_word += &type_name[len..]; + words.push(current_word); + } else { + words.push(type_name.to_owned()); + } + + words +} + +pub fn common_words(words_sets: &[Vec]) -> Vec { + let word_sets: Vec> = words_sets + .iter() + .cloned() + .map(BTreeSet::from_iter) + .collect(); + + let mut intersection = if let Some(first) = word_sets.first() { + first.clone() + } else { + return vec![]; + }; + + for word_set in word_sets { + intersection = intersection.intersection(&word_set).cloned().collect(); + } + Vec::from_iter(intersection) +} + +fn create_type_name_substitute( + customized_names_from_file: &BTreeMap, + v: &[(Ident, ItemStruct)], +) -> String { + let words: Vec> = v + .iter() + .map(|v| break_into_words(&v.0.to_string())) + .collect(); + + let common_words = common_words(&words); + + let new_name = common_words.iter().cloned().collect::(); + + if let Some(customized_name) = customized_names_from_file.get(&new_name) { + customized_name.clone() + } else { + new_name + } +} + +fn read_type_mappings_from_file( + mapped_names: &Path, +) -> Result, Box> { + let mut mapped_types = BTreeMap::new(); + let mapped_names_file = std::fs::File::open(mapped_names)?; + for line in io::BufReader::new(mapped_names_file) + .lines() + .map_while(Result::ok) + { + let mut parts = line.split("->"); + if let (Some(type_name), Some(new_type_name)) = (parts.next(), parts.next()) { + mapped_types.insert(type_name.to_owned(), new_type_name.to_owned()); + } + } + Ok(mapped_types) +} + +fn read_type_names_from_file( + mapped_names: &Path, +) -> Result, Box> { + let mapped_names_file = std::fs::File::open(mapped_names)?; + Ok(io::BufReader::new(mapped_names_file) + .lines() + .map_while(Result::ok) + .collect::>()) +} + +fn write_type_names_to_file( + mapped_types: &BTreeMap, +) -> Result<(), Box> { + let mut mapped_names_file = std::fs::File::create("./mapped_names.txt")?; + for v in mapped_types.values().sorted().dedup() { + mapped_names_file.write_all(format!("{v}\n").as_bytes())?; + } + + let mut mapped_names_file = std::fs::File::create("./mapped_types_to_names.txt")?; + for (k, v) in mapped_types + .iter() + .sorted_by(|(_, this), (_, other)| this.cmp(other)) + { + mapped_names_file.write_all(format!("{k}->{v}\n").as_bytes())?; + } + Ok(()) +} + +fn delete_replaced_structs(file: File, type_names: Vec) -> File { + let File { + shebang, + attrs, + items, + } = file; + + let items = items + .into_iter() + .filter(|i| match i { + // delete top level items with ident that was replaced + Item::Struct(item) => { + if type_names.contains(&item.ident.to_string()) { + debug!("Deleting {}", item.ident); + false + } else { + true + } + } + _ => true, + }) + .collect(); + + File { + shebang, + attrs, + items, + } +} + +struct FindSimilarTypesResult { + visitors: Vec<(String, File)>, + similar_items: MultiMap, +} + +fn find_similar_types(visitors: Vec<(StructVisitor<'_, '_>, File)>) -> FindSimilarTypesResult { + let mut similar_items = MultiMap::new(); + + let visitors: Vec<_> = visitors + .into_iter() + .map(|(mut visitor, file)| { + visitor.visit_file(&file); + visitor.structs.into_iter().for_each(|i| { + similar_items.insert(i.fields.clone(), (i.ident.clone(), (*i).clone())); + }); + (visitor.name, file) + }) + .collect(); + + FindSimilarTypesResult { + visitors, + similar_items, + } +} + +fn prune_replaced_structs( + renaming_visitor: &mut StructRenamer, + visitors: Vec<(String, File)>, +) -> Vec<(String, String, bool)> { + visitors + .into_iter() + .map(|(name, mut f)| { + renaming_visitor.changed = false; + renaming_visitor.visit_file_mut(&mut f); + let new_file = + delete_replaced_structs(f, renaming_visitor.names.keys().cloned().collect()); + ( + name, + prettyplease::unparse(&new_file), + renaming_visitor.changed, + ) + }) + .collect() +} + +fn generate_file_preamble( + changed: bool, + content: &str, + output_path: &Path, + name: &str, +) -> Result> { + if changed { + info!("Writing changed file {name}"); + let mut out_file = std::fs::File::create(output_path.join(name))?; + if !content.starts_with(GENERATED_PREAMBLE) { + out_file.write_all(GENERATED_PREAMBLE.as_bytes())?; + } + + if !content.contains(COMMON_TYPES_USE_PREAMBLE) { + out_file.write_all(COMMON_TYPES_USE_PREAMBLE.as_bytes())?; + } + Ok(out_file) + } else { + info!("Writing NOT changed file {name}"); + let mut out_file = std::fs::File::create(output_path.join(name))?; + if !content.starts_with(GENERATED_PREAMBLE) { + out_file.write_all(GENERATED_PREAMBLE.as_bytes())?; + } + Ok(out_file) + } +} + +fn recreate_project_files( + out_dir: &str, + unparsed_files: Vec<(String, String, bool)>, + items: Vec, +) -> Result<(), Box> { + let common_types = prettyplease::unparse(&File { + shebang: None, + attrs: vec![], + items, + }); + + let output_path = std::path::Path::new(&out_dir); + if output_path.is_dir() && output_path.exists() { + info!("Writing changed file mod.rs"); + let mut mod_file = std::fs::File::create(output_path.join("mod.rs"))?; + mod_file.write_all(GENERATED_PREAMBLE.as_bytes())?; + + let mut mod_names = vec!["pub mod common_types;".to_owned()]; + + for (name, content, changed) in unparsed_files { + let mut out_file = generate_file_preamble(changed, &content, output_path, &name)?; + out_file.write_all(content.as_bytes())?; + mod_names.push(format!("pub mod {};", &name[..name.len() - 3])); + } + + for mod_name in mod_names.into_iter().sorted().dedup() { + mod_file.write_all((mod_name + "\n").as_bytes())?; + } + + let common_types_file_name = output_path.join("common_types.rs"); + + if common_types_file_name.exists() { + let mut common_out_file = OpenOptions::new() + .append(true) + .open(common_types_file_name)?; + + info!("Current position {}", common_out_file.stream_position()?); + + common_out_file.write_all("\n\n// Next attempt \n\n".as_bytes())?; + common_out_file.write_all(common_types.as_bytes())?; + } else { + let mut common_out_file = std::fs::File::create(common_types_file_name)?; + let common_types_file_content = + COMMON_TYPES_FILE_PREAMBLE.to_owned() + "\n\n\n" + &common_types; + common_out_file.write_all(common_types_file_content.as_bytes())?; + } + Ok(()) + } else { + Err("Make sure that output path is a folder and tha it exists".into()) + } +} + +fn create_common_type_struct(s: &ItemStruct, type_new_name: &str) -> ItemStruct { + let mut new_struct = s.clone(); + new_struct.attrs = s + .attrs + .iter() + .filter(|&a| a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site()))) + .cloned() + .collect(); + new_struct.fields = s.fields.clone(); + new_struct.fields.iter_mut().for_each(|f| { + f.attrs = f + .attrs + .clone() + .into_iter() + .filter(|a| a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site()))) + .collect::>() + }); + + new_struct.ident = Ident::new(type_new_name, Span::call_site()); + new_struct +} + +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +struct Args { + #[arg(long)] + apis_dir: String, + + #[arg(long)] + out_dir: String, + + #[arg(long)] + current_pass_substitute_names: Option, + + #[arg(long)] + previous_pass_derived_type_names: Option, +} + +#[cfg(test)] +mod tests { + use crate::break_into_words; + + #[test] + fn test_word_breaking() { + let expected_words = [ + "GRPC", "Route", "Rules", "Backend", "Refs", "Filters", "Request", "Mirror", "Backend", + "Ref", + ]; + let words = break_into_words("GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef"); + assert_eq!(expected_words.to_vec(), words); + + let expected_words = [ + "GRPC", "Route", "Rules", "Backend", "Refs", "Filters", "Request", "HTTPS", "Mirror", + "Backend", "Ref", + ]; + let words = + break_into_words("GRPCRouteRulesBackendRefsFiltersRequestHTTPSMirrorBackendRef"); + assert_eq!(expected_words.to_vec(), words); + + let expected_words = ["f", "RP"]; + let words = break_into_words("fRP"); + assert_eq!(expected_words.to_vec(), words); + } +} diff --git a/update.sh b/update.sh index 296806e..d7f1a78 100755 --- a/update.sh +++ b/update.sh @@ -47,6 +47,7 @@ EOF mkdir -p $APIS_DIR/standard/ mkdir -p $APIS_DIR/experimental/ + echo "// WARNING! generated file do not edit" > $APIS_DIR/standard/mod.rs for API in "${STANDARD_APIS[@]}" @@ -128,3 +129,13 @@ echo "pub mod constants;" >> $APIS_DIR/experimental/mod.rs # Format the code. cargo fmt + +rm -rf $APIS_DIR/processed +mkdir -p $APIS_DIR/processed +export RUST_LOG=info +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/processed --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_1.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_1.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_2.txt + +cat << EOF >> $APIS_DIR/mod.rs +pub mod processed; +EOF From 14199f1b7ad617a131216a32c6b3446fc8b15e97 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Mon, 9 Jun 2025 14:46:16 +0100 Subject: [PATCH 02/16] Added type reduction for enums and some more refactoring Signed-off-by: Dawid Nowak --- gateway-api/Cargo.toml | 9 +- .../src/apis/processed/common_types.rs | 104 +++- .../src/apis/processed/enum_defaults.rs | 50 +- gateway-api/src/apis/processed/grpcroutes.rs | 48 +- gateway-api/src/apis/processed/httproutes.rs | 146 +---- type-reducer/Cargo.toml | 2 +- ...tomized_mapped_names_pass_1_with_enums.txt | 12 + ...tomized_mapped_names_pass_2_with_enums.txt | 0 type-reducer/reduce_types.sh | 8 + .../reduced_types_pass_1_with_enums.txt | 12 + type-reducer/src/lib.rs | 445 ++++++++++++++ type-reducer/src/main.rs | 564 ++---------------- type-reducer/src/visitors.rs | 197 ++++++ update.sh | 16 + 14 files changed, 871 insertions(+), 742 deletions(-) create mode 100644 type-reducer/customized_mapped_names_pass_1_with_enums.txt create mode 100644 type-reducer/customized_mapped_names_pass_2_with_enums.txt create mode 100755 type-reducer/reduce_types.sh create mode 100644 type-reducer/reduced_types_pass_1_with_enums.txt create mode 100644 type-reducer/src/lib.rs create mode 100644 type-reducer/src/visitors.rs diff --git a/gateway-api/Cargo.toml b/gateway-api/Cargo.toml index 70286e8..8f0fe96 100644 --- a/gateway-api/Cargo.toml +++ b/gateway-api/Cargo.toml @@ -41,4 +41,11 @@ features = ["k8s-openapi/v1_32"] default = ["processed"] standard = [] experimental = [] -processed=[] \ No newline at end of file +processed=[] + + +[lints.clippy] +derivable_impls="allow" +doc_lazy_continuation="allow" +tabs_in_doc_comments="allow" +empty_line_after_doc_comments="allow" \ No newline at end of file diff --git a/gateway-api/src/apis/processed/common_types.rs b/gateway-api/src/apis/processed/common_types.rs index 19c5c1b..44e36cc 100644 --- a/gateway-api/src/apis/processed/common_types.rs +++ b/gateway-api/src/apis/processed/common_types.rs @@ -10,18 +10,7 @@ mod prelude { } use self::prelude::*; #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HeaderModifierRules { - pub name: String, - pub value: String, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct Kind { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - pub kind: String, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct MirrorBackendRef { +pub struct RouteRef { #[serde(default, skip_serializing_if = "Option::is_none")] pub group: Option, #[serde(default, skip_serializing_if = "Option::is_none")] @@ -31,9 +20,11 @@ pub struct MirrorBackendRef { pub namespace: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub port: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")] + pub section_name: Option, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct RouteRef { +pub struct MirrorBackendRef { #[serde(default, skip_serializing_if = "Option::is_none")] pub group: Option, #[serde(default, skip_serializing_if = "Option::is_none")] @@ -43,8 +34,18 @@ pub struct RouteRef { pub namespace: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub port: Option, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")] - pub section_name: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct Kind { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + pub kind: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct ExtensionBackendRef { + pub group: String, + pub kind: String, + pub name: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GatewayAddress { @@ -53,10 +54,77 @@ pub struct GatewayAddress { pub value: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct ExtensionBackendRef { - pub group: String, - pub kind: String, +pub struct HeaderModifierRules { pub name: String, + pub value: String, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum FiltersHTTPRedirectRequestRouteRulesScheme { + #[serde(rename = "http")] + Http, + #[serde(rename = "https")] + Https, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum CodeFiltersHTTPRedirectRequestRouteRulesStatus { + #[serde(rename = "301")] + r#_301, + #[serde(rename = "302")] + r#_302, +} +/// GRPCRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. GRPCRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum FiltersGRPCRouteRulesType { + ResponseHeaderModifier, + RequestHeaderModifier, + RequestMirror, + ExtensionRef, +} +/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request +/// headers. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum MatchesRouteRulesType { + Exact, + RegularExpression, +} +/// Path defines parameters used to modify the path of the incoming request. +/// The modified path is then used to construct the `Location` header. When +/// empty, the request path is used as-is. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum FiltersHTTPPathRouteRulesType { + ReplaceFullPath, + ReplacePrefixMatch, +} +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum FiltersHTTPRouteRulesType { + RequestHeaderModifier, + ResponseHeaderModifier, + RequestMirror, + RequestRedirect, + #[serde(rename = "URLRewrite")] + UrlRewrite, + ExtensionRef, } diff --git a/gateway-api/src/apis/processed/enum_defaults.rs b/gateway-api/src/apis/processed/enum_defaults.rs index 1fee271..d155cd8 100644 --- a/gateway-api/src/apis/processed/enum_defaults.rs +++ b/gateway-api/src/apis/processed/enum_defaults.rs @@ -1,50 +1,26 @@ -// WARNING! generated file do not edit +use super::common_types::*; +// WARNING: generated file - manual changes will be overriden -use super::httproutes::{ - HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType, - HTTPRouteRulesBackendRefsFiltersType, - HTTPRouteRulesBackendRefsFiltersUrlRewritePathType, - HTTPRouteRulesFiltersRequestRedirectPathType, HTTPRouteRulesFiltersType, - HTTPRouteRulesFiltersUrlRewritePathType, -}; -use super::grpcroutes::{GRPCRouteRulesBackendRefsFiltersType, GRPCRouteRulesFiltersType}; -impl Default for GRPCRouteRulesBackendRefsFiltersType { +impl Default for FiltersGRPCRouteRulesType { fn default() -> Self { - GRPCRouteRulesBackendRefsFiltersType::RequestHeaderModifier + FiltersGRPCRouteRulesType::RequestHeaderModifier } } -impl Default for GRPCRouteRulesFiltersType { - fn default() -> Self { - GRPCRouteRulesFiltersType::RequestHeaderModifier - } -} -impl Default for HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType { - fn default() -> Self { - HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType::ReplaceFullPath - } -} -impl Default for HTTPRouteRulesBackendRefsFiltersType { - fn default() -> Self { - HTTPRouteRulesBackendRefsFiltersType::RequestHeaderModifier - } -} -impl Default for HTTPRouteRulesBackendRefsFiltersUrlRewritePathType { - fn default() -> Self { - HTTPRouteRulesBackendRefsFiltersUrlRewritePathType::ReplaceFullPath - } -} -impl Default for HTTPRouteRulesFiltersRequestRedirectPathType { + +impl Default for FiltersHTTPPathRouteRulesType { fn default() -> Self { - HTTPRouteRulesFiltersRequestRedirectPathType::ReplaceFullPath + FiltersHTTPPathRouteRulesType::ReplaceFullPath } } -impl Default for HTTPRouteRulesFiltersType { + +impl Default for FiltersHTTPRedirectRequestRouteRulesScheme { fn default() -> Self { - HTTPRouteRulesFiltersType::RequestHeaderModifier + FiltersHTTPRedirectRequestRouteRulesScheme::Http } } -impl Default for HTTPRouteRulesFiltersUrlRewritePathType { + +impl Default for FiltersHTTPRouteRulesType { fn default() -> Self { - HTTPRouteRulesFiltersUrlRewritePathType::ReplaceFullPath + FiltersHTTPRouteRulesType::RequestHeaderModifier } } diff --git a/gateway-api/src/apis/processed/grpcroutes.rs b/gateway-api/src/apis/processed/grpcroutes.rs index 8c517f8..ddbb716 100644 --- a/gateway-api/src/apis/processed/grpcroutes.rs +++ b/gateway-api/src/apis/processed/grpcroutes.rs @@ -428,20 +428,7 @@ pub struct GRPCRouteRulesBackendRefsFilters { /// /// #[serde(rename = "type")] - pub r#type: GRPCRouteRulesBackendRefsFiltersType, -} -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesBackendRefsFiltersType { - ResponseHeaderModifier, - RequestHeaderModifier, - RequestMirror, - ExtensionRef, + pub r#type: FiltersGRPCRouteRulesType, } /// GRPCRouteFilter defines processing steps that must be completed during the /// request or response lifecycle. GRPCRouteFilters are meant as an extension @@ -521,20 +508,7 @@ pub struct GRPCRouteRulesFilters { /// /// #[serde(rename = "type")] - pub r#type: GRPCRouteRulesFiltersType, -} -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesFiltersType { - ResponseHeaderModifier, - RequestHeaderModifier, - RequestMirror, - ExtensionRef, + pub r#type: FiltersGRPCRouteRulesType, } /// GRPCRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will @@ -579,17 +553,10 @@ pub struct GRPCRouteRulesMatchesHeaders { pub name: String, /// Type specifies how to match against the value of the header. #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, + pub r#type: Option, /// Value is the value of the gRPC Header to be matched. pub value: String, } -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesMatchesHeadersType { - Exact, - RegularExpression, -} /// Method specifies a gRPC request service/method matcher. If this field is /// not specified, all services and methods will match. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] @@ -613,14 +580,7 @@ pub struct GRPCRouteRulesMatchesMethod { /// /// Support: Implementation-specific (RegularExpression) #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, -} -/// Method specifies a gRPC request service/method matcher. If this field is -/// not specified, all services and methods will match. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesMatchesMethodType { - Exact, - RegularExpression, + pub r#type: Option, } /// Status defines the current state of GRPCRoute. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] diff --git a/gateway-api/src/apis/processed/httproutes.rs b/gateway-api/src/apis/processed/httproutes.rs index 18944ba..7b737b8 100644 --- a/gateway-api/src/apis/processed/httproutes.rs +++ b/gateway-api/src/apis/processed/httproutes.rs @@ -478,7 +478,7 @@ pub struct HTTPRouteRulesBackendRefsFilters { /// Accepted Condition for the Route to `status: False`, with a /// Reason of `UnsupportedValue`. #[serde(rename = "type")] - pub r#type: HTTPRouteRulesBackendRefsFiltersType, + pub r#type: FiltersHTTPRouteRulesType, /// URLRewrite defines a schema for a filter that modifies a request during forwarding. /// /// Support: Extended @@ -544,7 +544,7 @@ pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirect { /// /// Support: Extended #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, + pub scheme: Option, /// StatusCode is the HTTP status code to be used in response. /// /// Note that values may be added to this enum, implementations @@ -605,55 +605,7 @@ pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirectPath { /// Accepted Condition for the Route to `status: False`, with a /// Reason of `UnsupportedValue`. #[serde(rename = "type")] - pub r#type: HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType, -} -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType { - ReplaceFullPath, - ReplacePrefixMatch, -} -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectScheme { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, -} -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectStatusCode { - #[serde(rename = "301")] - r#_301, - #[serde(rename = "302")] - r#_302, -} -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersType { - RequestHeaderModifier, - ResponseHeaderModifier, - RequestMirror, - RequestRedirect, - #[serde(rename = "URLRewrite")] - UrlRewrite, - ExtensionRef, + pub r#type: FiltersHTTPPathRouteRulesType, } /// URLRewrite defines a schema for a filter that modifies a request during forwarding. /// @@ -717,15 +669,7 @@ pub struct HTTPRouteRulesBackendRefsFiltersUrlRewritePath { /// Accepted Condition for the Route to `status: False`, with a /// Reason of `UnsupportedValue`. #[serde(rename = "type")] - pub r#type: HTTPRouteRulesBackendRefsFiltersUrlRewritePathType, -} -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersUrlRewritePathType { - ReplaceFullPath, - ReplacePrefixMatch, + pub r#type: FiltersHTTPPathRouteRulesType, } /// HTTPRouteFilter defines processing steps that must be completed during the /// request or response lifecycle. HTTPRouteFilters are meant as an extension @@ -821,7 +765,7 @@ pub struct HTTPRouteRulesFilters { /// Accepted Condition for the Route to `status: False`, with a /// Reason of `UnsupportedValue`. #[serde(rename = "type")] - pub r#type: HTTPRouteRulesFiltersType, + pub r#type: FiltersHTTPRouteRulesType, /// URLRewrite defines a schema for a filter that modifies a request during forwarding. /// /// Support: Extended @@ -887,7 +831,7 @@ pub struct HTTPRouteRulesFiltersRequestRedirect { /// /// Support: Extended #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, + pub scheme: Option, /// StatusCode is the HTTP status code to be used in response. /// /// Note that values may be added to this enum, implementations @@ -948,55 +892,7 @@ pub struct HTTPRouteRulesFiltersRequestRedirectPath { /// Accepted Condition for the Route to `status: False`, with a /// Reason of `UnsupportedValue`. #[serde(rename = "type")] - pub r#type: HTTPRouteRulesFiltersRequestRedirectPathType, -} -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersRequestRedirectPathType { - ReplaceFullPath, - ReplacePrefixMatch, -} -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersRequestRedirectScheme { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, -} -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersRequestRedirectStatusCode { - #[serde(rename = "301")] - r#_301, - #[serde(rename = "302")] - r#_302, -} -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersType { - RequestHeaderModifier, - ResponseHeaderModifier, - RequestMirror, - RequestRedirect, - #[serde(rename = "URLRewrite")] - UrlRewrite, - ExtensionRef, + pub r#type: FiltersHTTPPathRouteRulesType, } /// URLRewrite defines a schema for a filter that modifies a request during forwarding. /// @@ -1060,15 +956,7 @@ pub struct HTTPRouteRulesFiltersUrlRewritePath { /// Accepted Condition for the Route to `status: False`, with a /// Reason of `UnsupportedValue`. #[serde(rename = "type")] - pub r#type: HTTPRouteRulesFiltersUrlRewritePathType, -} -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersUrlRewritePathType { - ReplaceFullPath, - ReplacePrefixMatch, + pub r#type: FiltersHTTPPathRouteRulesType, } /// HTTPRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will @@ -1143,17 +1031,10 @@ pub struct HTTPRouteRulesMatchesHeaders { /// of regular expressions. Please read the implementation's documentation to /// determine the supported dialect. #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, + pub r#type: Option, /// Value is the value of HTTP Header to be matched. pub value: String, } -/// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesHeadersType { - Exact, - RegularExpression, -} /// HTTPRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will /// evaluate to true only if all conditions are satisfied. @@ -1248,17 +1129,10 @@ pub struct HTTPRouteRulesMatchesQueryParams { /// dialects of regular expressions. Please read the implementation's /// documentation to determine the supported dialect. #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, + pub r#type: Option, /// Value is the value of HTTP query param to be matched. pub value: String, } -/// HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP -/// query parameters. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesQueryParamsType { - Exact, - RegularExpression, -} /// Timeouts defines the timeouts that can be configured for an HTTP request. /// /// Support: Extended diff --git a/type-reducer/Cargo.toml b/type-reducer/Cargo.toml index c10d5de..a521d3a 100644 --- a/type-reducer/Cargo.toml +++ b/type-reducer/Cargo.toml @@ -2,7 +2,7 @@ name = "type-reducer" version = "0.1.0" edition = "2024" -author = "Dawid Nowak nowakd@gmail.com" +authors = ["Dawid Nowak nowakd@gmail.com"] [dependencies] syn = { version = "2", features = [ diff --git a/type-reducer/customized_mapped_names_pass_1_with_enums.txt b/type-reducer/customized_mapped_names_pass_1_with_enums.txt new file mode 100644 index 0000000..5f7a1c9 --- /dev/null +++ b/type-reducer/customized_mapped_names_pass_1_with_enums.txt @@ -0,0 +1,12 @@ +AddressesGateway->GatewayAddress +BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef +ExtensionFiltersRefRouteRules->ExtensionBackendRef +FiltersHeaderModifierRouteRules->HeaderModifierRules +GatewayKindsListeners->Kind +ParentRoute->RouteRef +CodeFiltersHTTPRedirectRequestRouteRulesStatus->RedirectStatusCode +FiltersGRPCRouteRulesType->GRPCFilterType +FiltersHTTPPathRouteRulesType->HTTPPathType +FiltersHTTPRedirectRequestRouteRulesScheme->HTTPRedirectScheme +FiltersHTTPRouteRulesType->HTTPFiltersType +MatchesRouteRulesType->HeaderMatchesType diff --git a/type-reducer/customized_mapped_names_pass_2_with_enums.txt b/type-reducer/customized_mapped_names_pass_2_with_enums.txt new file mode 100644 index 0000000..e69de29 diff --git a/type-reducer/reduce_types.sh b/type-reducer/reduce_types.sh new file mode 100755 index 0000000..f5e2702 --- /dev/null +++ b/type-reducer/reduce_types.sh @@ -0,0 +1,8 @@ +#!/bin/bash +rm -rf ../gateway-api/src/apis/processed +mkdir ../gateway-api/src/apis/processed +cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed +#cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --current-pass-substitute-names customized_mapped_names_pass_1_with_enums.txt +#cargo run -- --apis-dir ../gateway-api/src/apis/processed --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names reduced_types_pass_1_with_enums.txt --current-pass-substitute-names customized_mapped_names_pass_2_with_enums.txt + + diff --git a/type-reducer/reduced_types_pass_1_with_enums.txt b/type-reducer/reduced_types_pass_1_with_enums.txt new file mode 100644 index 0000000..9443bf7 --- /dev/null +++ b/type-reducer/reduced_types_pass_1_with_enums.txt @@ -0,0 +1,12 @@ +GatewayAddress +MirrorBackendRef +ExtensionBackendRef +HeaderModifierRules +Kind +RouteRef +RedirectStatusCode +GRPCFilterType +HTTPPathType +HTTPRedirectScheme +HTTPFiltersType +HeaderMatchesType diff --git a/type-reducer/src/lib.rs b/type-reducer/src/lib.rs new file mode 100644 index 0000000..53d01ec --- /dev/null +++ b/type-reducer/src/lib.rs @@ -0,0 +1,445 @@ +use std::collections::BTreeMap; +use std::collections::BTreeSet; + +use itertools::Itertools; +use log::debug; +use log::info; +use multimap::MultiMap; +use proc_macro2::{Ident, Span}; +use std::fs::OpenOptions; +use std::io; +use std::io::BufRead; +use std::io::Seek; +use std::io::Write; +use std::path::Path; +use syn::Fields; +use syn::File; +use syn::Item; +use syn::ItemEnum; +use syn::ItemStruct; +use syn::Variant; +use syn::punctuated::Punctuated; +use syn::token::Comma; + +use syn::visit::Visit; + +use syn::visit_mut::VisitMut; + +mod visitors; +pub use visitors::*; + +const COMMON_TYPES_FILE_PREAMBLE: &str = "#[allow(unused_imports)] +mod prelude { + pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; + pub use kube::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Deserialize, Serialize}; + pub use std::collections::BTreeMap; +} +use self::prelude::*;"; + +const COMMON_TYPES_USE_PREAMBLE: &str = "use super::common_types::*;"; +const GENERATED_PREAMBLE: &str = "// WARNING! generated file do not edit\n\n"; + +fn break_into_words(type_name: &str) -> Vec { + let mut words = vec![]; + let mut current_word = String::new(); + + for t in type_name.chars().tuple_windows() { + let (current, next, next_next) = t; + if current.is_uppercase() { + if next.is_uppercase() { + current_word.push(current); + if !next_next.is_uppercase() { + words.push(current_word); + current_word = String::new(); + } + } else { + current_word.push(current); + } + } else { + current_word.push(current); + if next.is_uppercase() { + words.push(current_word); + current_word = String::new(); + } + } + } + let len = type_name.len() - 2; + if len > 0 { + current_word += &type_name[len..]; + words.push(current_word); + } else { + words.push(type_name.to_owned()); + } + + words +} + +pub fn common_words(words_sets: &[Vec]) -> Vec { + let word_sets: Vec> = words_sets + .iter() + .cloned() + .map(BTreeSet::from_iter) + .collect(); + + let mut intersection = if let Some(first) = word_sets.first() { + first.clone() + } else { + return vec![]; + }; + + for word_set in word_sets { + intersection = intersection.intersection(&word_set).cloned().collect(); + } + Vec::from_iter(intersection) +} + +pub fn create_struct_type_name_substitute( + customized_names_from_file: &BTreeMap, + v: &[(Ident, ItemStruct)], +) -> String { + let words: Vec> = v + .iter() + .map(|v| break_into_words(&v.0.to_string())) + .collect(); + + let common_words = common_words(&words); + + let new_name = common_words.iter().cloned().collect::(); + + if let Some(customized_name) = customized_names_from_file.get(&new_name) { + customized_name.clone() + } else { + new_name + } +} + +pub fn create_enum_type_name_substitute( + customized_names_from_file: &BTreeMap, + v: &[(Ident, ItemEnum)], +) -> String { + let words: Vec> = v + .iter() + .map(|v| break_into_words(&v.0.to_string())) + .collect(); + + let common_words = common_words(&words); + + let new_name = common_words.iter().cloned().collect::(); + + if let Some(customized_name) = customized_names_from_file.get(&new_name) { + customized_name.clone() + } else { + new_name + } +} + +pub fn read_type_mappings_from_file( + mapped_names: &Path, +) -> Result, Box> { + let mut mapped_types = BTreeMap::new(); + let mapped_names_file = std::fs::File::open(mapped_names)?; + for line in io::BufReader::new(mapped_names_file) + .lines() + .map_while(Result::ok) + { + let mut parts = line.split("->"); + if let (Some(type_name), Some(new_type_name)) = (parts.next(), parts.next()) { + mapped_types.insert(type_name.to_owned(), new_type_name.to_owned()); + } + } + Ok(mapped_types) +} + +pub fn read_type_names_from_file( + mapped_names: &Path, +) -> Result, Box> { + let mapped_names_file = std::fs::File::open(mapped_names)?; + Ok(io::BufReader::new(mapped_names_file) + .lines() + .map_while(Result::ok) + .collect::>()) +} + +pub fn write_type_names_to_file( + mapped_types: &BTreeMap, +) -> Result<(), Box> { + let mut mapped_names_file = std::fs::File::create("./mapped_names.txt")?; + for v in mapped_types.values().sorted().dedup() { + mapped_names_file.write_all(format!("{v}\n").as_bytes())?; + } + + let mut mapped_names_file = std::fs::File::create("./mapped_types_to_names.txt")?; + for (k, v) in mapped_types + .iter() + .sorted_by(|(_, this), (_, other)| this.cmp(other)) + { + mapped_names_file.write_all(format!("{k}->{v}\n").as_bytes())?; + } + Ok(()) +} + +pub fn delete_replaced_structs(file: File, type_names: Vec) -> File { + let File { + shebang, + attrs, + items, + } = file; + + let items = items + .into_iter() + .filter(|i| match i { + // delete top level items with ident that was replaced + Item::Struct(item) => { + if type_names.contains(&item.ident.to_string()) { + debug!("Deleting {}", item.ident); + false + } else { + true + } + } + Item::Enum(item) => { + if type_names.contains(&item.ident.to_string()) { + debug!("Deleting {}", item.ident); + false + } else { + true + } + } + _ => true, + }) + .collect(); + + File { + shebang, + attrs, + items, + } +} + +pub struct FindSimilarTypesResult { + pub visitors: Vec<(String, File)>, + pub similar_structs: MultiMap, + pub similar_enums: MultiMap, (Ident, ItemEnum)>, +} + +pub fn find_similar_types( + visitors: Vec<(StructEnumVisitor<'_, '_>, File)>, +) -> FindSimilarTypesResult { + let mut similar_structs = MultiMap::new(); + let mut similar_enums = MultiMap::new(); + + let visitors: Vec<_> = visitors + .into_iter() + .map(|(mut visitor, file)| { + visitor.visit_file(&file); + visitor.structs.into_iter().for_each(|i| { + similar_structs.insert(i.fields.clone(), (i.ident.clone(), (*i).clone())); + }); + visitor.enums.into_iter().for_each(|i| { + similar_enums.insert(i.variants.clone(), (i.ident.clone(), (*i).clone())); + }); + (visitor.name, file) + }) + .collect(); + + FindSimilarTypesResult { + visitors, + similar_structs, + similar_enums, + } +} + +pub fn prune_replaced_structs( + renaming_visitor: &mut StructRenamer, + visitors: Vec<(String, File)>, +) -> Vec<(String, String, bool)> { + visitors + .into_iter() + .map(|(name, mut f)| { + renaming_visitor.changed = false; + renaming_visitor.visit_file_mut(&mut f); + let new_file = + delete_replaced_structs(f, renaming_visitor.names.keys().cloned().collect()); + ( + name, + prettyplease::unparse(&new_file), + renaming_visitor.changed, + ) + }) + .collect() +} + +fn generate_file_preamble( + changed: bool, + content: &str, + output_path: &Path, + name: &str, +) -> Result> { + if changed { + info!("Writing changed file {name}"); + let mut out_file = std::fs::File::create(output_path.join(name))?; + if !content.starts_with(GENERATED_PREAMBLE) { + out_file.write_all(GENERATED_PREAMBLE.as_bytes())?; + } + + if !content.contains(COMMON_TYPES_USE_PREAMBLE) { + out_file.write_all(COMMON_TYPES_USE_PREAMBLE.as_bytes())?; + } + Ok(out_file) + } else { + info!("Writing NOT changed file {name}"); + let mut out_file = std::fs::File::create(output_path.join(name))?; + if !content.starts_with(GENERATED_PREAMBLE) { + out_file.write_all(GENERATED_PREAMBLE.as_bytes())?; + } + Ok(out_file) + } +} + +pub fn recreate_project_files( + out_dir: &str, + unparsed_files: Vec<(String, String, bool)>, + items: Vec, +) -> Result<(), Box> { + let common_types = prettyplease::unparse(&File { + shebang: None, + attrs: vec![], + items, + }); + + let output_path = std::path::Path::new(&out_dir); + if output_path.is_dir() && output_path.exists() { + info!("Writing changed file mod.rs"); + let mut mod_file = std::fs::File::create(output_path.join("mod.rs"))?; + mod_file.write_all(GENERATED_PREAMBLE.as_bytes())?; + + let mut mod_names = vec!["pub mod common_types;".to_owned()]; + + for (name, content, changed) in unparsed_files { + let mut out_file = generate_file_preamble(changed, &content, output_path, &name)?; + out_file.write_all(content.as_bytes())?; + mod_names.push(format!("pub mod {};", &name[..name.len() - 3])); + } + + for mod_name in mod_names.into_iter().sorted().dedup() { + mod_file.write_all((mod_name + "\n").as_bytes())?; + } + + let common_types_file_name = output_path.join("common_types.rs"); + + if common_types_file_name.exists() { + let mut common_out_file = OpenOptions::new() + .append(true) + .open(common_types_file_name)?; + + info!("Current position {}", common_out_file.stream_position()?); + + common_out_file.write_all("\n\n// Next attempt \n\n".as_bytes())?; + common_out_file.write_all(common_types.as_bytes())?; + } else { + let mut common_out_file = std::fs::File::create(common_types_file_name)?; + let common_types_file_content = + COMMON_TYPES_FILE_PREAMBLE.to_owned() + "\n\n\n" + &common_types; + common_out_file.write_all(common_types_file_content.as_bytes())?; + } + Ok(()) + } else { + Err("Make sure that output path is a folder and tha it exists".into()) + } +} + +pub fn create_common_type_struct(s: &ItemStruct, type_new_name: &str) -> ItemStruct { + let mut new_struct = s.clone(); + new_struct.attrs = s + .attrs + .iter() + .filter(|&a| a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site()))) + .cloned() + .collect(); + new_struct.fields = s.fields.clone(); + new_struct.fields.iter_mut().for_each(|f| { + f.attrs = f + .attrs + .clone() + .into_iter() + .filter(|a| a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site()))) + .collect::>() + }); + + new_struct.ident = Ident::new(type_new_name, Span::call_site()); + new_struct +} + +pub fn create_common_type_enum(s: &ItemEnum, type_new_name: &str) -> ItemEnum { + let mut new_enum = s.clone(); + + // new_enum.attrs = s + // .attrs + // .iter() + // .filter(|&a| a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site()))) + // .cloned() + // .collect(); + // new_enum.attrs = s.attrs.clone(); + // let attributes: Vec<_> = new_enum + // .attrs + // .iter_mut() + // .filter(|a| { + // if let Ok(s) = a.meta.require_list() { + // if let Some(s) = s.path.segments.first() { + // s.ident == Ident::new("derive", Span::call_site()) + // } else { + // false + // } + // } else { + // false + // } + // }) + // .map(|a| { + // let mut new_attr = a.clone(); + // if let Ok(s) = a.meta.require_list() { + // let mut new_meta = s.clone(); + // let mut new_tokens = new_meta.tokens.clone(); + // //new_tokens.extend(TokenStream::from_str(", Default").unwrap()); + // new_meta.tokens = new_tokens; + // warn!("Enum tokens {:?}", new_meta.tokens.to_string()); + // new_attr.meta = Meta::List(new_meta); + // } + // new_attr + // }) + // .collect(); + + // new_enum.attrs = attributes; + // warn!("New enum = {:?}", new_enum); + + new_enum.ident = Ident::new(type_new_name, Span::call_site()); + new_enum +} + +#[cfg(test)] +mod tests { + use crate::break_into_words; + + #[test] + fn test_word_breaking() { + let expected_words = [ + "GRPC", "Route", "Rules", "Backend", "Refs", "Filters", "Request", "Mirror", "Backend", + "Ref", + ]; + let words = break_into_words("GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef"); + assert_eq!(expected_words.to_vec(), words); + + let expected_words = [ + "GRPC", "Route", "Rules", "Backend", "Refs", "Filters", "Request", "HTTPS", "Mirror", + "Backend", "Ref", + ]; + let words = + break_into_words("GRPCRouteRulesBackendRefsFiltersRequestHTTPSMirrorBackendRef"); + assert_eq!(expected_words.to_vec(), words); + + let expected_words = ["f", "RP"]; + let words = break_into_words("fRP"); + assert_eq!(expected_words.to_vec(), words); + } +} diff --git a/type-reducer/src/main.rs b/type-reducer/src/main.rs index c54cf6f..ad31940 100644 --- a/type-reducer/src/main.rs +++ b/type-reducer/src/main.rs @@ -1,44 +1,27 @@ +use clap::Parser; +use log::info; use std::collections::BTreeMap; use std::collections::BTreeSet; use std::fs; -use std::fs::OpenOptions; -use std::io; -use std::io::Seek; -use std::io::Write; -use std::path::Path; use std::path::PathBuf; - -use clap::Parser; -use clap::command; -use itertools::Itertools; -use log::debug; -use log::info; -use log::trace; -use multimap::MultiMap; -use proc_macro2::{Ident, Span}; -use std::io::BufRead; -use syn::Fields; -use syn::File; use syn::Item; -use syn::ItemStruct; -use syn::PathSegment; -use syn::Type; -use syn::visit::{self, Visit}; -use syn::visit_mut; -use syn::visit_mut::VisitMut; +use type_reducer::*; -const COMMON_TYPES_FILE_PREAMBLE: &str = "#[allow(unused_imports)] -mod prelude { - pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; - pub use kube::CustomResource; - pub use schemars::JsonSchema; - pub use serde::{Deserialize, Serialize}; - pub use std::collections::BTreeMap; -} -use self::prelude::*;"; +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +struct Args { + #[arg(long)] + apis_dir: String, + + #[arg(long)] + out_dir: String, + + #[arg(long)] + current_pass_substitute_names: Option, -const COMMON_TYPES_USE_PREAMBLE: &str = "use super::common_types::*;"; -const GENERATED_PREAMBLE: &str = "// WARNING! generated file do not edit\n\n"; + #[arg(long)] + previous_pass_derived_type_names: Option, +} fn main() -> Result<(), Box> { simple_logger::init_with_env().unwrap(); @@ -79,9 +62,10 @@ fn main() -> Result<(), Box> { info!("Adding file {:?}", dir_entry.path()); if let Ok(api_file) = fs::read_to_string(dir_entry.path()) { if let Ok(syntaxt_file) = syn::parse_file(&api_file) { - let visitor = StructVisitor { + let visitor = StructEnumVisitor { name, structs: Vec::new(), + enums: Vec::new(), derived_type_names: &previous_pass_derived_type_names, }; visitors.push((visitor, syntaxt_file)); @@ -93,10 +77,11 @@ fn main() -> Result<(), Box> { let FindSimilarTypesResult { visitors, - similar_items, + similar_structs, + similar_enums, } = find_similar_types(visitors); - let items: Vec<_> = similar_items + let struct_items: Vec<_> = similar_structs .iter_all() .filter(|(_k, v)| v.len() > 1) .filter_map(|(_k, v)| { @@ -106,7 +91,8 @@ fn main() -> Result<(), Box> { ); let mapped_type_names = v.iter().map(|v| v.0.to_string()).collect::>(); - let type_new_name = create_type_name_substitute(¤t_pass_type_name_substitutes, v); + let type_new_name = + create_struct_type_name_substitute(¤t_pass_type_name_substitutes, v); if let Some((_i, s)) = v.first() { let new_struct = create_common_type_struct(s, &type_new_name); @@ -128,486 +114,54 @@ fn main() -> Result<(), Box> { }) .collect(); - let (mapped_types, items): (Vec>, Vec) = - items.into_iter().unzip(); - - let mut renaming_visitor = StructRenamer { - changed: false, - names: mapped_types.into_iter().flatten().collect(), - }; - - if current_pass_substitute_names.is_none() { - write_type_names_to_file(&renaming_visitor.names)? - }; - - let unparsed_files = prune_replaced_structs(&mut renaming_visitor, visitors); - - recreate_project_files(&out_dir, unparsed_files, items) -} - -struct StructVisitor<'ast, 'b> { - name: String, - structs: Vec<&'ast ItemStruct>, - derived_type_names: &'b BTreeSet, -} - -struct StructRenamer { - changed: bool, - names: BTreeMap, -} - -fn rewrite_ident(path: &mut PathSegment, names: &BTreeMap) -> bool { - let mut file_changed = false; - if path.arguments.is_empty() { - let ident = &path.ident; - if let Some(new_name) = names.get(&ident.to_string()) { - path.ident = Ident::new(new_name, Span::call_site()); - file_changed = true; - } - } else { - match path.arguments { - syn::PathArguments::None => {} - syn::PathArguments::AngleBracketed(ref mut angle_bracketed_generic_arguments) => { - for a in angle_bracketed_generic_arguments.args.iter_mut() { - if let syn::GenericArgument::Type(Type::Path(path)) = a { - for s in path.path.segments.iter_mut() { - file_changed |= rewrite_ident(s, names); - } - } - } - } - syn::PathArguments::Parenthesized(_) => {} - } - } - file_changed -} - -fn check_simple_type( - path: &PathSegment, - is_simple: &mut bool, - derived_type_names: &BTreeSet, -) { - if path.arguments.is_empty() { - let ident = &path.ident; - if ident == &Ident::new("String", Span::call_site()) - || ident == &Ident::new("i32", Span::call_site()) - || ident == &Ident::new("i64", Span::call_site()) - || derived_type_names.contains(&ident.to_string()) - { - } else { - *is_simple = false; - } - } else { - match &path.arguments { - syn::PathArguments::None => *is_simple = false, - syn::PathArguments::AngleBracketed(angle_bracketed_generic_arguments) => { - for a in &angle_bracketed_generic_arguments.args { - match a { - syn::GenericArgument::Type(Type::Path(path)) => { - for s in &path.path.segments { - check_simple_type(s, is_simple, derived_type_names); - } - } - _ => *is_simple = false, - } - } - } - syn::PathArguments::Parenthesized(_) => *is_simple = false, - } - } -} - -impl<'ast, 'b> Visit<'ast> for StructVisitor<'ast, 'b> { - fn visit_item_struct(&mut self, node: &'ast ItemStruct) { - debug!("Visiting Struct name == {}", node.ident); - //debug!("Visiting Struct name == {:#?}", node); - let mut is_simple_leaf = true; - node.fields.iter().for_each(|f| match &f.ty { - Type::Path(path_type) => { - trace!( - "\twith field name = {:?} \n\t\tfield type = {:?}", - f.ident, f.ty - ); - - for segment in &path_type.path.segments { - check_simple_type(segment, &mut is_simple_leaf, self.derived_type_names); - } - } - - _ => { - is_simple_leaf = false; - } - }); - debug!( - "Visiting Struct name == {} is leaf {is_simple_leaf}", - node.ident - ); - if is_simple_leaf { - self.structs.push(node); - } - visit::visit_item_struct(self, node); - } -} - -impl VisitMut for StructRenamer { - fn visit_item_struct_mut(&mut self, node: &mut ItemStruct) { - debug!( - "Visiting and changing fields in struct name == {}", - node.ident - ); - - node.fields.iter_mut().for_each(|f| { - let ty = f.ty.clone(); - if let Type::Path(path_type) = &mut f.ty { - trace!( - "\twith field name = {:?} \n\t\tfield type = {:?}", - f.ident, ty - ); - - for segment in &mut path_type.path.segments { - self.changed |= rewrite_ident(segment, &self.names); - } - } - }); + let enum_items: Vec<_> = similar_enums + .iter_all() + .filter(|(_k, v)| v.len() > 1) + .filter_map(|(_k, v)| { + info!( + "Potentially similar enums {:#?}", + v.iter().map(|(i, _)| i.to_string()).collect::>() + ); + let mapped_type_names = v.iter().map(|v| v.0.to_string()).collect::>(); - visit_mut::visit_item_struct_mut(self, node); - } -} + let type_new_name = + create_enum_type_name_substitute(¤t_pass_type_name_substitutes, v); -fn break_into_words(type_name: &str) -> Vec { - let mut words = vec![]; - let mut current_word = String::new(); + if let Some((_i, s)) = v.first() { + let new_enum = create_common_type_enum(s, &type_new_name); - for t in type_name.chars().tuple_windows() { - let (current, next, next_next) = t; - if current.is_uppercase() { - if next.is_uppercase() { - current_word.push(current); - if !next_next.is_uppercase() { - words.push(current_word); - current_word = String::new(); + let mut mapped = BTreeMap::new(); + for mapped_type_name in mapped_type_names { + mapped.insert(mapped_type_name, new_enum.ident.to_string().to_owned()); } - } else { - current_word.push(current); - } - } else { - current_word.push(current); - if next.is_uppercase() { - words.push(current_word); - current_word = String::new(); - } - } - } - let len = type_name.len() - 2; - if len > 0 { - current_word += &type_name[len..]; - words.push(current_word); - } else { - words.push(type_name.to_owned()); - } - - words -} - -pub fn common_words(words_sets: &[Vec]) -> Vec { - let word_sets: Vec> = words_sets - .iter() - .cloned() - .map(BTreeSet::from_iter) - .collect(); - - let mut intersection = if let Some(first) = word_sets.first() { - first.clone() - } else { - return vec![]; - }; - for word_set in word_sets { - intersection = intersection.intersection(&word_set).cloned().collect(); - } - Vec::from_iter(intersection) -} - -fn create_type_name_substitute( - customized_names_from_file: &BTreeMap, - v: &[(Ident, ItemStruct)], -) -> String { - let words: Vec> = v - .iter() - .map(|v| break_into_words(&v.0.to_string())) - .collect(); - - let common_words = common_words(&words); - - let new_name = common_words.iter().cloned().collect::(); - - if let Some(customized_name) = customized_names_from_file.get(&new_name) { - customized_name.clone() - } else { - new_name - } -} - -fn read_type_mappings_from_file( - mapped_names: &Path, -) -> Result, Box> { - let mut mapped_types = BTreeMap::new(); - let mapped_names_file = std::fs::File::open(mapped_names)?; - for line in io::BufReader::new(mapped_names_file) - .lines() - .map_while(Result::ok) - { - let mut parts = line.split("->"); - if let (Some(type_name), Some(new_type_name)) = (parts.next(), parts.next()) { - mapped_types.insert(type_name.to_owned(), new_type_name.to_owned()); - } - } - Ok(mapped_types) -} - -fn read_type_names_from_file( - mapped_names: &Path, -) -> Result, Box> { - let mapped_names_file = std::fs::File::open(mapped_names)?; - Ok(io::BufReader::new(mapped_names_file) - .lines() - .map_while(Result::ok) - .collect::>()) -} - -fn write_type_names_to_file( - mapped_types: &BTreeMap, -) -> Result<(), Box> { - let mut mapped_names_file = std::fs::File::create("./mapped_names.txt")?; - for v in mapped_types.values().sorted().dedup() { - mapped_names_file.write_all(format!("{v}\n").as_bytes())?; - } - - let mut mapped_names_file = std::fs::File::create("./mapped_types_to_names.txt")?; - for (k, v) in mapped_types - .iter() - .sorted_by(|(_, this), (_, other)| this.cmp(other)) - { - mapped_names_file.write_all(format!("{k}->{v}\n").as_bytes())?; - } - Ok(()) -} - -fn delete_replaced_structs(file: File, type_names: Vec) -> File { - let File { - shebang, - attrs, - items, - } = file; - - let items = items - .into_iter() - .filter(|i| match i { - // delete top level items with ident that was replaced - Item::Struct(item) => { - if type_names.contains(&item.ident.to_string()) { - debug!("Deleting {}", item.ident); - false + info!("Mapped types = {:#?}", &mapped); + if mapped.keys().len() < 2 { + None } else { - true + Some((mapped, Item::Enum(new_enum))) } + } else { + None } - _ => true, - }) - .collect(); - - File { - shebang, - attrs, - items, - } -} - -struct FindSimilarTypesResult { - visitors: Vec<(String, File)>, - similar_items: MultiMap, -} - -fn find_similar_types(visitors: Vec<(StructVisitor<'_, '_>, File)>) -> FindSimilarTypesResult { - let mut similar_items = MultiMap::new(); - - let visitors: Vec<_> = visitors - .into_iter() - .map(|(mut visitor, file)| { - visitor.visit_file(&file); - visitor.structs.into_iter().for_each(|i| { - similar_items.insert(i.fields.clone(), (i.ident.clone(), (*i).clone())); - }); - (visitor.name, file) }) .collect(); - FindSimilarTypesResult { - visitors, - similar_items, - } -} - -fn prune_replaced_structs( - renaming_visitor: &mut StructRenamer, - visitors: Vec<(String, File)>, -) -> Vec<(String, String, bool)> { - visitors - .into_iter() - .map(|(name, mut f)| { - renaming_visitor.changed = false; - renaming_visitor.visit_file_mut(&mut f); - let new_file = - delete_replaced_structs(f, renaming_visitor.names.keys().cloned().collect()); - ( - name, - prettyplease::unparse(&new_file), - renaming_visitor.changed, - ) - }) - .collect() -} - -fn generate_file_preamble( - changed: bool, - content: &str, - output_path: &Path, - name: &str, -) -> Result> { - if changed { - info!("Writing changed file {name}"); - let mut out_file = std::fs::File::create(output_path.join(name))?; - if !content.starts_with(GENERATED_PREAMBLE) { - out_file.write_all(GENERATED_PREAMBLE.as_bytes())?; - } - - if !content.contains(COMMON_TYPES_USE_PREAMBLE) { - out_file.write_all(COMMON_TYPES_USE_PREAMBLE.as_bytes())?; - } - Ok(out_file) - } else { - info!("Writing NOT changed file {name}"); - let mut out_file = std::fs::File::create(output_path.join(name))?; - if !content.starts_with(GENERATED_PREAMBLE) { - out_file.write_all(GENERATED_PREAMBLE.as_bytes())?; - } - Ok(out_file) - } -} - -fn recreate_project_files( - out_dir: &str, - unparsed_files: Vec<(String, String, bool)>, - items: Vec, -) -> Result<(), Box> { - let common_types = prettyplease::unparse(&File { - shebang: None, - attrs: vec![], - items, - }); - - let output_path = std::path::Path::new(&out_dir); - if output_path.is_dir() && output_path.exists() { - info!("Writing changed file mod.rs"); - let mut mod_file = std::fs::File::create(output_path.join("mod.rs"))?; - mod_file.write_all(GENERATED_PREAMBLE.as_bytes())?; - - let mut mod_names = vec!["pub mod common_types;".to_owned()]; - - for (name, content, changed) in unparsed_files { - let mut out_file = generate_file_preamble(changed, &content, output_path, &name)?; - out_file.write_all(content.as_bytes())?; - mod_names.push(format!("pub mod {};", &name[..name.len() - 3])); - } - - for mod_name in mod_names.into_iter().sorted().dedup() { - mod_file.write_all((mod_name + "\n").as_bytes())?; - } - - let common_types_file_name = output_path.join("common_types.rs"); - - if common_types_file_name.exists() { - let mut common_out_file = OpenOptions::new() - .append(true) - .open(common_types_file_name)?; - - info!("Current position {}", common_out_file.stream_position()?); - - common_out_file.write_all("\n\n// Next attempt \n\n".as_bytes())?; - common_out_file.write_all(common_types.as_bytes())?; - } else { - let mut common_out_file = std::fs::File::create(common_types_file_name)?; - let common_types_file_content = - COMMON_TYPES_FILE_PREAMBLE.to_owned() + "\n\n\n" + &common_types; - common_out_file.write_all(common_types_file_content.as_bytes())?; - } - Ok(()) - } else { - Err("Make sure that output path is a folder and tha it exists".into()) - } -} - -fn create_common_type_struct(s: &ItemStruct, type_new_name: &str) -> ItemStruct { - let mut new_struct = s.clone(); - new_struct.attrs = s - .attrs - .iter() - .filter(|&a| a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site()))) - .cloned() - .collect(); - new_struct.fields = s.fields.clone(); - new_struct.fields.iter_mut().for_each(|f| { - f.attrs = f - .attrs - .clone() - .into_iter() - .filter(|a| a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site()))) - .collect::>() - }); - - new_struct.ident = Ident::new(type_new_name, Span::call_site()); - new_struct -} - -#[derive(Parser, Debug)] -#[command(version, about, long_about = None)] -struct Args { - #[arg(long)] - apis_dir: String, - - #[arg(long)] - out_dir: String, - - #[arg(long)] - current_pass_substitute_names: Option, - - #[arg(long)] - previous_pass_derived_type_names: Option, -} + let (mapped_types, items): (Vec>, Vec) = + struct_items.into_iter().chain(enum_items).unzip(); + // let (mapped_types, items): (Vec>, Vec) = + // all_items.into_iter().unzip(); -#[cfg(test)] -mod tests { - use crate::break_into_words; + let mut renaming_visitor = StructRenamer { + changed: false, + names: mapped_types.into_iter().flatten().collect(), + }; - #[test] - fn test_word_breaking() { - let expected_words = [ - "GRPC", "Route", "Rules", "Backend", "Refs", "Filters", "Request", "Mirror", "Backend", - "Ref", - ]; - let words = break_into_words("GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef"); - assert_eq!(expected_words.to_vec(), words); + if current_pass_substitute_names.is_none() { + write_type_names_to_file(&renaming_visitor.names)? + }; - let expected_words = [ - "GRPC", "Route", "Rules", "Backend", "Refs", "Filters", "Request", "HTTPS", "Mirror", - "Backend", "Ref", - ]; - let words = - break_into_words("GRPCRouteRulesBackendRefsFiltersRequestHTTPSMirrorBackendRef"); - assert_eq!(expected_words.to_vec(), words); + let unparsed_files = prune_replaced_structs(&mut renaming_visitor, visitors); - let expected_words = ["f", "RP"]; - let words = break_into_words("fRP"); - assert_eq!(expected_words.to_vec(), words); - } + recreate_project_files(&out_dir, unparsed_files, items) } diff --git a/type-reducer/src/visitors.rs b/type-reducer/src/visitors.rs new file mode 100644 index 0000000..4be2f9f --- /dev/null +++ b/type-reducer/src/visitors.rs @@ -0,0 +1,197 @@ +use log::debug; +use log::info; +use log::trace; +use proc_macro2::{Ident, Span}; +use std::collections::BTreeMap; +use std::collections::BTreeSet; +use syn::Fields; +use syn::ItemEnum; +use syn::ItemStruct; +use syn::PathSegment; +use syn::Type; +use syn::visit; +use syn::visit::Visit; +use syn::visit_mut; + +use syn::visit_mut::VisitMut; + +pub struct StructVisitor<'ast, 'b> { + pub name: String, + pub structs: Vec<&'ast ItemStruct>, + pub derived_type_names: &'b BTreeSet, +} + +pub struct StructEnumVisitor<'ast, 'b> { + pub name: String, + pub structs: Vec<&'ast ItemStruct>, + pub enums: Vec<&'ast ItemEnum>, + pub derived_type_names: &'b BTreeSet, +} + +pub struct StructRenamer { + pub changed: bool, + pub names: BTreeMap, +} + +fn rewrite_ident(path: &mut PathSegment, names: &BTreeMap) -> bool { + let mut file_changed = false; + if path.arguments.is_empty() { + let ident = &path.ident; + if let Some(new_name) = names.get(&ident.to_string()) { + path.ident = Ident::new(new_name, Span::call_site()); + file_changed = true; + } + } else { + match path.arguments { + syn::PathArguments::None => {} + syn::PathArguments::AngleBracketed(ref mut angle_bracketed_generic_arguments) => { + for a in angle_bracketed_generic_arguments.args.iter_mut() { + if let syn::GenericArgument::Type(Type::Path(path)) = a { + for s in path.path.segments.iter_mut() { + file_changed |= rewrite_ident(s, names); + } + } + } + } + syn::PathArguments::Parenthesized(_) => {} + } + } + file_changed +} + +impl<'ast, 'b> Visit<'ast> for StructVisitor<'ast, 'b> { + fn visit_item_struct(&mut self, node: &'ast ItemStruct) { + debug!("Visiting Struct name == {}", node.ident); + //debug!("Visiting Struct name == {:#?}", node); + let mut is_simple_leaf = true; + node.fields.iter().for_each(|f| match &f.ty { + Type::Path(path_type) => { + trace!( + "\twith field name = {:?} \n\t\tfield type = {:?}", + f.ident, f.ty + ); + + for segment in &path_type.path.segments { + check_simple_type(segment, &mut is_simple_leaf, self.derived_type_names); + } + } + + _ => { + is_simple_leaf = false; + } + }); + debug!( + "Visiting Struct name == {} is leaf {is_simple_leaf}", + node.ident + ); + if is_simple_leaf { + self.structs.push(node); + } + visit::visit_item_struct(self, node); + } +} + +impl<'ast, 'b> Visit<'ast> for StructEnumVisitor<'ast, 'b> { + fn visit_item_struct(&mut self, node: &'ast ItemStruct) { + debug!("Visiting Struct name == {}", node.ident); + //debug!("Visiting Struct name == {:#?}", node); + let mut is_simple_leaf = true; + node.fields.iter().for_each(|f| match &f.ty { + Type::Path(path_type) => { + trace!( + "\twith field name = {:?} \n\t\tfield type = {:?}", + f.ident, f.ty + ); + + for segment in &path_type.path.segments { + check_simple_type(segment, &mut is_simple_leaf, self.derived_type_names); + } + } + + _ => { + is_simple_leaf = false; + } + }); + debug!( + "Visiting Struct name == {} is leaf {is_simple_leaf}", + node.ident + ); + if is_simple_leaf { + self.structs.push(node); + } + visit::visit_item_struct(self, node); + } + + fn visit_item_enum(&mut self, node: &'ast ItemEnum) { + info!("Visiting Enum name == {} {:?}", node.ident, node.variants); + + if node + .variants + .iter() + .map(|f| &f.fields) + .all(|f| *f == Fields::Unit) + { + self.enums.push(node); + } + } +} + +impl VisitMut for StructRenamer { + fn visit_item_struct_mut(&mut self, node: &mut ItemStruct) { + debug!( + "Visiting and changing fields in struct name == {}", + node.ident + ); + + node.fields.iter_mut().for_each(|f| { + let ty = f.ty.clone(); + if let Type::Path(path_type) = &mut f.ty { + trace!( + "\twith field name = {:?} \n\t\tfield type = {:?}", + f.ident, ty + ); + + for segment in &mut path_type.path.segments { + self.changed |= rewrite_ident(segment, &self.names); + } + } + }); + + visit_mut::visit_item_struct_mut(self, node); + } +} + +fn check_simple_type( + path: &PathSegment, + is_simple: &mut bool, + derived_type_names: &BTreeSet, +) { + if path.arguments.is_empty() { + let ident = &path.ident; + if ident == &Ident::new("String", Span::call_site()) + || ident == &Ident::new("i32", Span::call_site()) + || ident == &Ident::new("i64", Span::call_site()) + || derived_type_names.contains(&ident.to_string()) + { + } else { + *is_simple = false; + } + } else { + match &path.arguments { + syn::PathArguments::None => *is_simple = false, + syn::PathArguments::AngleBracketed(angle_bracketed_generic_arguments) => { + for a in &angle_bracketed_generic_arguments.args { + match a { + syn::GenericArgument::Type(Type::Path(path)) => { + for s in &path.path.segments { + check_simple_type(s, is_simple, derived_type_names); + } + } + _ => *is_simple = false, + } + } + } + syn::PathArguments::Parenthesized(_) => *is_simple = false, + } + } +} diff --git a/update.sh b/update.sh index d7f1a78..3eb595e 100755 --- a/update.sh +++ b/update.sh @@ -139,3 +139,19 @@ cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/proces cat << EOF >> $APIS_DIR/mod.rs pub mod processed; EOF + +ENUMS=( + FiltersHTTPRedirectRequestRouteRulesScheme=Http + FiltersGRPCRouteRulesType=RequestHeaderModifier + FiltersHTTPPathRouteRulesType=ReplaceFullPath + FiltersHTTPRouteRulesType=RequestHeaderModifier +) + +ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}") +ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1} +echo "use super::common_types::*;" > $APIS_DIR/processed/enum_defaults.rs +GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/processed/enum_defaults.rs + + + + From 514bc63e907bc517c59edb4de5c0ae4b14f3c6a8 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Tue, 10 Jun 2025 21:22:53 +0100 Subject: [PATCH 03/16] Reducing common struct types Signed-off-by: Dawid Nowak --- gateway-api/src/apis/mod.rs | 1 + .../src/apis/processed/common_types.rs | 220 ++++-- .../src/apis/processed/enum_defaults.rs | 18 +- gateway-api/src/apis/processed/grpcroutes.rs | 215 +----- gateway-api/src/apis/processed/httproutes.rs | 629 +----------------- type-reducer/README.md | 38 ++ .../customized_mapped_names_pass_1.txt | 6 - ...tomized_mapped_names_pass_1_with_enums.txt | 10 +- .../customized_mapped_names_pass_2.txt | 3 - ...tomized_mapped_names_pass_2_with_enums.txt | 17 + ...tomized_mapped_names_pass_3_with_enums.txt | 20 + ...tomized_mapped_names_pass_4_with_enums.txt | 21 + type-reducer/mapped_names.txt | 3 + type-reducer/mapped_types_to_names.txt | 16 + type-reducer/reduce_types.sh | 9 +- .../reduced_types_pass_0_with_enums.txt | 1 + type-reducer/reduced_types_pass_1.txt | 7 - .../reduced_types_pass_1_with_enums.txt | 11 +- .../reduced_types_pass_2_with_enums.txt | 17 + .../reduced_types_pass_3_with_enums.txt | 23 + .../reduced_types_pass_4_with_enums.txt | 22 + type-reducer/src/lib.rs | 2 +- type-reducer/src/main.rs | 8 +- type-reducer/src/visitors.rs | 44 +- update.sh | 29 +- 25 files changed, 403 insertions(+), 987 deletions(-) create mode 100644 type-reducer/README.md delete mode 100644 type-reducer/customized_mapped_names_pass_1.txt delete mode 100644 type-reducer/customized_mapped_names_pass_2.txt create mode 100644 type-reducer/customized_mapped_names_pass_3_with_enums.txt create mode 100644 type-reducer/customized_mapped_names_pass_4_with_enums.txt create mode 100644 type-reducer/mapped_names.txt create mode 100644 type-reducer/mapped_types_to_names.txt create mode 100644 type-reducer/reduced_types_pass_0_with_enums.txt delete mode 100644 type-reducer/reduced_types_pass_1.txt create mode 100644 type-reducer/reduced_types_pass_2_with_enums.txt create mode 100644 type-reducer/reduced_types_pass_3_with_enums.txt create mode 100644 type-reducer/reduced_types_pass_4_with_enums.txt diff --git a/gateway-api/src/apis/mod.rs b/gateway-api/src/apis/mod.rs index 70353fa..1eb5595 100644 --- a/gateway-api/src/apis/mod.rs +++ b/gateway-api/src/apis/mod.rs @@ -1,3 +1,4 @@ pub mod experimental; pub mod standard; + pub mod processed; diff --git a/gateway-api/src/apis/processed/common_types.rs b/gateway-api/src/apis/processed/common_types.rs index 44e36cc..1c4a064 100644 --- a/gateway-api/src/apis/processed/common_types.rs +++ b/gateway-api/src/apis/processed/common_types.rs @@ -10,18 +10,9 @@ mod prelude { } use self::prelude::*; #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct RouteRef { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, +pub struct HTTPHeader { pub name: String, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")] - pub section_name: Option, + pub value: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct MirrorBackendRef { @@ -42,105 +33,210 @@ pub struct Kind { pub kind: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct ExtensionBackendRef { - pub group: String, - pub kind: String, - pub name: String, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GatewayAddress { #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] pub r#type: Option, pub value: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HeaderModifierRules { +pub struct RouteRef { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, pub name: String, - pub value: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")] + pub section_name: Option, } -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct ExtensionBackendRef { + pub group: String, + pub kind: String, + pub name: String, +} +/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request +/// headers. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HeaderMatchesType { + Exact, + RegularExpression, +} +/// Path defines parameters used to modify the path of the incoming request. +/// The modified path is then used to construct the `Location` header. When +/// empty, the request path is used as-is. /// -/// Support: Core +/// Support: Extended #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum FiltersHTTPRedirectRequestRouteRulesScheme { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, +pub enum HTTPPathType { + ReplaceFullPath, + ReplacePrefixMatch, } /// RequestRedirect defines a schema for a filter that responds to the /// request with an HTTP redirection. /// /// Support: Core #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum CodeFiltersHTTPRedirectRequestRouteRulesStatus { +pub enum RedirectStatusCode { #[serde(rename = "301")] r#_301, #[serde(rename = "302")] r#_302, } -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension /// point to express processing that may be done in Gateway implementations. Some /// examples include request or response modification, implementing /// authentication strategies, rate-limiting, and traffic shaping. API /// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum FiltersGRPCRouteRulesType { - ResponseHeaderModifier, +pub enum HTTPFilterType { RequestHeaderModifier, + ResponseHeaderModifier, RequestMirror, + RequestRedirect, + #[serde(rename = "URLRewrite")] + UrlRewrite, ExtensionRef, } -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum MatchesRouteRulesType { - Exact, - RegularExpression, -} -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. /// -/// Support: Extended +/// Support: Core #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum FiltersHTTPPathRouteRulesType { - ReplaceFullPath, - ReplacePrefixMatch, +pub enum HTTPRedirectScheme { + #[serde(rename = "http")] + Http, + #[serde(rename = "https")] + Https, } -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// GRPCRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. GRPCRouteFilters are meant as an extension /// point to express processing that may be done in Gateway implementations. Some /// examples include request or response modification, implementing /// authentication strategies, rate-limiting, and traffic shaping. API /// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum FiltersHTTPRouteRulesType { - RequestHeaderModifier, +pub enum GRPCFilterType { ResponseHeaderModifier, + RequestHeaderModifier, RequestMirror, - RequestRedirect, - #[serde(rename = "URLRewrite")] - UrlRewrite, ExtensionRef, } - - -// Next attempt - #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct FilterMirrorRouteRules { +pub struct ParentsRouteStatus { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub conditions: Option>, + #[serde(rename = "controllerName")] + pub controller_name: String, + #[serde(rename = "parentRef")] + pub parent_ref: RouteRef, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPPathModifier { + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replaceFullPath" + )] + pub replace_full_path: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replacePrefixMatch" + )] + pub replace_prefix_match: Option, + #[serde(rename = "type")] + pub r#type: HTTPPathType, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HeaderModifier { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub add: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub remove: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub set: Option>, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RequestMirrorModifier { #[serde(rename = "backendRef")] pub backend_ref: MirrorBackendRef, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct FilterHeaderRouteRules { +pub struct HTTPRequestRewrite { #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, + pub hostname: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, + pub path: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRequestRedirect { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, + pub path: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub scheme: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "statusCode")] + pub status_code: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteFilter { + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + #[serde(rename = "type")] + pub r#type: GRPCFilterType, +} + + +// Next attempt + +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteFilter { + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestRedirect" + )] + pub request_redirect: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + #[serde(rename = "type")] + pub r#type: HTTPFilterType, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] + pub url_rewrite: Option, } diff --git a/gateway-api/src/apis/processed/enum_defaults.rs b/gateway-api/src/apis/processed/enum_defaults.rs index d155cd8..6aa5d2b 100644 --- a/gateway-api/src/apis/processed/enum_defaults.rs +++ b/gateway-api/src/apis/processed/enum_defaults.rs @@ -1,26 +1,20 @@ use super::common_types::*; // WARNING: generated file - manual changes will be overriden -impl Default for FiltersGRPCRouteRulesType { +impl Default for GRPCFilterType { fn default() -> Self { - FiltersGRPCRouteRulesType::RequestHeaderModifier + GRPCFilterType::RequestHeaderModifier } } -impl Default for FiltersHTTPPathRouteRulesType { +impl Default for HTTPFilterType { fn default() -> Self { - FiltersHTTPPathRouteRulesType::ReplaceFullPath + HTTPFilterType::RequestHeaderModifier } } -impl Default for FiltersHTTPRedirectRequestRouteRulesScheme { +impl Default for HTTPPathType { fn default() -> Self { - FiltersHTTPRedirectRequestRouteRulesScheme::Http - } -} - -impl Default for FiltersHTTPRouteRulesType { - fn default() -> Self { - FiltersHTTPRouteRulesType::RequestHeaderModifier + HTTPPathType::ReplaceFullPath } } diff --git a/gateway-api/src/apis/processed/grpcroutes.rs b/gateway-api/src/apis/processed/grpcroutes.rs index ddbb716..8cc090e 100644 --- a/gateway-api/src/apis/processed/grpcroutes.rs +++ b/gateway-api/src/apis/processed/grpcroutes.rs @@ -208,7 +208,7 @@ pub struct GRPCRouteRules { /// /// Support: Core #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Matches define conditions used for matching the rule against incoming /// gRPC requests. Each match is independent, i.e. this rule will be matched /// if **any** one of the matches is satisfied. @@ -293,7 +293,7 @@ pub struct GRPCRouteRulesBackendRefs { /// Support: Implementation-specific (For broader support of filters, use the /// Filters field in GRPCRouteRule.) #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Group is the group of the referent. For example, "gateway.networking.k8s.io". /// When unspecified or empty string, core API group is inferred. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -350,166 +350,6 @@ pub struct GRPCRouteRulesBackendRefs { #[serde(default, skip_serializing_if = "Option::is_none")] pub weight: Option, } -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// Support: Implementation-specific - /// - /// This filter can be used multiple times within the same rule. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] - pub request_mirror: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations supporting GRPCRoute MUST support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` MUST be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// - #[serde(rename = "type")] - pub r#type: FiltersGRPCRouteRulesType, -} -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// Support: Implementation-specific - /// - /// This filter can be used multiple times within the same rule. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] - pub request_mirror: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations supporting GRPCRoute MUST support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` MUST be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// - #[serde(rename = "type")] - pub r#type: FiltersGRPCRouteRulesType, -} /// GRPCRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will /// evaluate to true only if all conditions are satisfied. @@ -553,7 +393,7 @@ pub struct GRPCRouteRulesMatchesHeaders { pub name: String, /// Type specifies how to match against the value of the header. #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, + pub r#type: Option, /// Value is the value of the gRPC Header to be matched. pub value: String, } @@ -580,7 +420,7 @@ pub struct GRPCRouteRulesMatchesMethod { /// /// Support: Implementation-specific (RegularExpression) #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, + pub r#type: Option, } /// Status defines the current state of GRPCRoute. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] @@ -599,50 +439,5 @@ pub struct GRPCRouteStatus { /// /// A maximum of 32 Gateways will be represented in this list. An empty list /// means the route has not been attached to any Gateway. - pub parents: Vec, -} -/// RouteParentStatus describes the status of a route with respect to an -/// associated Parent. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteStatusParents { - /// Conditions describes the status of the route with respect to the Gateway. - /// Note that the route's availability is also subject to the Gateway's own - /// status conditions and listener status. - /// - /// If the Route's ParentRef specifies an existing Gateway that supports - /// Routes of this kind AND that Gateway's controller has sufficient access, - /// then that Gateway's controller MUST set the "Accepted" condition on the - /// Route, to indicate whether the route has been accepted or rejected by the - /// Gateway, and why. - /// - /// A Route MUST be considered "Accepted" if at least one of the Route's - /// rules is implemented by the Gateway. - /// - /// There are a number of cases where the "Accepted" condition may not be set - /// due to lack of controller visibility, that includes when: - /// - /// * The Route refers to a non-existent parent. - /// * The Route is of a type that the controller does not support. - /// * The Route is in a namespace the controller does not have access to. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// ControllerName is a domain/path string that indicates the name of the - /// controller that wrote this status. This corresponds with the - /// controllerName field on GatewayClass. - /// - /// Example: "example.net/gateway-controller". - /// - /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are - /// valid Kubernetes names - /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). - /// - /// Controllers MUST populate this field when writing status. Controllers should ensure that - /// entries to status populated with their ControllerName are cleaned up when they are no - /// longer necessary. - #[serde(rename = "controllerName")] - pub controller_name: String, - /// ParentRef corresponds with a ParentRef in the spec that this - /// RouteParentStatus struct describes the status of. - #[serde(rename = "parentRef")] - pub parent_ref: RouteRef, + pub parents: Vec, } diff --git a/gateway-api/src/apis/processed/httproutes.rs b/gateway-api/src/apis/processed/httproutes.rs index 7b737b8..fca9649 100644 --- a/gateway-api/src/apis/processed/httproutes.rs +++ b/gateway-api/src/apis/processed/httproutes.rs @@ -230,7 +230,7 @@ pub struct HTTPRouteRules { /// /// Support: Core #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Matches define conditions used for matching the rule against incoming /// HTTP requests. Each match is independent, i.e. this rule will be matched /// if **any** one of the matches is satisfied. @@ -327,7 +327,7 @@ pub struct HTTPRouteRulesBackendRefs { /// Support: Implementation-specific (For broader support of filters, use the /// Filters field in HTTPRouteRule.) #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Group is the group of the referent. For example, "gateway.networking.k8s.io". /// When unspecified or empty string, core API group is inferred. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -384,580 +384,6 @@ pub struct HTTPRouteRulesBackendRefs { #[serde(default, skip_serializing_if = "Option::is_none")] pub weight: Option, } -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// This filter can be used multiple times within the same rule. - /// - /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] - pub request_mirror: Option, - /// RequestRedirect defines a schema for a filter that responds to the - /// request with an HTTP redirection. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestRedirect" - )] - pub request_redirect: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations must support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by - /// specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` should be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: FiltersHTTPRouteRulesType, - /// URLRewrite defines a schema for a filter that modifies a request during forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] - pub url_rewrite: Option, -} -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirect { - /// Hostname is the hostname to be used in the value of the `Location` - /// header in the response. - /// When empty, the hostname in the `Host` header of the request is used. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines parameters used to modify the path of the incoming request. - /// The modified path is then used to construct the `Location` header. When - /// empty, the request path is used as-is. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, - /// Port is the port to be used in the value of the `Location` - /// header in the response. - /// - /// If no port is specified, the redirect port MUST be derived using the - /// following rules: - /// - /// * If redirect scheme is not-empty, the redirect port MUST be the well-known - /// port associated with the redirect scheme. Specifically "http" to port 80 - /// and "https" to port 443. If the redirect scheme does not have a - /// well-known port, the listener port of the Gateway SHOULD be used. - /// * If redirect scheme is empty, the redirect port MUST be the Gateway - /// Listener port. - /// - /// Implementations SHOULD NOT add the port number in the 'Location' - /// header in the following cases: - /// - /// * A Location header that will use HTTP (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 80. - /// * A Location header that will use HTTPS (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 443. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Scheme is the scheme to be used in the value of the `Location` header in - /// the response. When empty, the scheme of the request is used. - /// - /// Scheme redirects can affect the port of the redirect, for more information, - /// refer to the documentation for the port field of this filter. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, - /// StatusCode is the HTTP status code to be used in response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none", rename = "statusCode")] - pub status_code: Option, -} -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirectPath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: FiltersHTTPPathRouteRulesType, -} -/// URLRewrite defines a schema for a filter that modifies a request during forwarding. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersUrlRewrite { - /// Hostname is the value to be used to replace the Host header value during - /// forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines a path rewrite. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, -} -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersUrlRewritePath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: FiltersHTTPPathRouteRulesType, -} -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// This filter can be used multiple times within the same rule. - /// - /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] - pub request_mirror: Option, - /// RequestRedirect defines a schema for a filter that responds to the - /// request with an HTTP redirection. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestRedirect" - )] - pub request_redirect: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations must support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by - /// specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` should be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: FiltersHTTPRouteRulesType, - /// URLRewrite defines a schema for a filter that modifies a request during forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] - pub url_rewrite: Option, -} -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestRedirect { - /// Hostname is the hostname to be used in the value of the `Location` - /// header in the response. - /// When empty, the hostname in the `Host` header of the request is used. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines parameters used to modify the path of the incoming request. - /// The modified path is then used to construct the `Location` header. When - /// empty, the request path is used as-is. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, - /// Port is the port to be used in the value of the `Location` - /// header in the response. - /// - /// If no port is specified, the redirect port MUST be derived using the - /// following rules: - /// - /// * If redirect scheme is not-empty, the redirect port MUST be the well-known - /// port associated with the redirect scheme. Specifically "http" to port 80 - /// and "https" to port 443. If the redirect scheme does not have a - /// well-known port, the listener port of the Gateway SHOULD be used. - /// * If redirect scheme is empty, the redirect port MUST be the Gateway - /// Listener port. - /// - /// Implementations SHOULD NOT add the port number in the 'Location' - /// header in the following cases: - /// - /// * A Location header that will use HTTP (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 80. - /// * A Location header that will use HTTPS (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 443. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Scheme is the scheme to be used in the value of the `Location` header in - /// the response. When empty, the scheme of the request is used. - /// - /// Scheme redirects can affect the port of the redirect, for more information, - /// refer to the documentation for the port field of this filter. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, - /// StatusCode is the HTTP status code to be used in response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none", rename = "statusCode")] - pub status_code: Option, -} -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestRedirectPath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: FiltersHTTPPathRouteRulesType, -} -/// URLRewrite defines a schema for a filter that modifies a request during forwarding. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersUrlRewrite { - /// Hostname is the value to be used to replace the Host header value during - /// forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines a path rewrite. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, -} -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersUrlRewritePath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: FiltersHTTPPathRouteRulesType, -} /// HTTPRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will /// evaluate to true only if all conditions are satisfied. @@ -1031,7 +457,7 @@ pub struct HTTPRouteRulesMatchesHeaders { /// of regular expressions. Please read the implementation's documentation to /// determine the supported dialect. #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, + pub r#type: Option, /// Value is the value of HTTP Header to be matched. pub value: String, } @@ -1129,7 +555,7 @@ pub struct HTTPRouteRulesMatchesQueryParams { /// dialects of regular expressions. Please read the implementation's /// documentation to determine the supported dialect. #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, + pub r#type: Option, /// Value is the value of HTTP query param to be matched. pub value: String, } @@ -1201,50 +627,5 @@ pub struct HTTPRouteStatus { /// /// A maximum of 32 Gateways will be represented in this list. An empty list /// means the route has not been attached to any Gateway. - pub parents: Vec, -} -/// RouteParentStatus describes the status of a route with respect to an -/// associated Parent. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteStatusParents { - /// Conditions describes the status of the route with respect to the Gateway. - /// Note that the route's availability is also subject to the Gateway's own - /// status conditions and listener status. - /// - /// If the Route's ParentRef specifies an existing Gateway that supports - /// Routes of this kind AND that Gateway's controller has sufficient access, - /// then that Gateway's controller MUST set the "Accepted" condition on the - /// Route, to indicate whether the route has been accepted or rejected by the - /// Gateway, and why. - /// - /// A Route MUST be considered "Accepted" if at least one of the Route's - /// rules is implemented by the Gateway. - /// - /// There are a number of cases where the "Accepted" condition may not be set - /// due to lack of controller visibility, that includes when: - /// - /// * The Route refers to a non-existent parent. - /// * The Route is of a type that the controller does not support. - /// * The Route is in a namespace the controller does not have access to. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// ControllerName is a domain/path string that indicates the name of the - /// controller that wrote this status. This corresponds with the - /// controllerName field on GatewayClass. - /// - /// Example: "example.net/gateway-controller". - /// - /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are - /// valid Kubernetes names - /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). - /// - /// Controllers MUST populate this field when writing status. Controllers should ensure that - /// entries to status populated with their ControllerName are cleaned up when they are no - /// longer necessary. - #[serde(rename = "controllerName")] - pub controller_name: String, - /// ParentRef corresponds with a ParentRef in the spec that this - /// RouteParentStatus struct describes the status of. - #[serde(rename = "parentRef")] - pub parent_ref: RouteRef, + pub parents: Vec, } diff --git a/type-reducer/README.md b/type-reducer/README.md new file mode 100644 index 0000000..c9488c9 --- /dev/null +++ b/type-reducer/README.md @@ -0,0 +1,38 @@ +# ast_parser + +Usage : + +Will create common types and create APIs using those. Additionally will output the mapped types to "./mapped_types_to_names.txt" and "./mapped_names.txt" files. ./mapped_names.txt can be use as a source to provide some customer/more sensible substitutes for type names in step two. + +1. Step 1 - Reducing leaf types, all structs that only simple types or arrays of simple types such as String, u32, etc. +```bash +cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names mapped_names.txt --current-pass-derived-type-prefix=Common +``` + +2. Step 2 (Optional) +Create a file with new type names. The file format is like this: +``` +# type_name->new_type_name where type_name is taken from ./mapped_names.txt + +CommonAddressesGateway->AddressGateway +CommonBackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef +CommonExtensionFiltersRefRouteRules->FilterExtensionRef +CommonFiltersHeaderModifierRouteRules->HeaderModifier +CommonGatewayKindsListeners->ListenerRouteKinds +CommonParentRoute->ParentRef + +``` +3. Step 3 (Optional) + +Will read a file specified by --with-substitute-names and try to use those names as substitutions when modifying the APIs. + +```bash +cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --with-substitute-names ./custom_mapped_names.txt +``` + +4. Step 4(Optional) - Reducing types further + +```bash +cargo run -- --apis-dir ../gateway-api/src/apis/processed --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names mapped_names.txt --current-pass-derived-type-prefix=Common +``` + diff --git a/type-reducer/customized_mapped_names_pass_1.txt b/type-reducer/customized_mapped_names_pass_1.txt deleted file mode 100644 index 661940f..0000000 --- a/type-reducer/customized_mapped_names_pass_1.txt +++ /dev/null @@ -1,6 +0,0 @@ -AddressesGateway->GatewayAddress -BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef -ExtensionFiltersRefRouteRules->ExtensionBackendRef -FiltersHeaderModifierRouteRules->HeaderModifierRules -GatewayKindsListeners->Kind -ParentRoute->RouteRef diff --git a/type-reducer/customized_mapped_names_pass_1_with_enums.txt b/type-reducer/customized_mapped_names_pass_1_with_enums.txt index 5f7a1c9..9f83c5c 100644 --- a/type-reducer/customized_mapped_names_pass_1_with_enums.txt +++ b/type-reducer/customized_mapped_names_pass_1_with_enums.txt @@ -1,12 +1,12 @@ AddressesGateway->GatewayAddress BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef -ExtensionFiltersRefRouteRules->ExtensionBackendRef -FiltersHeaderModifierRouteRules->HeaderModifierRules -GatewayKindsListeners->Kind -ParentRoute->RouteRef CodeFiltersHTTPRedirectRequestRouteRulesStatus->RedirectStatusCode +ExtensionFiltersRefRouteRules->ExtensionBackendRef FiltersGRPCRouteRulesType->GRPCFilterType FiltersHTTPPathRouteRulesType->HTTPPathType FiltersHTTPRedirectRequestRouteRulesScheme->HTTPRedirectScheme -FiltersHTTPRouteRulesType->HTTPFiltersType +FiltersHTTPRouteRulesType->HTTPFilterType +FiltersHeaderModifierRouteRules->HTTPHeader +GatewayKindsListeners->Kind MatchesRouteRulesType->HeaderMatchesType +ParentRoute->RouteRef diff --git a/type-reducer/customized_mapped_names_pass_2.txt b/type-reducer/customized_mapped_names_pass_2.txt deleted file mode 100644 index af1d7aa..0000000 --- a/type-reducer/customized_mapped_names_pass_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -FiltersHeaderModifierRouteRules->FilterHeaderRouteRules -FiltersMirrorRequestRouteRules->FilterMirrorRouteRules - diff --git a/type-reducer/customized_mapped_names_pass_2_with_enums.txt b/type-reducer/customized_mapped_names_pass_2_with_enums.txt index e69de29..6d9c741 100644 --- a/type-reducer/customized_mapped_names_pass_2_with_enums.txt +++ b/type-reducer/customized_mapped_names_pass_2_with_enums.txt @@ -0,0 +1,17 @@ +AddressesGateway->GatewayAddress +BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef +CodeFiltersHTTPRedirectRequestRouteRulesStatus->RedirectStatusCode +ExtensionFiltersRefRouteRules->ExtensionBackendRef +FiltersGRPCRouteRulesType->GRPCFilterType +FiltersHTTPPathRouteRulesType->HTTPPathType +FiltersHTTPRedirectRequestRouteRulesScheme->HTTPRedirectScheme +FiltersHTTPRouteRulesType->HTTPFilterType +FiltersHeaderModifierRouteRules->HTTPHeader +GatewayKindsListeners->Kind +MatchesRouteRulesType->HeaderMatchesType +ParentRoute->RouteRef +FiltersHTTPPathRouteRules->HTTPPathModifier +FiltersHeaderModifierRouteRules->HeaderModifier +FiltersMirrorRequestRouteRules->RequestMirrorModifier + + diff --git a/type-reducer/customized_mapped_names_pass_3_with_enums.txt b/type-reducer/customized_mapped_names_pass_3_with_enums.txt new file mode 100644 index 0000000..e205c9e --- /dev/null +++ b/type-reducer/customized_mapped_names_pass_3_with_enums.txt @@ -0,0 +1,20 @@ +AddressesGateway->GatewayAddress +BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef +CodeFiltersHTTPRedirectRequestRouteRulesStatus->RedirectStatusCode +ExtensionFiltersRefRouteRules->ExtensionBackendRef +FiltersGRPCRouteRulesType->GRPCFilterType +FiltersHTTPPathRouteRulesType->HTTPPathType +FiltersHTTPRedirectRequestRouteRulesScheme->HTTPRedirectScheme +FiltersHTTPRouteRulesType->HTTPFilterType +FiltersHeaderModifierRouteRules->HTTPHeader +GatewayKindsListeners->Kind +MatchesRouteRulesType->HeaderMatchesType +ParentRoute->RouteRef +FiltersHTTPPathRouteRules->HTTPPathModifier +FiltersHeaderModifierRouteRules->HeaderModifier +FiltersMirrorRequestRouteRules->RequestMirrorModifier +FiltersGRPCRouteRules->GRPCRouteFilter +FiltersHTTPRedirectRequestRouteRules->HTTPRequestRedirect +FiltersHTTPRewriteRouteRulesUrl->HTTPRequestRewrite + + diff --git a/type-reducer/customized_mapped_names_pass_4_with_enums.txt b/type-reducer/customized_mapped_names_pass_4_with_enums.txt new file mode 100644 index 0000000..ced4de1 --- /dev/null +++ b/type-reducer/customized_mapped_names_pass_4_with_enums.txt @@ -0,0 +1,21 @@ +AddressesGateway->GatewayAddress +BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef +CodeFiltersHTTPRedirectRequestRouteRulesStatus->RedirectStatusCode +ExtensionFiltersRefRouteRules->ExtensionBackendRef +FiltersGRPCRouteRulesType->GRPCFilterType +FiltersHTTPPathRouteRulesType->HTTPPathType +FiltersHTTPRedirectRequestRouteRulesScheme->HTTPRedirectScheme +FiltersHTTPRouteRulesType->HTTPFilterType +FiltersHeaderModifierRouteRules->HTTPHeader +GatewayKindsListeners->Kind +MatchesRouteRulesTypey->HeaderMatchesType +ParentRoute->RouteRef +FiltersHTTPPathRouteRules->HTTPPathModifier +FiltersHeaderModifierRouteRules->HeaderModifier +FiltersMirrorRequestRouteRules->RequestMirrorModifier +FiltersGRPCRouteRules->GRPCRouteFilter +FiltersHTTPRedirectRequestRouteRules->HTTPRequestRedirect +FiltersHTTPRewriteRouteRulesUrl->HTTPRequestRewrite +FiltersHTTPRouteRules->HTTPRouteFilter + + diff --git a/type-reducer/mapped_names.txt b/type-reducer/mapped_names.txt new file mode 100644 index 0000000..1ed2ca8 --- /dev/null +++ b/type-reducer/mapped_names.txt @@ -0,0 +1,3 @@ +FiltersHTTPPathRouteRules +FiltersHeaderModifierRouteRules +FiltersMirrorRequestRouteRules diff --git a/type-reducer/mapped_types_to_names.txt b/type-reducer/mapped_types_to_names.txt new file mode 100644 index 0000000..8adb3b5 --- /dev/null +++ b/type-reducer/mapped_types_to_names.txt @@ -0,0 +1,16 @@ +HTTPRouteRulesBackendRefsFiltersRequestRedirectPath->FiltersHTTPPathRouteRules +HTTPRouteRulesBackendRefsFiltersUrlRewritePath->FiltersHTTPPathRouteRules +HTTPRouteRulesFiltersRequestRedirectPath->FiltersHTTPPathRouteRules +HTTPRouteRulesFiltersUrlRewritePath->FiltersHTTPPathRouteRules +GRPCRouteRulesBackendRefsFiltersRequestHeaderModifier->FiltersHeaderModifierRouteRules +GRPCRouteRulesBackendRefsFiltersResponseHeaderModifier->FiltersHeaderModifierRouteRules +GRPCRouteRulesFiltersRequestHeaderModifier->FiltersHeaderModifierRouteRules +GRPCRouteRulesFiltersResponseHeaderModifier->FiltersHeaderModifierRouteRules +HTTPRouteRulesBackendRefsFiltersRequestHeaderModifier->FiltersHeaderModifierRouteRules +HTTPRouteRulesBackendRefsFiltersResponseHeaderModifier->FiltersHeaderModifierRouteRules +HTTPRouteRulesFiltersRequestHeaderModifier->FiltersHeaderModifierRouteRules +HTTPRouteRulesFiltersResponseHeaderModifier->FiltersHeaderModifierRouteRules +GRPCRouteRulesBackendRefsFiltersRequestMirror->FiltersMirrorRequestRouteRules +GRPCRouteRulesFiltersRequestMirror->FiltersMirrorRequestRouteRules +HTTPRouteRulesBackendRefsFiltersRequestMirror->FiltersMirrorRequestRouteRules +HTTPRouteRulesFiltersRequestMirror->FiltersMirrorRequestRouteRules diff --git a/type-reducer/reduce_types.sh b/type-reducer/reduce_types.sh index f5e2702..252945a 100755 --- a/type-reducer/reduce_types.sh +++ b/type-reducer/reduce_types.sh @@ -1,8 +1,9 @@ #!/bin/bash rm -rf ../gateway-api/src/apis/processed mkdir ../gateway-api/src/apis/processed -cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed -#cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --current-pass-substitute-names customized_mapped_names_pass_1_with_enums.txt -#cargo run -- --apis-dir ../gateway-api/src/apis/processed --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names reduced_types_pass_1_with_enums.txt --current-pass-substitute-names customized_mapped_names_pass_2_with_enums.txt - +#cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed +echo "\n\n PHASE 1\n\n" +cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --current-pass-substitute-names customized_mapped_names_pass_1_with_enums.txt --previous-pass-derived-type-names reduced_types_pass_0_with_enums.txt +echo "\n\n PHASE 2\n\n" +cargo run -- --apis-dir ../gateway-api/src/apis/processed --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names reduced_types_pass_1_with_enums.txt --current-pass-substitute-names customized_mapped_names_pass_2_with_enums.txt diff --git a/type-reducer/reduced_types_pass_0_with_enums.txt b/type-reducer/reduced_types_pass_0_with_enums.txt new file mode 100644 index 0000000..b2f52f2 --- /dev/null +++ b/type-reducer/reduced_types_pass_0_with_enums.txt @@ -0,0 +1 @@ +Condition diff --git a/type-reducer/reduced_types_pass_1.txt b/type-reducer/reduced_types_pass_1.txt deleted file mode 100644 index ed5258e..0000000 --- a/type-reducer/reduced_types_pass_1.txt +++ /dev/null @@ -1,7 +0,0 @@ -GatewayAddress -MirrorBackendRef -ExtensionBackendRef -HeaderModifierRules -Kind -ParentRouteRef - diff --git a/type-reducer/reduced_types_pass_1_with_enums.txt b/type-reducer/reduced_types_pass_1_with_enums.txt index 9443bf7..e085284 100644 --- a/type-reducer/reduced_types_pass_1_with_enums.txt +++ b/type-reducer/reduced_types_pass_1_with_enums.txt @@ -1,12 +1,13 @@ +Condition GatewayAddress MirrorBackendRef -ExtensionBackendRef -HeaderModifierRules -Kind -RouteRef RedirectStatusCode +ExtensionBackendRef GRPCFilterType HTTPPathType HTTPRedirectScheme -HTTPFiltersType +HTTPFilterType +HTTPHeader +Kind HeaderMatchesType +RouteRef diff --git a/type-reducer/reduced_types_pass_2_with_enums.txt b/type-reducer/reduced_types_pass_2_with_enums.txt new file mode 100644 index 0000000..e0dd85d --- /dev/null +++ b/type-reducer/reduced_types_pass_2_with_enums.txt @@ -0,0 +1,17 @@ +Condition +GatewayAddress +MirrorBackendRef +RedirectStatusCode +ExtensionBackendRef +GRPCFilterType +HTTPPathType +HTTPRedirectScheme +HTTPFilterType +HTTPHeader +HeaderModifierRules +Kind +HeaderMatchesType +RouteRef +HTTPPathModifier +HeaderModifier +RequestMirrorModifier diff --git a/type-reducer/reduced_types_pass_3_with_enums.txt b/type-reducer/reduced_types_pass_3_with_enums.txt new file mode 100644 index 0000000..29cd7ed --- /dev/null +++ b/type-reducer/reduced_types_pass_3_with_enums.txt @@ -0,0 +1,23 @@ +Condition +GatewayAddress +MirrorBackendRef +RedirectStatusCode +ExtensionBackendRef +GRPCFilterType +HTTPPathType +HTTPRedirectScheme +HTTPFilterType +RouteHeaderModifier +HTTPHeader +Kind +HeaderMatchesType +RouteRef +HTTPPathModifier +HeaderModifier +RequestMirrorModifier +GRPCRouteFilter +HTTPRequestRedirect +HTTPRequestRewrite + + + diff --git a/type-reducer/reduced_types_pass_4_with_enums.txt b/type-reducer/reduced_types_pass_4_with_enums.txt new file mode 100644 index 0000000..09291aa --- /dev/null +++ b/type-reducer/reduced_types_pass_4_with_enums.txt @@ -0,0 +1,22 @@ +Condition +GatewayAddress +MirrorBackendRef +RedirectStatusCode +ExtensionBackendRef +GRPCFilterType +HTTPPathType +HTTPRedirectScheme +HTTPFilterType +RouteHeaderModifier +HTTPHeader +Kind +HeaderMatchesType +RouteRef +HTTPPathModifier +HeaderModifier +RequestMirrorModifier +GRPCRouteFilter +HTTPRequestRedirect +HTTPRequestRewrite +HTTPRouteFilter + diff --git a/type-reducer/src/lib.rs b/type-reducer/src/lib.rs index 53d01ec..e585ef4 100644 --- a/type-reducer/src/lib.rs +++ b/type-reducer/src/lib.rs @@ -252,7 +252,7 @@ pub fn find_similar_types( } pub fn prune_replaced_structs( - renaming_visitor: &mut StructRenamer, + renaming_visitor: &mut StructEnumRenamer, visitors: Vec<(String, File)>, ) -> Vec<(String, String, bool)> { visitors diff --git a/type-reducer/src/main.rs b/type-reducer/src/main.rs index ad31940..511d76b 100644 --- a/type-reducer/src/main.rs +++ b/type-reducer/src/main.rs @@ -149,17 +149,13 @@ fn main() -> Result<(), Box> { let (mapped_types, items): (Vec>, Vec) = struct_items.into_iter().chain(enum_items).unzip(); - // let (mapped_types, items): (Vec>, Vec) = - // all_items.into_iter().unzip(); - let mut renaming_visitor = StructRenamer { + let mut renaming_visitor = StructEnumRenamer { changed: false, names: mapped_types.into_iter().flatten().collect(), }; - if current_pass_substitute_names.is_none() { - write_type_names_to_file(&renaming_visitor.names)? - }; + write_type_names_to_file(&renaming_visitor.names)?; let unparsed_files = prune_replaced_structs(&mut renaming_visitor, visitors); diff --git a/type-reducer/src/visitors.rs b/type-reducer/src/visitors.rs index 4be2f9f..4e8a390 100644 --- a/type-reducer/src/visitors.rs +++ b/type-reducer/src/visitors.rs @@ -28,7 +28,7 @@ pub struct StructEnumVisitor<'ast, 'b> { pub derived_type_names: &'b BTreeSet, } -pub struct StructRenamer { +pub struct StructEnumRenamer { pub changed: bool, pub names: BTreeMap, } @@ -59,41 +59,9 @@ fn rewrite_ident(path: &mut PathSegment, names: &BTreeMap) -> bo file_changed } -impl<'ast, 'b> Visit<'ast> for StructVisitor<'ast, 'b> { - fn visit_item_struct(&mut self, node: &'ast ItemStruct) { - debug!("Visiting Struct name == {}", node.ident); - //debug!("Visiting Struct name == {:#?}", node); - let mut is_simple_leaf = true; - node.fields.iter().for_each(|f| match &f.ty { - Type::Path(path_type) => { - trace!( - "\twith field name = {:?} \n\t\tfield type = {:?}", - f.ident, f.ty - ); - - for segment in &path_type.path.segments { - check_simple_type(segment, &mut is_simple_leaf, self.derived_type_names); - } - } - - _ => { - is_simple_leaf = false; - } - }); - debug!( - "Visiting Struct name == {} is leaf {is_simple_leaf}", - node.ident - ); - if is_simple_leaf { - self.structs.push(node); - } - visit::visit_item_struct(self, node); - } -} - impl<'ast, 'b> Visit<'ast> for StructEnumVisitor<'ast, 'b> { fn visit_item_struct(&mut self, node: &'ast ItemStruct) { - debug!("Visiting Struct name == {}", node.ident); + info!("Visiting Struct name == {}", node.ident); //debug!("Visiting Struct name == {:#?}", node); let mut is_simple_leaf = true; node.fields.iter().for_each(|f| match &f.ty { @@ -136,7 +104,7 @@ impl<'ast, 'b> Visit<'ast> for StructEnumVisitor<'ast, 'b> { } } -impl VisitMut for StructRenamer { +impl VisitMut for StructEnumRenamer { fn visit_item_struct_mut(&mut self, node: &mut ItemStruct) { debug!( "Visiting and changing fields in struct name == {}", @@ -168,6 +136,12 @@ fn check_simple_type( ) { if path.arguments.is_empty() { let ident = &path.ident; + debug!( + "Checking path segment {} {} ", + path.ident, + derived_type_names.contains(&ident.to_string()) + ); + if ident == &Ident::new("String", Span::call_site()) || ident == &Ident::new("i32", Span::call_site()) || ident == &Ident::new("i64", Span::call_site()) diff --git a/update.sh b/update.sh index 3eb595e..729a894 100755 --- a/update.sh +++ b/update.sh @@ -132,19 +132,34 @@ cargo fmt rm -rf $APIS_DIR/processed mkdir -p $APIS_DIR/processed -export RUST_LOG=info -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/processed --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_1.txt -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_1.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_2.txt +export RUST_LOG=debug + +echo " **** PHASE 1 ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/processed --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_1_with_enums.txt +mv mapped_names.txt mapped_names_phase_1.txt +mv mapped_types_to_names.txt mapped_types_to_names_pahse_1.txt +echo " **** PHASE 2 ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_1_with_enums.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_2_with_enums.txt +mv mapped_names.txt mapped_names_phase_2.txt +mv mapped_types_to_names.txt mapped_types_to_names_pahse_2.txt +echo " **** PHASE 3 ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_2_with_enums.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_3_with_enums.txt +mv mapped_names.txt mapped_names_phase_3.txt +mv mapped_types_to_names.txt mapped_types_to_names_pahse_3.txt +echo " **** PHASE 4 ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_3_with_enums.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_4_with_enums.txt +mv mapped_names.txt mapped_names_phase_4.txt +mv mapped_types_to_names.txt mapped_types_to_names_pahse_4.txt cat << EOF >> $APIS_DIR/mod.rs + pub mod processed; EOF ENUMS=( - FiltersHTTPRedirectRequestRouteRulesScheme=Http - FiltersGRPCRouteRulesType=RequestHeaderModifier - FiltersHTTPPathRouteRulesType=ReplaceFullPath - FiltersHTTPRouteRulesType=RequestHeaderModifier + GRPCFilterType=RequestHeaderModifier + HTTPPathType=ReplaceFullPath + HTTPFilterType=RequestHeaderModifier ) ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}") From 485684197051194911a5449cdf04573034f450e1 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Wed, 11 Jun 2025 20:48:51 +0100 Subject: [PATCH 04/16] Removal of intermediate dervied types, fixing bugs Signed-off-by: Dawid Nowak --- .../src/apis/processed/common_types.rs | 210 ++++++------ .../src/apis/processed/enum_defaults.rs | 4 +- gateway-api/src/apis/processed/gateways.rs | 20 -- gateway-api/src/apis/processed/grpcroutes.rs | 43 +-- gateway-api/src/apis/processed/httproutes.rs | 302 ++++++++++++------ type-reducer/customized_mapped_names.txt | 84 +++++ ...tomized_mapped_names_pass_1_with_enums.txt | 12 - ...tomized_mapped_names_pass_2_with_enums.txt | 17 - ...tomized_mapped_names_pass_3_with_enums.txt | 20 -- ...tomized_mapped_names_pass_4_with_enums.txt | 21 -- type-reducer/mapped_names.txt | 3 - type-reducer/mapped_types_to_names.txt | 16 - type-reducer/reduce_types.sh | 4 +- ...ith_enums.txt => reduced_types_pass_0.txt} | 0 type-reducer/reduced_types_pass_1.txt | 14 + .../reduced_types_pass_1_with_enums.txt | 13 - type-reducer/reduced_types_pass_2.txt | 20 ++ .../reduced_types_pass_2_with_enums.txt | 17 - type-reducer/reduced_types_pass_3.txt | 25 ++ .../reduced_types_pass_3_with_enums.txt | 23 -- .../reduced_types_pass_4_with_enums.txt | 22 -- type-reducer/src/lib.rs | 23 +- type-reducer/src/main.rs | 22 +- type-reducer/src/visitors.rs | 5 +- update.sh | 16 +- 25 files changed, 501 insertions(+), 455 deletions(-) create mode 100644 type-reducer/customized_mapped_names.txt delete mode 100644 type-reducer/customized_mapped_names_pass_1_with_enums.txt delete mode 100644 type-reducer/customized_mapped_names_pass_2_with_enums.txt delete mode 100644 type-reducer/customized_mapped_names_pass_3_with_enums.txt delete mode 100644 type-reducer/customized_mapped_names_pass_4_with_enums.txt delete mode 100644 type-reducer/mapped_names.txt delete mode 100644 type-reducer/mapped_types_to_names.txt rename type-reducer/{reduced_types_pass_0_with_enums.txt => reduced_types_pass_0.txt} (100%) create mode 100644 type-reducer/reduced_types_pass_1.txt delete mode 100644 type-reducer/reduced_types_pass_1_with_enums.txt create mode 100644 type-reducer/reduced_types_pass_2.txt delete mode 100644 type-reducer/reduced_types_pass_2_with_enums.txt create mode 100644 type-reducer/reduced_types_pass_3.txt delete mode 100644 type-reducer/reduced_types_pass_3_with_enums.txt delete mode 100644 type-reducer/reduced_types_pass_4_with_enums.txt diff --git a/gateway-api/src/apis/processed/common_types.rs b/gateway-api/src/apis/processed/common_types.rs index 1c4a064..d1bf70d 100644 --- a/gateway-api/src/apis/processed/common_types.rs +++ b/gateway-api/src/apis/processed/common_types.rs @@ -10,12 +10,30 @@ mod prelude { } use self::prelude::*; #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayAddress { + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + pub value: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayInfrastructureParametersRef { + pub group: String, + pub kind: String, + pub name: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct Kind { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + pub kind: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct HTTPHeader { pub name: String, pub value: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct MirrorBackendRef { +pub struct RequestMirrorRef { #[serde(default, skip_serializing_if = "Option::is_none")] pub group: Option, #[serde(default, skip_serializing_if = "Option::is_none")] @@ -27,18 +45,6 @@ pub struct MirrorBackendRef { pub port: Option, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct Kind { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - pub kind: String, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayAddress { - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - pub value: String, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct RouteRef { #[serde(default, skip_serializing_if = "Option::is_none")] pub group: Option, @@ -52,40 +58,6 @@ pub struct RouteRef { #[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")] pub section_name: Option, } -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct ExtensionBackendRef { - pub group: String, - pub kind: String, - pub name: String, -} -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HeaderMatchesType { - Exact, - RegularExpression, -} -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPPathType { - ReplaceFullPath, - ReplacePrefixMatch, -} -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum RedirectStatusCode { - #[serde(rename = "301")] - r#_301, - #[serde(rename = "302")] - r#_302, -} /// HTTPRouteFilter defines processing steps that must be completed during the /// request or response lifecycle. HTTPRouteFilters are meant as an extension /// point to express processing that may be done in Gateway implementations. Some @@ -102,17 +74,6 @@ pub enum HTTPFilterType { UrlRewrite, ExtensionRef, } -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRedirectScheme { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, -} /// GRPCRouteFilter defines processing steps that must be completed during the /// request or response lifecycle. GRPCRouteFilters are meant as an extension /// point to express processing that may be done in Gateway implementations. Some @@ -126,17 +87,47 @@ pub enum GRPCFilterType { RequestMirror, ExtensionRef, } -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct ParentsRouteStatus { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - #[serde(rename = "controllerName")] - pub controller_name: String, - #[serde(rename = "parentRef")] - pub parent_ref: RouteRef, +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum RequestRedirectScheme { + #[serde(rename = "http")] + Http, + #[serde(rename = "https")] + Https, +} +/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request +/// headers. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HeaderMatchType { + Exact, + RegularExpression, +} +/// Path defines parameters used to modify the path of the incoming request. +/// The modified path is then used to construct the `Location` header. When +/// empty, the request path is used as-is. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum RequestOperationType { + ReplaceFullPath, + ReplacePrefixMatch, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum RedirectStatusCode { + #[serde(rename = "301")] + r#_301, + #[serde(rename = "302")] + r#_302, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPPathModifier { +pub struct RequestRedirectPath { #[serde( default, skip_serializing_if = "Option::is_none", @@ -150,46 +141,66 @@ pub struct HTTPPathModifier { )] pub replace_prefix_match: Option, #[serde(rename = "type")] - pub r#type: HTTPPathType, + pub r#type: RequestOperationType, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HeaderModifier { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, +pub struct MatchingHeaders { + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + pub value: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct RequestMirrorModifier { +pub struct RequestMirror { #[serde(rename = "backendRef")] - pub backend_ref: MirrorBackendRef, + pub backend_ref: RequestMirrorRef, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRequestRewrite { +pub struct ParentRouteStatus { #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, + pub conditions: Option>, + #[serde(rename = "controllerName")] + pub controller_name: String, + #[serde(rename = "parentRef")] + pub parent_ref: RouteRef, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HeaderModifier { #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, + pub add: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub remove: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub set: Option>, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRequestRedirect { +pub struct HTTPRouteRequestRedirect { #[serde(default, skip_serializing_if = "Option::is_none")] pub hostname: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, + pub path: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub port: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, + pub scheme: Option, #[serde(default, skip_serializing_if = "Option::is_none", rename = "statusCode")] pub status_code: Option, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RouteStatus { + pub parents: Vec, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteUrlRewrite { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GRPCRouteFilter { #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] - pub extension_ref: Option, + pub extension_ref: Option, #[serde( default, skip_serializing_if = "Option::is_none", @@ -197,7 +208,7 @@ pub struct GRPCRouteFilter { )] pub request_header_modifier: Option, #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] - pub request_mirror: Option, + pub request_mirror: Option, #[serde( default, skip_serializing_if = "Option::is_none", @@ -211,32 +222,3 @@ pub struct GRPCRouteFilter { // Next attempt -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteFilter { - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] - pub extension_ref: Option, - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] - pub request_mirror: Option, - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestRedirect" - )] - pub request_redirect: Option, - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - #[serde(rename = "type")] - pub r#type: HTTPFilterType, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] - pub url_rewrite: Option, -} diff --git a/gateway-api/src/apis/processed/enum_defaults.rs b/gateway-api/src/apis/processed/enum_defaults.rs index 6aa5d2b..5a40b4d 100644 --- a/gateway-api/src/apis/processed/enum_defaults.rs +++ b/gateway-api/src/apis/processed/enum_defaults.rs @@ -13,8 +13,8 @@ impl Default for HTTPFilterType { } } -impl Default for HTTPPathType { +impl Default for RequestOperationType { fn default() -> Self { - HTTPPathType::ReplaceFullPath + RequestOperationType::ReplaceFullPath } } diff --git a/gateway-api/src/apis/processed/gateways.rs b/gateway-api/src/apis/processed/gateways.rs index eb51a9d..7a47c1c 100644 --- a/gateway-api/src/apis/processed/gateways.rs +++ b/gateway-api/src/apis/processed/gateways.rs @@ -226,26 +226,6 @@ pub struct GatewayInfrastructure { #[serde(default, skip_serializing_if = "Option::is_none", rename = "parametersRef")] pub parameters_ref: Option, } -/// ParametersRef is a reference to a resource that contains the configuration -/// parameters corresponding to the Gateway. This is optional if the -/// controller does not require any additional configuration. -/// -/// This follows the same semantics as GatewayClass's `parametersRef`, but on a per-Gateway basis -/// -/// The Gateway's GatewayClass may provide its own `parametersRef`. When both are specified, -/// the merging behavior is implementation specific. -/// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. -/// -/// Support: Implementation-specific -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayInfrastructureParametersRef { - /// Group is the group of the referent. - pub group: String, - /// Kind is kind of the referent. - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} /// Listener embodies the concept of a logical endpoint where a Gateway accepts /// network connections. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] diff --git a/gateway-api/src/apis/processed/grpcroutes.rs b/gateway-api/src/apis/processed/grpcroutes.rs index 8cc090e..8b9a315 100644 --- a/gateway-api/src/apis/processed/grpcroutes.rs +++ b/gateway-api/src/apis/processed/grpcroutes.rs @@ -27,7 +27,7 @@ use self::prelude::*; plural = "grpcroutes" )] #[kube(namespaced)] -#[kube(status = "GRPCRouteStatus")] +#[kube(status = "RouteStatus")] #[kube(derive = "Default")] #[kube(derive = "PartialEq")] pub struct GRPCRouteSpec { @@ -373,30 +373,12 @@ pub struct GRPCRouteRulesMatches { /// ANDed together, meaning, a request MUST match all the specified headers /// to select the route. #[serde(default, skip_serializing_if = "Option::is_none")] - pub headers: Option>, + pub headers: Option>, /// Method specifies a gRPC request service/method matcher. If this field is /// not specified, all services and methods will match. #[serde(default, skip_serializing_if = "Option::is_none")] pub method: Option, } -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesMatchesHeaders { - /// Name is the name of the gRPC Header to be matched. - /// - /// If multiple entries specify equivalent header names, only the first - /// entry with an equivalent name MUST be considered for a match. Subsequent - /// entries with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Type specifies how to match against the value of the header. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value is the value of the gRPC Header to be matched. - pub value: String, -} /// Method specifies a gRPC request service/method matcher. If this field is /// not specified, all services and methods will match. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] @@ -420,24 +402,5 @@ pub struct GRPCRouteRulesMatchesMethod { /// /// Support: Implementation-specific (RegularExpression) #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, -} -/// Status defines the current state of GRPCRoute. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteStatus { - /// Parents is a list of parent resources (usually Gateways) that are - /// associated with the route, and the status of the route with respect to - /// each parent. When this route attaches to a parent, the controller that - /// manages the parent must add an entry to this list when the controller - /// first sees the route and should update the entry as appropriate when the - /// route or gateway is modified. - /// - /// Note that parent references that cannot be resolved by an implementation - /// of this API will not be added to this list. Implementations of this API - /// can only populate Route status for the Gateways/parent resources they are - /// responsible for. - /// - /// A maximum of 32 Gateways will be represented in this list. An empty list - /// means the route has not been attached to any Gateway. - pub parents: Vec, + pub r#type: Option, } diff --git a/gateway-api/src/apis/processed/httproutes.rs b/gateway-api/src/apis/processed/httproutes.rs index fca9649..c3eeac7 100644 --- a/gateway-api/src/apis/processed/httproutes.rs +++ b/gateway-api/src/apis/processed/httproutes.rs @@ -27,7 +27,7 @@ use self::prelude::*; plural = "httproutes" )] #[kube(namespaced)] -#[kube(status = "HTTPRouteStatus")] +#[kube(status = "RouteStatus")] #[kube(derive = "Default")] #[kube(derive = "PartialEq")] pub struct HTTPRouteSpec { @@ -230,7 +230,7 @@ pub struct HTTPRouteRules { /// /// Support: Core #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Matches define conditions used for matching the rule against incoming /// HTTP requests. Each match is independent, i.e. this rule will be matched /// if **any** one of the matches is satisfied. @@ -327,7 +327,7 @@ pub struct HTTPRouteRulesBackendRefs { /// Support: Implementation-specific (For broader support of filters, use the /// Filters field in HTTPRouteRule.) #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Group is the group of the referent. For example, "gateway.networking.k8s.io". /// When unspecified or empty string, core API group is inferred. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -384,6 +384,208 @@ pub struct HTTPRouteRulesBackendRefs { #[serde(default, skip_serializing_if = "Option::is_none")] pub weight: Option, } +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesBackendRefsFilters { + /// ExtensionRef is an optional, implementation-specific extension to the + /// "filter" behavior. For example, resource "myroutefilter" in group + /// "networking.example.net"). ExtensionRef MUST NOT be used for core and + /// extended filters. + /// + /// This filter can be used multiple times within the same rule. + /// + /// Support: Implementation-specific + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, + /// RequestHeaderModifier defines a schema for a filter that modifies request + /// headers. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + /// RequestMirror defines a schema for a filter that mirrors requests. + /// Requests are sent to the specified destination, but responses from + /// that destination are ignored. + /// + /// This filter can be used multiple times within the same rule. Note that + /// not all implementations will be able to support mirroring to multiple + /// backends. + /// + /// Support: Extended + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, + /// RequestRedirect defines a schema for a filter that responds to the + /// request with an HTTP redirection. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestRedirect" + )] + pub request_redirect: Option, + /// ResponseHeaderModifier defines a schema for a filter that modifies response + /// headers. + /// + /// Support: Extended + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + /// Type identifies the type of filter to apply. As with other API fields, + /// types are classified into three conformance levels: + /// + /// - Core: Filter types and their corresponding configuration defined by + /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All + /// implementations must support core filters. + /// + /// - Extended: Filter types and their corresponding configuration defined by + /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers + /// are encouraged to support extended filters. + /// + /// - Implementation-specific: Filters that are defined and supported by + /// specific vendors. + /// In the future, filters showing convergence in behavior across multiple + /// implementations will be considered for inclusion in extended or core + /// conformance levels. Filter-specific configuration for such filters + /// is specified using the ExtensionRef field. `Type` should be set to + /// "ExtensionRef" for custom filters. + /// + /// Implementers are encouraged to define custom implementation types to + /// extend the core API with implementation-specific behavior. + /// + /// If a reference to a custom filter type cannot be resolved, the filter + /// MUST NOT be skipped. Instead, requests that would have been processed by + /// that filter MUST receive a HTTP error response. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + #[serde(rename = "type")] + pub r#type: HTTPFilterType, + /// URLRewrite defines a schema for a filter that modifies a request during forwarding. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] + pub url_rewrite: Option, +} +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteRulesFilters { + /// ExtensionRef is an optional, implementation-specific extension to the + /// "filter" behavior. For example, resource "myroutefilter" in group + /// "networking.example.net"). ExtensionRef MUST NOT be used for core and + /// extended filters. + /// + /// This filter can be used multiple times within the same rule. + /// + /// Support: Implementation-specific + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, + /// RequestHeaderModifier defines a schema for a filter that modifies request + /// headers. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + /// RequestMirror defines a schema for a filter that mirrors requests. + /// Requests are sent to the specified destination, but responses from + /// that destination are ignored. + /// + /// This filter can be used multiple times within the same rule. Note that + /// not all implementations will be able to support mirroring to multiple + /// backends. + /// + /// Support: Extended + /// + /// + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, + /// RequestRedirect defines a schema for a filter that responds to the + /// request with an HTTP redirection. + /// + /// Support: Core + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestRedirect" + )] + pub request_redirect: Option, + /// ResponseHeaderModifier defines a schema for a filter that modifies response + /// headers. + /// + /// Support: Extended + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + /// Type identifies the type of filter to apply. As with other API fields, + /// types are classified into three conformance levels: + /// + /// - Core: Filter types and their corresponding configuration defined by + /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All + /// implementations must support core filters. + /// + /// - Extended: Filter types and their corresponding configuration defined by + /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers + /// are encouraged to support extended filters. + /// + /// - Implementation-specific: Filters that are defined and supported by + /// specific vendors. + /// In the future, filters showing convergence in behavior across multiple + /// implementations will be considered for inclusion in extended or core + /// conformance levels. Filter-specific configuration for such filters + /// is specified using the ExtensionRef field. `Type` should be set to + /// "ExtensionRef" for custom filters. + /// + /// Implementers are encouraged to define custom implementation types to + /// extend the core API with implementation-specific behavior. + /// + /// If a reference to a custom filter type cannot be resolved, the filter + /// MUST NOT be skipped. Instead, requests that would have been processed by + /// that filter MUST receive a HTTP error response. + /// + /// Note that values may be added to this enum, implementations + /// must ensure that unknown values will not cause a crash. + /// + /// Unknown values here must result in the implementation setting the + /// Accepted Condition for the Route to `status: False`, with a + /// Reason of `UnsupportedValue`. + #[serde(rename = "type")] + pub r#type: HTTPFilterType, + /// URLRewrite defines a schema for a filter that modifies a request during forwarding. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] + pub url_rewrite: Option, +} /// HTTPRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will /// evaluate to true only if all conditions are satisfied. @@ -407,7 +609,7 @@ pub struct HTTPRouteRulesMatches { /// ANDed together, meaning, a request must match all the specified headers /// to select the route. #[serde(default, skip_serializing_if = "Option::is_none")] - pub headers: Option>, + pub headers: Option>, /// Method specifies HTTP method matcher. /// When specified, this route will be matched only if the request has the /// specified method. @@ -425,41 +627,7 @@ pub struct HTTPRouteRulesMatches { /// /// Support: Extended #[serde(default, skip_serializing_if = "Option::is_none", rename = "queryParams")] - pub query_params: Option>, -} -/// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatchesHeaders { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, only the first - /// entry with an equivalent name MUST be considered for a match. Subsequent - /// entries with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - /// - /// When a header is repeated in an HTTP request, it is - /// implementation-specific behavior as to how this is represented. - /// Generally, proxies should follow the guidance from the RFC: - /// https://www.rfc-editor.org/rfc/rfc7230.html#section-3.2.2 regarding - /// processing a repeated header, with special handling for "Set-Cookie". - pub name: String, - /// Type specifies how to match against the value of the header. - /// - /// Support: Core (Exact) - /// - /// Support: Implementation-specific (RegularExpression) - /// - /// Since RegularExpression HeaderMatchType has implementation-specific - /// conformance, implementations can support POSIX, PCRE or any other dialects - /// of regular expressions. Please read the implementation's documentation to - /// determine the supported dialect. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value is the value of HTTP Header to be matched. - pub value: String, + pub query_params: Option>, } /// HTTPRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will @@ -522,43 +690,6 @@ pub enum HTTPRouteRulesMatchesPathType { PathPrefix, RegularExpression, } -/// HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP -/// query parameters. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatchesQueryParams { - /// Name is the name of the HTTP query param to be matched. This must be an - /// exact string match. (See - /// https://tools.ietf.org/html/rfc7230#section-2.7.3). - /// - /// If multiple entries specify equivalent query param names, only the first - /// entry with an equivalent name MUST be considered for a match. Subsequent - /// entries with an equivalent query param name MUST be ignored. - /// - /// If a query param is repeated in an HTTP request, the behavior is - /// purposely left undefined, since different data planes have different - /// capabilities. However, it is *recommended* that implementations should - /// match against the first value of the param if the data plane supports it, - /// as this behavior is expected in other load balancing contexts outside of - /// the Gateway API. - /// - /// Users SHOULD NOT route traffic based on repeated query params to guard - /// themselves against potential differences in the implementations. - pub name: String, - /// Type specifies how to match against the value of the query parameter. - /// - /// Support: Extended (Exact) - /// - /// Support: Implementation-specific (RegularExpression) - /// - /// Since RegularExpression QueryParamMatchType has Implementation-specific - /// conformance, implementations can support POSIX, PCRE or any other - /// dialects of regular expressions. Please read the implementation's - /// documentation to determine the supported dialect. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value is the value of HTTP query param to be matched. - pub value: String, -} /// Timeouts defines the timeouts that can be configured for an HTTP request. /// /// Support: Extended @@ -610,22 +741,3 @@ pub struct HTTPRouteRulesTimeouts { #[serde(default, skip_serializing_if = "Option::is_none")] pub request: Option, } -/// Status defines the current state of HTTPRoute. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteStatus { - /// Parents is a list of parent resources (usually Gateways) that are - /// associated with the route, and the status of the route with respect to - /// each parent. When this route attaches to a parent, the controller that - /// manages the parent must add an entry to this list when the controller - /// first sees the route and should update the entry as appropriate when the - /// route or gateway is modified. - /// - /// Note that parent references that cannot be resolved by an implementation - /// of this API will not be added to this list. Implementations of this API - /// can only populate Route status for the Gateways/parent resources they are - /// responsible for. - /// - /// A maximum of 32 Gateways will be represented in this list. An empty list - /// means the route has not been attached to any Gateway. - pub parents: Vec, -} diff --git a/type-reducer/customized_mapped_names.txt b/type-reducer/customized_mapped_names.txt new file mode 100644 index 0000000..6712948 --- /dev/null +++ b/type-reducer/customized_mapped_names.txt @@ -0,0 +1,84 @@ +GRPCRouteRulesBackendRefsFiltersType->GRPCFilterType +GRPCRouteRulesFiltersType->GRPCFilterType +GatewayAddresses->GatewayAddress +GatewayStatusAddresses->GatewayAddress +GRPCRouteRulesBackendRefsFiltersExtensionRef->GatewayInfrastructureParametersRef +GRPCRouteRulesFiltersExtensionRef->GatewayInfrastructureParametersRef +GatewayInfrastructureParametersRef->GatewayInfrastructureParametersRef +HTTPRouteRulesBackendRefsFiltersExtensionRef->GatewayInfrastructureParametersRef +HTTPRouteRulesFiltersExtensionRef->GatewayInfrastructureParametersRef +GatewayListenersAllowedRoutesKinds->Kind +GatewayStatusListenersSupportedKinds->Kind +GRPCRouteParentRefs->RouteRef +GRPCRouteStatusParentsParentRef->RouteRef +HTTPRouteParentRefs->RouteRef +HTTPRouteStatusParentsParentRef->RouteRef +GRPCRouteRulesBackendRefsFiltersExtensionRef->FilterExtensionRef +GRPCRouteRulesFiltersExtensionRef->FilterExtensionRef +HTTPRouteRulesBackendRefsFiltersExtensionRef->FilterExtensionRef +HTTPRouteRulesFiltersExtensionRef->FilterExtensionRef +GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd->HTTPHeader +GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierSet->HTTPHeader +GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierAdd->HTTPHeader +GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierSet->HTTPHeader +GRPCRouteRulesFiltersRequestHeaderModifierAdd->HTTPHeader +GRPCRouteRulesFiltersRequestHeaderModifierSet->HTTPHeader +GRPCRouteRulesFiltersResponseHeaderModifierAdd->HTTPHeader +GRPCRouteRulesFiltersResponseHeaderModifierSet->HTTPHeader +HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierAdd->HTTPHeader +HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierSet->HTTPHeader +HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierAdd->HTTPHeader +HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierSet->HTTPHeader +HTTPRouteRulesFiltersRequestHeaderModifierAdd->HTTPHeader +HTTPRouteRulesFiltersRequestHeaderModifierSet->HTTPHeader +HTTPRouteRulesFiltersResponseHeaderModifierAdd->HTTPHeader +HTTPRouteRulesFiltersResponseHeaderModifierSet->HTTPHeader +GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef->RequestMirrorRef +GRPCRouteRulesFiltersRequestMirrorBackendRef->RequestMirrorRef +HTTPRouteRulesBackendRefsFiltersRequestMirrorBackendRef->RequestMirrorRef +HTTPRouteRulesFiltersRequestMirrorBackendRef->RequestMirrorRef +HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType->RequestOperationType +HTTPRouteRulesBackendRefsFiltersUrlRewritePathType->RequestOperationType +HTTPRouteRulesFiltersRequestRedirectPathType->RequestOperationType +HTTPRouteRulesFiltersUrlRewritePathType->RequestOperationType +HTTPRouteRulesBackendRefsFiltersRequestRedirectScheme->RequestRedirectScheme +HTTPRouteRulesFiltersRequestRedirectScheme->RequestRedirectScheme +HTTPRouteRulesBackendRefsFiltersRequestRedirectStatusCode->RedirectStatusCode +HTTPRouteRulesFiltersRequestRedirectStatusCode->RedirectStatusCode +HTTPRouteRulesBackendRefsFiltersType->HTTPFilterType +HTTPRouteRulesFiltersType->HTTPFilterType +GRPCRouteRulesMatchesHeadersType->HeaderMatchType +GRPCRouteRulesMatchesMethodType->HeaderMatchType +HTTPRouteRulesMatchesHeadersType->HeaderMatchType +HTTPRouteRulesMatchesQueryParamsType->HeaderMatchType +#### Pass 2 +GRPCRouteRulesBackendRefsFiltersRequestHeaderModifier->HeaderModifier +GRPCRouteRulesBackendRefsFiltersResponseHeaderModifier->HeaderModifier +GRPCRouteRulesFiltersRequestHeaderModifier->HeaderModifier +GRPCRouteRulesFiltersResponseHeaderModifier->HeaderModifier +HTTPRouteRulesBackendRefsFiltersRequestHeaderModifier->HeaderModifier +HTTPRouteRulesBackendRefsFiltersResponseHeaderModifier->HeaderModifier +HTTPRouteRulesFiltersRequestHeaderModifier->HeaderModifier +HTTPRouteRulesFiltersResponseHeaderModifier->HeaderModifier +GRPCRouteRulesMatchesHeaders->MatchingHeaders +HTTPRouteRulesMatchesHeaders->MatchingHeaders +HTTPRouteRulesMatchesQueryParams->MatchingHeaders +GRPCRouteStatusParents->ParentRouteStatus +HTTPRouteStatusParents->ParentRouteStatus +GRPCRouteRulesBackendRefsFiltersRequestMirror->RequestMirror +GRPCRouteRulesFiltersRequestMirror->RequestMirror +HTTPRouteRulesBackendRefsFiltersRequestMirror->RequestMirror +HTTPRouteRulesFiltersRequestMirror->RequestMirror +HTTPRouteRulesBackendRefsFiltersRequestRedirectPath->RequestRedirectPath +HTTPRouteRulesBackendRefsFiltersUrlRewritePath->RequestRedirectPath +HTTPRouteRulesFiltersRequestRedirectPath->RequestRedirectPath +HTTPRouteRulesFiltersUrlRewritePath->RequestRedirectPath +#### Pass 3 +GRPCRouteRulesBackendRefsFilters->GRPCRouteFilter +GRPCRouteRulesFilters->GRPCRouteFilter +HTTPRouteRulesBackendRefsFiltersRequestRedirect->HTTPRouteRequestRedirect +HTTPRouteRulesFiltersRequestRedirect->HTTPRouteRequestRedirect +HTTPRouteRulesBackendRefsFiltersUrlRewrite->HTTPRouteUrlRewrite +HTTPRouteRulesFiltersUrlRewrite->HTTPRouteUrlRewrite +GRPCRouteStatus->RouteStatus +HTTPRouteStatus->RouteStatus diff --git a/type-reducer/customized_mapped_names_pass_1_with_enums.txt b/type-reducer/customized_mapped_names_pass_1_with_enums.txt deleted file mode 100644 index 9f83c5c..0000000 --- a/type-reducer/customized_mapped_names_pass_1_with_enums.txt +++ /dev/null @@ -1,12 +0,0 @@ -AddressesGateway->GatewayAddress -BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef -CodeFiltersHTTPRedirectRequestRouteRulesStatus->RedirectStatusCode -ExtensionFiltersRefRouteRules->ExtensionBackendRef -FiltersGRPCRouteRulesType->GRPCFilterType -FiltersHTTPPathRouteRulesType->HTTPPathType -FiltersHTTPRedirectRequestRouteRulesScheme->HTTPRedirectScheme -FiltersHTTPRouteRulesType->HTTPFilterType -FiltersHeaderModifierRouteRules->HTTPHeader -GatewayKindsListeners->Kind -MatchesRouteRulesType->HeaderMatchesType -ParentRoute->RouteRef diff --git a/type-reducer/customized_mapped_names_pass_2_with_enums.txt b/type-reducer/customized_mapped_names_pass_2_with_enums.txt deleted file mode 100644 index 6d9c741..0000000 --- a/type-reducer/customized_mapped_names_pass_2_with_enums.txt +++ /dev/null @@ -1,17 +0,0 @@ -AddressesGateway->GatewayAddress -BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef -CodeFiltersHTTPRedirectRequestRouteRulesStatus->RedirectStatusCode -ExtensionFiltersRefRouteRules->ExtensionBackendRef -FiltersGRPCRouteRulesType->GRPCFilterType -FiltersHTTPPathRouteRulesType->HTTPPathType -FiltersHTTPRedirectRequestRouteRulesScheme->HTTPRedirectScheme -FiltersHTTPRouteRulesType->HTTPFilterType -FiltersHeaderModifierRouteRules->HTTPHeader -GatewayKindsListeners->Kind -MatchesRouteRulesType->HeaderMatchesType -ParentRoute->RouteRef -FiltersHTTPPathRouteRules->HTTPPathModifier -FiltersHeaderModifierRouteRules->HeaderModifier -FiltersMirrorRequestRouteRules->RequestMirrorModifier - - diff --git a/type-reducer/customized_mapped_names_pass_3_with_enums.txt b/type-reducer/customized_mapped_names_pass_3_with_enums.txt deleted file mode 100644 index e205c9e..0000000 --- a/type-reducer/customized_mapped_names_pass_3_with_enums.txt +++ /dev/null @@ -1,20 +0,0 @@ -AddressesGateway->GatewayAddress -BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef -CodeFiltersHTTPRedirectRequestRouteRulesStatus->RedirectStatusCode -ExtensionFiltersRefRouteRules->ExtensionBackendRef -FiltersGRPCRouteRulesType->GRPCFilterType -FiltersHTTPPathRouteRulesType->HTTPPathType -FiltersHTTPRedirectRequestRouteRulesScheme->HTTPRedirectScheme -FiltersHTTPRouteRulesType->HTTPFilterType -FiltersHeaderModifierRouteRules->HTTPHeader -GatewayKindsListeners->Kind -MatchesRouteRulesType->HeaderMatchesType -ParentRoute->RouteRef -FiltersHTTPPathRouteRules->HTTPPathModifier -FiltersHeaderModifierRouteRules->HeaderModifier -FiltersMirrorRequestRouteRules->RequestMirrorModifier -FiltersGRPCRouteRules->GRPCRouteFilter -FiltersHTTPRedirectRequestRouteRules->HTTPRequestRedirect -FiltersHTTPRewriteRouteRulesUrl->HTTPRequestRewrite - - diff --git a/type-reducer/customized_mapped_names_pass_4_with_enums.txt b/type-reducer/customized_mapped_names_pass_4_with_enums.txt deleted file mode 100644 index ced4de1..0000000 --- a/type-reducer/customized_mapped_names_pass_4_with_enums.txt +++ /dev/null @@ -1,21 +0,0 @@ -AddressesGateway->GatewayAddress -BackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef -CodeFiltersHTTPRedirectRequestRouteRulesStatus->RedirectStatusCode -ExtensionFiltersRefRouteRules->ExtensionBackendRef -FiltersGRPCRouteRulesType->GRPCFilterType -FiltersHTTPPathRouteRulesType->HTTPPathType -FiltersHTTPRedirectRequestRouteRulesScheme->HTTPRedirectScheme -FiltersHTTPRouteRulesType->HTTPFilterType -FiltersHeaderModifierRouteRules->HTTPHeader -GatewayKindsListeners->Kind -MatchesRouteRulesTypey->HeaderMatchesType -ParentRoute->RouteRef -FiltersHTTPPathRouteRules->HTTPPathModifier -FiltersHeaderModifierRouteRules->HeaderModifier -FiltersMirrorRequestRouteRules->RequestMirrorModifier -FiltersGRPCRouteRules->GRPCRouteFilter -FiltersHTTPRedirectRequestRouteRules->HTTPRequestRedirect -FiltersHTTPRewriteRouteRulesUrl->HTTPRequestRewrite -FiltersHTTPRouteRules->HTTPRouteFilter - - diff --git a/type-reducer/mapped_names.txt b/type-reducer/mapped_names.txt deleted file mode 100644 index 1ed2ca8..0000000 --- a/type-reducer/mapped_names.txt +++ /dev/null @@ -1,3 +0,0 @@ -FiltersHTTPPathRouteRules -FiltersHeaderModifierRouteRules -FiltersMirrorRequestRouteRules diff --git a/type-reducer/mapped_types_to_names.txt b/type-reducer/mapped_types_to_names.txt deleted file mode 100644 index 8adb3b5..0000000 --- a/type-reducer/mapped_types_to_names.txt +++ /dev/null @@ -1,16 +0,0 @@ -HTTPRouteRulesBackendRefsFiltersRequestRedirectPath->FiltersHTTPPathRouteRules -HTTPRouteRulesBackendRefsFiltersUrlRewritePath->FiltersHTTPPathRouteRules -HTTPRouteRulesFiltersRequestRedirectPath->FiltersHTTPPathRouteRules -HTTPRouteRulesFiltersUrlRewritePath->FiltersHTTPPathRouteRules -GRPCRouteRulesBackendRefsFiltersRequestHeaderModifier->FiltersHeaderModifierRouteRules -GRPCRouteRulesBackendRefsFiltersResponseHeaderModifier->FiltersHeaderModifierRouteRules -GRPCRouteRulesFiltersRequestHeaderModifier->FiltersHeaderModifierRouteRules -GRPCRouteRulesFiltersResponseHeaderModifier->FiltersHeaderModifierRouteRules -HTTPRouteRulesBackendRefsFiltersRequestHeaderModifier->FiltersHeaderModifierRouteRules -HTTPRouteRulesBackendRefsFiltersResponseHeaderModifier->FiltersHeaderModifierRouteRules -HTTPRouteRulesFiltersRequestHeaderModifier->FiltersHeaderModifierRouteRules -HTTPRouteRulesFiltersResponseHeaderModifier->FiltersHeaderModifierRouteRules -GRPCRouteRulesBackendRefsFiltersRequestMirror->FiltersMirrorRequestRouteRules -GRPCRouteRulesFiltersRequestMirror->FiltersMirrorRequestRouteRules -HTTPRouteRulesBackendRefsFiltersRequestMirror->FiltersMirrorRequestRouteRules -HTTPRouteRulesFiltersRequestMirror->FiltersMirrorRequestRouteRules diff --git a/type-reducer/reduce_types.sh b/type-reducer/reduce_types.sh index 252945a..398c617 100755 --- a/type-reducer/reduce_types.sh +++ b/type-reducer/reduce_types.sh @@ -3,7 +3,7 @@ rm -rf ../gateway-api/src/apis/processed mkdir ../gateway-api/src/apis/processed #cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed echo "\n\n PHASE 1\n\n" -cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --current-pass-substitute-names customized_mapped_names_pass_1_with_enums.txt --previous-pass-derived-type-names reduced_types_pass_0_with_enums.txt +cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --current-pass-substitute-names customized_mapped_names.txt --previous-pass-derived-type-names reduced_types_pass_0.txt echo "\n\n PHASE 2\n\n" -cargo run -- --apis-dir ../gateway-api/src/apis/processed --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names reduced_types_pass_1_with_enums.txt --current-pass-substitute-names customized_mapped_names_pass_2_with_enums.txt +cargo run -- --apis-dir ../gateway-api/src/apis/processed --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names reduced_types_pass_1.txt --current-pass-substitute-names customized_mapped_names.txt diff --git a/type-reducer/reduced_types_pass_0_with_enums.txt b/type-reducer/reduced_types_pass_0.txt similarity index 100% rename from type-reducer/reduced_types_pass_0_with_enums.txt rename to type-reducer/reduced_types_pass_0.txt diff --git a/type-reducer/reduced_types_pass_1.txt b/type-reducer/reduced_types_pass_1.txt new file mode 100644 index 0000000..7fead51 --- /dev/null +++ b/type-reducer/reduced_types_pass_1.txt @@ -0,0 +1,14 @@ +Condition +GRPCFilterType +GatewayAddress +GatewayInfrastructureParametersRef +Kind +RouteRef +FilterExtensionRef +HTTPHeader +RequestMirrorRef +RequestOperationType +RequestRedirectScheme +RedirectStatusCode +FiltersType +HeaderMatchType diff --git a/type-reducer/reduced_types_pass_1_with_enums.txt b/type-reducer/reduced_types_pass_1_with_enums.txt deleted file mode 100644 index e085284..0000000 --- a/type-reducer/reduced_types_pass_1_with_enums.txt +++ /dev/null @@ -1,13 +0,0 @@ -Condition -GatewayAddress -MirrorBackendRef -RedirectStatusCode -ExtensionBackendRef -GRPCFilterType -HTTPPathType -HTTPRedirectScheme -HTTPFilterType -HTTPHeader -Kind -HeaderMatchesType -RouteRef diff --git a/type-reducer/reduced_types_pass_2.txt b/type-reducer/reduced_types_pass_2.txt new file mode 100644 index 0000000..f0d7012 --- /dev/null +++ b/type-reducer/reduced_types_pass_2.txt @@ -0,0 +1,20 @@ +Condition +GRPCFilterType +GatewayAddress +GatewayInfrastructureParametersRef +Kind +RouteRef +FilterExtensionRef +HTTPHeader +RequestMirrorRef +RequestOperationType +RequestRedirectScheme +RedirectStatusCode +FiltersType +HeaderMatchType +#### Pass 2 +MatchingHeaders +HeaderModifier +RequestMirror +RequestRedirectPath +ParentRouteStatus diff --git a/type-reducer/reduced_types_pass_2_with_enums.txt b/type-reducer/reduced_types_pass_2_with_enums.txt deleted file mode 100644 index e0dd85d..0000000 --- a/type-reducer/reduced_types_pass_2_with_enums.txt +++ /dev/null @@ -1,17 +0,0 @@ -Condition -GatewayAddress -MirrorBackendRef -RedirectStatusCode -ExtensionBackendRef -GRPCFilterType -HTTPPathType -HTTPRedirectScheme -HTTPFilterType -HTTPHeader -HeaderModifierRules -Kind -HeaderMatchesType -RouteRef -HTTPPathModifier -HeaderModifier -RequestMirrorModifier diff --git a/type-reducer/reduced_types_pass_3.txt b/type-reducer/reduced_types_pass_3.txt new file mode 100644 index 0000000..552f3bc --- /dev/null +++ b/type-reducer/reduced_types_pass_3.txt @@ -0,0 +1,25 @@ +Condition +GRPCFilterType +GatewayAddress +GatewayInfrastructureParametersRef +Kind +RouteRef +FilterExtensionRef +HTTPHeader +RequestMirrorRef +RequestOperationType +RequestRedirectScheme +RedirectStatusCode +FiltersType +HeaderMatchType +#### Pass 2 +MatchingHeaders +HeaderModifier +RequestMirror +RequestRedirectPath +ParentRouteStatus +#### Pass 3 +GRPCRouteFilter +HTTPRouteRequestRedirect +HTTPRouteUrlRewrite +RouteStatus diff --git a/type-reducer/reduced_types_pass_3_with_enums.txt b/type-reducer/reduced_types_pass_3_with_enums.txt deleted file mode 100644 index 29cd7ed..0000000 --- a/type-reducer/reduced_types_pass_3_with_enums.txt +++ /dev/null @@ -1,23 +0,0 @@ -Condition -GatewayAddress -MirrorBackendRef -RedirectStatusCode -ExtensionBackendRef -GRPCFilterType -HTTPPathType -HTTPRedirectScheme -HTTPFilterType -RouteHeaderModifier -HTTPHeader -Kind -HeaderMatchesType -RouteRef -HTTPPathModifier -HeaderModifier -RequestMirrorModifier -GRPCRouteFilter -HTTPRequestRedirect -HTTPRequestRewrite - - - diff --git a/type-reducer/reduced_types_pass_4_with_enums.txt b/type-reducer/reduced_types_pass_4_with_enums.txt deleted file mode 100644 index 09291aa..0000000 --- a/type-reducer/reduced_types_pass_4_with_enums.txt +++ /dev/null @@ -1,22 +0,0 @@ -Condition -GatewayAddress -MirrorBackendRef -RedirectStatusCode -ExtensionBackendRef -GRPCFilterType -HTTPPathType -HTTPRedirectScheme -HTTPFilterType -RouteHeaderModifier -HTTPHeader -Kind -HeaderMatchesType -RouteRef -HTTPPathModifier -HeaderModifier -RequestMirrorModifier -GRPCRouteFilter -HTTPRequestRedirect -HTTPRequestRewrite -HTTPRouteFilter - diff --git a/type-reducer/src/lib.rs b/type-reducer/src/lib.rs index e585ef4..99cecb3 100644 --- a/type-reducer/src/lib.rs +++ b/type-reducer/src/lib.rs @@ -115,6 +115,14 @@ pub fn create_struct_type_name_substitute( } } +pub fn read_substitute(customized_names_from_file: &BTreeMap, i: &Ident) -> String { + if let Some(customized_name) = customized_names_from_file.get(&i.to_string()) { + customized_name.clone() + } else { + i.to_string() + } +} + pub fn create_enum_type_name_substitute( customized_names_from_file: &BTreeMap, v: &[(Ident, ItemEnum)], @@ -235,7 +243,20 @@ pub fn find_similar_types( .map(|(mut visitor, file)| { visitor.visit_file(&file); visitor.structs.into_iter().for_each(|i| { - similar_structs.insert(i.fields.clone(), (i.ident.clone(), (*i).clone())); + let mut fields = i.fields.clone(); + + fields.iter_mut().for_each(|f| { + f.attrs = f + .attrs + .clone() + .into_iter() + .filter(|a| { + a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site())) + }) + .collect::>() + }); + + similar_structs.insert(fields, (i.ident.clone(), (*i).clone())); }); visitor.enums.into_iter().for_each(|i| { similar_enums.insert(i.variants.clone(), (i.ident.clone(), (*i).clone())); diff --git a/type-reducer/src/main.rs b/type-reducer/src/main.rs index 511d76b..e8c57ea 100644 --- a/type-reducer/src/main.rs +++ b/type-reducer/src/main.rs @@ -91,11 +91,14 @@ fn main() -> Result<(), Box> { ); let mapped_type_names = v.iter().map(|v| v.0.to_string()).collect::>(); - let type_new_name = - create_struct_type_name_substitute(¤t_pass_type_name_substitutes, v); + // let type_new_name = + // create_struct_type_name_substitute(¤t_pass_type_name_substitutes, v); - if let Some((_i, s)) = v.first() { - let new_struct = create_common_type_struct(s, &type_new_name); + if let Some((i, s)) = v.first() { + let new_struct = create_common_type_struct( + s, + &read_substitute(¤t_pass_type_name_substitutes, i), + ); let mut mapped = BTreeMap::new(); for mapped_type_name in mapped_type_names { @@ -124,11 +127,14 @@ fn main() -> Result<(), Box> { ); let mapped_type_names = v.iter().map(|v| v.0.to_string()).collect::>(); - let type_new_name = - create_enum_type_name_substitute(¤t_pass_type_name_substitutes, v); + // let type_new_name = + // create_enum_type_name_substitute(¤t_pass_type_name_substitutes, v); - if let Some((_i, s)) = v.first() { - let new_enum = create_common_type_enum(s, &type_new_name); + if let Some((i, s)) = v.first() { + let new_enum = create_common_type_enum( + s, + &read_substitute(¤t_pass_type_name_substitutes, i), + ); let mut mapped = BTreeMap::new(); for mapped_type_name in mapped_type_names { diff --git a/type-reducer/src/visitors.rs b/type-reducer/src/visitors.rs index 4e8a390..99d258f 100644 --- a/type-reducer/src/visitors.rs +++ b/type-reducer/src/visitors.rs @@ -1,5 +1,4 @@ use log::debug; -use log::info; use log::trace; use proc_macro2::{Ident, Span}; use std::collections::BTreeMap; @@ -61,7 +60,7 @@ fn rewrite_ident(path: &mut PathSegment, names: &BTreeMap) -> bo impl<'ast, 'b> Visit<'ast> for StructEnumVisitor<'ast, 'b> { fn visit_item_struct(&mut self, node: &'ast ItemStruct) { - info!("Visiting Struct name == {}", node.ident); + debug!("Visiting Struct name == {}", node.ident); //debug!("Visiting Struct name == {:#?}", node); let mut is_simple_leaf = true; node.fields.iter().for_each(|f| match &f.ty { @@ -91,7 +90,7 @@ impl<'ast, 'b> Visit<'ast> for StructEnumVisitor<'ast, 'b> { } fn visit_item_enum(&mut self, node: &'ast ItemEnum) { - info!("Visiting Enum name == {} {:?}", node.ident, node.variants); + debug!("Visiting Enum name == {} {:?}", node.ident, node.variants); if node .variants diff --git a/update.sh b/update.sh index 729a894..9c82000 100755 --- a/update.sh +++ b/update.sh @@ -132,22 +132,24 @@ cargo fmt rm -rf $APIS_DIR/processed mkdir -p $APIS_DIR/processed -export RUST_LOG=debug +export RUST_LOG=info echo " **** PHASE 1 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/processed --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_1_with_enums.txt +#cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_0_with_enums.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_0.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt mv mapped_names.txt mapped_names_phase_1.txt mv mapped_types_to_names.txt mapped_types_to_names_pahse_1.txt echo " **** PHASE 2 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_1_with_enums.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_2_with_enums.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_1.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt mv mapped_names.txt mapped_names_phase_2.txt mv mapped_types_to_names.txt mapped_types_to_names_pahse_2.txt echo " **** PHASE 3 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_2_with_enums.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_3_with_enums.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_2.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt mv mapped_names.txt mapped_names_phase_3.txt mv mapped_types_to_names.txt mapped_types_to_names_pahse_3.txt echo " **** PHASE 4 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_3_with_enums.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_4_with_enums.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_3.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt +# cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_3_with_enums.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_4_with_enums.txt mv mapped_names.txt mapped_names_phase_4.txt mv mapped_types_to_names.txt mapped_types_to_names_pahse_4.txt @@ -158,7 +160,7 @@ EOF ENUMS=( GRPCFilterType=RequestHeaderModifier - HTTPPathType=ReplaceFullPath + RequestOperationType=ReplaceFullPath HTTPFilterType=RequestHeaderModifier ) @@ -167,6 +169,8 @@ ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1} echo "use super::common_types::*;" > $APIS_DIR/processed/enum_defaults.rs GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/processed/enum_defaults.rs +sed -i '/#\[kube(status = "GRPCRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' ./gateway-api/src/apis/processed/grpcroutes.rs +sed -i '/#\[kube(status = "HTTPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' ./gateway-api/src/apis/processed/httproutes.rs From 609c9cd582dab5711b82f5b1c31f28b45d6968e0 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Thu, 26 Jun 2025 10:31:55 +0100 Subject: [PATCH 05/16] Removal of processed folder, adding an ability to rename-only types, ordering types in common, changes to argument parsing Signed-off-by: Dawid Nowak --- Cargo.lock | 54 +- gateway-api/src/apis/mod.rs | 2 - gateway-api/src/apis/processed/constants.rs | 90 - .../src/apis/processed/enum_defaults.rs | 20 - .../src/apis/processed/gatewayclasses.rs | 111 - gateway-api/src/apis/processed/gateways.rs | 624 ------ gateway-api/src/apis/processed/grpcroutes.rs | 406 ---- gateway-api/src/apis/processed/httproutes.rs | 743 ------- gateway-api/src/apis/processed/mod.rs | 10 - .../src/apis/processed/referencegrants.rs | 96 - .../common_types.rs => standard/common.rs} | 246 ++- gateway-api/src/apis/standard/constants.rs | 13 +- .../src/apis/standard/enum_defaults.rs | 52 +- .../src/apis/standard/gatewayclasses.rs | 24 +- gateway-api/src/apis/standard/gateways.rs | 129 +- gateway-api/src/apis/standard/grpcroutes.rs | 1206 +---------- gateway-api/src/apis/standard/httproutes.rs | 1779 ++--------------- gateway-api/src/apis/standard/mod.rs | 4 +- .../src/apis/standard/referencegrants.rs | 18 +- gateway-api/src/duration.rs | 7 +- gateway-api/src/lib.rs | 52 +- type-reducer/customized_mapped_names.txt | 40 +- type-reducer/reduced_types_pass_0.txt | 2 +- type-reducer/reduced_types_pass_1.txt | 8 +- type-reducer/reduced_types_pass_2.txt | 9 +- type-reducer/reduced_types_pass_3.txt | 9 +- type-reducer/rename_only_mapped_names.txt | 14 + type-reducer/src/lib.rs | 184 +- type-reducer/src/main.rs | 194 +- type-reducer/src/visitors.rs | 53 +- update.sh | 31 +- 31 files changed, 657 insertions(+), 5573 deletions(-) delete mode 100644 gateway-api/src/apis/processed/constants.rs delete mode 100644 gateway-api/src/apis/processed/enum_defaults.rs delete mode 100644 gateway-api/src/apis/processed/gatewayclasses.rs delete mode 100644 gateway-api/src/apis/processed/gateways.rs delete mode 100644 gateway-api/src/apis/processed/grpcroutes.rs delete mode 100644 gateway-api/src/apis/processed/httproutes.rs delete mode 100644 gateway-api/src/apis/processed/mod.rs delete mode 100644 gateway-api/src/apis/processed/referencegrants.rs rename gateway-api/src/apis/{processed/common_types.rs => standard/common.rs} (96%) create mode 100644 type-reducer/rename_only_mapped_names.txt diff --git a/Cargo.lock b/Cargo.lock index 8670e11..7e3aedf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "adler2" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "aho-corasick" @@ -147,9 +147,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "chrono" @@ -163,9 +163,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.39" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f" +checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" dependencies = [ "clap_builder", "clap_derive", @@ -173,9 +173,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.39" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51" +checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" dependencies = [ "anstream", "anstyle", @@ -185,9 +185,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.32" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" +checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" dependencies = [ "heck", "proc-macro2", @@ -197,9 +197,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "codegen" @@ -496,7 +496,7 @@ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi 0.11.1+wasi-snapshot-preview1", ] [[package]] @@ -525,9 +525,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.15.3" +version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "headers" @@ -728,7 +728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", - "hashbrown 0.15.3", + "hashbrown 0.15.4", ] [[package]] @@ -914,9 +914,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" dependencies = [ "adler2", ] @@ -928,7 +928,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" dependencies = [ "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi 0.11.1+wasi-snapshot-preview1", "windows-sys 0.59.0", ] @@ -1251,9 +1251,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.24" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" [[package]] name = "rustls" @@ -1555,9 +1555,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.15.0" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "socket2" @@ -1583,9 +1583,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.101" +version = "2.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +checksum = "f6397daf94fa90f058bd0fd88429dd9e5738999cca8d701813c80723add80462" dependencies = [ "proc-macro2", "quote", @@ -1909,9 +1909,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" diff --git a/gateway-api/src/apis/mod.rs b/gateway-api/src/apis/mod.rs index 1eb5595..7651e9f 100644 --- a/gateway-api/src/apis/mod.rs +++ b/gateway-api/src/apis/mod.rs @@ -1,4 +1,2 @@ pub mod experimental; pub mod standard; - -pub mod processed; diff --git a/gateway-api/src/apis/processed/constants.rs b/gateway-api/src/apis/processed/constants.rs deleted file mode 100644 index ef75c43..0000000 --- a/gateway-api/src/apis/processed/constants.rs +++ /dev/null @@ -1,90 +0,0 @@ -// WARNING! generated file do not edit - -#[derive(Debug, PartialEq, Eq)] -pub enum GatewayClassConditionType { - Accepted, -} -impl std::fmt::Display for GatewayClassConditionType { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} -#[derive(Debug, PartialEq, Eq)] -pub enum GatewayClassConditionReason { - Accepted, - InvalidParameters, - Pending, - Unsupported, - Waiting, -} -impl std::fmt::Display for GatewayClassConditionReason { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} -#[derive(Debug, PartialEq, Eq)] -pub enum GatewayConditionType { - Programmed, - Accepted, - Ready, -} -impl std::fmt::Display for GatewayConditionType { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} -#[derive(Debug, PartialEq, Eq)] -pub enum GatewayConditionReason { - Programmed, - Invalid, - NoResources, - AddressNotAssigned, - AddressNotUsable, - Accepted, - ListenersNotValid, - Pending, - UnsupportedAddress, - InvalidParameters, - Ready, - ListenersNotReady, -} -impl std::fmt::Display for GatewayConditionReason { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} -#[derive(Debug, PartialEq, Eq)] -pub enum ListenerConditionType { - Conflicted, - Accepted, - ResolvedRefs, - Programmed, - Ready, -} -impl std::fmt::Display for ListenerConditionType { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} -#[derive(Debug, PartialEq, Eq)] -pub enum ListenerConditionReason { - HostnameConflict, - ProtocolConflict, - NoConflicts, - Accepted, - PortUnavailable, - UnsupportedProtocol, - ResolvedRefs, - InvalidCertificateRef, - InvalidRouteKinds, - RefNotPermitted, - Programmed, - Invalid, - Pending, - Ready, -} -impl std::fmt::Display for ListenerConditionReason { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} diff --git a/gateway-api/src/apis/processed/enum_defaults.rs b/gateway-api/src/apis/processed/enum_defaults.rs deleted file mode 100644 index 5a40b4d..0000000 --- a/gateway-api/src/apis/processed/enum_defaults.rs +++ /dev/null @@ -1,20 +0,0 @@ -use super::common_types::*; -// WARNING: generated file - manual changes will be overriden - -impl Default for GRPCFilterType { - fn default() -> Self { - GRPCFilterType::RequestHeaderModifier - } -} - -impl Default for HTTPFilterType { - fn default() -> Self { - HTTPFilterType::RequestHeaderModifier - } -} - -impl Default for RequestOperationType { - fn default() -> Self { - RequestOperationType::ReplaceFullPath - } -} diff --git a/gateway-api/src/apis/processed/gatewayclasses.rs b/gateway-api/src/apis/processed/gatewayclasses.rs deleted file mode 100644 index 7efa74c..0000000 --- a/gateway-api/src/apis/processed/gatewayclasses.rs +++ /dev/null @@ -1,111 +0,0 @@ -// WARNING! generated file do not edit - -#[allow(unused_imports)] -mod prelude { - pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; - pub use kube::CustomResource; - pub use schemars::JsonSchema; - pub use serde::{Deserialize, Serialize}; -} -use self::prelude::*; -/// Spec defines the desired state of GatewayClass. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] -#[kube( - group = "gateway.networking.k8s.io", - version = "v1", - kind = "GatewayClass", - plural = "gatewayclasses" -)] -#[kube(status = "GatewayClassStatus")] -#[kube(derive = "Default")] -#[kube(derive = "PartialEq")] -pub struct GatewayClassSpec { - /// ControllerName is the name of the controller that is managing Gateways of - /// this class. The value of this field MUST be a domain prefixed path. - /// - /// Example: "example.net/gateway-controller". - /// - /// This field is not mutable and cannot be empty. - /// - /// Support: Core - #[serde(rename = "controllerName")] - pub controller_name: String, - /// Description helps describe a GatewayClass with more details. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub description: Option, - /// ParametersRef is a reference to a resource that contains the configuration - /// parameters corresponding to the GatewayClass. This is optional if the - /// controller does not require any additional configuration. - /// - /// ParametersRef can reference a standard Kubernetes resource, i.e. ConfigMap, - /// or an implementation-specific custom resource. The resource can be - /// cluster-scoped or namespace-scoped. - /// - /// If the referent cannot be found, refers to an unsupported kind, or when - /// the data within that resource is malformed, the GatewayClass SHOULD be - /// rejected with the "Accepted" status condition set to "False" and an - /// "InvalidParameters" reason. - /// - /// A Gateway for this GatewayClass may provide its own `parametersRef`. When both are specified, - /// the merging behavior is implementation specific. - /// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. - /// - /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "parametersRef")] - pub parameters_ref: Option, -} -/// ParametersRef is a reference to a resource that contains the configuration -/// parameters corresponding to the GatewayClass. This is optional if the -/// controller does not require any additional configuration. -/// -/// ParametersRef can reference a standard Kubernetes resource, i.e. ConfigMap, -/// or an implementation-specific custom resource. The resource can be -/// cluster-scoped or namespace-scoped. -/// -/// If the referent cannot be found, refers to an unsupported kind, or when -/// the data within that resource is malformed, the GatewayClass SHOULD be -/// rejected with the "Accepted" status condition set to "False" and an -/// "InvalidParameters" reason. -/// -/// A Gateway for this GatewayClass may provide its own `parametersRef`. When both are specified, -/// the merging behavior is implementation specific. -/// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. -/// -/// Support: Implementation-specific -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayClassParametersRef { - /// Group is the group of the referent. - pub group: String, - /// Kind is kind of the referent. - pub kind: String, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the referent. - /// This field is required when referring to a Namespace-scoped resource and - /// MUST be unset when referring to a Cluster-scoped resource. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, -} -/// Status defines the current state of GatewayClass. -/// -/// Implementations MUST populate status on all GatewayClass resources which -/// specify their controller name. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayClassStatus { - /// Conditions is the current status from the controller for - /// this GatewayClass. - /// - /// Controllers should prefer to publish conditions using values - /// of GatewayClassConditionType for the type of each Condition. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, -} diff --git a/gateway-api/src/apis/processed/gateways.rs b/gateway-api/src/apis/processed/gateways.rs deleted file mode 100644 index 7a47c1c..0000000 --- a/gateway-api/src/apis/processed/gateways.rs +++ /dev/null @@ -1,624 +0,0 @@ -// WARNING! generated file do not edit - -use super::common_types::*; -#[allow(unused_imports)] -mod prelude { - pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; - pub use kube::CustomResource; - pub use schemars::JsonSchema; - pub use serde::{Deserialize, Serialize}; - pub use std::collections::BTreeMap; -} -use self::prelude::*; -/// Spec defines the desired state of Gateway. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] -#[kube( - group = "gateway.networking.k8s.io", - version = "v1", - kind = "Gateway", - plural = "gateways" -)] -#[kube(namespaced)] -#[kube(status = "GatewayStatus")] -#[kube(derive = "Default")] -#[kube(derive = "PartialEq")] -pub struct GatewaySpec { - /// Addresses requested for this Gateway. This is optional and behavior can - /// depend on the implementation. If a value is set in the spec and the - /// requested address is invalid or unavailable, the implementation MUST - /// indicate this in the associated entry in GatewayStatus.Addresses. - /// - /// The Addresses field represents a request for the address(es) on the - /// "outside of the Gateway", that traffic bound for this Gateway will use. - /// This could be the IP address or hostname of an external load balancer or - /// other networking infrastructure, or some other address that traffic will - /// be sent to. - /// - /// If no Addresses are specified, the implementation MAY schedule the - /// Gateway in an implementation-specific manner, assigning an appropriate - /// set of Addresses. - /// - /// The implementation MUST bind all Listeners to every GatewayAddress that - /// it assigns to the Gateway and add a corresponding entry in - /// GatewayStatus.Addresses. - /// - /// Support: Extended - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub addresses: Option>, - /// GatewayClassName used for this Gateway. This is the name of a - /// GatewayClass resource. - #[serde(rename = "gatewayClassName")] - pub gateway_class_name: String, - /// Infrastructure defines infrastructure level attributes about this Gateway instance. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub infrastructure: Option, - /// Listeners associated with this Gateway. Listeners define - /// logical endpoints that are bound on this Gateway's addresses. - /// At least one Listener MUST be specified. - /// - /// Each Listener in a set of Listeners (for example, in a single Gateway) - /// MUST be _distinct_, in that a traffic flow MUST be able to be assigned to - /// exactly one listener. (This section uses "set of Listeners" rather than - /// "Listeners in a single Gateway" because implementations MAY merge configuration - /// from multiple Gateways onto a single data plane, and these rules _also_ - /// apply in that case). - /// - /// Practically, this means that each listener in a set MUST have a unique - /// combination of Port, Protocol, and, if supported by the protocol, Hostname. - /// - /// Some combinations of port, protocol, and TLS settings are considered - /// Core support and MUST be supported by implementations based on their - /// targeted conformance profile: - /// - /// HTTP Profile - /// - /// 1. HTTPRoute, Port: 80, Protocol: HTTP - /// 2. HTTPRoute, Port: 443, Protocol: HTTPS, TLS Mode: Terminate, TLS keypair provided - /// - /// TLS Profile - /// - /// 1. TLSRoute, Port: 443, Protocol: TLS, TLS Mode: Passthrough - /// - /// "Distinct" Listeners have the following property: - /// - /// The implementation can match inbound requests to a single distinct - /// Listener. When multiple Listeners share values for fields (for - /// example, two Listeners with the same Port value), the implementation - /// can match requests to only one of the Listeners using other - /// Listener fields. - /// - /// For example, the following Listener scenarios are distinct: - /// - /// 1. Multiple Listeners with the same Port that all use the "HTTP" - /// Protocol that all have unique Hostname values. - /// 2. Multiple Listeners with the same Port that use either the "HTTPS" or - /// "TLS" Protocol that all have unique Hostname values. - /// 3. A mixture of "TCP" and "UDP" Protocol Listeners, where no Listener - /// with the same Protocol has the same Port value. - /// - /// Some fields in the Listener struct have possible values that affect - /// whether the Listener is distinct. Hostname is particularly relevant - /// for HTTP or HTTPS protocols. - /// - /// When using the Hostname value to select between same-Port, same-Protocol - /// Listeners, the Hostname value must be different on each Listener for the - /// Listener to be distinct. - /// - /// When the Listeners are distinct based on Hostname, inbound request - /// hostnames MUST match from the most specific to least specific Hostname - /// values to choose the correct Listener and its associated set of Routes. - /// - /// Exact matches must be processed before wildcard matches, and wildcard - /// matches must be processed before fallback (empty Hostname value) - /// matches. For example, `"foo.example.com"` takes precedence over - /// `"*.example.com"`, and `"*.example.com"` takes precedence over `""`. - /// - /// Additionally, if there are multiple wildcard entries, more specific - /// wildcard entries must be processed before less specific wildcard entries. - /// For example, `"*.foo.example.com"` takes precedence over `"*.example.com"`. - /// The precise definition here is that the higher the number of dots in the - /// hostname to the right of the wildcard character, the higher the precedence. - /// - /// The wildcard character will match any number of characters _and dots_ to - /// the left, however, so `"*.example.com"` will match both - /// `"foo.bar.example.com"` _and_ `"bar.example.com"`. - /// - /// If a set of Listeners contains Listeners that are not distinct, then those - /// Listeners are Conflicted, and the implementation MUST set the "Conflicted" - /// condition in the Listener Status to "True". - /// - /// Implementations MAY choose to accept a Gateway with some Conflicted - /// Listeners only if they only accept the partial Listener set that contains - /// no Conflicted Listeners. To put this another way, implementations may - /// accept a partial Listener set only if they throw out *all* the conflicting - /// Listeners. No picking one of the conflicting listeners as the winner. - /// This also means that the Gateway must have at least one non-conflicting - /// Listener in this case, otherwise it violates the requirement that at - /// least one Listener must be present. - /// - /// The implementation MUST set a "ListenersNotValid" condition on the - /// Gateway Status when the Gateway contains Conflicted Listeners whether or - /// not they accept the Gateway. That Condition SHOULD clearly - /// indicate in the Message which Listeners are conflicted, and which are - /// Accepted. Additionally, the Listener status for those listeners SHOULD - /// indicate which Listeners are conflicted and not Accepted. - /// - /// A Gateway's Listeners are considered "compatible" if: - /// - /// 1. They are distinct. - /// 2. The implementation can serve them in compliance with the Addresses - /// requirement that all Listeners are available on all assigned - /// addresses. - /// - /// Compatible combinations in Extended support are expected to vary across - /// implementations. A combination that is compatible for one implementation - /// may not be compatible for another. - /// - /// For example, an implementation that cannot serve both TCP and UDP listeners - /// on the same address, or cannot mix HTTPS and generic TLS listens on the same port - /// would not consider those cases compatible, even though they are distinct. - /// - /// Note that requests SHOULD match at most one Listener. For example, if - /// Listeners are defined for "foo.example.com" and "*.example.com", a - /// request to "foo.example.com" SHOULD only be routed using routes attached - /// to the "foo.example.com" Listener (and not the "*.example.com" Listener). - /// This concept is known as "Listener Isolation". Implementations that do - /// not support Listener Isolation MUST clearly document this. - /// - /// Implementations MAY merge separate Gateways onto a single set of - /// Addresses if all Listeners across all Gateways are compatible. - /// - /// Support: Core - pub listeners: Vec, -} -/// Infrastructure defines infrastructure level attributes about this Gateway instance. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayInfrastructure { - /// Annotations that SHOULD be applied to any resources created in response to this Gateway. - /// - /// For implementations creating other Kubernetes objects, this should be the `metadata.annotations` field on resources. - /// For other implementations, this refers to any relevant (implementation specific) "annotations" concepts. - /// - /// An implementation may chose to add additional implementation-specific annotations as they see fit. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub annotations: Option>, - /// Labels that SHOULD be applied to any resources created in response to this Gateway. - /// - /// For implementations creating other Kubernetes objects, this should be the `metadata.labels` field on resources. - /// For other implementations, this refers to any relevant (implementation specific) "labels" concepts. - /// - /// An implementation may chose to add additional implementation-specific labels as they see fit. - /// - /// If an implementation maps these labels to Pods, or any other resource that would need to be recreated when labels - /// change, it SHOULD clearly warn about this behavior in documentation. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub labels: Option>, - /// ParametersRef is a reference to a resource that contains the configuration - /// parameters corresponding to the Gateway. This is optional if the - /// controller does not require any additional configuration. - /// - /// This follows the same semantics as GatewayClass's `parametersRef`, but on a per-Gateway basis - /// - /// The Gateway's GatewayClass may provide its own `parametersRef`. When both are specified, - /// the merging behavior is implementation specific. - /// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. - /// - /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "parametersRef")] - pub parameters_ref: Option, -} -/// Listener embodies the concept of a logical endpoint where a Gateway accepts -/// network connections. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListeners { - /// AllowedRoutes defines the types of routes that MAY be attached to a - /// Listener and the trusted namespaces where those Route resources MAY be - /// present. - /// - /// Although a client request may match multiple route rules, only one rule - /// may ultimately receive the request. Matching precedence MUST be - /// determined in order of the following criteria: - /// - /// * The most specific match as defined by the Route type. - /// * The oldest Route based on creation timestamp. For example, a Route with - /// a creation timestamp of "2020-09-08 01:02:03" is given precedence over - /// a Route with a creation timestamp of "2020-09-08 01:02:04". - /// * If everything else is equivalent, the Route appearing first in - /// alphabetical order (namespace/name) should be given precedence. For - /// example, foo/bar is given precedence over foo/baz. - /// - /// All valid rules within a Route attached to this Listener should be - /// implemented. Invalid Route rules can be ignored (sometimes that will mean - /// the full Route). If a Route rule transitions from valid to invalid, - /// support for that Route rule should be dropped to ensure consistency. For - /// example, even if a filter specified by a Route rule is invalid, the rest - /// of the rules within that Route should still be supported. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none", rename = "allowedRoutes")] - pub allowed_routes: Option, - /// Hostname specifies the virtual hostname to match for protocol types that - /// define this concept. When unspecified, all hostnames are matched. This - /// field is ignored for protocols that don't require hostname based - /// matching. - /// - /// Implementations MUST apply Hostname matching appropriately for each of - /// the following protocols: - /// - /// * TLS: The Listener Hostname MUST match the SNI. - /// * HTTP: The Listener Hostname MUST match the Host header of the request. - /// * HTTPS: The Listener Hostname SHOULD match at both the TLS and HTTP - /// protocol layers as described above. If an implementation does not - /// ensure that both the SNI and Host header match the Listener hostname, - /// it MUST clearly document that. - /// - /// For HTTPRoute and TLSRoute resources, there is an interaction with the - /// `spec.hostnames` array. When both listener and route specify hostnames, - /// there MUST be an intersection between the values for a Route to be - /// accepted. For more information, refer to the Route specific Hostnames - /// documentation. - /// - /// Hostnames that are prefixed with a wildcard label (`*.`) are interpreted - /// as a suffix match. That means that a match for `*.example.com` would match - /// both `test.example.com`, and `foo.test.example.com`, but not `example.com`. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Name is the name of the Listener. This name MUST be unique within a - /// Gateway. - /// - /// Support: Core - pub name: String, - /// Port is the network port. Multiple listeners may use the - /// same port, subject to the Listener compatibility rules. - /// - /// Support: Core - pub port: i32, - /// Protocol specifies the network protocol this listener expects to receive. - /// - /// Support: Core - pub protocol: String, - /// TLS is the TLS configuration for the Listener. This field is required if - /// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field - /// if the Protocol field is "HTTP", "TCP", or "UDP". - /// - /// The association of SNIs to Certificate defined in GatewayTLSConfig is - /// defined based on the Hostname field for this listener. - /// - /// The GatewayClass MUST use the longest matching SNI out of all - /// available certificates for any TLS handshake. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub tls: Option, -} -/// AllowedRoutes defines the types of routes that MAY be attached to a -/// Listener and the trusted namespaces where those Route resources MAY be -/// present. -/// -/// Although a client request may match multiple route rules, only one rule -/// may ultimately receive the request. Matching precedence MUST be -/// determined in order of the following criteria: -/// -/// * The most specific match as defined by the Route type. -/// * The oldest Route based on creation timestamp. For example, a Route with -/// a creation timestamp of "2020-09-08 01:02:03" is given precedence over -/// a Route with a creation timestamp of "2020-09-08 01:02:04". -/// * If everything else is equivalent, the Route appearing first in -/// alphabetical order (namespace/name) should be given precedence. For -/// example, foo/bar is given precedence over foo/baz. -/// -/// All valid rules within a Route attached to this Listener should be -/// implemented. Invalid Route rules can be ignored (sometimes that will mean -/// the full Route). If a Route rule transitions from valid to invalid, -/// support for that Route rule should be dropped to ensure consistency. For -/// example, even if a filter specified by a Route rule is invalid, the rest -/// of the rules within that Route should still be supported. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersAllowedRoutes { - /// Kinds specifies the groups and kinds of Routes that are allowed to bind - /// to this Gateway Listener. When unspecified or empty, the kinds of Routes - /// selected are determined using the Listener protocol. - /// - /// A RouteGroupKind MUST correspond to kinds of Routes that are compatible - /// with the application protocol specified in the Listener's Protocol field. - /// If an implementation does not support or recognize this resource type, it - /// MUST set the "ResolvedRefs" condition to False for this Listener with the - /// "InvalidRouteKinds" reason. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kinds: Option>, - /// Namespaces indicates namespaces from which Routes may be attached to this - /// Listener. This is restricted to the namespace of this Gateway by default. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespaces: Option, -} -/// Namespaces indicates namespaces from which Routes may be attached to this -/// Listener. This is restricted to the namespace of this Gateway by default. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersAllowedRoutesNamespaces { - /// From indicates where Routes will be selected for this Gateway. Possible - /// values are: - /// - /// * All: Routes in all namespaces may be used by this Gateway. - /// * Selector: Routes in namespaces selected by the selector may be used by - /// this Gateway. - /// * Same: Only Routes in the same namespace may be used by this Gateway. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub from: Option, - /// Selector must be specified when From is set to "Selector". In that case, - /// only Routes in Namespaces matching this Selector will be selected by this - /// Gateway. This field is ignored for other values of "From". - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub selector: Option, -} -/// Namespaces indicates namespaces from which Routes may be attached to this -/// Listener. This is restricted to the namespace of this Gateway by default. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GatewayListenersAllowedRoutesNamespacesFrom { - All, - Selector, - Same, -} -/// Selector must be specified when From is set to "Selector". In that case, -/// only Routes in Namespaces matching this Selector will be selected by this -/// Gateway. This field is ignored for other values of "From". -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersAllowedRoutesNamespacesSelector { - /// matchExpressions is a list of label selector requirements. The requirements are ANDed. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "matchExpressions" - )] - pub match_expressions: Option< - Vec, - >, - /// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels - /// map is equivalent to an element of matchExpressions, whose key field is "key", the - /// operator is "In", and the values array contains only "value". The requirements are ANDed. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "matchLabels")] - pub match_labels: Option>, -} -/// A label selector requirement is a selector that contains values, a key, and an operator that -/// relates the key and values. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersAllowedRoutesNamespacesSelectorMatchExpressions { - /// key is the label key that the selector applies to. - pub key: String, - /// operator represents a key's relationship to a set of values. - /// Valid operators are In, NotIn, Exists and DoesNotExist. - pub operator: String, - /// values is an array of string values. If the operator is In or NotIn, - /// the values array must be non-empty. If the operator is Exists or DoesNotExist, - /// the values array must be empty. This array is replaced during a strategic - /// merge patch. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub values: Option>, -} -/// TLS is the TLS configuration for the Listener. This field is required if -/// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field -/// if the Protocol field is "HTTP", "TCP", or "UDP". -/// -/// The association of SNIs to Certificate defined in GatewayTLSConfig is -/// defined based on the Hostname field for this listener. -/// -/// The GatewayClass MUST use the longest matching SNI out of all -/// available certificates for any TLS handshake. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersTls { - /// CertificateRefs contains a series of references to Kubernetes objects that - /// contains TLS certificates and private keys. These certificates are used to - /// establish a TLS handshake for requests that match the hostname of the - /// associated listener. - /// - /// A single CertificateRef to a Kubernetes Secret has "Core" support. - /// Implementations MAY choose to support attaching multiple certificates to - /// a Listener, but this behavior is implementation-specific. - /// - /// References to a resource in different namespace are invalid UNLESS there - /// is a ReferenceGrant in the target namespace that allows the certificate - /// to be attached. If a ReferenceGrant does not allow this reference, the - /// "ResolvedRefs" condition MUST be set to False for this listener with the - /// "RefNotPermitted" reason. - /// - /// This field is required to have at least one element when the mode is set - /// to "Terminate" (default) and is optional otherwise. - /// - /// CertificateRefs can reference to standard Kubernetes resources, i.e. - /// Secret, or implementation-specific custom resources. - /// - /// Support: Core - A single reference to a Kubernetes Secret of type kubernetes.io/tls - /// - /// Support: Implementation-specific (More than one reference or other resource types) - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "certificateRefs" - )] - pub certificate_refs: Option>, - /// Mode defines the TLS behavior for the TLS session initiated by the client. - /// There are two possible modes: - /// - /// - Terminate: The TLS session between the downstream client and the - /// Gateway is terminated at the Gateway. This mode requires certificates - /// to be specified in some way, such as populating the certificateRefs - /// field. - /// - Passthrough: The TLS session is NOT terminated by the Gateway. This - /// implies that the Gateway can't decipher the TLS stream except for - /// the ClientHello message of the TLS protocol. The certificateRefs field - /// is ignored in this mode. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub mode: Option, - /// Options are a list of key/value pairs to enable extended TLS - /// configuration for each implementation. For example, configuring the - /// minimum TLS version or supported cipher suites. - /// - /// A set of common keys MAY be defined by the API in the future. To avoid - /// any ambiguity, implementation-specific definitions MUST use - /// domain-prefixed names, such as `example.com/my-custom-option`. - /// Un-prefixed names are reserved for key names defined by Gateway API. - /// - /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none")] - pub options: Option>, -} -/// SecretObjectReference identifies an API object including its namespace, -/// defaulting to Secret. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -/// -/// References to objects with invalid Group and Kind are not valid, and must -/// be rejected by the implementation, with appropriate Conditions set -/// on the containing object. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersTlsCertificateRefs { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. For example "Secret". - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the referenced object. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, -} -/// TLS is the TLS configuration for the Listener. This field is required if -/// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field -/// if the Protocol field is "HTTP", "TCP", or "UDP". -/// -/// The association of SNIs to Certificate defined in GatewayTLSConfig is -/// defined based on the Hostname field for this listener. -/// -/// The GatewayClass MUST use the longest matching SNI out of all -/// available certificates for any TLS handshake. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GatewayListenersTlsMode { - Terminate, - Passthrough, -} -/// Status defines the current state of Gateway. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayStatus { - /// Addresses lists the network addresses that have been bound to the - /// Gateway. - /// - /// This list may differ from the addresses provided in the spec under some - /// conditions: - /// - /// * no addresses are specified, all addresses are dynamically assigned - /// * a combination of specified and dynamic addresses are assigned - /// * a specified address was unusable (e.g. already in use) - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub addresses: Option>, - /// Conditions describe the current conditions of the Gateway. - /// - /// Implementations should prefer to express Gateway conditions - /// using the `GatewayConditionType` and `GatewayConditionReason` - /// constants so that operators and tools can converge on a common - /// vocabulary to describe Gateway state. - /// - /// Known condition types are: - /// - /// * "Accepted" - /// * "Programmed" - /// * "Ready" - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// Listeners provide status for each unique listener port defined in the Spec. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub listeners: Option>, -} -/// ListenerStatus is the status associated with a Listener. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayStatusListeners { - /// AttachedRoutes represents the total number of Routes that have been - /// successfully attached to this Listener. - /// - /// Successful attachment of a Route to a Listener is based solely on the - /// combination of the AllowedRoutes field on the corresponding Listener - /// and the Route's ParentRefs field. A Route is successfully attached to - /// a Listener when it is selected by the Listener's AllowedRoutes field - /// AND the Route has a valid ParentRef selecting the whole Gateway - /// resource or a specific Listener as a parent resource (more detail on - /// attachment semantics can be found in the documentation on the various - /// Route kinds ParentRefs fields). Listener or Route status does not impact - /// successful attachment, i.e. the AttachedRoutes field count MUST be set - /// for Listeners with condition Accepted: false and MUST count successfully - /// attached Routes that may themselves have Accepted: false conditions. - /// - /// Uses for this field include troubleshooting Route attachment and - /// measuring blast radius/impact of changes to a Listener. - #[serde(rename = "attachedRoutes")] - pub attached_routes: i32, - /// Conditions describe the current condition of this listener. - pub conditions: Vec, - /// Name is the name of the Listener that this status corresponds to. - pub name: String, - /// SupportedKinds is the list indicating the Kinds supported by this - /// listener. This MUST represent the kinds an implementation supports for - /// that Listener configuration. - /// - /// If kinds are specified in Spec that are not supported, they MUST NOT - /// appear in this list and an implementation MUST set the "ResolvedRefs" - /// condition to "False" with the "InvalidRouteKinds" reason. If both valid - /// and invalid Route kinds are specified, the implementation MUST - /// reference the valid Route kinds that have been specified. - #[serde(rename = "supportedKinds")] - pub supported_kinds: Vec, -} diff --git a/gateway-api/src/apis/processed/grpcroutes.rs b/gateway-api/src/apis/processed/grpcroutes.rs deleted file mode 100644 index 8b9a315..0000000 --- a/gateway-api/src/apis/processed/grpcroutes.rs +++ /dev/null @@ -1,406 +0,0 @@ -// WARNING! generated file do not edit - -use super::common_types::*; -#[allow(unused_imports)] -mod prelude { - pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; - pub use kube::CustomResource; - pub use schemars::JsonSchema; - pub use serde::{Deserialize, Serialize}; -} -use self::prelude::*; -/// Spec defines the desired state of GRPCRoute. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] -#[kube( - group = "gateway.networking.k8s.io", - version = "v1", - kind = "GRPCRoute", - plural = "grpcroutes" -)] -#[kube(namespaced)] -#[kube(status = "RouteStatus")] -#[kube(derive = "Default")] -#[kube(derive = "PartialEq")] -pub struct GRPCRouteSpec { - /// Hostnames defines a set of hostnames to match against the GRPC - /// Host header to select a GRPCRoute to process the request. This matches - /// the RFC 1123 definition of a hostname with 2 notable exceptions: - /// - /// 1. IPs are not allowed. - /// 2. A hostname may be prefixed with a wildcard label (`*.`). The wildcard - /// label MUST appear by itself as the first label. - /// - /// If a hostname is specified by both the Listener and GRPCRoute, there - /// MUST be at least one intersecting hostname for the GRPCRoute to be - /// attached to the Listener. For example: - /// - /// * A Listener with `test.example.com` as the hostname matches GRPCRoutes - /// that have either not specified any hostnames, or have specified at - /// least one of `test.example.com` or `*.example.com`. - /// * A Listener with `*.example.com` as the hostname matches GRPCRoutes - /// that have either not specified any hostnames or have specified at least - /// one hostname that matches the Listener hostname. For example, - /// `test.example.com` and `*.example.com` would both match. On the other - /// hand, `example.com` and `test.example.net` would not match. - /// - /// Hostnames that are prefixed with a wildcard label (`*.`) are interpreted - /// as a suffix match. That means that a match for `*.example.com` would match - /// both `test.example.com`, and `foo.test.example.com`, but not `example.com`. - /// - /// If both the Listener and GRPCRoute have specified hostnames, any - /// GRPCRoute hostnames that do not match the Listener hostname MUST be - /// ignored. For example, if a Listener specified `*.example.com`, and the - /// GRPCRoute specified `test.example.com` and `test.example.net`, - /// `test.example.net` MUST NOT be considered for a match. - /// - /// If both the Listener and GRPCRoute have specified hostnames, and none - /// match with the criteria above, then the GRPCRoute MUST NOT be accepted by - /// the implementation. The implementation MUST raise an 'Accepted' Condition - /// with a status of `False` in the corresponding RouteParentStatus. - /// - /// If a Route (A) of type HTTPRoute or GRPCRoute is attached to a - /// Listener and that listener already has another Route (B) of the other - /// type attached and the intersection of the hostnames of A and B is - /// non-empty, then the implementation MUST accept exactly one of these two - /// routes, determined by the following criteria, in order: - /// - /// * The oldest Route based on creation timestamp. - /// * The Route appearing first in alphabetical order by - /// "{namespace}/{name}". - /// - /// The rejected Route MUST raise an 'Accepted' condition with a status of - /// 'False' in the corresponding RouteParentStatus. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostnames: Option>, - /// ParentRefs references the resources (usually Gateways) that a Route wants - /// to be attached to. Note that the referenced parent resource needs to - /// allow this for the attachment to be complete. For Gateways, that means - /// the Gateway needs to allow attachment from Routes of this kind and - /// namespace. For Services, that means the Service must either be in the same - /// namespace for a "producer" route, or the mesh implementation must support - /// and allow "consumer" routes for the referenced Service. ReferenceGrant is - /// not applicable for governing ParentRefs to Services - it is not possible to - /// create a "producer" route for a Service in a different namespace from the - /// Route. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// This API may be extended in the future to support additional kinds of parent - /// resources. - /// - /// ParentRefs must be _distinct_. This means either that: - /// - /// * They select different objects. If this is the case, then parentRef - /// entries are distinct. In terms of fields, this means that the - /// multi-part key defined by `group`, `kind`, `namespace`, and `name` must - /// be unique across all parentRef entries in the Route. - /// * They do not select different objects, but for each optional field used, - /// each ParentRef that selects the same object must set the same set of - /// optional fields to different values. If one ParentRef sets a - /// combination of optional fields, all must set the same combination. - /// - /// Some examples: - /// - /// * If one ParentRef sets `sectionName`, all ParentRefs referencing the - /// same object must also set `sectionName`. - /// * If one ParentRef sets `port`, all ParentRefs referencing the same - /// object must also set `port`. - /// * If one ParentRef sets `sectionName` and `port`, all ParentRefs - /// referencing the same object must also set `sectionName` and `port`. - /// - /// It is possible to separately reference multiple distinct objects that may - /// be collapsed by an implementation. For example, some implementations may - /// choose to merge compatible Gateway Listeners together. If that is the - /// case, the list of routes attached to those resources should also be - /// merged. - /// - /// Note that for ParentRefs that cross namespace boundaries, there are specific - /// rules. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example, - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable other kinds of cross-namespace reference. - /// - /// - /// - /// - /// - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "parentRefs")] - pub parent_refs: Option>, - /// Rules are a list of GRPC matchers, filters and actions. - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub rules: Option>, -} -/// GRPCRouteRule defines the semantics for matching a gRPC request based on -/// conditions (matches), processing it (filters), and forwarding the request to -/// an API object (backendRefs). -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRules { - /// BackendRefs defines the backend(s) where matching requests should be - /// sent. - /// - /// Failure behavior here depends on how many BackendRefs are specified and - /// how many are invalid. - /// - /// If *all* entries in BackendRefs are invalid, and there are also no filters - /// specified in this route rule, *all* traffic which matches this rule MUST - /// receive an `UNAVAILABLE` status. - /// - /// See the GRPCBackendRef definition for the rules about what makes a single - /// GRPCBackendRef invalid. - /// - /// When a GRPCBackendRef is invalid, `UNAVAILABLE` statuses MUST be returned for - /// requests that would have otherwise been routed to an invalid backend. If - /// multiple backends are specified, and some are invalid, the proportion of - /// requests that would otherwise have been routed to an invalid backend - /// MUST receive an `UNAVAILABLE` status. - /// - /// For example, if two backends are specified with equal weights, and one is - /// invalid, 50 percent of traffic MUST receive an `UNAVAILABLE` status. - /// Implementations may choose how that 50 percent is determined. - /// - /// Support: Core for Kubernetes Service - /// - /// Support: Implementation-specific for any other resource - /// - /// Support for weight: Core - #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRefs")] - pub backend_refs: Option>, - /// Filters define the filters that are applied to requests that match - /// this rule. - /// - /// The effects of ordering of multiple behaviors are currently unspecified. - /// This can change in the future based on feedback during the alpha stage. - /// - /// Conformance-levels at this level are defined based on the type of filter: - /// - /// - ALL core filters MUST be supported by all implementations that support - /// GRPCRoute. - /// - Implementers are encouraged to support extended filters. - /// - Implementation-specific custom filters have no API guarantees across - /// implementations. - /// - /// Specifying the same filter multiple times is not supported unless explicitly - /// indicated in the filter. - /// - /// If an implementation can not support a combination of filters, it must clearly - /// document that limitation. In cases where incompatible or unsupported - /// filters are specified and cause the `Accepted` condition to be set to status - /// `False`, implementations may use the `IncompatibleFilters` reason to specify - /// this configuration error. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, - /// Matches define conditions used for matching the rule against incoming - /// gRPC requests. Each match is independent, i.e. this rule will be matched - /// if **any** one of the matches is satisfied. - /// - /// For example, take the following matches configuration: - /// - /// ```text - /// matches: - /// - method: - /// service: foo.bar - /// headers: - /// values: - /// version: 2 - /// - method: - /// service: foo.bar.v2 - /// ``` - /// - /// For a request to match against this rule, it MUST satisfy - /// EITHER of the two conditions: - /// - /// - service of foo.bar AND contains the header `version: 2` - /// - service of foo.bar.v2 - /// - /// See the documentation for GRPCRouteMatch on how to specify multiple - /// match conditions to be ANDed together. - /// - /// If no matches are specified, the implementation MUST match every gRPC request. - /// - /// Proxy or Load Balancer routing configuration generated from GRPCRoutes - /// MUST prioritize rules based on the following criteria, continuing on - /// ties. Merging MUST not be done between GRPCRoutes and HTTPRoutes. - /// Precedence MUST be given to the rule with the largest number of: - /// - /// * Characters in a matching non-wildcard hostname. - /// * Characters in a matching hostname. - /// * Characters in a matching service. - /// * Characters in a matching method. - /// * Header matches. - /// - /// If ties still exist across multiple Routes, matching precedence MUST be - /// determined in order of the following criteria, continuing on ties: - /// - /// * The oldest Route based on creation timestamp. - /// * The Route appearing first in alphabetical order by - /// "{namespace}/{name}". - /// - /// If ties still exist within the Route that has been given precedence, - /// matching precedence MUST be granted to the first matching rule meeting - /// the above criteria. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub matches: Option>, -} -/// GRPCBackendRef defines how a GRPCRoute forwards a gRPC request. -/// -/// Note that when a namespace different than the local namespace is specified, a -/// ReferenceGrant object is required in the referent namespace to allow that -/// namespace's owner to accept the reference. See the ReferenceGrant -/// documentation for details. -/// -/// -/// -/// When the BackendRef points to a Kubernetes Service, implementations SHOULD -/// honor the appProtocol field if it is set for the target Service Port. -/// -/// Implementations supporting appProtocol SHOULD recognize the Kubernetes -/// Standard Application Protocols defined in KEP-3726. -/// -/// If a Service appProtocol isn't specified, an implementation MAY infer the -/// backend protocol through its own means. Implementations MAY infer the -/// protocol from the Route type referring to the backend Service. -/// -/// If a Route is not able to send traffic to the backend using the specified -/// protocol then the backend is considered invalid. Implementations MUST set the -/// "ResolvedRefs" condition to "False" with the "UnsupportedProtocol" reason. -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefs { - /// Filters defined at this level MUST be executed if and only if the - /// request is being forwarded to the backend defined here. - /// - /// Support: Implementation-specific (For broader support of filters, use the - /// Filters field in GRPCRouteRule.) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Weight specifies the proportion of requests forwarded to the referenced - /// backend. This is computed as weight/(sum of all weights in this - /// BackendRefs list). For non-zero values, there may be some epsilon from - /// the exact proportion defined here depending on the precision an - /// implementation supports. Weight is not a percentage and the sum of - /// weights does not need to equal 100. - /// - /// If only one backend is specified and it has a weight greater than 0, 100% - /// of the traffic is forwarded to that backend. If weight is set to 0, no - /// traffic should be forwarded for this entry. If unspecified, weight - /// defaults to 1. - /// - /// Support for this field varies based on the context where used. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub weight: Option, -} -/// GRPCRouteMatch defines the predicate used to match requests to a given -/// action. Multiple match types are ANDed together, i.e. the match will -/// evaluate to true only if all conditions are satisfied. -/// -/// For example, the match below will match a gRPC request only if its service -/// is `foo` AND it contains the `version: v1` header: -/// -/// ```text -/// matches: -/// - method: -/// type: Exact -/// service: "foo" -/// headers: -/// - name: "version" -/// value "v1" -/// -/// ``` -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesMatches { - /// Headers specifies gRPC request header matchers. Multiple match values are - /// ANDed together, meaning, a request MUST match all the specified headers - /// to select the route. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub headers: Option>, - /// Method specifies a gRPC request service/method matcher. If this field is - /// not specified, all services and methods will match. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub method: Option, -} -/// Method specifies a gRPC request service/method matcher. If this field is -/// not specified, all services and methods will match. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesMatchesMethod { - /// Value of the method to match against. If left empty or omitted, will - /// match all services. - /// - /// At least one of Service and Method MUST be a non-empty string. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub method: Option, - /// Value of the service to match against. If left empty or omitted, will - /// match any service. - /// - /// At least one of Service and Method MUST be a non-empty string. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub service: Option, - /// Type specifies how to match against the service and/or method. - /// Support: Core (Exact with service and method specified) - /// - /// Support: Implementation-specific (Exact with method specified but no service specified) - /// - /// Support: Implementation-specific (RegularExpression) - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, -} diff --git a/gateway-api/src/apis/processed/httproutes.rs b/gateway-api/src/apis/processed/httproutes.rs deleted file mode 100644 index c3eeac7..0000000 --- a/gateway-api/src/apis/processed/httproutes.rs +++ /dev/null @@ -1,743 +0,0 @@ -// WARNING! generated file do not edit - -use super::common_types::*; -#[allow(unused_imports)] -mod prelude { - pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; - pub use kube::CustomResource; - pub use schemars::JsonSchema; - pub use serde::{Deserialize, Serialize}; -} -use self::prelude::*; -/// Spec defines the desired state of HTTPRoute. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] -#[kube( - group = "gateway.networking.k8s.io", - version = "v1", - kind = "HTTPRoute", - plural = "httproutes" -)] -#[kube(namespaced)] -#[kube(status = "RouteStatus")] -#[kube(derive = "Default")] -#[kube(derive = "PartialEq")] -pub struct HTTPRouteSpec { - /// Hostnames defines a set of hostnames that should match against the HTTP Host - /// header to select a HTTPRoute used to process the request. Implementations - /// MUST ignore any port value specified in the HTTP Host header while - /// performing a match and (absent of any applicable header modification - /// configuration) MUST forward this header unmodified to the backend. - /// - /// Valid values for Hostnames are determined by RFC 1123 definition of a - /// hostname with 2 notable exceptions: - /// - /// 1. IPs are not allowed. - /// 2. A hostname may be prefixed with a wildcard label (`*.`). The wildcard - /// label must appear by itself as the first label. - /// - /// If a hostname is specified by both the Listener and HTTPRoute, there - /// must be at least one intersecting hostname for the HTTPRoute to be - /// attached to the Listener. For example: - /// - /// * A Listener with `test.example.com` as the hostname matches HTTPRoutes - /// that have either not specified any hostnames, or have specified at - /// least one of `test.example.com` or `*.example.com`. - /// * A Listener with `*.example.com` as the hostname matches HTTPRoutes - /// that have either not specified any hostnames or have specified at least - /// one hostname that matches the Listener hostname. For example, - /// `*.example.com`, `test.example.com`, and `foo.test.example.com` would - /// all match. On the other hand, `example.com` and `test.example.net` would - /// not match. - /// - /// Hostnames that are prefixed with a wildcard label (`*.`) are interpreted - /// as a suffix match. That means that a match for `*.example.com` would match - /// both `test.example.com`, and `foo.test.example.com`, but not `example.com`. - /// - /// If both the Listener and HTTPRoute have specified hostnames, any - /// HTTPRoute hostnames that do not match the Listener hostname MUST be - /// ignored. For example, if a Listener specified `*.example.com`, and the - /// HTTPRoute specified `test.example.com` and `test.example.net`, - /// `test.example.net` must not be considered for a match. - /// - /// If both the Listener and HTTPRoute have specified hostnames, and none - /// match with the criteria above, then the HTTPRoute is not accepted. The - /// implementation must raise an 'Accepted' Condition with a status of - /// `False` in the corresponding RouteParentStatus. - /// - /// In the event that multiple HTTPRoutes specify intersecting hostnames (e.g. - /// overlapping wildcard matching and exact matching hostnames), precedence must - /// be given to rules from the HTTPRoute with the largest number of: - /// - /// * Characters in a matching non-wildcard hostname. - /// * Characters in a matching hostname. - /// - /// If ties exist across multiple Routes, the matching precedence rules for - /// HTTPRouteMatches takes over. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostnames: Option>, - /// ParentRefs references the resources (usually Gateways) that a Route wants - /// to be attached to. Note that the referenced parent resource needs to - /// allow this for the attachment to be complete. For Gateways, that means - /// the Gateway needs to allow attachment from Routes of this kind and - /// namespace. For Services, that means the Service must either be in the same - /// namespace for a "producer" route, or the mesh implementation must support - /// and allow "consumer" routes for the referenced Service. ReferenceGrant is - /// not applicable for governing ParentRefs to Services - it is not possible to - /// create a "producer" route for a Service in a different namespace from the - /// Route. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// This API may be extended in the future to support additional kinds of parent - /// resources. - /// - /// ParentRefs must be _distinct_. This means either that: - /// - /// * They select different objects. If this is the case, then parentRef - /// entries are distinct. In terms of fields, this means that the - /// multi-part key defined by `group`, `kind`, `namespace`, and `name` must - /// be unique across all parentRef entries in the Route. - /// * They do not select different objects, but for each optional field used, - /// each ParentRef that selects the same object must set the same set of - /// optional fields to different values. If one ParentRef sets a - /// combination of optional fields, all must set the same combination. - /// - /// Some examples: - /// - /// * If one ParentRef sets `sectionName`, all ParentRefs referencing the - /// same object must also set `sectionName`. - /// * If one ParentRef sets `port`, all ParentRefs referencing the same - /// object must also set `port`. - /// * If one ParentRef sets `sectionName` and `port`, all ParentRefs - /// referencing the same object must also set `sectionName` and `port`. - /// - /// It is possible to separately reference multiple distinct objects that may - /// be collapsed by an implementation. For example, some implementations may - /// choose to merge compatible Gateway Listeners together. If that is the - /// case, the list of routes attached to those resources should also be - /// merged. - /// - /// Note that for ParentRefs that cross namespace boundaries, there are specific - /// rules. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example, - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable other kinds of cross-namespace reference. - /// - /// - /// - /// - /// - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "parentRefs")] - pub parent_refs: Option>, - /// Rules are a list of HTTP matchers, filters and actions. - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub rules: Option>, -} -/// HTTPRouteRule defines semantics for matching an HTTP request based on -/// conditions (matches), processing it (filters), and forwarding the request to -/// an API object (backendRefs). -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRules { - /// BackendRefs defines the backend(s) where matching requests should be - /// sent. - /// - /// Failure behavior here depends on how many BackendRefs are specified and - /// how many are invalid. - /// - /// If *all* entries in BackendRefs are invalid, and there are also no filters - /// specified in this route rule, *all* traffic which matches this rule MUST - /// receive a 500 status code. - /// - /// See the HTTPBackendRef definition for the rules about what makes a single - /// HTTPBackendRef invalid. - /// - /// When a HTTPBackendRef is invalid, 500 status codes MUST be returned for - /// requests that would have otherwise been routed to an invalid backend. If - /// multiple backends are specified, and some are invalid, the proportion of - /// requests that would otherwise have been routed to an invalid backend - /// MUST receive a 500 status code. - /// - /// For example, if two backends are specified with equal weights, and one is - /// invalid, 50 percent of traffic must receive a 500. Implementations may - /// choose how that 50 percent is determined. - /// - /// When a HTTPBackendRef refers to a Service that has no ready endpoints, - /// implementations SHOULD return a 503 for requests to that backend instead. - /// If an implementation chooses to do this, all of the above rules for 500 responses - /// MUST also apply for responses that return a 503. - /// - /// Support: Core for Kubernetes Service - /// - /// Support: Extended for Kubernetes ServiceImport - /// - /// Support: Implementation-specific for any other resource - /// - /// Support for weight: Core - #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRefs")] - pub backend_refs: Option>, - /// Filters define the filters that are applied to requests that match - /// this rule. - /// - /// Wherever possible, implementations SHOULD implement filters in the order - /// they are specified. - /// - /// Implementations MAY choose to implement this ordering strictly, rejecting - /// any combination or order of filters that can not be supported. If implementations - /// choose a strict interpretation of filter ordering, they MUST clearly document - /// that behavior. - /// - /// To reject an invalid combination or order of filters, implementations SHOULD - /// consider the Route Rules with this configuration invalid. If all Route Rules - /// in a Route are invalid, the entire Route would be considered invalid. If only - /// a portion of Route Rules are invalid, implementations MUST set the - /// "PartiallyInvalid" condition for the Route. - /// - /// Conformance-levels at this level are defined based on the type of filter: - /// - /// - ALL core filters MUST be supported by all implementations. - /// - Implementers are encouraged to support extended filters. - /// - Implementation-specific custom filters have no API guarantees across - /// implementations. - /// - /// Specifying the same filter multiple times is not supported unless explicitly - /// indicated in the filter. - /// - /// All filters are expected to be compatible with each other except for the - /// URLRewrite and RequestRedirect filters, which may not be combined. If an - /// implementation can not support other combinations of filters, they must clearly - /// document that limitation. In cases where incompatible or unsupported - /// filters are specified and cause the `Accepted` condition to be set to status - /// `False`, implementations may use the `IncompatibleFilters` reason to specify - /// this configuration error. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, - /// Matches define conditions used for matching the rule against incoming - /// HTTP requests. Each match is independent, i.e. this rule will be matched - /// if **any** one of the matches is satisfied. - /// - /// For example, take the following matches configuration: - /// - /// ```text - /// matches: - /// - path: - /// value: "/foo" - /// headers: - /// - name: "version" - /// value: "v2" - /// - path: - /// value: "/v2/foo" - /// ``` - /// - /// For a request to match against this rule, a request must satisfy - /// EITHER of the two conditions: - /// - /// - path prefixed with `/foo` AND contains the header `version: v2` - /// - path prefix of `/v2/foo` - /// - /// See the documentation for HTTPRouteMatch on how to specify multiple - /// match conditions that should be ANDed together. - /// - /// If no matches are specified, the default is a prefix - /// path match on "/", which has the effect of matching every - /// HTTP request. - /// - /// Proxy or Load Balancer routing configuration generated from HTTPRoutes - /// MUST prioritize matches based on the following criteria, continuing on - /// ties. Across all rules specified on applicable Routes, precedence must be - /// given to the match having: - /// - /// * "Exact" path match. - /// * "Prefix" path match with largest number of characters. - /// * Method match. - /// * Largest number of header matches. - /// * Largest number of query param matches. - /// - /// Note: The precedence of RegularExpression path matches are implementation-specific. - /// - /// If ties still exist across multiple Routes, matching precedence MUST be - /// determined in order of the following criteria, continuing on ties: - /// - /// * The oldest Route based on creation timestamp. - /// * The Route appearing first in alphabetical order by - /// "{namespace}/{name}". - /// - /// If ties still exist within an HTTPRoute, matching precedence MUST be granted - /// to the FIRST matching rule (in list order) with a match meeting the above - /// criteria. - /// - /// When no rules matching a request have been successfully attached to the - /// parent a request is coming from, a HTTP 404 status code MUST be returned. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub matches: Option>, - /// Timeouts defines the timeouts that can be configured for an HTTP request. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub timeouts: Option, -} -/// HTTPBackendRef defines how a HTTPRoute forwards a HTTP request. -/// -/// Note that when a namespace different than the local namespace is specified, a -/// ReferenceGrant object is required in the referent namespace to allow that -/// namespace's owner to accept the reference. See the ReferenceGrant -/// documentation for details. -/// -/// -/// -/// When the BackendRef points to a Kubernetes Service, implementations SHOULD -/// honor the appProtocol field if it is set for the target Service Port. -/// -/// Implementations supporting appProtocol SHOULD recognize the Kubernetes -/// Standard Application Protocols defined in KEP-3726. -/// -/// If a Service appProtocol isn't specified, an implementation MAY infer the -/// backend protocol through its own means. Implementations MAY infer the -/// protocol from the Route type referring to the backend Service. -/// -/// If a Route is not able to send traffic to the backend using the specified -/// protocol then the backend is considered invalid. Implementations MUST set the -/// "ResolvedRefs" condition to "False" with the "UnsupportedProtocol" reason. -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefs { - /// Filters defined at this level should be executed if and only if the - /// request is being forwarded to the backend defined here. - /// - /// Support: Implementation-specific (For broader support of filters, use the - /// Filters field in HTTPRouteRule.) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Weight specifies the proportion of requests forwarded to the referenced - /// backend. This is computed as weight/(sum of all weights in this - /// BackendRefs list). For non-zero values, there may be some epsilon from - /// the exact proportion defined here depending on the precision an - /// implementation supports. Weight is not a percentage and the sum of - /// weights does not need to equal 100. - /// - /// If only one backend is specified and it has a weight greater than 0, 100% - /// of the traffic is forwarded to that backend. If weight is set to 0, no - /// traffic should be forwarded for this entry. If unspecified, weight - /// defaults to 1. - /// - /// Support for this field varies based on the context where used. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub weight: Option, -} -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// This filter can be used multiple times within the same rule. - /// - /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] - pub request_mirror: Option, - /// RequestRedirect defines a schema for a filter that responds to the - /// request with an HTTP redirection. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestRedirect" - )] - pub request_redirect: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations must support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by - /// specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` should be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPFilterType, - /// URLRewrite defines a schema for a filter that modifies a request during forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] - pub url_rewrite: Option, -} -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// This filter can be used multiple times within the same rule. - /// - /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] - pub request_mirror: Option, - /// RequestRedirect defines a schema for a filter that responds to the - /// request with an HTTP redirection. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestRedirect" - )] - pub request_redirect: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations must support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by - /// specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` should be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPFilterType, - /// URLRewrite defines a schema for a filter that modifies a request during forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] - pub url_rewrite: Option, -} -/// HTTPRouteMatch defines the predicate used to match requests to a given -/// action. Multiple match types are ANDed together, i.e. the match will -/// evaluate to true only if all conditions are satisfied. -/// -/// For example, the match below will match a HTTP request only if its path -/// starts with `/foo` AND it contains the `version: v1` header: -/// -/// ```text -/// match: -/// -/// path: -/// value: "/foo" -/// headers: -/// - name: "version" -/// value "v1" -/// -/// ``` -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatches { - /// Headers specifies HTTP request header matchers. Multiple match values are - /// ANDed together, meaning, a request must match all the specified headers - /// to select the route. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub headers: Option>, - /// Method specifies HTTP method matcher. - /// When specified, this route will be matched only if the request has the - /// specified method. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub method: Option, - /// Path specifies a HTTP request path matcher. If this field is not - /// specified, a default prefix match on the "/" path is provided. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, - /// QueryParams specifies HTTP query parameter matchers. Multiple match - /// values are ANDed together, meaning, a request must match all the - /// specified query parameters to select the route. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "queryParams")] - pub query_params: Option>, -} -/// HTTPRouteMatch defines the predicate used to match requests to a given -/// action. Multiple match types are ANDed together, i.e. the match will -/// evaluate to true only if all conditions are satisfied. -/// -/// For example, the match below will match a HTTP request only if its path -/// starts with `/foo` AND it contains the `version: v1` header: -/// -/// ```text -/// match: -/// -/// path: -/// value: "/foo" -/// headers: -/// - name: "version" -/// value "v1" -/// -/// ``` -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesMethod { - #[serde(rename = "GET")] - Get, - #[serde(rename = "HEAD")] - Head, - #[serde(rename = "POST")] - Post, - #[serde(rename = "PUT")] - Put, - #[serde(rename = "DELETE")] - Delete, - #[serde(rename = "CONNECT")] - Connect, - #[serde(rename = "OPTIONS")] - Options, - #[serde(rename = "TRACE")] - Trace, - #[serde(rename = "PATCH")] - Patch, -} -/// Path specifies a HTTP request path matcher. If this field is not -/// specified, a default prefix match on the "/" path is provided. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatchesPath { - /// Type specifies how to match against the path Value. - /// - /// Support: Core (Exact, PathPrefix) - /// - /// Support: Implementation-specific (RegularExpression) - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value of the HTTP path to match against. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub value: Option, -} -/// Path specifies a HTTP request path matcher. If this field is not -/// specified, a default prefix match on the "/" path is provided. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesPathType { - Exact, - PathPrefix, - RegularExpression, -} -/// Timeouts defines the timeouts that can be configured for an HTTP request. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesTimeouts { - /// BackendRequest specifies a timeout for an individual request from the gateway - /// to a backend. This covers the time from when the request first starts being - /// sent from the gateway to when the full response has been received from the backend. - /// - /// Setting a timeout to the zero duration (e.g. "0s") SHOULD disable the timeout - /// completely. Implementations that cannot completely disable the timeout MUST - /// instead interpret the zero duration as the longest possible value to which - /// the timeout can be set. - /// - /// An entire client HTTP transaction with a gateway, covered by the Request timeout, - /// may result in more than one call from the gateway to the destination backend, - /// for example, if automatic retries are supported. - /// - /// The value of BackendRequest must be a Gateway API Duration string as defined by - /// GEP-2257. When this field is unspecified, its behavior is implementation-specific; - /// when specified, the value of BackendRequest must be no more than the value of the - /// Request timeout (since the Request timeout encompasses the BackendRequest timeout). - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRequest")] - pub backend_request: Option, - /// Request specifies the maximum duration for a gateway to respond to an HTTP request. - /// If the gateway has not been able to respond before this deadline is met, the gateway - /// MUST return a timeout error. - /// - /// For example, setting the `rules.timeouts.request` field to the value `10s` in an - /// `HTTPRoute` will cause a timeout if a client request is taking longer than 10 seconds - /// to complete. - /// - /// Setting a timeout to the zero duration (e.g. "0s") SHOULD disable the timeout - /// completely. Implementations that cannot completely disable the timeout MUST - /// instead interpret the zero duration as the longest possible value to which - /// the timeout can be set. - /// - /// This timeout is intended to cover as close to the whole request-response transaction - /// as possible although an implementation MAY choose to start the timeout after the entire - /// request stream has been received instead of immediately after the transaction is - /// initiated by the client. - /// - /// The value of Request is a Gateway API Duration string as defined by GEP-2257. When this - /// field is unspecified, request timeout behavior is implementation-specific. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub request: Option, -} diff --git a/gateway-api/src/apis/processed/mod.rs b/gateway-api/src/apis/processed/mod.rs deleted file mode 100644 index 937b77b..0000000 --- a/gateway-api/src/apis/processed/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -// WARNING! generated file do not edit - -pub mod common_types; -pub mod constants; -pub mod enum_defaults; -pub mod gatewayclasses; -pub mod gateways; -pub mod grpcroutes; -pub mod httproutes; -pub mod referencegrants; diff --git a/gateway-api/src/apis/processed/referencegrants.rs b/gateway-api/src/apis/processed/referencegrants.rs deleted file mode 100644 index c785978..0000000 --- a/gateway-api/src/apis/processed/referencegrants.rs +++ /dev/null @@ -1,96 +0,0 @@ -// WARNING! generated file do not edit - -#[allow(unused_imports)] -mod prelude { - pub use kube::CustomResource; - pub use schemars::JsonSchema; - pub use serde::{Deserialize, Serialize}; -} -use self::prelude::*; -/// Spec defines the desired state of ReferenceGrant. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] -#[kube( - group = "gateway.networking.k8s.io", - version = "v1beta1", - kind = "ReferenceGrant", - plural = "referencegrants" -)] -#[kube(namespaced)] -#[kube(derive = "Default")] -#[kube(derive = "PartialEq")] -pub struct ReferenceGrantSpec { - /// From describes the trusted namespaces and kinds that can reference the - /// resources described in "To". Each entry in this list MUST be considered - /// to be an additional place that references can be valid from, or to put - /// this another way, entries MUST be combined using OR. - /// - /// Support: Core - pub from: Vec, - /// To describes the resources that may be referenced by the resources - /// described in "From". Each entry in this list MUST be considered to be an - /// additional place that references can be valid to, or to put this another - /// way, entries MUST be combined using OR. - /// - /// Support: Core - pub to: Vec, -} -/// ReferenceGrantFrom describes trusted namespaces and kinds. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct ReferenceGrantFrom { - /// Group is the group of the referent. - /// When empty, the Kubernetes core API group is inferred. - /// - /// Support: Core - pub group: String, - /// Kind is the kind of the referent. Although implementations may support - /// additional resources, the following types are part of the "Core" - /// support level for this field. - /// - /// When used to permit a SecretObjectReference: - /// - /// * Gateway - /// - /// When used to permit a BackendObjectReference: - /// - /// * GRPCRoute - /// * HTTPRoute - /// * TCPRoute - /// * TLSRoute - /// * UDPRoute - pub kind: String, - /// Namespace is the namespace of the referent. - /// - /// Support: Core - pub namespace: String, -} -/// ReferenceGrantTo describes what Kinds are allowed as targets of the -/// references. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct ReferenceGrantTo { - /// Group is the group of the referent. - /// When empty, the Kubernetes core API group is inferred. - /// - /// Support: Core - pub group: String, - /// Kind is the kind of the referent. Although implementations may support - /// additional resources, the following types are part of the "Core" - /// support level for this field: - /// - /// * Secret when used to permit a SecretObjectReference - /// * Service when used to permit a BackendObjectReference - pub kind: String, - /// Name is the name of the referent. When unspecified, this policy - /// refers to all resources of the specified Group and Kind in the local - /// namespace. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub name: Option, -} diff --git a/gateway-api/src/apis/processed/common_types.rs b/gateway-api/src/apis/standard/common.rs similarity index 96% rename from gateway-api/src/apis/processed/common_types.rs rename to gateway-api/src/apis/standard/common.rs index d1bf70d..293de6b 100644 --- a/gateway-api/src/apis/processed/common_types.rs +++ b/gateway-api/src/apis/standard/common.rs @@ -9,95 +9,35 @@ mod prelude { pub use std::collections::BTreeMap; } use self::prelude::*; -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayAddress { - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - pub value: String, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayInfrastructureParametersRef { - pub group: String, - pub kind: String, - pub name: String, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct Kind { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - pub kind: String, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPHeader { - pub name: String, - pub value: String, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct RequestMirrorRef { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - pub name: String, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, -} -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct RouteRef { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - pub name: String, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")] - pub section_name: Option, -} -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// GRPCRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. GRPCRouteFilters are meant as an extension /// point to express processing that may be done in Gateway implementations. Some /// examples include request or response modification, implementing /// authentication strategies, rate-limiting, and traffic shaping. API /// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPFilterType { - RequestHeaderModifier, +pub enum GRPCFilterType { ResponseHeaderModifier, + RequestHeaderModifier, RequestMirror, - RequestRedirect, - #[serde(rename = "URLRewrite")] - UrlRewrite, ExtensionRef, } -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension /// point to express processing that may be done in Gateway implementations. Some /// examples include request or response modification, implementing /// authentication strategies, rate-limiting, and traffic shaping. API /// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCFilterType { - ResponseHeaderModifier, +pub enum HTTPFilterType { RequestHeaderModifier, + ResponseHeaderModifier, RequestMirror, + RequestRedirect, + #[serde(rename = "URLRewrite")] + UrlRewrite, ExtensionRef, } -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum RequestRedirectScheme { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, -} /// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request /// headers. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] @@ -105,6 +45,17 @@ pub enum HeaderMatchType { Exact, RegularExpression, } +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum RedirectStatusCode { + #[serde(rename = "301")] + r#_301, + #[serde(rename = "302")] + r#_302, +} /// Path defines parameters used to modify the path of the incoming request. /// The modified path is then used to construct the `Location` header. When /// empty, the request path is used as-is. @@ -120,87 +71,112 @@ pub enum RequestOperationType { /// /// Support: Core #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum RedirectStatusCode { - #[serde(rename = "301")] - r#_301, - #[serde(rename = "302")] - r#_302, +pub enum RequestRedirectScheme { + #[serde(rename = "http")] + Http, + #[serde(rename = "https")] + Https, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct RequestRedirectPath { - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - #[serde(rename = "type")] - pub r#type: RequestOperationType, +pub struct GatewayAddress { + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + pub value: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct MatchingHeaders { +pub struct GatewayInfrastructureParametersReference { + pub group: String, + pub kind: String, pub name: String, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - pub value: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct RequestMirror { - #[serde(rename = "backendRef")] - pub backend_ref: RequestMirrorRef, +pub struct HTTPHeader { + pub name: String, + pub value: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct ParentRouteStatus { +pub struct Kind { #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - #[serde(rename = "controllerName")] - pub controller_name: String, - #[serde(rename = "parentRef")] - pub parent_ref: RouteRef, + pub group: Option, + pub kind: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HeaderModifier { +pub struct ParentReference { #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, + pub group: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, + pub kind: Option, + pub name: String, #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, + pub namespace: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")] + pub section_name: Option, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRequestRedirect { +pub struct RequestMirrorReference { #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, + pub group: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, + pub kind: Option, + pub name: String, #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, + pub namespace: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "statusCode")] - pub status_code: Option, + pub port: Option, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct RouteStatus { - pub parents: Vec, +pub struct HeaderMatch { + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + pub value: String, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteUrlRewrite { +pub struct HeaderModifier { #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, + pub add: Option>, #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, + pub remove: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub set: Option>, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct ParentRouteStatus { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub conditions: Option>, + #[serde(rename = "controllerName")] + pub controller_name: String, + #[serde(rename = "parentRef")] + pub parent_ref: ParentReference, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RequestMirror { + #[serde(rename = "backendRef")] + pub backend_ref: RequestMirrorReference, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RequestRedirectPath { + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replaceFullPath" + )] + pub replace_full_path: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replacePrefixMatch" + )] + pub replace_prefix_match: Option, + #[serde(rename = "type")] + pub r#type: RequestOperationType, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GRPCRouteFilter { #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] - pub extension_ref: Option, + pub extension_ref: Option, #[serde( default, skip_serializing_if = "Option::is_none", @@ -218,7 +194,27 @@ pub struct GRPCRouteFilter { #[serde(rename = "type")] pub r#type: GRPCFilterType, } - - -// Next attempt - +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RequestRedirect { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub scheme: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "statusCode")] + pub status_code: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteUrlRewrite { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RouteStatus { + pub parents: Vec, +} diff --git a/gateway-api/src/apis/standard/constants.rs b/gateway-api/src/apis/standard/constants.rs index 2605e44..ef75c43 100644 --- a/gateway-api/src/apis/standard/constants.rs +++ b/gateway-api/src/apis/standard/constants.rs @@ -1,16 +1,14 @@ -// WARNING: generated file - manual changes will be overriden +// WARNING! generated file do not edit #[derive(Debug, PartialEq, Eq)] pub enum GatewayClassConditionType { Accepted, } - impl std::fmt::Display for GatewayClassConditionType { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum GatewayClassConditionReason { Accepted, @@ -19,26 +17,22 @@ pub enum GatewayClassConditionReason { Unsupported, Waiting, } - impl std::fmt::Display for GatewayClassConditionReason { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum GatewayConditionType { Programmed, Accepted, Ready, } - impl std::fmt::Display for GatewayConditionType { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum GatewayConditionReason { Programmed, @@ -54,13 +48,11 @@ pub enum GatewayConditionReason { Ready, ListenersNotReady, } - impl std::fmt::Display for GatewayConditionReason { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum ListenerConditionType { Conflicted, @@ -69,13 +61,11 @@ pub enum ListenerConditionType { Programmed, Ready, } - impl std::fmt::Display for ListenerConditionType { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum ListenerConditionReason { HostnameConflict, @@ -93,7 +83,6 @@ pub enum ListenerConditionReason { Pending, Ready, } - impl std::fmt::Display for ListenerConditionReason { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) diff --git a/gateway-api/src/apis/standard/enum_defaults.rs b/gateway-api/src/apis/standard/enum_defaults.rs index 3fee275..fe4f3ae 100644 --- a/gateway-api/src/apis/standard/enum_defaults.rs +++ b/gateway-api/src/apis/standard/enum_defaults.rs @@ -1,58 +1,20 @@ +use super::common::*; // WARNING: generated file - manual changes will be overriden -use super::httproutes::{ - HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType, HTTPRouteRulesBackendRefsFiltersType, - HTTPRouteRulesBackendRefsFiltersUrlRewritePathType, - HTTPRouteRulesFiltersRequestRedirectPathType, HTTPRouteRulesFiltersType, - HTTPRouteRulesFiltersUrlRewritePathType, -}; - -use super::grpcroutes::{GRPCRouteRulesBackendRefsFiltersType, GRPCRouteRulesFiltersType}; - -impl Default for GRPCRouteRulesBackendRefsFiltersType { - fn default() -> Self { - GRPCRouteRulesBackendRefsFiltersType::RequestHeaderModifier - } -} - -impl Default for GRPCRouteRulesFiltersType { - fn default() -> Self { - GRPCRouteRulesFiltersType::RequestHeaderModifier - } -} - -impl Default for HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType { - fn default() -> Self { - HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType::ReplaceFullPath - } -} - -impl Default for HTTPRouteRulesBackendRefsFiltersType { - fn default() -> Self { - HTTPRouteRulesBackendRefsFiltersType::RequestHeaderModifier - } -} - -impl Default for HTTPRouteRulesBackendRefsFiltersUrlRewritePathType { - fn default() -> Self { - HTTPRouteRulesBackendRefsFiltersUrlRewritePathType::ReplaceFullPath - } -} - -impl Default for HTTPRouteRulesFiltersRequestRedirectPathType { +impl Default for GRPCFilterType { fn default() -> Self { - HTTPRouteRulesFiltersRequestRedirectPathType::ReplaceFullPath + GRPCFilterType::RequestHeaderModifier } } -impl Default for HTTPRouteRulesFiltersType { +impl Default for HTTPFilterType { fn default() -> Self { - HTTPRouteRulesFiltersType::RequestHeaderModifier + HTTPFilterType::RequestHeaderModifier } } -impl Default for HTTPRouteRulesFiltersUrlRewritePathType { +impl Default for RequestOperationType { fn default() -> Self { - HTTPRouteRulesFiltersUrlRewritePathType::ReplaceFullPath + RequestOperationType::ReplaceFullPath } } diff --git a/gateway-api/src/apis/standard/gatewayclasses.rs b/gateway-api/src/apis/standard/gatewayclasses.rs index 2152e73..7efa74c 100644 --- a/gateway-api/src/apis/standard/gatewayclasses.rs +++ b/gateway-api/src/apis/standard/gatewayclasses.rs @@ -1,6 +1,4 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.1 +// WARNING! generated file do not edit #[allow(unused_imports)] mod prelude { @@ -10,9 +8,17 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of GatewayClass. -#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] #[kube( group = "gateway.networking.k8s.io", version = "v1", @@ -54,14 +60,9 @@ pub struct GatewayClassSpec { /// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. /// /// Support: Implementation-specific - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "parametersRef" - )] + #[serde(default, skip_serializing_if = "Option::is_none", rename = "parametersRef")] pub parameters_ref: Option, } - /// ParametersRef is a reference to a resource that contains the configuration /// parameters corresponding to the GatewayClass. This is optional if the /// controller does not require any additional configuration. @@ -94,7 +95,6 @@ pub struct GatewayClassParametersRef { #[serde(default, skip_serializing_if = "Option::is_none")] pub namespace: Option, } - /// Status defines the current state of GatewayClass. /// /// Implementations MUST populate status on all GatewayClass resources which diff --git a/gateway-api/src/apis/standard/gateways.rs b/gateway-api/src/apis/standard/gateways.rs index ad06c70..462e52e 100644 --- a/gateway-api/src/apis/standard/gateways.rs +++ b/gateway-api/src/apis/standard/gateways.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.1 +// WARNING! generated file do not edit +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -11,9 +10,17 @@ mod prelude { pub use std::collections::BTreeMap; } use self::prelude::*; - /// Spec defines the desired state of Gateway. -#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] #[kube( group = "gateway.networking.k8s.io", version = "v1", @@ -48,7 +55,7 @@ pub struct GatewaySpec { /// /// #[serde(default, skip_serializing_if = "Option::is_none")] - pub addresses: Option>, + pub addresses: Option>, /// GatewayClassName used for this Gateway. This is the name of a /// GatewayClass resource. #[serde(rename = "gatewayClassName")] @@ -177,20 +184,6 @@ pub struct GatewaySpec { /// Support: Core pub listeners: Vec, } - -/// GatewayAddress describes an address that can be bound to a Gateway. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayAddresses { - /// Type of the address. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value of the address. The validity of the values will depend - /// on the type and support by the controller. - /// - /// Examples: `1.2.3.4`, `128::1`, `my-ip-address`. - pub value: String, -} - /// Infrastructure defines infrastructure level attributes about this Gateway instance. /// /// Support: Extended @@ -230,35 +223,9 @@ pub struct GatewayInfrastructure { /// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. /// /// Support: Implementation-specific - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "parametersRef" - )] - pub parameters_ref: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "parametersRef")] + pub parameters_ref: Option, } - -/// ParametersRef is a reference to a resource that contains the configuration -/// parameters corresponding to the Gateway. This is optional if the -/// controller does not require any additional configuration. -/// -/// This follows the same semantics as GatewayClass's `parametersRef`, but on a per-Gateway basis -/// -/// The Gateway's GatewayClass may provide its own `parametersRef`. When both are specified, -/// the merging behavior is implementation specific. -/// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. -/// -/// Support: Implementation-specific -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayInfrastructureParametersRef { - /// Group is the group of the referent. - pub group: String, - /// Kind is kind of the referent. - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} - /// Listener embodies the concept of a logical endpoint where a Gateway accepts /// network connections. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] @@ -287,11 +254,7 @@ pub struct GatewayListeners { /// of the rules within that Route should still be supported. /// /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "allowedRoutes" - )] + #[serde(default, skip_serializing_if = "Option::is_none", rename = "allowedRoutes")] pub allowed_routes: Option, /// Hostname specifies the virtual hostname to match for protocol types that /// define this concept. When unspecified, all hostnames are matched. This @@ -349,7 +312,6 @@ pub struct GatewayListeners { #[serde(default, skip_serializing_if = "Option::is_none")] pub tls: Option, } - /// AllowedRoutes defines the types of routes that MAY be attached to a /// Listener and the trusted namespaces where those Route resources MAY be /// present. @@ -388,7 +350,7 @@ pub struct GatewayListenersAllowedRoutes { /// /// Support: Core #[serde(default, skip_serializing_if = "Option::is_none")] - pub kinds: Option>, + pub kinds: Option>, /// Namespaces indicates namespaces from which Routes may be attached to this /// Listener. This is restricted to the namespace of this Gateway by default. /// @@ -396,17 +358,6 @@ pub struct GatewayListenersAllowedRoutes { #[serde(default, skip_serializing_if = "Option::is_none")] pub namespaces: Option, } - -/// RouteGroupKind indicates the group and kind of a Route resource. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersAllowedRoutesKinds { - /// Group is the group of the Route. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the kind of the Route. - pub kind: String, -} - /// Namespaces indicates namespaces from which Routes may be attached to this /// Listener. This is restricted to the namespace of this Gateway by default. /// @@ -432,7 +383,6 @@ pub struct GatewayListenersAllowedRoutesNamespaces { #[serde(default, skip_serializing_if = "Option::is_none")] pub selector: Option, } - /// Namespaces indicates namespaces from which Routes may be attached to this /// Listener. This is restricted to the namespace of this Gateway by default. /// @@ -443,7 +393,6 @@ pub enum GatewayListenersAllowedRoutesNamespacesFrom { Selector, Same, } - /// Selector must be specified when From is set to "Selector". In that case, /// only Routes in Namespaces matching this Selector will be selected by this /// Gateway. This field is ignored for other values of "From". @@ -457,19 +406,15 @@ pub struct GatewayListenersAllowedRoutesNamespacesSelector { skip_serializing_if = "Option::is_none", rename = "matchExpressions" )] - pub match_expressions: - Option>, + pub match_expressions: Option< + Vec, + >, /// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels /// map is equivalent to an element of matchExpressions, whose key field is "key", the /// operator is "In", and the values array contains only "value". The requirements are ANDed. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "matchLabels" - )] + #[serde(default, skip_serializing_if = "Option::is_none", rename = "matchLabels")] pub match_labels: Option>, } - /// A label selector requirement is a selector that contains values, a key, and an operator that /// relates the key and values. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] @@ -486,7 +431,6 @@ pub struct GatewayListenersAllowedRoutesNamespacesSelectorMatchExpressions { #[serde(default, skip_serializing_if = "Option::is_none")] pub values: Option>, } - /// TLS is the TLS configuration for the Listener. This field is required if /// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field /// if the Protocol field is "HTTP", "TCP", or "UDP". @@ -558,7 +502,6 @@ pub struct GatewayListenersTls { #[serde(default, skip_serializing_if = "Option::is_none")] pub options: Option>, } - /// SecretObjectReference identifies an API object including its namespace, /// defaulting to Secret. /// @@ -591,7 +534,6 @@ pub struct GatewayListenersTlsCertificateRefs { #[serde(default, skip_serializing_if = "Option::is_none")] pub namespace: Option, } - /// TLS is the TLS configuration for the Listener. This field is required if /// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field /// if the Protocol field is "HTTP", "TCP", or "UDP". @@ -608,7 +550,6 @@ pub enum GatewayListenersTlsMode { Terminate, Passthrough, } - /// Status defines the current state of Gateway. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GatewayStatus { @@ -624,7 +565,7 @@ pub struct GatewayStatus { /// /// #[serde(default, skip_serializing_if = "Option::is_none")] - pub addresses: Option>, + pub addresses: Option>, /// Conditions describe the current conditions of the Gateway. /// /// Implementations should prefer to express Gateway conditions @@ -643,20 +584,6 @@ pub struct GatewayStatus { #[serde(default, skip_serializing_if = "Option::is_none")] pub listeners: Option>, } - -/// GatewayStatusAddress describes a network address that is bound to a Gateway. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayStatusAddresses { - /// Type of the address. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value of the address. The validity of the values will depend - /// on the type and support by the controller. - /// - /// Examples: `1.2.3.4`, `128::1`, `my-ip-address`. - pub value: String, -} - /// ListenerStatus is the status associated with a Listener. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GatewayStatusListeners { @@ -693,15 +620,5 @@ pub struct GatewayStatusListeners { /// and invalid Route kinds are specified, the implementation MUST /// reference the valid Route kinds that have been specified. #[serde(rename = "supportedKinds")] - pub supported_kinds: Vec, -} - -/// RouteGroupKind indicates the group and kind of a Route resource. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayStatusListenersSupportedKinds { - /// Group is the group of the Route. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the kind of the Route. - pub kind: String, + pub supported_kinds: Vec, } diff --git a/gateway-api/src/apis/standard/grpcroutes.rs b/gateway-api/src/apis/standard/grpcroutes.rs index 0353700..f83165f 100644 --- a/gateway-api/src/apis/standard/grpcroutes.rs +++ b/gateway-api/src/apis/standard/grpcroutes.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.1 +// WARNING! generated file do not edit +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -10,9 +9,17 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of GRPCRoute. -#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] #[kube( group = "gateway.networking.k8s.io", version = "v1", @@ -20,7 +27,7 @@ use self::prelude::*; plural = "grpcroutes" )] #[kube(namespaced)] -#[kube(status = "GRPCRouteStatus")] +#[kube(status = "RouteStatus")] #[kube(derive = "Default")] #[kube(derive = "PartialEq")] pub struct GRPCRouteSpec { @@ -133,134 +140,19 @@ pub struct GRPCRouteSpec { /// /// /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "parentRefs" - )] - pub parent_refs: Option>, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "parentRefs")] + pub parent_refs: Option>, /// Rules are a list of GRPC matchers, filters and actions. /// /// #[serde(default, skip_serializing_if = "Option::is_none")] - pub rules: Option>, -} - -/// ParentReference identifies an API object (usually a Gateway) that can be considered -/// a parent of this resource (usually a route). There are two kinds of parent resources -/// with "Core" support: -/// -/// * Gateway (Gateway conformance profile) -/// * Service (Mesh conformance profile, ClusterIP Services only) -/// -/// This API may be extended in the future to support additional kinds of parent -/// resources. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteParentRefs { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, + pub rules: Option>, } - /// GRPCRouteRule defines the semantics for matching a gRPC request based on /// conditions (matches), processing it (filters), and forwarding the request to /// an API object (backendRefs). #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRules { +pub struct GRPCRouteRule { /// BackendRefs defines the backend(s) where matching requests should be /// sent. /// @@ -289,12 +181,8 @@ pub struct GRPCRouteRules { /// Support: Implementation-specific for any other resource /// /// Support for weight: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "backendRefs" - )] - pub backend_refs: Option>, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRefs")] + pub backend_refs: Option>, /// Filters define the filters that are applied to requests that match /// this rule. /// @@ -320,7 +208,7 @@ pub struct GRPCRouteRules { /// /// Support: Core #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Matches define conditions used for matching the rule against incoming /// gRPC requests. Each match is independent, i.e. this rule will be matched /// if **any** one of the matches is satisfied. @@ -371,9 +259,8 @@ pub struct GRPCRouteRules { /// matching precedence MUST be granted to the first matching rule meeting /// the above criteria. #[serde(default, skip_serializing_if = "Option::is_none")] - pub matches: Option>, + pub matches: Option>, } - /// GRPCBackendRef defines how a GRPCRoute forwards a gRPC request. /// /// Note that when a namespace different than the local namespace is specified, a @@ -399,14 +286,14 @@ pub struct GRPCRouteRules { /// /// #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefs { +pub struct GRPCBackendReference { /// Filters defined at this level MUST be executed if and only if the /// request is being forwarded to the backend defined here. /// /// Support: Implementation-specific (For broader support of filters, use the /// Filters field in GRPCRouteRule.) #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Group is the group of the referent. For example, "gateway.networking.k8s.io". /// When unspecified or empty string, core API group is inferred. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -463,841 +350,6 @@ pub struct GRPCRouteRulesBackendRefs { #[serde(default, skip_serializing_if = "Option::is_none")] pub weight: Option, } - -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// Support: Implementation-specific - /// - /// This filter can be used multiple times within the same rule. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "extensionRef" - )] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestMirror" - )] - pub request_mirror: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations supporting GRPCRoute MUST support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` MUST be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// - #[serde(rename = "type")] - pub r#type: GRPCRouteRulesBackendRefsFiltersType, -} - -/// ExtensionRef is an optional, implementation-specific extension to the -/// "filter" behavior. For example, resource "myroutefilter" in group -/// "networking.example.net"). ExtensionRef MUST NOT be used for core and -/// extended filters. -/// -/// Support: Implementation-specific -/// -/// This filter can be used multiple times within the same rule. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersExtensionRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - pub group: String, - /// Kind is kind of the referent. For example "HTTPRoute" or "Service". - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} - -/// RequestHeaderModifier defines a schema for a filter that modifies request -/// headers. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// RequestMirror defines a schema for a filter that mirrors requests. -/// Requests are sent to the specified destination, but responses from -/// that destination are ignored. -/// -/// This filter can be used multiple times within the same rule. Note that -/// not all implementations will be able to support mirroring to multiple -/// backends. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestMirror { - /// BackendRef references a resource where mirrored requests are sent. - /// - /// Mirrored requests must be sent only to a single destination endpoint - /// within this BackendRef, irrespective of how many endpoints are present - /// within this BackendRef. - /// - /// If the referent cannot be found, this BackendRef is invalid and must be - /// dropped from the Gateway. The controller must ensure the "ResolvedRefs" - /// condition on the Route status is set to `status: False` and not configure - /// this backend in the underlying implementation. - /// - /// If there is a cross-namespace reference to an *existing* object - /// that is not allowed by a ReferenceGrant, the controller must ensure the - /// "ResolvedRefs" condition on the Route is set to `status: False`, - /// with the "RefNotPermitted" reason and not configure this backend in the - /// underlying implementation. - /// - /// In either error case, the Message of the `ResolvedRefs` Condition - /// should be used to provide more detail about the problem. - /// - /// Support: Extended for Kubernetes Service - /// - /// Support: Implementation-specific for any other resource - #[serde(rename = "backendRef")] - pub backend_ref: GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef, -} - -/// BackendRef references a resource where mirrored requests are sent. -/// -/// Mirrored requests must be sent only to a single destination endpoint -/// within this BackendRef, irrespective of how many endpoints are present -/// within this BackendRef. -/// -/// If the referent cannot be found, this BackendRef is invalid and must be -/// dropped from the Gateway. The controller must ensure the "ResolvedRefs" -/// condition on the Route status is set to `status: False` and not configure -/// this backend in the underlying implementation. -/// -/// If there is a cross-namespace reference to an *existing* object -/// that is not allowed by a ReferenceGrant, the controller must ensure the -/// "ResolvedRefs" condition on the Route is set to `status: False`, -/// with the "RefNotPermitted" reason and not configure this backend in the -/// underlying implementation. -/// -/// In either error case, the Message of the `ResolvedRefs` Condition -/// should be used to provide more detail about the problem. -/// -/// Support: Extended for Kubernetes Service -/// -/// Support: Implementation-specific for any other resource -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, -} - -/// ResponseHeaderModifier defines a schema for a filter that modifies response -/// headers. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersResponseHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesBackendRefsFiltersType { - ResponseHeaderModifier, - RequestHeaderModifier, - RequestMirror, - ExtensionRef, -} - -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// Support: Implementation-specific - /// - /// This filter can be used multiple times within the same rule. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "extensionRef" - )] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestMirror" - )] - pub request_mirror: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations supporting GRPCRoute MUST support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` MUST be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// - #[serde(rename = "type")] - pub r#type: GRPCRouteRulesFiltersType, -} - -/// ExtensionRef is an optional, implementation-specific extension to the -/// "filter" behavior. For example, resource "myroutefilter" in group -/// "networking.example.net"). ExtensionRef MUST NOT be used for core and -/// extended filters. -/// -/// Support: Implementation-specific -/// -/// This filter can be used multiple times within the same rule. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersExtensionRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - pub group: String, - /// Kind is kind of the referent. For example "HTTPRoute" or "Service". - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} - -/// RequestHeaderModifier defines a schema for a filter that modifies request -/// headers. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// RequestMirror defines a schema for a filter that mirrors requests. -/// Requests are sent to the specified destination, but responses from -/// that destination are ignored. -/// -/// This filter can be used multiple times within the same rule. Note that -/// not all implementations will be able to support mirroring to multiple -/// backends. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestMirror { - /// BackendRef references a resource where mirrored requests are sent. - /// - /// Mirrored requests must be sent only to a single destination endpoint - /// within this BackendRef, irrespective of how many endpoints are present - /// within this BackendRef. - /// - /// If the referent cannot be found, this BackendRef is invalid and must be - /// dropped from the Gateway. The controller must ensure the "ResolvedRefs" - /// condition on the Route status is set to `status: False` and not configure - /// this backend in the underlying implementation. - /// - /// If there is a cross-namespace reference to an *existing* object - /// that is not allowed by a ReferenceGrant, the controller must ensure the - /// "ResolvedRefs" condition on the Route is set to `status: False`, - /// with the "RefNotPermitted" reason and not configure this backend in the - /// underlying implementation. - /// - /// In either error case, the Message of the `ResolvedRefs` Condition - /// should be used to provide more detail about the problem. - /// - /// Support: Extended for Kubernetes Service - /// - /// Support: Implementation-specific for any other resource - #[serde(rename = "backendRef")] - pub backend_ref: GRPCRouteRulesFiltersRequestMirrorBackendRef, -} - -/// BackendRef references a resource where mirrored requests are sent. -/// -/// Mirrored requests must be sent only to a single destination endpoint -/// within this BackendRef, irrespective of how many endpoints are present -/// within this BackendRef. -/// -/// If the referent cannot be found, this BackendRef is invalid and must be -/// dropped from the Gateway. The controller must ensure the "ResolvedRefs" -/// condition on the Route status is set to `status: False` and not configure -/// this backend in the underlying implementation. -/// -/// If there is a cross-namespace reference to an *existing* object -/// that is not allowed by a ReferenceGrant, the controller must ensure the -/// "ResolvedRefs" condition on the Route is set to `status: False`, -/// with the "RefNotPermitted" reason and not configure this backend in the -/// underlying implementation. -/// -/// In either error case, the Message of the `ResolvedRefs` Condition -/// should be used to provide more detail about the problem. -/// -/// Support: Extended for Kubernetes Service -/// -/// Support: Implementation-specific for any other resource -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestMirrorBackendRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, -} - -/// ResponseHeaderModifier defines a schema for a filter that modifies response -/// headers. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersResponseHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersResponseHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersResponseHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesFiltersType { - ResponseHeaderModifier, - RequestHeaderModifier, - RequestMirror, - ExtensionRef, -} - /// GRPCRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will /// evaluate to true only if all conditions are satisfied. @@ -1316,49 +368,21 @@ pub enum GRPCRouteRulesFiltersType { /// /// ``` #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesMatches { +pub struct GRPCRouteMatch { /// Headers specifies gRPC request header matchers. Multiple match values are /// ANDed together, meaning, a request MUST match all the specified headers /// to select the route. #[serde(default, skip_serializing_if = "Option::is_none")] - pub headers: Option>, + pub headers: Option>, /// Method specifies a gRPC request service/method matcher. If this field is /// not specified, all services and methods will match. #[serde(default, skip_serializing_if = "Option::is_none")] - pub method: Option, -} - -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesMatchesHeaders { - /// Name is the name of the gRPC Header to be matched. - /// - /// If multiple entries specify equivalent header names, only the first - /// entry with an equivalent name MUST be considered for a match. Subsequent - /// entries with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Type specifies how to match against the value of the header. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value is the value of the gRPC Header to be matched. - pub value: String, -} - -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesMatchesHeadersType { - Exact, - RegularExpression, + pub method: Option, } - /// Method specifies a gRPC request service/method matcher. If this field is /// not specified, all services and methods will match. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesMatchesMethod { +pub struct GRPCMethodMatch { /// Value of the method to match against. If left empty or omitted, will /// match all services. /// @@ -1378,179 +402,5 @@ pub struct GRPCRouteRulesMatchesMethod { /// /// Support: Implementation-specific (RegularExpression) #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, -} - -/// Method specifies a gRPC request service/method matcher. If this field is -/// not specified, all services and methods will match. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesMatchesMethodType { - Exact, - RegularExpression, -} - -/// Status defines the current state of GRPCRoute. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteStatus { - /// Parents is a list of parent resources (usually Gateways) that are - /// associated with the route, and the status of the route with respect to - /// each parent. When this route attaches to a parent, the controller that - /// manages the parent must add an entry to this list when the controller - /// first sees the route and should update the entry as appropriate when the - /// route or gateway is modified. - /// - /// Note that parent references that cannot be resolved by an implementation - /// of this API will not be added to this list. Implementations of this API - /// can only populate Route status for the Gateways/parent resources they are - /// responsible for. - /// - /// A maximum of 32 Gateways will be represented in this list. An empty list - /// means the route has not been attached to any Gateway. - pub parents: Vec, -} - -/// RouteParentStatus describes the status of a route with respect to an -/// associated Parent. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteStatusParents { - /// Conditions describes the status of the route with respect to the Gateway. - /// Note that the route's availability is also subject to the Gateway's own - /// status conditions and listener status. - /// - /// If the Route's ParentRef specifies an existing Gateway that supports - /// Routes of this kind AND that Gateway's controller has sufficient access, - /// then that Gateway's controller MUST set the "Accepted" condition on the - /// Route, to indicate whether the route has been accepted or rejected by the - /// Gateway, and why. - /// - /// A Route MUST be considered "Accepted" if at least one of the Route's - /// rules is implemented by the Gateway. - /// - /// There are a number of cases where the "Accepted" condition may not be set - /// due to lack of controller visibility, that includes when: - /// - /// * The Route refers to a non-existent parent. - /// * The Route is of a type that the controller does not support. - /// * The Route is in a namespace the controller does not have access to. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// ControllerName is a domain/path string that indicates the name of the - /// controller that wrote this status. This corresponds with the - /// controllerName field on GatewayClass. - /// - /// Example: "example.net/gateway-controller". - /// - /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are - /// valid Kubernetes names - /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). - /// - /// Controllers MUST populate this field when writing status. Controllers should ensure that - /// entries to status populated with their ControllerName are cleaned up when they are no - /// longer necessary. - #[serde(rename = "controllerName")] - pub controller_name: String, - /// ParentRef corresponds with a ParentRef in the spec that this - /// RouteParentStatus struct describes the status of. - #[serde(rename = "parentRef")] - pub parent_ref: GRPCRouteStatusParentsParentRef, -} - -/// ParentRef corresponds with a ParentRef in the spec that this -/// RouteParentStatus struct describes the status of. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteStatusParentsParentRef { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, + pub r#type: Option, } diff --git a/gateway-api/src/apis/standard/httproutes.rs b/gateway-api/src/apis/standard/httproutes.rs index af416a4..60314f0 100644 --- a/gateway-api/src/apis/standard/httproutes.rs +++ b/gateway-api/src/apis/standard/httproutes.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.1 +// WARNING! generated file do not edit +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -10,9 +9,17 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of HTTPRoute. -#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] #[kube( group = "gateway.networking.k8s.io", version = "v1", @@ -20,7 +27,7 @@ use self::prelude::*; plural = "httproutes" )] #[kube(namespaced)] -#[kube(status = "HTTPRouteStatus")] +#[kube(status = "RouteStatus")] #[kube(derive = "Default")] #[kube(derive = "PartialEq")] pub struct HTTPRouteSpec { @@ -136,134 +143,19 @@ pub struct HTTPRouteSpec { /// /// /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "parentRefs" - )] - pub parent_refs: Option>, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "parentRefs")] + pub parent_refs: Option>, /// Rules are a list of HTTP matchers, filters and actions. /// /// #[serde(default, skip_serializing_if = "Option::is_none")] - pub rules: Option>, -} - -/// ParentReference identifies an API object (usually a Gateway) that can be considered -/// a parent of this resource (usually a route). There are two kinds of parent resources -/// with "Core" support: -/// -/// * Gateway (Gateway conformance profile) -/// * Service (Mesh conformance profile, ClusterIP Services only) -/// -/// This API may be extended in the future to support additional kinds of parent -/// resources. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteParentRefs { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, + pub rules: Option>, } - /// HTTPRouteRule defines semantics for matching an HTTP request based on /// conditions (matches), processing it (filters), and forwarding the request to /// an API object (backendRefs). #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRules { +pub struct HTTPRouteRule { /// BackendRefs defines the backend(s) where matching requests should be /// sent. /// @@ -299,12 +191,8 @@ pub struct HTTPRouteRules { /// Support: Implementation-specific for any other resource /// /// Support for weight: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "backendRefs" - )] - pub backend_refs: Option>, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRefs")] + pub backend_refs: Option>, /// Filters define the filters that are applied to requests that match /// this rule. /// @@ -342,7 +230,7 @@ pub struct HTTPRouteRules { /// /// Support: Core #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Matches define conditions used for matching the rule against incoming /// HTTP requests. Each match is independent, i.e. this rule will be matched /// if **any** one of the matches is satisfied. @@ -400,14 +288,13 @@ pub struct HTTPRouteRules { /// When no rules matching a request have been successfully attached to the /// parent a request is coming from, a HTTP 404 status code MUST be returned. #[serde(default, skip_serializing_if = "Option::is_none")] - pub matches: Option>, + pub matches: Option>, /// Timeouts defines the timeouts that can be configured for an HTTP request. /// /// Support: Extended #[serde(default, skip_serializing_if = "Option::is_none")] - pub timeouts: Option, + pub timeouts: Option, } - /// HTTPBackendRef defines how a HTTPRoute forwards a HTTP request. /// /// Note that when a namespace different than the local namespace is specified, a @@ -433,14 +320,14 @@ pub struct HTTPRouteRules { /// /// #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefs { +pub struct HTTPBackendReference { /// Filters defined at this level should be executed if and only if the /// request is being forwarded to the backend defined here. /// /// Support: Implementation-specific (For broader support of filters, use the /// Filters field in HTTPRouteRule.) #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Group is the group of the referent. For example, "gateway.networking.k8s.io". /// When unspecified or empty string, core API group is inferred. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -497,7 +384,6 @@ pub struct HTTPRouteRulesBackendRefs { #[serde(default, skip_serializing_if = "Option::is_none")] pub weight: Option, } - /// HTTPRouteFilter defines processing steps that must be completed during the /// request or response lifecycle. HTTPRouteFilters are meant as an extension /// point to express processing that may be done in Gateway implementations. Some @@ -505,7 +391,7 @@ pub struct HTTPRouteRulesBackendRefs { /// authentication strategies, rate-limiting, and traffic shaping. API /// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFilters { +pub struct HTTPRouteBackendFilter { /// ExtensionRef is an optional, implementation-specific extension to the /// "filter" behavior. For example, resource "myroutefilter" in group /// "networking.example.net"). ExtensionRef MUST NOT be used for core and @@ -514,12 +400,8 @@ pub struct HTTPRouteRulesBackendRefsFilters { /// This filter can be used multiple times within the same rule. /// /// Support: Implementation-specific - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "extensionRef" - )] - pub extension_ref: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, /// RequestHeaderModifier defines a schema for a filter that modifies request /// headers. /// @@ -529,7 +411,7 @@ pub struct HTTPRouteRulesBackendRefsFilters { skip_serializing_if = "Option::is_none", rename = "requestHeaderModifier" )] - pub request_header_modifier: Option, + pub request_header_modifier: Option, /// RequestMirror defines a schema for a filter that mirrors requests. /// Requests are sent to the specified destination, but responses from /// that destination are ignored. @@ -541,12 +423,8 @@ pub struct HTTPRouteRulesBackendRefsFilters { /// Support: Extended /// /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestMirror" - )] - pub request_mirror: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, /// RequestRedirect defines a schema for a filter that responds to the /// request with an HTTP redirection. /// @@ -556,7 +434,7 @@ pub struct HTTPRouteRulesBackendRefsFilters { skip_serializing_if = "Option::is_none", rename = "requestRedirect" )] - pub request_redirect: Option, + pub request_redirect: Option, /// ResponseHeaderModifier defines a schema for a filter that modifies response /// headers. /// @@ -566,7 +444,7 @@ pub struct HTTPRouteRulesBackendRefsFilters { skip_serializing_if = "Option::is_none", rename = "responseHeaderModifier" )] - pub response_header_modifier: Option, + pub response_header_modifier: Option, /// Type identifies the type of filter to apply. As with other API fields, /// types are classified into three conformance levels: /// @@ -600,355 +478,99 @@ pub struct HTTPRouteRulesBackendRefsFilters { /// Accepted Condition for the Route to `status: False`, with a /// Reason of `UnsupportedValue`. #[serde(rename = "type")] - pub r#type: HTTPRouteRulesBackendRefsFiltersType, + pub r#type: HTTPFilterType, /// URLRewrite defines a schema for a filter that modifies a request during forwarding. /// /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "urlRewrite" - )] - pub url_rewrite: Option, -} - -/// ExtensionRef is an optional, implementation-specific extension to the -/// "filter" behavior. For example, resource "myroutefilter" in group -/// "networking.example.net"). ExtensionRef MUST NOT be used for core and -/// extended filters. -/// -/// This filter can be used multiple times within the same rule. -/// -/// Support: Implementation-specific -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersExtensionRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - pub group: String, - /// Kind is kind of the referent. For example "HTTPRoute" or "Service". - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} - -/// RequestHeaderModifier defines a schema for a filter that modifies request -/// headers. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// RequestMirror defines a schema for a filter that mirrors requests. -/// Requests are sent to the specified destination, but responses from -/// that destination are ignored. -/// -/// This filter can be used multiple times within the same rule. Note that -/// not all implementations will be able to support mirroring to multiple -/// backends. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestMirror { - /// BackendRef references a resource where mirrored requests are sent. - /// - /// Mirrored requests must be sent only to a single destination endpoint - /// within this BackendRef, irrespective of how many endpoints are present - /// within this BackendRef. - /// - /// If the referent cannot be found, this BackendRef is invalid and must be - /// dropped from the Gateway. The controller must ensure the "ResolvedRefs" - /// condition on the Route status is set to `status: False` and not configure - /// this backend in the underlying implementation. - /// - /// If there is a cross-namespace reference to an *existing* object - /// that is not allowed by a ReferenceGrant, the controller must ensure the - /// "ResolvedRefs" condition on the Route is set to `status: False`, - /// with the "RefNotPermitted" reason and not configure this backend in the - /// underlying implementation. - /// - /// In either error case, the Message of the `ResolvedRefs` Condition - /// should be used to provide more detail about the problem. - /// - /// Support: Extended for Kubernetes Service - /// - /// Support: Implementation-specific for any other resource - #[serde(rename = "backendRef")] - pub backend_ref: HTTPRouteRulesBackendRefsFiltersRequestMirrorBackendRef, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] + pub url_rewrite: Option, } - -/// BackendRef references a resource where mirrored requests are sent. -/// -/// Mirrored requests must be sent only to a single destination endpoint -/// within this BackendRef, irrespective of how many endpoints are present -/// within this BackendRef. -/// -/// If the referent cannot be found, this BackendRef is invalid and must be -/// dropped from the Gateway. The controller must ensure the "ResolvedRefs" -/// condition on the Route status is set to `status: False` and not configure -/// this backend in the underlying implementation. -/// -/// If there is a cross-namespace reference to an *existing* object -/// that is not allowed by a ReferenceGrant, the controller must ensure the -/// "ResolvedRefs" condition on the Route is set to `status: False`, -/// with the "RefNotPermitted" reason and not configure this backend in the -/// underlying implementation. -/// -/// In either error case, the Message of the `ResolvedRefs` Condition -/// should be used to provide more detail about the problem. -/// -/// Support: Extended for Kubernetes Service -/// -/// Support: Implementation-specific for any other resource +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestMirrorBackendRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. +pub struct HTTPRouteFilter { + /// ExtensionRef is an optional, implementation-specific extension to the + /// "filter" behavior. For example, resource "myroutefilter" in group + /// "networking.example.net"). ExtensionRef MUST NOT be used for core and + /// extended filters. /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. + /// This filter can be used multiple times within the same rule. /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirect { - /// Hostname is the hostname to be used in the value of the `Location` - /// header in the response. - /// When empty, the hostname in the `Host` header of the request is used. + /// Support: Implementation-specific + #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + pub extension_ref: Option, + /// RequestHeaderModifier defines a schema for a filter that modifies request + /// headers. /// /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines parameters used to modify the path of the incoming request. - /// The modified path is then used to construct the `Location` header. When - /// empty, the request path is used as-is. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, - /// Port is the port to be used in the value of the `Location` - /// header in the response. - /// - /// If no port is specified, the redirect port MUST be derived using the - /// following rules: - /// - /// * If redirect scheme is not-empty, the redirect port MUST be the well-known - /// port associated with the redirect scheme. Specifically "http" to port 80 - /// and "https" to port 443. If the redirect scheme does not have a - /// well-known port, the listener port of the Gateway SHOULD be used. - /// * If redirect scheme is empty, the redirect port MUST be the Gateway - /// Listener port. - /// - /// Implementations SHOULD NOT add the port number in the 'Location' - /// header in the following cases: - /// - /// * A Location header that will use HTTP (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 80. - /// * A Location header that will use HTTPS (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 443. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Scheme is the scheme to be used in the value of the `Location` header in - /// the response. When empty, the scheme of the request is used. - /// - /// Scheme redirects can affect the port of the redirect, for more information, - /// refer to the documentation for the port field of this filter. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + /// RequestMirror defines a schema for a filter that mirrors requests. + /// Requests are sent to the specified destination, but responses from + /// that destination are ignored. /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. + /// This filter can be used multiple times within the same rule. Note that + /// not all implementations will be able to support mirroring to multiple + /// backends. /// /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, - /// StatusCode is the HTTP status code to be used in response. /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. + #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + pub request_mirror: Option, + /// RequestRedirect defines a schema for a filter that responds to the + /// request with an HTTP redirection. /// /// Support: Core #[serde( default, skip_serializing_if = "Option::is_none", - rename = "statusCode" - )] - pub status_code: Option, -} - -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirectPath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" + rename = "requestRedirect" )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path + pub request_redirect: Option, + /// ResponseHeaderModifier defines a schema for a filter that modifies response + /// headers. + /// + /// Support: Extended #[serde( default, skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" + rename = "responseHeaderModifier" )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. + pub response_header_modifier: Option, + /// Type identifies the type of filter to apply. As with other API fields, + /// types are classified into three conformance levels: + /// + /// - Core: Filter types and their corresponding configuration defined by + /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All + /// implementations must support core filters. + /// + /// - Extended: Filter types and their corresponding configuration defined by + /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers + /// are encouraged to support extended filters. + /// + /// - Implementation-specific: Filters that are defined and supported by + /// specific vendors. + /// In the future, filters showing convergence in behavior across multiple + /// implementations will be considered for inclusion in extended or core + /// conformance levels. Filter-specific configuration for such filters + /// is specified using the ExtensionRef field. `Type` should be set to + /// "ExtensionRef" for custom filters. + /// + /// Implementers are encouraged to define custom implementation types to + /// extend the core API with implementation-specific behavior. + /// + /// If a reference to a custom filter type cannot be resolved, the filter + /// MUST NOT be skipped. Instead, requests that would have been processed by + /// that filter MUST receive a HTTP error response. /// /// Note that values may be added to this enum, implementations /// must ensure that unknown values will not cause a crash. @@ -957,913 +579,13 @@ pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirectPath { /// Accepted Condition for the Route to `status: False`, with a /// Reason of `UnsupportedValue`. #[serde(rename = "type")] - pub r#type: HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType, + pub r#type: HTTPFilterType, + /// URLRewrite defines a schema for a filter that modifies a request during forwarding. + /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] + pub url_rewrite: Option, } - -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType { - ReplaceFullPath, - ReplacePrefixMatch, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectScheme { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectStatusCode { - #[serde(rename = "301")] - r#_301, - #[serde(rename = "302")] - r#_302, -} - -/// ResponseHeaderModifier defines a schema for a filter that modifies response -/// headers. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersResponseHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersType { - RequestHeaderModifier, - ResponseHeaderModifier, - RequestMirror, - RequestRedirect, - #[serde(rename = "URLRewrite")] - UrlRewrite, - ExtensionRef, -} - -/// URLRewrite defines a schema for a filter that modifies a request during forwarding. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersUrlRewrite { - /// Hostname is the value to be used to replace the Host header value during - /// forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines a path rewrite. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, -} - -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersUrlRewritePath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesBackendRefsFiltersUrlRewritePathType, -} - -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersUrlRewritePathType { - ReplaceFullPath, - ReplacePrefixMatch, -} - -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// This filter can be used multiple times within the same rule. - /// - /// Support: Implementation-specific - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "extensionRef" - )] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestMirror" - )] - pub request_mirror: Option, - /// RequestRedirect defines a schema for a filter that responds to the - /// request with an HTTP redirection. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestRedirect" - )] - pub request_redirect: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations must support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by - /// specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` should be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesFiltersType, - /// URLRewrite defines a schema for a filter that modifies a request during forwarding. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "urlRewrite" - )] - pub url_rewrite: Option, -} - -/// ExtensionRef is an optional, implementation-specific extension to the -/// "filter" behavior. For example, resource "myroutefilter" in group -/// "networking.example.net"). ExtensionRef MUST NOT be used for core and -/// extended filters. -/// -/// This filter can be used multiple times within the same rule. -/// -/// Support: Implementation-specific -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersExtensionRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - pub group: String, - /// Kind is kind of the referent. For example "HTTPRoute" or "Service". - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} - -/// RequestHeaderModifier defines a schema for a filter that modifies request -/// headers. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// RequestMirror defines a schema for a filter that mirrors requests. -/// Requests are sent to the specified destination, but responses from -/// that destination are ignored. -/// -/// This filter can be used multiple times within the same rule. Note that -/// not all implementations will be able to support mirroring to multiple -/// backends. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestMirror { - /// BackendRef references a resource where mirrored requests are sent. - /// - /// Mirrored requests must be sent only to a single destination endpoint - /// within this BackendRef, irrespective of how many endpoints are present - /// within this BackendRef. - /// - /// If the referent cannot be found, this BackendRef is invalid and must be - /// dropped from the Gateway. The controller must ensure the "ResolvedRefs" - /// condition on the Route status is set to `status: False` and not configure - /// this backend in the underlying implementation. - /// - /// If there is a cross-namespace reference to an *existing* object - /// that is not allowed by a ReferenceGrant, the controller must ensure the - /// "ResolvedRefs" condition on the Route is set to `status: False`, - /// with the "RefNotPermitted" reason and not configure this backend in the - /// underlying implementation. - /// - /// In either error case, the Message of the `ResolvedRefs` Condition - /// should be used to provide more detail about the problem. - /// - /// Support: Extended for Kubernetes Service - /// - /// Support: Implementation-specific for any other resource - #[serde(rename = "backendRef")] - pub backend_ref: HTTPRouteRulesFiltersRequestMirrorBackendRef, -} - -/// BackendRef references a resource where mirrored requests are sent. -/// -/// Mirrored requests must be sent only to a single destination endpoint -/// within this BackendRef, irrespective of how many endpoints are present -/// within this BackendRef. -/// -/// If the referent cannot be found, this BackendRef is invalid and must be -/// dropped from the Gateway. The controller must ensure the "ResolvedRefs" -/// condition on the Route status is set to `status: False` and not configure -/// this backend in the underlying implementation. -/// -/// If there is a cross-namespace reference to an *existing* object -/// that is not allowed by a ReferenceGrant, the controller must ensure the -/// "ResolvedRefs" condition on the Route is set to `status: False`, -/// with the "RefNotPermitted" reason and not configure this backend in the -/// underlying implementation. -/// -/// In either error case, the Message of the `ResolvedRefs` Condition -/// should be used to provide more detail about the problem. -/// -/// Support: Extended for Kubernetes Service -/// -/// Support: Implementation-specific for any other resource -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestMirrorBackendRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestRedirect { - /// Hostname is the hostname to be used in the value of the `Location` - /// header in the response. - /// When empty, the hostname in the `Host` header of the request is used. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines parameters used to modify the path of the incoming request. - /// The modified path is then used to construct the `Location` header. When - /// empty, the request path is used as-is. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, - /// Port is the port to be used in the value of the `Location` - /// header in the response. - /// - /// If no port is specified, the redirect port MUST be derived using the - /// following rules: - /// - /// * If redirect scheme is not-empty, the redirect port MUST be the well-known - /// port associated with the redirect scheme. Specifically "http" to port 80 - /// and "https" to port 443. If the redirect scheme does not have a - /// well-known port, the listener port of the Gateway SHOULD be used. - /// * If redirect scheme is empty, the redirect port MUST be the Gateway - /// Listener port. - /// - /// Implementations SHOULD NOT add the port number in the 'Location' - /// header in the following cases: - /// - /// * A Location header that will use HTTP (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 80. - /// * A Location header that will use HTTPS (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 443. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Scheme is the scheme to be used in the value of the `Location` header in - /// the response. When empty, the scheme of the request is used. - /// - /// Scheme redirects can affect the port of the redirect, for more information, - /// refer to the documentation for the port field of this filter. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, - /// StatusCode is the HTTP status code to be used in response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "statusCode" - )] - pub status_code: Option, -} - -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestRedirectPath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesFiltersRequestRedirectPathType, -} - -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersRequestRedirectPathType { - ReplaceFullPath, - ReplacePrefixMatch, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersRequestRedirectScheme { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersRequestRedirectStatusCode { - #[serde(rename = "301")] - r#_301, - #[serde(rename = "302")] - r#_302, -} - -/// ResponseHeaderModifier defines a schema for a filter that modifies response -/// headers. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersResponseHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersResponseHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersResponseHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersType { - RequestHeaderModifier, - ResponseHeaderModifier, - RequestMirror, - RequestRedirect, - #[serde(rename = "URLRewrite")] - UrlRewrite, - ExtensionRef, -} - -/// URLRewrite defines a schema for a filter that modifies a request during forwarding. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersUrlRewrite { - /// Hostname is the value to be used to replace the Host header value during - /// forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines a path rewrite. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, -} - -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersUrlRewritePath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesFiltersUrlRewritePathType, -} - -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersUrlRewritePathType { - ReplaceFullPath, - ReplacePrefixMatch, -} - /// HTTPRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will /// evaluate to true only if all conditions are satisfied. @@ -1882,79 +604,31 @@ pub enum HTTPRouteRulesFiltersUrlRewritePathType { /// /// ``` #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatches { +pub struct RouteMatch { /// Headers specifies HTTP request header matchers. Multiple match values are /// ANDed together, meaning, a request must match all the specified headers /// to select the route. #[serde(default, skip_serializing_if = "Option::is_none")] - pub headers: Option>, + pub headers: Option>, /// Method specifies HTTP method matcher. /// When specified, this route will be matched only if the request has the /// specified method. /// /// Support: Extended #[serde(default, skip_serializing_if = "Option::is_none")] - pub method: Option, + pub method: Option, /// Path specifies a HTTP request path matcher. If this field is not /// specified, a default prefix match on the "/" path is provided. #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, + pub path: Option, /// QueryParams specifies HTTP query parameter matchers. Multiple match /// values are ANDed together, meaning, a request must match all the /// specified query parameters to select the route. /// /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "queryParams" - )] - pub query_params: Option>, -} - -/// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatchesHeaders { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, only the first - /// entry with an equivalent name MUST be considered for a match. Subsequent - /// entries with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - /// - /// When a header is repeated in an HTTP request, it is - /// implementation-specific behavior as to how this is represented. - /// Generally, proxies should follow the guidance from the RFC: - /// https://www.rfc-editor.org/rfc/rfc7230.html#section-3.2.2 regarding - /// processing a repeated header, with special handling for "Set-Cookie". - pub name: String, - /// Type specifies how to match against the value of the header. - /// - /// Support: Core (Exact) - /// - /// Support: Implementation-specific (RegularExpression) - /// - /// Since RegularExpression HeaderMatchType has implementation-specific - /// conformance, implementations can support POSIX, PCRE or any other dialects - /// of regular expressions. Please read the implementation's documentation to - /// determine the supported dialect. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value is the value of HTTP Header to be matched. - pub value: String, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "queryParams")] + pub query_params: Option>, } - -/// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesHeadersType { - Exact, - RegularExpression, -} - /// HTTPRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will /// evaluate to true only if all conditions are satisfied. @@ -1973,7 +647,7 @@ pub enum HTTPRouteRulesMatchesHeadersType { /// /// ``` #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesMethod { +pub enum HTTPMethodMatch { #[serde(rename = "GET")] Get, #[serde(rename = "HEAD")] @@ -1993,11 +667,10 @@ pub enum HTTPRouteRulesMatchesMethod { #[serde(rename = "PATCH")] Patch, } - /// Path specifies a HTTP request path matcher. If this field is not /// specified, a default prefix match on the "/" path is provided. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatchesPath { +pub struct PathMatch { /// Type specifies how to match against the path Value. /// /// Support: Core (Exact, PathPrefix) @@ -2009,7 +682,6 @@ pub struct HTTPRouteRulesMatchesPath { #[serde(default, skip_serializing_if = "Option::is_none")] pub value: Option, } - /// Path specifies a HTTP request path matcher. If this field is not /// specified, a default prefix match on the "/" path is provided. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] @@ -2018,58 +690,11 @@ pub enum HTTPRouteRulesMatchesPathType { PathPrefix, RegularExpression, } - -/// HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP -/// query parameters. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatchesQueryParams { - /// Name is the name of the HTTP query param to be matched. This must be an - /// exact string match. (See - /// https://tools.ietf.org/html/rfc7230#section-2.7.3). - /// - /// If multiple entries specify equivalent query param names, only the first - /// entry with an equivalent name MUST be considered for a match. Subsequent - /// entries with an equivalent query param name MUST be ignored. - /// - /// If a query param is repeated in an HTTP request, the behavior is - /// purposely left undefined, since different data planes have different - /// capabilities. However, it is *recommended* that implementations should - /// match against the first value of the param if the data plane supports it, - /// as this behavior is expected in other load balancing contexts outside of - /// the Gateway API. - /// - /// Users SHOULD NOT route traffic based on repeated query params to guard - /// themselves against potential differences in the implementations. - pub name: String, - /// Type specifies how to match against the value of the query parameter. - /// - /// Support: Extended (Exact) - /// - /// Support: Implementation-specific (RegularExpression) - /// - /// Since RegularExpression QueryParamMatchType has Implementation-specific - /// conformance, implementations can support POSIX, PCRE or any other - /// dialects of regular expressions. Please read the implementation's - /// documentation to determine the supported dialect. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value is the value of HTTP query param to be matched. - pub value: String, -} - -/// HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP -/// query parameters. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesQueryParamsType { - Exact, - RegularExpression, -} - /// Timeouts defines the timeouts that can be configured for an HTTP request. /// /// Support: Extended #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesTimeouts { +pub struct HTTPRouteTimeout { /// BackendRequest specifies a timeout for an individual request from the gateway /// to a backend. This covers the time from when the request first starts being /// sent from the gateway to when the full response has been received from the backend. @@ -2089,11 +714,7 @@ pub struct HTTPRouteRulesTimeouts { /// Request timeout (since the Request timeout encompasses the BackendRequest timeout). /// /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "backendRequest" - )] + #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRequest")] pub backend_request: Option, /// Request specifies the maximum duration for a gateway to respond to an HTTP request. /// If the gateway has not been able to respond before this deadline is met, the gateway @@ -2120,169 +741,3 @@ pub struct HTTPRouteRulesTimeouts { #[serde(default, skip_serializing_if = "Option::is_none")] pub request: Option, } - -/// Status defines the current state of HTTPRoute. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteStatus { - /// Parents is a list of parent resources (usually Gateways) that are - /// associated with the route, and the status of the route with respect to - /// each parent. When this route attaches to a parent, the controller that - /// manages the parent must add an entry to this list when the controller - /// first sees the route and should update the entry as appropriate when the - /// route or gateway is modified. - /// - /// Note that parent references that cannot be resolved by an implementation - /// of this API will not be added to this list. Implementations of this API - /// can only populate Route status for the Gateways/parent resources they are - /// responsible for. - /// - /// A maximum of 32 Gateways will be represented in this list. An empty list - /// means the route has not been attached to any Gateway. - pub parents: Vec, -} - -/// RouteParentStatus describes the status of a route with respect to an -/// associated Parent. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteStatusParents { - /// Conditions describes the status of the route with respect to the Gateway. - /// Note that the route's availability is also subject to the Gateway's own - /// status conditions and listener status. - /// - /// If the Route's ParentRef specifies an existing Gateway that supports - /// Routes of this kind AND that Gateway's controller has sufficient access, - /// then that Gateway's controller MUST set the "Accepted" condition on the - /// Route, to indicate whether the route has been accepted or rejected by the - /// Gateway, and why. - /// - /// A Route MUST be considered "Accepted" if at least one of the Route's - /// rules is implemented by the Gateway. - /// - /// There are a number of cases where the "Accepted" condition may not be set - /// due to lack of controller visibility, that includes when: - /// - /// * The Route refers to a non-existent parent. - /// * The Route is of a type that the controller does not support. - /// * The Route is in a namespace the controller does not have access to. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// ControllerName is a domain/path string that indicates the name of the - /// controller that wrote this status. This corresponds with the - /// controllerName field on GatewayClass. - /// - /// Example: "example.net/gateway-controller". - /// - /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are - /// valid Kubernetes names - /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). - /// - /// Controllers MUST populate this field when writing status. Controllers should ensure that - /// entries to status populated with their ControllerName are cleaned up when they are no - /// longer necessary. - #[serde(rename = "controllerName")] - pub controller_name: String, - /// ParentRef corresponds with a ParentRef in the spec that this - /// RouteParentStatus struct describes the status of. - #[serde(rename = "parentRef")] - pub parent_ref: HTTPRouteStatusParentsParentRef, -} - -/// ParentRef corresponds with a ParentRef in the spec that this -/// RouteParentStatus struct describes the status of. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteStatusParentsParentRef { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, -} diff --git a/gateway-api/src/apis/standard/mod.rs b/gateway-api/src/apis/standard/mod.rs index 5111225..af85ef7 100644 --- a/gateway-api/src/apis/standard/mod.rs +++ b/gateway-api/src/apis/standard/mod.rs @@ -1,6 +1,8 @@ // WARNING! generated file do not edit + +pub mod common; pub mod constants; -mod enum_defaults; +pub mod enum_defaults; pub mod gatewayclasses; pub mod gateways; pub mod grpcroutes; diff --git a/gateway-api/src/apis/standard/referencegrants.rs b/gateway-api/src/apis/standard/referencegrants.rs index f3cab13..c785978 100644 --- a/gateway-api/src/apis/standard/referencegrants.rs +++ b/gateway-api/src/apis/standard/referencegrants.rs @@ -1,6 +1,4 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.1 +// WARNING! generated file do not edit #[allow(unused_imports)] mod prelude { @@ -9,9 +7,17 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of ReferenceGrant. -#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +#[derive( + CustomResource, + Serialize, + Deserialize, + Clone, + Debug, + JsonSchema, + Default, + PartialEq +)] #[kube( group = "gateway.networking.k8s.io", version = "v1beta1", @@ -37,7 +43,6 @@ pub struct ReferenceGrantSpec { /// Support: Core pub to: Vec, } - /// ReferenceGrantFrom describes trusted namespaces and kinds. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct ReferenceGrantFrom { @@ -67,7 +72,6 @@ pub struct ReferenceGrantFrom { /// Support: Core pub namespace: String, } - /// ReferenceGrantTo describes what Kinds are allowed as targets of the /// references. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] diff --git a/gateway-api/src/duration.rs b/gateway-api/src/duration.rs index 699bee9..2ec98ed 100644 --- a/gateway-api/src/duration.rs +++ b/gateway-api/src/duration.rs @@ -389,13 +389,12 @@ impl FromStr for Duration { // This Lazy Regex::new should never ever fail, given that the regex // is a compile-time constant. But just in case..... static RE: Lazy = Lazy::new(|| { - Regex::new(GEP2257_PATTERN).expect( - format!( + Regex::new(GEP2257_PATTERN).unwrap_or_else(|_| { + panic!( r#"GEP2257 regex "{}" did not compile (this is a bug!)"#, GEP2257_PATTERN ) - .as_str(), - ) + }) }); // If the string doesn't match the regex, it's invalid. diff --git a/gateway-api/src/lib.rs b/gateway-api/src/lib.rs index f5a5e44..65ab012 100644 --- a/gateway-api/src/lib.rs +++ b/gateway-api/src/lib.rs @@ -8,9 +8,6 @@ pub use apis::standard::*; #[cfg(feature = "experimental")] pub use apis::experimental; -#[cfg(feature = "processed")] -pub use apis::processed::*; - #[cfg(test)] mod tests { use std::process::Command; @@ -31,14 +28,13 @@ mod tests { use uuid::Uuid; use crate::{ + apis::standard::common::GatewayAddress, apis::standard::constants::{ GatewayConditionReason, GatewayConditionType, ListenerConditionReason, ListenerConditionType, }, apis::standard::gatewayclasses::{GatewayClass, GatewayClassSpec}, - apis::standard::gateways::{ - Gateway, GatewaySpec, GatewayStatus, GatewayStatusAddresses, GatewayStatusListeners, - }, + apis::standard::gateways::{Gateway, GatewaySpec, GatewayStatus, GatewayStatusListeners}, }; // ------------------------------------------------------------------------- @@ -92,29 +88,30 @@ mod tests { assert!(gw.metadata.name.is_some()); assert!(gw.metadata.uid.is_some()); - let mut gw_status = GatewayStatus::default(); - gw_status.addresses = Some(vec![GatewayStatusAddresses::default()]); - gw_status.listeners = Some(vec![GatewayStatusListeners { - name: "tcp".into(), - attached_routes: 0, - supported_kinds: vec![], - conditions: vec![Condition { + let gw_status = GatewayStatus { + addresses: Some(vec![GatewayAddress::default()]), + listeners: Some(vec![GatewayStatusListeners { + name: "tcp".into(), + attached_routes: 0, + supported_kinds: vec![], + conditions: vec![Condition { + last_transition_time: Time(Utc::now()), + message: "testing gateway".to_string(), + observed_generation: Some(1), + reason: ListenerConditionReason::Programmed.to_string(), + status: "True".to_string(), + type_: ListenerConditionType::Programmed.to_string(), + }], + }]), + conditions: Some(vec![Condition { last_transition_time: Time(Utc::now()), message: "testing gateway".to_string(), observed_generation: Some(1), - reason: ListenerConditionReason::Programmed.to_string(), + reason: GatewayConditionReason::Programmed.to_string(), status: "True".to_string(), - type_: ListenerConditionType::Programmed.to_string(), - }], - }]); - gw_status.conditions = Some(vec![Condition { - last_transition_time: Time(Utc::now()), - message: "testing gateway".to_string(), - observed_generation: Some(1), - reason: GatewayConditionReason::Programmed.to_string(), - status: "True".to_string(), - type_: GatewayConditionType::Programmed.to_string(), - }]); + type_: GatewayConditionType::Programmed.to_string(), + }]), + }; gw = Api::default_namespaced(client) .patch_status( @@ -144,9 +141,8 @@ mod tests { impl Drop for Cluster { fn drop(&mut self) { - match delete_kind_cluster(&self.name) { - Err(err) => panic!("failed to cleanup kind cluster {}: {}", self.name, err), - Ok(()) => {} + if let Err(err) = delete_kind_cluster(&self.name) { + panic!("failed to cleanup kind cluster {}: {}", self.name, err) } } } diff --git a/type-reducer/customized_mapped_names.txt b/type-reducer/customized_mapped_names.txt index 6712948..7e4ca88 100644 --- a/type-reducer/customized_mapped_names.txt +++ b/type-reducer/customized_mapped_names.txt @@ -2,21 +2,21 @@ GRPCRouteRulesBackendRefsFiltersType->GRPCFilterType GRPCRouteRulesFiltersType->GRPCFilterType GatewayAddresses->GatewayAddress GatewayStatusAddresses->GatewayAddress -GRPCRouteRulesBackendRefsFiltersExtensionRef->GatewayInfrastructureParametersRef -GRPCRouteRulesFiltersExtensionRef->GatewayInfrastructureParametersRef -GatewayInfrastructureParametersRef->GatewayInfrastructureParametersRef -HTTPRouteRulesBackendRefsFiltersExtensionRef->GatewayInfrastructureParametersRef -HTTPRouteRulesFiltersExtensionRef->GatewayInfrastructureParametersRef +GRPCRouteRulesBackendRefsFiltersExtensionRef->GatewayInfrastructureParametersReference +GRPCRouteRulesFiltersExtensionRef->GatewayInfrastructureParametersReference +GatewayInfrastructureParametersRef->GatewayInfrastructureParametersReference +HTTPRouteRulesBackendRefsFiltersExtensionRef->GatewayInfrastructureParametersReference +HTTPRouteRulesFiltersExtensionRef->GatewayInfrastructureParametersReference GatewayListenersAllowedRoutesKinds->Kind GatewayStatusListenersSupportedKinds->Kind -GRPCRouteParentRefs->RouteRef -GRPCRouteStatusParentsParentRef->RouteRef -HTTPRouteParentRefs->RouteRef -HTTPRouteStatusParentsParentRef->RouteRef -GRPCRouteRulesBackendRefsFiltersExtensionRef->FilterExtensionRef -GRPCRouteRulesFiltersExtensionRef->FilterExtensionRef -HTTPRouteRulesBackendRefsFiltersExtensionRef->FilterExtensionRef -HTTPRouteRulesFiltersExtensionRef->FilterExtensionRef +GRPCRouteParentRefs->ParentReference +GRPCRouteStatusParentsParentRef->ParentReference +HTTPRouteParentRefs->ParentReference +HTTPRouteStatusParentsParentRef->ParentReference +GRPCRouteRulesBackendRefsFiltersExtensionRef->FilterExtensionReference +GRPCRouteRulesFiltersExtensionRef->FilterExtensionReference +HTTPRouteRulesBackendRefsFiltersExtensionRef->FilterExtensionReference +HTTPRouteRulesFiltersExtensionRef->FilterExtensionReference GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd->HTTPHeader GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierSet->HTTPHeader GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierAdd->HTTPHeader @@ -33,10 +33,10 @@ HTTPRouteRulesFiltersRequestHeaderModifierAdd->HTTPHeader HTTPRouteRulesFiltersRequestHeaderModifierSet->HTTPHeader HTTPRouteRulesFiltersResponseHeaderModifierAdd->HTTPHeader HTTPRouteRulesFiltersResponseHeaderModifierSet->HTTPHeader -GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef->RequestMirrorRef -GRPCRouteRulesFiltersRequestMirrorBackendRef->RequestMirrorRef -HTTPRouteRulesBackendRefsFiltersRequestMirrorBackendRef->RequestMirrorRef -HTTPRouteRulesFiltersRequestMirrorBackendRef->RequestMirrorRef +GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef->RequestMirrorReference +GRPCRouteRulesFiltersRequestMirrorBackendRef->RequestMirrorReference +HTTPRouteRulesBackendRefsFiltersRequestMirrorBackendRef->RequestMirrorReference +HTTPRouteRulesFiltersRequestMirrorBackendRef->RequestMirrorReference HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType->RequestOperationType HTTPRouteRulesBackendRefsFiltersUrlRewritePathType->RequestOperationType HTTPRouteRulesFiltersRequestRedirectPathType->RequestOperationType @@ -60,9 +60,9 @@ HTTPRouteRulesBackendRefsFiltersRequestHeaderModifier->HeaderModifier HTTPRouteRulesBackendRefsFiltersResponseHeaderModifier->HeaderModifier HTTPRouteRulesFiltersRequestHeaderModifier->HeaderModifier HTTPRouteRulesFiltersResponseHeaderModifier->HeaderModifier -GRPCRouteRulesMatchesHeaders->MatchingHeaders -HTTPRouteRulesMatchesHeaders->MatchingHeaders -HTTPRouteRulesMatchesQueryParams->MatchingHeaders +GRPCRouteRulesMatchesHeaders->HeaderMatch +HTTPRouteRulesMatchesHeaders->HeaderMatch +HTTPRouteRulesMatchesQueryParams->HeaderMatch GRPCRouteStatusParents->ParentRouteStatus HTTPRouteStatusParents->ParentRouteStatus GRPCRouteRulesBackendRefsFiltersRequestMirror->RequestMirror diff --git a/type-reducer/reduced_types_pass_0.txt b/type-reducer/reduced_types_pass_0.txt index b2f52f2..3c2773d 100644 --- a/type-reducer/reduced_types_pass_0.txt +++ b/type-reducer/reduced_types_pass_0.txt @@ -1 +1 @@ -Condition +Condition \ No newline at end of file diff --git a/type-reducer/reduced_types_pass_1.txt b/type-reducer/reduced_types_pass_1.txt index 7fead51..312e0e4 100644 --- a/type-reducer/reduced_types_pass_1.txt +++ b/type-reducer/reduced_types_pass_1.txt @@ -1,12 +1,12 @@ Condition GRPCFilterType GatewayAddress -GatewayInfrastructureParametersRef +GatewayInfrastructureParametersReference Kind -RouteRef -FilterExtensionRef +ParentReference +FilterExtensionReference HTTPHeader -RequestMirrorRef +RequestMirrorReference RequestOperationType RequestRedirectScheme RedirectStatusCode diff --git a/type-reducer/reduced_types_pass_2.txt b/type-reducer/reduced_types_pass_2.txt index f0d7012..145b480 100644 --- a/type-reducer/reduced_types_pass_2.txt +++ b/type-reducer/reduced_types_pass_2.txt @@ -1,12 +1,12 @@ Condition GRPCFilterType GatewayAddress -GatewayInfrastructureParametersRef +GatewayInfrastructureParametersReference Kind -RouteRef -FilterExtensionRef +ParentReferenceerence +FilterExtensionReference HTTPHeader -RequestMirrorRef +RequestMirrorReference RequestOperationType RequestRedirectScheme RedirectStatusCode @@ -15,6 +15,7 @@ HeaderMatchType #### Pass 2 MatchingHeaders HeaderModifier +HeaderMatch RequestMirror RequestRedirectPath ParentRouteStatus diff --git a/type-reducer/reduced_types_pass_3.txt b/type-reducer/reduced_types_pass_3.txt index 552f3bc..3b5cbd3 100644 --- a/type-reducer/reduced_types_pass_3.txt +++ b/type-reducer/reduced_types_pass_3.txt @@ -1,12 +1,12 @@ Condition GRPCFilterType GatewayAddress -GatewayInfrastructureParametersRef +GatewayInfrastructureParametersReference Kind -RouteRef -FilterExtensionRef +ParentReferenceerence +FilterExtensionReference HTTPHeader -RequestMirrorRef +RequestMirrorReference RequestOperationType RequestRedirectScheme RedirectStatusCode @@ -15,6 +15,7 @@ HeaderMatchType #### Pass 2 MatchingHeaders HeaderModifier +HeaderMatch RequestMirror RequestRedirectPath ParentRouteStatus diff --git a/type-reducer/rename_only_mapped_names.txt b/type-reducer/rename_only_mapped_names.txt new file mode 100644 index 0000000..b8c7e41 --- /dev/null +++ b/type-reducer/rename_only_mapped_names.txt @@ -0,0 +1,14 @@ +### Rename only +GRPCRouteRules->GRPCRouteRule +HTTPRouteRules->HTTPRouteRule +HTTPRouteRulesFilters->HTTPRouteFilter +GRPCRouteRulesMatches->GRPCRouteMatch +HTTPRouteRulesMatches->RouteMatch +HTTPRouteRulesTimeouts->HTTPRouteTimeout +GRPCRouteRulesBackendRefs->GRPCBackendReference +HTTPRouteRulesBackendRefs->HTTPBackendReference +GRPCRouteRulesMatchesMethod->GRPCMethodMatch +HTTPRouteRulesMatchesMethod->HTTPMethodMatch +HTTPRouteRulesBackendRefsFilters->HTTPRouteBackendFilter +HTTPRouteRequestRedirect->RequestRedirect +HTTPRouteRulesMatchesPath->PathMatch \ No newline at end of file diff --git a/type-reducer/src/lib.rs b/type-reducer/src/lib.rs index 99cecb3..b98576c 100644 --- a/type-reducer/src/lib.rs +++ b/type-reducer/src/lib.rs @@ -9,7 +9,6 @@ use proc_macro2::{Ident, Span}; use std::fs::OpenOptions; use std::io; use std::io::BufRead; -use std::io::Seek; use std::io::Write; use std::path::Path; use syn::Fields; @@ -28,6 +27,7 @@ use syn::visit_mut::VisitMut; mod visitors; pub use visitors::*; +pub const COMMON_TYPES_MOD_NAME: &str = "common"; const COMMON_TYPES_FILE_PREAMBLE: &str = "#[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -38,83 +38,9 @@ mod prelude { } use self::prelude::*;"; -const COMMON_TYPES_USE_PREAMBLE: &str = "use super::common_types::*;"; +const COMMON_TYPES_USE_PREAMBLE: &str = "use super::common::*;\n"; const GENERATED_PREAMBLE: &str = "// WARNING! generated file do not edit\n\n"; -fn break_into_words(type_name: &str) -> Vec { - let mut words = vec![]; - let mut current_word = String::new(); - - for t in type_name.chars().tuple_windows() { - let (current, next, next_next) = t; - if current.is_uppercase() { - if next.is_uppercase() { - current_word.push(current); - if !next_next.is_uppercase() { - words.push(current_word); - current_word = String::new(); - } - } else { - current_word.push(current); - } - } else { - current_word.push(current); - if next.is_uppercase() { - words.push(current_word); - current_word = String::new(); - } - } - } - let len = type_name.len() - 2; - if len > 0 { - current_word += &type_name[len..]; - words.push(current_word); - } else { - words.push(type_name.to_owned()); - } - - words -} - -pub fn common_words(words_sets: &[Vec]) -> Vec { - let word_sets: Vec> = words_sets - .iter() - .cloned() - .map(BTreeSet::from_iter) - .collect(); - - let mut intersection = if let Some(first) = word_sets.first() { - first.clone() - } else { - return vec![]; - }; - - for word_set in word_sets { - intersection = intersection.intersection(&word_set).cloned().collect(); - } - Vec::from_iter(intersection) -} - -pub fn create_struct_type_name_substitute( - customized_names_from_file: &BTreeMap, - v: &[(Ident, ItemStruct)], -) -> String { - let words: Vec> = v - .iter() - .map(|v| break_into_words(&v.0.to_string())) - .collect(); - - let common_words = common_words(&words); - - let new_name = common_words.iter().cloned().collect::(); - - if let Some(customized_name) = customized_names_from_file.get(&new_name) { - customized_name.clone() - } else { - new_name - } -} - pub fn read_substitute(customized_names_from_file: &BTreeMap, i: &Ident) -> String { if let Some(customized_name) = customized_names_from_file.get(&i.to_string()) { customized_name.clone() @@ -123,26 +49,6 @@ pub fn read_substitute(customized_names_from_file: &BTreeMap, i: } } -pub fn create_enum_type_name_substitute( - customized_names_from_file: &BTreeMap, - v: &[(Ident, ItemEnum)], -) -> String { - let words: Vec> = v - .iter() - .map(|v| break_into_words(&v.0.to_string())) - .collect(); - - let common_words = common_words(&words); - - let new_name = common_words.iter().cloned().collect::(); - - if let Some(customized_name) = customized_names_from_file.get(&new_name) { - customized_name.clone() - } else { - new_name - } -} - pub fn read_type_mappings_from_file( mapped_names: &Path, ) -> Result, Box> { @@ -273,7 +179,7 @@ pub fn find_similar_types( } pub fn prune_replaced_structs( - renaming_visitor: &mut StructEnumRenamer, + renaming_visitor: &mut StructEnumFieldsRenamer, visitors: Vec<(String, File)>, ) -> Vec<(String, String, bool)> { visitors @@ -292,15 +198,17 @@ pub fn prune_replaced_structs( .collect() } -fn generate_file_preamble( +pub fn generate_file_preamble( changed: bool, content: &str, output_path: &Path, name: &str, ) -> Result> { + let output_path = output_path.join(name); + if changed { - info!("Writing changed file {name}"); - let mut out_file = std::fs::File::create(output_path.join(name))?; + info!("Writing changed file {}", output_path.display()); + let mut out_file = std::fs::File::create(output_path)?; if !content.starts_with(GENERATED_PREAMBLE) { out_file.write_all(GENERATED_PREAMBLE.as_bytes())?; } @@ -310,8 +218,8 @@ fn generate_file_preamble( } Ok(out_file) } else { - info!("Writing NOT changed file {name}"); - let mut out_file = std::fs::File::create(output_path.join(name))?; + info!("Writing NOT changed file {}", output_path.display()); + let mut out_file = std::fs::File::create(output_path)?; if !content.starts_with(GENERATED_PREAMBLE) { out_file.write_all(GENERATED_PREAMBLE.as_bytes())?; } @@ -336,7 +244,7 @@ pub fn recreate_project_files( let mut mod_file = std::fs::File::create(output_path.join("mod.rs"))?; mod_file.write_all(GENERATED_PREAMBLE.as_bytes())?; - let mut mod_names = vec!["pub mod common_types;".to_owned()]; + let mut mod_names = vec![format!("pub mod {COMMON_TYPES_MOD_NAME};")]; for (name, content, changed) in unparsed_files { let mut out_file = generate_file_preamble(changed, &content, output_path, &name)?; @@ -348,15 +256,13 @@ pub fn recreate_project_files( mod_file.write_all((mod_name + "\n").as_bytes())?; } - let common_types_file_name = output_path.join("common_types.rs"); + let common_types_file_name = output_path.join(COMMON_TYPES_MOD_NAME.to_owned() + ".rs"); if common_types_file_name.exists() { let mut common_out_file = OpenOptions::new() .append(true) .open(common_types_file_name)?; - info!("Current position {}", common_out_file.stream_position()?); - common_out_file.write_all("\n\n// Next attempt \n\n".as_bytes())?; common_out_file.write_all(common_types.as_bytes())?; } else { @@ -395,72 +301,6 @@ pub fn create_common_type_struct(s: &ItemStruct, type_new_name: &str) -> ItemStr pub fn create_common_type_enum(s: &ItemEnum, type_new_name: &str) -> ItemEnum { let mut new_enum = s.clone(); - - // new_enum.attrs = s - // .attrs - // .iter() - // .filter(|&a| a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site()))) - // .cloned() - // .collect(); - // new_enum.attrs = s.attrs.clone(); - // let attributes: Vec<_> = new_enum - // .attrs - // .iter_mut() - // .filter(|a| { - // if let Ok(s) = a.meta.require_list() { - // if let Some(s) = s.path.segments.first() { - // s.ident == Ident::new("derive", Span::call_site()) - // } else { - // false - // } - // } else { - // false - // } - // }) - // .map(|a| { - // let mut new_attr = a.clone(); - // if let Ok(s) = a.meta.require_list() { - // let mut new_meta = s.clone(); - // let mut new_tokens = new_meta.tokens.clone(); - // //new_tokens.extend(TokenStream::from_str(", Default").unwrap()); - // new_meta.tokens = new_tokens; - // warn!("Enum tokens {:?}", new_meta.tokens.to_string()); - // new_attr.meta = Meta::List(new_meta); - // } - // new_attr - // }) - // .collect(); - - // new_enum.attrs = attributes; - // warn!("New enum = {:?}", new_enum); - new_enum.ident = Ident::new(type_new_name, Span::call_site()); new_enum } - -#[cfg(test)] -mod tests { - use crate::break_into_words; - - #[test] - fn test_word_breaking() { - let expected_words = [ - "GRPC", "Route", "Rules", "Backend", "Refs", "Filters", "Request", "Mirror", "Backend", - "Ref", - ]; - let words = break_into_words("GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef"); - assert_eq!(expected_words.to_vec(), words); - - let expected_words = [ - "GRPC", "Route", "Rules", "Backend", "Refs", "Filters", "Request", "HTTPS", "Mirror", - "Backend", "Ref", - ]; - let words = - break_into_words("GRPCRouteRulesBackendRefsFiltersRequestHTTPSMirrorBackendRef"); - assert_eq!(expected_words.to_vec(), words); - - let expected_words = ["f", "RP"]; - let words = break_into_words("fRP"); - assert_eq!(expected_words.to_vec(), words); - } -} diff --git a/type-reducer/src/main.rs b/type-reducer/src/main.rs index e8c57ea..6fe84d8 100644 --- a/type-reducer/src/main.rs +++ b/type-reducer/src/main.rs @@ -1,80 +1,98 @@ use clap::Parser; +use clap::Subcommand; +use itertools::Itertools; use log::info; +use std::cmp::Ordering; use std::collections::BTreeMap; use std::collections::BTreeSet; use std::fs; +use std::io::Write; use std::path::PathBuf; use syn::Item; +use syn::visit_mut::VisitMut; use type_reducer::*; +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Subcommand)] +enum Action { + Reduce(ReduceArgs), + Rename(RenameArgs), +} + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] +struct ReduceArgs { + #[arg(long)] + current_pass_substitute_names: PathBuf, + + #[arg(long)] + previous_pass_derived_type_names: PathBuf, +} + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] +struct RenameArgs { + #[arg(long)] + rename_only_substitute_names: PathBuf, +} + #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Args { + #[command(subcommand)] + action: Action, #[arg(long)] apis_dir: String, #[arg(long)] out_dir: String, - - #[arg(long)] - current_pass_substitute_names: Option, - - #[arg(long)] - previous_pass_derived_type_names: Option, } fn main() -> Result<(), Box> { simple_logger::init_with_env().unwrap(); let Args { + action, apis_dir, out_dir, - current_pass_substitute_names, - previous_pass_derived_type_names, } = Args::parse(); let Ok(_) = fs::exists(out_dir.clone()) else { return Err("our dir doesn't exist".into()); }; - let current_pass_type_name_substitutes = - if let Some(mapped_names) = current_pass_substitute_names.as_ref() { - read_type_mappings_from_file(mapped_names.as_path())? - } else { - BTreeMap::new() - }; + match action { + Action::Rename(args) => { + let RenameArgs { + rename_only_substitute_names, + } = args; + let rename_only_substitute_names = + read_type_mappings_from_file(rename_only_substitute_names.as_path())?; - let previous_pass_derived_type_names = - if let Some(mapped_names) = previous_pass_derived_type_names.as_ref() { - read_type_names_from_file(mapped_names.as_path())? - } else { - BTreeSet::new() - }; + let previous_pass_derived_type_names = BTreeSet::new(); - let mut visitors = vec![]; + let visitors = create_visitors(&apis_dir, &previous_pass_derived_type_names)?; + handle_rename_types(rename_only_substitute_names, visitors, &out_dir) + } - for dir_entry in fs::read_dir(apis_dir).unwrap() { - let Ok(dir_entry) = dir_entry else { - continue; - }; + Action::Reduce(args) => { + let ReduceArgs { + current_pass_substitute_names, + previous_pass_derived_type_names, + } = args; + let previous_pass_derived_type_names = + read_type_names_from_file(previous_pass_derived_type_names.as_path())?; - if let Ok(name) = dir_entry.file_name().into_string() { - if name.ends_with(".rs") && name != "mod.rs" { - info!("Adding file {:?}", dir_entry.path()); - if let Ok(api_file) = fs::read_to_string(dir_entry.path()) { - if let Ok(syntaxt_file) = syn::parse_file(&api_file) { - let visitor = StructEnumVisitor { - name, - structs: Vec::new(), - enums: Vec::new(), - derived_type_names: &previous_pass_derived_type_names, - }; - visitors.push((visitor, syntaxt_file)); - } - } - } + let current_pass_type_name_substitutes = + read_type_mappings_from_file(current_pass_substitute_names.as_path())?; + + let visitors = create_visitors(&apis_dir, &previous_pass_derived_type_names)?; + handle_reduce_types(current_pass_type_name_substitutes, visitors, &out_dir) } } +} +fn handle_reduce_types( + current_pass_type_name_substitutes: BTreeMap, + visitors: Vec<(StructEnumVisitor<'_, '_>, syn::File)>, + out_dir: &str, +) -> Result<(), Box> { let FindSimilarTypesResult { visitors, similar_structs, @@ -156,7 +174,7 @@ fn main() -> Result<(), Box> { let (mapped_types, items): (Vec>, Vec) = struct_items.into_iter().chain(enum_items).unzip(); - let mut renaming_visitor = StructEnumRenamer { + let mut renaming_visitor = StructEnumFieldsRenamer { changed: false, names: mapped_types.into_iter().flatten().collect(), }; @@ -165,5 +183,97 @@ fn main() -> Result<(), Box> { let unparsed_files = prune_replaced_structs(&mut renaming_visitor, visitors); - recreate_project_files(&out_dir, unparsed_files, items) + recreate_project_files( + out_dir, + unparsed_files, + items.into_iter().sorted_by(order_types).collect(), + ) +} + +fn handle_rename_types( + rename_only_substitute_names: BTreeMap, + visitors: Vec<(StructEnumVisitor<'_, '_>, syn::File)>, + out_dir: &str, +) -> Result<(), Box> { + if !rename_only_substitute_names.is_empty() { + let mut renaming_visitor = StructEnumNameRenamer { + changed: false, + names: rename_only_substitute_names, + }; + + write_type_names_to_file(&renaming_visitor.names)?; + + let files: Vec<_> = visitors + .into_iter() + .map(|(visitor, mut f)| { + renaming_visitor.changed = false; + renaming_visitor.visit_file_mut(&mut f); + + (renaming_visitor.changed, visitor, f) + }) + .collect(); + for (changed, visitor, file) in files { + let changed = if visitor.name == COMMON_TYPES_MOD_NAME.to_owned() + ".rs" { + false + } else { + changed + }; + let path = PathBuf::from(&visitor.name); + info!("Renaming types in files {}", path.display()); + let content = &prettyplease::unparse(&file); + let mut file = generate_file_preamble( + changed, + content, + std::path::Path::new(&out_dir), + &visitor.name, + )?; + file.write_all(content.as_bytes())?; + } + Ok(()) + } else { + Ok(()) + } +} + +fn create_visitors<'a>( + apis_dir: &'a str, + previous_pass_derived_type_names: &'a BTreeSet, +) -> Result, syn::File)>, Box> { + let mut visitors = vec![]; + + for dir_entry in fs::read_dir(apis_dir)? { + let Ok(dir_entry) = dir_entry else { + continue; + }; + + if let Ok(name) = dir_entry.file_name().into_string() { + if name.ends_with(".rs") && name != "mod.rs" { + info!("Adding file {:?}", dir_entry.path()); + if let Ok(api_file) = fs::read_to_string(dir_entry.path()) { + if let Ok(syntaxt_file) = syn::parse_file(&api_file) { + let visitor = StructEnumVisitor { + name, + structs: Vec::new(), + enums: Vec::new(), + derived_type_names: previous_pass_derived_type_names, + }; + visitors.push((visitor, syntaxt_file)); + } + } + } + } + } + Ok(visitors) +} + +fn order_types(this: &Item, other: &Item) -> Ordering { + match (this, other) { + (Item::Enum(this), Item::Enum(other)) => this.ident.cmp(&other.ident), + (Item::Struct(this), Item::Struct(other)) => this.ident.cmp(&other.ident), + _ => { + let this_discriminant = unsafe { *(this as *const Item as *const u8) }; + let other_discriminant = unsafe { *(other as *const Item as *const u8) }; + this_discriminant.cmp(&other_discriminant) + } + } } diff --git a/type-reducer/src/visitors.rs b/type-reducer/src/visitors.rs index 99d258f..6cf50a7 100644 --- a/type-reducer/src/visitors.rs +++ b/type-reducer/src/visitors.rs @@ -27,7 +27,12 @@ pub struct StructEnumVisitor<'ast, 'b> { pub derived_type_names: &'b BTreeSet, } -pub struct StructEnumRenamer { +pub struct StructEnumFieldsRenamer { + pub changed: bool, + pub names: BTreeMap, +} + +pub struct StructEnumNameRenamer { pub changed: bool, pub names: BTreeMap, } @@ -103,8 +108,43 @@ impl<'ast, 'b> Visit<'ast> for StructEnumVisitor<'ast, 'b> { } } -impl VisitMut for StructEnumRenamer { +impl VisitMut for StructEnumFieldsRenamer { + fn visit_item_struct_mut(&mut self, node: &mut ItemStruct) { + debug!( + "Visiting and changing fields in struct name == {}", + node.ident + ); + + node.fields.iter_mut().for_each(|f| { + let ty = f.ty.clone(); + if let Type::Path(path_type) = &mut f.ty { + trace!( + "\twith field name = {:?} \n\t\tfield type = {:?}", + f.ident, ty + ); + + for segment in &mut path_type.path.segments { + self.changed |= rewrite_ident(segment, &self.names); + } + } + }); + + visit_mut::visit_item_struct_mut(self, node); + } +} + +impl VisitMut for StructEnumNameRenamer { fn visit_item_struct_mut(&mut self, node: &mut ItemStruct) { + debug!( + "Visiting and renaming struct name in struct name == {}", + node.ident + ); + + if let Some(new_name) = self.names.get(&node.ident.to_string()) { + self.changed = true; + node.ident = Ident::new(new_name, Span::call_site()); + }; + debug!( "Visiting and changing fields in struct name == {}", node.ident @@ -126,6 +166,15 @@ impl VisitMut for StructEnumRenamer { visit_mut::visit_item_struct_mut(self, node); } + + fn visit_item_enum_mut(&mut self, node: &mut ItemEnum) { + debug!("Visiting and renaming enum name == {}", node.ident); + + if let Some(new_name) = self.names.get(&node.ident.to_string()) { + self.changed = true; + node.ident = Ident::new(new_name, Span::call_site()); + }; + } } fn check_simple_type( diff --git a/update.sh b/update.sh index 9c82000..07fc52e 100755 --- a/update.sh +++ b/update.sh @@ -130,47 +130,48 @@ echo "pub mod constants;" >> $APIS_DIR/experimental/mod.rs cargo fmt -rm -rf $APIS_DIR/processed -mkdir -p $APIS_DIR/processed +# rm -rf $APIS_DIR/processed +# mkdir -p $APIS_DIR/processed export RUST_LOG=info echo " **** PHASE 1 ***** " #cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_0_with_enums.txt -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_0.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_0.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt mv mapped_names.txt mapped_names_phase_1.txt mv mapped_types_to_names.txt mapped_types_to_names_pahse_1.txt echo " **** PHASE 2 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_1.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_1.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt mv mapped_names.txt mapped_names_phase_2.txt mv mapped_types_to_names.txt mapped_types_to_names_pahse_2.txt echo " **** PHASE 3 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_2.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_2.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt mv mapped_names.txt mapped_names_phase_3.txt mv mapped_types_to_names.txt mapped_types_to_names_pahse_3.txt echo " **** PHASE 4 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_3.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt -# cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/processed --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_3_with_enums.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names_pass_4_with_enums.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_3.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt mv mapped_names.txt mapped_names_phase_4.txt mv mapped_types_to_names.txt mapped_types_to_names_pahse_4.txt +echo " **** PHASE 5 ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard rename --rename-only-substitute-names ./type-reducer/rename_only_mapped_names.txt -cat << EOF >> $APIS_DIR/mod.rs +# cat << EOF >> $APIS_DIR/mod.rs -pub mod processed; -EOF +# pub mod processed; +# EOF ENUMS=( GRPCFilterType=RequestHeaderModifier RequestOperationType=ReplaceFullPath - HTTPFilterType=RequestHeaderModifier + HTTPFilterType=RequestHeaderModifier ) ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}") ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1} -echo "use super::common_types::*;" > $APIS_DIR/processed/enum_defaults.rs -GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/processed/enum_defaults.rs +echo "use super::common::*;" > $APIS_DIR/standard/enum_defaults.rs +GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/standard/enum_defaults.rs -sed -i '/#\[kube(status = "GRPCRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' ./gateway-api/src/apis/processed/grpcroutes.rs -sed -i '/#\[kube(status = "HTTPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' ./gateway-api/src/apis/processed/httproutes.rs +sed -i '/#\[kube(status = "GRPCRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/standard/grpcroutes.rs +sed -i '/#\[kube(status = "HTTPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/standard/httproutes.rs From f08841e8c326089a5fde69be99bfe2b7763c3c0c Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Thu, 26 Jun 2025 17:55:47 +0100 Subject: [PATCH 06/16] Adding CHANGELOG and support for experimental APIs, which requires adding ignorable types to solve for UDP, TCP RouteSpec case Signed-off-by: Dawid Nowak --- gateway-api/CHANGELOG.md | 16 + gateway-api/Cargo.toml | 11 +- gateway-api/src/apis/experimental/common.rs | 388 +++ .../src/apis/experimental/constants.rs | 11 - .../src/apis/experimental/enum_defaults.rs | 52 +- .../src/apis/experimental/gatewayclasses.rs | 43 +- gateway-api/src/apis/experimental/gateways.rs | 206 +- .../src/apis/experimental/grpcroutes.rs | 1395 +--------- .../src/apis/experimental/httproutes.rs | 2257 ++--------------- gateway-api/src/apis/experimental/mod.rs | 6 +- .../src/apis/experimental/referencegrants.rs | 7 +- .../src/apis/experimental/tcproutes.rs | 434 +--- .../src/apis/experimental/tlsroutes.rs | 437 +--- .../src/apis/experimental/udproutes.rs | 434 +--- gateway-api/src/apis/standard/common.rs | 24 +- .../src/apis/standard/gatewayclasses.rs | 17 +- gateway-api/src/apis/standard/gateways.rs | 34 +- gateway-api/src/apis/standard/grpcroutes.rs | 23 +- gateway-api/src/apis/standard/httproutes.rs | 71 +- .../src/apis/standard/referencegrants.rs | 11 +- .../experimental_customized_mapped_names.txt | 119 + .../experimental_ignorable_mapped_names.txt | 2 + ... => experimental_reduced_types_pass_0.txt} | 0 .../experimental_reduced_types_pass_1.txt | 19 + .../experimental_reduced_types_pass_2.txt | 27 + .../experimental_reduced_types_pass_3.txt | 33 + .../experimental_reduced_types_pass_4.txt | 35 + ...experimental_rename_only_mapped_names.txt} | 0 type-reducer/src/main.rs | 33 +- ...t => standard_customized_mapped_names.txt} | 0 .../standard_reduced_types_pass_0.txt | 1 + ....txt => standard_reduced_types_pass_1.txt} | 0 ....txt => standard_reduced_types_pass_2.txt} | 0 ....txt => standard_reduced_types_pass_3.txt} | 0 .../standard_rename_only_mapped_names.txt | 14 + update.sh | 69 +- 36 files changed, 1056 insertions(+), 5173 deletions(-) create mode 100644 gateway-api/CHANGELOG.md create mode 100644 gateway-api/src/apis/experimental/common.rs create mode 100644 type-reducer/experimental_customized_mapped_names.txt create mode 100644 type-reducer/experimental_ignorable_mapped_names.txt rename type-reducer/{reduced_types_pass_0.txt => experimental_reduced_types_pass_0.txt} (100%) create mode 100644 type-reducer/experimental_reduced_types_pass_1.txt create mode 100644 type-reducer/experimental_reduced_types_pass_2.txt create mode 100644 type-reducer/experimental_reduced_types_pass_3.txt create mode 100644 type-reducer/experimental_reduced_types_pass_4.txt rename type-reducer/{rename_only_mapped_names.txt => experimental_rename_only_mapped_names.txt} (100%) rename type-reducer/{customized_mapped_names.txt => standard_customized_mapped_names.txt} (100%) create mode 100644 type-reducer/standard_reduced_types_pass_0.txt rename type-reducer/{reduced_types_pass_1.txt => standard_reduced_types_pass_1.txt} (100%) rename type-reducer/{reduced_types_pass_2.txt => standard_reduced_types_pass_2.txt} (100%) rename type-reducer/{reduced_types_pass_3.txt => standard_reduced_types_pass_3.txt} (100%) create mode 100644 type-reducer/standard_rename_only_mapped_names.txt diff --git a/gateway-api/CHANGELOG.md b/gateway-api/CHANGELOG.md new file mode 100644 index 0000000..c060b4c --- /dev/null +++ b/gateway-api/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog + +## 0.2.0 + +>[!IMPORTANT] +Breaking change + +### Changed +The structure of APIs has changed to promote the re-use of types in the generated code. The APIs are still generated with Kopium in the first step, but there is a second stage where additional task is executed to reduce and rename the Kopium-generated types. +While with this approach we can significantly reduce the surface of exposed APIs, it is also a breaking change. +See [issue](https://github.com/kube-rs/gateway-api-rs/issues/38) for more context. + +## 0.1.0 + +### Changed +Initial release. All types are generated with Kopium. diff --git a/gateway-api/Cargo.toml b/gateway-api/Cargo.toml index 8f0fe96..a36f39e 100644 --- a/gateway-api/Cargo.toml +++ b/gateway-api/Cargo.toml @@ -38,14 +38,13 @@ uuid.workspace = true features = ["k8s-openapi/v1_32"] [features] -default = ["processed"] +default = ["standard", "experimental"] standard = [] experimental = [] -processed=[] [lints.clippy] -derivable_impls="allow" -doc_lazy_continuation="allow" -tabs_in_doc_comments="allow" -empty_line_after_doc_comments="allow" \ No newline at end of file +derivable_impls = "allow" +doc_lazy_continuation = "allow" +tabs_in_doc_comments = "allow" +empty_line_after_doc_comments = "allow" diff --git a/gateway-api/src/apis/experimental/common.rs b/gateway-api/src/apis/experimental/common.rs new file mode 100644 index 0000000..f25f083 --- /dev/null +++ b/gateway-api/src/apis/experimental/common.rs @@ -0,0 +1,388 @@ +// WARNING: generated file - manual changes will be overriden + +#[allow(unused_imports)] +mod prelude { + pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; + pub use kube::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Deserialize, Serialize}; + pub use std::collections::BTreeMap; +} +use self::prelude::*; +/// GRPCRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. GRPCRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum GRPCFilterType { + ResponseHeaderModifier, + RequestHeaderModifier, + RequestMirror, + ExtensionRef, +} +/// HTTPRouteFilter defines processing steps that must be completed during the +/// request or response lifecycle. HTTPRouteFilters are meant as an extension +/// point to express processing that may be done in Gateway implementations. Some +/// examples include request or response modification, implementing +/// authentication strategies, rate-limiting, and traffic shaping. API +/// guarantee/conformance is defined based on the type of the filter. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPFilterType { + RequestHeaderModifier, + ResponseHeaderModifier, + RequestMirror, + RequestRedirect, + #[serde(rename = "URLRewrite")] + UrlRewrite, + ExtensionRef, +} +/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request +/// headers. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HeaderMatchType { + Exact, + RegularExpression, +} +/// CookieConfig provides configuration settings that are specific +/// to cookie-based session persistence. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum PersistenceCookieConfigLifetime { + Permanent, + Session, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum RedirectStatusCode { + #[serde(rename = "301")] + r#_301, + #[serde(rename = "302")] + r#_302, +} +/// Path defines parameters used to modify the path of the incoming request. +/// The modified path is then used to construct the `Location` header. When +/// empty, the request path is used as-is. +/// +/// Support: Extended +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum RequestOperationType { + ReplaceFullPath, + ReplacePrefixMatch, +} +/// RequestRedirect defines a schema for a filter that responds to the +/// request with an HTTP redirection. +/// +/// Support: Core +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum RequestRedirectScheme { + #[serde(rename = "http")] + Http, + #[serde(rename = "https")] + Https, +} +/// SessionPersistence defines and configures session persistence +/// for the route rule. +/// +/// Support: Extended +/// +/// +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum SessionPersistenceType { + Cookie, + Header, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct BackendReference { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub weight: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct BackendTlsClientCertificateReference { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayAddress { + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + pub value: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GatewayInfrastructureParametersReference { + pub group: String, + pub kind: String, + pub name: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPHeader { + pub name: String, + pub value: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct Kind { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + pub kind: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct ParametersReference { + pub group: String, + pub kind: String, + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct ParentReference { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "sectionName" + )] + pub section_name: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RequestMirrorFraction { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub denominator: Option, + pub numerator: i32, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RequestMirrorReference { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct CommonRouteRule { + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "backendRefs" + )] + pub backend_refs: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub name: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HeaderMatch { + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + pub value: String, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HeaderModifier { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub add: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub remove: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub set: Option>, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct ParentRouteStatus { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub conditions: Option>, + #[serde(rename = "controllerName")] + pub controller_name: String, + #[serde(rename = "parentRef")] + pub parent_ref: ParentReference, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RequestMirror { + #[serde(rename = "backendRef")] + pub backend_ref: RequestMirrorReference, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub fraction: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub percent: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RequestRedirectPath { + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replaceFullPath" + )] + pub replace_full_path: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "replacePrefixMatch" + )] + pub replace_prefix_match: Option, + #[serde(rename = "type")] + pub r#type: RequestOperationType, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct SessionPersistenceCookieConfig { + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "lifetimeType" + )] + pub lifetime_type: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct GRPCRouteFilter { + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "extensionRef" + )] + pub extension_ref: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestMirror" + )] + pub request_mirror: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + #[serde(rename = "type")] + pub r#type: GRPCFilterType, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RequestRedirect { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub port: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub scheme: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "statusCode" + )] + pub status_code: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteUrlRewrite { + #[serde(default, skip_serializing_if = "Option::is_none")] + pub hostname: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct RouteStatus { + pub parents: Vec, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct SessionPersistence { + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "absoluteTimeout" + )] + pub absolute_timeout: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "cookieConfig" + )] + pub cookie_config: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "idleTimeout" + )] + pub idle_timeout: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "sessionName" + )] + pub session_name: Option, + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, +} +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct HTTPRouteBackendFilters { + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "extensionRef" + )] + pub extension_ref: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestHeaderModifier" + )] + pub request_header_modifier: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestMirror" + )] + pub request_mirror: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestRedirect" + )] + pub request_redirect: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "responseHeaderModifier" + )] + pub response_header_modifier: Option, + #[serde(rename = "type")] + pub r#type: HTTPFilterType, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "urlRewrite" + )] + pub url_rewrite: Option, +} diff --git a/gateway-api/src/apis/experimental/constants.rs b/gateway-api/src/apis/experimental/constants.rs index 83691ec..65653d9 100644 --- a/gateway-api/src/apis/experimental/constants.rs +++ b/gateway-api/src/apis/experimental/constants.rs @@ -5,13 +5,11 @@ pub enum GatewayClassConditionType { Accepted, SupportedVersion, } - impl std::fmt::Display for GatewayClassConditionType { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum GatewayClassConditionReason { Accepted, @@ -22,26 +20,22 @@ pub enum GatewayClassConditionReason { SupportedVersion, UnsupportedVersion, } - impl std::fmt::Display for GatewayClassConditionReason { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum GatewayConditionType { Programmed, Accepted, Ready, } - impl std::fmt::Display for GatewayConditionType { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum GatewayConditionReason { Programmed, @@ -57,13 +51,11 @@ pub enum GatewayConditionReason { Ready, ListenersNotReady, } - impl std::fmt::Display for GatewayConditionReason { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum ListenerConditionType { Conflicted, @@ -72,13 +64,11 @@ pub enum ListenerConditionType { Programmed, Ready, } - impl std::fmt::Display for ListenerConditionType { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) } } - #[derive(Debug, PartialEq, Eq)] pub enum ListenerConditionReason { HostnameConflict, @@ -96,7 +86,6 @@ pub enum ListenerConditionReason { Pending, Ready, } - impl std::fmt::Display for ListenerConditionReason { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", self) diff --git a/gateway-api/src/apis/experimental/enum_defaults.rs b/gateway-api/src/apis/experimental/enum_defaults.rs index 3fee275..fe4f3ae 100644 --- a/gateway-api/src/apis/experimental/enum_defaults.rs +++ b/gateway-api/src/apis/experimental/enum_defaults.rs @@ -1,58 +1,20 @@ +use super::common::*; // WARNING: generated file - manual changes will be overriden -use super::httproutes::{ - HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType, HTTPRouteRulesBackendRefsFiltersType, - HTTPRouteRulesBackendRefsFiltersUrlRewritePathType, - HTTPRouteRulesFiltersRequestRedirectPathType, HTTPRouteRulesFiltersType, - HTTPRouteRulesFiltersUrlRewritePathType, -}; - -use super::grpcroutes::{GRPCRouteRulesBackendRefsFiltersType, GRPCRouteRulesFiltersType}; - -impl Default for GRPCRouteRulesBackendRefsFiltersType { - fn default() -> Self { - GRPCRouteRulesBackendRefsFiltersType::RequestHeaderModifier - } -} - -impl Default for GRPCRouteRulesFiltersType { - fn default() -> Self { - GRPCRouteRulesFiltersType::RequestHeaderModifier - } -} - -impl Default for HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType { - fn default() -> Self { - HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType::ReplaceFullPath - } -} - -impl Default for HTTPRouteRulesBackendRefsFiltersType { - fn default() -> Self { - HTTPRouteRulesBackendRefsFiltersType::RequestHeaderModifier - } -} - -impl Default for HTTPRouteRulesBackendRefsFiltersUrlRewritePathType { - fn default() -> Self { - HTTPRouteRulesBackendRefsFiltersUrlRewritePathType::ReplaceFullPath - } -} - -impl Default for HTTPRouteRulesFiltersRequestRedirectPathType { +impl Default for GRPCFilterType { fn default() -> Self { - HTTPRouteRulesFiltersRequestRedirectPathType::ReplaceFullPath + GRPCFilterType::RequestHeaderModifier } } -impl Default for HTTPRouteRulesFiltersType { +impl Default for HTTPFilterType { fn default() -> Self { - HTTPRouteRulesFiltersType::RequestHeaderModifier + HTTPFilterType::RequestHeaderModifier } } -impl Default for HTTPRouteRulesFiltersUrlRewritePathType { +impl Default for RequestOperationType { fn default() -> Self { - HTTPRouteRulesFiltersUrlRewritePathType::ReplaceFullPath + RequestOperationType::ReplaceFullPath } } diff --git a/gateway-api/src/apis/experimental/gatewayclasses.rs b/gateway-api/src/apis/experimental/gatewayclasses.rs index 2d6053a..b2c3268 100644 --- a/gateway-api/src/apis/experimental/gatewayclasses.rs +++ b/gateway-api/src/apis/experimental/gatewayclasses.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.2 +// WARNING: generated file - manual changes will be overriden +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -10,7 +9,6 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of GatewayClass. #[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( @@ -59,42 +57,8 @@ pub struct GatewayClassSpec { skip_serializing_if = "Option::is_none", rename = "parametersRef" )] - pub parameters_ref: Option, -} - -/// ParametersRef is a reference to a resource that contains the configuration -/// parameters corresponding to the GatewayClass. This is optional if the -/// controller does not require any additional configuration. -/// -/// ParametersRef can reference a standard Kubernetes resource, i.e. ConfigMap, -/// or an implementation-specific custom resource. The resource can be -/// cluster-scoped or namespace-scoped. -/// -/// If the referent cannot be found, refers to an unsupported kind, or when -/// the data within that resource is malformed, the GatewayClass SHOULD be -/// rejected with the "Accepted" status condition set to "False" and an -/// "InvalidParameters" reason. -/// -/// A Gateway for this GatewayClass may provide its own `parametersRef`. When both are specified, -/// the merging behavior is implementation specific. -/// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. -/// -/// Support: Implementation-specific -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayClassParametersRef { - /// Group is the group of the referent. - pub group: String, - /// Kind is kind of the referent. - pub kind: String, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the referent. - /// This field is required when referring to a Namespace-scoped resource and - /// MUST be unset when referring to a Cluster-scoped resource. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, + pub parameters_ref: Option, } - /// Status defines the current state of GatewayClass. /// /// Implementations MUST populate status on all GatewayClass resources which @@ -118,7 +82,6 @@ pub struct GatewayClassStatus { )] pub supported_features: Option>, } - #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GatewayClassStatusSupportedFeatures { /// FeatureName is used to describe distinct features that are covered by diff --git a/gateway-api/src/apis/experimental/gateways.rs b/gateway-api/src/apis/experimental/gateways.rs index fa590f4..10e21a0 100644 --- a/gateway-api/src/apis/experimental/gateways.rs +++ b/gateway-api/src/apis/experimental/gateways.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.2 +// WARNING: generated file - manual changes will be overriden +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -11,7 +10,6 @@ mod prelude { pub use std::collections::BTreeMap; } use self::prelude::*; - /// Spec defines the desired state of Gateway. #[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( @@ -48,7 +46,7 @@ pub struct GatewaySpec { /// /// #[serde(default, skip_serializing_if = "Option::is_none")] - pub addresses: Option>, + pub addresses: Option>, /// BackendTLS configures TLS settings for when this Gateway is connecting to /// backends with TLS. /// @@ -189,20 +187,6 @@ pub struct GatewaySpec { /// Support: Core pub listeners: Vec, } - -/// GatewayAddress describes an address that can be bound to a Gateway. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayAddresses { - /// Type of the address. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value of the address. The validity of the values will depend - /// on the type and support by the controller. - /// - /// Examples: `1.2.3.4`, `128::1`, `my-ip-address`. - pub value: String, -} - /// BackendTLS configures TLS settings for when this Gateway is connecting to /// backends with TLS. /// @@ -233,50 +217,8 @@ pub struct GatewayBackendTls { skip_serializing_if = "Option::is_none", rename = "clientCertificateRef" )] - pub client_certificate_ref: Option, + pub client_certificate_ref: Option, } - -/// ClientCertificateRef is a reference to an object that contains a Client -/// Certificate and the associated private key. -/// -/// References to a resource in different namespace are invalid UNLESS there -/// is a ReferenceGrant in the target namespace that allows the certificate -/// to be attached. If a ReferenceGrant does not allow this reference, the -/// "ResolvedRefs" condition MUST be set to False for this listener with the -/// "RefNotPermitted" reason. -/// -/// ClientCertificateRef can reference to standard Kubernetes resources, i.e. -/// Secret, or implementation-specific custom resources. -/// -/// This setting can be overridden on the service level by use of BackendTLSPolicy. -/// -/// Support: Core -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayBackendTlsClientCertificateRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. For example "Secret". - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the referenced object. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, -} - /// Infrastructure defines infrastructure level attributes about this Gateway instance. /// /// Support: Extended @@ -321,30 +263,8 @@ pub struct GatewayInfrastructure { skip_serializing_if = "Option::is_none", rename = "parametersRef" )] - pub parameters_ref: Option, -} - -/// ParametersRef is a reference to a resource that contains the configuration -/// parameters corresponding to the Gateway. This is optional if the -/// controller does not require any additional configuration. -/// -/// This follows the same semantics as GatewayClass's `parametersRef`, but on a per-Gateway basis -/// -/// The Gateway's GatewayClass may provide its own `parametersRef`. When both are specified, -/// the merging behavior is implementation specific. -/// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. -/// -/// Support: Implementation-specific -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayInfrastructureParametersRef { - /// Group is the group of the referent. - pub group: String, - /// Kind is kind of the referent. - pub kind: String, - /// Name is the name of the referent. - pub name: String, + pub parameters_ref: Option, } - /// Listener embodies the concept of a logical endpoint where a Gateway accepts /// network connections. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] @@ -435,7 +355,6 @@ pub struct GatewayListeners { #[serde(default, skip_serializing_if = "Option::is_none")] pub tls: Option, } - /// AllowedRoutes defines the types of routes that MAY be attached to a /// Listener and the trusted namespaces where those Route resources MAY be /// present. @@ -474,7 +393,7 @@ pub struct GatewayListenersAllowedRoutes { /// /// Support: Core #[serde(default, skip_serializing_if = "Option::is_none")] - pub kinds: Option>, + pub kinds: Option>, /// Namespaces indicates namespaces from which Routes may be attached to this /// Listener. This is restricted to the namespace of this Gateway by default. /// @@ -482,17 +401,6 @@ pub struct GatewayListenersAllowedRoutes { #[serde(default, skip_serializing_if = "Option::is_none")] pub namespaces: Option, } - -/// RouteGroupKind indicates the group and kind of a Route resource. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersAllowedRoutesKinds { - /// Group is the group of the Route. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the kind of the Route. - pub kind: String, -} - /// Namespaces indicates namespaces from which Routes may be attached to this /// Listener. This is restricted to the namespace of this Gateway by default. /// @@ -518,7 +426,6 @@ pub struct GatewayListenersAllowedRoutesNamespaces { #[serde(default, skip_serializing_if = "Option::is_none")] pub selector: Option, } - /// Namespaces indicates namespaces from which Routes may be attached to this /// Listener. This is restricted to the namespace of this Gateway by default. /// @@ -529,7 +436,6 @@ pub enum GatewayListenersAllowedRoutesNamespacesFrom { Selector, Same, } - /// Selector must be specified when From is set to "Selector". In that case, /// only Routes in Namespaces matching this Selector will be selected by this /// Gateway. This field is ignored for other values of "From". @@ -555,7 +461,6 @@ pub struct GatewayListenersAllowedRoutesNamespacesSelector { )] pub match_labels: Option>, } - /// A label selector requirement is a selector that contains values, a key, and an operator that /// relates the key and values. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] @@ -572,7 +477,6 @@ pub struct GatewayListenersAllowedRoutesNamespacesSelectorMatchExpressions { #[serde(default, skip_serializing_if = "Option::is_none")] pub values: Option>, } - /// TLS is the TLS configuration for the Listener. This field is required if /// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field /// if the Protocol field is "HTTP", "TCP", or "UDP". @@ -615,7 +519,7 @@ pub struct GatewayListenersTls { skip_serializing_if = "Option::is_none", rename = "certificateRefs" )] - pub certificate_refs: Option>, + pub certificate_refs: Option>, /// FrontendValidation holds configuration information for validating the frontend (client). /// Setting this field will require clients to send a client certificate /// required for validation during the TLS handshake. In browsers this may result in a dialog appearing @@ -659,40 +563,6 @@ pub struct GatewayListenersTls { #[serde(default, skip_serializing_if = "Option::is_none")] pub options: Option>, } - -/// SecretObjectReference identifies an API object including its namespace, -/// defaulting to Secret. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -/// -/// References to objects with invalid Group and Kind are not valid, and must -/// be rejected by the implementation, with appropriate Conditions set -/// on the containing object. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersTlsCertificateRefs { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. For example "Secret". - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the referenced object. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, -} - /// FrontendValidation holds configuration information for validating the frontend (client). /// Setting this field will require clients to send a client certificate /// required for validation during the TLS handshake. In browsers this may result in a dialog appearing @@ -730,39 +600,8 @@ pub struct GatewayListenersTlsFrontendValidation { skip_serializing_if = "Option::is_none", rename = "caCertificateRefs" )] - pub ca_certificate_refs: Option>, + pub ca_certificate_refs: Option>, } - -/// ObjectReference identifies an API object including its namespace. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -/// -/// References to objects with invalid Group and Kind are not valid, and must -/// be rejected by the implementation, with appropriate Conditions set -/// on the containing object. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayListenersTlsFrontendValidationCaCertificateRefs { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - pub group: String, - /// Kind is kind of the referent. For example "ConfigMap" or "Service". - pub kind: String, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the referenced object. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, -} - /// TLS is the TLS configuration for the Listener. This field is required if /// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field /// if the Protocol field is "HTTP", "TCP", or "UDP". @@ -779,7 +618,6 @@ pub enum GatewayListenersTlsMode { Terminate, Passthrough, } - /// Status defines the current state of Gateway. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GatewayStatus { @@ -795,7 +633,7 @@ pub struct GatewayStatus { /// /// #[serde(default, skip_serializing_if = "Option::is_none")] - pub addresses: Option>, + pub addresses: Option>, /// Conditions describe the current conditions of the Gateway. /// /// Implementations should prefer to express Gateway conditions @@ -814,20 +652,6 @@ pub struct GatewayStatus { #[serde(default, skip_serializing_if = "Option::is_none")] pub listeners: Option>, } - -/// GatewayStatusAddress describes a network address that is bound to a Gateway. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayStatusAddresses { - /// Type of the address. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value of the address. The validity of the values will depend - /// on the type and support by the controller. - /// - /// Examples: `1.2.3.4`, `128::1`, `my-ip-address`. - pub value: String, -} - /// ListenerStatus is the status associated with a Listener. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GatewayStatusListeners { @@ -864,15 +688,5 @@ pub struct GatewayStatusListeners { /// and invalid Route kinds are specified, the implementation MUST /// reference the valid Route kinds that have been specified. #[serde(rename = "supportedKinds")] - pub supported_kinds: Vec, -} - -/// RouteGroupKind indicates the group and kind of a Route resource. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GatewayStatusListenersSupportedKinds { - /// Group is the group of the Route. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the kind of the Route. - pub kind: String, + pub supported_kinds: Vec, } diff --git a/gateway-api/src/apis/experimental/grpcroutes.rs b/gateway-api/src/apis/experimental/grpcroutes.rs index 5710d30..e47c4b8 100644 --- a/gateway-api/src/apis/experimental/grpcroutes.rs +++ b/gateway-api/src/apis/experimental/grpcroutes.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.2 +// WARNING: generated file - manual changes will be overriden +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -10,7 +9,6 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of GRPCRoute. #[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( @@ -20,7 +18,7 @@ use self::prelude::*; plural = "grpcroutes" )] #[kube(namespaced)] -#[kube(status = "GRPCRouteStatus")] +#[kube(status = "RouteStatus")] #[kube(derive = "Default")] #[kube(derive = "PartialEq")] pub struct GRPCRouteSpec { @@ -148,143 +146,18 @@ pub struct GRPCRouteSpec { skip_serializing_if = "Option::is_none", rename = "parentRefs" )] - pub parent_refs: Option>, + pub parent_refs: Option>, /// Rules are a list of GRPC matchers, filters and actions. /// /// #[serde(default, skip_serializing_if = "Option::is_none")] - pub rules: Option>, -} - -/// ParentReference identifies an API object (usually a Gateway) that can be considered -/// a parent of this resource (usually a route). There are two kinds of parent resources -/// with "Core" support: -/// -/// * Gateway (Gateway conformance profile) -/// * Service (Mesh conformance profile, ClusterIP Services only) -/// -/// This API may be extended in the future to support additional kinds of parent -/// resources. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteParentRefs { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, + pub rules: Option>, } - /// GRPCRouteRule defines the semantics for matching a gRPC request based on /// conditions (matches), processing it (filters), and forwarding the request to /// an API object (backendRefs). #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRules { +pub struct GRPCRouteRule { /// BackendRefs defines the backend(s) where matching requests should be /// sent. /// @@ -318,7 +191,7 @@ pub struct GRPCRouteRules { skip_serializing_if = "Option::is_none", rename = "backendRefs" )] - pub backend_refs: Option>, + pub backend_refs: Option>, /// Filters define the filters that are applied to requests that match /// this rule. /// @@ -344,7 +217,7 @@ pub struct GRPCRouteRules { /// /// Support: Core #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Matches define conditions used for matching the rule against incoming /// gRPC requests. Each match is independent, i.e. this rule will be matched /// if **any** one of the matches is satisfied. @@ -395,7 +268,7 @@ pub struct GRPCRouteRules { /// matching precedence MUST be granted to the first matching rule meeting /// the above criteria. #[serde(default, skip_serializing_if = "Option::is_none")] - pub matches: Option>, + pub matches: Option>, /// Name is the name of the route rule. This name MUST be unique within a Route if it is set. /// /// Support: Extended @@ -413,9 +286,8 @@ pub struct GRPCRouteRules { skip_serializing_if = "Option::is_none", rename = "sessionPersistence" )] - pub session_persistence: Option, + pub session_persistence: Option, } - /// GRPCBackendRef defines how a GRPCRoute forwards a gRPC request. /// /// Note that when a namespace different than the local namespace is specified, a @@ -441,14 +313,14 @@ pub struct GRPCRouteRules { /// /// #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefs { +pub struct GRPCBackendReference { /// Filters defined at this level MUST be executed if and only if the /// request is being forwarded to the backend defined here. /// /// Support: Implementation-specific (For broader support of filters, use the /// Filters field in GRPCRouteRule.) #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Group is the group of the referent. For example, "gateway.networking.k8s.io". /// When unspecified or empty string, core API group is inferred. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -505,907 +377,6 @@ pub struct GRPCRouteRulesBackendRefs { #[serde(default, skip_serializing_if = "Option::is_none")] pub weight: Option, } - -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// Support: Implementation-specific - /// - /// This filter can be used multiple times within the same rule. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "extensionRef" - )] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestMirror" - )] - pub request_mirror: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations supporting GRPCRoute MUST support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` MUST be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// - #[serde(rename = "type")] - pub r#type: GRPCRouteRulesBackendRefsFiltersType, -} - -/// ExtensionRef is an optional, implementation-specific extension to the -/// "filter" behavior. For example, resource "myroutefilter" in group -/// "networking.example.net"). ExtensionRef MUST NOT be used for core and -/// extended filters. -/// -/// Support: Implementation-specific -/// -/// This filter can be used multiple times within the same rule. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersExtensionRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - pub group: String, - /// Kind is kind of the referent. For example "HTTPRoute" or "Service". - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} - -/// RequestHeaderModifier defines a schema for a filter that modifies request -/// headers. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// RequestMirror defines a schema for a filter that mirrors requests. -/// Requests are sent to the specified destination, but responses from -/// that destination are ignored. -/// -/// This filter can be used multiple times within the same rule. Note that -/// not all implementations will be able to support mirroring to multiple -/// backends. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestMirror { - /// BackendRef references a resource where mirrored requests are sent. - /// - /// Mirrored requests must be sent only to a single destination endpoint - /// within this BackendRef, irrespective of how many endpoints are present - /// within this BackendRef. - /// - /// If the referent cannot be found, this BackendRef is invalid and must be - /// dropped from the Gateway. The controller must ensure the "ResolvedRefs" - /// condition on the Route status is set to `status: False` and not configure - /// this backend in the underlying implementation. - /// - /// If there is a cross-namespace reference to an *existing* object - /// that is not allowed by a ReferenceGrant, the controller must ensure the - /// "ResolvedRefs" condition on the Route is set to `status: False`, - /// with the "RefNotPermitted" reason and not configure this backend in the - /// underlying implementation. - /// - /// In either error case, the Message of the `ResolvedRefs` Condition - /// should be used to provide more detail about the problem. - /// - /// Support: Extended for Kubernetes Service - /// - /// Support: Implementation-specific for any other resource - #[serde(rename = "backendRef")] - pub backend_ref: GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef, - /// Fraction represents the fraction of requests that should be - /// mirrored to BackendRef. - /// - /// Only one of Fraction or Percent may be specified. If neither field - /// is specified, 100% of requests will be mirrored. - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub fraction: Option, - /// Percent represents the percentage of requests that should be - /// mirrored to BackendRef. Its minimum value is 0 (indicating 0% of - /// requests) and its maximum value is 100 (indicating 100% of requests). - /// - /// Only one of Fraction or Percent may be specified. If neither field - /// is specified, 100% of requests will be mirrored. - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub percent: Option, -} - -/// BackendRef references a resource where mirrored requests are sent. -/// -/// Mirrored requests must be sent only to a single destination endpoint -/// within this BackendRef, irrespective of how many endpoints are present -/// within this BackendRef. -/// -/// If the referent cannot be found, this BackendRef is invalid and must be -/// dropped from the Gateway. The controller must ensure the "ResolvedRefs" -/// condition on the Route status is set to `status: False` and not configure -/// this backend in the underlying implementation. -/// -/// If there is a cross-namespace reference to an *existing* object -/// that is not allowed by a ReferenceGrant, the controller must ensure the -/// "ResolvedRefs" condition on the Route is set to `status: False`, -/// with the "RefNotPermitted" reason and not configure this backend in the -/// underlying implementation. -/// -/// In either error case, the Message of the `ResolvedRefs` Condition -/// should be used to provide more detail about the problem. -/// -/// Support: Extended for Kubernetes Service -/// -/// Support: Implementation-specific for any other resource -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, -} - -/// Fraction represents the fraction of requests that should be -/// mirrored to BackendRef. -/// -/// Only one of Fraction or Percent may be specified. If neither field -/// is specified, 100% of requests will be mirrored. -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersRequestMirrorFraction { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub denominator: Option, - pub numerator: i32, -} - -/// ResponseHeaderModifier defines a schema for a filter that modifies response -/// headers. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersResponseHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesBackendRefsFiltersType { - ResponseHeaderModifier, - RequestHeaderModifier, - RequestMirror, - ExtensionRef, -} - -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// Support: Implementation-specific - /// - /// This filter can be used multiple times within the same rule. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "extensionRef" - )] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestMirror" - )] - pub request_mirror: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations supporting GRPCRoute MUST support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` MUST be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// - #[serde(rename = "type")] - pub r#type: GRPCRouteRulesFiltersType, -} - -/// ExtensionRef is an optional, implementation-specific extension to the -/// "filter" behavior. For example, resource "myroutefilter" in group -/// "networking.example.net"). ExtensionRef MUST NOT be used for core and -/// extended filters. -/// -/// Support: Implementation-specific -/// -/// This filter can be used multiple times within the same rule. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersExtensionRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - pub group: String, - /// Kind is kind of the referent. For example "HTTPRoute" or "Service". - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} - -/// RequestHeaderModifier defines a schema for a filter that modifies request -/// headers. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// RequestMirror defines a schema for a filter that mirrors requests. -/// Requests are sent to the specified destination, but responses from -/// that destination are ignored. -/// -/// This filter can be used multiple times within the same rule. Note that -/// not all implementations will be able to support mirroring to multiple -/// backends. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestMirror { - /// BackendRef references a resource where mirrored requests are sent. - /// - /// Mirrored requests must be sent only to a single destination endpoint - /// within this BackendRef, irrespective of how many endpoints are present - /// within this BackendRef. - /// - /// If the referent cannot be found, this BackendRef is invalid and must be - /// dropped from the Gateway. The controller must ensure the "ResolvedRefs" - /// condition on the Route status is set to `status: False` and not configure - /// this backend in the underlying implementation. - /// - /// If there is a cross-namespace reference to an *existing* object - /// that is not allowed by a ReferenceGrant, the controller must ensure the - /// "ResolvedRefs" condition on the Route is set to `status: False`, - /// with the "RefNotPermitted" reason and not configure this backend in the - /// underlying implementation. - /// - /// In either error case, the Message of the `ResolvedRefs` Condition - /// should be used to provide more detail about the problem. - /// - /// Support: Extended for Kubernetes Service - /// - /// Support: Implementation-specific for any other resource - #[serde(rename = "backendRef")] - pub backend_ref: GRPCRouteRulesFiltersRequestMirrorBackendRef, - /// Fraction represents the fraction of requests that should be - /// mirrored to BackendRef. - /// - /// Only one of Fraction or Percent may be specified. If neither field - /// is specified, 100% of requests will be mirrored. - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub fraction: Option, - /// Percent represents the percentage of requests that should be - /// mirrored to BackendRef. Its minimum value is 0 (indicating 0% of - /// requests) and its maximum value is 100 (indicating 100% of requests). - /// - /// Only one of Fraction or Percent may be specified. If neither field - /// is specified, 100% of requests will be mirrored. - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub percent: Option, -} - -/// BackendRef references a resource where mirrored requests are sent. -/// -/// Mirrored requests must be sent only to a single destination endpoint -/// within this BackendRef, irrespective of how many endpoints are present -/// within this BackendRef. -/// -/// If the referent cannot be found, this BackendRef is invalid and must be -/// dropped from the Gateway. The controller must ensure the "ResolvedRefs" -/// condition on the Route status is set to `status: False` and not configure -/// this backend in the underlying implementation. -/// -/// If there is a cross-namespace reference to an *existing* object -/// that is not allowed by a ReferenceGrant, the controller must ensure the -/// "ResolvedRefs" condition on the Route is set to `status: False`, -/// with the "RefNotPermitted" reason and not configure this backend in the -/// underlying implementation. -/// -/// In either error case, the Message of the `ResolvedRefs` Condition -/// should be used to provide more detail about the problem. -/// -/// Support: Extended for Kubernetes Service -/// -/// Support: Implementation-specific for any other resource -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestMirrorBackendRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, -} - -/// Fraction represents the fraction of requests that should be -/// mirrored to BackendRef. -/// -/// Only one of Fraction or Percent may be specified. If neither field -/// is specified, 100% of requests will be mirrored. -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersRequestMirrorFraction { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub denominator: Option, - pub numerator: i32, -} - -/// ResponseHeaderModifier defines a schema for a filter that modifies response -/// headers. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersResponseHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersResponseHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesFiltersResponseHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesFiltersType { - ResponseHeaderModifier, - RequestHeaderModifier, - RequestMirror, - ExtensionRef, -} - /// GRPCRouteMatch defines the predicate used to match requests to a given /// action. Multiple match types are ANDed together, i.e. the match will /// evaluate to true only if all conditions are satisfied. @@ -1424,49 +395,21 @@ pub enum GRPCRouteRulesFiltersType { /// /// ``` #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesMatches { +pub struct GRPCRouteMatch { /// Headers specifies gRPC request header matchers. Multiple match values are /// ANDed together, meaning, a request MUST match all the specified headers /// to select the route. #[serde(default, skip_serializing_if = "Option::is_none")] - pub headers: Option>, + pub headers: Option>, /// Method specifies a gRPC request service/method matcher. If this field is /// not specified, all services and methods will match. #[serde(default, skip_serializing_if = "Option::is_none")] - pub method: Option, + pub method: Option, } - -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesMatchesHeaders { - /// Name is the name of the gRPC Header to be matched. - /// - /// If multiple entries specify equivalent header names, only the first - /// entry with an equivalent name MUST be considered for a match. Subsequent - /// entries with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Type specifies how to match against the value of the header. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value is the value of the gRPC Header to be matched. - pub value: String, -} - -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesMatchesHeadersType { - Exact, - RegularExpression, -} - /// Method specifies a gRPC request service/method matcher. If this field is /// not specified, all services and methods will match. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesMatchesMethod { +pub struct GRPCMethodMatch { /// Value of the method to match against. If left empty or omitted, will /// match all services. /// @@ -1486,309 +429,5 @@ pub struct GRPCRouteRulesMatchesMethod { /// /// Support: Implementation-specific (RegularExpression) #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, -} - -/// Method specifies a gRPC request service/method matcher. If this field is -/// not specified, all services and methods will match. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesMatchesMethodType { - Exact, - RegularExpression, -} - -/// SessionPersistence defines and configures session persistence -/// for the route rule. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesSessionPersistence { - /// AbsoluteTimeout defines the absolute timeout of the persistent - /// session. Once the AbsoluteTimeout duration has elapsed, the - /// session becomes invalid. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "absoluteTimeout" - )] - pub absolute_timeout: Option, - /// CookieConfig provides configuration settings that are specific - /// to cookie-based session persistence. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "cookieConfig" - )] - pub cookie_config: Option, - /// IdleTimeout defines the idle timeout of the persistent session. - /// Once the session has been idle for more than the specified - /// IdleTimeout duration, the session becomes invalid. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "idleTimeout" - )] - pub idle_timeout: Option, - /// SessionName defines the name of the persistent session token - /// which may be reflected in the cookie or the header. Users - /// should avoid reusing session names to prevent unintended - /// consequences, such as rejection or unpredictable behavior. - /// - /// Support: Implementation-specific - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sessionName" - )] - pub session_name: Option, - /// Type defines the type of session persistence such as through - /// the use a header or cookie. Defaults to cookie based session - /// persistence. - /// - /// Support: Core for "Cookie" type - /// - /// Support: Extended for "Header" type - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, -} - -/// CookieConfig provides configuration settings that are specific -/// to cookie-based session persistence. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteRulesSessionPersistenceCookieConfig { - /// LifetimeType specifies whether the cookie has a permanent or - /// session-based lifetime. A permanent cookie persists until its - /// specified expiry time, defined by the Expires or Max-Age cookie - /// attributes, while a session cookie is deleted when the current - /// session ends. - /// - /// When set to "Permanent", AbsoluteTimeout indicates the - /// cookie's lifetime via the Expires or Max-Age cookie attributes - /// and is required. - /// - /// When set to "Session", AbsoluteTimeout indicates the - /// absolute lifetime of the cookie tracked by the gateway and - /// is optional. - /// - /// Support: Core for "Session" type - /// - /// Support: Extended for "Permanent" type - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "lifetimeType" - )] - pub lifetime_type: Option, -} - -/// CookieConfig provides configuration settings that are specific -/// to cookie-based session persistence. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesSessionPersistenceCookieConfigLifetimeType { - Permanent, - Session, -} - -/// SessionPersistence defines and configures session persistence -/// for the route rule. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum GRPCRouteRulesSessionPersistenceType { - Cookie, - Header, -} - -/// Status defines the current state of GRPCRoute. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteStatus { - /// Parents is a list of parent resources (usually Gateways) that are - /// associated with the route, and the status of the route with respect to - /// each parent. When this route attaches to a parent, the controller that - /// manages the parent must add an entry to this list when the controller - /// first sees the route and should update the entry as appropriate when the - /// route or gateway is modified. - /// - /// Note that parent references that cannot be resolved by an implementation - /// of this API will not be added to this list. Implementations of this API - /// can only populate Route status for the Gateways/parent resources they are - /// responsible for. - /// - /// A maximum of 32 Gateways will be represented in this list. An empty list - /// means the route has not been attached to any Gateway. - pub parents: Vec, -} - -/// RouteParentStatus describes the status of a route with respect to an -/// associated Parent. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteStatusParents { - /// Conditions describes the status of the route with respect to the Gateway. - /// Note that the route's availability is also subject to the Gateway's own - /// status conditions and listener status. - /// - /// If the Route's ParentRef specifies an existing Gateway that supports - /// Routes of this kind AND that Gateway's controller has sufficient access, - /// then that Gateway's controller MUST set the "Accepted" condition on the - /// Route, to indicate whether the route has been accepted or rejected by the - /// Gateway, and why. - /// - /// A Route MUST be considered "Accepted" if at least one of the Route's - /// rules is implemented by the Gateway. - /// - /// There are a number of cases where the "Accepted" condition may not be set - /// due to lack of controller visibility, that includes when: - /// - /// * The Route refers to a non-existent parent. - /// * The Route is of a type that the controller does not support. - /// * The Route is in a namespace the controller does not have access to. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// ControllerName is a domain/path string that indicates the name of the - /// controller that wrote this status. This corresponds with the - /// controllerName field on GatewayClass. - /// - /// Example: "example.net/gateway-controller". - /// - /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are - /// valid Kubernetes names - /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). - /// - /// Controllers MUST populate this field when writing status. Controllers should ensure that - /// entries to status populated with their ControllerName are cleaned up when they are no - /// longer necessary. - #[serde(rename = "controllerName")] - pub controller_name: String, - /// ParentRef corresponds with a ParentRef in the spec that this - /// RouteParentStatus struct describes the status of. - #[serde(rename = "parentRef")] - pub parent_ref: GRPCRouteStatusParentsParentRef, -} - -/// ParentRef corresponds with a ParentRef in the spec that this -/// RouteParentStatus struct describes the status of. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct GRPCRouteStatusParentsParentRef { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, + pub r#type: Option, } diff --git a/gateway-api/src/apis/experimental/httproutes.rs b/gateway-api/src/apis/experimental/httproutes.rs index d5dfc8a..8a7115b 100644 --- a/gateway-api/src/apis/experimental/httproutes.rs +++ b/gateway-api/src/apis/experimental/httproutes.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.2 +// WARNING: generated file - manual changes will be overriden +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -10,7 +9,6 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of HTTPRoute. #[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( @@ -20,7 +18,7 @@ use self::prelude::*; plural = "httproutes" )] #[kube(namespaced)] -#[kube(status = "HTTPRouteStatus")] +#[kube(status = "RouteStatus")] #[kube(derive = "Default")] #[kube(derive = "PartialEq")] pub struct HTTPRouteSpec { @@ -151,143 +149,18 @@ pub struct HTTPRouteSpec { skip_serializing_if = "Option::is_none", rename = "parentRefs" )] - pub parent_refs: Option>, + pub parent_refs: Option>, /// Rules are a list of HTTP matchers, filters and actions. /// /// #[serde(default, skip_serializing_if = "Option::is_none")] - pub rules: Option>, -} - -/// ParentReference identifies an API object (usually a Gateway) that can be considered -/// a parent of this resource (usually a route). There are two kinds of parent resources -/// with "Core" support: -/// -/// * Gateway (Gateway conformance profile) -/// * Service (Mesh conformance profile, ClusterIP Services only) -/// -/// This API may be extended in the future to support additional kinds of parent -/// resources. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteParentRefs { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, + pub rules: Option>, } - /// HTTPRouteRule defines semantics for matching an HTTP request based on /// conditions (matches), processing it (filters), and forwarding the request to /// an API object (backendRefs). #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRules { +pub struct HTTPRouteRule { /// BackendRefs defines the backend(s) where matching requests should be /// sent. /// @@ -328,7 +201,7 @@ pub struct HTTPRouteRules { skip_serializing_if = "Option::is_none", rename = "backendRefs" )] - pub backend_refs: Option>, + pub backend_refs: Option>, /// Filters define the filters that are applied to requests that match /// this rule. /// @@ -366,7 +239,7 @@ pub struct HTTPRouteRules { /// /// Support: Core #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Matches define conditions used for matching the rule against incoming /// HTTP requests. Each match is independent, i.e. this rule will be matched /// if **any** one of the matches is satisfied. @@ -424,7 +297,7 @@ pub struct HTTPRouteRules { /// When no rules matching a request have been successfully attached to the /// parent a request is coming from, a HTTP 404 status code MUST be returned. #[serde(default, skip_serializing_if = "Option::is_none")] - pub matches: Option>, + pub matches: Option>, /// Name is the name of the route rule. This name MUST be unique within a Route if it is set. /// /// Support: Extended @@ -449,14 +322,13 @@ pub struct HTTPRouteRules { skip_serializing_if = "Option::is_none", rename = "sessionPersistence" )] - pub session_persistence: Option, + pub session_persistence: Option, /// Timeouts defines the timeouts that can be configured for an HTTP request. /// /// Support: Extended #[serde(default, skip_serializing_if = "Option::is_none")] - pub timeouts: Option, + pub timeouts: Option, } - /// HTTPBackendRef defines how a HTTPRoute forwards a HTTP request. /// /// Note that when a namespace different than the local namespace is specified, a @@ -482,14 +354,14 @@ pub struct HTTPRouteRules { /// /// #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefs { +pub struct HTTPBackendReference { /// Filters defined at this level should be executed if and only if the /// request is being forwarded to the backend defined here. /// /// Support: Implementation-specific (For broader support of filters, use the /// Filters field in HTTPRouteRule.) #[serde(default, skip_serializing_if = "Option::is_none")] - pub filters: Option>, + pub filters: Option>, /// Group is the group of the referent. For example, "gateway.networking.k8s.io". /// When unspecified or empty string, core API group is inferred. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -546,1826 +418,183 @@ pub struct HTTPRouteRulesBackendRefs { #[serde(default, skip_serializing_if = "Option::is_none")] pub weight: Option, } - -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. +/// HTTPRouteMatch defines the predicate used to match requests to a given +/// action. Multiple match types are ANDed together, i.e. the match will +/// evaluate to true only if all conditions are satisfied. +/// +/// For example, the match below will match a HTTP request only if its path +/// starts with `/foo` AND it contains the `version: v1` header: +/// +/// ```text +/// match: +/// +/// path: +/// value: "/foo" +/// headers: +/// - name: "version" +/// value "v1" +/// +/// ``` #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// This filter can be used multiple times within the same rule. - /// - /// Support: Implementation-specific - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "extensionRef" - )] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestMirror" - )] - pub request_mirror: Option, - /// RequestRedirect defines a schema for a filter that responds to the - /// request with an HTTP redirection. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestRedirect" - )] - pub request_redirect: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. +pub struct RouteMatch { + /// Headers specifies HTTP request header matchers. Multiple match values are + /// ANDed together, meaning, a request must match all the specified headers + /// to select the route. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub headers: Option>, + /// Method specifies HTTP method matcher. + /// When specified, this route will be matched only if the request has the + /// specified method. /// /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations must support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by - /// specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` should be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesBackendRefsFiltersType, - /// URLRewrite defines a schema for a filter that modifies a request during forwarding. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub method: Option, + /// Path specifies a HTTP request path matcher. If this field is not + /// specified, a default prefix match on the "/" path is provided. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub path: Option, + /// QueryParams specifies HTTP query parameter matchers. Multiple match + /// values are ANDed together, meaning, a request must match all the + /// specified query parameters to select the route. /// /// Support: Extended #[serde( default, skip_serializing_if = "Option::is_none", - rename = "urlRewrite" + rename = "queryParams" )] - pub url_rewrite: Option, + pub query_params: Option>, } - -/// ExtensionRef is an optional, implementation-specific extension to the -/// "filter" behavior. For example, resource "myroutefilter" in group -/// "networking.example.net"). ExtensionRef MUST NOT be used for core and -/// extended filters. +/// HTTPRouteMatch defines the predicate used to match requests to a given +/// action. Multiple match types are ANDed together, i.e. the match will +/// evaluate to true only if all conditions are satisfied. +/// +/// For example, the match below will match a HTTP request only if its path +/// starts with `/foo` AND it contains the `version: v1` header: /// -/// This filter can be used multiple times within the same rule. +/// ```text +/// match: /// -/// Support: Implementation-specific -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersExtensionRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - pub group: String, - /// Kind is kind of the referent. For example "HTTPRoute" or "Service". - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} - -/// RequestHeaderModifier defines a schema for a filter that modifies request -/// headers. +/// path: +/// value: "/foo" +/// headers: +/// - name: "version" +/// value "v1" /// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, +/// ``` +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPMethodMatch { + #[serde(rename = "GET")] + Get, + #[serde(rename = "HEAD")] + Head, + #[serde(rename = "POST")] + Post, + #[serde(rename = "PUT")] + Put, + #[serde(rename = "DELETE")] + Delete, + #[serde(rename = "CONNECT")] + Connect, + #[serde(rename = "OPTIONS")] + Options, + #[serde(rename = "TRACE")] + Trace, + #[serde(rename = "PATCH")] + Patch, } - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. +/// Path specifies a HTTP request path matcher. If this field is not +/// specified, a default prefix match on the "/" path is provided. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, +pub struct PathMatch { + /// Type specifies how to match against the path Value. + /// + /// Support: Core (Exact, PathPrefix) + /// + /// Support: Implementation-specific (RegularExpression) + #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] + pub r#type: Option, + /// Value of the HTTP path to match against. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub value: Option, } - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, +/// Path specifies a HTTP request path matcher. If this field is not +/// specified, a default prefix match on the "/" path is provided. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum HTTPRouteRulesMatchesPathType { + Exact, + PathPrefix, + RegularExpression, } - -/// RequestMirror defines a schema for a filter that mirrors requests. -/// Requests are sent to the specified destination, but responses from -/// that destination are ignored. -/// -/// This filter can be used multiple times within the same rule. Note that -/// not all implementations will be able to support mirroring to multiple -/// backends. +/// Retry defines the configuration for when to retry an HTTP request. /// /// Support: Extended /// /// #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestMirror { - /// BackendRef references a resource where mirrored requests are sent. - /// - /// Mirrored requests must be sent only to a single destination endpoint - /// within this BackendRef, irrespective of how many endpoints are present - /// within this BackendRef. +pub struct HTTPRouteRulesRetry { + /// Attempts specifies the maxmimum number of times an individual request + /// from the gateway to a backend should be retried. /// - /// If the referent cannot be found, this BackendRef is invalid and must be - /// dropped from the Gateway. The controller must ensure the "ResolvedRefs" - /// condition on the Route status is set to `status: False` and not configure - /// this backend in the underlying implementation. + /// If the maximum number of retries has been attempted without a successful + /// response from the backend, the Gateway MUST return an error. /// - /// If there is a cross-namespace reference to an *existing* object - /// that is not allowed by a ReferenceGrant, the controller must ensure the - /// "ResolvedRefs" condition on the Route is set to `status: False`, - /// with the "RefNotPermitted" reason and not configure this backend in the - /// underlying implementation. + /// When this field is unspecified, the number of times to attempt to retry + /// a backend request is implementation-specific. /// - /// In either error case, the Message of the `ResolvedRefs` Condition - /// should be used to provide more detail about the problem. + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub attempts: Option, + /// Backoff specifies the minimum duration a Gateway should wait between + /// retry attempts and is represented in Gateway API Duration formatting. /// - /// Support: Extended for Kubernetes Service + /// For example, setting the `rules[].retry.backoff` field to the value + /// `100ms` will cause a backend request to first be retried approximately + /// 100 milliseconds after timing out or receiving a response code configured + /// to be retryable. /// - /// Support: Implementation-specific for any other resource - #[serde(rename = "backendRef")] - pub backend_ref: HTTPRouteRulesBackendRefsFiltersRequestMirrorBackendRef, - /// Fraction represents the fraction of requests that should be - /// mirrored to BackendRef. + /// An implementation MAY use an exponential or alternative backoff strategy + /// for subsequent retry attempts, MAY cap the maximum backoff duration to + /// some amount greater than the specified minimum, and MAY add arbitrary + /// jitter to stagger requests, as long as unsuccessful backend requests are + /// not retried before the configured minimum duration. /// - /// Only one of Fraction or Percent may be specified. If neither field - /// is specified, 100% of requests will be mirrored. + /// If a Request timeout (`rules[].timeouts.request`) is configured on the + /// route, the entire duration of the initial request and any retry attempts + /// MUST not exceed the Request timeout duration. If any retry attempts are + /// still in progress when the Request timeout duration has been reached, + /// these SHOULD be canceled if possible and the Gateway MUST immediately + /// return a timeout error. /// + /// If a BackendRequest timeout (`rules[].timeouts.backendRequest`) is + /// configured on the route, any retry attempts which reach the configured + /// BackendRequest timeout duration without a response SHOULD be canceled if + /// possible and the Gateway should wait for at least the specified backoff + /// duration before attempting to retry the backend request again. /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub fraction: Option, - /// Percent represents the percentage of requests that should be - /// mirrored to BackendRef. Its minimum value is 0 (indicating 0% of - /// requests) and its maximum value is 100 (indicating 100% of requests). + /// If a BackendRequest timeout is _not_ configured on the route, retry + /// attempts MAY time out after an implementation default duration, or MAY + /// remain pending until a configured Request timeout or implementation + /// default duration for total request time is reached. /// - /// Only one of Fraction or Percent may be specified. If neither field - /// is specified, 100% of requests will be mirrored. + /// When this field is unspecified, the time to wait between retry attempts + /// is implementation-specific. /// + /// Support: Extended + #[serde(default, skip_serializing_if = "Option::is_none")] + pub backoff: Option, + /// Codes defines the HTTP response status codes for which a backend request + /// should be retried. /// + /// Support: Extended #[serde(default, skip_serializing_if = "Option::is_none")] - pub percent: Option, + pub codes: Option>, } - -/// BackendRef references a resource where mirrored requests are sent. -/// -/// Mirrored requests must be sent only to a single destination endpoint -/// within this BackendRef, irrespective of how many endpoints are present -/// within this BackendRef. -/// -/// If the referent cannot be found, this BackendRef is invalid and must be -/// dropped from the Gateway. The controller must ensure the "ResolvedRefs" -/// condition on the Route status is set to `status: False` and not configure -/// this backend in the underlying implementation. -/// -/// If there is a cross-namespace reference to an *existing* object -/// that is not allowed by a ReferenceGrant, the controller must ensure the -/// "ResolvedRefs" condition on the Route is set to `status: False`, -/// with the "RefNotPermitted" reason and not configure this backend in the -/// underlying implementation. -/// -/// In either error case, the Message of the `ResolvedRefs` Condition -/// should be used to provide more detail about the problem. -/// -/// Support: Extended for Kubernetes Service +/// Timeouts defines the timeouts that can be configured for an HTTP request. /// -/// Support: Implementation-specific for any other resource +/// Support: Extended #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestMirrorBackendRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, -} - -/// Fraction represents the fraction of requests that should be -/// mirrored to BackendRef. -/// -/// Only one of Fraction or Percent may be specified. If neither field -/// is specified, 100% of requests will be mirrored. -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestMirrorFraction { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub denominator: Option, - pub numerator: i32, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirect { - /// Hostname is the hostname to be used in the value of the `Location` - /// header in the response. - /// When empty, the hostname in the `Host` header of the request is used. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines parameters used to modify the path of the incoming request. - /// The modified path is then used to construct the `Location` header. When - /// empty, the request path is used as-is. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, - /// Port is the port to be used in the value of the `Location` - /// header in the response. - /// - /// If no port is specified, the redirect port MUST be derived using the - /// following rules: - /// - /// * If redirect scheme is not-empty, the redirect port MUST be the well-known - /// port associated with the redirect scheme. Specifically "http" to port 80 - /// and "https" to port 443. If the redirect scheme does not have a - /// well-known port, the listener port of the Gateway SHOULD be used. - /// * If redirect scheme is empty, the redirect port MUST be the Gateway - /// Listener port. - /// - /// Implementations SHOULD NOT add the port number in the 'Location' - /// header in the following cases: - /// - /// * A Location header that will use HTTP (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 80. - /// * A Location header that will use HTTPS (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 443. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Scheme is the scheme to be used in the value of the `Location` header in - /// the response. When empty, the scheme of the request is used. - /// - /// Scheme redirects can affect the port of the redirect, for more information, - /// refer to the documentation for the port field of this filter. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, - /// StatusCode is the HTTP status code to be used in response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "statusCode" - )] - pub status_code: Option, -} - -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersRequestRedirectPath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType, -} - -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType { - ReplaceFullPath, - ReplacePrefixMatch, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectScheme { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersRequestRedirectStatusCode { - #[serde(rename = "301")] - r#_301, - #[serde(rename = "302")] - r#_302, -} - -/// ResponseHeaderModifier defines a schema for a filter that modifies response -/// headers. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersResponseHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersType { - RequestHeaderModifier, - ResponseHeaderModifier, - RequestMirror, - RequestRedirect, - #[serde(rename = "URLRewrite")] - UrlRewrite, - ExtensionRef, -} - -/// URLRewrite defines a schema for a filter that modifies a request during forwarding. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersUrlRewrite { - /// Hostname is the value to be used to replace the Host header value during - /// forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines a path rewrite. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, -} - -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesBackendRefsFiltersUrlRewritePath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesBackendRefsFiltersUrlRewritePathType, -} - -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesBackendRefsFiltersUrlRewritePathType { - ReplaceFullPath, - ReplacePrefixMatch, -} - -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFilters { - /// ExtensionRef is an optional, implementation-specific extension to the - /// "filter" behavior. For example, resource "myroutefilter" in group - /// "networking.example.net"). ExtensionRef MUST NOT be used for core and - /// extended filters. - /// - /// This filter can be used multiple times within the same rule. - /// - /// Support: Implementation-specific - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "extensionRef" - )] - pub extension_ref: Option, - /// RequestHeaderModifier defines a schema for a filter that modifies request - /// headers. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestHeaderModifier" - )] - pub request_header_modifier: Option, - /// RequestMirror defines a schema for a filter that mirrors requests. - /// Requests are sent to the specified destination, but responses from - /// that destination are ignored. - /// - /// This filter can be used multiple times within the same rule. Note that - /// not all implementations will be able to support mirroring to multiple - /// backends. - /// - /// Support: Extended - /// - /// - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestMirror" - )] - pub request_mirror: Option, - /// RequestRedirect defines a schema for a filter that responds to the - /// request with an HTTP redirection. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "requestRedirect" - )] - pub request_redirect: Option, - /// ResponseHeaderModifier defines a schema for a filter that modifies response - /// headers. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "responseHeaderModifier" - )] - pub response_header_modifier: Option, - /// Type identifies the type of filter to apply. As with other API fields, - /// types are classified into three conformance levels: - /// - /// - Core: Filter types and their corresponding configuration defined by - /// "Support: Core" in this package, e.g. "RequestHeaderModifier". All - /// implementations must support core filters. - /// - /// - Extended: Filter types and their corresponding configuration defined by - /// "Support: Extended" in this package, e.g. "RequestMirror". Implementers - /// are encouraged to support extended filters. - /// - /// - Implementation-specific: Filters that are defined and supported by - /// specific vendors. - /// In the future, filters showing convergence in behavior across multiple - /// implementations will be considered for inclusion in extended or core - /// conformance levels. Filter-specific configuration for such filters - /// is specified using the ExtensionRef field. `Type` should be set to - /// "ExtensionRef" for custom filters. - /// - /// Implementers are encouraged to define custom implementation types to - /// extend the core API with implementation-specific behavior. - /// - /// If a reference to a custom filter type cannot be resolved, the filter - /// MUST NOT be skipped. Instead, requests that would have been processed by - /// that filter MUST receive a HTTP error response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesFiltersType, - /// URLRewrite defines a schema for a filter that modifies a request during forwarding. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "urlRewrite" - )] - pub url_rewrite: Option, -} - -/// ExtensionRef is an optional, implementation-specific extension to the -/// "filter" behavior. For example, resource "myroutefilter" in group -/// "networking.example.net"). ExtensionRef MUST NOT be used for core and -/// extended filters. -/// -/// This filter can be used multiple times within the same rule. -/// -/// Support: Implementation-specific -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersExtensionRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - pub group: String, - /// Kind is kind of the referent. For example "HTTPRoute" or "Service". - pub kind: String, - /// Name is the name of the referent. - pub name: String, -} - -/// RequestHeaderModifier defines a schema for a filter that modifies request -/// headers. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// RequestMirror defines a schema for a filter that mirrors requests. -/// Requests are sent to the specified destination, but responses from -/// that destination are ignored. -/// -/// This filter can be used multiple times within the same rule. Note that -/// not all implementations will be able to support mirroring to multiple -/// backends. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestMirror { - /// BackendRef references a resource where mirrored requests are sent. - /// - /// Mirrored requests must be sent only to a single destination endpoint - /// within this BackendRef, irrespective of how many endpoints are present - /// within this BackendRef. - /// - /// If the referent cannot be found, this BackendRef is invalid and must be - /// dropped from the Gateway. The controller must ensure the "ResolvedRefs" - /// condition on the Route status is set to `status: False` and not configure - /// this backend in the underlying implementation. - /// - /// If there is a cross-namespace reference to an *existing* object - /// that is not allowed by a ReferenceGrant, the controller must ensure the - /// "ResolvedRefs" condition on the Route is set to `status: False`, - /// with the "RefNotPermitted" reason and not configure this backend in the - /// underlying implementation. - /// - /// In either error case, the Message of the `ResolvedRefs` Condition - /// should be used to provide more detail about the problem. - /// - /// Support: Extended for Kubernetes Service - /// - /// Support: Implementation-specific for any other resource - #[serde(rename = "backendRef")] - pub backend_ref: HTTPRouteRulesFiltersRequestMirrorBackendRef, - /// Fraction represents the fraction of requests that should be - /// mirrored to BackendRef. - /// - /// Only one of Fraction or Percent may be specified. If neither field - /// is specified, 100% of requests will be mirrored. - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub fraction: Option, - /// Percent represents the percentage of requests that should be - /// mirrored to BackendRef. Its minimum value is 0 (indicating 0% of - /// requests) and its maximum value is 100 (indicating 100% of requests). - /// - /// Only one of Fraction or Percent may be specified. If neither field - /// is specified, 100% of requests will be mirrored. - /// - /// - #[serde(default, skip_serializing_if = "Option::is_none")] - pub percent: Option, -} - -/// BackendRef references a resource where mirrored requests are sent. -/// -/// Mirrored requests must be sent only to a single destination endpoint -/// within this BackendRef, irrespective of how many endpoints are present -/// within this BackendRef. -/// -/// If the referent cannot be found, this BackendRef is invalid and must be -/// dropped from the Gateway. The controller must ensure the "ResolvedRefs" -/// condition on the Route status is set to `status: False` and not configure -/// this backend in the underlying implementation. -/// -/// If there is a cross-namespace reference to an *existing* object -/// that is not allowed by a ReferenceGrant, the controller must ensure the -/// "ResolvedRefs" condition on the Route is set to `status: False`, -/// with the "RefNotPermitted" reason and not configure this backend in the -/// underlying implementation. -/// -/// In either error case, the Message of the `ResolvedRefs` Condition -/// should be used to provide more detail about the problem. -/// -/// Support: Extended for Kubernetes Service -/// -/// Support: Implementation-specific for any other resource -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestMirrorBackendRef { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, -} - -/// Fraction represents the fraction of requests that should be -/// mirrored to BackendRef. -/// -/// Only one of Fraction or Percent may be specified. If neither field -/// is specified, 100% of requests will be mirrored. -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestMirrorFraction { - #[serde(default, skip_serializing_if = "Option::is_none")] - pub denominator: Option, - pub numerator: i32, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestRedirect { - /// Hostname is the hostname to be used in the value of the `Location` - /// header in the response. - /// When empty, the hostname in the `Host` header of the request is used. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines parameters used to modify the path of the incoming request. - /// The modified path is then used to construct the `Location` header. When - /// empty, the request path is used as-is. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, - /// Port is the port to be used in the value of the `Location` - /// header in the response. - /// - /// If no port is specified, the redirect port MUST be derived using the - /// following rules: - /// - /// * If redirect scheme is not-empty, the redirect port MUST be the well-known - /// port associated with the redirect scheme. Specifically "http" to port 80 - /// and "https" to port 443. If the redirect scheme does not have a - /// well-known port, the listener port of the Gateway SHOULD be used. - /// * If redirect scheme is empty, the redirect port MUST be the Gateway - /// Listener port. - /// - /// Implementations SHOULD NOT add the port number in the 'Location' - /// header in the following cases: - /// - /// * A Location header that will use HTTP (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 80. - /// * A Location header that will use HTTPS (whether that is determined via - /// the Listener protocol or the Scheme field) _and_ use port 443. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Scheme is the scheme to be used in the value of the `Location` header in - /// the response. When empty, the scheme of the request is used. - /// - /// Scheme redirects can affect the port of the redirect, for more information, - /// refer to the documentation for the port field of this filter. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub scheme: Option, - /// StatusCode is the HTTP status code to be used in response. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "statusCode" - )] - pub status_code: Option, -} - -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersRequestRedirectPath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesFiltersRequestRedirectPathType, -} - -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersRequestRedirectPathType { - ReplaceFullPath, - ReplacePrefixMatch, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersRequestRedirectScheme { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, -} - -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersRequestRedirectStatusCode { - #[serde(rename = "301")] - r#_301, - #[serde(rename = "302")] - r#_302, -} - -/// ResponseHeaderModifier defines a schema for a filter that modifies response -/// headers. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersResponseHeaderModifier { - /// Add adds the given header(s) (name, value) to the request - /// before the action. It appends to any existing values associated - /// with the header name. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// add: - /// - name: "my-header" - /// value: "bar,baz" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: foo,bar,baz - #[serde(default, skip_serializing_if = "Option::is_none")] - pub add: Option>, - /// Remove the given header(s) from the HTTP request before the action. The - /// value of Remove is a list of HTTP header names. Note that the header - /// names are case-insensitive (see - /// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header1: foo - /// my-header2: bar - /// my-header3: baz - /// - /// Config: - /// remove: ["my-header1", "my-header3"] - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header2: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub remove: Option>, - /// Set overwrites the request with the given header (name, value) - /// before the action. - /// - /// Input: - /// GET /foo HTTP/1.1 - /// my-header: foo - /// - /// Config: - /// set: - /// - name: "my-header" - /// value: "bar" - /// - /// Output: - /// GET /foo HTTP/1.1 - /// my-header: bar - #[serde(default, skip_serializing_if = "Option::is_none")] - pub set: Option>, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersResponseHeaderModifierAdd { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersResponseHeaderModifierSet { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, the first entry with - /// an equivalent name MUST be considered for a match. Subsequent entries - /// with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - pub name: String, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersType { - RequestHeaderModifier, - ResponseHeaderModifier, - RequestMirror, - RequestRedirect, - #[serde(rename = "URLRewrite")] - UrlRewrite, - ExtensionRef, -} - -/// URLRewrite defines a schema for a filter that modifies a request during forwarding. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersUrlRewrite { - /// Hostname is the value to be used to replace the Host header value during - /// forwarding. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub hostname: Option, - /// Path defines a path rewrite. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, -} - -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesFiltersUrlRewritePath { - /// ReplaceFullPath specifies the value with which to replace the full path - /// of a request during a rewrite or redirect. - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replaceFullPath" - )] - pub replace_full_path: Option, - /// ReplacePrefixMatch specifies the value with which to replace the prefix - /// match of a request during a rewrite or redirect. For example, a request - /// to "/foo/bar" with a prefix match of "/foo" and a ReplacePrefixMatch - /// of "/xyz" would be modified to "/xyz/bar". - /// - /// Note that this matches the behavior of the PathPrefix match type. This - /// matches full path elements. A path element refers to the list of labels - /// in the path split by the `/` separator. When specified, a trailing `/` is - /// ignored. For example, the paths `/abc`, `/abc/`, and `/abc/def` would all - /// match the prefix `/abc`, but the path `/abcd` would not. - /// - /// ReplacePrefixMatch is only compatible with a `PathPrefix` HTTPRouteMatch. - /// Using any other HTTPRouteMatch type on the same HTTPRouteRule will result in - /// the implementation setting the Accepted Condition for the Route to `status: False`. - /// - /// Request Path | Prefix Match | Replace Prefix | Modified Path - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "replacePrefixMatch" - )] - pub replace_prefix_match: Option, - /// Type defines the type of path modifier. Additional types may be - /// added in a future release of the API. - /// - /// Note that values may be added to this enum, implementations - /// must ensure that unknown values will not cause a crash. - /// - /// Unknown values here must result in the implementation setting the - /// Accepted Condition for the Route to `status: False`, with a - /// Reason of `UnsupportedValue`. - #[serde(rename = "type")] - pub r#type: HTTPRouteRulesFiltersUrlRewritePathType, -} - -/// Path defines a path rewrite. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesFiltersUrlRewritePathType { - ReplaceFullPath, - ReplacePrefixMatch, -} - -/// HTTPRouteMatch defines the predicate used to match requests to a given -/// action. Multiple match types are ANDed together, i.e. the match will -/// evaluate to true only if all conditions are satisfied. -/// -/// For example, the match below will match a HTTP request only if its path -/// starts with `/foo` AND it contains the `version: v1` header: -/// -/// ```text -/// match: -/// -/// path: -/// value: "/foo" -/// headers: -/// - name: "version" -/// value "v1" -/// -/// ``` -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatches { - /// Headers specifies HTTP request header matchers. Multiple match values are - /// ANDed together, meaning, a request must match all the specified headers - /// to select the route. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub headers: Option>, - /// Method specifies HTTP method matcher. - /// When specified, this route will be matched only if the request has the - /// specified method. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub method: Option, - /// Path specifies a HTTP request path matcher. If this field is not - /// specified, a default prefix match on the "/" path is provided. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub path: Option, - /// QueryParams specifies HTTP query parameter matchers. Multiple match - /// values are ANDed together, meaning, a request must match all the - /// specified query parameters to select the route. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "queryParams" - )] - pub query_params: Option>, -} - -/// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatchesHeaders { - /// Name is the name of the HTTP Header to be matched. Name matching MUST be - /// case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). - /// - /// If multiple entries specify equivalent header names, only the first - /// entry with an equivalent name MUST be considered for a match. Subsequent - /// entries with an equivalent header name MUST be ignored. Due to the - /// case-insensitivity of header names, "foo" and "Foo" are considered - /// equivalent. - /// - /// When a header is repeated in an HTTP request, it is - /// implementation-specific behavior as to how this is represented. - /// Generally, proxies should follow the guidance from the RFC: - /// https://www.rfc-editor.org/rfc/rfc7230.html#section-3.2.2 regarding - /// processing a repeated header, with special handling for "Set-Cookie". - pub name: String, - /// Type specifies how to match against the value of the header. - /// - /// Support: Core (Exact) - /// - /// Support: Implementation-specific (RegularExpression) - /// - /// Since RegularExpression HeaderMatchType has implementation-specific - /// conformance, implementations can support POSIX, PCRE or any other dialects - /// of regular expressions. Please read the implementation's documentation to - /// determine the supported dialect. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value is the value of HTTP Header to be matched. - pub value: String, -} - -/// HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request -/// headers. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesHeadersType { - Exact, - RegularExpression, -} - -/// HTTPRouteMatch defines the predicate used to match requests to a given -/// action. Multiple match types are ANDed together, i.e. the match will -/// evaluate to true only if all conditions are satisfied. -/// -/// For example, the match below will match a HTTP request only if its path -/// starts with `/foo` AND it contains the `version: v1` header: -/// -/// ```text -/// match: -/// -/// path: -/// value: "/foo" -/// headers: -/// - name: "version" -/// value "v1" -/// -/// ``` -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesMethod { - #[serde(rename = "GET")] - Get, - #[serde(rename = "HEAD")] - Head, - #[serde(rename = "POST")] - Post, - #[serde(rename = "PUT")] - Put, - #[serde(rename = "DELETE")] - Delete, - #[serde(rename = "CONNECT")] - Connect, - #[serde(rename = "OPTIONS")] - Options, - #[serde(rename = "TRACE")] - Trace, - #[serde(rename = "PATCH")] - Patch, -} - -/// Path specifies a HTTP request path matcher. If this field is not -/// specified, a default prefix match on the "/" path is provided. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatchesPath { - /// Type specifies how to match against the path Value. - /// - /// Support: Core (Exact, PathPrefix) - /// - /// Support: Implementation-specific (RegularExpression) - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value of the HTTP path to match against. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub value: Option, -} - -/// Path specifies a HTTP request path matcher. If this field is not -/// specified, a default prefix match on the "/" path is provided. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesPathType { - Exact, - PathPrefix, - RegularExpression, -} - -/// HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP -/// query parameters. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesMatchesQueryParams { - /// Name is the name of the HTTP query param to be matched. This must be an - /// exact string match. (See - /// https://tools.ietf.org/html/rfc7230#section-2.7.3). - /// - /// If multiple entries specify equivalent query param names, only the first - /// entry with an equivalent name MUST be considered for a match. Subsequent - /// entries with an equivalent query param name MUST be ignored. - /// - /// If a query param is repeated in an HTTP request, the behavior is - /// purposely left undefined, since different data planes have different - /// capabilities. However, it is *recommended* that implementations should - /// match against the first value of the param if the data plane supports it, - /// as this behavior is expected in other load balancing contexts outside of - /// the Gateway API. - /// - /// Users SHOULD NOT route traffic based on repeated query params to guard - /// themselves against potential differences in the implementations. - pub name: String, - /// Type specifies how to match against the value of the query parameter. - /// - /// Support: Extended (Exact) - /// - /// Support: Implementation-specific (RegularExpression) - /// - /// Since RegularExpression QueryParamMatchType has Implementation-specific - /// conformance, implementations can support POSIX, PCRE or any other - /// dialects of regular expressions. Please read the implementation's - /// documentation to determine the supported dialect. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, - /// Value is the value of HTTP query param to be matched. - pub value: String, -} - -/// HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP -/// query parameters. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesMatchesQueryParamsType { - Exact, - RegularExpression, -} - -/// Retry defines the configuration for when to retry an HTTP request. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesRetry { - /// Attempts specifies the maxmimum number of times an individual request - /// from the gateway to a backend should be retried. - /// - /// If the maximum number of retries has been attempted without a successful - /// response from the backend, the Gateway MUST return an error. - /// - /// When this field is unspecified, the number of times to attempt to retry - /// a backend request is implementation-specific. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub attempts: Option, - /// Backoff specifies the minimum duration a Gateway should wait between - /// retry attempts and is represented in Gateway API Duration formatting. - /// - /// For example, setting the `rules[].retry.backoff` field to the value - /// `100ms` will cause a backend request to first be retried approximately - /// 100 milliseconds after timing out or receiving a response code configured - /// to be retryable. - /// - /// An implementation MAY use an exponential or alternative backoff strategy - /// for subsequent retry attempts, MAY cap the maximum backoff duration to - /// some amount greater than the specified minimum, and MAY add arbitrary - /// jitter to stagger requests, as long as unsuccessful backend requests are - /// not retried before the configured minimum duration. - /// - /// If a Request timeout (`rules[].timeouts.request`) is configured on the - /// route, the entire duration of the initial request and any retry attempts - /// MUST not exceed the Request timeout duration. If any retry attempts are - /// still in progress when the Request timeout duration has been reached, - /// these SHOULD be canceled if possible and the Gateway MUST immediately - /// return a timeout error. - /// - /// If a BackendRequest timeout (`rules[].timeouts.backendRequest`) is - /// configured on the route, any retry attempts which reach the configured - /// BackendRequest timeout duration without a response SHOULD be canceled if - /// possible and the Gateway should wait for at least the specified backoff - /// duration before attempting to retry the backend request again. - /// - /// If a BackendRequest timeout is _not_ configured on the route, retry - /// attempts MAY time out after an implementation default duration, or MAY - /// remain pending until a configured Request timeout or implementation - /// default duration for total request time is reached. - /// - /// When this field is unspecified, the time to wait between retry attempts - /// is implementation-specific. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub backoff: Option, - /// Codes defines the HTTP response status codes for which a backend request - /// should be retried. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub codes: Option>, -} - -/// SessionPersistence defines and configures session persistence -/// for the route rule. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesSessionPersistence { - /// AbsoluteTimeout defines the absolute timeout of the persistent - /// session. Once the AbsoluteTimeout duration has elapsed, the - /// session becomes invalid. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "absoluteTimeout" - )] - pub absolute_timeout: Option, - /// CookieConfig provides configuration settings that are specific - /// to cookie-based session persistence. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "cookieConfig" - )] - pub cookie_config: Option, - /// IdleTimeout defines the idle timeout of the persistent session. - /// Once the session has been idle for more than the specified - /// IdleTimeout duration, the session becomes invalid. - /// - /// Support: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "idleTimeout" - )] - pub idle_timeout: Option, - /// SessionName defines the name of the persistent session token - /// which may be reflected in the cookie or the header. Users - /// should avoid reusing session names to prevent unintended - /// consequences, such as rejection or unpredictable behavior. - /// - /// Support: Implementation-specific - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sessionName" - )] - pub session_name: Option, - /// Type defines the type of session persistence such as through - /// the use a header or cookie. Defaults to cookie based session - /// persistence. - /// - /// Support: Core for "Cookie" type - /// - /// Support: Extended for "Header" type - #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")] - pub r#type: Option, -} - -/// CookieConfig provides configuration settings that are specific -/// to cookie-based session persistence. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesSessionPersistenceCookieConfig { - /// LifetimeType specifies whether the cookie has a permanent or - /// session-based lifetime. A permanent cookie persists until its - /// specified expiry time, defined by the Expires or Max-Age cookie - /// attributes, while a session cookie is deleted when the current - /// session ends. - /// - /// When set to "Permanent", AbsoluteTimeout indicates the - /// cookie's lifetime via the Expires or Max-Age cookie attributes - /// and is required. - /// - /// When set to "Session", AbsoluteTimeout indicates the - /// absolute lifetime of the cookie tracked by the gateway and - /// is optional. - /// - /// Support: Core for "Session" type - /// - /// Support: Extended for "Permanent" type - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "lifetimeType" - )] - pub lifetime_type: Option, -} - -/// CookieConfig provides configuration settings that are specific -/// to cookie-based session persistence. -/// -/// Support: Core -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesSessionPersistenceCookieConfigLifetimeType { - Permanent, - Session, -} - -/// SessionPersistence defines and configures session persistence -/// for the route rule. -/// -/// Support: Extended -/// -/// -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] -pub enum HTTPRouteRulesSessionPersistenceType { - Cookie, - Header, -} - -/// Timeouts defines the timeouts that can be configured for an HTTP request. -/// -/// Support: Extended -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteRulesTimeouts { +pub struct HTTPRouteTimeout { /// BackendRequest specifies a timeout for an individual request from the gateway /// to a backend. This covers the time from when the request first starts being /// sent from the gateway to when the full response has been received from the backend. @@ -2416,183 +645,3 @@ pub struct HTTPRouteRulesTimeouts { #[serde(default, skip_serializing_if = "Option::is_none")] pub request: Option, } - -/// Status defines the current state of HTTPRoute. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteStatus { - /// Parents is a list of parent resources (usually Gateways) that are - /// associated with the route, and the status of the route with respect to - /// each parent. When this route attaches to a parent, the controller that - /// manages the parent must add an entry to this list when the controller - /// first sees the route and should update the entry as appropriate when the - /// route or gateway is modified. - /// - /// Note that parent references that cannot be resolved by an implementation - /// of this API will not be added to this list. Implementations of this API - /// can only populate Route status for the Gateways/parent resources they are - /// responsible for. - /// - /// A maximum of 32 Gateways will be represented in this list. An empty list - /// means the route has not been attached to any Gateway. - pub parents: Vec, -} - -/// RouteParentStatus describes the status of a route with respect to an -/// associated Parent. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteStatusParents { - /// Conditions describes the status of the route with respect to the Gateway. - /// Note that the route's availability is also subject to the Gateway's own - /// status conditions and listener status. - /// - /// If the Route's ParentRef specifies an existing Gateway that supports - /// Routes of this kind AND that Gateway's controller has sufficient access, - /// then that Gateway's controller MUST set the "Accepted" condition on the - /// Route, to indicate whether the route has been accepted or rejected by the - /// Gateway, and why. - /// - /// A Route MUST be considered "Accepted" if at least one of the Route's - /// rules is implemented by the Gateway. - /// - /// There are a number of cases where the "Accepted" condition may not be set - /// due to lack of controller visibility, that includes when: - /// - /// * The Route refers to a non-existent parent. - /// * The Route is of a type that the controller does not support. - /// * The Route is in a namespace the controller does not have access to. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// ControllerName is a domain/path string that indicates the name of the - /// controller that wrote this status. This corresponds with the - /// controllerName field on GatewayClass. - /// - /// Example: "example.net/gateway-controller". - /// - /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are - /// valid Kubernetes names - /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). - /// - /// Controllers MUST populate this field when writing status. Controllers should ensure that - /// entries to status populated with their ControllerName are cleaned up when they are no - /// longer necessary. - #[serde(rename = "controllerName")] - pub controller_name: String, - /// ParentRef corresponds with a ParentRef in the spec that this - /// RouteParentStatus struct describes the status of. - #[serde(rename = "parentRef")] - pub parent_ref: HTTPRouteStatusParentsParentRef, -} - -/// ParentRef corresponds with a ParentRef in the spec that this -/// RouteParentStatus struct describes the status of. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct HTTPRouteStatusParentsParentRef { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, -} diff --git a/gateway-api/src/apis/experimental/mod.rs b/gateway-api/src/apis/experimental/mod.rs index 2c13095..67cff9c 100644 --- a/gateway-api/src/apis/experimental/mod.rs +++ b/gateway-api/src/apis/experimental/mod.rs @@ -1,6 +1,8 @@ -// WARNING! generated file do not edit +// WARNING: generated file - manual changes will be overriden + +pub mod common; pub mod constants; -mod enum_defaults; +pub mod enum_defaults; pub mod gatewayclasses; pub mod gateways; pub mod grpcroutes; diff --git a/gateway-api/src/apis/experimental/referencegrants.rs b/gateway-api/src/apis/experimental/referencegrants.rs index a383a35..70f0bbc 100644 --- a/gateway-api/src/apis/experimental/referencegrants.rs +++ b/gateway-api/src/apis/experimental/referencegrants.rs @@ -1,6 +1,4 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.2 +// WARNING: generated file - manual changes will be overriden #[allow(unused_imports)] mod prelude { @@ -9,7 +7,6 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of ReferenceGrant. #[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( @@ -37,7 +34,6 @@ pub struct ReferenceGrantSpec { /// Support: Core pub to: Vec, } - /// ReferenceGrantFrom describes trusted namespaces and kinds. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct ReferenceGrantFrom { @@ -67,7 +63,6 @@ pub struct ReferenceGrantFrom { /// Support: Core pub namespace: String, } - /// ReferenceGrantTo describes what Kinds are allowed as targets of the /// references. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] diff --git a/gateway-api/src/apis/experimental/tcproutes.rs b/gateway-api/src/apis/experimental/tcproutes.rs index 9342e6b..dea5e1e 100644 --- a/gateway-api/src/apis/experimental/tcproutes.rs +++ b/gateway-api/src/apis/experimental/tcproutes.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.2 +// WARNING: generated file - manual changes will be overriden +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -10,7 +9,6 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of TCPRoute. #[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( @@ -20,7 +18,7 @@ use self::prelude::*; plural = "tcproutes" )] #[kube(namespaced)] -#[kube(status = "TCPRouteStatus")] +#[kube(status = "RouteStatus")] #[kube(derive = "Default")] #[kube(derive = "PartialEq")] pub struct TCPRouteSpec { @@ -96,431 +94,9 @@ pub struct TCPRouteSpec { skip_serializing_if = "Option::is_none", rename = "parentRefs" )] - pub parent_refs: Option>, + pub parent_refs: Option>, /// Rules are a list of TCP matchers and actions. /// /// - pub rules: Vec, -} - -/// ParentReference identifies an API object (usually a Gateway) that can be considered -/// a parent of this resource (usually a route). There are two kinds of parent resources -/// with "Core" support: -/// -/// * Gateway (Gateway conformance profile) -/// * Service (Mesh conformance profile, ClusterIP Services only) -/// -/// This API may be extended in the future to support additional kinds of parent -/// resources. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TCPRouteParentRefs { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, -} - -/// TCPRouteRule is the configuration for a given rule. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TCPRouteRules { - /// BackendRefs defines the backend(s) where matching requests should be - /// sent. If unspecified or invalid (refers to a non-existent resource or a - /// Service with no endpoints), the underlying implementation MUST actively - /// reject connection attempts to this backend. Connection rejections must - /// respect weight; if an invalid backend is requested to have 80% of - /// connections, then 80% of connections must be rejected instead. - /// - /// Support: Core for Kubernetes Service - /// - /// Support: Extended for Kubernetes ServiceImport - /// - /// Support: Implementation-specific for any other resource - /// - /// Support for weight: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "backendRefs" - )] - pub backend_refs: Option>, - /// Name is the name of the route rule. This name MUST be unique within a Route if it is set. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub name: Option, -} - -/// BackendRef defines how a Route should forward a request to a Kubernetes -/// resource. -/// -/// Note that when a namespace different than the local namespace is specified, a -/// ReferenceGrant object is required in the referent namespace to allow that -/// namespace's owner to accept the reference. See the ReferenceGrant -/// documentation for details. -/// -/// -/// -/// When the BackendRef points to a Kubernetes Service, implementations SHOULD -/// honor the appProtocol field if it is set for the target Service Port. -/// -/// Implementations supporting appProtocol SHOULD recognize the Kubernetes -/// Standard Application Protocols defined in KEP-3726. -/// -/// If a Service appProtocol isn't specified, an implementation MAY infer the -/// backend protocol through its own means. Implementations MAY infer the -/// protocol from the Route type referring to the backend Service. -/// -/// If a Route is not able to send traffic to the backend using the specified -/// protocol then the backend is considered invalid. Implementations MUST set the -/// "ResolvedRefs" condition to "False" with the "UnsupportedProtocol" reason. -/// -/// -/// -/// Note that when the BackendTLSPolicy object is enabled by the implementation, -/// there are some extra rules about validity to consider here. See the fields -/// where this struct is used for more information about the exact behavior. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TCPRouteRulesBackendRefs { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Weight specifies the proportion of requests forwarded to the referenced - /// backend. This is computed as weight/(sum of all weights in this - /// BackendRefs list). For non-zero values, there may be some epsilon from - /// the exact proportion defined here depending on the precision an - /// implementation supports. Weight is not a percentage and the sum of - /// weights does not need to equal 100. - /// - /// If only one backend is specified and it has a weight greater than 0, 100% - /// of the traffic is forwarded to that backend. If weight is set to 0, no - /// traffic should be forwarded for this entry. If unspecified, weight - /// defaults to 1. - /// - /// Support for this field varies based on the context where used. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub weight: Option, -} - -/// Status defines the current state of TCPRoute. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TCPRouteStatus { - /// Parents is a list of parent resources (usually Gateways) that are - /// associated with the route, and the status of the route with respect to - /// each parent. When this route attaches to a parent, the controller that - /// manages the parent must add an entry to this list when the controller - /// first sees the route and should update the entry as appropriate when the - /// route or gateway is modified. - /// - /// Note that parent references that cannot be resolved by an implementation - /// of this API will not be added to this list. Implementations of this API - /// can only populate Route status for the Gateways/parent resources they are - /// responsible for. - /// - /// A maximum of 32 Gateways will be represented in this list. An empty list - /// means the route has not been attached to any Gateway. - pub parents: Vec, -} - -/// RouteParentStatus describes the status of a route with respect to an -/// associated Parent. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TCPRouteStatusParents { - /// Conditions describes the status of the route with respect to the Gateway. - /// Note that the route's availability is also subject to the Gateway's own - /// status conditions and listener status. - /// - /// If the Route's ParentRef specifies an existing Gateway that supports - /// Routes of this kind AND that Gateway's controller has sufficient access, - /// then that Gateway's controller MUST set the "Accepted" condition on the - /// Route, to indicate whether the route has been accepted or rejected by the - /// Gateway, and why. - /// - /// A Route MUST be considered "Accepted" if at least one of the Route's - /// rules is implemented by the Gateway. - /// - /// There are a number of cases where the "Accepted" condition may not be set - /// due to lack of controller visibility, that includes when: - /// - /// * The Route refers to a non-existent parent. - /// * The Route is of a type that the controller does not support. - /// * The Route is in a namespace the controller does not have access to. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// ControllerName is a domain/path string that indicates the name of the - /// controller that wrote this status. This corresponds with the - /// controllerName field on GatewayClass. - /// - /// Example: "example.net/gateway-controller". - /// - /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are - /// valid Kubernetes names - /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). - /// - /// Controllers MUST populate this field when writing status. Controllers should ensure that - /// entries to status populated with their ControllerName are cleaned up when they are no - /// longer necessary. - #[serde(rename = "controllerName")] - pub controller_name: String, - /// ParentRef corresponds with a ParentRef in the spec that this - /// RouteParentStatus struct describes the status of. - #[serde(rename = "parentRef")] - pub parent_ref: TCPRouteStatusParentsParentRef, -} - -/// ParentRef corresponds with a ParentRef in the spec that this -/// RouteParentStatus struct describes the status of. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TCPRouteStatusParentsParentRef { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, + pub rules: Vec, } diff --git a/gateway-api/src/apis/experimental/tlsroutes.rs b/gateway-api/src/apis/experimental/tlsroutes.rs index fed8e98..397fc3b 100644 --- a/gateway-api/src/apis/experimental/tlsroutes.rs +++ b/gateway-api/src/apis/experimental/tlsroutes.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.2 +// WARNING: generated file - manual changes will be overriden +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -10,7 +9,6 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of TLSRoute. #[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( @@ -20,7 +18,7 @@ use self::prelude::*; plural = "tlsroutes" )] #[kube(namespaced)] -#[kube(status = "TLSRouteStatus")] +#[kube(status = "RouteStatus")] #[kube(derive = "Default")] #[kube(derive = "PartialEq")] pub struct TLSRouteSpec { @@ -131,434 +129,9 @@ pub struct TLSRouteSpec { skip_serializing_if = "Option::is_none", rename = "parentRefs" )] - pub parent_refs: Option>, + pub parent_refs: Option>, /// Rules are a list of TLS matchers and actions. /// /// - pub rules: Vec, -} - -/// ParentReference identifies an API object (usually a Gateway) that can be considered -/// a parent of this resource (usually a route). There are two kinds of parent resources -/// with "Core" support: -/// -/// * Gateway (Gateway conformance profile) -/// * Service (Mesh conformance profile, ClusterIP Services only) -/// -/// This API may be extended in the future to support additional kinds of parent -/// resources. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TLSRouteParentRefs { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, -} - -/// TLSRouteRule is the configuration for a given rule. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TLSRouteRules { - /// BackendRefs defines the backend(s) where matching requests should be - /// sent. If unspecified or invalid (refers to a non-existent resource or - /// a Service with no endpoints), the rule performs no forwarding; if no - /// filters are specified that would result in a response being sent, the - /// underlying implementation must actively reject request attempts to this - /// backend, by rejecting the connection or returning a 500 status code. - /// Request rejections must respect weight; if an invalid backend is - /// requested to have 80% of requests, then 80% of requests must be rejected - /// instead. - /// - /// Support: Core for Kubernetes Service - /// - /// Support: Extended for Kubernetes ServiceImport - /// - /// Support: Implementation-specific for any other resource - /// - /// Support for weight: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "backendRefs" - )] - pub backend_refs: Option>, - /// Name is the name of the route rule. This name MUST be unique within a Route if it is set. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub name: Option, -} - -/// BackendRef defines how a Route should forward a request to a Kubernetes -/// resource. -/// -/// Note that when a namespace different than the local namespace is specified, a -/// ReferenceGrant object is required in the referent namespace to allow that -/// namespace's owner to accept the reference. See the ReferenceGrant -/// documentation for details. -/// -/// -/// -/// When the BackendRef points to a Kubernetes Service, implementations SHOULD -/// honor the appProtocol field if it is set for the target Service Port. -/// -/// Implementations supporting appProtocol SHOULD recognize the Kubernetes -/// Standard Application Protocols defined in KEP-3726. -/// -/// If a Service appProtocol isn't specified, an implementation MAY infer the -/// backend protocol through its own means. Implementations MAY infer the -/// protocol from the Route type referring to the backend Service. -/// -/// If a Route is not able to send traffic to the backend using the specified -/// protocol then the backend is considered invalid. Implementations MUST set the -/// "ResolvedRefs" condition to "False" with the "UnsupportedProtocol" reason. -/// -/// -/// -/// Note that when the BackendTLSPolicy object is enabled by the implementation, -/// there are some extra rules about validity to consider here. See the fields -/// where this struct is used for more information about the exact behavior. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TLSRouteRulesBackendRefs { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Weight specifies the proportion of requests forwarded to the referenced - /// backend. This is computed as weight/(sum of all weights in this - /// BackendRefs list). For non-zero values, there may be some epsilon from - /// the exact proportion defined here depending on the precision an - /// implementation supports. Weight is not a percentage and the sum of - /// weights does not need to equal 100. - /// - /// If only one backend is specified and it has a weight greater than 0, 100% - /// of the traffic is forwarded to that backend. If weight is set to 0, no - /// traffic should be forwarded for this entry. If unspecified, weight - /// defaults to 1. - /// - /// Support for this field varies based on the context where used. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub weight: Option, -} - -/// Status defines the current state of TLSRoute. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TLSRouteStatus { - /// Parents is a list of parent resources (usually Gateways) that are - /// associated with the route, and the status of the route with respect to - /// each parent. When this route attaches to a parent, the controller that - /// manages the parent must add an entry to this list when the controller - /// first sees the route and should update the entry as appropriate when the - /// route or gateway is modified. - /// - /// Note that parent references that cannot be resolved by an implementation - /// of this API will not be added to this list. Implementations of this API - /// can only populate Route status for the Gateways/parent resources they are - /// responsible for. - /// - /// A maximum of 32 Gateways will be represented in this list. An empty list - /// means the route has not been attached to any Gateway. - pub parents: Vec, -} - -/// RouteParentStatus describes the status of a route with respect to an -/// associated Parent. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TLSRouteStatusParents { - /// Conditions describes the status of the route with respect to the Gateway. - /// Note that the route's availability is also subject to the Gateway's own - /// status conditions and listener status. - /// - /// If the Route's ParentRef specifies an existing Gateway that supports - /// Routes of this kind AND that Gateway's controller has sufficient access, - /// then that Gateway's controller MUST set the "Accepted" condition on the - /// Route, to indicate whether the route has been accepted or rejected by the - /// Gateway, and why. - /// - /// A Route MUST be considered "Accepted" if at least one of the Route's - /// rules is implemented by the Gateway. - /// - /// There are a number of cases where the "Accepted" condition may not be set - /// due to lack of controller visibility, that includes when: - /// - /// * The Route refers to a non-existent parent. - /// * The Route is of a type that the controller does not support. - /// * The Route is in a namespace the controller does not have access to. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// ControllerName is a domain/path string that indicates the name of the - /// controller that wrote this status. This corresponds with the - /// controllerName field on GatewayClass. - /// - /// Example: "example.net/gateway-controller". - /// - /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are - /// valid Kubernetes names - /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). - /// - /// Controllers MUST populate this field when writing status. Controllers should ensure that - /// entries to status populated with their ControllerName are cleaned up when they are no - /// longer necessary. - #[serde(rename = "controllerName")] - pub controller_name: String, - /// ParentRef corresponds with a ParentRef in the spec that this - /// RouteParentStatus struct describes the status of. - #[serde(rename = "parentRef")] - pub parent_ref: TLSRouteStatusParentsParentRef, -} - -/// ParentRef corresponds with a ParentRef in the spec that this -/// RouteParentStatus struct describes the status of. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct TLSRouteStatusParentsParentRef { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, + pub rules: Vec, } diff --git a/gateway-api/src/apis/experimental/udproutes.rs b/gateway-api/src/apis/experimental/udproutes.rs index b531c7e..85b5d1b 100644 --- a/gateway-api/src/apis/experimental/udproutes.rs +++ b/gateway-api/src/apis/experimental/udproutes.rs @@ -1,7 +1,6 @@ -// WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - -// kopium version: 0.21.2 +// WARNING: generated file - manual changes will be overriden +use super::common::*; #[allow(unused_imports)] mod prelude { pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; @@ -10,7 +9,6 @@ mod prelude { pub use serde::{Deserialize, Serialize}; } use self::prelude::*; - /// Spec defines the desired state of UDPRoute. #[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( @@ -20,7 +18,7 @@ use self::prelude::*; plural = "udproutes" )] #[kube(namespaced)] -#[kube(status = "UDPRouteStatus")] +#[kube(status = "RouteStatus")] #[kube(derive = "Default")] #[kube(derive = "PartialEq")] pub struct UDPRouteSpec { @@ -96,431 +94,9 @@ pub struct UDPRouteSpec { skip_serializing_if = "Option::is_none", rename = "parentRefs" )] - pub parent_refs: Option>, + pub parent_refs: Option>, /// Rules are a list of UDP matchers and actions. /// /// - pub rules: Vec, -} - -/// ParentReference identifies an API object (usually a Gateway) that can be considered -/// a parent of this resource (usually a route). There are two kinds of parent resources -/// with "Core" support: -/// -/// * Gateway (Gateway conformance profile) -/// * Service (Mesh conformance profile, ClusterIP Services only) -/// -/// This API may be extended in the future to support additional kinds of parent -/// resources. -/// -/// The API object must be valid in the cluster; the Group and Kind must -/// be registered in the cluster for this reference to be valid. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct UDPRouteParentRefs { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, -} - -/// UDPRouteRule is the configuration for a given rule. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct UDPRouteRules { - /// BackendRefs defines the backend(s) where matching requests should be - /// sent. If unspecified or invalid (refers to a non-existent resource or a - /// Service with no endpoints), the underlying implementation MUST actively - /// reject connection attempts to this backend. Packet drops must - /// respect weight; if an invalid backend is requested to have 80% of - /// the packets, then 80% of packets must be dropped instead. - /// - /// Support: Core for Kubernetes Service - /// - /// Support: Extended for Kubernetes ServiceImport - /// - /// Support: Implementation-specific for any other resource - /// - /// Support for weight: Extended - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "backendRefs" - )] - pub backend_refs: Option>, - /// Name is the name of the route rule. This name MUST be unique within a Route if it is set. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub name: Option, -} - -/// BackendRef defines how a Route should forward a request to a Kubernetes -/// resource. -/// -/// Note that when a namespace different than the local namespace is specified, a -/// ReferenceGrant object is required in the referent namespace to allow that -/// namespace's owner to accept the reference. See the ReferenceGrant -/// documentation for details. -/// -/// -/// -/// When the BackendRef points to a Kubernetes Service, implementations SHOULD -/// honor the appProtocol field if it is set for the target Service Port. -/// -/// Implementations supporting appProtocol SHOULD recognize the Kubernetes -/// Standard Application Protocols defined in KEP-3726. -/// -/// If a Service appProtocol isn't specified, an implementation MAY infer the -/// backend protocol through its own means. Implementations MAY infer the -/// protocol from the Route type referring to the backend Service. -/// -/// If a Route is not able to send traffic to the backend using the specified -/// protocol then the backend is considered invalid. Implementations MUST set the -/// "ResolvedRefs" condition to "False" with the "UnsupportedProtocol" reason. -/// -/// -/// -/// Note that when the BackendTLSPolicy object is enabled by the implementation, -/// there are some extra rules about validity to consider here. See the fields -/// where this struct is used for more information about the exact behavior. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct UDPRouteRulesBackendRefs { - /// Group is the group of the referent. For example, "gateway.networking.k8s.io". - /// When unspecified or empty string, core API group is inferred. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is the Kubernetes resource kind of the referent. For example - /// "Service". - /// - /// Defaults to "Service" when not specified. - /// - /// ExternalName services can refer to CNAME DNS records that may live - /// outside of the cluster and as such are difficult to reason about in - /// terms of conformance. They also may not be safe to forward to (see - /// CVE-2021-25740 for more information). Implementations SHOULD NOT - /// support ExternalName Services. - /// - /// Support: Core (Services with a type other than ExternalName) - /// - /// Support: Implementation-specific (Services with type ExternalName) - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - pub name: String, - /// Namespace is the namespace of the backend. When unspecified, the local - /// namespace is inferred. - /// - /// Note that when a namespace different than the local namespace is specified, - /// a ReferenceGrant object is required in the referent namespace to allow that - /// namespace's owner to accept the reference. See the ReferenceGrant - /// documentation for details. - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port specifies the destination port number to use for this resource. - /// Port is required when the referent is a Kubernetes Service. In this - /// case, the port number is the service port number, not the target port. - /// For other resources, destination port might be derived from the referent - /// resource or this field. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// Weight specifies the proportion of requests forwarded to the referenced - /// backend. This is computed as weight/(sum of all weights in this - /// BackendRefs list). For non-zero values, there may be some epsilon from - /// the exact proportion defined here depending on the precision an - /// implementation supports. Weight is not a percentage and the sum of - /// weights does not need to equal 100. - /// - /// If only one backend is specified and it has a weight greater than 0, 100% - /// of the traffic is forwarded to that backend. If weight is set to 0, no - /// traffic should be forwarded for this entry. If unspecified, weight - /// defaults to 1. - /// - /// Support for this field varies based on the context where used. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub weight: Option, -} - -/// Status defines the current state of UDPRoute. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct UDPRouteStatus { - /// Parents is a list of parent resources (usually Gateways) that are - /// associated with the route, and the status of the route with respect to - /// each parent. When this route attaches to a parent, the controller that - /// manages the parent must add an entry to this list when the controller - /// first sees the route and should update the entry as appropriate when the - /// route or gateway is modified. - /// - /// Note that parent references that cannot be resolved by an implementation - /// of this API will not be added to this list. Implementations of this API - /// can only populate Route status for the Gateways/parent resources they are - /// responsible for. - /// - /// A maximum of 32 Gateways will be represented in this list. An empty list - /// means the route has not been attached to any Gateway. - pub parents: Vec, -} - -/// RouteParentStatus describes the status of a route with respect to an -/// associated Parent. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct UDPRouteStatusParents { - /// Conditions describes the status of the route with respect to the Gateway. - /// Note that the route's availability is also subject to the Gateway's own - /// status conditions and listener status. - /// - /// If the Route's ParentRef specifies an existing Gateway that supports - /// Routes of this kind AND that Gateway's controller has sufficient access, - /// then that Gateway's controller MUST set the "Accepted" condition on the - /// Route, to indicate whether the route has been accepted or rejected by the - /// Gateway, and why. - /// - /// A Route MUST be considered "Accepted" if at least one of the Route's - /// rules is implemented by the Gateway. - /// - /// There are a number of cases where the "Accepted" condition may not be set - /// due to lack of controller visibility, that includes when: - /// - /// * The Route refers to a non-existent parent. - /// * The Route is of a type that the controller does not support. - /// * The Route is in a namespace the controller does not have access to. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub conditions: Option>, - /// ControllerName is a domain/path string that indicates the name of the - /// controller that wrote this status. This corresponds with the - /// controllerName field on GatewayClass. - /// - /// Example: "example.net/gateway-controller". - /// - /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are - /// valid Kubernetes names - /// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). - /// - /// Controllers MUST populate this field when writing status. Controllers should ensure that - /// entries to status populated with their ControllerName are cleaned up when they are no - /// longer necessary. - #[serde(rename = "controllerName")] - pub controller_name: String, - /// ParentRef corresponds with a ParentRef in the spec that this - /// RouteParentStatus struct describes the status of. - #[serde(rename = "parentRef")] - pub parent_ref: UDPRouteStatusParentsParentRef, -} - -/// ParentRef corresponds with a ParentRef in the spec that this -/// RouteParentStatus struct describes the status of. -#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] -pub struct UDPRouteStatusParentsParentRef { - /// Group is the group of the referent. - /// When unspecified, "gateway.networking.k8s.io" is inferred. - /// To set the core API group (such as for a "Service" kind referent), - /// Group must be explicitly set to "" (empty string). - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub group: Option, - /// Kind is kind of the referent. - /// - /// There are two kinds of parent resources with "Core" support: - /// - /// * Gateway (Gateway conformance profile) - /// * Service (Mesh conformance profile, ClusterIP Services only) - /// - /// Support for other resources is Implementation-Specific. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub kind: Option, - /// Name is the name of the referent. - /// - /// Support: Core - pub name: String, - /// Namespace is the namespace of the referent. When unspecified, this refers - /// to the local namespace of the Route. - /// - /// Note that there are specific rules for ParentRefs which cross namespace - /// boundaries. Cross-namespace references are only valid if they are explicitly - /// allowed by something in the namespace they are referring to. For example: - /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a - /// generic way to enable any other kind of cross-namespace reference. - /// - /// - /// ParentRefs from a Route to a Service in the same namespace are "producer" - /// routes, which apply default routing rules to inbound connections from - /// any namespace to the Service. - /// - /// ParentRefs from a Route to a Service in a different namespace are - /// "consumer" routes, and these routing rules are only applied to outbound - /// connections originating from the same namespace as the Route, for which - /// the intended destination of the connections are a Service targeted as a - /// ParentRef of the Route. - /// - /// - /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none")] - pub namespace: Option, - /// Port is the network port this Route targets. It can be interpreted - /// differently based on the type of parent resource. - /// - /// When the parent resource is a Gateway, this targets all listeners - /// listening on the specified port that also support this kind of Route(and - /// select this Route). It's not recommended to set `Port` unless the - /// networking behaviors specified in a Route must apply to a specific port - /// as opposed to a listener(s) whose port(s) may be changed. When both Port - /// and SectionName are specified, the name and port of the selected listener - /// must match both specified values. - /// - /// - /// When the parent resource is a Service, this targets a specific port in the - /// Service spec. When both Port (experimental) and SectionName are specified, - /// the name and port of the selected port must match both specified values. - /// - /// - /// Implementations MAY choose to support other parent resources. - /// Implementations supporting other types of parent resources MUST clearly - /// document how/if Port is interpreted. - /// - /// For the purpose of status, an attachment is considered successful as - /// long as the parent resource accepts it partially. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment - /// from the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, - /// the Route MUST be considered detached from the Gateway. - /// - /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none")] - pub port: Option, - /// SectionName is the name of a section within the target resource. In the - /// following resources, SectionName is interpreted as the following: - /// - /// * Gateway: Listener name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// * Service: Port name. When both Port (experimental) and SectionName - /// are specified, the name and port of the selected listener must match - /// both specified values. - /// - /// Implementations MAY choose to support attaching Routes to other resources. - /// If that is the case, they MUST clearly document how SectionName is - /// interpreted. - /// - /// When unspecified (empty string), this will reference the entire resource. - /// For the purpose of status, an attachment is considered successful if at - /// least one section in the parent resource accepts it. For example, Gateway - /// listeners can restrict which Routes can attach to them by Route kind, - /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from - /// the referencing Route, the Route MUST be considered successfully - /// attached. If no Gateway listeners accept attachment from this Route, the - /// Route MUST be considered detached from the Gateway. - /// - /// Support: Core - #[serde( - default, - skip_serializing_if = "Option::is_none", - rename = "sectionName" - )] - pub section_name: Option, + pub rules: Vec, } diff --git a/gateway-api/src/apis/standard/common.rs b/gateway-api/src/apis/standard/common.rs index 0028cd4..9bd9ae6 100644 --- a/gateway-api/src/apis/standard/common.rs +++ b/gateway-api/src/apis/standard/common.rs @@ -111,7 +111,11 @@ pub struct ParentReference { pub namespace: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub port: Option, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "sectionName" + )] pub section_name: Option, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] @@ -175,7 +179,11 @@ pub struct RequestRedirectPath { } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] pub struct GRPCRouteFilter { - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "extensionRef" + )] pub extension_ref: Option, #[serde( default, @@ -183,7 +191,11 @@ pub struct GRPCRouteFilter { rename = "requestHeaderModifier" )] pub request_header_modifier: Option, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestMirror" + )] pub request_mirror: Option, #[serde( default, @@ -204,7 +216,11 @@ pub struct RequestRedirect { pub port: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub scheme: Option, - #[serde(default, skip_serializing_if = "Option::is_none", rename = "statusCode")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "statusCode" + )] pub status_code: Option, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] diff --git a/gateway-api/src/apis/standard/gatewayclasses.rs b/gateway-api/src/apis/standard/gatewayclasses.rs index 35974f4..f83a7f1 100644 --- a/gateway-api/src/apis/standard/gatewayclasses.rs +++ b/gateway-api/src/apis/standard/gatewayclasses.rs @@ -9,16 +9,7 @@ mod prelude { } use self::prelude::*; /// Spec defines the desired state of GatewayClass. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] +#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( group = "gateway.networking.k8s.io", version = "v1", @@ -60,7 +51,11 @@ pub struct GatewayClassSpec { /// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. /// /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "parametersRef")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "parametersRef" + )] pub parameters_ref: Option, } /// ParametersRef is a reference to a resource that contains the configuration diff --git a/gateway-api/src/apis/standard/gateways.rs b/gateway-api/src/apis/standard/gateways.rs index f4e7f81..98257a8 100644 --- a/gateway-api/src/apis/standard/gateways.rs +++ b/gateway-api/src/apis/standard/gateways.rs @@ -11,16 +11,7 @@ mod prelude { } use self::prelude::*; /// Spec defines the desired state of Gateway. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] +#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( group = "gateway.networking.k8s.io", version = "v1", @@ -223,7 +214,11 @@ pub struct GatewayInfrastructure { /// It is generally recommended that GatewayClass provides defaults that can be overridden by a Gateway. /// /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "parametersRef")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "parametersRef" + )] pub parameters_ref: Option, } /// Listener embodies the concept of a logical endpoint where a Gateway accepts @@ -254,7 +249,11 @@ pub struct GatewayListeners { /// of the rules within that Route should still be supported. /// /// Support: Core - #[serde(default, skip_serializing_if = "Option::is_none", rename = "allowedRoutes")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "allowedRoutes" + )] pub allowed_routes: Option, /// Hostname specifies the virtual hostname to match for protocol types that /// define this concept. When unspecified, all hostnames are matched. This @@ -406,13 +405,16 @@ pub struct GatewayListenersAllowedRoutesNamespacesSelector { skip_serializing_if = "Option::is_none", rename = "matchExpressions" )] - pub match_expressions: Option< - Vec, - >, + pub match_expressions: + Option>, /// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels /// map is equivalent to an element of matchExpressions, whose key field is "key", the /// operator is "In", and the values array contains only "value". The requirements are ANDed. - #[serde(default, skip_serializing_if = "Option::is_none", rename = "matchLabels")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "matchLabels" + )] pub match_labels: Option>, } /// A label selector requirement is a selector that contains values, a key, and an operator that diff --git a/gateway-api/src/apis/standard/grpcroutes.rs b/gateway-api/src/apis/standard/grpcroutes.rs index 2bd4278..80ffb94 100644 --- a/gateway-api/src/apis/standard/grpcroutes.rs +++ b/gateway-api/src/apis/standard/grpcroutes.rs @@ -10,16 +10,7 @@ mod prelude { } use self::prelude::*; /// Spec defines the desired state of GRPCRoute. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] +#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( group = "gateway.networking.k8s.io", version = "v1", @@ -140,7 +131,11 @@ pub struct GRPCRouteSpec { /// /// /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "parentRefs")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "parentRefs" + )] pub parent_refs: Option>, /// Rules are a list of GRPC matchers, filters and actions. /// @@ -181,7 +176,11 @@ pub struct GRPCRouteRule { /// Support: Implementation-specific for any other resource /// /// Support for weight: Core - #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRefs")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "backendRefs" + )] pub backend_refs: Option>, /// Filters define the filters that are applied to requests that match /// this rule. diff --git a/gateway-api/src/apis/standard/httproutes.rs b/gateway-api/src/apis/standard/httproutes.rs index 51fb02f..ef1183e 100644 --- a/gateway-api/src/apis/standard/httproutes.rs +++ b/gateway-api/src/apis/standard/httproutes.rs @@ -10,16 +10,7 @@ mod prelude { } use self::prelude::*; /// Spec defines the desired state of HTTPRoute. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] +#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( group = "gateway.networking.k8s.io", version = "v1", @@ -143,7 +134,11 @@ pub struct HTTPRouteSpec { /// /// /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "parentRefs")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "parentRefs" + )] pub parent_refs: Option>, /// Rules are a list of HTTP matchers, filters and actions. /// @@ -191,7 +186,11 @@ pub struct HTTPRouteRule { /// Support: Implementation-specific for any other resource /// /// Support for weight: Core - #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRefs")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "backendRefs" + )] pub backend_refs: Option>, /// Filters define the filters that are applied to requests that match /// this rule. @@ -400,7 +399,11 @@ pub struct HTTPRouteBackendFilter { /// This filter can be used multiple times within the same rule. /// /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "extensionRef" + )] pub extension_ref: Option, /// RequestHeaderModifier defines a schema for a filter that modifies request /// headers. @@ -423,7 +426,11 @@ pub struct HTTPRouteBackendFilter { /// Support: Extended /// /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestMirror" + )] pub request_mirror: Option, /// RequestRedirect defines a schema for a filter that responds to the /// request with an HTTP redirection. @@ -482,7 +489,11 @@ pub struct HTTPRouteBackendFilter { /// URLRewrite defines a schema for a filter that modifies a request during forwarding. /// /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "urlRewrite" + )] pub url_rewrite: Option, } /// HTTPRouteFilter defines processing steps that must be completed during the @@ -501,7 +512,11 @@ pub struct HTTPRouteFilter { /// This filter can be used multiple times within the same rule. /// /// Support: Implementation-specific - #[serde(default, skip_serializing_if = "Option::is_none", rename = "extensionRef")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "extensionRef" + )] pub extension_ref: Option, /// RequestHeaderModifier defines a schema for a filter that modifies request /// headers. @@ -524,7 +539,11 @@ pub struct HTTPRouteFilter { /// Support: Extended /// /// - #[serde(default, skip_serializing_if = "Option::is_none", rename = "requestMirror")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "requestMirror" + )] pub request_mirror: Option, /// RequestRedirect defines a schema for a filter that responds to the /// request with an HTTP redirection. @@ -583,7 +602,11 @@ pub struct HTTPRouteFilter { /// URLRewrite defines a schema for a filter that modifies a request during forwarding. /// /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "urlRewrite")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "urlRewrite" + )] pub url_rewrite: Option, } /// HTTPRouteMatch defines the predicate used to match requests to a given @@ -626,7 +649,11 @@ pub struct RouteMatch { /// specified query parameters to select the route. /// /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "queryParams")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "queryParams" + )] pub query_params: Option>, } /// HTTPRouteMatch defines the predicate used to match requests to a given @@ -714,7 +741,11 @@ pub struct HTTPRouteTimeout { /// Request timeout (since the Request timeout encompasses the BackendRequest timeout). /// /// Support: Extended - #[serde(default, skip_serializing_if = "Option::is_none", rename = "backendRequest")] + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "backendRequest" + )] pub backend_request: Option, /// Request specifies the maximum duration for a gateway to respond to an HTTP request. /// If the gateway has not been able to respond before this deadline is met, the gateway diff --git a/gateway-api/src/apis/standard/referencegrants.rs b/gateway-api/src/apis/standard/referencegrants.rs index 3ee5a78..70f0bbc 100644 --- a/gateway-api/src/apis/standard/referencegrants.rs +++ b/gateway-api/src/apis/standard/referencegrants.rs @@ -8,16 +8,7 @@ mod prelude { } use self::prelude::*; /// Spec defines the desired state of ReferenceGrant. -#[derive( - CustomResource, - Serialize, - Deserialize, - Clone, - Debug, - JsonSchema, - Default, - PartialEq -)] +#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] #[kube( group = "gateway.networking.k8s.io", version = "v1beta1", diff --git a/type-reducer/experimental_customized_mapped_names.txt b/type-reducer/experimental_customized_mapped_names.txt new file mode 100644 index 0000000..245e344 --- /dev/null +++ b/type-reducer/experimental_customized_mapped_names.txt @@ -0,0 +1,119 @@ +GRPCRouteRulesBackendRefsFiltersType->GRPCFilterType +GRPCRouteRulesFiltersType->GRPCFilterType +GRPCRouteRulesBackendRefsFiltersRequestMirrorFraction->RequestMirrorFraction +GRPCRouteRulesFiltersRequestMirrorFraction->RequestMirrorFraction +HTTPRouteRulesBackendRefsFiltersRequestMirrorFraction->RequestMirrorFraction +HTTPRouteRulesFiltersRequestMirrorFraction->RequestMirrorFraction +GRPCRouteRulesSessionPersistenceCookieConfigLifetimeType->PersistenceCookieConfigLifetime +HTTPRouteRulesSessionPersistenceCookieConfigLifetimeType->PersistenceCookieConfigLifetime +GRPCRouteRulesSessionPersistenceType->SessionPersistenceType +HTTPRouteRulesSessionPersistenceType->SessionPersistenceType +GatewayAddresses->GatewayAddress +GatewayStatusAddresses->GatewayAddress +GatewayBackendTlsClientCertificateRef->BackendTlsClientCertificateReference +GatewayListenersTlsCertificateRefs->BackendTlsClientCertificateReference +GatewayClassParametersRef->ParametersReference +GatewayListenersTlsFrontendValidationCaCertificateRefs->ParametersReference +GRPCRouteRulesBackendRefsFiltersExtensionRef->GatewayInfrastructureParametersReference +GRPCRouteRulesFiltersExtensionRef->GatewayInfrastructureParametersReference +GatewayInfrastructureParametersRef->GatewayInfrastructureParametersReference +HTTPRouteRulesBackendRefsFiltersExtensionRef->GatewayInfrastructureParametersReference +HTTPRouteRulesFiltersExtensionRef->GatewayInfrastructureParametersReference +HTTPRouteRulesBackendRefsFiltersType->HTTPFilterType +HTTPRouteRulesFiltersType->HTTPFilterType +GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd->HTTPHeader +GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierSet->HTTPHeader +GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierAdd->HTTPHeader +GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierSet->HTTPHeader +GRPCRouteRulesFiltersRequestHeaderModifierAdd->HTTPHeader +GRPCRouteRulesFiltersRequestHeaderModifierSet->HTTPHeader +GRPCRouteRulesFiltersResponseHeaderModifierAdd->HTTPHeader +GRPCRouteRulesFiltersResponseHeaderModifierSet->HTTPHeader +HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierAdd->HTTPHeader +HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierSet->HTTPHeader +HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierAdd->HTTPHeader +HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierSet->HTTPHeader +HTTPRouteRulesFiltersRequestHeaderModifierAdd->HTTPHeader +HTTPRouteRulesFiltersRequestHeaderModifierSet->HTTPHeader +HTTPRouteRulesFiltersResponseHeaderModifierAdd->HTTPHeader +HTTPRouteRulesFiltersResponseHeaderModifierSet->HTTPHeader +GRPCRouteRulesMatchesHeadersType->HeaderMatchType +GRPCRouteRulesMatchesMethodType->HeaderMatchType +HTTPRouteRulesMatchesHeadersType->HeaderMatchType +HTTPRouteRulesMatchesQueryParamsType->HeaderMatchType +GatewayListenersAllowedRoutesKinds->Kind +GatewayStatusListenersSupportedKinds->Kind +HTTPRouteRulesBackendRefsFiltersRequestRedirectStatusCode->RedirectStatusCode +HTTPRouteRulesFiltersRequestRedirectStatusCode->RedirectStatusCode +GRPCRouteRulesBackendRefsFiltersRequestMirrorBackendRef->RequestMirrorReference +GRPCRouteRulesFiltersRequestMirrorBackendRef->RequestMirrorReference +HTTPRouteRulesBackendRefsFiltersRequestMirrorBackendRef->RequestMirrorReference +HTTPRouteRulesFiltersRequestMirrorBackendRef->RequestMirrorReference +HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType->RequestOperationType +HTTPRouteRulesBackendRefsFiltersUrlRewritePathType->RequestOperationType +HTTPRouteRulesFiltersRequestRedirectPathType->RequestOperationType +HTTPRouteRulesFiltersUrlRewritePathType->RequestOperationType +HTTPRouteRulesBackendRefsFiltersRequestRedirectScheme->RequestRedirectScheme +HTTPRouteRulesFiltersRequestRedirectScheme->RequestRedirectScheme +GRPCRouteParentRefs->ParentReference +GRPCRouteStatusParentsParentRef->ParentReference +HTTPRouteParentRefs->ParentReference +HTTPRouteStatusParentsParentRef->ParentReference +TCPRouteParentRefs->ParentReference +TCPRouteStatusParentsParentRef->ParentReference +TLSRouteParentRefs->ParentReference +TLSRouteStatusParentsParentRef->ParentReference +UDPRouteParentRefs->ParentReference +UDPRouteStatusParentsParentRef->ParentReference +TCPRouteRulesBackendRefs->BackendReference +TLSRouteRulesBackendRefs->BackendReference +UDPRouteRulesBackendRefs->BackendReference +#### Pass 2 +GRPCRouteRulesSessionPersistenceCookieConfig->SessionPersistenceCookieConfig +HTTPRouteRulesSessionPersistenceCookieConfig->SessionPersistenceCookieConfig +GRPCRouteRulesMatchesHeaders->HeaderMatch +HTTPRouteRulesMatchesHeaders->HeaderMatch +HTTPRouteRulesMatchesQueryParams->HeaderMatch +GRPCRouteRulesBackendRefsFiltersRequestHeaderModifier->HeaderModifier +GRPCRouteRulesBackendRefsFiltersResponseHeaderModifier->HeaderModifier +GRPCRouteRulesFiltersRequestHeaderModifier->HeaderModifier +GRPCRouteRulesFiltersResponseHeaderModifier->HeaderModifier +HTTPRouteRulesBackendRefsFiltersRequestHeaderModifier->HeaderModifier +HTTPRouteRulesBackendRefsFiltersResponseHeaderModifier->HeaderModifier +HTTPRouteRulesFiltersRequestHeaderModifier->HeaderModifier +HTTPRouteRulesFiltersResponseHeaderModifier->HeaderModifier +GRPCRouteRulesBackendRefsFiltersRequestMirror->RequestMirror +GRPCRouteRulesFiltersRequestMirror->RequestMirror +HTTPRouteRulesBackendRefsFiltersRequestMirror->RequestMirror +HTTPRouteRulesFiltersRequestMirror->RequestMirror +HTTPRouteRulesBackendRefsFiltersRequestRedirectPath->RequestRedirectPath +HTTPRouteRulesBackendRefsFiltersUrlRewritePath->RequestRedirectPath +HTTPRouteRulesFiltersRequestRedirectPath->RequestRedirectPath +HTTPRouteRulesFiltersUrlRewritePath->RequestRedirectPath +TCPRouteRules->CommonRouteRule +TLSRouteRules->CommonRouteRule +UDPRouteRules->CommonRouteRule +GRPCRouteStatusParents->ParentRouteStatus +HTTPRouteStatusParents->ParentRouteStatus +TCPRouteStatusParents->ParentRouteStatus +TLSRouteStatusParents->ParentRouteStatus +UDPRouteStatusParents->ParentRouteStatus +#### Pass 3 +GRPCRouteRulesBackendRefsFilters->GRPCRouteFilter +GRPCRouteRulesFilters->GRPCRouteFilter +GRPCRouteRulesSessionPersistence->SessionPersistence +HTTPRouteRulesSessionPersistence->SessionPersistence +HTTPRouteRulesBackendRefsFiltersRequestRedirect->HTTPRouteRequestRedirect +HTTPRouteRulesFiltersRequestRedirect->HTTPRouteRequestRedirect +HTTPRouteRulesBackendRefsFiltersUrlRewrite->HTTPRouteUrlRewrite +HTTPRouteRulesFiltersUrlRewrite->HTTPRouteUrlRewrite +TCPRouteSpec->RouteSpec +UDPRouteSpec->RouteSpec +GRPCRouteStatus->RouteStatus +HTTPRouteStatus->RouteStatus +TCPRouteStatus->RouteStatus +TLSRouteStatus->RouteStatus +UDPRouteStatus->RouteStatus +#### Pass 4 +HTTPRouteRulesBackendRefsFilters->HTTPRouteBackendFilters +HTTPRouteRulesFilters->HTTPRouteRulesBackendRefsFilters diff --git a/type-reducer/experimental_ignorable_mapped_names.txt b/type-reducer/experimental_ignorable_mapped_names.txt new file mode 100644 index 0000000..b278bf5 --- /dev/null +++ b/type-reducer/experimental_ignorable_mapped_names.txt @@ -0,0 +1,2 @@ +TCPRouteSpec->RouteSpec +UDPRouteSpec->RouteSpec diff --git a/type-reducer/reduced_types_pass_0.txt b/type-reducer/experimental_reduced_types_pass_0.txt similarity index 100% rename from type-reducer/reduced_types_pass_0.txt rename to type-reducer/experimental_reduced_types_pass_0.txt diff --git a/type-reducer/experimental_reduced_types_pass_1.txt b/type-reducer/experimental_reduced_types_pass_1.txt new file mode 100644 index 0000000..9fe55af --- /dev/null +++ b/type-reducer/experimental_reduced_types_pass_1.txt @@ -0,0 +1,19 @@ +Condition +GRPCFilterType +RequestMirrorFraction +PersistenceCookieConfigLifetime +SessionPersistenceType +GatewayAddress +BackendTlsClientCertificateReference +ParametersReference +GatewayInfrastructureParametersReference +HTTPFilterType +HTTPHeader +HeaderMatchType +Kind +RedirectStatusCode +RequestMirrorReference +RequestOperationType +RequestRedirectScheme +ParentReference +BackendReference diff --git a/type-reducer/experimental_reduced_types_pass_2.txt b/type-reducer/experimental_reduced_types_pass_2.txt new file mode 100644 index 0000000..402636a --- /dev/null +++ b/type-reducer/experimental_reduced_types_pass_2.txt @@ -0,0 +1,27 @@ +Condition +GRPCFilterType +RequestMirrorFraction +PersistenceCookieConfigLifetime +SessionPersistenceType +GatewayAddress +BackendTlsClientCertificateReference +ParametersReference +GatewayInfrastructureParametersReference +HTTPFilterType +HTTPHeader +HeaderMatchType +Kind +RedirectStatusCode +RequestMirrorReference +RequestOperationType +RequestRedirectScheme +ParentReference +BackendReference +#### Pass 2 +SessionPersistenceCookieConfig +HeaderModifier +HeaderMatch +RequestMirror +RequestRedirectPath +ParentRouteStatus +CommonRouteRule diff --git a/type-reducer/experimental_reduced_types_pass_3.txt b/type-reducer/experimental_reduced_types_pass_3.txt new file mode 100644 index 0000000..2c06609 --- /dev/null +++ b/type-reducer/experimental_reduced_types_pass_3.txt @@ -0,0 +1,33 @@ +Condition +GRPCFilterType +RequestMirrorFraction +PersistenceCookieConfigLifetime +SessionPersistenceType +GatewayAddress +BackendTlsClientCertificateReference +ParametersReference +GatewayInfrastructureParametersReference +HTTPFilterType +HTTPHeader +HeaderMatchType +Kind +RedirectStatusCode +RequestMirrorReference +RequestOperationType +RequestRedirectScheme +ParentReference +BackendReference +#### Pass 2 +SessionPersistenceCookieConfig +HeaderModifier +HeaderMatch +RequestMirror +RequestRedirectPath +ParentRouteStatus +CommonRouteRule +#### Pass 3 +GRPCRouteFilter +HTTPRouteRequestRedirect +HTTPRouteUrlRewrite +RouteStatus +SessionPersistence diff --git a/type-reducer/experimental_reduced_types_pass_4.txt b/type-reducer/experimental_reduced_types_pass_4.txt new file mode 100644 index 0000000..2d40c18 --- /dev/null +++ b/type-reducer/experimental_reduced_types_pass_4.txt @@ -0,0 +1,35 @@ +Condition +GRPCFilterType +RequestMirrorFraction +PersistenceCookieConfigLifetime +SessionPersistenceType +GatewayAddress +BackendTlsClientCertificateReference +ParametersReference +GatewayInfrastructureParametersReference +HTTPFilterType +HTTPHeader +HeaderMatchType +Kind +RedirectStatusCode +RequestMirrorReference +RequestOperationType +RequestRedirectScheme +ParentReference +BackendReference +#### Pass 2 +SessionPersistenceCookieConfig +HeaderModifier +HeaderMatch +RequestMirror +RequestRedirectPath +ParentRouteStatus +CommonRouteRule +#### Pass 3 +GRPCRouteFilter +HTTPRouteRequestRedirect +HTTPRouteUrlRewrite +RouteStatus +SessionPersistence +#### Pass 4 +HTTPRouteBackendFilters diff --git a/type-reducer/rename_only_mapped_names.txt b/type-reducer/experimental_rename_only_mapped_names.txt similarity index 100% rename from type-reducer/rename_only_mapped_names.txt rename to type-reducer/experimental_rename_only_mapped_names.txt diff --git a/type-reducer/src/main.rs b/type-reducer/src/main.rs index 6fe84d8..9e181d4 100644 --- a/type-reducer/src/main.rs +++ b/type-reducer/src/main.rs @@ -1,6 +1,7 @@ use clap::Parser; use clap::Subcommand; use itertools::Itertools; +use log::debug; use log::info; use std::cmp::Ordering; use std::collections::BTreeMap; @@ -25,6 +26,9 @@ struct ReduceArgs { #[arg(long)] previous_pass_derived_type_names: PathBuf, + + #[arg(long)] + ignorable_type_names: Option, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Parser)] @@ -75,6 +79,7 @@ fn main() -> Result<(), Box> { let ReduceArgs { current_pass_substitute_names, previous_pass_derived_type_names, + ignorable_type_names, } = args; let previous_pass_derived_type_names = read_type_names_from_file(previous_pass_derived_type_names.as_path())?; @@ -82,8 +87,20 @@ fn main() -> Result<(), Box> { let current_pass_type_name_substitutes = read_type_mappings_from_file(current_pass_substitute_names.as_path())?; + let ignorable_type_names = + if let Some(ignorable_type_names) = ignorable_type_names.as_ref() { + read_type_mappings_from_file(ignorable_type_names.as_path())? + } else { + BTreeMap::new() + }; + let visitors = create_visitors(&apis_dir, &previous_pass_derived_type_names)?; - handle_reduce_types(current_pass_type_name_substitutes, visitors, &out_dir) + handle_reduce_types( + current_pass_type_name_substitutes, + visitors, + &out_dir, + ignorable_type_names, + ) } } } @@ -92,6 +109,7 @@ fn handle_reduce_types( current_pass_type_name_substitutes: BTreeMap, visitors: Vec<(StructEnumVisitor<'_, '_>, syn::File)>, out_dir: &str, + ignorable_types: BTreeMap, ) -> Result<(), Box> { let FindSimilarTypesResult { visitors, @@ -109,6 +127,19 @@ fn handle_reduce_types( ); let mapped_type_names = v.iter().map(|v| v.0.to_string()).collect::>(); + let mut ignore = false; + if !ignorable_types.is_empty() { + for mapped_type in &mapped_type_names { + if ignorable_types.contains_key(mapped_type) { + debug!("Ignoring type {mapped_type}"); + ignore = true; + } + } + } + if ignore { + return None; + } + // let type_new_name = // create_struct_type_name_substitute(¤t_pass_type_name_substitutes, v); diff --git a/type-reducer/customized_mapped_names.txt b/type-reducer/standard_customized_mapped_names.txt similarity index 100% rename from type-reducer/customized_mapped_names.txt rename to type-reducer/standard_customized_mapped_names.txt diff --git a/type-reducer/standard_reduced_types_pass_0.txt b/type-reducer/standard_reduced_types_pass_0.txt new file mode 100644 index 0000000..3c2773d --- /dev/null +++ b/type-reducer/standard_reduced_types_pass_0.txt @@ -0,0 +1 @@ +Condition \ No newline at end of file diff --git a/type-reducer/reduced_types_pass_1.txt b/type-reducer/standard_reduced_types_pass_1.txt similarity index 100% rename from type-reducer/reduced_types_pass_1.txt rename to type-reducer/standard_reduced_types_pass_1.txt diff --git a/type-reducer/reduced_types_pass_2.txt b/type-reducer/standard_reduced_types_pass_2.txt similarity index 100% rename from type-reducer/reduced_types_pass_2.txt rename to type-reducer/standard_reduced_types_pass_2.txt diff --git a/type-reducer/reduced_types_pass_3.txt b/type-reducer/standard_reduced_types_pass_3.txt similarity index 100% rename from type-reducer/reduced_types_pass_3.txt rename to type-reducer/standard_reduced_types_pass_3.txt diff --git a/type-reducer/standard_rename_only_mapped_names.txt b/type-reducer/standard_rename_only_mapped_names.txt new file mode 100644 index 0000000..b8c7e41 --- /dev/null +++ b/type-reducer/standard_rename_only_mapped_names.txt @@ -0,0 +1,14 @@ +### Rename only +GRPCRouteRules->GRPCRouteRule +HTTPRouteRules->HTTPRouteRule +HTTPRouteRulesFilters->HTTPRouteFilter +GRPCRouteRulesMatches->GRPCRouteMatch +HTTPRouteRulesMatches->RouteMatch +HTTPRouteRulesTimeouts->HTTPRouteTimeout +GRPCRouteRulesBackendRefs->GRPCBackendReference +HTTPRouteRulesBackendRefs->HTTPBackendReference +GRPCRouteRulesMatchesMethod->GRPCMethodMatch +HTTPRouteRulesMatchesMethod->HTTPMethodMatch +HTTPRouteRulesBackendRefsFilters->HTTPRouteBackendFilter +HTTPRouteRequestRedirect->RequestRedirect +HTTPRouteRulesMatchesPath->PathMatch \ No newline at end of file diff --git a/update.sh b/update.sh index 07fc52e..7da3778 100755 --- a/update.sh +++ b/update.sh @@ -130,34 +130,24 @@ echo "pub mod constants;" >> $APIS_DIR/experimental/mod.rs cargo fmt -# rm -rf $APIS_DIR/processed -# mkdir -p $APIS_DIR/processed export RUST_LOG=info echo " **** PHASE 1 ***** " -#cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/processed --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_0_with_enums.txt -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_0.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt -mv mapped_names.txt mapped_names_phase_1.txt -mv mapped_types_to_names.txt mapped_types_to_names_pahse_1.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/standard_reduced_types_pass_0.txt --current-pass-substitute-names ./type-reducer/standard_customized_mapped_names.txt +mv mapped_names.txt standard_mapped_names_phase_1.txt +mv mapped_types_to_names.txt standard_mapped_types_to_names_phase_1.txt echo " **** PHASE 2 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_1.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt -mv mapped_names.txt mapped_names_phase_2.txt -mv mapped_types_to_names.txt mapped_types_to_names_pahse_2.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/standard_reduced_types_pass_1.txt --current-pass-substitute-names ./type-reducer/standard_customized_mapped_names.txt +mv mapped_names.txt standard_mapped_names_phase_2.txt +mv mapped_types_to_names.txt standard_mapped_types_to_names_phase_2.txt echo " **** PHASE 3 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_2.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt -mv mapped_names.txt mapped_names_phase_3.txt -mv mapped_types_to_names.txt mapped_types_to_names_pahse_3.txt -echo " **** PHASE 4 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/reduced_types_pass_3.txt --current-pass-substitute-names ./type-reducer/customized_mapped_names.txt -mv mapped_names.txt mapped_names_phase_4.txt -mv mapped_types_to_names.txt mapped_types_to_names_pahse_4.txt -echo " **** PHASE 5 ***** " -cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard rename --rename-only-substitute-names ./type-reducer/rename_only_mapped_names.txt +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/standard_reduced_types_pass_2.txt --current-pass-substitute-names ./type-reducer/standard_customized_mapped_names.txt +mv mapped_names.txt standard_mapped_names_phase_3.txt +mv mapped_types_to_names.txt standard_mapped_types_to_names_phase_3.txt -# cat << EOF >> $APIS_DIR/mod.rs +echo " **** RENAMING PHASE ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard rename --rename-only-substitute-names ./type-reducer/standard_rename_only_mapped_names.txt -# pub mod processed; -# EOF ENUMS=( GRPCFilterType=RequestHeaderModifier @@ -175,3 +165,40 @@ sed -i '/#\[kube(status = "HTTPRouteStatus")\]/c\#\[kube(status = "RouteStatus") +export RUST_LOG=info +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/experimental --out-dir $APIS_DIR/experimental reduce --previous-pass-derived-type-names ./type-reducer/experimental_reduced_types_pass_0.txt --current-pass-substitute-names ./type-reducer/experimental_customized_mapped_names.txt +mv mapped_names.txt experimental_mapped_names_phase_1.txt +mv mapped_types_to_names.txt experimental_mapped_types_to_names_phase_1.txt +echo " **** PHASE 2 ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/experimental --out-dir $APIS_DIR/experimental reduce --previous-pass-derived-type-names ./type-reducer/experimental_reduced_types_pass_1.txt --current-pass-substitute-names ./type-reducer/experimental_customized_mapped_names.txt +mv mapped_names.txt experimental_mapped_names_phase_2.txt +mv mapped_types_to_names.txt experimental_mapped_types_to_names_phase_2.txt +echo " **** PHASE 3 ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/experimental --out-dir $APIS_DIR/experimental reduce --previous-pass-derived-type-names ./type-reducer/experimental_reduced_types_pass_2.txt --current-pass-substitute-names ./type-reducer/experimental_customized_mapped_names.txt --ignorable-type-names ./type-reducer/experimental_ignorable_mapped_names.txt +mv mapped_names.txt experimental_mapped_names_phase_3.txt +mv mapped_types_to_names.txt experimental_mapped_types_to_names_phase_3.txt +echo " **** PHASE 4 ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/experimental --out-dir $APIS_DIR/experimental reduce --previous-pass-derived-type-names ./type-reducer/experimental_reduced_types_pass_3.txt --current-pass-substitute-names ./type-reducer/experimental_customized_mapped_names.txt --ignorable-type-names ./type-reducer/experimental_ignorable_mapped_names.txt +mv mapped_names.txt experimental_mapped_names_phase_4.txt +mv mapped_types_to_names.txt experimental_mapped_types_to_names_phase_4.txt + +echo " **** RENAMING PHASE ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/experimental --out-dir $APIS_DIR/experimental rename --rename-only-substitute-names ./type-reducer/experimental_rename_only_mapped_names.txt + + +ENUMS=( + GRPCFilterType=RequestHeaderModifier + RequestOperationType=ReplaceFullPath + HTTPFilterType=RequestHeaderModifier +) + +ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}") +ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1} +echo "use super::common::*;" > $APIS_DIR/experimental/enum_defaults.rs +GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/experimental/enum_defaults.rs + +sed -i '/#\[kube(status = "GRPCRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/grpcroutes.rs +sed -i '/#\[kube(status = "HTTPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/httproutes.rs +sed -i '/#\[kube(status = "TLSRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/tlsroutes.rs +sed -i '/#\[kube(status = "UDPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/udproutes.rs +sed -i '/#\[kube(status = "TCPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/tcproutes.rs \ No newline at end of file From 6a4199e07ca8bf290761f71f7fa7c370d200c2d9 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Fri, 27 Jun 2025 16:54:06 +0000 Subject: [PATCH 07/16] Update gateway-api/CHANGELOG.md Co-authored-by: Shane Utt Signed-off-by: Dawid Nowak --- gateway-api/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway-api/CHANGELOG.md b/gateway-api/CHANGELOG.md index c060b4c..71329dd 100644 --- a/gateway-api/CHANGELOG.md +++ b/gateway-api/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 0.2.0 +## Next >[!IMPORTANT] Breaking change From b91120bcd90ac37e8fe47e628ece1d77b6b70faa Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Fri, 27 Jun 2025 16:54:18 +0000 Subject: [PATCH 08/16] Update gateway-api/CHANGELOG.md Co-authored-by: Shane Utt Signed-off-by: Dawid Nowak --- gateway-api/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway-api/CHANGELOG.md b/gateway-api/CHANGELOG.md index 71329dd..401e38c 100644 --- a/gateway-api/CHANGELOG.md +++ b/gateway-api/CHANGELOG.md @@ -10,7 +10,7 @@ The structure of APIs has changed to promote the re-use of types in the generate While with this approach we can significantly reduce the surface of exposed APIs, it is also a breaking change. See [issue](https://github.com/kube-rs/gateway-api-rs/issues/38) for more context. -## 0.1.0 +## 0.16.0 ### Changed Initial release. All types are generated with Kopium. From b1f8ecdcb08a7a32b86f5a5316703027a8f5f841 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Fri, 27 Jun 2025 18:52:57 +0100 Subject: [PATCH 09/16] Removing scripts, updating READMEs in type-reducer and other nits Signed-off-by: Dawid Nowak --- gateway-api/src/lib.rs | 3 +- type-reducer/README.md | 64 +++++++++++++++++++++--------------- type-reducer/reduce_types.sh | 9 ----- 3 files changed, 38 insertions(+), 38 deletions(-) delete mode 100755 type-reducer/reduce_types.sh diff --git a/gateway-api/src/lib.rs b/gateway-api/src/lib.rs index 083cf55..29c1b32 100644 --- a/gateway-api/src/lib.rs +++ b/gateway-api/src/lib.rs @@ -28,7 +28,6 @@ mod tests { use uuid::Uuid; use crate::{ - apis::standard::common::GatewayAddress, apis::standard::constants::{ GatewayConditionReason, GatewayConditionType, ListenerConditionReason, ListenerConditionType, @@ -89,7 +88,6 @@ mod tests { assert!(gw.metadata.uid.is_some()); let gw_status = GatewayStatus { - addresses: Some(vec![GatewayAddress::default()]), listeners: Some(vec![GatewayStatusListeners { name: "tcp".into(), attached_routes: 0, @@ -111,6 +109,7 @@ mod tests { status: "True".to_string(), type_: GatewayConditionType::Programmed.to_string(), }]), + ..Default::default() }; gw = Api::default_namespaced(client) diff --git a/type-reducer/README.md b/type-reducer/README.md index c9488c9..aac0c1a 100644 --- a/type-reducer/README.md +++ b/type-reducer/README.md @@ -1,38 +1,48 @@ -# ast_parser +## Type Reduction -Usage : +This application will parse Kopium generated files and will try to identify the types that are potentially the same. The new types will be saved into "common" mod with a new, user selected name and the code will be updated with the new names. +The overall approach has three steps. -Will create common types and create APIs using those. Additionally will output the mapped types to "./mapped_types_to_names.txt" and "./mapped_names.txt" files. ./mapped_names.txt can be use as a source to provide some customer/more sensible substitutes for type names in step two. +### 1. Reducing leaf types. +The algorithm will try to identify the structs that can be reduced or "leaf" types. Leaf types are the types with fields which are simple types (String, u32, u64) or types reduced in the previous steps. As the output, the application will produce files with "mappings". -1. Step 1 - Reducing leaf types, all structs that only simple types or arrays of simple types such as String, u32, etc. -```bash -cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names mapped_names.txt --current-pass-derived-type-prefix=Common -``` +### 2. Provide new names +The mappings from step 1 should be used to provide new, user selected names. -2. Step 2 (Optional) -Create a file with new type names. The file format is like this: -``` -# type_name->new_type_name where type_name is taken from ./mapped_names.txt -CommonAddressesGateway->AddressGateway -CommonBackendFiltersMirrorRefRequestRouteRules->MirrorBackendRef -CommonExtensionFiltersRefRouteRules->FilterExtensionRef -CommonFiltersHeaderModifierRouteRules->HeaderModifier -CommonGatewayKindsListeners->ListenerRouteKinds -CommonParentRoute->ParentRef +##### Before the change. +This shows that all above Kopium generated types are the same and we should replace "GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd" with a more meaningful name. -``` -3. Step 3 (Optional) +| Kopium generated names | | User selected name| +|------------------------|--|-------------------| +|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd| +|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierSet|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd| +|GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierAdd|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd| +|GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierSet|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd| +|HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd| +|HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierSet|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd| +|HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierAdd|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd| +|HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierSet|->|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd| -Will read a file specified by --with-substitute-names and try to use those names as substitutions when modifying the APIs. -```bash -cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --with-substitute-names ./custom_mapped_names.txt -``` +##### After the change. +On subsequent runs, the algorithm will use HTTPHeader as new name for all those types. -4. Step 4(Optional) - Reducing types further -```bash -cargo run -- --apis-dir ../gateway-api/src/apis/processed --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names mapped_names.txt --current-pass-derived-type-prefix=Common -``` +| Kopium generated names | | User selected name| +|------------------------|--|-------------------| +|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|->|HTTPHeader| +|GRPCRouteRulesBackendRefsFiltersRequestHeaderModifierSet|->|HTTPHeader| +|GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierAdd|->|HTTPHeader| +|GRPCRouteRulesBackendRefsFiltersResponseHeaderModifierSet|->|HTTPHeader| +|HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierAdd|->|HTTPHeader| +|HTTPRouteRulesBackendRefsFiltersRequestHeaderModifierSet|->|HTTPHeader| +|HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierAdd|->|HTTPHeader| +|HTTPRouteRulesBackendRefsFiltersResponseHeaderModifierSet|->|HTTPHeader| + + +### 3. Re-run the application to produce the code with desired types + + +Steps 1 to 3 should be repeated until no similar types are detected. Check [update.sh](../update.sh) for more details on how to use it. diff --git a/type-reducer/reduce_types.sh b/type-reducer/reduce_types.sh deleted file mode 100755 index 398c617..0000000 --- a/type-reducer/reduce_types.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -rm -rf ../gateway-api/src/apis/processed -mkdir ../gateway-api/src/apis/processed -#cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed -echo "\n\n PHASE 1\n\n" -cargo run -- --apis-dir ../gateway-api/src/apis/standard --out-dir ../gateway-api/src/apis/processed --current-pass-substitute-names customized_mapped_names.txt --previous-pass-derived-type-names reduced_types_pass_0.txt -echo "\n\n PHASE 2\n\n" -cargo run -- --apis-dir ../gateway-api/src/apis/processed --out-dir ../gateway-api/src/apis/processed --previous-pass-derived-type-names reduced_types_pass_1.txt --current-pass-substitute-names customized_mapped_names.txt - From 6eb5d0109fb692fdf1d760157baa553cb3973a71 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Fri, 27 Jun 2025 19:47:42 +0100 Subject: [PATCH 10/16] Removing comments from enum files Signed-off-by: Dawid Nowak --- gateway-api/src/apis/experimental/common.rs | 37 --------------------- gateway-api/src/apis/standard/common.rs | 27 --------------- type-reducer/src/lib.rs | 12 +++++-- type-reducer/src/main.rs | 8 +---- update.sh | 5 ++- 5 files changed, 14 insertions(+), 75 deletions(-) diff --git a/gateway-api/src/apis/experimental/common.rs b/gateway-api/src/apis/experimental/common.rs index f25f083..600a85b 100644 --- a/gateway-api/src/apis/experimental/common.rs +++ b/gateway-api/src/apis/experimental/common.rs @@ -9,12 +9,6 @@ mod prelude { pub use std::collections::BTreeMap; } use self::prelude::*; -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum GRPCFilterType { ResponseHeaderModifier, @@ -22,12 +16,6 @@ pub enum GRPCFilterType { RequestMirror, ExtensionRef, } -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum HTTPFilterType { RequestHeaderModifier, @@ -38,26 +26,16 @@ pub enum HTTPFilterType { UrlRewrite, ExtensionRef, } -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum HeaderMatchType { Exact, RegularExpression, } -/// CookieConfig provides configuration settings that are specific -/// to cookie-based session persistence. -/// -/// Support: Core #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum PersistenceCookieConfigLifetime { Permanent, Session, } -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum RedirectStatusCode { #[serde(rename = "301")] @@ -65,20 +43,11 @@ pub enum RedirectStatusCode { #[serde(rename = "302")] r#_302, } -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum RequestOperationType { ReplaceFullPath, ReplacePrefixMatch, } -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum RequestRedirectScheme { #[serde(rename = "http")] @@ -86,12 +55,6 @@ pub enum RequestRedirectScheme { #[serde(rename = "https")] Https, } -/// SessionPersistence defines and configures session persistence -/// for the route rule. -/// -/// Support: Extended -/// -/// #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum SessionPersistenceType { Cookie, diff --git a/gateway-api/src/apis/standard/common.rs b/gateway-api/src/apis/standard/common.rs index 9bd9ae6..024f39d 100644 --- a/gateway-api/src/apis/standard/common.rs +++ b/gateway-api/src/apis/standard/common.rs @@ -9,12 +9,6 @@ mod prelude { pub use std::collections::BTreeMap; } use self::prelude::*; -/// GRPCRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. GRPCRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum GRPCFilterType { ResponseHeaderModifier, @@ -22,12 +16,6 @@ pub enum GRPCFilterType { RequestMirror, ExtensionRef, } -/// HTTPRouteFilter defines processing steps that must be completed during the -/// request or response lifecycle. HTTPRouteFilters are meant as an extension -/// point to express processing that may be done in Gateway implementations. Some -/// examples include request or response modification, implementing -/// authentication strategies, rate-limiting, and traffic shaping. API -/// guarantee/conformance is defined based on the type of the filter. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum HTTPFilterType { RequestHeaderModifier, @@ -38,17 +26,11 @@ pub enum HTTPFilterType { UrlRewrite, ExtensionRef, } -/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request -/// headers. #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum HeaderMatchType { Exact, RegularExpression, } -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum RedirectStatusCode { #[serde(rename = "301")] @@ -56,20 +38,11 @@ pub enum RedirectStatusCode { #[serde(rename = "302")] r#_302, } -/// Path defines parameters used to modify the path of the incoming request. -/// The modified path is then used to construct the `Location` header. When -/// empty, the request path is used as-is. -/// -/// Support: Extended #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum RequestOperationType { ReplaceFullPath, ReplacePrefixMatch, } -/// RequestRedirect defines a schema for a filter that responds to the -/// request with an HTTP redirection. -/// -/// Support: Core #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] pub enum RequestRedirectScheme { #[serde(rename = "http")] diff --git a/type-reducer/src/lib.rs b/type-reducer/src/lib.rs index e4fb5e0..39af624 100644 --- a/type-reducer/src/lib.rs +++ b/type-reducer/src/lib.rs @@ -95,7 +95,7 @@ pub fn write_type_names_to_file( Ok(()) } -pub fn delete_replaced_structs(file: File, type_names: Vec) -> File { +pub fn delete_replaced_types(file: File, type_names: Vec) -> File { let File { shebang, attrs, @@ -179,7 +179,7 @@ pub fn find_similar_types( } } -pub fn prune_replaced_structs( +pub fn prune_replaced_types( renaming_visitor: &mut StructEnumFieldsRenamer, visitors: Vec<(String, File)>, ) -> Vec<(String, String, bool)> { @@ -189,7 +189,7 @@ pub fn prune_replaced_structs( renaming_visitor.changed = false; renaming_visitor.visit_file_mut(&mut f); let new_file = - delete_replaced_structs(f, renaming_visitor.names.keys().cloned().collect()); + delete_replaced_types(f, renaming_visitor.names.keys().cloned().collect()); ( name, prettyplease::unparse(&new_file), @@ -303,5 +303,11 @@ pub fn create_common_type_struct(s: &ItemStruct, type_new_name: &str) -> ItemStr pub fn create_common_type_enum(s: &ItemEnum, type_new_name: &str) -> ItemEnum { let mut new_enum = s.clone(); new_enum.ident = Ident::new(type_new_name, Span::call_site()); + new_enum.attrs = s + .attrs + .iter() + .filter(|&a| a.meta.path().get_ident() != Some(&Ident::new("doc", Span::call_site()))) + .cloned() + .collect(); new_enum } diff --git a/type-reducer/src/main.rs b/type-reducer/src/main.rs index 9e181d4..8f8684c 100644 --- a/type-reducer/src/main.rs +++ b/type-reducer/src/main.rs @@ -140,9 +140,6 @@ fn handle_reduce_types( return None; } - // let type_new_name = - // create_struct_type_name_substitute(¤t_pass_type_name_substitutes, v); - if let Some((i, s)) = v.first() { let new_struct = create_common_type_struct( s, @@ -176,9 +173,6 @@ fn handle_reduce_types( ); let mapped_type_names = v.iter().map(|v| v.0.to_string()).collect::>(); - // let type_new_name = - // create_enum_type_name_substitute(¤t_pass_type_name_substitutes, v); - if let Some((i, s)) = v.first() { let new_enum = create_common_type_enum( s, @@ -212,7 +206,7 @@ fn handle_reduce_types( write_type_names_to_file(&renaming_visitor.names)?; - let unparsed_files = prune_replaced_structs(&mut renaming_visitor, visitors); + let unparsed_files = prune_replaced_types(&mut renaming_visitor, visitors); recreate_project_files( out_dir, diff --git a/update.sh b/update.sh index 7da3778..dd8ab10 100755 --- a/update.sh +++ b/update.sh @@ -201,4 +201,7 @@ sed -i '/#\[kube(status = "GRPCRouteStatus")\]/c\#\[kube(status = "RouteStatus") sed -i '/#\[kube(status = "HTTPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/httproutes.rs sed -i '/#\[kube(status = "TLSRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/tlsroutes.rs sed -i '/#\[kube(status = "UDPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/udproutes.rs -sed -i '/#\[kube(status = "TCPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/tcproutes.rs \ No newline at end of file +sed -i '/#\[kube(status = "TCPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/tcproutes.rs + + +cargo fmt From 9e02c64f96d7c6fb869da54e97f5e1b724dc2cbd Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Fri, 27 Jun 2025 22:33:09 +0100 Subject: [PATCH 11/16] Fixing integration tests Signed-off-by: Dawid Nowak --- gateway-api/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gateway-api/src/lib.rs b/gateway-api/src/lib.rs index 29c1b32..91a761e 100644 --- a/gateway-api/src/lib.rs +++ b/gateway-api/src/lib.rs @@ -27,6 +27,7 @@ mod tests { use tower::ServiceBuilder; use uuid::Uuid; + use crate::common::GatewayAddress; use crate::{ apis::standard::constants::{ GatewayConditionReason, GatewayConditionType, ListenerConditionReason, @@ -88,6 +89,7 @@ mod tests { assert!(gw.metadata.uid.is_some()); let gw_status = GatewayStatus { + addresses: Some(vec![GatewayAddress::default()]), listeners: Some(vec![GatewayStatusListeners { name: "tcp".into(), attached_routes: 0, @@ -109,7 +111,6 @@ mod tests { status: "True".to_string(), type_: GatewayConditionType::Programmed.to_string(), }]), - ..Default::default() }; gw = Api::default_namespaced(client) From 65015b00c7a8bcfc0f6a9c7923179e6a8ac3521d Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Tue, 15 Jul 2025 17:13:58 +0000 Subject: [PATCH 12/16] Update type-reducer/src/visitors.rs Co-authored-by: Shane Utt Signed-off-by: Dawid Nowak --- type-reducer/src/visitors.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/type-reducer/src/visitors.rs b/type-reducer/src/visitors.rs index 6cf50a7..dbf12fa 100644 --- a/type-reducer/src/visitors.rs +++ b/type-reducer/src/visitors.rs @@ -66,7 +66,6 @@ fn rewrite_ident(path: &mut PathSegment, names: &BTreeMap) -> bo impl<'ast, 'b> Visit<'ast> for StructEnumVisitor<'ast, 'b> { fn visit_item_struct(&mut self, node: &'ast ItemStruct) { debug!("Visiting Struct name == {}", node.ident); - //debug!("Visiting Struct name == {:#?}", node); let mut is_simple_leaf = true; node.fields.iter().for_each(|f| match &f.ty { Type::Path(path_type) => { From bbf952fc04ad65d2915990ba6ede27c1ff6e6565 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Tue, 15 Jul 2025 17:14:07 +0000 Subject: [PATCH 13/16] Update update.sh Co-authored-by: Shane Utt Signed-off-by: Dawid Nowak --- update.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/update.sh b/update.sh index dd8ab10..a3c65c4 100755 --- a/update.sh +++ b/update.sh @@ -163,8 +163,6 @@ GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_ sed -i '/#\[kube(status = "GRPCRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/standard/grpcroutes.rs sed -i '/#\[kube(status = "HTTPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/standard/httproutes.rs - - export RUST_LOG=info cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/experimental --out-dir $APIS_DIR/experimental reduce --previous-pass-derived-type-names ./type-reducer/experimental_reduced_types_pass_0.txt --current-pass-substitute-names ./type-reducer/experimental_customized_mapped_names.txt mv mapped_names.txt experimental_mapped_names_phase_1.txt From d6b633aec8d84a6f46ea17e730f389d76fb3a759 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Tue, 15 Jul 2025 17:14:15 +0000 Subject: [PATCH 14/16] Update update.sh Co-authored-by: Shane Utt Signed-off-by: Dawid Nowak --- update.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/update.sh b/update.sh index a3c65c4..99d825e 100755 --- a/update.sh +++ b/update.sh @@ -183,7 +183,6 @@ mv mapped_types_to_names.txt experimental_mapped_types_to_names_phase_4.txt echo " **** RENAMING PHASE ***** " cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/experimental --out-dir $APIS_DIR/experimental rename --rename-only-substitute-names ./type-reducer/experimental_rename_only_mapped_names.txt - ENUMS=( GRPCFilterType=RequestHeaderModifier RequestOperationType=ReplaceFullPath From 59bc023f7488a28cd83cbaac72eda3c720eb649f Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Tue, 15 Jul 2025 17:14:23 +0000 Subject: [PATCH 15/16] Update update.sh Co-authored-by: Shane Utt Signed-off-by: Dawid Nowak --- update.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/update.sh b/update.sh index 99d825e..b3f03d4 100755 --- a/update.sh +++ b/update.sh @@ -200,5 +200,4 @@ sed -i '/#\[kube(status = "TLSRouteStatus")\]/c\#\[kube(status = "RouteStatus")\ sed -i '/#\[kube(status = "UDPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/udproutes.rs sed -i '/#\[kube(status = "TCPRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/tcproutes.rs - cargo fmt From 30da35c7a6b81b559a765709cde9b6a971f7addd Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Tue, 15 Jul 2025 17:15:26 +0000 Subject: [PATCH 16/16] Update update.sh Co-authored-by: Shane Utt Signed-off-by: Dawid Nowak --- update.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update.sh b/update.sh index b3f03d4..e6c3210 100755 --- a/update.sh +++ b/update.sh @@ -132,7 +132,8 @@ cargo fmt export RUST_LOG=info -echo " **** PHASE 1 ***** " +echo " **** Starting Type Reducer - Collapsing Duplicative Types **** " +echo " **** Type Reducer - PHASE 1 - First Pass ***** " cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard --out-dir $APIS_DIR/standard reduce --previous-pass-derived-type-names ./type-reducer/standard_reduced_types_pass_0.txt --current-pass-substitute-names ./type-reducer/standard_customized_mapped_names.txt mv mapped_names.txt standard_mapped_names_phase_1.txt mv mapped_types_to_names.txt standard_mapped_types_to_names_phase_1.txt