fix svc long name (#9245)

Signed-off-by: tombokombo <tombo@sysart.tech>

Signed-off-by: tombokombo <tombo@sysart.tech>
This commit is contained in:
Tomas Hulata 2022-11-05 22:22:15 +01:00 committed by GitHub
parent 3c32413e30
commit 490ecffc52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 115 additions and 1 deletions

View file

@ -21,6 +21,7 @@ import (
"strings"
discoveryv1 "k8s.io/api/discovery/v1"
apiNames "k8s.io/apiserver/pkg/storage/names"
"k8s.io/client-go/tools/cache"
)
@ -32,9 +33,21 @@ type EndpointSliceLister struct {
// MatchByKey returns the EndpointsSlices of the Service matching key in the local Endpoint Store.
func (s *EndpointSliceLister) MatchByKey(key string) ([]*discoveryv1.EndpointSlice, error) {
var eps []*discoveryv1.EndpointSlice
keyNsLen := strings.Index(key, "/")
if keyNsLen < -1 {
keyNsLen = 0
} else {
// count '/' char
keyNsLen += 1
}
// filter endpointSlices owned by svc
for _, listKey := range s.ListKeys() {
if !strings.HasPrefix(listKey, key) {
if len(key) < (apiNames.MaxGeneratedNameLength+keyNsLen) && !strings.HasPrefix(listKey, key) {
continue
}
// generated endpointslices names has truncated svc name as prefix when svc name is too long, we compare only non truncated part
// https://github.com/kubernetes/ingress-nginx/issues/9240
if len(key) >= (apiNames.MaxGeneratedNameLength+keyNsLen) && !strings.HasPrefix(listKey, key[:apiNames.MaxGeneratedNameLength+keyNsLen-1]) {
continue
}
epss, exists, err := s.GetByKey(listKey)