diff --git a/Cargo.lock b/Cargo.lock index 97ed05c78..64cc914b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,7 +30,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa514b7c2d4cb8ac9d54925c91900d21fdda508877694661858744211c11c69c" dependencies = [ "futures-lite", - "libc 0.2.179", + "libc 0.2.180", "tokio", ] @@ -68,7 +68,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -334,7 +334,7 @@ checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6" dependencies = [ "addr2line", "cfg-if", - "libc 0.2.179", + "libc 0.2.180", "miniz_oxide", "object", "rustc-demangle", @@ -647,7 +647,7 @@ checksum = "4a6e71767585f51c2a33fed6d67147ec0343725fc3c03bf4b89fe67fede56aa5" dependencies = [ "bitflags 1.3.2", "cfg-if", - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -656,7 +656,7 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd1ddba47aba30b6a889298ad0109c3b8dcb0e8fc993b459daa7067d46f865e0" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -680,13 +680,13 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.51" +version = "1.2.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203" +checksum = "cd4932aefd12402b36c60956a4fe0035421f544799057659ff86f923657aada3" dependencies = [ "find-msvc-tools", "jobserver", - "libc 0.2.179", + "libc 0.2.180", "shlex", ] @@ -732,7 +732,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ "glob", - "libc 0.2.179", + "libc 0.2.180", "libloading", ] @@ -902,7 +902,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" dependencies = [ "core-foundation-sys", - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -926,7 +926,7 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -1395,6 +1395,7 @@ version = "0.7.0" dependencies = [ "bolero", "dataplane-hardware", + "dataplane-k8s-sample-derive", "dataplane-lpm", "dataplane-net", "dataplane-tracectl", @@ -1428,6 +1429,23 @@ dependencies = [ "tracing-test", ] +[[package]] +name = "dataplane-k8s-sample-crds" +version = "0.7.0" +dependencies = [ + "dataplane-k8s-intf", +] + +[[package]] +name = "dataplane-k8s-sample-derive" +version = "0.7.0" +dependencies = [ + "proc-macro2", + "quote", + "schemars 1.2.0", + "syn 2.0.114", +] + [[package]] name = "dataplane-left-right-tlcache" version = "0.7.0" @@ -1856,7 +1874,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", "redox_users", "winapi", ] @@ -1869,7 +1887,7 @@ checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" dependencies = [ "bitflags 2.10.0", "block2", - "libc 0.2.179", + "libc 0.2.180", "objc2", ] @@ -1890,7 +1908,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09b4f5f101177ff01b8ec4ecc81eead416a8aa42819a2869311b3420fa114ffa" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", "once_cell", "winapi", ] @@ -2019,7 +2037,7 @@ version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", "windows-sys 0.61.2", ] @@ -2086,9 +2104,9 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "find-msvc-tools" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff" +checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41" [[package]] name = "findshlibs" @@ -2098,7 +2116,7 @@ checksum = "40b9e59cd0f7e0806cca4be089683ecb6434e602038df21fe6bf6711b2f07f64" dependencies = [ "cc", "lazy_static", - "libc 0.2.179", + "libc 0.2.180", "winapi", ] @@ -2292,7 +2310,7 @@ checksum = "52f04ae4152da20c76fe800fa48659201d5cf627c5149ca0b707b69d7eef6cf9" dependencies = [ "cc", "cfg-if", - "libc 0.2.179", + "libc 0.2.180", "log", "rustversion", "windows-link", @@ -2316,7 +2334,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", - "libc 0.2.179", + "libc 0.2.180", "wasi", ] @@ -2327,7 +2345,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", - "libc 0.2.179", + "libc 0.2.180", "r-efi", "wasip2", ] @@ -2442,7 +2460,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "617aaa3557aef3810a6369d0a99fac8a080891b68bd9f9812a1eeda0c0730cbd" dependencies = [ "cfg-if", - "libc 0.2.179", + "libc 0.2.180", "windows-link", ] @@ -2513,7 +2531,7 @@ dependencies = [ "derive_more", "errno", "hwlocality-sys", - "libc 0.2.179", + "libc 0.2.180", "strum", "thiserror 2.0.17", "windows-sys 0.61.2", @@ -2525,7 +2543,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d55ff554bde432473a6d17dc219a2d7fedc1be12d1e150418526f666dc9d096" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", "pkg-config", "windows-sys 0.61.2", ] @@ -2614,7 +2632,7 @@ dependencies = [ "http-body", "hyper", "ipnet", - "libc 0.2.179", + "libc 0.2.180", "percent-encoding", "pin-project-lite", "socket2", @@ -2808,7 +2826,7 @@ dependencies = [ "bitflags 2.10.0", "futures-core", "inotify-sys", - "libc 0.2.179", + "libc 0.2.180", "tokio", ] @@ -2818,7 +2836,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -2892,7 +2910,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" dependencies = [ "getrandom 0.3.4", - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -3091,9 +3109,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.179" +version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5a2d376baa530d1238d133232d15e239abad80d05838b4b59354e5268af431f" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] name = "libc" @@ -3138,7 +3156,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" dependencies = [ "bitflags 2.10.0", - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -3253,7 +3271,7 @@ version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "744133e4a0e0a658e1374cf3bf8e415c4052a15a111acd372764c55b4177d490" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -3372,7 +3390,7 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", "log", "wasi", "windows-sys 0.61.2", @@ -3472,7 +3490,7 @@ dependencies = [ "dispatch2", "dlopen2", "ipnet", - "libc 0.2.179", + "libc 0.2.180", "mac-addr", "netlink-packet-core", "netlink-packet-route 0.25.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3500,7 +3518,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ec2f5b6839be2a19d7fa5aab5bc444380f6311c2b693551cb80f45caaa7b5ef" dependencies = [ "bitflags 2.10.0", - "libc 0.2.179", + "libc 0.2.180", "log", "netlink-packet-core", ] @@ -3511,7 +3529,7 @@ version = "0.25.1" source = "git+https://github.com/githedgehog/netlink-packet-route.git?branch=pr%2Fdaniel-noland%2Fswing4#09b8ffdf9b4e9bbc8780a3efb4ec3494ee7ee3fd" dependencies = [ "bitflags 2.10.0", - "libc 0.2.179", + "libc 0.2.180", "log", "netlink-packet-core", ] @@ -3549,7 +3567,7 @@ checksum = "16c903aa70590cb93691bf97a767c8d1d6122d2cc9070433deb3bbf36ce8bd23" dependencies = [ "bytes", "futures", - "libc 0.2.179", + "libc 0.2.180", "log", "tokio", ] @@ -3571,7 +3589,7 @@ checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ "bitflags 1.3.2", "cfg-if", - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -3583,7 +3601,7 @@ dependencies = [ "autocfg", "bitflags 1.3.2", "cfg-if", - "libc 0.2.179", + "libc 0.2.180", "memoffset 0.6.5", "pin-utils", ] @@ -3596,7 +3614,7 @@ checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ "bitflags 2.10.0", "cfg-if", - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -3608,7 +3626,7 @@ dependencies = [ "bitflags 2.10.0", "cfg-if", "cfg_aliases", - "libc 0.2.179", + "libc 0.2.180", "memoffset 0.9.1", ] @@ -3621,7 +3639,7 @@ dependencies = [ "bitflags 2.10.0", "cfg-if", "cfg_aliases", - "libc 0.2.179", + "libc 0.2.180", "memoffset 0.9.1", ] @@ -3688,7 +3706,7 @@ dependencies = [ "bitflags 2.10.0", "block2", "dispatch2", - "libc 0.2.179", + "libc 0.2.180", "objc2", ] @@ -3717,7 +3735,7 @@ checksum = "7216bd11cbda54ccabcab84d523dc93b858ec75ecfb3a7d89513fa22464da396" dependencies = [ "bitflags 2.10.0", "dispatch2", - "libc 0.2.179", + "libc 0.2.180", "objc2", "objc2-core-foundation", "objc2-security", @@ -3803,7 +3821,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", - "libc 0.2.179", + "libc 0.2.180", "redox_syscall", "smallvec", "windows-link", @@ -4012,7 +4030,7 @@ dependencies = [ "backtrace", "cfg-if", "findshlibs", - "libc 0.2.179", + "libc 0.2.180", "log", "nix 0.27.1", "once_cell", @@ -4178,7 +4196,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3a5f63b0d2727095db59045e6a0ef3259b28b90d481ae88f0e3d866d0234ce8" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", "libflate", "log", "names", @@ -4208,7 +4226,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3ab5a9d756f0d97bdc89019bd2e4ea098cf9cde50ee7564dde6b81ccc8f06c7" dependencies = [ "crossbeam-utils", - "libc 0.2.179", + "libc 0.2.180", "once_cell", "raw-cpuid", "wasi", @@ -4271,7 +4289,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", "rand_chacha 0.3.1", "rand_core 0.6.4", ] @@ -4501,7 +4519,7 @@ dependencies = [ "cc", "cfg-if", "getrandom 0.2.16", - "libc 0.2.179", + "libc 0.2.180", "untrusted", "windows-sys 0.52.0", ] @@ -4594,7 +4612,7 @@ checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" dependencies = [ "bitflags 2.10.0", "errno", - "libc 0.2.179", + "libc 0.2.180", "linux-raw-sys 0.11.0", "windows-sys 0.61.2", ] @@ -4672,7 +4690,7 @@ dependencies = [ "bitflags 2.10.0", "cfg-if", "clipboard-win", - "libc 0.2.179", + "libc 0.2.180", "log", "memchr", "nix 0.30.1", @@ -4787,7 +4805,7 @@ dependencies = [ "bitflags 2.10.0", "core-foundation", "core-foundation-sys", - "libc 0.2.179", + "libc 0.2.180", "security-framework-sys", ] @@ -4798,7 +4816,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" dependencies = [ "core-foundation-sys", - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -5040,7 +5058,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" dependencies = [ "errno", - "libc 0.2.179", + "libc 0.2.180", ] [[package]] @@ -5122,7 +5140,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", "windows-sys 0.60.2", ] @@ -5434,7 +5452,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" dependencies = [ "bytes", - "libc 0.2.179", + "libc 0.2.180", "mio", "pin-project-lite", "signal-hook-registry", @@ -5512,7 +5530,7 @@ checksum = "8b319ef9394889dab2e1b4f0085b45ba11d0c79dc9d1a9d1afc057d009d0f1c7" dependencies = [ "bytes", "futures", - "libc 0.2.179", + "libc 0.2.180", "tokio", "vsock", ] @@ -5883,7 +5901,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2da6e4ac76cd19635dce0f98985378bb62f8044ee2ff80abd2a7334b920ed63" dependencies = [ - "libc 0.2.179", + "libc 0.2.180", "nix 0.30.1", ] diff --git a/Cargo.toml b/Cargo.toml index 0049318df..bc87089da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,8 @@ members = [ "interface-manager", "k8s-intf", "k8s-less", + "k8s-sample-crds", + "k8s-sample-derive", "left-right-tlcache", "mgmt", "nat", @@ -64,6 +66,8 @@ init = { path = "./init", package = "dataplane-init", features = [] } interface-manager = { path = "./interface-manager", package = "dataplane-interface-manager", features = [] } k8s-intf = { path = "./k8s-intf", package = "dataplane-k8s-intf", features = [] } k8s-less = { path = "./k8s-less", package = "dataplane-k8s-less", features = [] } +k8s-sample-crds = { path = "./k8s-sample-crds", package = "dataplane-k8s-sample-crds", features = [] } +k8s-sample-derive = { path = "./k8s-sample-derive", package = "dataplane-k8s-sample-derive", features = [] } left-right-tlcache = { path = "./left-right-tlcache", package = "dataplane-left-right-tlcache", features = [] } lpm = { path = "./lpm", package = "dataplane-lpm", features = [] } mgmt = { path = "./mgmt", package = "dataplane-mgmt", features = [] } diff --git a/k8s-intf/Cargo.toml b/k8s-intf/Cargo.toml index 95fc5fc8f..87126668b 100644 --- a/k8s-intf/Cargo.toml +++ b/k8s-intf/Cargo.toml @@ -15,6 +15,7 @@ lpm = { workspace = true, optional = true } net = { workspace = true, optional = true, features = ["bolero"] } tracectl = { workspace = true } tracing = { workspace = true } +k8s-sample-derive = { workspace = true } # external bolero = { workspace = true, optional = true } @@ -40,3 +41,4 @@ net = { workspace = true, features = ["bolero", "test_buffer"] } [build-dependencies] dotenvy = { workspace = true, features = [] } ureq = { workspace = true, features = ["rustls", "gzip"] } + diff --git a/k8s-intf/build.rs b/k8s-intf/build.rs index 05d58f45d..976b2957a 100644 --- a/k8s-intf/build.rs +++ b/k8s-intf/build.rs @@ -45,6 +45,8 @@ fn fetch_crd(url: &str) -> String { const LICENSE_PREAMBLE: &str = "// SPDX-License-Identifier: Apache-2.0 // Copyright Open Network Fabric Authors +use k8s_sample_derive::Sample; +use crate::samplegen::sample::Sample; "; /// Fixup the types in the generated Rust code @@ -75,7 +77,7 @@ fn fixup_types(raw: String) -> String { fn generate_rust_for_crd(crd_content: &str) -> String { // Run kopium with stdin input let mut child = std::process::Command::new("kopium") - .args(["-D", "PartialEq", "-Af", "-"]) + .args(["-D", "PartialEq", "-D", "Sample", "-Af", "-"]) .stdin(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped()) diff --git a/k8s-intf/src/generated/gateway_agent_crd.rs b/k8s-intf/src/generated/gateway_agent_crd.rs index 1728fe0dd..825c69f30 100644 --- a/k8s-intf/src/generated/gateway_agent_crd.rs +++ b/k8s-intf/src/generated/gateway_agent_crd.rs @@ -1,8 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Open Network Fabric Authors +use k8s_sample_derive::Sample; +use crate::samplegen::sample::Sample; // WARNING: generated by kopium - manual changes will be overwritten -// kopium command: kopium -D PartialEq -Af - +// kopium command: kopium -D PartialEq -D Sample -Af - // kopium version: 0.22.5 #[allow(unused_imports)] @@ -15,11 +17,12 @@ mod prelude { use self::prelude::*; /// GatewayAgentSpec defines the desired state of GatewayAgent. -#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] #[kube(group = "gwint.githedgehog.com", version = "v1alpha1", kind = "GatewayAgent", plural = "gatewayagents")] #[kube(namespaced)] #[kube(status = "GatewayAgentStatus")] #[kube(derive="PartialEq")] +#[kube(derive="Sample")] pub struct GatewayAgentSpec { /// AgentVersion is the desired version of the gateway agent to trigger generation changes on controller upgrades #[serde(default, skip_serializing_if = "Option::is_none", rename = "agentVersion")] @@ -38,7 +41,7 @@ pub struct GatewayAgentSpec { } /// GatewaySpec defines the desired state of Gateway. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentGateway { /// ASN is the ASN of the gateway #[serde(default, skip_serializing_if = "Option::is_none")] @@ -75,7 +78,7 @@ pub struct GatewayAgentGateway { pub workers: Option, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentGatewayGroups { /// Name is the name of the group to which the gateway belongs #[serde(default, skip_serializing_if = "Option::is_none")] @@ -86,7 +89,7 @@ pub struct GatewayAgentGatewayGroups { } /// Interfaces is a map of interface names to their configurations -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentGatewayInterfaces { /// IPs is the list of IP address to assign to the interface #[serde(default, skip_serializing_if = "Option::is_none")] @@ -103,7 +106,7 @@ pub struct GatewayAgentGatewayInterfaces { } /// Logs defines the configuration for logging levels -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentGatewayLogs { #[serde(default, skip_serializing_if = "Option::is_none")] pub default: Option, @@ -112,7 +115,7 @@ pub struct GatewayAgentGatewayLogs { } /// GatewayBGPNeighbor defines the configuration for a BGP neighbor -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentGatewayNeighbors { /// ASN is the remote ASN of the BGP neighbor #[serde(default, skip_serializing_if = "Option::is_none")] @@ -126,19 +129,19 @@ pub struct GatewayAgentGatewayNeighbors { } /// Profiling defines the configuration for profiling -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentGatewayProfiling { #[serde(default, skip_serializing_if = "Option::is_none")] pub enabled: Option, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentGroups { #[serde(default, skip_serializing_if = "Option::is_none")] pub members: Option>, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentGroupsMembers { pub name: String, pub priority: u32, @@ -146,7 +149,7 @@ pub struct GatewayAgentGroupsMembers { pub vtep_ip: String, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentPeerings { /// GatewayGroup is the name of the gateway group that should process the peering #[serde(default, skip_serializing_if = "Option::is_none", rename = "gatewayGroup")] @@ -157,13 +160,13 @@ pub struct GatewayAgentPeerings { } /// Peerings is a map of peering entries for each VPC participating in the peering (keyed by VPC name) -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentPeeringsPeering { #[serde(default, skip_serializing_if = "Option::is_none")] pub expose: Option>, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentPeeringsPeeringExpose { #[serde(default, skip_serializing_if = "Option::is_none", rename = "as")] pub r#as: Option>, @@ -173,7 +176,7 @@ pub struct GatewayAgentPeeringsPeeringExpose { pub nat: Option, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentPeeringsPeeringExposeAs { /// CIDR to include, only one of cidr, not can be set #[serde(default, skip_serializing_if = "Option::is_none")] @@ -186,7 +189,7 @@ pub struct GatewayAgentPeeringsPeeringExposeAs { pub ports: Option, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentPeeringsPeeringExposeIps { /// CIDR to include, only one of cidr, not, vpcSubnet can be set #[serde(default, skip_serializing_if = "Option::is_none")] @@ -202,7 +205,7 @@ pub struct GatewayAgentPeeringsPeeringExposeIps { pub vpc_subnet: Option, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentPeeringsPeeringExposeNat { /// Use connection state tracking when performing NAT #[serde(default, skip_serializing_if = "Option::is_none")] @@ -213,7 +216,7 @@ pub struct GatewayAgentPeeringsPeeringExposeNat { } /// Use connection state tracking when performing NAT -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentPeeringsPeeringExposeNatStateful { /// Time since the last packet after which flows are removed from the connection state table #[serde(default, skip_serializing_if = "Option::is_none", rename = "idleTimeout")] @@ -221,11 +224,11 @@ pub struct GatewayAgentPeeringsPeeringExposeNatStateful { } /// Use connection state tracking when performing NAT, use stateful NAT if omitted -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentPeeringsPeeringExposeNatStateless { } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentVpcs { #[serde(default, skip_serializing_if = "Option::is_none", rename = "internalID")] pub internal_id: Option, @@ -238,7 +241,7 @@ pub struct GatewayAgentVpcs { } /// Subnets is a map of all subnets in the VPC (incl. CIDRs, VNIs, etc) keyed by the subnet name -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentVpcsSubnets { /// CIDR is the subnet CIDR block, such as "10.0.0.0/24" #[serde(default, skip_serializing_if = "Option::is_none")] @@ -246,7 +249,7 @@ pub struct GatewayAgentVpcsSubnets { } /// GatewayAgentStatus defines the observed state of GatewayAgent. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentStatus { /// AgentVersion is the version of the gateway agent #[serde(default, skip_serializing_if = "Option::is_none", rename = "agentVersion")] @@ -266,7 +269,7 @@ pub struct GatewayAgentStatus { } /// State represents collected data from the dataplane API that includes FRR as well -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentStatusState { /// Dataplane is the status of the dataplane #[serde(default, skip_serializing_if = "Option::is_none")] @@ -286,14 +289,14 @@ pub struct GatewayAgentStatusState { } /// Dataplane is the status of the dataplane -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentStatusStateDataplane { #[serde(default, skip_serializing_if = "Option::is_none")] pub version: Option, } /// FRR is the status of the FRR daemon -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentStatusStateFrr { /// LastAppliedGen is the generation of the last successful application of a configuration to the FRR #[serde(default, skip_serializing_if = "Option::is_none", rename = "lastAppliedGen")] @@ -301,7 +304,7 @@ pub struct GatewayAgentStatusStateFrr { } /// Peerings is the status of the VPCs peerings where key is VPC1->VPC2 and data is for one direction only -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentStatusStatePeerings { /// Bytes is the number of bytes sent on the peering #[serde(default, skip_serializing_if = "Option::is_none")] @@ -321,7 +324,7 @@ pub struct GatewayAgentStatusStatePeerings { } /// VPCs is the status of the VPCs where key is the vpc (vpcinfo) name -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Sample, JsonSchema)] pub struct GatewayAgentStatusStateVpcs { /// Bytes is the number of bytes sent on the vpc #[serde(default, skip_serializing_if = "Option::is_none")] diff --git a/k8s-intf/src/generated/mod.rs b/k8s-intf/src/generated/mod.rs index 7c48aa95a..c720f69eb 100644 --- a/k8s-intf/src/generated/mod.rs +++ b/k8s-intf/src/generated/mod.rs @@ -5,3 +5,5 @@ #[allow(clippy::all, clippy::pedantic)] #[rustfmt::skip] pub mod gateway_agent_crd; + +pub use k8s_sample_derive::Sample; diff --git a/k8s-intf/src/lib.rs b/k8s-intf/src/lib.rs index d7d8dc0b2..8b0949efb 100644 --- a/k8s-intf/src/lib.rs +++ b/k8s-intf/src/lib.rs @@ -9,6 +9,7 @@ pub mod bolero; pub mod client; pub mod generated; +pub mod samplegen; pub mod utils; pub mod gateway_agent_crd { diff --git a/k8s-intf/src/samplegen/mod.rs b/k8s-intf/src/samplegen/mod.rs new file mode 100644 index 000000000..0d2157201 --- /dev/null +++ b/k8s-intf/src/samplegen/mod.rs @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Open Network Fabric Authors + +pub mod sample; + +use crate::gateway_agent_crd::GatewayAgentSpec; +use crate::samplegen::sample::Sample; + +use serde_json::to_string_pretty; +use std::fs; +use std::path::PathBuf; + +/// Generate sample json and yaml files in the indicated path +/// +/// # Errors +/// On error, this function returns a string describing what went wrong. +pub fn generate_samples(path: &str, filename: &str) -> Result<(), String> { + let crd = GatewayAgentSpec::sample(); + let json = to_string_pretty(&crd) + .map_err(|e| format!("Failed to serialize CRD as pretty-JSON: {e}"))?; + let yaml = serde_yaml_ng::to_string(&crd) + .map_err(|e| format!("Failed to serialize CRD as YAML: {e}"))?; + + let output_dir = PathBuf::from(path); + fs::create_dir_all(&output_dir) + .map_err(|e| format!("Failed to create output directory: {e}"))?; + + let mut jsonfile = PathBuf::from(path).join(filename); + jsonfile.set_extension("json"); + fs::write(&jsonfile, json).map_err(|e| format!("Failed to write sample JSON file: {e}"))?; + + let mut yamlfile = PathBuf::from(path).join(filename); + yamlfile.set_extension("yaml"); + fs::write(&yamlfile, yaml).map_err(|e| format!("Failed to write sample YAML file: {e}"))?; + + Ok(()) +} + +#[cfg(test)] +mod test { + use crate::gateway_agent_crd::GatewayAgentSpec; + use crate::samplegen::sample::Sample; + use serde_json::to_string_pretty; + + // This basically tests that sample can be built + #[test] + fn test_samples() { + let crd = GatewayAgentSpec::sample(); + println!("\n CRD in Rust:\n"); + println!("{crd:#?}"); + + let json = to_string_pretty(&crd).unwrap(); + println!("\n CRD in JSON:\n"); + println!("{json}"); + + let yaml = serde_yaml_ng::to_string(&crd).unwrap(); + println!("\n CRD in YAML:\n"); + println!("{yaml}"); + } +} diff --git a/k8s-intf/src/samplegen/sample.rs b/k8s-intf/src/samplegen/sample.rs new file mode 100644 index 000000000..80c32ac61 --- /dev/null +++ b/k8s-intf/src/samplegen/sample.rs @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Open Network Fabric Authors + +//! Implements trait `Sample` to generate sample json objects from the CRD + +use kube::api::ObjectMeta; +use std::collections::BTreeMap; +use std::time::Duration; + +/// Somewhat dummy trait to generate sample data. +/// We implement this trait for all of the types present in our CRD. +pub trait Sample { + fn sample() -> Self; +} + +impl Sample for String { + fn sample() -> Self { + "FIXME".to_string() + } +} +impl Sample for bool { + fn sample() -> Self { + false + } +} +impl Sample for u8 { + fn sample() -> Self { + 0 + } +} +impl Sample for i32 { + fn sample() -> Self { + 0 + } +} +impl Sample for i64 { + fn sample() -> Self { + 0 + } +} +impl Sample for u32 { + fn sample() -> Self { + 0 + } +} +impl Sample for u64 { + fn sample() -> Self { + 0 + } +} +impl Sample for f64 { + fn sample() -> Self { + 0.0 + } +} +impl Sample for Duration { + fn sample() -> Self { + Duration::new(0, 0) + } +} +impl Sample for ObjectMeta { + fn sample() -> Self { + ObjectMeta::default() + } +} +impl Sample for Option { + fn sample() -> Self { + Some(T::sample()) + } +} +impl Sample for Vec { + fn sample() -> Self { + vec![T::sample(), T::sample()] + } +} + +// impl Sample for BTreeMap { +// fn sample() -> Self { +// let mut tree = BTreeMap::new(); +// tree.insert(K::default(), V::sample()); +// tree +// } +// } + +impl Sample for BTreeMap { + fn sample() -> Self { + let mut tree = BTreeMap::new(); + tree.insert("fixme-key-1".to_string(), V::sample()); + tree.insert("fixme-key-2".to_string(), V::sample()); + tree + } +} diff --git a/k8s-sample-crds/Cargo.toml b/k8s-sample-crds/Cargo.toml new file mode 100644 index 000000000..5b9121619 --- /dev/null +++ b/k8s-sample-crds/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "dataplane-k8s-sample-crds" +version.workspace = true +edition.workspace = true +license.workspace = true +publish.workspace = true +repository.workspace = true + +[dependencies] +k8s-intf = { workspace = true } + +[build-dependencies] +k8s-intf = { workspace = true } \ No newline at end of file diff --git a/k8s-sample-crds/build.rs b/k8s-sample-crds/build.rs new file mode 100644 index 000000000..a9f0be810 --- /dev/null +++ b/k8s-sample-crds/build.rs @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Open Network Fabric Authors + +//! Autogenerated CRD sample/templates + +use k8s_intf::samplegen::generate_samples; + +const SAMPLES_OUT_DIR: &str = "generated-samples"; +const SAMPLE_FILE_NAME: &str = "sample"; + +fn main() { + if let Err(e) = generate_samples(SAMPLES_OUT_DIR, SAMPLE_FILE_NAME) { + eprintln!("Failed to generate CRD JSON/YAML samples: {e}"); + std::process::exit(1); + } + println!("Successfully generated CRD JSON + YAML samples in folder '{SAMPLES_OUT_DIR}'"); +} diff --git a/k8s-sample-crds/generated-samples/sample.json b/k8s-sample-crds/generated-samples/sample.json new file mode 100644 index 000000000..967e6fb3f --- /dev/null +++ b/k8s-sample-crds/generated-samples/sample.json @@ -0,0 +1,447 @@ +{ + "agentVersion": "FIXME", + "communities": { + "fixme-key-1": "FIXME", + "fixme-key-2": "FIXME" + }, + "gateway": { + "asn": 0, + "groups": [ + { + "name": "FIXME", + "priority": 0 + }, + { + "name": "FIXME", + "priority": 0 + } + ], + "interfaces": { + "fixme-key-1": { + "ips": [ + "FIXME", + "FIXME" + ], + "kernel": "FIXME", + "mtu": 0, + "pci": "FIXME" + }, + "fixme-key-2": { + "ips": [ + "FIXME", + "FIXME" + ], + "kernel": "FIXME", + "mtu": 0, + "pci": "FIXME" + } + }, + "logs": { + "default": "FIXME", + "tags": { + "fixme-key-1": "FIXME", + "fixme-key-2": "FIXME" + } + }, + "neighbors": [ + { + "asn": 0, + "ip": "FIXME", + "source": "FIXME" + }, + { + "asn": 0, + "ip": "FIXME", + "source": "FIXME" + } + ], + "profiling": { + "enabled": false + }, + "protocolIP": "FIXME", + "vtepIP": "FIXME", + "vtepMAC": "FIXME", + "vtepMTU": 0, + "workers": 0 + }, + "groups": { + "fixme-key-1": { + "members": [ + { + "name": "FIXME", + "priority": 0, + "vtepIP": "FIXME" + }, + { + "name": "FIXME", + "priority": 0, + "vtepIP": "FIXME" + } + ] + }, + "fixme-key-2": { + "members": [ + { + "name": "FIXME", + "priority": 0, + "vtepIP": "FIXME" + }, + { + "name": "FIXME", + "priority": 0, + "vtepIP": "FIXME" + } + ] + } + }, + "peerings": { + "fixme-key-1": { + "gatewayGroup": "FIXME", + "peering": { + "fixme-key-1": { + "expose": [ + { + "as": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + } + ], + "ips": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + } + ], + "nat": { + "stateful": { + "idleTimeout": { + "secs": 0, + "nanos": 0 + } + }, + "stateless": {} + } + }, + { + "as": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + } + ], + "ips": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + } + ], + "nat": { + "stateful": { + "idleTimeout": { + "secs": 0, + "nanos": 0 + } + }, + "stateless": {} + } + } + ] + }, + "fixme-key-2": { + "expose": [ + { + "as": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + } + ], + "ips": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + } + ], + "nat": { + "stateful": { + "idleTimeout": { + "secs": 0, + "nanos": 0 + } + }, + "stateless": {} + } + }, + { + "as": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + } + ], + "ips": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + } + ], + "nat": { + "stateful": { + "idleTimeout": { + "secs": 0, + "nanos": 0 + } + }, + "stateless": {} + } + } + ] + } + } + }, + "fixme-key-2": { + "gatewayGroup": "FIXME", + "peering": { + "fixme-key-1": { + "expose": [ + { + "as": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + } + ], + "ips": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + } + ], + "nat": { + "stateful": { + "idleTimeout": { + "secs": 0, + "nanos": 0 + } + }, + "stateless": {} + } + }, + { + "as": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + } + ], + "ips": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + } + ], + "nat": { + "stateful": { + "idleTimeout": { + "secs": 0, + "nanos": 0 + } + }, + "stateless": {} + } + } + ] + }, + "fixme-key-2": { + "expose": [ + { + "as": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + } + ], + "ips": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + } + ], + "nat": { + "stateful": { + "idleTimeout": { + "secs": 0, + "nanos": 0 + } + }, + "stateless": {} + } + }, + { + "as": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME" + } + ], + "ips": [ + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + }, + { + "cidr": "FIXME", + "not": "FIXME", + "ports": "FIXME", + "vpcSubnet": "FIXME" + } + ], + "nat": { + "stateful": { + "idleTimeout": { + "secs": 0, + "nanos": 0 + } + }, + "stateless": {} + } + } + ] + } + } + } + }, + "vpcs": { + "fixme-key-1": { + "internalID": "FIXME", + "subnets": { + "fixme-key-1": { + "cidr": "FIXME" + }, + "fixme-key-2": { + "cidr": "FIXME" + } + }, + "vni": 0 + }, + "fixme-key-2": { + "internalID": "FIXME", + "subnets": { + "fixme-key-1": { + "cidr": "FIXME" + }, + "fixme-key-2": { + "cidr": "FIXME" + } + }, + "vni": 0 + } + } +} \ No newline at end of file diff --git a/k8s-sample-crds/generated-samples/sample.yaml b/k8s-sample-crds/generated-samples/sample.yaml new file mode 100644 index 000000000..a60cd44e4 --- /dev/null +++ b/k8s-sample-crds/generated-samples/sample.yaml @@ -0,0 +1,270 @@ +agentVersion: FIXME +communities: + fixme-key-1: FIXME + fixme-key-2: FIXME +gateway: + asn: 0 + groups: + - name: FIXME + priority: 0 + - name: FIXME + priority: 0 + interfaces: + fixme-key-1: + ips: + - FIXME + - FIXME + kernel: FIXME + mtu: 0 + pci: FIXME + fixme-key-2: + ips: + - FIXME + - FIXME + kernel: FIXME + mtu: 0 + pci: FIXME + logs: + default: FIXME + tags: + fixme-key-1: FIXME + fixme-key-2: FIXME + neighbors: + - asn: 0 + ip: FIXME + source: FIXME + - asn: 0 + ip: FIXME + source: FIXME + profiling: + enabled: false + protocolIP: FIXME + vtepIP: FIXME + vtepMAC: FIXME + vtepMTU: 0 + workers: 0 +groups: + fixme-key-1: + members: + - name: FIXME + priority: 0 + vtepIP: FIXME + - name: FIXME + priority: 0 + vtepIP: FIXME + fixme-key-2: + members: + - name: FIXME + priority: 0 + vtepIP: FIXME + - name: FIXME + priority: 0 + vtepIP: FIXME +peerings: + fixme-key-1: + gatewayGroup: FIXME + peering: + fixme-key-1: + expose: + - as: + - cidr: FIXME + not: FIXME + ports: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + ips: + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + nat: + stateful: + idleTimeout: + secs: 0 + nanos: 0 + stateless: {} + - as: + - cidr: FIXME + not: FIXME + ports: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + ips: + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + nat: + stateful: + idleTimeout: + secs: 0 + nanos: 0 + stateless: {} + fixme-key-2: + expose: + - as: + - cidr: FIXME + not: FIXME + ports: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + ips: + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + nat: + stateful: + idleTimeout: + secs: 0 + nanos: 0 + stateless: {} + - as: + - cidr: FIXME + not: FIXME + ports: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + ips: + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + nat: + stateful: + idleTimeout: + secs: 0 + nanos: 0 + stateless: {} + fixme-key-2: + gatewayGroup: FIXME + peering: + fixme-key-1: + expose: + - as: + - cidr: FIXME + not: FIXME + ports: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + ips: + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + nat: + stateful: + idleTimeout: + secs: 0 + nanos: 0 + stateless: {} + - as: + - cidr: FIXME + not: FIXME + ports: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + ips: + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + nat: + stateful: + idleTimeout: + secs: 0 + nanos: 0 + stateless: {} + fixme-key-2: + expose: + - as: + - cidr: FIXME + not: FIXME + ports: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + ips: + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + nat: + stateful: + idleTimeout: + secs: 0 + nanos: 0 + stateless: {} + - as: + - cidr: FIXME + not: FIXME + ports: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + ips: + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + - cidr: FIXME + not: FIXME + ports: FIXME + vpcSubnet: FIXME + nat: + stateful: + idleTimeout: + secs: 0 + nanos: 0 + stateless: {} +vpcs: + fixme-key-1: + internalID: FIXME + subnets: + fixme-key-1: + cidr: FIXME + fixme-key-2: + cidr: FIXME + vni: 0 + fixme-key-2: + internalID: FIXME + subnets: + fixme-key-1: + cidr: FIXME + fixme-key-2: + cidr: FIXME + vni: 0 diff --git a/k8s-sample-crds/src/lib.rs b/k8s-sample-crds/src/lib.rs new file mode 100644 index 000000000..373666671 --- /dev/null +++ b/k8s-sample-crds/src/lib.rs @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Open Network Fabric Authors + +//! Tiny crate to automatically generate JSON/YAML CRD templates +//! These are mostly for manual testing. + +#[cfg(test)] +mod test { + use k8s_intf::utils::load_crd_from_file; + + #[test] + fn test_load_crd_from_file() { + let crd_from_json = load_crd_from_file("generated-samples/sample.yaml").unwrap(); + let crd_from_yaml = load_crd_from_file("generated-samples/sample.json").unwrap(); + + assert_eq!(crd_from_json, crd_from_yaml); + } +} diff --git a/k8s-sample-derive/Cargo.toml b/k8s-sample-derive/Cargo.toml new file mode 100644 index 000000000..d01b8b601 --- /dev/null +++ b/k8s-sample-derive/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "dataplane-k8s-sample-derive" +version.workspace = true +edition.workspace = true +license.workspace = true +publish.workspace = true +repository.workspace = true + +[lib] +proc-macro = true + +[dependencies] +syn = { workspace = true, features = ["derive", "parsing", "proc-macro", "full"] } +quote = { workspace = true } +proc-macro2 = { workspace = true } +schemars = { workspace = true, features = ["derive", "std"] } diff --git a/k8s-sample-derive/src/lib.rs b/k8s-sample-derive/src/lib.rs new file mode 100644 index 000000000..040976e58 --- /dev/null +++ b/k8s-sample-derive/src/lib.rs @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Open Network Fabric Authors + +extern crate proc_macro; + +use proc_macro::TokenStream; +use quote::quote; +use syn::{Data, DeriveInput, Fields, Type, TypePath, parse_macro_input}; + +#[proc_macro_derive(Sample)] +pub fn derive_sample(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let name = &input.ident; + + let field_inits = match &input.data { + Data::Struct(data_struct) => match &data_struct.fields { + Fields::Named(fields_named) => { + let inits: Vec<_> = fields_named + .named + .iter() + .map(|f| { + let fname = f.ident.as_ref().unwrap(); + + match &f.ty { + Type::Path(TypePath { path, .. }) => { + quote! { + #fname: <#path as Sample>::sample() + } + } + _ => panic!("Unsupported field type"), + } + }) + .collect(); + + quote! { #(#inits),* } + } + _ => unimplemented!(), + }, + _ => unimplemented!(), + }; + + let expanded = quote! { + impl Sample for #name { + fn sample() -> Self { + Self { #field_inits } + } + } + }; + + // uncomment to debug + // eprintln!("{}", expanded); + + TokenStream::from(expanded) +}