Skip to content

fix: register e2e Service cleanup defer before it can be skipped - #10829

Open
pujitha24 wants to merge 1 commit into
kubernetes-sigs:masterfrom
pujitha24:auto/issue-10126
Open

fix: register e2e Service cleanup defer before it can be skipped#10829
pujitha24 wants to merge 1 commit into
kubernetes-sigs:masterfrom
pujitha24:auto/issue-10126

Conversation

@pujitha24

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

In tests/e2e/network/ensureloadbalancer.go, four specs create/expose a
Service and only register the cleanup defer DeleteService(...) after a
later Get(...) call, with one or more Expect(...) assertions running
between successful service creation and that defer registration. In
Ginkgo v2 + Gomega, a failing Expect(...) unwinds the current goroutine
via runtime.Goexit(); any defer not yet registered at that point is
skipped. If the Service already exists by then and one of those
intervening assertions fails, the cleanup never runs and the Service is
left behind in the cluster.

This PR moves each defer to be registered immediately after the point
where the Service is first known to exist (right after Create(...)
succeeds, or right after the createAndExposeDefaultServiceWithAnnotation(...)
helper returns), before any subsequent Expect(...) calls. This mirrors
the fix suggested in the issue report. utils.DeleteService already
treats a NotFound error as success, so registering the deferred delete
this early is safe even on the path where creation itself failed.

Which issue(s) this PR fixes:

Fixes #10126

Special notes for your reviewer:

  • This is a test-only change; tests/e2e/network/ensureloadbalancer.go is
    the only file touched (4 hunks, 14 insertions / 14 deletions).
  • Validation performed: go build ./e2e/network/..., go vet ./e2e/network/...,
    gofmt -l, and golangci-lint run against the tests module — all pass,
    and golangci-lint reports the same 33 pre-existing issues before and after
    this change, confirming no new lint issues were introduced.
  • These specs are Ginkgo e2e tests that require a live Azure/AKS cluster to
    execute; that isn't available in this environment, so the fix was not
    exercised against a live cluster. The correctness argument rests on Go's
    documented defer/Goexit semantics and static review of the reordered
    control flow, not a live reproduction.
  • CI on this repo requires a maintainer to add ok-to-test — happy to
    address anything it surfaces.

Does this PR introduce a user-facing change?

NONE

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


Motivation:
In tests/e2e/network/ensureloadbalancer.go, four specs create/expose a
Service and only register the cleanup `defer DeleteService(...)` after
a later Get(...) call, with one or more Expect(...) assertions running
between successful service creation and that defer registration. In
Ginkgo v2 + Gomega, a failing Expect(...) unwinds the current goroutine
via runtime.Goexit(); any defer not yet registered at that point is
skipped. If the Service already exists by then and one of those
intervening assertions fails, the cleanup never runs and the Service
leaks.

Approach:
Move each defer to be registered immediately after the point where the
Service is first known to exist (right after Create(...) succeeds, or
right after the createAndExposeDefaultServiceWithAnnotation(...)
helper returns), before any subsequent Expect(...) calls. This mirrors
the fix suggested in the issue report. utils.DeleteService already
treats a NotFound error as success, so registering the deferred delete
this early is safe even on the path where creation itself failed.

Validation:
- cd tests && go build ./e2e/network/...  (passes)
- cd tests && go vet ./e2e/network/...  (passes, no findings)
- gofmt -l tests/e2e/network/ensureloadbalancer.go  (no output, file formatted)
- cd tests && golangci-lint run --config ../.golangci.yml ./e2e/network/...
  reports the same 33 pre-existing issues (goconst/ineffassign/staticcheck)
  before and after this change, confirming no new lint issues were introduced.
These specs are Ginkgo e2e tests that require a live Azure/AKS cluster
to execute; that is not available in this environment, so the fix was
not exercised against a live cluster. The correctness argument rests on
Go's documented defer/Goexit semantics and static review of the
reordered control flow, not a live reproduction.

Report: kubernetes-sigs#10126
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@kubernetes-prow kubernetes-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. labels Aug 13, 2026
@github-actions github-actions Bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Aug 13, 2026
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 13, 2026
@kubernetes-prow

Copy link
Copy Markdown

Hi @pujitha24. 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.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

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.

Details

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.

@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Details 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

@kubernetes-prow kubernetes-prow Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 13, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from anndono and nilo19 August 13, 2026 22:35
@pujitha24

Copy link
Copy Markdown
Author

/assign @bridgetkromhout

Small test-only fix, ready for review whenever you have a moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests/e2e: ensureloadbalancer can skip service cleanup when post-create Get fails

2 participants