kubernetes-sigs / apiserver-network-proxy

Apache License 2.0
381 stars 182 forks source link

New proxy server counting logic for agent and server #634

Closed carreter closed 5 months ago

carreter commented 5 months ago

An initial pass at the groundwork for #358 and #273 (i.e. allowing a dynamic proxy server count on both the server and the agent in a backwards-compatible manner). Currently a draft, depends on #632. Design doc here.

Changes

New package: pkg/servercounter

This package is structured around the ServerCounter interface:

// A ServerCounter counts the number of available proxy servers.
type ServerCounter interface {
    CountServers() int
}

Currently provided are StaticServerCounter, which simply returns a stored int, and CachedServerCounter, which wraps another ServerCounter and provides catching functionality with a configurable cache expiry time.

Proxy server

This PR wires the ServerCounter into the proxy server without changing its behavior by creating a StaticServerCounter with the command-line provided count.

Proxy agent

This PR wires the ServerCounter into the proxy agent without changing its behavior by creating a StaticServerCounter with a default count of 0.

This PR also adds the respectReceivedServerCount field to the agent ClientSet struct. This field toggles whether the server count received from the proxy server should overwrite the proxy agent's server counter. Since I didn't want to change the behavior of the agent yet, this is set to true by default.

Open questions

Should CountServers() return an error?

Sometimes the ServerCounter will fail to get an updated server count. In this case, we could have CountServers() return (int, error) instead.

I opted against this because we can handle errors in the ServerCounter itself. This simplifies things on the caller side and allows for including a fallback server count in the ServerCounter.

Should ServerCounter include an UpdateCount(int) method?

It might be useful for clients to (a) temporarily override the server count or (b) request an update to any cached server counts. They could do this by calling UpdateCount() with a non-negative value to temporarily override the count or with -1 to reset the override and request a count update.

I opted against this because the client can accomplish (a) using a StaticServerCounter (downside: this overwrites the previous ServerCounter if stored in the same field), and (b) seems like it would have limited use as the ServerCounter should be completely responsible for managing the server count.

A possible workaround is to add the UpdateCount() method to just CachedServerCounter rather than the entire interface. This allows for finer control of caching while maintaining a simple API for the general case.

Should respectReceivedServerCount be true or false by default?

My take: have it true by default unless an alternative server count method is provided in the commandline args to the proxy agent. This ensures backwards compatibility with old proxy servers.

k8s-ci-robot commented 5 months ago

Hi @carreter. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
k8s-ci-robot commented 5 months ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: carreter Once this PR has been reviewed and has the lgtm label, please assign cheftako for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files: - **[OWNERS](https://github.com/kubernetes-sigs/apiserver-network-proxy/blob/master/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
carreter commented 5 months ago

@avrittrohwer for visibility

jkh52 commented 5 months ago

/ok-to-test

k8s-ci-robot commented 5 months ago

@carreter: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-apiserver-network-proxy-make-lint-master d2120466a6b2e8512c7294108b2fc2604780b326 link true /test pull-apiserver-network-proxy-make-lint-master

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](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).