-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Port aggregated apiserver discovery to EndpointSlices #129837
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: master
Are you sure you want to change the base?
Port aggregated apiserver discovery to EndpointSlices #129837
Conversation
will not be solved by the mirroring controller? |
one suggestion, in the eventual situation something goes wrong with one of the changes, having all of them in the same commit will revert all, should we have one commit for aggregator, other for proxy and other for remote available controller so we avoid that possible problem? |
yes, but
|
They're all basically a single feature ( |
6e33fa6
to
3aed1e3
Compare
LGTM label has been added. Git tree hash: cbc6a1a992fedf76a537663543b4993d4eee61aa
|
ep := &slice.Endpoints[(epi+offset)%len(slice.Endpoints)] | ||
if ep.Conditions.Ready == nil || *ep.Conditions.Ready { | ||
ip := ep.Addresses[0] | ||
port := int(*slice.Ports[i].Port) |
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.
godoc on the Port field sounds like Port can be nil... should we check / require a non-nil port value above when deciding if the Port is valid for our use?
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.
Huh. This is another unused future-extensibility point. Port is allowed to be unset (and thus not validated as required) even though it's required to be set for EndpointSlices corresponding to Services. Grumble.
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 just don't know the EndpointSlice API surface well enough to know which of these "allowed by the spec" things we have to handle, so my default is to check everything we could possibly encounter
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 I'm missing it, but it still looks like we can hit a nil port and panic here? should we add || slice.Ports[i].Port == nil
to the conditions above where we just continue?
staging/src/k8s.io/kube-aggregator/pkg/controllers/status/remote/remote_available_controller.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/kube-aggregator/pkg/controllers/status/remote/remote_available_controller.go
Show resolved
Hide resolved
/triage accepted |
3aed1e3
to
139a933
Compare
/lgtm |
LGTM label has been added. Git tree hash: 626403b39cc1e94c2349cfd9ae9b5f4d95fbc5a9
|
// If there are multiple slices, we want to look at them in a random | ||
// order, but we need to look at all of the slices of the primary IP | ||
// family first. | ||
preferredAddressType := discoveryv1.AddressType(svc.Spec.IPFamilies[0]) |
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.
ensure svc.Spec.IPFamilies is non-zero length before indexing into [0]
, since there are circumstances where IPFamilies is blank
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.
IPFamilies can only be blank if the Service is ExternalName or headless, but it appears that ResolveEndpoint does allow you to use a headless Service. OK.
EDIT: Actually, from what I can tell, IPFamilies seems to get defaulted (via registry, not apis) even for headless services. However, I definitely couldn't prove that that's the case so I'll add the check anyway...
ep := &slice.Endpoints[(epi+offset)%len(slice.Endpoints)] | ||
if ep.Conditions.Ready == nil || *ep.Conditions.Ready { | ||
ip := ep.Addresses[0] | ||
port := int(*slice.Ports[i].Port) |
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 I'm missing it, but it still looks like we can hit a nil port and panic here? should we add || slice.Ports[i].Port == nil
to the conditions above where we just continue?
@@ -70,32 +76,50 @@ func ResolveEndpoint(services listersv1.ServiceLister, endpoints listersv1.Endpo | |||
return nil, err | |||
} | |||
|
|||
eps, err := endpoints.Endpoints(namespace).Get(svc.Name) | |||
endpointSliceSelector := labels.SelectorFromSet(labels.Set{discoveryv1.LabelServiceName: svc.Name}) | |||
slices, err := endpointSlices.EndpointSlices(namespace).List(endpointSliceSelector) |
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.
This changes an O(1) lookup by name into a O(n) selection.
I don't expect this to be an issue under normal circumstances, but when there are bananas numbers of services in a single namespace, this could be observably more expensive. We sort of won't know until this change gets into the wild what clusters with unexpectedly large numbers of endpointslices in a namespace this lookup degrades.
Should we add a namespaceName+svcName indexer onto the endpointslice informer/lister, and make use of that to keep from having to traverse / do selection on all endpointslices in a namespace on every webhook / aggregated server dial?
The top commit of https://github.com/liggitt/kubernetes/commits/aggregated-apiserver-endpointslices/ has a sketch of what that could look like. I'm on the fence...
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 selection on all endpointslices in a namespace on every webhook
oh... huh, I was assuming that because this function is only called from within staging/src/k8s.io/kube-aggregator
, that that meant it was only used for aggregated apiserver stuff (and thus "bananas numbers of services in the same namespace" was unlikely to be a problem). Looks like the API outgrew its original use case.
I'm on the fence...
Yeah, I understand the general concern, but I don't have any sense of if it matters in this specific case...
(Though if we add EndpointSliceGetter
it should eventually migrate somewhere more public/generic, possibly as part of #124777.)
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 are limited by IPs in Services so it will unlikely to have 1M of Services (famous last words :) ) but with 100k we already take a 7 ms hits that is really high for http requests #130967
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.
1M Services isn't unreasonable - folks have reached a third of that using Knative and ended up re-architecting it to remove the use of services
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.
folks have reached a third of that using Knative
glad to know, and I also heard good feedback from that community with the ServiceCIDR feature since they seems to consume those IPs very quickly, but still feel is a long shot to get there, those are a lot of ips , 2^20 = 1,048,576 , means they have to use a /12 mask ... I'll be the most happy person in the world if we get to the 1M of Services
return err | ||
} else if err != nil { | ||
endpointSliceSelector := labels.SelectorFromSet(labels.Set{discoveryv1.LabelServiceName: apiService.Spec.Service.Name}) | ||
endpointSlices, err := c.endpointSliceLister.EndpointSlices(apiService.Spec.Service.Namespace).List(endpointSliceSelector) |
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.
same comment about wondering if this should make use of an indexer, the POC commit I linked to also fixes up this call site
staging/src/k8s.io/kube-aggregator/pkg/controllers/status/remote/remote_available_controller.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/kube-aggregator/pkg/controllers/status/remote/remote_available_controller.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/kube-aggregator/pkg/controllers/status/remote/remote_available_controller.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/kube-aggregator/pkg/controllers/status/remote/remote_available_controller.go
Outdated
Show resolved
Hide resolved
139a933
to
f79dcf9
Compare
New changes are detected. LGTM label has been removed. |
Co-Authored-by: Jordan Liggitt <[email protected]>
Co-Authored-by: Jordan Liggitt <[email protected]>
f79dcf9
to
c141385
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: danwinship 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 |
Now includes an updated version of Jordan's "Sketch of indexing on endpointslice namespace/service-name". As compared to that:
Plus the new push also includes the e2e test update that got bumped from #131732 because it depends specifically on whether the proxying code uses Endpoints or EndpointSlices. |
@danwinship: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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 understand the commands that are listed here. |
which makes |
@liggitt this is ready for review (though we need to decide where to put the code / how to deal with the verify-imports failure) |
Jordan is OOO through 6/6 (From slack status, github just says on vacation) |
Hello @danwinship @liggitt |
What this PR does / why we need it:
Belatedly ports the aggregated apiserver code to use EndpointSlices rather than Endpoints.
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
(The KEP is not yet merged, but this PR is correct/desirable in terms of internal consistency even if the KEP is rejected.)/kind cleanup
/kind feature
/sig network
/sig api-machinery