Skip to content

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

@nilo19

Description

@nilo19

What happened:

Several e2e cases in tests/e2e/network/ensureloadbalancer.go create and expose a Service, then call Get(...), and only register the cleanup defer after that Get returns. If that Get call fails, or if Expect(err).NotTo(HaveOccurred()) fails immediately after it, the cleanup defer is never registered, so the test can leave the Service behind.

Confirmed occurrences:

  • It("should respect service with various configurations") at tests/e2e/network/ensureloadbalancer.go:986-992
  • It("should respect service with BYO public IP with various configurations") at tests/e2e/network/ensureloadbalancer.go:1050-1056
  • It("should respect service with BYO public IP prefix with various configurations") at tests/e2e/network/ensureloadbalancer.go:1114-1120
  • It("should respect internal service with various configurations") at tests/e2e/network/ensureloadbalancer.go:1148-1154

What you expected to happen:

Cleanup should be registered as soon as the Service is known to exist, before later Get(...) calls or assertions that can abort the spec.

How to reproduce it (as minimally and precisely as possible):

  1. Run one of the listed tests.
  2. Force the Get(...) call at one of the listed locations to return an error, or inject a failing assertion before the cleanup defer line.
  3. Observe that the DeleteService(...) cleanup block is never executed because the defer was not registered yet.

Anything else we need to know?:

I searched tests/e2e for the same Get(...); defer cleanup; Expect(err) ordering and found the four confirmed cases above.

I also checked nearby WaitServiceExposureAndValidateConnectivity(...) cases. Those are less urgent because that helper already deletes the Service on its own error path, so this issue is scoped to the confirmed post-create Get(...) gaps.

A straightforward fix would be to move the cleanup registration earlier, immediately after Create(...) succeeds or immediately after any helper that guarantees the Service exists.

Environment:

  • Kubernetes version (use kubectl version): N/A
  • Cloud provider or hardware configuration: N/A
  • OS (e.g: cat /etc/os-release): N/A
  • Kernel (e.g. uname -a): N/A
  • Install tools: N/A
  • Network plugin and version (if this is a network-related bug): N/A
  • Others: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions