Skip to content

test(e2e): hold the pod in Pending so the Sandbox Pending phase is observable - #1154

Open
NopeCharon wants to merge 1 commit into
openkruise:masterfrom
NopeCharon:fix/e2e-sandbox-pending-phase-flake
Open

NopeCharon wants to merge 1 commit into
openkruise:masterfrom
NopeCharon:fix/e2e-sandbox-pending-phase-flake

Conversation

@NopeCharon

Copy link
Copy Markdown

Ⅰ. Describe what this PR does

Fixes the intermittent failure of the E2E spec Sandbox / creation and pending phase / should create sandbox and transition to running phase. The spec fails with Expected <Running> to equal <Pending> after the 30s timeout.

The sandbox controller moves a Sandbox from Pending to Running as soon as the Pod phase becomes Running (EnsureSandboxRunning in pkg/controller/sandbox/core/common_control.go). It doesn't wait for readiness. The spec currently sets a readiness probe with InitialDelaySeconds: 5 to keep Pending observable, but that probe only delays the Pod Ready condition, not the Pod phase. On a warm Kind node the Sandbox Pending window is just scheduling plus IP allocation. It was ~497ms in the run linked from #1110, which is shorter than the 500ms Eventually poll interval, so the first GET can already return Running.

This PR replaces the readiness probe with a short init container (sh -c "sleep 5", same image as the main container, so there's no extra pull). A Pod stays in phase Pending while its init containers run, so the Sandbox stays Pending for at least 5 seconds, about ten poll intervals. Nothing changes after that: the spec still waits for Running and checks the revision.

The other Should(Equal(SandboxPending)) assertions in this file (mentioned in #1094) belong to the ResourceQuota spec. There the Pod is never created, so Pending is stable and those assertions don't race.

Ⅱ. Does this pull request fix one issue?

fixes #1110
fixes #1094

Ⅲ. Describe how to verify it

  • go vet ./test/e2e/ passes.
  • Run the E2E-1.32 workflow. The creation and pending phase spec now observes Pending even on a node where nginx:stable-alpine3.20 is already cached, because the Pod is held in its Pending phase for the 5 seconds the init container runs.

Ⅳ. Special notes for reviews

This is a test-only change. Controller behavior is unchanged.

…servable

The "should create sandbox and transition to running phase" spec polls
every 500ms for Sandbox.Status.Phase == Pending. The sandbox controller
moves a Sandbox from Pending to Running as soon as its Pod phase becomes
Running (EnsureSandboxRunning in common_control.go), independent of the
Pod's readiness. On a warm Kind node the whole Pending window is only
scheduling plus IP allocation, which has been observed at ~497ms, so the
first poll can already see Running and the spec times out.

The readiness probe with InitialDelaySeconds: 5 that was meant to keep
the Pending phase observable only delays the Pod Ready condition, not the
Pod phase, so it never extended the window.

Replace it with a short init container that sleeps for 5 seconds. A Pod
stays in its Pending phase while init containers run, so the Sandbox
remains Pending for at least 5 seconds (about ten poll intervals). The
init container reuses the image of the main container, so no extra image
pull is introduced.

The other Pending assertions in this file belong to the ResourceQuota
spec, where the Pod is never created and Pending is stable, so they do
not race.

Fixes openkruise#1110
Fixes openkruise#1094

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
@kruise-bot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign furykerry for approval by writing /assign @furykerry in a comment. For more information see:The Kubernetes 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

@kruise-bot

Copy link
Copy Markdown

Welcome @NopeCharon! It looks like this is your first PR to openkruise/agents 🎉

@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.47%. Comparing base (0f98e18) to head (d444720).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1154   +/-   ##
=======================================
  Coverage   84.47%   84.47%           
=======================================
  Files         280      280           
  Lines       25109    25109           
=======================================
  Hits        21212    21212           
  Misses       3082     3082           
  Partials      815      815           
Flag Coverage Δ
unittests 84.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

Projects

None yet

2 participants