Skip to content

Commit aabb28e

Browse files
authored
Pulling standard APIs up and hiding experimental apis behind a feature flag (#137)
Signed-off-by: Dawid Nowak <[email protected]>
1 parent d45de05 commit aabb28e

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

gateway-api/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ serde.workspace = true
2525
serde_yaml.workspace = true
2626

2727
[dev-dependencies]
28-
k8s-openapi = { workspace = true, features = [ "v1_32", "schemars" ] }
28+
k8s-openapi = { workspace = true, features = ["v1_32", "schemars"] }
2929
kube = { workspace = true, features = ["derive"] }
3030

3131
anyhow.workspace = true
@@ -35,4 +35,8 @@ tower.workspace = true
3535
uuid.workspace = true
3636

3737
[package.metadata.docs.rs]
38-
features = [ "k8s-openapi/v1_32" ]
38+
features = ["k8s-openapi/v1_32"]
39+
40+
[features]
41+
default = []
42+
experimental = []

gateway-api/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
pub mod apis;
2-
31
pub mod duration;
42
pub use duration::Duration;
3+
pub mod apis;
4+
pub use apis::standard::*;
5+
6+
#[cfg(feature = "experimental")]
7+
pub use apis::experimental;
58

69
#[cfg(test)]
710
mod tests {
@@ -22,7 +25,7 @@ mod tests {
2225
use tower::ServiceBuilder;
2326
use uuid::Uuid;
2427

25-
use crate::apis::standard::{
28+
use crate::{
2629
constants::{
2730
GatewayConditionReason, GatewayConditionType, ListenerConditionReason,
2831
ListenerConditionType,

update.sh

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

37-
rm -rf gateway-api/src/apis/
37+
export APIS_DIR='gateway-api/src/apis'
38+
rm -rf $APIS_DIR/standard/
39+
rm -rf $APIS_DIR/experimental/
3840

39-
mkdir -p gateway-api/src/apis/
40-
cat << EOF > gateway-api/src/apis/mod.rs
41+
cat << EOF > $APIS_DIR/mod.rs
4142
pub mod experimental;
4243
pub mod standard;
4344
EOF
4445

45-
mkdir -p gateway-api/src/apis/standard/
46-
mkdir -p gateway-api/src/apis/experimental/
4746

48-
echo "// WARNING! generated file do not edit" > gateway-api/src/apis/standard/mod.rs
47+
mkdir -p $APIS_DIR/standard/
48+
mkdir -p $APIS_DIR/experimental/
49+
50+
echo "// WARNING! generated file do not edit" > $APIS_DIR/standard/mod.rs
4951

5052
for API in "${STANDARD_APIS[@]}"
5153
do
5254
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
55+
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 - > $APIS_DIR/standard/${API}.rs
56+
echo "pub mod ${API};" >> $APIS_DIR/standard/mod.rs
5557
done
5658

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

7375
# 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
76+
GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/standard/enum_defaults.rs
77+
echo "mod enum_defaults;" >> $APIS_DIR/standard/mod.rs
7678

7779
GATEWAY_CLASS_CONDITION_CONSTANTS="GatewayClassConditionType=Accepted"
7880
GATEWAY_CLASS_REASON_CONSTANTS="GatewayClassConditionReason=Accepted,InvalidParameters,Pending,Unsupported,Waiting"
@@ -84,16 +86,16 @@ LISTENER_REASON_CONSTANTS="ListenerConditionReason=HostnameConflict,ProtocolConf
8486
GATEWAY_CLASS_CONDITION_CONSTANTS=${GATEWAY_CLASS_CONDITION_CONSTANTS} GATEWAY_CLASS_REASON_CONSTANTS=${GATEWAY_CLASS_REASON_CONSTANTS} \
8587
GATEWAY_CONDITION_CONSTANTS=${GATEWAY_CONDITION_CONSTANTS} GATEWAY_REASON_CONSTANTS=${GATEWAY_REASON_CONSTANTS} \
8688
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
89+
cargo xtask gen_condition_constants >> $APIS_DIR/standard/constants.rs
90+
echo "pub mod constants;" >> $APIS_DIR/standard/mod.rs
8991

90-
echo "// WARNING! generated file do not edit" > gateway-api/src/apis/experimental/mod.rs
92+
echo "// WARNING! generated file do not edit" > $APIS_DIR/experimental/mod.rs
9193

9294
for API in "${EXPERIMENTAL_APIS[@]}"
9395
do
9496
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
97+
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 - > $APIS_DIR/experimental/${API}.rs
98+
echo "pub mod ${API};" >> $APIS_DIR/experimental/mod.rs
9799
done
98100

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

111113
ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}")
112114
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
115+
GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/experimental/enum_defaults.rs
116+
echo "mod enum_defaults;" >> $APIS_DIR/experimental/mod.rs
115117

116118
# GatewayClass conditions vary between standard and experimental
117119
GATEWAY_CLASS_CONDITION_CONSTANTS="${GATEWAY_CLASS_CONDITION_CONSTANTS},SupportedVersion"
@@ -120,8 +122,9 @@ GATEWAY_CLASS_REASON_CONSTANTS="${GATEWAY_CLASS_REASON_CONSTANTS},SupportedVersi
120122
GATEWAY_CLASS_CONDITION_CONSTANTS=${GATEWAY_CLASS_CONDITION_CONSTANTS} GATEWAY_CLASS_REASON_CONSTANTS=${GATEWAY_CLASS_REASON_CONSTANTS} \
121123
GATEWAY_CONDITION_CONSTANTS=${GATEWAY_CONDITION_CONSTANTS} GATEWAY_REASON_CONSTANTS=${GATEWAY_REASON_CONSTANTS} \
122124
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
125+
cargo xtask gen_condition_constants >> $APIS_DIR/experimental/constants.rs
126+
echo "pub mod constants;" >> $APIS_DIR/experimental/mod.rs
125127

126128
# Format the code.
127129
cargo fmt
130+

0 commit comments

Comments
 (0)