Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
Use wire injection for trigger and broker controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Lin committed Sep 17, 2020
1 parent f39db1d commit 081d748
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
}
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/controller/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand All @@ -50,5 +52,7 @@ func InitializeControllers(ctx context.Context) ([]injection.ControllerConstruct
keda.NewConstructor,
topic.NewConstructor,
channel.NewConstructor,
trigger.NewConstructor,
broker.NewConstructor,
))
}
6 changes: 5 additions & 1 deletion cmd/controller/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions pkg/reconciler/broker/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand All @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions pkg/reconciler/trigger/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 081d748

Please sign in to comment.