Skip to content

OCPBUGS-77990: kubelet: close resize race in sync pod - #2743

Closed
haircommander wants to merge 2 commits into
openshift:masterfrom
haircommander:fix-syncpod-resize-race-openshift
Closed

haircommander wants to merge 2 commits into
openshift:masterfrom
haircommander:fix-syncpod-resize-race-openshift

Conversation

@haircommander

@haircommander haircommander commented Aug 11, 2026

Copy link
Copy Markdown
Member

What type of PR is this?

/kind bug

What this PR does / why we need it:

Formerly there was a race condition where SyncPod would check whether a resize was in progress using a stale snapshot of the pod. The pod worker snapshots the allocation at UpdatePod time, but the allocation manager goroutine may accept a new resize before SyncPod runs, so IsPodResizeInProgress could compare the stale allocation against actuated state and prematurely clear the PodResizeInProgress condition.

Move the resize progress check into the allocation manager (CheckResizeProgress), where it is serialized with retryPendingResizes under allocationMutex. This reads the current allocation and manages the condition atomically, closing the race.

fixes flakes in pod-resize-retry-deferred-test-2 seen in openshift CI

Which issue(s) this PR is related to:

Special notes for your reviewer:

co-authored by claude 4.8

Does this PR introduce a user-facing change?

none

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


Summary by CodeRabbit

  • Bug Fixes
    • Improved in-place pod resizing progress tracking.
    • Pod resize status now remains accurate when allocation data is temporarily outdated.
    • Resize completion is reported only after resources are fully applied.
    • Improved handling of pending resize operations and completion events.

Formerly there was a race condition where SyncPod would check whether a
resize was in progress using a stale snapshot of the pod. The pod worker
snapshots the allocation at UpdatePod time, but the allocation manager
goroutine may accept a new resize before SyncPod runs, so
IsPodResizeInProgress could compare the stale allocation against actuated
state and prematurely clear the PodResizeInProgress condition.

Move the resize progress check into the allocation manager
(CheckResizeProgress), where it is serialized with retryPendingResizes
under allocationMutex. This reads the current allocation and manages the
condition atomically, closing the race.

Signed-off-by: Peter Hunt <pehunt@redhat.com>
The stale-allocation race in SyncPod resize completion detection that
caused pod-resize-retry-deferred-test-2 to fail is fixed by
UPSTREAM: 141325. Remove the OCPBUGS-64847 skip so the test runs again.

Signed-off-by: Peter Hunt <pehunt@redhat.com>
@openshift-merge-bot

Copy link
Copy Markdown

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the backports/unvalidated-commits Indicates that not all commits come to merged upstream PRs. label Aug 11, 2026
@openshift-ci openshift-ci Bot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 11, 2026
@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Aug 11, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@haircommander: This pull request references Jira Issue OCPBUGS-77990, which is invalid:

  • expected the bug to be open, but it isn't
  • expected the bug to target either version "5.0." or "openshift-5.0.", but it targets "4.22.0" instead
  • expected the bug to be in one of the following states: NEW, ASSIGNED, POST, but it is Closed (Done) instead

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

What type of PR is this?

/kind bug

What this PR does / why we need it:

Formerly there was a race condition where SyncPod would check whether a resize was in progress using a stale snapshot of the pod. The pod worker snapshots the allocation at UpdatePod time, but the allocation manager goroutine may accept a new resize before SyncPod runs, so IsPodResizeInProgress could compare the stale allocation against actuated state and prematurely clear the PodResizeInProgress condition.

Move the resize progress check into the allocation manager (CheckResizeProgress), where it is serialized with retryPendingResizes under allocationMutex. This reads the current allocation and manages the condition atomically, closing the race.

fixes flakes in pod-resize-retry-deferred-test-2 seen in openshift CI

Which issue(s) this PR is related to:

Special notes for your reviewer:

co-authored by claude 4.8

Does this PR introduce a user-facing change?

none

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


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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot

Copy link
Copy Markdown

@haircommander: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

@openshift-ci
openshift-ci Bot requested review from jacobsee and sjenning August 11, 2026 20:30
@openshift-ci

openshift-ci Bot commented Aug 11, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Walkthrough

The kubelet now delegates pod resize-progress evaluation to the allocation manager. Runtime resize state drives condition updates and completion events. Tests add asynchronous synchronization and cover stale allocation snapshots and completed resizes.

Changes

Pod resize progress

Layer / File(s) Summary
Allocation resize-progress contract
pkg/kubelet/allocation/allocation_manager.go
Adds Manager.CheckResizeProgress to serialize allocation reads, update resize conditions, and return the cleared generation.
Kubelet resize-progress integration
pkg/kubelet/container/testing/fake_runtime.go, pkg/kubelet/kubelet.go
Adds an injectable runtime resize-state callback. SyncPod uses allocation-manager progress checks and emits completion events when resizing finishes.
Resize race regression coverage
pkg/kubelet/kubelet_test.go, openshift-hack/cmd/k8s-tests-ext/disabled_tests.go
Synchronizes asynchronous pod syncs, tests stale and current allocations, and removes the deferred resize test from the disabled list.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SyncPod
  participant ContainerRuntime
  participant AllocationManager
  SyncPod->>ContainerRuntime: Read pod resize state
  SyncPod->>AllocationManager: CheckResizeProgress with runtime predicate
  AllocationManager->>AllocationManager: Apply allocation and update condition
  AllocationManager-->>SyncPod: Return cleared generation
  SyncPod-->>SyncPod: Emit ResizeCompleted when resizing is complete
Loading
🚥 Pre-merge checks | ✅ 5 | ❌ 10

❌ Failed checks (10 inconclusive)

Check name Status Explanation Resolution
Stable And Deterministic Test Names ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Test Structure And Quality ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Microshift Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Single Node Openshift (Sno) Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Topology-Aware Scheduling Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Ote Binary Stdout Contract ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Ipv6 And Disconnected Network Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
No-Weak-Crypto ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Container-Privileges ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
No-Sensitive-Data-In-Logs ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the kubelet resize-race fix, which is the main change in the pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@haircommander haircommander changed the title OCPBUGS-77990: Fix syncpod resize race openshift OCPBUGS-77990: Open kubelet: close resize race in sync pod Aug 11, 2026
@haircommander haircommander changed the title OCPBUGS-77990: Open kubelet: close resize race in sync pod OCPBUGS-77990: kubelet: close resize race in sync pod Aug 11, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@haircommander: This pull request references Jira Issue OCPBUGS-77990, which is invalid:

  • expected the bug to be open, but it isn't
  • expected the bug to target either version "5.0." or "openshift-5.0.", but it targets "4.22.0" instead
  • expected the bug to be in one of the following states: NEW, ASSIGNED, POST, but it is Closed (Done) instead

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

What type of PR is this?

/kind bug

What this PR does / why we need it:

Formerly there was a race condition where SyncPod would check whether a resize was in progress using a stale snapshot of the pod. The pod worker snapshots the allocation at UpdatePod time, but the allocation manager goroutine may accept a new resize before SyncPod runs, so IsPodResizeInProgress could compare the stale allocation against actuated state and prematurely clear the PodResizeInProgress condition.

Move the resize progress check into the allocation manager (CheckResizeProgress), where it is serialized with retryPendingResizes under allocationMutex. This reads the current allocation and manages the condition atomically, closing the race.

fixes flakes in pod-resize-retry-deferred-test-2 seen in openshift CI

Which issue(s) this PR is related to:

Special notes for your reviewer:

co-authored by claude 4.8

Does this PR introduce a user-facing change?

none

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


Summary by CodeRabbit

  • Bug Fixes
  • Improved in-place pod resizing progress tracking.
  • Pod resize status now remains accurate when allocation data is temporarily outdated.
  • Resize completion is reported only after resources are fully applied.
  • Improved handling of pending resize operations and completion events.

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 openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
pkg/kubelet/container/testing/fake_runtime.go (1)

595-599: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Guard the field reads with the existing mutex.

FakeRuntime embeds sync.Mutex, and methods such as SyncPod lock it before they touch fields. IsPodResizeInProgress reads PodResizeInProgressFunc and PodResizeInProgress without the lock. Tests now assign these fields while the allocation manager can dispatch SyncPod on a separate goroutine (see pkg/kubelet/kubelet_test.go lines 356-362). That combination can trigger a -race failure.

Note that the callback itself runs while the allocation manager holds allocationMutex, so keep the locked section limited to the field reads.

♻️ Proposed change
 func (f *FakeRuntime) IsPodResizeInProgress(allocatedPod *v1.Pod, podStatus *kubecontainer.PodStatus) bool {
-	if f.PodResizeInProgressFunc != nil {
-		return f.PodResizeInProgressFunc(allocatedPod, podStatus)
+	f.Lock()
+	fn := f.PodResizeInProgressFunc
+	inProgress := f.PodResizeInProgress
+	f.Unlock()
+	if fn != nil {
+		return fn(allocatedPod, podStatus)
 	}
-	return f.PodResizeInProgress
+	return inProgress
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/kubelet/container/testing/fake_runtime.go` around lines 595 - 599, Update
FakeRuntime.IsPodResizeInProgress to lock the embedded mutex while reading
PodResizeInProgressFunc and PodResizeInProgress, but release it before invoking
the callback; preserve the existing callback-precedence and fallback behavior.
pkg/kubelet/allocation/allocation_manager.go (2)

113-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document that the callback runs while allocationMutex is held.

CheckResizeProgress invokes isResizeInProgress inside the lock. A callback that calls any other Manager method deadlocks, because sync.Mutex is not reentrant. State this constraint in the interface comment so future callers do not re-enter the manager.

📝 Proposed doc addition
 	// The isResizeInProgress callback receives the pod with current allocation
 	// applied and should return true if the resize has not yet been actuated.
+	// The callback is invoked while the allocation lock is held. It must not
+	// call back into the allocation Manager, and it should not block.
 	// Returns the cleared generation and true if the resize completed.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/kubelet/allocation/allocation_manager.go` around lines 113 - 121, Update
the interface comment for CheckResizeProgress to state that isResizeInProgress
executes while allocationMutex is held and must not call other Manager methods
or otherwise re-enter the manager. Keep the existing callback behavior and
return-value documentation unchanged.

558-566: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Document that CheckResizeProgress invokes the callback while holding allocationMutex

kubeGenericRuntimeManager.IsPodResizeInProgress performs only in-memory checks and state reads. Keep the callback contract explicit: it must not re-enter the allocation manager or perform blocking work.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/kubelet/allocation/allocation_manager.go` around lines 558 - 566,
Document in CheckResizeProgress that isResizeInProgress executes while
allocationMutex is held, and state that callbacks must perform only non-blocking
in-memory checks without re-entering the allocation manager. Keep the existing
locking and callback behavior unchanged.
pkg/kubelet/kubelet_test.go (1)

4215-4245: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the generation carried by the completion path.

CheckResizeProgress returns the cleared generation, and SyncPod puts that generation into the ResizeCompleted message. The subtest checks only that the event string contains ResizeCompleted. Assert the generation too, so a regression in the returned value is caught.

pod.Generation is 2 and the condition is set with that generation at line 4221, so the message should carry generation 2.

♻️ Proposed assertion
 		var foundCompleted bool
 		for len(fakeRecorder.Events) > 0 {
 			event := <-fakeRecorder.Events
 			if strings.Contains(event, "ResizeCompleted") {
 				foundCompleted = true
+				require.Contains(t, event, `"generation":2`, "ResizeCompleted event should carry the cleared generation")
 			}
 		}
 		require.True(t, foundCompleted, "expected ResizeCompleted event")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/kubelet/kubelet_test.go` around lines 4215 - 4245, Strengthen the
“completed resize should clear condition and emit event” subtest by asserting
that the captured ResizeCompleted event also contains generation 2, matching
pod.Generation and the generation passed to SetPodResizeInProgressCondition.
Keep the existing event-presence assertion and inspect the event text while
draining fakeRecorder.Events.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/kubelet/kubelet_test.go`:
- Around line 348-362: Add defer testKubelet.Cleanup() to the test fixtures at
the specified locations in kubelet_node_status_test.go and kubelet_pods_test.go.
Ensure each test performs cleanup before returning so the WaitGroup is joined
and the kubelet root directory is removed.

---

Nitpick comments:
In `@pkg/kubelet/allocation/allocation_manager.go`:
- Around line 113-121: Update the interface comment for CheckResizeProgress to
state that isResizeInProgress executes while allocationMutex is held and must
not call other Manager methods or otherwise re-enter the manager. Keep the
existing callback behavior and return-value documentation unchanged.
- Around line 558-566: Document in CheckResizeProgress that isResizeInProgress
executes while allocationMutex is held, and state that callbacks must perform
only non-blocking in-memory checks without re-entering the allocation manager.
Keep the existing locking and callback behavior unchanged.

In `@pkg/kubelet/container/testing/fake_runtime.go`:
- Around line 595-599: Update FakeRuntime.IsPodResizeInProgress to lock the
embedded mutex while reading PodResizeInProgressFunc and PodResizeInProgress,
but release it before invoking the callback; preserve the existing
callback-precedence and fallback behavior.

In `@pkg/kubelet/kubelet_test.go`:
- Around line 4215-4245: Strengthen the “completed resize should clear condition
and emit event” subtest by asserting that the captured ResizeCompleted event
also contains generation 2, matching pod.Generation and the generation passed to
SetPodResizeInProgressCondition. Keep the existing event-presence assertion and
inspect the event text while draining fakeRecorder.Events.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c9a82ced-cda5-4236-8a8a-16c2047024d0

📥 Commits

Reviewing files that changed from the base of the PR and between e63ab41 and c1129f0.

📒 Files selected for processing (5)
  • openshift-hack/cmd/k8s-tests-ext/disabled_tests.go
  • pkg/kubelet/allocation/allocation_manager.go
  • pkg/kubelet/container/testing/fake_runtime.go
  • pkg/kubelet/kubelet.go
  • pkg/kubelet/kubelet_test.go
💤 Files with no reviewable changes (1)
  • openshift-hack/cmd/k8s-tests-ext/disabled_tests.go

Comment on lines +348 to +362
podSyncWG := &sync.WaitGroup{}
kubelet.allocationManager = allocation.NewInMemoryManager(
kubelet.statusManager,
func(pod *v1.Pod) { kubelet.HandlePodSyncs(tCtx, []*v1.Pod{pod}) },
// The production pod worker dispatches syncs asynchronously, so the
// allocation manager can trigger a sync while holding allocationMutex
// (e.g. from retryPendingResizes) without the resulting SyncPod, which
// re-acquires allocationMutex via CheckResizeProgress, deadlocking.
// Mirror that here by running the sync on a separate goroutine.
func(pod *v1.Pod) {
podSyncWG.Add(1)
go func() {
defer podSyncWG.Done()
kubelet.HandlePodSyncs(tCtx, []*v1.Pod{pod})
}()
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: List TestKubelet construction sites and check for Cleanup in the same function.
set -euo pipefail

fd -e go . pkg/kubelet --max-depth 1 | while IFS= read -r f; do
  rg -n 'newTestKubelet[A-Za-z]*\(' "$f" || true
done

echo "--- Cleanup call sites ---"
rg -n --type=go '\.Cleanup\(\)' pkg/kubelet

Repository: openshift/kubernetes

Length of output: 15697


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- TestKubelet definition and Cleanup ---"
rg -n -A35 -B8 'type TestKubelet struct|func \(.*TestKubelet.*Cleanup' pkg/kubelet

echo "--- Construction sites with enclosing test/function context ---"
python3 - <<'PY'
from pathlib import Path
import re

for path in sorted(Path("pkg/kubelet").glob("*_test.go")):
    text = path.read_text()
    lines = text.splitlines()
    starts = [i for i, line in enumerate(lines) if re.search(r'\bnewTestKubelet(?:WithImageList|ExcludeAdmitHandlers)?\s*\(', line)]
    if not starts:
        continue
    print(f"\n{path}")
    for i in starts:
        # Show the nearest preceding function declaration and a bounded local region.
        fn = next((j for j in range(i, -1, -1) if re.match(r'\s*func\b', lines[j])), None)
        end = min(len(lines), i + 8)
        print(f"construction line {i+1}; enclosing declaration line {(fn+1) if fn is not None else '?'}")
        for j in range(max(0, i-1), end):
            print(f"{j+1}: {lines[j]}")
PY

echo "--- All Cleanup references in kubelet test files ---"
rg -n --type=go '\b(?:testKubelet|testKubeletNoReset|tk)\.Cleanup\(\)|\.Cleanup\(func' pkg/kubelet

Repository: openshift/kubernetes

Length of output: 50376


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- TestKubelet definition and Cleanup ---"
rg -n -A35 -B8 'type TestKubelet struct|func \(.*TestKubelet.*Cleanup' pkg/kubelet

echo "--- Construction sites with enclosing test/function context ---"
python3 - <<'PY'
from pathlib import Path
import re

for path in sorted(Path("pkg/kubelet").glob("*_test.go")):
    text = path.read_text()
    lines = text.splitlines()
    starts = [i for i, line in enumerate(lines) if re.search(r'\bnewTestKubelet(?:WithImageList|ExcludeAdmitHandlers)?\s*\(', line)]
    if not starts:
        continue
    print(f"\n{path}")
    for i in starts:
        fn = next((j for j in range(i, -1, -1) if re.match(r'\s*func\b', lines[j])), None)
        end = min(len(lines), i + 8)
        print(f"construction line {i+1}; enclosing declaration line {(fn+1) if fn is not None else '?'}")
        for j in range(max(0, i-1), end):
            print(f"{j+1}: {lines[j]}")
PY

echo "--- All Cleanup references in kubelet test files ---"
rg -n --type=go '\b(?:testKubelet|testKubeletNoReset|tk)\.Cleanup\(\)|\.Cleanup\(func' pkg/kubelet

Repository: openshift/kubernetes

Length of output: 50376


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- Target test and related synchronization ---"
sed -n '320,390p' pkg/kubelet/kubelet_node_status_test.go
rg -n -C4 'podSyncWG|triggerPodSync|HandlePodSyncs|retryPendingResizes|enableResizing|NewInMemoryManager' pkg/kubelet/kubelet_test.go pkg/kubelet/*_test.go

echo "--- Construction sites without a nearby Cleanup ---"
python3 - <<'PY'
from pathlib import Path
import re

construct = re.compile(r'\b(newTestKubelet(?:WithImageList|ExcludeAdmitHandlers)?)\s*\(')
cleanup = re.compile(r'\b(?:testKubelet|testKubeletNoReset|tk)\.Cleanup\s*\(\)|\.Cleanup\s*\(\s*func')
for path in sorted(Path("pkg/kubelet").glob("*_test.go")):
    lines = path.read_text().splitlines()
    for i, line in enumerate(lines):
        if not construct.search(line):
            continue
        # Skip helper definitions and calls inside helper implementations.
        if re.match(r'\s*func\b', line) or i < 230 and path.name == "kubelet_test.go":
            continue
        window = "\n".join(lines[i:min(len(lines), i+12)])
        if not cleanup.search(window):
            print(f"{path}:{i+1}: {line.strip()}")
PY

echo "--- Missing-cleanup test bodies ---"
sed -n '1645,1685p' pkg/kubelet/kubelet_node_status_test.go
sed -n '2160,2205p' pkg/kubelet/kubelet_node_status_test.go
sed -n '2455,2510p' pkg/kubelet/kubelet_node_status_test.go
sed -n '3575,3625p' pkg/kubelet/kubelet_pods_test.go

Repository: openshift/kubernetes

Length of output: 37402


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- Target test and related synchronization ---"
sed -n '320,390p' pkg/kubelet/kubelet_node_status_test.go
rg -n -C4 'podSyncWG|triggerPodSync|HandlePodSyncs|retryPendingResizes|enableResizing|NewInMemoryManager' pkg/kubelet/kubelet_test.go pkg/kubelet/*_test.go

echo "--- Construction sites without a nearby Cleanup ---"
python3 - <<'PY'
from pathlib import Path
import re

construct = re.compile(r'\b(newTestKubelet(?:WithImageList|ExcludeAdmitHandlers)?)\s*\(')
cleanup = re.compile(r'\b(?:testKubelet|testKubeletNoReset|tk)\.Cleanup\s*\(\)|\.Cleanup\s*\(\s*func')
for path in sorted(Path("pkg/kubelet").glob("*_test.go")):
    lines = path.read_text().splitlines()
    for i, line in enumerate(lines):
        if not construct.search(line):
            continue
        if re.match(r'\s*func\b', line) or i < 230 and path.name == "kubelet_test.go":
            continue
        window = "\n".join(lines[i:min(len(lines), i+12)])
        if not cleanup.search(window):
            print(f"{path}:{i+1}: {line.strip()}")
PY

echo "--- Missing-cleanup test bodies ---"
sed -n '1645,1685p' pkg/kubelet/kubelet_node_status_test.go
sed -n '2160,2205p' pkg/kubelet/kubelet_node_status_test.go
sed -n '2455,2510p' pkg/kubelet/kubelet_node_status_test.go
sed -n '3575,3625p' pkg/kubelet/kubelet_pods_test.go

Repository: openshift/kubernetes

Length of output: 37402


Add cleanup for all uncleaned TestKubelet fixtures

Add defer testKubelet.Cleanup() at pkg/kubelet/kubelet_node_status_test.go:1659, pkg/kubelet/kubelet_node_status_test.go:2468, and pkg/kubelet/kubelet_pods_test.go:3590. These tests otherwise skip the WaitGroup join and kubelet root-directory cleanup.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/kubelet/kubelet_test.go` around lines 348 - 362, Add defer
testKubelet.Cleanup() to the test fixtures at the specified locations in
kubelet_node_status_test.go and kubelet_pods_test.go. Ensure each test performs
cleanup before returning so the WaitGroup is joined and the kubelet root
directory is removed.

@openshift-ci

openshift-ci Bot commented Aug 11, 2026

Copy link
Copy Markdown

@haircommander: 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
ci/prow/perfscale-control-plane-6nodes c1129f0 link false /test perfscale-control-plane-6nodes

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 12, 2026
@openshift-ci

openshift-ci Bot commented Aug 12, 2026

Copy link
Copy Markdown

PR needs rebase.

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.

@openshift-ci-robot

Copy link
Copy Markdown

@haircommander: This pull request references Jira Issue OCPBUGS-77990. The bug has been updated to no longer refer to the pull request using the external bug tracker.

Details

In response to this:

What type of PR is this?

/kind bug

What this PR does / why we need it:

Formerly there was a race condition where SyncPod would check whether a resize was in progress using a stale snapshot of the pod. The pod worker snapshots the allocation at UpdatePod time, but the allocation manager goroutine may accept a new resize before SyncPod runs, so IsPodResizeInProgress could compare the stale allocation against actuated state and prematurely clear the PodResizeInProgress condition.

Move the resize progress check into the allocation manager (CheckResizeProgress), where it is serialized with retryPendingResizes under allocationMutex. This reads the current allocation and manages the condition atomically, closing the race.

fixes flakes in pod-resize-retry-deferred-test-2 seen in openshift CI

Which issue(s) this PR is related to:

Special notes for your reviewer:

co-authored by claude 4.8

Does this PR introduce a user-facing change?

none

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


Summary by CodeRabbit

  • Bug Fixes
  • Improved in-place pod resizing progress tracking.
  • Pod resize status now remains accurate when allocation data is temporarily outdated.
  • Resize completion is reported only after resources are fully applied.
  • Improved handling of pending resize operations and completion events.

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 openshift-eng/jira-lifecycle-plugin repository.

@haircommander

Copy link
Copy Markdown
Member Author

trying #2765 instead

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

Labels

backports/unvalidated-commits Indicates that not all commits come to merged upstream PRs. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. kind/bug Categorizes issue or PR as related to a bug. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants