NO-JIRA: Add thread-safe AddSchemes() to fix concurrent map writes#1401
NO-JIRA: Add thread-safe AddSchemes() to fix concurrent map writes#1401hongkailiu wants to merge 1 commit into
Conversation
|
@hongkailiu: This pull request explicitly references no jira issue. DetailsIn response to this:
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. |
WalkthroughThis PR centralizes registration of the proposalv1alpha1 API into a concurrency-safe helper ChangesCentralized scheme registration
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 14 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (14 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hongkailiu The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/internal/schema_test.go (1)
11-35: 💤 Low valueTest effectively validates concurrent safety.
The test correctly verifies that
AddSchemes()can be called concurrently without panics or errors, which addresses the reported "fatal error: concurrent map writes."💡 Optional enhancement to verify scheme registration
Consider adding an assertion after the concurrent calls to confirm the scheme is actually registered:
// Check if any goroutine encountered an error for err := range errChan { t.Errorf("AddSchemes failed: %v", err) } + + // Verify the scheme is actually registered + if !scheme.Scheme.Recognizes(schema.GroupVersionKind{ + Group: "lightspeed.openshift.io", + Version: "v1alpha1", + Kind: "Proposal", + }) { + t.Error("proposalv1alpha1 scheme was not registered") + }🤖 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/internal/schema_test.go` around lines 11 - 35, After the concurrent AddSchemes() calls in TestAddSchemesConcurrent, add an assertion that the expected scheme/GVK is actually registered to ensure registration happened (not just absence of errors); locate the check after wg.Wait() and close(errChan) and, using the same scheme registry used by AddSchemes (e.g., the global scheme or the registry type manipulated by AddSchemes), lookup the expected type/GroupVersionKind and fail the test with t.Fatalf/t.Errorf if the lookup returns not found or nil. Ensure this assertion uses the same identifying symbols as AddSchemes so the test verifies both concurrency safety and successful registration.
🤖 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.
Nitpick comments:
In `@pkg/internal/schema_test.go`:
- Around line 11-35: After the concurrent AddSchemes() calls in
TestAddSchemesConcurrent, add an assertion that the expected scheme/GVK is
actually registered to ensure registration happened (not just absence of
errors); locate the check after wg.Wait() and close(errChan) and, using the same
scheme registry used by AddSchemes (e.g., the global scheme or the registry type
manipulated by AddSchemes), lookup the expected type/GroupVersionKind and fail
the test with t.Fatalf/t.Errorf if the lookup returns not found or nil. Ensure
this assertion uses the same identifying symbols as AddSchemes so the test
verifies both concurrency safety and successful registration.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 59bf3fcf-20a5-4eed-b457-fee44959795f
📒 Files selected for processing (4)
pkg/internal/schema.gopkg/internal/schema_test.gopkg/proposal/controller_test.gopkg/start/start.go
Fixes "fatal error: concurrent map writes" in e2e-agnostic-operator [1, 2]. The issue occurred because multiple tests (e.g., controller_test.go and start_integration_test.go) calling addSchemes() would modified the global scheme.Scheme map without synchronization. Changes: - Created pkg/internal/schema.go with AddSchemes() using sync.Once - Moved addSchemes() from pkg/start/start.go to avoid import cycles (proposal <- cvo <- start creates cycle when proposal imports start) - Updated pkg/start/start.go to call internal.AddSchemes() - Updated pkg/proposal/controller_test.go to call internal.AddSchemes() - Added pkg/internal/schema_test.go with concurrent safety test The sync.Once pattern ensures scheme registration executes exactly once across all concurrent callers, preventing race conditions. [1]. https://prow.ci.openshift.org/view/gs/test-platform-results/pr-logs/pull/openshift_cluster-version-operator/1386/pull-ci-openshift-cluster-version-operator-main-e2e-agnostic-operator/2063953653860929536 [2]. https://prow.ci.openshift.org/view/gs/test-platform-results/pr-logs/pull/openshift_cluster-version-operator/1399/pull-ci-openshift-cluster-version-operator-main-e2e-agnostic-operator/2064194902241054720 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
/test e2e-agnostic-ovn-techpreview-serial-2of3 |
|
@hongkailiu: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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. |
Fixes "fatal error: concurrent map writes" in e2e-agnostic-operator [1, 2].
The issue occurred because multiple tests (e.g., controller_test.go and
start_integration_test.go) calling addSchemes() would
modified the global scheme.Scheme map without synchronization.
Changes:
(proposal <- cvo <- start creates cycle when proposal imports start)
The sync.Once pattern ensures scheme registration executes exactly once
across all concurrent callers, preventing race conditions.
[1]. https://prow.ci.openshift.org/view/gs/test-platform-results/pr-logs/pull/openshift_cluster-version-operator/1386/pull-ci-openshift-cluster-version-operator-main-e2e-agnostic-operator/2063953653860929536
[2]. https://prow.ci.openshift.org/view/gs/test-platform-results/pr-logs/pull/openshift_cluster-version-operator/1399/pull-ci-openshift-cluster-version-operator-main-e2e-agnostic-operator/2064194902241054720
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com
Summary by CodeRabbit
Refactor
Tests