From 081d748441441a9b861bb3a98f99c389ab757281 Mon Sep 17 00:00:00 2001 From: Jimmy Lin Date: Thu, 17 Sep 2020 13:53:18 -0400 Subject: [PATCH] Use wire injection for trigger and broker controller --- cmd/controller/main.go | 6 ++++-- cmd/controller/wire.go | 4 ++++ cmd/controller/wire_gen.go | 6 +++++- pkg/reconciler/broker/controller.go | 16 ++++++++++++---- pkg/reconciler/trigger/controller.go | 15 ++++++++++++--- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/cmd/controller/main.go b/cmd/controller/main.go index b6a8ba0d27..f24507fbad 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -63,6 +63,8 @@ func Controllers( kedaPullsubscriptionController kedapullsubscription.Constructor, topicController topic.Constructor, channelController channel.Constructor, + triggerController trigger.Constructor, + brokerController broker.Constructor, ) []injection.ControllerConstructor { return []injection.ControllerConstructor{ injection.ControllerConstructor(auditlogsController), @@ -74,9 +76,9 @@ func Controllers( injection.ControllerConstructor(kedaPullsubscriptionController), injection.ControllerConstructor(topicController), injection.ControllerConstructor(channelController), + injection.ControllerConstructor(triggerController), + injection.ControllerConstructor(brokerController), deployment.NewController, - broker.NewController, - trigger.NewController, brokercell.NewController, } } diff --git a/cmd/controller/wire.go b/cmd/controller/wire.go index 10879a54ab..daa2cfad4a 100644 --- a/cmd/controller/wire.go +++ b/cmd/controller/wire.go @@ -20,6 +20,7 @@ import ( "github.com/google/knative-gcp/pkg/apis/configs/dataresidency" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" + "github.com/google/knative-gcp/pkg/reconciler/broker" "github.com/google/knative-gcp/pkg/reconciler/events/auditlogs" "github.com/google/knative-gcp/pkg/reconciler/events/build" "github.com/google/knative-gcp/pkg/reconciler/events/pubsub" @@ -30,6 +31,7 @@ import ( "github.com/google/knative-gcp/pkg/reconciler/intevents/pullsubscription/static" "github.com/google/knative-gcp/pkg/reconciler/intevents/topic" "github.com/google/knative-gcp/pkg/reconciler/messaging/channel" + "github.com/google/knative-gcp/pkg/reconciler/trigger" "github.com/google/wire" "knative.dev/pkg/injection" ) @@ -50,5 +52,7 @@ func InitializeControllers(ctx context.Context) ([]injection.ControllerConstruct keda.NewConstructor, topic.NewConstructor, channel.NewConstructor, + trigger.NewConstructor, + broker.NewConstructor, )) } diff --git a/cmd/controller/wire_gen.go b/cmd/controller/wire_gen.go index 4b4bcad37b..d7aeeccb80 100644 --- a/cmd/controller/wire_gen.go +++ b/cmd/controller/wire_gen.go @@ -10,6 +10,7 @@ import ( "context" "github.com/google/knative-gcp/pkg/apis/configs/dataresidency" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" + "github.com/google/knative-gcp/pkg/reconciler/broker" "github.com/google/knative-gcp/pkg/reconciler/events/auditlogs" "github.com/google/knative-gcp/pkg/reconciler/events/build" "github.com/google/knative-gcp/pkg/reconciler/events/pubsub" @@ -20,6 +21,7 @@ import ( "github.com/google/knative-gcp/pkg/reconciler/intevents/pullsubscription/static" "github.com/google/knative-gcp/pkg/reconciler/intevents/topic" "github.com/google/knative-gcp/pkg/reconciler/messaging/channel" + "github.com/google/knative-gcp/pkg/reconciler/trigger" "knative.dev/pkg/injection" ) @@ -50,6 +52,8 @@ func InitializeControllers(ctx context.Context) ([]injection.ControllerConstruct dataresidencyStoreSingleton := &dataresidency.StoreSingleton{} topicConstructor := topic.NewConstructor(iamPolicyManager, storeSingleton, dataresidencyStoreSingleton) channelConstructor := channel.NewConstructor(iamPolicyManager, storeSingleton) - v2 := Controllers(constructor, storageConstructor, schedulerConstructor, pubsubConstructor, buildConstructor, staticConstructor, kedaConstructor, topicConstructor, channelConstructor) + triggerConstructor := trigger.NewConstructor(dataresidencyStoreSingleton) + brokerConstructor := broker.NewConstructor(dataresidencyStoreSingleton) + v2 := Controllers(constructor, storageConstructor, schedulerConstructor, pubsubConstructor, buildConstructor, staticConstructor, kedaConstructor, topicConstructor, channelConstructor, triggerConstructor, brokerConstructor) return v2, nil } diff --git a/pkg/reconciler/broker/controller.go b/pkg/reconciler/broker/controller.go index 7ba6705583..f9faa12181 100644 --- a/pkg/reconciler/broker/controller.go +++ b/pkg/reconciler/broker/controller.go @@ -31,6 +31,7 @@ import ( "knative.dev/eventing/pkg/logging" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" + "knative.dev/pkg/injection" pkgreconciler "knative.dev/pkg/reconciler" brokerv1beta1 "github.com/google/knative-gcp/pkg/apis/broker/v1beta1" @@ -49,7 +50,16 @@ const ( controllerAgentName = "broker-controller" ) -func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { +type Constructor injection.ControllerConstructor + +// NewConstructor creates a constructor to make a Topic controller. +func NewConstructor(dataresidencyss *dataresidency.StoreSingleton) Constructor { + return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl { + return newController(ctx, cmw, dataresidencyss.Store(ctx, cmw)) + } +} + +func newController(ctx context.Context, cmw configmap.Watcher, dataresidencyss *dataresidency.Store) *controller.Impl { brokerInformer := brokerinformer.Get(ctx) bcInformer := brokercellinformer.Get(ctx) @@ -74,13 +84,11 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl }() } - dataresidencySingleton := &dataresidency.StoreSingleton{} - r := &Reconciler{ Base: reconciler.NewBase(ctx, controllerAgentName, cmw), brokerCellLister: bcInformer.Lister(), pubsubClient: client, - dataresidencyStore: dataresidencySingleton.Store(ctx, cmw), + dataresidencyStore: dataresidencyss, } impl := brokerreconciler.NewImpl(ctx, r, brokerv1beta1.BrokerClass) diff --git a/pkg/reconciler/trigger/controller.go b/pkg/reconciler/trigger/controller.go index c651bf1a61..eb4e5fb4a1 100644 --- a/pkg/reconciler/trigger/controller.go +++ b/pkg/reconciler/trigger/controller.go @@ -34,6 +34,7 @@ import ( "knative.dev/pkg/configmap" "knative.dev/pkg/controller" pkgcontroller "knative.dev/pkg/controller" + "knative.dev/pkg/injection" pkgreconciler "knative.dev/pkg/reconciler" "knative.dev/pkg/resolver" @@ -62,7 +63,16 @@ type envConfig struct { ProjectID string `envconfig:"PROJECT_ID"` } -func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { +type Constructor injection.ControllerConstructor + +// NewConstructor creates a constructor to make a Topic controller. +func NewConstructor(dataresidencyss *dataresidency.StoreSingleton) Constructor { + return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl { + return newController(ctx, cmw, dataresidencyss.Store(ctx, cmw)) + } +} + +func newController(ctx context.Context, cmw configmap.Watcher, dataresidencyss *dataresidency.Store) *controller.Impl { var env envConfig if err := envconfig.Process("", &env); err != nil { logging.FromContext(ctx).Fatal("Failed to process env var", zap.Error(err)) @@ -91,13 +101,12 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl client.Close() }() } - dataresidencySingleton := &dataresidency.StoreSingleton{} r := &Reconciler{ Base: reconciler.NewBase(ctx, controllerAgentName, cmw), brokerLister: brokerinformer.Get(ctx).Lister(), pubsubClient: client, projectID: projectID, - dataresidencyStore: dataresidencySingleton.Store(ctx, cmw), + dataresidencyStore: dataresidencyss, } impl := triggerreconciler.NewImpl(ctx, r, withAgentAndFinalizer)