Skip to content

use ginkgo.DeferCleanup to do cleanup tasks #128585

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

Closed
wants to merge 1 commit into from

Conversation

carlory
Copy link
Member

@carlory carlory commented Nov 5, 2024

What type of PR is this?

/kind flake

What this PR does / why we need it:

defer cannot make sure the function is called when the test is unexpectedly terminated. Use ginkgo.DeferCleanup instead.

Which issue(s) this PR fixes:

Ref #128578

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/flake Categorizes issue or PR as related to a flaky test. 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 Nov 5, 2024
@k8s-ci-robot k8s-ci-robot added area/test sig/auth Categorizes an issue or PR as relevant to SIG Auth. 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 Nov 5, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: carlory
Once this PR has been reviewed and has the lgtm label, please assign tallclair 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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@carlory
Copy link
Member Author

carlory commented Nov 5, 2024

/cc @aojea @stlaz

@k8s-ci-robot k8s-ci-robot requested review from aojea and stlaz November 5, 2024 17:09
@carlory
Copy link
Member Author

carlory commented Nov 5, 2024

#128581 is at the merge pool, so I open this PR.

@ffromani
Copy link
Contributor

ffromani commented Nov 5, 2024

defer cannot make sure the function is called when the test is unexpectedly terminated. Use ginkgo.DeferCleanup instead.

Can you please give more details?

(code itself LGTM, but I'm not a reviewer for this area)

@carlory
Copy link
Member Author

carlory commented Nov 5, 2024

@ffromani there is an example. #127790 (comment)

@ffromani
Copy link
Contributor

ffromani commented Nov 5, 2024

@ffromani there is an example. #127790 (comment)

thanks, the reason I ask is because defer is a core golang mechanism so I'm a bit surprised it doesn't work. But thinking about it, the way ginkgo works can explain the situation.

@ffromani
Copy link
Contributor

ffromani commented Nov 5, 2024

/triage accepted

I think we have enough evidence this is a fix we want, so I'm triage-accepting. Deferring prioritization (and review) to sig-auth

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 5, 2024
@carlory
Copy link
Member Author

carlory commented Nov 6, 2024

{ failed [FAILED] unexpected delay duration before killing the pod, cost = 20.118938619s
In [It] at: k8s.io/kubernetes/test/e2e/common/node/lifecycle_hook.go:610 @ 11/05/24 17:26:38.009
}

unrelated failure

/retest

@@ -268,11 +268,11 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
var cleanups []func(ctx context.Context)
var projections []v1.VolumeProjection

defer func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is added to that hook at the beginning, see line 65

	ginkgo.JustBeforeEach(func(ctx context.Context) {
		cleanup := mustInitCTBs(ctx, f, initCTBs)
		ginkgo.DeferCleanup(cleanup)
	})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aojea The initCTBs and cleanups are declared in the It container, not in its parent container Describe.

so JustBeforeEach won't call cleanups.

BTW, in my opinion, the JustBeforeEach is abused here. It's used to separate creation and configuration which is set with the BeforeEach in each child It container. JustBeforeEach should be used with care as it can add complexity to a test suite.

While powerful and flexible overuse of JustBeforeEach (and nest JustBeforeEaches in particular!) can lead to confusing suites to be sure to use JustBeforeEach judiciously!
From the doc https://onsi.github.io/ginkgo/#separating-creation-and-configuration-justbeforeeach

BeforeEach may be enough for this e2e suite.

@stlaz
Copy link
Member

stlaz commented Jan 2, 2025

I used this patch in #129053 (with correct author - you) if that's ok. Aside from fixing the tests to run in parallel, the PR also replaces the JustBeforeEach with a plain BeforeEach.

@carlory
Copy link
Member Author

carlory commented Jan 3, 2025

Thanks @stlaz

/close

@k8s-ci-robot
Copy link
Contributor

@carlory: Closed this PR.

In response to this:

Thanks @stlaz

/close

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.

@carlory carlory deleted the fix-128578 branch January 3, 2025 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/flake Categorizes issue or PR as related to a flaky test. 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/auth Categorizes an issue or PR as relevant to SIG Auth. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XS Denotes a PR that changes 0-9 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.

5 participants