diff --git a/gateway-api/Cargo.toml b/gateway-api/Cargo.toml index 7fa30cb..81cef86 100644 --- a/gateway-api/Cargo.toml +++ b/gateway-api/Cargo.toml @@ -25,7 +25,7 @@ serde.workspace = true serde_yaml.workspace = true [dev-dependencies] -k8s-openapi = { workspace = true, features = [ "v1_32", "schemars" ] } +k8s-openapi = { workspace = true, features = ["v1_32", "schemars"] } kube = { workspace = true, features = ["derive"] } anyhow.workspace = true @@ -35,4 +35,8 @@ tower.workspace = true uuid.workspace = true [package.metadata.docs.rs] -features = [ "k8s-openapi/v1_32" ] +features = ["k8s-openapi/v1_32"] + +[features] +default = [] +experimental = [] diff --git a/gateway-api/src/lib.rs b/gateway-api/src/lib.rs index dc3fbc1..e3fc72e 100644 --- a/gateway-api/src/lib.rs +++ b/gateway-api/src/lib.rs @@ -1,7 +1,10 @@ -pub mod apis; - pub mod duration; pub use duration::Duration; +pub mod apis; +pub use apis::standard::*; + +#[cfg(feature = "experimental")] +pub use apis::experimental; #[cfg(test)] mod tests { @@ -22,7 +25,7 @@ mod tests { use tower::ServiceBuilder; use uuid::Uuid; - use crate::apis::standard::{ + use crate::{ constants::{ GatewayConditionReason, GatewayConditionType, ListenerConditionReason, ListenerConditionType, diff --git a/update.sh b/update.sh index ff1183d..296806e 100755 --- a/update.sh +++ b/update.sh @@ -34,24 +34,26 @@ EXPERIMENTAL_APIS=( udproutes ) -rm -rf gateway-api/src/apis/ +export APIS_DIR='gateway-api/src/apis' +rm -rf $APIS_DIR/standard/ +rm -rf $APIS_DIR/experimental/ -mkdir -p gateway-api/src/apis/ -cat << EOF > gateway-api/src/apis/mod.rs +cat << EOF > $APIS_DIR/mod.rs pub mod experimental; pub mod standard; EOF -mkdir -p gateway-api/src/apis/standard/ -mkdir -p gateway-api/src/apis/experimental/ -echo "// WARNING! generated file do not edit" > gateway-api/src/apis/standard/mod.rs +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[@]}" do echo "generating standard api ${API}" - 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 - echo "pub mod ${API};" >> gateway-api/src/apis/standard/mod.rs + 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 + echo "pub mod ${API};" >> $APIS_DIR/standard/mod.rs done # 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[@]}") ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1} # The task searches for $GATEWAY_API_ENUMS in the enviornment to get the enum names and their default variants. -GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> gateway-api/src/apis/standard/enum_defaults.rs -echo "mod enum_defaults;" >> gateway-api/src/apis/standard/mod.rs +GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/standard/enum_defaults.rs +echo "mod enum_defaults;" >> $APIS_DIR/standard/mod.rs GATEWAY_CLASS_CONDITION_CONSTANTS="GatewayClassConditionType=Accepted" GATEWAY_CLASS_REASON_CONSTANTS="GatewayClassConditionReason=Accepted,InvalidParameters,Pending,Unsupported,Waiting" @@ -84,16 +86,16 @@ LISTENER_REASON_CONSTANTS="ListenerConditionReason=HostnameConflict,ProtocolConf GATEWAY_CLASS_CONDITION_CONSTANTS=${GATEWAY_CLASS_CONDITION_CONSTANTS} GATEWAY_CLASS_REASON_CONSTANTS=${GATEWAY_CLASS_REASON_CONSTANTS} \ GATEWAY_CONDITION_CONSTANTS=${GATEWAY_CONDITION_CONSTANTS} GATEWAY_REASON_CONSTANTS=${GATEWAY_REASON_CONSTANTS} \ LISTENER_CONDITION_CONSTANTS=${LISTENER_CONDITION_CONSTANTS} LISTENER_REASON_CONSTANTS=${LISTENER_REASON_CONSTANTS} \ - cargo xtask gen_condition_constants >> gateway-api/src/apis/standard/constants.rs -echo "pub mod constants;" >> gateway-api/src/apis/standard/mod.rs + cargo xtask gen_condition_constants >> $APIS_DIR/standard/constants.rs +echo "pub mod constants;" >> $APIS_DIR/standard/mod.rs -echo "// WARNING! generated file do not edit" > gateway-api/src/apis/experimental/mod.rs +echo "// WARNING! generated file do not edit" > $APIS_DIR/experimental/mod.rs for API in "${EXPERIMENTAL_APIS[@]}" do echo "generating experimental api $API" - 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 - echo "pub mod ${API};" >> gateway-api/src/apis/experimental/mod.rs + 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 + echo "pub mod ${API};" >> $APIS_DIR/experimental/mod.rs done # Experimental API enums that need a Default trait impl along with their respective default variant. @@ -110,8 +112,8 @@ ENUMS=( ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}") ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1} -GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> gateway-api/src/apis/experimental/enum_defaults.rs -echo "mod enum_defaults;" >> gateway-api/src/apis/experimental/mod.rs +GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/experimental/enum_defaults.rs +echo "mod enum_defaults;" >> $APIS_DIR/experimental/mod.rs # GatewayClass conditions vary between standard and experimental GATEWAY_CLASS_CONDITION_CONSTANTS="${GATEWAY_CLASS_CONDITION_CONSTANTS},SupportedVersion" @@ -120,8 +122,9 @@ GATEWAY_CLASS_REASON_CONSTANTS="${GATEWAY_CLASS_REASON_CONSTANTS},SupportedVersi GATEWAY_CLASS_CONDITION_CONSTANTS=${GATEWAY_CLASS_CONDITION_CONSTANTS} GATEWAY_CLASS_REASON_CONSTANTS=${GATEWAY_CLASS_REASON_CONSTANTS} \ GATEWAY_CONDITION_CONSTANTS=${GATEWAY_CONDITION_CONSTANTS} GATEWAY_REASON_CONSTANTS=${GATEWAY_REASON_CONSTANTS} \ LISTENER_CONDITION_CONSTANTS=${LISTENER_CONDITION_CONSTANTS} LISTENER_REASON_CONSTANTS=${LISTENER_REASON_CONSTANTS} \ - cargo xtask gen_condition_constants >> gateway-api/src/apis/experimental/constants.rs -echo "pub mod constants;" >> gateway-api/src/apis/experimental/mod.rs + cargo xtask gen_condition_constants >> $APIS_DIR/experimental/constants.rs +echo "pub mod constants;" >> $APIS_DIR/experimental/mod.rs # Format the code. cargo fmt +