-
Notifications
You must be signed in to change notification settings - Fork 136
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. |
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. |
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 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
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.
+1 on using map[string]string. I don't think this kubebuilder validation is required.
as a side note, service label selector also doesn't have any kubebuilder validation
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.
Sadly we need the CRD validation @zetxqx added here to maintain compatibility with upstream validation. When defining built-in APIs, that validation can be written in Go, and that's what happened here. When reusing the same types in CRDs, it's critical for us to try to replicate that validation with CEL, as @zetxqx is doing in this PR.
I think there's some corresponding upstream efforts to move more validation to annotations in go types, and that would help in cases like this.
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.
we can keep LabelKey/LabelValue if that is needed 👍
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.
Yes, "Declarative Validation" (KEP-5073) is the upstream effort to replace validation in build-in APIs that is handwritten in Go with annotations.
One of the goals of that project is to make it so that if CRDs import native types (e.g. "PodSpec") into CRDs, either via Kubebuilder or via OpenAPI, that the validation of the native type is preserved.
It's unlikely that we will preserve 100% of validation, since there are some really complicated validation rules in the build-in types, but we believe we can preserve a lot of it.
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.
To clarify, for kubebuilder, our intention is to have kubebuilder understand and support validation of the annotations we add (we call them tags, and they usually look like this: // +k8s:maximum=5
). For openAPI we intent to publish the validation rules either using native OpenAPI value validation rules, or, if needed, by publishing the CEL expressions to perform the validation.
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.
Thanks you all! I'll keep the LabelKey/LabelValue.
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.
@lalitc375 @cheftako for visibility
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. |
@nirrozenbaum I see what's the confusing part. Here @robscott is talking about the implementation details on the gateway controller side. You are talking about the reconciler on the EPP side. In the gateway implementation, inference pool is mostly translated to a service. Specifically, the inferencePool.Selector is converted to service's selector under ServiceSpec. And its type is |
/cc |
@zetxqx thanks for the explanation. I think I've never really got into the details of how gateways are implementing the translation to InferencePool from the GW side. this makes sense, it's always good to learn :). now that it's all clearer to me: |
can you update also e2e tests manifest and the helm chart template along with its documentation? |
Good call, updated accordingly |
/test pull-gateway-api-inference-extension-test-unit-main |
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.
Thanks @zetxqx!
api/v1/shared_types.go
Outdated
// 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. | ||
// +optional |
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.
Since the previous field was required, I think this should be too. I'd also recommend adding +kubebuilder:validation:MaxItems
to some relatively high value (maybe 32 or 64) for the sake of always having an upper bound on resource size.
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.
Thanks @robscott
Added the following validation comment.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MaxItems=64
QQ: for the required
validation, in the future if we add new field to this struct, it may become not required. Could that happen? In that situation, will it be easy to downgrade required to optional? I think at least we can have a new API version for that change as the last resort.
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.
QQ: for the required validation, in the future if we add new field to this struct, it may become not required. Could that happen? In that situation, will it be easy to downgrade required to optional? I think at least we can have a new API version for that change as the last resort.
Yep, it's possible to loosen validation in the future, but impossible to retroactively tighten validation, that's why we usually try to start with validation that's as complete as possible.
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: robscott, 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 |
Thanks @zetxqx! LGTM once you rerun CRD generation. |
Context: #1173 (comment)
Change the InferencePool.Selector from map[string]string to a struct for future flexibility in v1.
fix #1327