-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
fix svc long name #9245
fix svc long name #9245
Conversation
@tombokombo: This issue is currently awaiting triage. If Ingress contributors determines this is a relevant issue, they will accept it by applying the The 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/test-infra repository. |
Hi @tombokombo. Thanks for your PR. I'm waiting for a kubernetes 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/test-infra repository. |
/assign @tao12345666333 |
/ok-to-test |
@@ -34,7 +34,12 @@ func (s *EndpointSliceLister) MatchByKey(key string) ([]*discoveryv1.EndpointSli | |||
var eps []*discoveryv1.EndpointSlice | |||
// filter endpointSlices owned by svc | |||
for _, listKey := range s.ListKeys() { | |||
if !strings.HasPrefix(listKey, key) { | |||
if len(key) < 58 && !strings.HasPrefix(listKey, key) { |
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.
Where does 58 come from? Can it change elsewhere and resurface this issue in another form?
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.
Also as per #9240 (comment), this is merely optimization and the actual check is done using ownerReferences
(which is great!). What if we skip this optimization completely, how bad would it be?
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.
Where does 58 come from? Can it change elsewhere and resurface this issue in another form?
If the svc is too long, Kubernetes will use the first 58 characters + a random string to form the name of the endpointslices
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.
Yeah, I'm concerned about that - what if in next k8s version they change it to say 48 characters?
What is the performance concern here? Is s.GetByKey(listKey)
costly? How costly? I'd guess it does not even make an API call and just fetches the object from the cache store.
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.
@ElvinEfendi slices are using meta generated name "feature" https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/endpointslice/utils.go#L142
this one is full lenght, still not truncated. Generated name is later used for name creation by k8s. As per docs
https://pkg.go.dev/k8s.io/apiserver/pkg/storage/names#NameGenerator.GenerateName
not exceed the length of a standard Kubernetes name (63 characters)
. Mentioned 63 chars needs to contain random generated part. Look at https://github.com/kubernetes/apiserver/blob/master/pkg/storage/names/generate.go#L45.
and truncating ifself https://github.com/kubernetes/apiserver/blob/master/pkg/storage/names/generate.go#L51
As you can see, its hardcoded, not optional, at least for now, but I can reference it ( see next commit ). Problem could rise if it becomes optional, but it will be compile error after go k8s deps upgrade. In edge case, that const will still be there ( reference will work ) and it somehow becomes optional, higher num would still work, but less effectively. The case with less characters, will brake whole k8s world, cannot even imagine consequences....
Regarding optimization, I did test with 10k slices in one namespace and 10k in another. With this optimization, we get rid of second namespace, because keys starts with namespace. Calling MatchByKey
10k times, results are 86.85sec and 36.42sec with this optimization. Using real world numbers, 500 slices + 500 slices different ns, 500 calls results in 120.881986ms and optimized 57.799922ms. It make sense to me at least to get rid of different namespaces.
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.
@tombokombo thanks for those numbers, the optimization does make sense in that case.
Also 👍🏼 for referencing MaxGeneratedNameLength
instead of hardcoding it. It looks good now.
Thanks @tombokombo! It'd be great to also have an e2e regression test for this bug. |
The fix LGTM, I also hope you can add e2e test case |
} | ||
if len(eps) != 1 { | ||
t.Errorf("expected one slice %v, error, got %d slices", endpointSlice, len(eps)) | ||
} |
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.
It'd also be good to assert that the 1 eps we expect is the eps we want (with name test-backend-http-test-http-test-http-test-http-test-http-bar88
and namespace ns
).
@ElvinEfendi @tao12345666333 hopefully there is nothing more to discuss. I'm going to provide e2e test soon. |
Thanks I think it's ok, wait for your e2e case |
LGTM - please rebase / squash the commits. I'll let @tao12345666333 to take a final look and approve. |
Signed-off-by: tombokombo <[email protected]>
5e5272b
to
ad8e828
Compare
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.
/lgtm
/approve
Thanks!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: tao12345666333, tombokombo The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This can be reverted when kubernetes/ingress-nginx#9245 is released
This can be reverted when kubernetes/ingress-nginx#9245 is released
Signed-off-by: tombokombo <[email protected]> Signed-off-by: tombokombo <[email protected]>
What this PR does / why we need it:
Fix endpointslices service matching when service name is too long.
Types of changes
Which issue/s this PR fixes
fixes #9240
How Has This Been Tested?
Checklist:
Does my pull request need a release note?