Skip to content

NO-JIRA: Refactor connection checker to fix redundant looping - #3099

Open
tpantelis wants to merge 1 commit into
openshift:masterfrom
tpantelis:conn_checker_run
Open

NO-JIRA: Refactor connection checker to fix redundant looping#3099
tpantelis wants to merge 1 commit into
openshift:masterfrom
tpantelis:conn_checker_run

Conversation

@tpantelis

Copy link
Copy Markdown
Contributor

The previous implementation had two layers of periodic execution - Run() used wait.UntilWithContext() to call checkConnection() periodically, but checkConnection() also had its own ticker and infinite loop. The code was simplified to have checkConnection() execute once per call, relying on wait.UntilWithContext() for periodic execution.

Also, the previous Run() method launched wait.UntilWithContext() in a goroutine and then blocked on <-ctx2.Done(). This is redundant because wait.UntilWithContext() already blocks until the context is cancelled. The new implementation calls wait.UntilWithContext() directly, which properly blocks the Run() method until the context is cancelled or Stop() is called.

Unit tests were added to cover the Run() functionality. To facilitate this, the check period was made configurable by introducing a ConnectionCheckerConfig struct to replace the long parameter list in NewConnectionChecker().

@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: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 3, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@tpantelis: This pull request explicitly references no jira issue.

Details

In response to this:

The previous implementation had two layers of periodic execution - Run() used wait.UntilWithContext() to call checkConnection() periodically, but checkConnection() also had its own ticker and infinite loop. The code was simplified to have checkConnection() execute once per call, relying on wait.UntilWithContext() for periodic execution.

Also, the previous Run() method launched wait.UntilWithContext() in a goroutine and then blocked on <-ctx2.Done(). This is redundant because wait.UntilWithContext() already blocks until the context is cancelled. The new implementation calls wait.UntilWithContext() directly, which properly blocks the Run() method until the context is cancelled or Stop() is called.

Unit tests were added to cover the Run() functionality. To facilitate this, the check period was made configurable by introducing a ConnectionCheckerConfig struct to replace the long parameter list in NewConnectionChecker().

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 commented Aug 3, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Connection checks now support configurable check intervals and timeouts, with sensible defaults when values aren’t provided.
    • Checkers can shut down cleanly when their operating context is cancelled.
  • Bug Fixes

    • Improved connection-check execution consistency by running checks synchronously at each configured interval.
  • Tests

    • Added coverage for connection-check execution, shutdown, cancellation, and connection status updates.

Walkthrough

The connection checker now accepts configuration, applies configurable timing, performs synchronous checks, and stops through context cancellation. Controller wiring uses the new configuration. Tests cover repeated checks and shutdown paths.

Changes

Connection checker lifecycle

Layer / File(s) Summary
Configure and run connection checks
pkg/cmd/checkendpoints/controller/connection_checker.go
ConnectionCheckerConfig defines checker dependencies and timing. The checker applies default timing when values are unset, performs one check per interval, and exits through a cancellable context.
Wire and validate checker lifecycle
pkg/cmd/checkendpoints/controller/pod_network_connectivity_check_controller.go, pkg/cmd/checkendpoints/controller/connection_checker_test.go
Sync constructs the checker with ConnectionCheckerConfig. Tests verify repeated checks and shutdown through Stop or context cancellation.

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

Suggested reviewers: jcaamano, kyrtapz

Sequence Diagram(s)

sequenceDiagram
  participant PodNetworkConnectivityCheckController
  participant ConnectionChecker
  participant EndpointCheck
  PodNetworkConnectivityCheckController->>ConnectionChecker: construct with ConnectionCheckerConfig
  ConnectionChecker->>ConnectionChecker: apply check period and timeout
  ConnectionChecker->>EndpointCheck: execute one check per interval
  EndpointCheck-->>ConnectionChecker: return check result
  PodNetworkConnectivityCheckController->>ConnectionChecker: stop or cancel context
  ConnectionChecker-->>PodNetworkConnectivityCheckController: exit Run
Loading

Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (4 errors)

Check name Status Explanation Resolution
Pr Quality ❌ Error The description explains the motivation and approach, but omits CI jobs/platforms, user impact, upgrade/rollback notes, and an issue link for the stated fix. Add Why, What, and Testing sections with automated CNO CI lanes and platforms; document impact and upgrade/rollback considerations; add a bug or issue link.
Commit Message Quality ❌ Error The PR has one logical non-merge commit with a useful body, but its subject is unscoped: “Refactor connection checker to fix redundant looping” lacks an affected-component prefix. Prefix the subject with the component, for example: “check-endpoints: Refactor connection checker to fix redundant looping”.
E2e Tests For Feature Changes ❌ Error The PR changes runtime scheduling in connection_checker.go and describes a bug fix, but no test/e2e/ files changed and the description has no required Testing or How to verify it section. Add appropriate test/e2e/ changes and a Testing/How to verify it section with CI jobs, platform coverage, and results; if E2E is infeasible, document why and follow the stated override process.
Ai-Generated Code Smell ❌ Error The added test contains obvious comment slop: “// Call Stop” only precedes checker.Stop(), and “// Cancel the context” only precedes cancel(). Remove comments that merely restate the immediately following statement; retain comments only when they explain test intent or non-obvious behavior.
✅ Passed checks (20 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the imperative mood, stays under 72 characters, and accurately describes the connection checker refactor.
Description check ✅ Passed The description clearly explains the redundant loop removal, configurable checker period, and added unit tests.
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.
Unit Tests For Go Changes ✅ Passed The PR modifies two production Go files under pkg/ and also modifies pkg/cmd/checkendpoints/controller/connection_checker_test.go.
Rbac Least Privilege ✅ Passed The pull request changes only three Go files; no YAML files under bindata/ or manifests/ changed, so no RBAC rules were added or modified.
Docs For Feature And Behavior Changes ✅ Passed The commit changes only internal Go controller code and tests. It adds no user-facing configuration, API, manifest, or CNO architecture change, so docs updates are not required.
Stale Project Docs And Config ✅ Passed No scoped docs or .coderabbit.yaml references the changed API or loop. Network diagnostics still runs regularly, and no architecture boundary changed.
Go And Test Code Quality ✅ Passed Changed hunks contain no prohibited logging, test Sleep/Setenv or bare fatal calls, bare durations, shadowed errors, IPv4-only logic, or unprotected shared map/slice access.
Stable And Deterministic Test Names ✅ Passed The added test uses static t.Run titles, and the affected package contains no Ginkgo title calls or dynamic test-name construction.
Test Structure And Quality ✅ Passed The PR adds standard Go testing.T subtests, not Ginkgo It blocks; no cluster resources are created, and all Eventually calls have Within timeouts.
Microshift Test Compatibility ✅ Passed The PR adds standard Go unit tests (TestConnectionCheckerRun), not Ginkgo e2e tests, and contains no MicroShift-incompatible API or namespace usage.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The PR adds a standard Go unit test using testing.T and Gomega; it adds no Ginkgo e2e test or multi-node/HA assumption, so SNO compatibility checks do not apply.
Topology-Aware Scheduling Compatibility ✅ Passed The patch changes only connection-check timing, status updates, tests, and checker construction; it adds no deployment, pod scheduling, affinity, selector, toleration, replica, or PDB constraints.
Ote Binary Stdout Contract ✅ Passed The patch adds no main/init/TestMain or suite setup and no stdout writes; its only added klog call is inside connectionChecker.Run, outside the check's process-level scope.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The PR adds a standard Go Test, not a Ginkgo e2e test; it uses a mock client, returns nil checks, and adds no IPv4 literals or external connectivity.
No-Weak-Crypto ✅ Passed The 143 added code lines contain no MD5, SHA1, DES, 3DES, RC4, Blowfish, ECB, custom crypto, or secret-comparison patterns; existing TLS usage was unchanged.
Container-Privileges ✅ Passed The PR changes only three Go files; no added manifest files or privilege settings such as privileged, hostPID, hostNetwork, SYS_ADMIN, or allowPrivilegeEscalation were found.
No-Sensitive-Data-In-Logs ✅ Passed The diff adds no sensitive logging. Existing endpoint and TLS error logs remain unchanged; only the stop message moves from the worker loop to Run.
✨ 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.

@openshift-ci
openshift-ci Bot requested review from jcaamano and kyrtapz August 3, 2026 18:20
@openshift-ci

openshift-ci Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

🤖 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/cmd/checkendpoints/controller/connection_checker.go`:
- Around line 105-116: Update the internal goroutine in connectionChecker.Run to
select on both c.stop and ctx2.Done(). Ensure it exits when either Stop() is
called or the parent context is cancelled, while preserving the existing
cancel() behavior.
🪄 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: Pro Plus

Run ID: 5491a332-19f7-434f-b151-d9ec567355fb

📥 Commits

Reviewing files that changed from the base of the PR and between 1dcce83 and 70f509e.

📒 Files selected for processing (3)
  • pkg/cmd/checkendpoints/controller/connection_checker.go
  • pkg/cmd/checkendpoints/controller/connection_checker_test.go
  • pkg/cmd/checkendpoints/controller/pod_network_connectivity_check_controller.go

Comment thread pkg/cmd/checkendpoints/controller/connection_checker.go
The previous implementation had two layers of periodic execution -
Run() used wait.UntilWithContext() to call checkConnection()
periodically, but checkConnection() also had its own ticker and
infinite loop. The code was simplified to have checkConnection()
execute once per call, relying on wait.UntilWithContext() for periodic
execution.

Also, the previous Run() method launched wait.UntilWithContext() in a
goroutine and then blocked on <-ctx2.Done(). This is redundant
because wait.UntilWithContext() already blocks until the context is
cancelled. The new implementation calls wait.UntilWithContext()
directly, which properly blocks the Run() method until the context is
cancelled or Stop() is called.

Unit tests were added to cover the Run() functionality. To facilitate
this, the check period was made configurable by introducing a
ConnectionCheckerConfig struct to replace the long parameter list in
NewConnectionChecker().

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
@openshift-ci

openshift-ci Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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

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

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants