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
controllers + apiserver: enhance context support #122148
controllers + apiserver: enhance context support #122148
Conversation
Please note that we're already in Test Freeze for the Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Fri Dec 1 04:07:07 UTC 2023. |
test/integration/replicationcontroller/replicationcontroller_test.go
Outdated
Show resolved
Hide resolved
@@ -162,6 +166,10 @@ func TestEndpointUpdates(t *testing.T) { | |||
// does not get endpoints, and after transition to ClusterIP, service gets endpoint, | |||
// without headless label | |||
func TestExternalNameToClusterIPTransition(t *testing.T) { | |||
_, ctx := ktesting.NewTestContext(t) | |||
ctx, cancel := context.WithCancel(ctx) | |||
defer cancel() |
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.
A lot of tests calling kubeapiservertesting.StartTestServerOrDie
need this boiler-plate code although that function internally also does the same thing.
Would it make sense to extend the kubeapiservertesting.TestServer
struct to include the context, TB and client set interfaces?
Including the client set would allow removing a lot of common code that usually follows StartTestServerOrDie()
, because pretty much every test which creates an API server then also instantiates a client set for it.
The downside is that test code might become a bit weird (?):
serverCtx.CoreV1().Pods().Get(serverCtx, ....)
Or, when not renaming the variable at all:
server.CoreV1().Pods().Get(server, ....)
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.
Would it make sense to extend the kubeapiservertesting.TestServer struct to include the context, TB and client set interfaces?
test/utils/ktesting
does that, but let's keep using it separate: #124093
staging/src/k8s.io/cloud-provider/controllers/service/controller.go
Outdated
Show resolved
Hide resolved
Yes, all of those changes are fine. |
/lgtm |
LGTM label has been added. Git tree hash: 0620d12963b85f32a381f3f7f42deb35ac306ace
|
/lgtm |
cd457e1
to
7858178
Compare
@tkashem: can you re-add LGTM? I had to rebase because of a minor conflict in |
@pohly: The following test 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/test-infra repository. I understand the commands that are listed here. |
There are new test failures after the rebase. Looking... |
27a68ae introduced context support for events. Creating an event broadcaster with context makes tests more resilient against leaking goroutines when that context gets canceled at the end of a test and enables per-test output via ktesting. The New method already had a context, therefore no API changes are needed.
27a68ae introduced context support for events. Creating an event broadcaster with context makes tests more resilient against leaking goroutines when that context gets canceled at the end of a test and enables per-test output via ktesting. The context could get passed to the constructor. A cleaner solution is to enhance context support for the apiserver and then pass the context into the controller's run method. This ripples up the call stack to all places which start an apiserver.
7858178
to
b92273a
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pohly, sttts 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 |
Found it (I think)... My own changes to |
/lgtm |
LGTM label has been added. Git tree hash: 4977206dd85c6a09f189dc35501139c6ff110ece
|
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
27a68ae introduced context support for events. Creating an event
broadcaster with context makes tests more resilient against leaking goroutines
when that context gets canceled at the end of a test and enables per-test
output via ktesting.
Special notes for your reviewer:
The context could get passed to the constructor. A cleaner solution is to
enhance context support for the apiserver and then pass the context into the
controller's run method. This ripples up the call stack to all places which
start an apiserver.
Does this PR introduce a user-facing change?