Skip to content
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

Merged
merged 2 commits into from Apr 30, 2024

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Dec 1, 2023

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?

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Dec 1, 2023
@k8s-ci-robot
Copy link
Contributor

Please note that we're already in Test Freeze for the release-1.29 branch. This means every merged PR will be automatically fast-forwarded via the periodic ci-fast-forward job to the release branch of the upcoming v1.29.0 release.

Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Fri Dec 1 04:07:07 UTC 2023.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Dec 1, 2023
@k8s-ci-robot k8s-ci-robot added area/apiserver area/cloudprovider area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 1, 2023
@@ -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()
Copy link
Contributor Author

@pohly pohly Dec 1, 2023

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, ....)

Copy link
Contributor Author

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

@bart0sh bart0sh added this to WIP in SIG Node PR Triage Dec 1, 2023
@sttts
Copy link
Contributor

sttts commented Apr 29, 2024

Yes, all of those changes are fine.

@sttts
Copy link
Contributor

sttts commented Apr 29, 2024

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 29, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 0620d12963b85f32a381f3f7f42deb35ac306ace

@tkashem
Copy link
Contributor

tkashem commented Apr 29, 2024

/lgtm

@pohly pohly force-pushed the controllers-context-support branch from cd457e1 to 7858178 Compare April 29, 2024 14:01
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 29, 2024
@pohly
Copy link
Contributor Author

pohly commented Apr 29, 2024

@tkashem: can you re-add LGTM?

I had to rebase because of a minor conflict in test/integration/framework/test_server.go (one line, and of course that one got changed on master...).

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Apr 29, 2024

@pohly: 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-kubernetes-apidiff cd457e1 link false /test pull-kubernetes-apidiff

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.

@pohly pohly changed the title controllers + apiserver: enhance context support WIP: controllers + apiserver: enhance context support Apr 29, 2024
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 29, 2024
@pohly
Copy link
Contributor Author

pohly commented Apr 29, 2024

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.
@pohly pohly force-pushed the controllers-context-support branch from 7858178 to b92273a Compare April 29, 2024 19:01
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 29, 2024
@pohly
Copy link
Contributor Author

pohly commented Apr 29, 2024

Found it (I think)... My own changes to staging/src/k8s.io/cloud-provider/controllers/service/controller.go in another PR got merged and conflicted with similar changes in this PR, without actually causing a merge conflict (different lines).

@sttts
Copy link
Contributor

sttts commented Apr 29, 2024

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 29, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 4977206dd85c6a09f189dc35501139c6ff110ece

@pohly pohly changed the title WIP: controllers + apiserver: enhance context support controllers + apiserver: enhance context support Apr 30, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 30, 2024
@k8s-ci-robot k8s-ci-robot merged commit d0fddf1 into kubernetes:master Apr 30, 2024
15 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.31 milestone Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/cloudprovider area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

8 participants