Skip to content

OCPBUGS-84504: retry transient kubeconfig read failures in GetClientConfig#31080

Merged
openshift-merge-bot[bot] merged 1 commit intoopenshift:mainfrom
dgoodwin:admin-kubeconfig-retry
Apr 28, 2026
Merged

OCPBUGS-84504: retry transient kubeconfig read failures in GetClientConfig#31080
openshift-merge-bot[bot] merged 1 commit intoopenshift:mainfrom
dgoodwin:admin-kubeconfig-retry

Conversation

@dgoodwin
Copy link
Copy Markdown
Contributor

@dgoodwin dgoodwin commented Apr 27, 2026

During upgrade prow jobs the kubeconfig Secret volume is re-mounted by
the kubelet, which atomically swaps symlinks and creates a sub-second
window where ReadFile() returns ENOENT or reads empty/partial content.
With 10-15 parallel Ginkgo goroutines all calling GetClientConfig() on
every client creation, this window can cause rare mass test failures.

Replace the single ReadFile attempt with a wait.PollImmediate retry
(200ms interval, 10s timeout) that retries on file-not-found, empty
file, or clientcmd parse errors. Non-transient I/O errors still fail
immediately. Adds unit tests covering all four cases.

Fixes: OCPBUGS-84504

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Summary by CodeRabbit

  • Bug Fixes

    • Improved kubeconfig file reading resilience with automatic retry logic for transient failures.
  • Tests

    • Added comprehensive test coverage for kubeconfig loading scenarios including file availability and content validation edge cases.

During upgrade prow jobs the kubeconfig Secret volume is re-mounted by
the kubelet, which atomically swaps symlinks and creates a sub-second
window where ReadFile() returns ENOENT or reads empty/partial content.
With 10-15 parallel Ginkgo goroutines all calling GetClientConfig() on
every client creation, this window reliably causes mass test failures.

Replace the single ReadFile attempt with a wait.PollImmediate retry
(200ms interval, 10s timeout) that retries on file-not-found, empty
file, or clientcmd parse errors. Non-transient I/O errors still fail
immediately. Adds unit tests covering all four cases.

Fixes: OCPBUGS-84504

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

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: automatic mode

@dgoodwin dgoodwin changed the title test/util: retry transient kubeconfig read failures in GetClientConfig OCPBUGS-84504: retry transient kubeconfig read failures in GetClientConfig Apr 27, 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 Apr 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Walkthrough

Modified GetClientConfig to use a retry/polling mechanism for reading and parsing kubeconfig files, with explicit handling for transient failures and empty file contents. Accompanying comprehensive unit tests verify success, retry, and error scenarios with time constraints.

Changes

Cohort / File(s) Summary
Kubeconfig Loading with Retry Logic
test/extended/util/client.go
Changed GetClientConfig from synchronous read/parse to PollImmediate-based retry approach. Now ignores transient "file not found" errors, rejects empty contents, and returns wrapped errors with kubeconfig path and last failure on timeout.
Kubeconfig Client Tests
test/extended/util/client_test.go
Added four test cases covering: successful config load with host verification, file removal/recreation retry success, empty-to-valid-content retry, and permanent file absence error handling with 15-second timeout constraint.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 10 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Structure And Quality ⚠️ Warning Tests lack determinism and proper error handling with unchecked errors from os.Remove() and os.WriteFile(), missing synchronization between file mutations and assertions, and fragile fixed-sleep timing that allows tests to pass without exercising retry logic. Add synchronization primitives (channels or sync.WaitGroup) to coordinate file mutations with test execution and replace fixed-sleep timing with deterministic synchronization using channels.
✅ Passed checks (10 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding retry logic for transient kubeconfig read failures in GetClientConfig, which matches the core change across both modified files.
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.
Stable And Deterministic Test Names ✅ Passed The test file uses standard Go testing functions, not Ginkgo tests, so the custom check targeting Ginkgo test names is not applicable.
Microshift Test Compatibility ✅ Passed The tests are standard Go unit tests, not Ginkgo e2e tests. The MicroShift compatibility check explicitly applies only to new Ginkgo e2e tests, so this check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed Standard Go unit tests using only testing package with no Ginkgo imports, isolating GetClientConfig function without cluster topology assumptions.
Topology-Aware Scheduling Compatibility ✅ Passed This PR only modifies test utility files in test/extended/util/ with no deployment manifests, operator configurations, controllers, or scheduling constraints.
Ote Binary Stdout Contract ✅ Passed The PR modifies internal utility functions and unit tests without any stdout writes in process-level code (init, main, TestMain, BeforeSuite, AfterSuite) that would violate the OTE Binary Stdout Contract.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Unit tests use localhost hostname and local filesystem operations only, with no IPv4-specific code patterns or external connectivity requirements.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci-robot
Copy link
Copy Markdown

@dgoodwin: This pull request references Jira Issue OCPBUGS-84504, which is invalid:

  • expected the bug to target the "5.0.0" version, but no target version was set

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:

During upgrade prow jobs the kubeconfig Secret volume is re-mounted by
the kubelet, which atomically swaps symlinks and creates a sub-second
window where ReadFile() returns ENOENT or reads empty/partial content.
With 10-15 parallel Ginkgo goroutines all calling GetClientConfig() on
every client creation, this window reliably causes mass test failures.

Replace the single ReadFile attempt with a wait.PollImmediate retry
(200ms interval, 10s timeout) that retries on file-not-found, empty
file, or clientcmd parse errors. Non-transient I/O errors still fail
immediately. Adds unit tests covering all four cases.

Fixes: OCPBUGS-84504

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

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 openshift-ci Bot requested review from deads2k and sjenning April 27, 2026 17:14
@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 27, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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 (1)
test/extended/util/client_test.go (1)

76-112: Add coverage for the remaining retry branches.

These tests still don’t exercise the parse-error and non-transient I/O paths that GetClientConfig now distinguishes, so the retry contract is only partially locked down. The timeout assertion is also looser than the 10s poll window, which makes regressions easier to miss.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/extended/util/client_test.go` around lines 76 - 112, Add tests covering
the parse-error and non-transient I/O branches of GetClientConfig and tighten
the timeout assertions to the 10s poll window: add one test that writes an
invalid kubeconfig to path (triggering parse error in GetClientConfig) and
assert it returns an error immediately (elapsed << 1s) with no retries; add
another test that simulates a non-transient I/O error (e.g., create the file or
directory with permissions that cause a permanent permission-denied read) and
assert GetClientConfig returns an error quickly (elapsed < 10s) without
retrying; update the existing TestGetClientConfigFailsOnPermanentMissing and
TestGetClientConfigSucceedsImmediately timeout checks to use the 10s poll window
(assert elapsed < 10s for failures and <1s for immediate success) so behavior is
fully covered and aligned with GetClientConfig’s retry contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/extended/util/client_test.go`:
- Around line 28-74: The retry tests TestGetClientConfigRetryOnMissingFile and
TestGetClientConfigRetryOnEmptyFile are flakey due to fixed sleeps and
fire-and-forget goroutines; change them to synchronize the background file
mutations and surface any file I/O errors so the test deterministically
exercises GetClientConfig's retry window. Specifically, replace the anonymous
goroutines with a goroutine that reports errors over a channel (or use a
sync.WaitGroup) and signal when the mutation is done, wait for that signal
before finishing the test, and check/require the returned error values from
os.Remove/os.WriteFile in those goroutines; ensure the test waits for the
background worker to start the mutation timing (e.g., signal readiness) so the
GetClientConfig call actually encounters the missing/empty file and triggers
retries.

---

Nitpick comments:
In `@test/extended/util/client_test.go`:
- Around line 76-112: Add tests covering the parse-error and non-transient I/O
branches of GetClientConfig and tighten the timeout assertions to the 10s poll
window: add one test that writes an invalid kubeconfig to path (triggering parse
error in GetClientConfig) and assert it returns an error immediately (elapsed <<
1s) with no retries; add another test that simulates a non-transient I/O error
(e.g., create the file or directory with permissions that cause a permanent
permission-denied read) and assert GetClientConfig returns an error quickly
(elapsed < 10s) without retrying; update the existing
TestGetClientConfigFailsOnPermanentMissing and
TestGetClientConfigSucceedsImmediately timeout checks to use the 10s poll window
(assert elapsed < 10s for failures and <1s for immediate success) so behavior is
fully covered and aligned with GetClientConfig’s retry contract.
🪄 Autofix (Beta)

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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: d353c3b8-2956-42cf-b1c8-0567cf438d2b

📥 Commits

Reviewing files that changed from the base of the PR and between bc1d61b and 94caafd.

📒 Files selected for processing (2)
  • test/extended/util/client.go
  • test/extended/util/client_test.go

Comment on lines +28 to +74
func TestGetClientConfigRetryOnMissingFile(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "kubeconfig")

if err := os.WriteFile(path, []byte(validKubeconfig), 0644); err != nil {
t.Fatal(err)
}

go func() {
time.Sleep(200 * time.Millisecond)
os.Remove(path)
time.Sleep(800 * time.Millisecond)
os.WriteFile(path, []byte(validKubeconfig), 0644)
}()

time.Sleep(300 * time.Millisecond)

cfg, err := GetClientConfig(path)
if err != nil {
t.Fatalf("expected retry to succeed, got error: %v", err)
}
if cfg.Host != "https://localhost:6443" {
t.Fatalf("unexpected host: %s", cfg.Host)
}
}

func TestGetClientConfigRetryOnEmptyFile(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "kubeconfig")

if err := os.WriteFile(path, []byte{}, 0644); err != nil {
t.Fatal(err)
}

go func() {
time.Sleep(500 * time.Millisecond)
os.WriteFile(path, []byte(validKubeconfig), 0644)
}()

cfg, err := GetClientConfig(path)
if err != nil {
t.Fatalf("expected retry to succeed, got error: %v", err)
}
if cfg.Host != "https://localhost:6443" {
t.Fatalf("unexpected host: %s", cfg.Host)
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Make the retry tests deterministic.

The fixed sleeps and fire-and-forget goroutines can let these tests pass without actually hitting the retry window, and they can also race t.TempDir() cleanup on slower CI workers. Please synchronize the file mutation and check the background write/remove errors.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/extended/util/client_test.go` around lines 28 - 74, The retry tests
TestGetClientConfigRetryOnMissingFile and TestGetClientConfigRetryOnEmptyFile
are flakey due to fixed sleeps and fire-and-forget goroutines; change them to
synchronize the background file mutations and surface any file I/O errors so the
test deterministically exercises GetClientConfig's retry window. Specifically,
replace the anonymous goroutines with a goroutine that reports errors over a
channel (or use a sync.WaitGroup) and signal when the mutation is done, wait for
that signal before finishing the test, and check/require the returned error
values from os.Remove/os.WriteFile in those goroutines; ensure the test waits
for the background worker to start the mutation timing (e.g., signal readiness)
so the GetClientConfig call actually encounters the missing/empty file and
triggers retries.

@dgoodwin
Copy link
Copy Markdown
Contributor Author

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Apr 27, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@dgoodwin: This pull request references Jira Issue OCPBUGS-84504, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

/jira refresh

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-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e-aws-csi
/test e2e-aws-ovn-fips
/test e2e-aws-ovn-microshift
/test e2e-aws-ovn-microshift-serial
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-gcp-csi
/test e2e-gcp-ovn
/test e2e-gcp-ovn-upgrade
/test e2e-metal-ipi-ovn-ipv6
/test e2e-vsphere-ovn
/test e2e-vsphere-ovn-upi

@jcmoraisjr
Copy link
Copy Markdown
Member

PollImmediate() is deprecated, maybe PollUntilContextTimeout() is a better option. Also 50x repetitions in the worst case seems a high amount of attempts, maybe either 200ms is too low for interval or 10s is to high for timeout.

None of them seems like a blocker, looks good just the way they are.

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 27, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 27, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dgoodwin, jcmoraisjr

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

The pull request process is described 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

@dgoodwin
Copy link
Copy Markdown
Contributor Author

/verified later

@openshift-ci-robot
Copy link
Copy Markdown

@dgoodwin: /verified later <@username> requires at least one GitHub @username to be specified (it can be a comma delimited list). It indicates the engineer(s) that will be performing the verification. See https://docs.ci.openshift.org/docs/architecture/jira/#premerge-verification for more information.

Details

In response to this:

/verified later

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.

@dgoodwin
Copy link
Copy Markdown
Contributor Author

/verified later @dgoodwin

@openshift-ci-robot openshift-ci-robot added verified-later verified Signifies that the PR passed pre-merge verification criteria labels Apr 28, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@dgoodwin: This PR has been marked to be verified later by @dgoodwin.

Details

In response to this:

/verified later @dgoodwin

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.

@dgoodwin
Copy link
Copy Markdown
Contributor Author

/cherry-pick release-4.21

@openshift-cherrypick-robot
Copy link
Copy Markdown

@dgoodwin: once the present PR merges, I will cherry-pick it on top of release-4.21 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release-4.21

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-merge-bot
Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD b6f09c2 and 2 for PR HEAD 94caafd in total

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 28, 2026

@dgoodwin: all tests passed!

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-merge-bot openshift-merge-bot Bot merged commit ae654cc into openshift:main Apr 28, 2026
21 checks passed
@openshift-ci-robot
Copy link
Copy Markdown

@dgoodwin: Jira Issue OCPBUGS-84504: All pull requests linked via external trackers have merged:

This pull request has the verified-later tag and will need to be manually moved to VERIFIED after testing. Jira Issue OCPBUGS-84504 has been moved to the MODIFIED state.

Details

In response to this:

During upgrade prow jobs the kubeconfig Secret volume is re-mounted by
the kubelet, which atomically swaps symlinks and creates a sub-second
window where ReadFile() returns ENOENT or reads empty/partial content.
With 10-15 parallel Ginkgo goroutines all calling GetClientConfig() on
every client creation, this window can cause rare mass test failures.

Replace the single ReadFile attempt with a wait.PollImmediate retry
(200ms interval, 10s timeout) that retries on file-not-found, empty
file, or clientcmd parse errors. Non-transient I/O errors still fail
immediately. Adds unit tests covering all four cases.

Fixes: OCPBUGS-84504

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Summary by CodeRabbit

  • Bug Fixes

  • Improved kubeconfig file reading resilience with automatic retry logic for transient failures.

  • Tests

  • Added comprehensive test coverage for kubeconfig loading scenarios including file availability and content validation edge cases.

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-cherrypick-robot
Copy link
Copy Markdown

@dgoodwin: new pull request created: #31086

Details

In response to this:

/cherry-pick release-4.21

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.

@dgoodwin
Copy link
Copy Markdown
Contributor Author

/cherry-pick release-4.22

@openshift-cherrypick-robot
Copy link
Copy Markdown

@dgoodwin: new pull request created: #31096

Details

In response to this:

/cherry-pick release-4.22

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.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. verified Signifies that the PR passed pre-merge verification criteria verified-later

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants