From dfe9926bae6b6c0c0e80933352362e589ab32b04 Mon Sep 17 00:00:00 2001 From: Nitishkumar Singh Date: Thu, 4 Dec 2025 09:38:47 +0530 Subject: [PATCH] inference extension support Signed-off-by: Nitishkumar Singh --- .../extension/inference/inferencepools.rs | 0 .../experimental/extension/inference/mod.rs | 1 + .../standard/extension/inference/constants.rs | 13 ++ .../extension/inference/enum_defaults.rs | 8 + .../extension/inference/inferencepools.rs | 184 ++++++++++++++++++ .../apis/standard/extension/inference/mod.rs | 4 + .../standard_customized_mapped_names.txt | 3 + .../standard_reduced_types_pass_0.txt | 1 + .../standard_reduced_types_pass_1.txt | 2 + .../standard_rename_only_mapped_names.txt | 3 + update.sh | 105 +++++++++- xtask/src/main.rs | 59 +++--- 12 files changed, 353 insertions(+), 30 deletions(-) create mode 100644 gateway-api/src/apis/experimental/extension/inference/inferencepools.rs create mode 100644 gateway-api/src/apis/experimental/extension/inference/mod.rs create mode 100644 gateway-api/src/apis/standard/extension/inference/constants.rs create mode 100644 gateway-api/src/apis/standard/extension/inference/enum_defaults.rs create mode 100644 gateway-api/src/apis/standard/extension/inference/inferencepools.rs create mode 100644 gateway-api/src/apis/standard/extension/inference/mod.rs create mode 100644 type-reducer/extension/inference/standard_customized_mapped_names.txt create mode 100644 type-reducer/extension/inference/standard_reduced_types_pass_0.txt create mode 100644 type-reducer/extension/inference/standard_reduced_types_pass_1.txt create mode 100644 type-reducer/extension/inference/standard_rename_only_mapped_names.txt diff --git a/gateway-api/src/apis/experimental/extension/inference/inferencepools.rs b/gateway-api/src/apis/experimental/extension/inference/inferencepools.rs new file mode 100644 index 0000000..e69de29 diff --git a/gateway-api/src/apis/experimental/extension/inference/mod.rs b/gateway-api/src/apis/experimental/extension/inference/mod.rs new file mode 100644 index 0000000..cdc56d9 --- /dev/null +++ b/gateway-api/src/apis/experimental/extension/inference/mod.rs @@ -0,0 +1 @@ +// WARNING! generated file do not edit diff --git a/gateway-api/src/apis/standard/extension/inference/constants.rs b/gateway-api/src/apis/standard/extension/inference/constants.rs new file mode 100644 index 0000000..31d072e --- /dev/null +++ b/gateway-api/src/apis/standard/extension/inference/constants.rs @@ -0,0 +1,13 @@ +// WARNING: generated file - manual changes will be overriden + +#[derive(Debug, PartialEq, Eq)] +pub enum InferencePoolEndpointPickerRefFailureMode { + FailOpen, + FailClose, +} + +impl std::fmt::Display for InferencePoolEndpointPickerRefFailureMode { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} diff --git a/gateway-api/src/apis/standard/extension/inference/enum_defaults.rs b/gateway-api/src/apis/standard/extension/inference/enum_defaults.rs new file mode 100644 index 0000000..591730a --- /dev/null +++ b/gateway-api/src/apis/standard/extension/inference/enum_defaults.rs @@ -0,0 +1,8 @@ +use super::common::*; +// WARNING: generated file - manual changes will be overriden + +impl Default for InferencePoolEndpointPickerRefFailureMode { + fn default() -> Self { + InferencePoolEndpointPickerRefFailureMode::FailOpen + } +} diff --git a/gateway-api/src/apis/standard/extension/inference/inferencepools.rs b/gateway-api/src/apis/standard/extension/inference/inferencepools.rs new file mode 100644 index 0000000..9f13917 --- /dev/null +++ b/gateway-api/src/apis/standard/extension/inference/inferencepools.rs @@ -0,0 +1,184 @@ +// 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.22.5 + +#[allow(unused_imports)] +mod prelude { + pub use kube_derive::CustomResource; + pub use schemars::JsonSchema; + pub use serde::{Serialize, Deserialize}; + pub use std::collections::BTreeMap; + pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; +} +use self::prelude::*; + +/// Spec defines the desired state of the InferencePool. +#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +#[kube(group = "inference.networking.k8s.io", version = "v1", kind = "InferencePool", plural = "inferencepools")] +#[kube(namespaced)] +#[kube(status = "InferencePoolStatus")] +#[kube(derive="Default")] +#[kube(derive="PartialEq")] +pub struct InferencePoolSpec { + /// EndpointPickerRef is a reference to the Endpoint Picker extension and its + /// associated configuration. + #[serde(rename = "endpointPickerRef")] + pub endpoint_picker_ref: InferencePoolEndpointPickerRef, + /// Selector determines which Pods are members of this inference pool. + /// It matches Pods by their labels only within the same namespace; cross-namespace + /// selection is not supported. + /// + /// The structure of this LabelSelector is intentionally simple to be compatible + /// with Kubernetes Service selectors, as some implementations may translate + /// this configuration into a Service resource. + pub selector: InferencePoolSelector, + /// TargetPorts defines a list of ports that are exposed by this InferencePool. + /// Currently, the list may only include a single port definition. + #[serde(rename = "targetPorts")] + pub target_ports: Vec, +} + +/// EndpointPickerRef is a reference to the Endpoint Picker extension and its +/// associated configuration. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct InferencePoolEndpointPickerRef { + /// FailureMode configures how the parent handles the case when the Endpoint Picker extension + /// is non-responsive. When unspecified, defaults to "FailClose". + #[serde(default, skip_serializing_if = "Option::is_none", rename = "failureMode")] + pub failure_mode: Option, + /// Group is the group of the referent API object. When unspecified, the default value + /// is "", representing the Core API group. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + /// Kind is the Kubernetes resource kind of the referent. + /// + /// Required if the referent is ambiguous, e.g. service with multiple ports. + /// + /// 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 MUST NOT + /// support ExternalName Services. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + /// Name is the name of the referent API object. + pub name: String, + /// Port is the port of the Endpoint Picker extension service. + /// + /// 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, +} + +/// EndpointPickerRef is a reference to the Endpoint Picker extension and its +/// associated configuration. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)] +pub enum InferencePoolEndpointPickerRefFailureMode { + FailOpen, + FailClose, +} + +/// Port is the port of the Endpoint Picker extension service. +/// +/// 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. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct InferencePoolEndpointPickerRefPort { + /// Number defines the port number to access the selected model server Pods. + /// The number must be in the range 1 to 65535. + pub number: i32, +} + +/// Selector determines which Pods are members of this inference pool. +/// It matches Pods by their labels only within the same namespace; cross-namespace +/// selection is not supported. +/// +/// The structure of this LabelSelector is intentionally simple to be compatible +/// with Kubernetes Service selectors, as some implementations may translate +/// this configuration into a Service resource. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct InferencePoolSelector { + /// MatchLabels contains a set of required {key,value} pairs. + /// An object must match every label in this map to be selected. + /// The matching logic is an AND operation on all entries. + #[serde(rename = "matchLabels")] + pub match_labels: BTreeMap, +} + +/// Port defines the network port that will be exposed by this InferencePool. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct InferencePoolTargetPorts { + /// Number defines the port number to access the selected model server Pods. + /// The number must be in the range 1 to 65535. + pub number: i32, +} + +/// Status defines the observed state of the InferencePool. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct InferencePoolStatus { + /// Parents is a list of parent resources, typically Gateways, that are associated with + /// the InferencePool, and the status of the InferencePool with respect to each parent. + /// + /// A controller that manages the InferencePool, must add an entry for each parent it manages + /// and remove the parent entry when the controller no longer considers the InferencePool to + /// be associated with that parent. + /// + /// A maximum of 32 parents will be represented in this list. When the list is empty, + /// it indicates that the InferencePool is not associated with any parents. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub parents: Option>, +} + +/// ParentStatus defines the observed state of InferencePool from a Parent, i.e. Gateway. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct InferencePoolStatusParents { + /// Conditions is a list of status conditions that provide information about the observed + /// state of the InferencePool. This field is required to be set by the controller that + /// manages the InferencePool. + /// + /// Supported condition types are: + /// + /// * "Accepted" + /// * "ResolvedRefs" + #[serde(default, skip_serializing_if = "Option::is_none")] + pub conditions: Option>, + /// ParentRef is used to identify the parent resource that this status + /// is associated with. It is used to match the InferencePool with the parent + /// resource, such as a Gateway. + #[serde(rename = "parentRef")] + pub parent_ref: InferencePoolStatusParentsParentRef, +} + +/// ParentRef is used to identify the parent resource that this status +/// is associated with. It is used to match the InferencePool with the parent +/// resource, such as a Gateway. +#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)] +pub struct InferencePoolStatusParentsParentRef { + /// Group is the group of the referent API object. When unspecified, the referent is assumed + /// to be in the "gateway.networking.k8s.io" API group. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group: Option, + /// Kind is the kind of the referent API object. When unspecified, the referent is assumed + /// to be a "Gateway" kind. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + /// Name is the name of the referent API object. + 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: + #[serde(default, skip_serializing_if = "Option::is_none")] + pub namespace: Option, +} + diff --git a/gateway-api/src/apis/standard/extension/inference/mod.rs b/gateway-api/src/apis/standard/extension/inference/mod.rs new file mode 100644 index 0000000..0006d62 --- /dev/null +++ b/gateway-api/src/apis/standard/extension/inference/mod.rs @@ -0,0 +1,4 @@ +// WARNING! generated file do not edit +pub mod inferencepools; +mod enum_defaults; +pub mod constants; diff --git a/type-reducer/extension/inference/standard_customized_mapped_names.txt b/type-reducer/extension/inference/standard_customized_mapped_names.txt new file mode 100644 index 0000000..99016ef --- /dev/null +++ b/type-reducer/extension/inference/standard_customized_mapped_names.txt @@ -0,0 +1,3 @@ +#### Pass 1 +InferencePoolEndpointPickerRefPort->EndPointPort +InferencePoolTargetPorts->EndPointPort \ No newline at end of file diff --git a/type-reducer/extension/inference/standard_reduced_types_pass_0.txt b/type-reducer/extension/inference/standard_reduced_types_pass_0.txt new file mode 100644 index 0000000..3c2773d --- /dev/null +++ b/type-reducer/extension/inference/standard_reduced_types_pass_0.txt @@ -0,0 +1 @@ +Condition \ No newline at end of file diff --git a/type-reducer/extension/inference/standard_reduced_types_pass_1.txt b/type-reducer/extension/inference/standard_reduced_types_pass_1.txt new file mode 100644 index 0000000..97eae3e --- /dev/null +++ b/type-reducer/extension/inference/standard_reduced_types_pass_1.txt @@ -0,0 +1,2 @@ +Condition +EndPointPort \ No newline at end of file diff --git a/type-reducer/extension/inference/standard_rename_only_mapped_names.txt b/type-reducer/extension/inference/standard_rename_only_mapped_names.txt new file mode 100644 index 0000000..9f402e7 --- /dev/null +++ b/type-reducer/extension/inference/standard_rename_only_mapped_names.txt @@ -0,0 +1,3 @@ +### Rename only +InferencePoolStatusParents->InferencePoolStatusParent +InferencePoolStatusParentsParentRef->ParentRef diff --git a/update.sh b/update.sh index c579005..e3cc959 100755 --- a/update.sh +++ b/update.sh @@ -96,8 +96,8 @@ ENUMS=( ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}") ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1} -# The task searches for $GATEWAY_API_ENUMS in the environment to get the enum names and their default variants. -GATEWAY_API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/standard/enum_defaults.rs +# The task searches for $API_ENUMS in the environment to get the enum names and their default variants. +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" @@ -141,7 +141,7 @@ 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 >> $APIS_DIR/experimental/enum_defaults.rs +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 @@ -189,7 +189,7 @@ 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 > $APIS_DIR/standard/enum_defaults.rs +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")\]' $APIS_DIR/standard/grpcroutes.rs sed -i '/#\[kube(status = "HttpRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/standard/httproutes.rs @@ -223,7 +223,7 @@ 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 > $APIS_DIR/experimental/enum_defaults.rs +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 @@ -232,9 +232,9 @@ sed -i '/#\[kube(status = "UdpRouteStatus")\]/c\#\[kube(status = "RouteStatus")\ sed -i '/#\[kube(status = "TcpRouteStatus")\]/c\#\[kube(status = "RouteStatus")\]' $APIS_DIR/experimental/tcproutes.rs cargo fmt -echo "API Generation complete" +echo "Gateway API Generation complete" -echo "Cleaning up temporary files" +echo "Gateway API Cleaning up temporary files" set -x rm -f standard_mapped_names_phase_*.txt rm -f standard_mapped_types_to_names_phase_*.txt @@ -243,4 +243,93 @@ rm -f experimental_mapped_types_to_names_phase_*.txt rm -f mapped_names.txt rm -f mapped_types_to_names.txt set +x -echo "Cleanup complete" +echo "Gateway API Cleanup complete" + + +# ------------------------------------------------------------------------------ +# Inference Extension +# ------------------------------------------------------------------------------ + +echo " **** Inference Extension Processing Starts **** " + +INFERENCE_EXT_VERSION="v1.0.2" +echo "Using Inference Extension version ${INFERENCE_EXT_VERSION}" + +INFERENCE_EXT_STANDARD_APIS=( + inferencepools +) + +INFERENCE_EXT_EXPERIMENTAL_APIS=( + inferencepools + inferenceobjectives +) + +mkdir -p $APIS_DIR/standard/extension/inference +mkdir -p $APIS_DIR/experimental/extension/inference + + +echo "// WARNING! generated file do not edit" > $APIS_DIR/standard/extension/inference/mod.rs + +for API in "${INFERENCE_EXT_STANDARD_APIS[@]}" +do + echo "generating inference extension standard api ${API}" + curl -sSL "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api-inference-extension/${INFERENCE_EXT_VERSION}/config/crd/bases/inference.networking.k8s.io_${API}.yaml" | kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - > $APIS_DIR/standard/extension/inference/${API}.rs + sed -i 's/pub use kube::CustomResource;/pub use kube_derive::CustomResource;/g' $APIS_DIR/standard/extension/inference/${API}.rs + echo "pub mod ${API};" >> $APIS_DIR/standard/extension/inference/mod.rs +done + +# Standard API enums that need a Default trait impl along with their respective default variant. +ENUMS=( + InferencePoolEndpointPickerRefFailureMode=FailOpen +) + +# Create a comma separated string out of $ENUMS. +ENUMS_WITH_DEFAULTS=$(printf ",%s" "${ENUMS[@]}") +ENUMS_WITH_DEFAULTS=${ENUMS_WITH_DEFAULTS:1} + +# The task searches for $API_ENUMS in the environment to get the enum names and their default variants. +API_ENUMS=${ENUMS_WITH_DEFAULTS} cargo xtask gen_enum_defaults >> $APIS_DIR/standard/extension/inference/enum_defaults.rs +echo "mod enum_defaults;" >> $APIS_DIR/standard/extension/inference/mod.rs + +EXT_INFERENCE_FAILURE_MODE_CONSTANTS="InferencePoolEndpointPickerRefFailureMode=FailOpen,FailClose" + +EXT_INFERENCE_FAILURE_MODE_CONSTANTS=${EXT_INFERENCE_FAILURE_MODE_CONSTANTS} \ + cargo xtask gen_condition_constants inference >> $APIS_DIR/standard/extension/inference/constants.rs +echo "pub mod constants;" >> $APIS_DIR/standard/extension/inference/mod.rs + +echo "// WARNING! generated file do not edit" > $APIS_DIR/experimental/extension/inference/mod.rs + +for API in "${INFERENCE_EXT_EXPERIMENTAL_APIS[@]}" +do + echo "generating inference extension experimental api ${API}" + curl -sSL "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api-inference-extension/${INFERENCE_EXT_VERSION}/config/crd/bases/inference.networking.x.k8s.io_${API}.yaml" | kopium --schema=derived --derive=JsonSchema --derive=Default --derive=PartialEq --docs -f - > $APIS_DIR/experimental/extension/inference/${API}.rs + sed -i 's/pub use kube::CustomResource;/pub use kube_derive::CustomResource;/g' $APIS_DIR/experimental/extension/inference/${API}.rs + echo "pub mod ${API};" >> $APIS_DIR/experimental/extension/inference/mod.rs +done + + +export RUST_LOG=info + +mkdir -p extension/inference/ + +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/extension/inference --out-dir $APIS_DIR/standard/extension/inference reduce --previous-pass-derived-type-names ./type-reducer/extension/inference/standard_reduced_types_pass_0.txt --current-pass-substitute-names ./type-reducer/extension/inference/standard_customized_mapped_names.txt +mv mapped_names.txt extension/inference/standard_extension_inference_mapped_names_phase_1.txt +mv mapped_types_to_names.txt extension/inference/standard_extension_inference_mapped_types_to_names_phase_1.txt +echo " **** PHASE 2 ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard/extension/inference --out-dir $APIS_DIR/standard/extension/inference reduce --previous-pass-derived-type-names ./type-reducer/extension/inference/standard_reduced_types_pass_1.txt --current-pass-substitute-names ./type-reducer/extension/inference/standard_customized_mapped_names.txt +mv mapped_names.txt extension/inference/standard_extension_inference_mapped_names_phase_2.txt +mv mapped_types_to_names.txt extension/inference/standard_extension_inference_mapped_types_to_names_phase_2.txt + +echo " **** RENAMING PHASE ***** " +cargo run --manifest-path type-reducer/Cargo.toml -- --apis-dir $APIS_DIR/standard/extension/inference --out-dir $APIS_DIR/standard/extension/inference rename --rename-only-substitute-names ./type-reducer/extension/inference/standard_rename_only_mapped_names.txt + +cargo fmt +echo "Inference Extension API Generation complete" + +echo "Inference Extension API Cleaning up temporary files" +set -x +rm -rf extension/inference/ +set +x +echo "Inference Extension API Cleanup complete" \ No newline at end of file diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 84406bb..efd3a12 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -7,7 +7,10 @@ fn main() { match task.as_deref() { Some("gen_enum_defaults") => gen_enum_defaults().unwrap(), - Some("gen_condition_constants") => gen_condition_constants().unwrap(), + Some("gen_condition_constants") => { + let extension = env::args().nth(2); + gen_condition_constants(extension).unwrap() + } _ => print_help(), } } @@ -24,25 +27,37 @@ gen_constants generates constants used for Conditions type DynError = Box; -fn gen_condition_constants() -> Result<(), DynError> { - let gateway_class_condition_types = env::var("GATEWAY_CLASS_CONDITION_CONSTANTS")?; - let gateway_class_reason_types = env::var("GATEWAY_CLASS_REASON_CONSTANTS")?; - let gateway_condition_types = env::var("GATEWAY_CONDITION_CONSTANTS")?; - let gateway_reason_types = env::var("GATEWAY_REASON_CONSTANTS")?; - let listener_condition_types = env::var("LISTENER_CONDITION_CONSTANTS")?; - let listener_reason_types = env::var("LISTENER_REASON_CONSTANTS")?; - let route_condition_types = env::var("ROUTE_CONDITION_CONSTANTS")?; - let route_reason_types = env::var("ROUTE_REASON_CONSTANTS")?; - +fn gen_condition_constants(extension: Option) -> Result<(), DynError> { let mut scope = Scope::new(); - gen_const_enums(&mut scope, gateway_class_condition_types); - gen_const_enums(&mut scope, gateway_class_reason_types); - gen_const_enums(&mut scope, gateway_condition_types); - gen_const_enums(&mut scope, gateway_reason_types); - gen_const_enums(&mut scope, listener_condition_types); - gen_const_enums(&mut scope, listener_reason_types); - gen_const_enums(&mut scope, route_condition_types); - gen_const_enums(&mut scope, route_reason_types); + match extension { + None => { + let gateway_class_condition_types = env::var("GATEWAY_CLASS_CONDITION_CONSTANTS")?; + let gateway_class_reason_types = env::var("GATEWAY_CLASS_REASON_CONSTANTS")?; + let gateway_condition_types = env::var("GATEWAY_CONDITION_CONSTANTS")?; + let gateway_reason_types = env::var("GATEWAY_REASON_CONSTANTS")?; + let listener_condition_types = env::var("LISTENER_CONDITION_CONSTANTS")?; + let listener_reason_types = env::var("LISTENER_REASON_CONSTANTS")?; + let route_condition_types = env::var("ROUTE_CONDITION_CONSTANTS")?; + let route_reason_types = env::var("ROUTE_REASON_CONSTANTS")?; + + gen_const_enums(&mut scope, gateway_class_condition_types); + gen_const_enums(&mut scope, gateway_class_reason_types); + gen_const_enums(&mut scope, gateway_condition_types); + gen_const_enums(&mut scope, gateway_reason_types); + gen_const_enums(&mut scope, listener_condition_types); + gen_const_enums(&mut scope, listener_reason_types); + gen_const_enums(&mut scope, route_condition_types); + gen_const_enums(&mut scope, route_reason_types); + } + Some(ext) if ext == "inference" => { + let inference_extension_failure_types = + env::var("EXT_INFERENCE_FAILURE_MODE_CONSTANTS")?; + + gen_const_enums(&mut scope, inference_extension_failure_types); + } + _ => println!("Not Supported Extension!"), + } + println!("{}", gen_generated_file_warning()); println!("{}", scope.to_string()); Ok(()) @@ -81,9 +96,9 @@ fn gen_display_impl(scope: &mut Scope, ty: &str) { } fn gen_enum_defaults() -> Result<(), DynError> { - // GATEWAY_API_ENUMS provides the enum names along with their default variant to be used in the - // generated Default impl. For eg: GATEWAY_API_ENUMS=enum1=default1,enum2=default2. - let gw_api_enums = env::var("GATEWAY_API_ENUMS")?; + // API_ENUMS provides the enum names along with their default variant to be used in the + // generated Default impl. For eg: API_ENUMS=enum1=default1,enum2=default2. + let gw_api_enums = env::var("API_ENUMS")?; let enums_with_defaults = get_enums_with_defaults_map(gw_api_enums); let mut scope = Scope::new();