Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// WARNING! generated file do not edit
13 changes: 13 additions & 0 deletions gateway-api/src/apis/standard/extension/inference/constants.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use super::common::*;
// WARNING: generated file - manual changes will be overriden

impl Default for InferencePoolEndpointPickerRefFailureMode {
fn default() -> Self {
InferencePoolEndpointPickerRefFailureMode::FailOpen
}
}
184 changes: 184 additions & 0 deletions gateway-api/src/apis/standard/extension/inference/inferencepools.rs
Original file line number Diff line number Diff line change
@@ -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<InferencePoolTargetPorts>,
}

/// 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<InferencePoolEndpointPickerRefFailureMode>,
/// 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<String>,
/// 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<String>,
/// 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<InferencePoolEndpointPickerRefPort>,
}

/// 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<String, String>,
}

/// 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<Vec<InferencePoolStatusParents>>,
}

/// 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<Vec<Condition>>,
/// 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<String>,
/// 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<String>,
/// 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: <https://gateway-api.sigs.k8s.io/api-types/referencegrant/>
#[serde(default, skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
}

4 changes: 4 additions & 0 deletions gateway-api/src/apis/standard/extension/inference/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// WARNING! generated file do not edit
pub mod inferencepools;
mod enum_defaults;
pub mod constants;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### Pass 1
InferencePoolEndpointPickerRefPort->EndPointPort
InferencePoolTargetPorts->EndPointPort
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Condition
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Condition
EndPointPort
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Rename only
InferencePoolStatusParents->InferencePoolStatusParent
InferencePoolStatusParentsParentRef->ParentRef
105 changes: 97 additions & 8 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
Loading
Loading