Skip to content

Commit b044fdc

Browse files
Merge pull request #2103 from njhale/fix/race
fix(openshift): prevent race condition in the clusteroperator controller
2 parents 15790a8 + 0d2a374 commit b044fdc

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

pkg/controller/operators/openshift/clusteroperator_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewClusterOperatorReconciler(opts ...ReconcilerOption) (*ClusterOperatorRec
5050
ReconcilerConfig: config,
5151
delayRequeue: reconcile.Result{RequeueAfter: config.RequeueDelay},
5252
co: co,
53-
syncTracker: NewSyncTracker(config.SyncCh, co),
53+
syncTracker: NewSyncTracker(config.SyncCh, co.DeepCopy()),
5454
}
5555

5656
var mutations SerialMutations

pkg/controller/operators/openshift/synctracker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"fmt"
66
"sync"
77

8+
configv1 "github.com/openshift/api/config/v1"
89
"sigs.k8s.io/controller-runtime/pkg/event"
910
)
1011

11-
func NewSyncTracker(syncCh <-chan error, co *ClusterOperator) *SyncTracker {
12+
func NewSyncTracker(syncCh <-chan error, co *configv1.ClusterOperator) *SyncTracker {
1213
return &SyncTracker{
1314
syncCh: syncCh,
1415
events: make(chan event.GenericEvent),
@@ -22,7 +23,7 @@ type SyncTracker struct {
2223
mutex sync.RWMutex
2324
once sync.Once
2425

25-
co *ClusterOperator
26+
co *configv1.ClusterOperator
2627
totalSyncs, successfulSyncs int
2728
}
2829

pkg/controller/operators/openshift/synctracker_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77
"testing/quick"
88

9+
configv1 "github.com/openshift/api/config/v1"
910
"github.com/stretchr/testify/require"
1011
"sigs.k8s.io/controller-runtime/pkg/event"
1112
)
@@ -22,7 +23,7 @@ func TestInvalidFields(t *testing.T) {
2223
// Add missing fields, then try again
2324
tracker.syncCh = make(chan error)
2425
tracker.events = make(chan event.GenericEvent)
25-
tracker.co = &ClusterOperator{}
26+
tracker.co = &configv1.ClusterOperator{}
2627
require.NoError(t, tracker.Start(cancelled))
2728
}
2829

@@ -31,7 +32,7 @@ func TestSyncCount(t *testing.T) {
3132
syncCh := make(chan error)
3233
defer close(syncCh)
3334

34-
co := NewClusterOperator("operator")
35+
co := NewClusterOperator("operator").DeepCopy()
3536
tracker := NewSyncTracker(syncCh, co)
3637

3738
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)