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

Commit

Permalink
Use wiregen for brokercell and deployment controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Lin committed Sep 17, 2020
1 parent 081d748 commit afff56b
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 9 deletions.
6 changes: 4 additions & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func Controllers(
channelController channel.Constructor,
triggerController trigger.Constructor,
brokerController broker.Constructor,
deploymentController deployment.Constructor,
brokercellController brokercell.Constructor,
) []injection.ControllerConstructor {
return []injection.ControllerConstructor{
injection.ControllerConstructor(auditlogsController),
Expand All @@ -78,8 +80,8 @@ func Controllers(
injection.ControllerConstructor(channelController),
injection.ControllerConstructor(triggerController),
injection.ControllerConstructor(brokerController),
deployment.NewController,
brokercell.NewController,
injection.ControllerConstructor(deploymentController),
injection.ControllerConstructor(brokercellController),
}
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/controller/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ 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/brokercell"
"github.com/google/knative-gcp/pkg/reconciler/deployment"
"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 Down Expand Up @@ -54,5 +56,7 @@ func InitializeControllers(ctx context.Context) ([]injection.ControllerConstruct
channel.NewConstructor,
trigger.NewConstructor,
broker.NewConstructor,
deployment.NewConstructor,
brokercell.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.

2 changes: 1 addition & 1 deletion pkg/reconciler/broker/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (

type Constructor injection.ControllerConstructor

// NewConstructor creates a constructor to make a Topic controller.
// NewConstructor creates a constructor to make a Broker 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))
Expand Down
5 changes: 3 additions & 2 deletions pkg/reconciler/broker/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/google/knative-gcp/pkg/apis/configs/dataresidency"
reconcilertesting "github.com/google/knative-gcp/pkg/reconciler/testing"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -38,7 +39,7 @@ import (
func TestNew(t *testing.T) {
ctx, _ := SetupFakeContext(t)

c := NewController(ctx, configmap.NewStaticWatcher(
c := newController(ctx, configmap.NewStaticWatcher(
&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: logging.ConfigMapName(),
Expand Down Expand Up @@ -67,7 +68,7 @@ func TestNew(t *testing.T) {
},
Data: map[string]string{},
},
))
), reconcilertesting.NewDataresidencyTestStore(t, nil))

if c == nil {
t.Fatal("Expected NewController to return a non-nil value")
Expand Down
10 changes: 10 additions & 0 deletions pkg/reconciler/brokercell/controller.go

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

10 changes: 10 additions & 0 deletions pkg/reconciler/deployment/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"knative.dev/pkg/client/injection/kube/informers/core/v1/secret"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/injection"

"github.com/google/knative-gcp/pkg/apis/duck"
"github.com/google/knative-gcp/pkg/reconciler"
Expand All @@ -45,6 +46,15 @@ const (
envKey = "GOOGLE_APPLICATION_CREDENTIALS"
)

type Constructor injection.ControllerConstructor

// NewConstructor creates a constructor to make a Deployment controller.
func NewConstructor() Constructor {
return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return NewController(ctx, cmw)
}
}

// NewController initializes the controller and is called by the generated code
// Registers event handlers to enqueue events.
// When the secret `google-cloud-key` of namespace `cloud-run-events` gets updated, we will enqueue the deployment `controller` of namespace `cloud-run-events`.
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/trigger/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type envConfig struct {

type Constructor injection.ControllerConstructor

// NewConstructor creates a constructor to make a Topic controller.
// NewConstructor creates a constructor to make a Trigger 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))
Expand Down
5 changes: 3 additions & 2 deletions pkg/reconciler/trigger/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/google/knative-gcp/pkg/apis/configs/dataresidency"
_ "github.com/google/knative-gcp/pkg/client/injection/informers/broker/v1beta1/broker/fake"
_ "github.com/google/knative-gcp/pkg/client/injection/informers/broker/v1beta1/trigger/fake"
reconcilertesting "github.com/google/knative-gcp/pkg/reconciler/testing"
_ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake"
_ "knative.dev/pkg/client/injection/ducks/duck/v1/conditions/fake"
_ "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment/fake"
Expand All @@ -44,7 +45,7 @@ import (
func TestNew(t *testing.T) {
ctx, _ := SetupFakeContext(t)

c := NewController(ctx, configmap.NewStaticWatcher(
c := newController(ctx, configmap.NewStaticWatcher(
&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: logging.ConfigMapName(),
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestNew(t *testing.T) {
},
Data: map[string]string{},
},
))
), reconcilertesting.NewDataresidencyTestStore(t, nil))

if c == nil {
t.Fatal("Expected NewController to return a non-nil value")
Expand Down

0 comments on commit afff56b

Please sign in to comment.