-
Notifications
You must be signed in to change notification settings - Fork 135
Upgrade the inferencePool selector to a struct from a map. #1330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zetxqx The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @zetxqx. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
||
// LabelSelector defines a query for resources based on their labels. | ||
// This simplified version uses only the matchLabels field. | ||
type LabelSelector struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this SimpleLabelSelector
or something similar so it's clear that this is a subset of the OSS type of the same name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we foresee adding more fields to this struct? My impression is we want to leave the possibility to grow this struct to the real LabelSelector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't change the name for now, because my understanding is that this struct could grow to be not "simple". I keep the name as-is for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @zetxqx. Otherwise, a)SimpleLabelSelector
will no longer be a simple selector when MatchExpressions
is added or b) we will have to create a new LabelSelector
type that mirrors upstream and implementations will have to refactor to use the new type.
I think in this PR, we also need to change https://github.com/kubernetes-sigs/gateway-api-inference-extension/blob/main/pkg/epp/controller/inferencepool_reconciler.go#L98, as the v1a2 InferencePool and v1 InferencePool are not exactly the same. The existing conversion via unstructured won't work. Need to do manual conversion. |
daf936f
to
886a0c4
Compare
@kfswain could I get a ok-to-test first? |
/ok-to-test |
return convert[EndpointPickerConfig](u) | ||
} | ||
|
||
func toUnstructured(obj any) (*unstructured.Unstructured, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the common util in https://github.com/kubernetes-sigs/gateway-api-inference-extension/blob/main/pkg/common/convert.go? At the same time, I think you can remove the
var ToInferencePool = convert[v1.InferencePool]
var ToXInferencePool = convert[v1alpha2.InferencePool]
in the common file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted the common/convert.go and moved it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you still need to use func toUnstructured(obj any) (*unstructured.Unstructured, error) in the codebase, it's better to leave it in common package instead of specific apix package as they are common util. But we can wait until cong to make a call to see whether we need to do manual conversion for all fields.
return dst, nil | ||
} | ||
|
||
func converStatusToV1(src InferencePoolStatus) (*v1.InferencePoolStatus, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we use manual conversation for label selector, I'm wondering whether it makes more sense to use manual conversion for all fields now. I know the code maybe a little bit cumbersome. But maybe AI tool can help. I know such cumbersome manual conversion is widely used in OSS, see https://github.com/google/knative-gcp/blob/4a435faedc46726299800e1cdf2ad998c357b25b/pkg/apis/convert/conversion_helper.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave it to go readability reviewer @liu-cong to make a call.
// An object must match every label in this map to be selected. | ||
// The matching logic is an AND operation on all entries. | ||
// +optional | ||
MatchLabels map[LabelKey]LabelValue `json:"matchLabels,omitempty" protobuf:"bytes,1,rep,name=matchLabels"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we want MatchLabels
to mirror upstream?
// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
// map is equivalent to an element of matchExpressions, whose key field is "key", the
// operator is "In", and the values array contains only "value". The requirements are ANDed.
// +optional
MatchLabels map[string]string `json:"matchLabels,omitempty" protobuf:"bytes,1,rep,name=matchLabels"`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I wanted to leverage the LabelKey
and LabelValue
because I saw they have some kubebuiler
validation on it. Does that need to be kept? If not, I'll change to map[string]string for the simplicity.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$`
type LabelKey string
// +kubebuilder:validation:MinLength=0
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern=`^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$`
type LabelValue string
out of curiosity, I'm looking in this PR and thinking - why actually we don't want to use k8s label selector as is? |
Great question @nirrozenbaum Here's Rob's origional comment on this. #1173 (comment) cc: @robscott to give more insights. Assuming this is a common implementation details, a lot of gateway implementations may not support the |
I'm not sure I fully got the explanation in that comment.
@robscott can you explain a bit more in detail? I understand from the above comment that Gateways implementation are creating service to get EndpointSlices, but how is that related to the InferencePool LabelSelector? I lost you in the middle. |
Context: #1173 (comment)
Change the InferencePool.Selector from map[string]string to a struct for future flexibility in v1.
fix #1327