Skip to content

Commit d81d810

Browse files
committed
Rename to fakeSyncContext
Signed-off-by: Jian Qiu <[email protected]>
1 parent 319a517 commit d81d810

File tree

105 files changed

+231
-450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+231
-450
lines changed

pkg/addon/controllers/addonconfiguration/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"testing"
66
"time"
7-
7+
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
99
"k8s.io/apimachinery/pkg/runtime"
1010
"k8s.io/client-go/tools/cache"
@@ -234,7 +234,7 @@ func TestAddonConfigurationControllerSync(t *testing.T) {
234234
}
235235

236236
// Create sync context
237-
syncCtx := testingcommon.NewFakeSDKSyncContext(t, c.queueKey)
237+
syncCtx := testingcommon.NewFakeSyncContext(t, c.queueKey)
238238

239239
// Test sync method
240240
ctx := context.TODO()

pkg/addon/controllers/addonmanagement/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ func TestAddonManagementControllerSync(t *testing.T) {
463463
}
464464

465465
// Create sync context
466-
syncCtx := testingcommon.NewFakeSDKSyncContext(t, c.queueKey)
466+
syncCtx := testingcommon.NewFakeSyncContext(t, c.queueKey)
467467

468468
// Test sync method
469469
ctx := context.TODO()

pkg/addon/controllers/addonowner/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestReconcile(t *testing.T) {
7474
}
7575
}
7676

77-
syncContext := testingcommon.NewFakeSDKSyncContext(t, c.syncKey)
77+
syncContext := testingcommon.NewFakeSyncContext(t, c.syncKey)
7878

7979
controller := NewAddonOwnerController(
8080
fakeAddonClient,

pkg/addon/controllers/addonprogressing/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ func TestReconcile(t *testing.T) {
735735
}
736736
}
737737

738-
syncContext := testingcommon.NewFakeSDKSyncContext(t, c.syncKey)
738+
syncContext := testingcommon.NewFakeSyncContext(t, c.syncKey)
739739

740740
controller := NewAddonProgressingController(
741741
fakeAddonClient,
@@ -1461,7 +1461,7 @@ func TestReconcileHostedAddons(t *testing.T) {
14611461
}
14621462
}
14631463

1464-
syncContext := testingcommon.NewFakeSDKSyncContext(t, c.syncKey)
1464+
syncContext := testingcommon.NewFakeSyncContext(t, c.syncKey)
14651465

14661466
controller := NewAddonProgressingController(
14671467
fakeAddonClient,

pkg/addon/controllers/addontemplate/controller.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"time"
66

7-
"github.com/openshift/library-go/pkg/operator/events"
87
"k8s.io/apimachinery/pkg/api/errors"
98
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
109
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -51,7 +50,6 @@ type addonTemplateController struct {
5150
dynamicInformers dynamicinformer.DynamicSharedInformerFactory
5251
workInformers workv1informers.SharedInformerFactory
5352
runControllerFunc runController
54-
eventRecorder events.Recorder
5553
}
5654

5755
type runController func(ctx context.Context, addonName string) error
@@ -66,7 +64,6 @@ func NewAddonTemplateController(
6664
clusterInformers clusterv1informers.SharedInformerFactory,
6765
dynamicInformers dynamicinformer.DynamicSharedInformerFactory,
6866
workInformers workv1informers.SharedInformerFactory,
69-
recorder events.Recorder,
7067
runController ...runController,
7168
) factory.Controller {
7269
c := &addonTemplateController{
@@ -81,7 +78,6 @@ func NewAddonTemplateController(
8178
clusterInformers: clusterInformers,
8279
dynamicInformers: dynamicInformers,
8380
workInformers: workInformers,
84-
eventRecorder: recorder,
8581
}
8682

8783
if len(runController) > 0 {
@@ -235,7 +231,6 @@ func (c *addonTemplateController) runController(ctx context.Context, addonName s
235231
c.addonClient,
236232
c.addonInformers, // use the shared informers, whose cache is synced already
237233
kubeInformers.Rbac().V1().RoleBindings().Lister(),
238-
c.eventRecorder,
239234
// image overrides from cluster annotation has lower priority than from the addonDeploymentConfig
240235
getValuesClosure,
241236
addonfactory.GetAddOnDeploymentConfigValues(

pkg/addon/controllers/addontemplate/controller_test.go

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

9-
"github.com/openshift/library-go/pkg/operator/events/eventstesting"
109
"github.com/stretchr/testify/assert"
1110
"k8s.io/apimachinery/pkg/runtime"
1211
"k8s.io/client-go/dynamic/dynamicinformer"
@@ -193,12 +192,11 @@ func TestReconcile(t *testing.T) {
193192
clusterInformers,
194193
dynamicInformerFactory,
195194
workInformers,
196-
eventstesting.NewTestingEventRecorder(t),
197195
runController,
198196
)
199197
ctx := context.TODO()
200198
for _, syncKey := range c.syncKeys {
201-
syncContext := testingcommon.NewFakeSDKSyncContext(t, syncKey)
199+
syncContext := testingcommon.NewFakeSyncContext(t, syncKey)
202200
err := controller.Sync(ctx, syncContext, syncKey)
203201
if err != nil {
204202
t.Errorf("expected no error when sync: %v", err)
@@ -383,15 +381,14 @@ func TestStopUnusedManagers(t *testing.T) {
383381
clusterInformers: clusterInformers,
384382
dynamicInformers: dynamicInformerFactory,
385383
workInformers: workInformers,
386-
eventRecorder: eventstesting.NewTestingEventRecorder(t),
387384
}
388385

389386
// Start informers and wait for cache sync
390387
ctx := context.TODO()
391388
addonInformers.Start(ctx.Done())
392389
addonInformers.WaitForCacheSync(ctx.Done())
393390

394-
syncContext := testingcommon.NewFakeSDKSyncContext(t, c.addonName)
391+
syncContext := testingcommon.NewFakeSyncContext(t, c.addonName)
395392

396393
err = controller.stopUnusedManagers(ctx, syncContext, c.addonName)
397394
assert.NoError(t, err)

pkg/addon/controllers/cmainstallprogression/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func TestReconcile(t *testing.T) {
339339
}
340340
}
341341

342-
syncContext := testingcommon.NewFakeSDKSyncContext(t, c.syncKey)
342+
syncContext := testingcommon.NewFakeSyncContext(t, c.syncKey)
343343

344344
controller := NewCMAInstallProgressionController(
345345
fakeAddonClient,

pkg/addon/manager.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ func RunControllerManagerWithInformers(
182182
// these addons only support addontemplate and addondeploymentconfig
183183
dynamicInformers,
184184
workinformers,
185-
controllerContext.EventRecorder,
186185
)
187186

188187
go addonManagementController.Run(ctx, 2)

pkg/addon/templateagent/registration.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import (
2323
"open-cluster-management.io/addon-framework/pkg/utils"
2424
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
2525
clusterv1 "open-cluster-management.io/api/cluster/v1"
26+
"open-cluster-management.io/sdk-go/pkg/basecontroller/events"
27+
28+
commonrecorder "open-cluster-management.io/ocm/pkg/common/recorder"
2629
)
2730

2831
const (
@@ -471,8 +474,14 @@ func (a *CRDTemplateAgentAddon) createPermissionBinding(clusterName, addonName,
471474
binding.OwnerReferences = []metav1.OwnerReference{*owner}
472475
}
473476

477+
// TODO(qiujian16) this should have ctx passed to build the wrapper
478+
recorderWrapper := commonrecorder.NewEventsRecorderWrapper(
479+
context.Background(),
480+
events.NewContextualLoggingEventRecorder(fmt.Sprintf("addontemplate-%s-%s", clusterName, addonName)),
481+
)
482+
474483
_, modified, err := resourceapply.ApplyRoleBinding(context.TODO(),
475-
a.hubKubeClient.RbacV1(), a.eventRecorder, binding)
484+
a.hubKubeClient.RbacV1(), recorderWrapper, binding)
476485
if err == nil && modified {
477486
a.logger.Info("Rolebinding for addon updated", "namespace", binding.Namespace, "name", binding.Name,
478487
"clusterName", clusterName, "addonName", addonName)

pkg/addon/templateagent/registration_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/openshift/library-go/pkg/operator/events/eventstesting"
1413
"github.com/stretchr/testify/assert"
1514
certificatesv1 "k8s.io/api/certificates/v1"
1615
certificates "k8s.io/api/certificates/v1beta1"
@@ -739,7 +738,7 @@ func TestTemplatePermissionConfigFunc(t *testing.T) {
739738
}
740739

741740
agent := NewCRDTemplateAgentAddon(ctx, c.addon.Name, hubKubeClient, addonClient, addonInformerFactory,
742-
kubeInformers.Rbac().V1().RoleBindings().Lister(), eventstesting.NewTestingEventRecorder(t))
741+
kubeInformers.Rbac().V1().RoleBindings().Lister())
743742
f := agent.TemplatePermissionConfigFunc()
744743
err := f(c.cluster, c.addon)
745744
if err != c.expectedErr {

0 commit comments

Comments
 (0)