Skip to content

Commit 57f6478

Browse files
committed
Pulling standard APIs up and hiding experimental apis behind a feature flag
Signed-off-by: Dawid Nowak <nowakd@gmail.com>
1 parent d45de05 commit 57f6478

25 files changed

+43
-27
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ name = "gateway-api"
331331
version = "0.15.0"
332332
dependencies = [
333333
"anyhow",
334+
"cfg-if",
334335
"delegate",
335336
"hyper-util",
336337
"k8s-openapi",

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ version = "0.15.0"
1010

1111
[workspace.dependencies]
1212
anyhow = "1.0.98"
13+
cfg-if = "1.0"
1314
delegate = "0.13.3"
1415
hyper-util = "0.1.11"
1516
kube = { version = "0.99.0" }
@@ -25,3 +26,4 @@ tower = { version = "0.5.2", features = ["limit"] }
2526
tracing = "0.1.41"
2627
tracing-subscriber = "0.3.19"
2728
uuid = { version = "1.16.0", features = ["v4", "fast-rng"] }
29+

gateway-api/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ schemars.workspace = true
2323
serde_json.workspace = true
2424
serde.workspace = true
2525
serde_yaml.workspace = true
26+
cfg-if.workspace = true
2627

2728
[dev-dependencies]
2829
k8s-openapi = { workspace = true, features = [ "v1_32", "schemars" ] }
@@ -36,3 +37,7 @@ uuid.workspace = true
3637

3738
[package.metadata.docs.rs]
3839
features = [ "k8s-openapi/v1_32" ]
40+
41+
[features]
42+
default = []
43+
experimental = []

gateway-api/src/apis/mod.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

gateway-api/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
pub mod apis;
2-
31
pub mod duration;
42
pub use duration::Duration;
3+
pub mod standard;
4+
pub use standard::*;
5+
6+
cfg_if::cfg_if! {
7+
if #[cfg(feature = "experimental")] {
8+
pub mod experimental;
9+
} else {
10+
11+
}
12+
}
513

614
#[cfg(test)]
715
mod tests {
@@ -22,7 +30,7 @@ mod tests {
2230
use tower::ServiceBuilder;
2331
use uuid::Uuid;
2432

25-
use crate::apis::standard::{
33+
use crate::{
2634
constants::{
2735
GatewayConditionReason, GatewayConditionType, ListenerConditionReason,
2836
ListenerConditionType,

update.sh

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,25 @@ EXPERIMENTAL_APIS=(
3434
udproutes
3535
)
3636

37-
rm -rf gateway-api/src/apis/
37+
rm -rf gateway-api/src/standard/
38+
rm -rf gateway-api/src/experimental/
3839

39-
mkdir -p gateway-api/src/apis/
40-
cat << EOF > gateway-api/src/apis/mod.rs
41-
pub mod experimental;
42-
pub mod standard;
43-
EOF
40+
# mkdir -p gateway-api/src/standard/
41+
# cat << EOF > gateway-api/src/standard/mod.rs
42+
# pub mod experimental;
43+
# pub mod standard;
44+
# EOF
4445

45-
mkdir -p gateway-api/src/apis/standard/
46-
mkdir -p gateway-api/src/apis/experimental/
46+
mkdir -p gateway-api/src/standard/
47+
mkdir -p gateway-api/src/experimental/
4748

48-
echo "// WARNING! generated file do not edit" > gateway-api/src/apis/standard/mod.rs
49+
echo "// WARNING! generated file do not edit" > gateway-api/src/standard/mod.rs
4950

5051
for API in "${STANDARD_APIS[@]}"
5152
do
5253
echo "generating standard api ${API}"
53-
curl -sSL "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/${VERSION}/config/crd/standard/gateway.networking.k8s.io_${API}.yaml" | kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - > gateway-api/src/apis/standard/${API}.rs
54-
echo "pub mod ${API};" >> gateway-api/src/apis/standard/mod.rs
54+
curl -sSL "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/${VERSION}/config/crd/standard/gateway.networking.k8s.io_${API}.yaml" | kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - > gateway-api/src/standard/${API}.rs
55+
echo "pub mod ${API};" >> gateway-api/src/standard/mod.rs
5556
done
5657

5758
# Standard API enums that need a Default trait impl along with their respective default variant.
@@ -71,8 +72,8 @@ ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}")
7172
ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1}
7273

7374
# The task searches for $GATEWAY_API_ENUMS in the enviornment to get the enum names and their default variants.
74-
GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> gateway-api/src/apis/standard/enum_defaults.rs
75-
echo "mod enum_defaults;" >> gateway-api/src/apis/standard/mod.rs
75+
GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> gateway-api/src/standard/enum_defaults.rs
76+
echo "mod enum_defaults;" >> gateway-api/src/standard/mod.rs
7677

7778
GATEWAY_CLASS_CONDITION_CONSTANTS="GatewayClassConditionType=Accepted"
7879
GATEWAY_CLASS_REASON_CONSTANTS="GatewayClassConditionReason=Accepted,InvalidParameters,Pending,Unsupported,Waiting"
@@ -84,16 +85,16 @@ LISTENER_REASON_CONSTANTS="ListenerConditionReason=HostnameConflict,ProtocolConf
8485
GATEWAY_CLASS_CONDITION_CONSTANTS=${GATEWAY_CLASS_CONDITION_CONSTANTS} GATEWAY_CLASS_REASON_CONSTANTS=${GATEWAY_CLASS_REASON_CONSTANTS} \
8586
GATEWAY_CONDITION_CONSTANTS=${GATEWAY_CONDITION_CONSTANTS} GATEWAY_REASON_CONSTANTS=${GATEWAY_REASON_CONSTANTS} \
8687
LISTENER_CONDITION_CONSTANTS=${LISTENER_CONDITION_CONSTANTS} LISTENER_REASON_CONSTANTS=${LISTENER_REASON_CONSTANTS} \
87-
cargo xtask gen_condition_constants >> gateway-api/src/apis/standard/constants.rs
88-
echo "pub mod constants;" >> gateway-api/src/apis/standard/mod.rs
88+
cargo xtask gen_condition_constants >> gateway-api/src/standard/constants.rs
89+
echo "pub mod constants;" >> gateway-api/src/standard/mod.rs
8990

90-
echo "// WARNING! generated file do not edit" > gateway-api/src/apis/experimental/mod.rs
91+
echo "// WARNING! generated file do not edit" > gateway-api/src/experimental/mod.rs
9192

9293
for API in "${EXPERIMENTAL_APIS[@]}"
9394
do
9495
echo "generating experimental api $API"
95-
curl -sSL "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/${VERSION}/config/crd/experimental/gateway.networking.k8s.io_${API}.yaml" | kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - > gateway-api/src/apis/experimental/${API}.rs
96-
echo "pub mod ${API};" >> gateway-api/src/apis/experimental/mod.rs
96+
curl -sSL "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/${VERSION}/config/crd/experimental/gateway.networking.k8s.io_${API}.yaml" | kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - > gateway-api/src/experimental/${API}.rs
97+
echo "pub mod ${API};" >> gateway-api/src/experimental/mod.rs
9798
done
9899

99100
# Experimental API enums that need a Default trait impl along with their respective default variant.
@@ -110,8 +111,8 @@ ENUMS=(
110111

111112
ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}")
112113
ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1}
113-
GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> gateway-api/src/apis/experimental/enum_defaults.rs
114-
echo "mod enum_defaults;" >> gateway-api/src/apis/experimental/mod.rs
114+
GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> gateway-api/src/experimental/enum_defaults.rs
115+
echo "mod enum_defaults;" >> gateway-api/src/experimental/mod.rs
115116

116117
# GatewayClass conditions vary between standard and experimental
117118
GATEWAY_CLASS_CONDITION_CONSTANTS="${GATEWAY_CLASS_CONDITION_CONSTANTS},SupportedVersion"
@@ -120,8 +121,9 @@ GATEWAY_CLASS_REASON_CONSTANTS="${GATEWAY_CLASS_REASON_CONSTANTS},SupportedVersi
120121
GATEWAY_CLASS_CONDITION_CONSTANTS=${GATEWAY_CLASS_CONDITION_CONSTANTS} GATEWAY_CLASS_REASON_CONSTANTS=${GATEWAY_CLASS_REASON_CONSTANTS} \
121122
GATEWAY_CONDITION_CONSTANTS=${GATEWAY_CONDITION_CONSTANTS} GATEWAY_REASON_CONSTANTS=${GATEWAY_REASON_CONSTANTS} \
122123
LISTENER_CONDITION_CONSTANTS=${LISTENER_CONDITION_CONSTANTS} LISTENER_REASON_CONSTANTS=${LISTENER_REASON_CONSTANTS} \
123-
cargo xtask gen_condition_constants >> gateway-api/src/apis/experimental/constants.rs
124-
echo "pub mod constants;" >> gateway-api/src/apis/experimental/mod.rs
124+
cargo xtask gen_condition_constants >> gateway-api/src/experimental/constants.rs
125+
echo "pub mod constants;" >> gateway-api/src/experimental/mod.rs
125126

126127
# Format the code.
127128
cargo fmt
129+

0 commit comments

Comments
 (0)