Skip to content

OCPBUGS-81716: Add retry logic for transient network errors in restartKubeletOnNode#30966

Open
BhargaviGudi wants to merge 1 commit intoopenshift:mainfrom
BhargaviGudi:OCPBUGS-81716
Open

OCPBUGS-81716: Add retry logic for transient network errors in restartKubeletOnNode#30966
BhargaviGudi wants to merge 1 commit intoopenshift:mainfrom
BhargaviGudi:OCPBUGS-81716

Conversation

@BhargaviGudi
Copy link
Copy Markdown
Contributor

Add retry logic for transient network errors in restartKubeletOnNode
Bug: https://redhat.atlassian.net/browse/OCPBUGS-81716

Problem
TC4 CNV swap tests were failing intermittently with "connection refused" errors when running oc debug commands to restart kubelet on nodes.

Solution
Added retry mechanism to restartKubeletOnNode that:

  • Retries up to 3 times for network errors
  • Uses increasing delays between retries (5s, 10s, 15s)
  • Fails immediately for non-network errors
  • Logs each retry attempt for debugging

Network errors handled:

  • connection refused
  • connection reset
  • connection timed out
  • i/o timeout

@openshift-ci-robot
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: automatic mode

@openshift-ci-robot openshift-ci-robot added jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. 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 7, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@BhargaviGudi: This pull request references Jira Issue OCPBUGS-81716, which is invalid:

  • expected the bug to target the "4.22.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:

Add retry logic for transient network errors in restartKubeletOnNode
Bug: https://redhat.atlassian.net/browse/OCPBUGS-81716

Problem
TC4 CNV swap tests were failing intermittently with "connection refused" errors when running oc debug commands to restart kubelet on nodes.

Solution
Added retry mechanism to restartKubeletOnNode that:

  • Retries up to 3 times for network errors
  • Uses increasing delays between retries (5s, 10s, 15s)
  • Fails immediately for non-network errors
  • Logs each retry attempt for debugging

Network errors handled:

  • connection refused
  • connection reset
  • connection timed out
  • i/o timeout

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

openshift-ci bot commented Apr 7, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BhargaviGudi
Once this PR has been reviewed and has the lgtm label, please assign cpmeadors 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
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

Walkthrough

The restartKubeletOnNode function in test/extended/node/node_utils.go was modified to implement retry logic with exponential backoff for transient network errors. A new helper function isTransientNetworkError was added to classify retryable error types.

Changes

Cohort / File(s) Summary
Kubelet restart retry logic
test/extended/node/node_utils.go
Modified restartKubeletOnNode to retry up to three times on transient network errors with attempt-based backoff (attempt×5 seconds). Added isTransientNetworkError helper function to detect retryable failures via substring matching against common transient network error phrases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@BhargaviGudi
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 7, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@BhargaviGudi: This pull request references Jira Issue OCPBUGS-81716, 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 (4.22.0) matches configured target version for branch (4.22.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.

@BhargaviGudi
Copy link
Copy Markdown
Contributor Author

/payload-job periodic-ci-openshift-release-main-nightly-4.22-e2e-aws-disruptive-longrunning

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 7, 2026

@BhargaviGudi: trigger 1 job(s) for the /payload-(with-prs|job|aggregate|job-with-prs|aggregate-with-prs) command

  • periodic-ci-openshift-release-main-nightly-4.22-e2e-aws-disruptive-longrunning

See details on https://pr-payload-tests.ci.openshift.org/runs/ci/343f3690-324b-11f1-94ea-e53d6b882dcb-0

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

🤖 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/node/node_utils.go`:
- Around line 200-215: The retry loop in restartKubeletOnNode is blocking and
sleeps even after the final attempt and isn't cancelable; change the signature
to accept a context.Context (restartKubeletOnNode(ctx context.Context, oc
*exutil.CLI, nodeName string)), remove the unconditional time.Sleep on the final
attempt by only sleeping when attempt < maxAttempts, and replace time.Sleep with
a context-aware wait (select between time.After(backoff) and ctx.Done()) so the
retry/backoff can be canceled; keep using ExecOnNodeWithChroot and
isTransientNetworkError to detect retryable errors and propagate the lastErr
when context is done or retries exhausted.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ed04415d-f102-4abf-86dc-8f0f443aeda3

📥 Commits

Reviewing files that changed from the base of the PR and between c77ff4a and c3c8d51.

📒 Files selected for processing (1)
  • test/extended/node/node_utils.go

Comment on lines 200 to +215
func restartKubeletOnNode(oc *exutil.CLI, nodeName string) error {
_, err := ExecOnNodeWithChroot(oc, nodeName, "systemctl", "restart", "kubelet")
return err
var lastErr error
for attempt := 1; attempt <= 3; attempt++ {
_, err := ExecOnNodeWithChroot(oc, nodeName, "systemctl", "restart", "kubelet")
if err == nil {
return nil
}
lastErr = err
if isTransientNetworkError(err) {
framework.Logf("Attempt %d/3 to restart kubelet on %s failed: %v, retrying...", attempt, nodeName, err)
time.Sleep(time.Duration(attempt*5) * time.Second)
continue
}
return err
}
return fmt.Errorf("failed to restart kubelet on %s after 3 attempts: %w", nodeName, lastErr)
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 | 🟠 Major

Retry loop adds a no-op 15s delay on final failure and cannot be canceled.

Line [210] sleeps even on the last attempt (Line [202]), so failure path pays an extra 15s with no next retry. Also, the backoff is not context-aware, which can overrun cleanup windows (see test/extended/node/node_swap_cnv.go:242-262 where restart runs in defer with test ctx).

Proposed fix
-func restartKubeletOnNode(oc *exutil.CLI, nodeName string) error {
+func restartKubeletOnNode(ctx context.Context, oc *exutil.CLI, nodeName string) error {
+	const maxRetries = 3
 	var lastErr error
-	for attempt := 1; attempt <= 3; attempt++ {
+	for attempt := 0; attempt <= maxRetries; attempt++ {
 		_, err := ExecOnNodeWithChroot(oc, nodeName, "systemctl", "restart", "kubelet")
 		if err == nil {
 			return nil
 		}
 		lastErr = err
-		if isTransientNetworkError(err) {
-			framework.Logf("Attempt %d/3 to restart kubelet on %s failed: %v, retrying...", attempt, nodeName, err)
-			time.Sleep(time.Duration(attempt*5) * time.Second)
-			continue
+		if !isTransientNetworkError(err) {
+			return fmt.Errorf("failed to restart kubelet on %s: %w", nodeName, err)
 		}
-		return err
+		if attempt == maxRetries {
+			break
+		}
+		backoff := time.Duration((attempt+1)*5) * time.Second
+		framework.Logf("Attempt %d/%d to restart kubelet on %s failed: %v; retrying in %s",
+			attempt+1, maxRetries+1, nodeName, err, backoff)
+		timer := time.NewTimer(backoff)
+		select {
+		case <-ctx.Done():
+			timer.Stop()
+			return fmt.Errorf("context canceled while restarting kubelet on %s: %w", nodeName, ctx.Err())
+		case <-timer.C:
+		}
 	}
-	return fmt.Errorf("failed to restart kubelet on %s after 3 attempts: %w", nodeName, lastErr)
+	return fmt.Errorf("failed to restart kubelet on %s after %d attempts: %w", nodeName, maxRetries+1, lastErr)
 }
// call sites (examples):
err = restartKubeletOnNode(ctx, oc, cnvWorkerNode)
restartKubeletOnNode(ctx, oc, nodeName)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/extended/node/node_utils.go` around lines 200 - 215, The retry loop in
restartKubeletOnNode is blocking and sleeps even after the final attempt and
isn't cancelable; change the signature to accept a context.Context
(restartKubeletOnNode(ctx context.Context, oc *exutil.CLI, nodeName string)),
remove the unconditional time.Sleep on the final attempt by only sleeping when
attempt < maxAttempts, and replace time.Sleep with a context-aware wait (select
between time.After(backoff) and ctx.Done()) so the retry/backoff can be
canceled; keep using ExecOnNodeWithChroot and isTransientNetworkError to detect
retryable errors and propagate the lastErr when context is done or retries
exhausted.

@openshift-ci-robot
Copy link
Copy Markdown

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

@BhargaviGudi
Copy link
Copy Markdown
Contributor Author

All test cases in the openshift/disruptive-longrunning suite are passing successfully.
CI job link: https://prow.ci.openshift.org/view/gs/test-platform-results/logs/openshift-origin-30966-nightly-4.22-e2e-aws-disruptive-longrunning/2041403110437425152

@BhargaviGudi
Copy link
Copy Markdown
Contributor Author

/verified by CI

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

@BhargaviGudi: This PR has been marked as verified by CI.

Details

In response to this:

/verified by CI

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.

@sosiouxme
Copy link
Copy Markdown
Member

/override ci/prow/e2e-aws-ovn-fips
/override ci/prow/e2e-aws-ovn-serial-1of2
/override ci/prow/e2e-gcp-ovn
/hold
feel free to release if you need.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 7, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 7, 2026

@sosiouxme: Overrode contexts on behalf of sosiouxme: ci/prow/e2e-aws-ovn-fips, ci/prow/e2e-aws-ovn-serial-1of2, ci/prow/e2e-gcp-ovn

Details

In response to this:

/override ci/prow/e2e-aws-ovn-fips
/override ci/prow/e2e-aws-ovn-serial-1of2
/override ci/prow/e2e-gcp-ovn
/hold
feel free to release if you need.

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

openshift-ci bot commented Apr 7, 2026

@BhargaviGudi: 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.

@BhargaviGudi
Copy link
Copy Markdown
Contributor Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 8, 2026
@BhargaviGudi
Copy link
Copy Markdown
Contributor Author

@cpmeadors and @ngopalak-redhat Could you please help to review this PR? Thanks

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

Labels

jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. 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. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants