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

Commit ae0bf76

Browse files
authored
Attach broker delivery ConfigMap to controller context (#1887) (#2143)
* Broker reconciler has delivery config store * Rename broker config package to brokerdelivery * Fix broker reconciler controller unit test failure * Use string builder for configmap testing
1 parent 24555be commit ae0bf76

File tree

21 files changed

+102
-49
lines changed

21 files changed

+102
-49
lines changed

cmd/controller/wire.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818
import (
1919
"context"
2020

21+
"github.com/google/knative-gcp/pkg/apis/configs/brokerdelivery"
2122
"github.com/google/knative-gcp/pkg/apis/configs/dataresidency"
2223
"github.com/google/knative-gcp/pkg/apis/configs/gcpauth"
2324
"github.com/google/knative-gcp/pkg/reconciler/broker"
@@ -43,6 +44,7 @@ func InitializeControllers(ctx context.Context) ([]injection.ControllerConstruct
4344
Controllers,
4445
ClientOptions,
4546
iam.PolicyManagerSet,
47+
wire.Struct(new(brokerdelivery.StoreSingleton)),
4648
wire.Struct(new(gcpauth.StoreSingleton)),
4749
wire.Struct(new(dataresidency.StoreSingleton)),
4850
auditlogs.NewConstructor,

cmd/controller/wire_gen.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/webhook/main.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"log"
2222

2323
brokerv1beta1 "github.com/google/knative-gcp/pkg/apis/broker/v1beta1"
24-
"github.com/google/knative-gcp/pkg/apis/configs/broker"
24+
"github.com/google/knative-gcp/pkg/apis/configs/brokerdelivery"
2525
"github.com/google/knative-gcp/pkg/apis/configs/dataresidency"
2626
"github.com/google/knative-gcp/pkg/apis/configs/gcpauth"
2727
"github.com/google/knative-gcp/pkg/apis/events"
@@ -92,16 +92,16 @@ var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
9292

9393
type defaultingAdmissionController func(context.Context, configmap.Watcher) *controller.Impl
9494

95-
func newDefaultingAdmissionConstructor(brokers *broker.StoreSingleton, gcpas *gcpauth.StoreSingleton) defaultingAdmissionController {
95+
func newDefaultingAdmissionConstructor(brokerdeliverys *brokerdelivery.StoreSingleton, gcpas *gcpauth.StoreSingleton) defaultingAdmissionController {
9696
return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
97-
return newDefaultingAdmissionController(ctx, cmw, brokers.Store(ctx, cmw), gcpas.Store(ctx, cmw))
97+
return newDefaultingAdmissionController(ctx, cmw, brokerdeliverys.Store(ctx, cmw), gcpas.Store(ctx, cmw))
9898
}
9999
}
100100

101-
func newDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher, brokers *broker.Store, gcpas *gcpauth.Store) *controller.Impl {
101+
func newDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher, brokerdeliverys *brokerdelivery.Store, gcpas *gcpauth.Store) *controller.Impl {
102102
// Decorate contexts with the current state of the config.
103103
ctxFunc := func(ctx context.Context) context.Context {
104-
return brokers.ToContext(gcpas.ToContext(ctx))
104+
return brokerdeliverys.ToContext(gcpas.ToContext(ctx))
105105
}
106106

107107
return defaulting.NewAdmissionController(ctx,
@@ -125,16 +125,16 @@ func newDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher
125125

126126
type validationController func(context.Context, configmap.Watcher) *controller.Impl
127127

128-
func newValidationConstructor(brokers *broker.StoreSingleton, gcpas *gcpauth.StoreSingleton) validationController {
128+
func newValidationConstructor(brokerdeliverys *brokerdelivery.StoreSingleton, gcpas *gcpauth.StoreSingleton) validationController {
129129
return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
130-
return newValidationAdmissionController(ctx, cmw, brokers.Store(ctx, cmw), gcpas.Store(ctx, cmw))
130+
return newValidationAdmissionController(ctx, cmw, brokerdeliverys.Store(ctx, cmw), gcpas.Store(ctx, cmw))
131131
}
132132
}
133133

134-
func newValidationAdmissionController(ctx context.Context, cmw configmap.Watcher, brokers *broker.Store, gcpas *gcpauth.Store) *controller.Impl {
134+
func newValidationAdmissionController(ctx context.Context, cmw configmap.Watcher, brokerdeliverys *brokerdelivery.Store, gcpas *gcpauth.Store) *controller.Impl {
135135
// A function that infuses the context passed to Validate/SetDefaults with custom metadata.
136136
ctxFunc := func(ctx context.Context) context.Context {
137-
return brokers.ToContext(gcpas.ToContext(ctx))
137+
return brokerdeliverys.ToContext(gcpas.ToContext(ctx))
138138
}
139139

140140
return validation.NewAdmissionController(ctx,
@@ -173,21 +173,21 @@ func NewConfigValidationController(ctx context.Context, _ configmap.Watcher) *co
173173
logging.ConfigMapName(): logging.NewConfigFromConfigMap,
174174
leaderelection.ConfigMapName(): leaderelection.NewConfigFromConfigMap,
175175
gcpauth.ConfigMapName(): gcpauth.NewDefaultsConfigFromConfigMap,
176-
broker.ConfigMapName(): broker.NewDefaultsConfigFromConfigMap,
176+
brokerdelivery.ConfigMapName(): brokerdelivery.NewDefaultsConfigFromConfigMap,
177177
dataresidency.ConfigMapName(): dataresidency.NewDefaultsConfigFromConfigMap,
178178
},
179179
)
180180
}
181181

182182
type conversionController func(context.Context, configmap.Watcher) *controller.Impl
183183

184-
func newConversionConstructor(brokers *broker.StoreSingleton, gcpas *gcpauth.StoreSingleton) conversionController {
184+
func newConversionConstructor(brokerdeliverys *brokerdelivery.StoreSingleton, gcpas *gcpauth.StoreSingleton) conversionController {
185185
return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
186-
return newConversionController(ctx, cmw, brokers.Store(ctx, cmw), gcpas.Store(ctx, cmw))
186+
return newConversionController(ctx, cmw, brokerdeliverys.Store(ctx, cmw), gcpas.Store(ctx, cmw))
187187
}
188188
}
189189

190-
func newConversionController(ctx context.Context, cmw configmap.Watcher, brokers *broker.Store, gcpas *gcpauth.Store) *controller.Impl {
190+
func newConversionController(ctx context.Context, cmw configmap.Watcher, brokerdeliverys *brokerdelivery.Store, gcpas *gcpauth.Store) *controller.Impl {
191191
var (
192192
eventsv1alpha1_ = eventsv1alpha1.SchemeGroupVersion.Version
193193
eventsv1beta1_ = eventsv1beta1.SchemeGroupVersion.Version
@@ -201,7 +201,7 @@ func newConversionController(ctx context.Context, cmw configmap.Watcher, brokers
201201

202202
// Decorate contexts with the current state of the config.
203203
ctxFunc := func(ctx context.Context) context.Context {
204-
return brokers.ToContext(gcpas.ToContext(ctx))
204+
return brokerdeliverys.ToContext(gcpas.ToContext(ctx))
205205
}
206206

207207
return conversion.NewConversionController(ctx,

cmd/webhook/wire.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package main
1818
import (
1919
"context"
2020

21-
"github.com/google/knative-gcp/pkg/apis/configs/broker"
21+
"github.com/google/knative-gcp/pkg/apis/configs/brokerdelivery"
2222
"github.com/google/knative-gcp/pkg/apis/configs/gcpauth"
2323
"github.com/google/wire"
2424
"knative.dev/pkg/injection"
@@ -27,7 +27,7 @@ import (
2727
func InitializeControllers(ctx context.Context) ([]injection.ControllerConstructor, error) {
2828
panic(wire.Build(
2929
Controllers,
30-
wire.Struct(new(broker.StoreSingleton)),
30+
wire.Struct(new(brokerdelivery.StoreSingleton)),
3131
wire.Struct(new(gcpauth.StoreSingleton)),
3232
newConversionConstructor,
3333
newDefaultingAdmissionConstructor,

cmd/webhook/wire_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/update-codegen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ${GOPATH}/bin/deepcopy-gen \
7676
-O zz_generated.deepcopy \
7777
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \
7878
-i github.com/google/knative-gcp/pkg/apis/configs/gcpauth \
79-
-i github.com/google/knative-gcp/pkg/apis/configs/broker \
79+
-i github.com/google/knative-gcp/pkg/apis/configs/brokerdelivery \
8080
-i github.com/google/knative-gcp/pkg/apis/configs/dataresidency \
8181

8282
# TODO(yolocs): generate autoscaling v2beta2 in knative/pkg.

pkg/apis/broker/v1beta1/broker_defaults.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import (
2323
"knative.dev/pkg/apis"
2424
"knative.dev/pkg/logging"
2525

26-
"github.com/google/knative-gcp/pkg/apis/configs/broker"
26+
"github.com/google/knative-gcp/pkg/apis/configs/brokerdelivery"
2727
)
2828

2929
// SetDefaults sets the default field values for a Broker.
3030
func (b *Broker) SetDefaults(ctx context.Context) {
3131
// Apply the default Broker delivery settings from the context.
3232
withNS := apis.WithinParent(ctx, b.ObjectMeta)
33-
deliverySpecDefaults := broker.FromContextOrDefaults(withNS).BrokerDeliverySpecDefaults
33+
deliverySpecDefaults := brokerdelivery.FromContextOrDefaults(withNS).BrokerDeliverySpecDefaults
3434
if deliverySpecDefaults == nil {
3535
logging.FromContext(ctx).Error("Failed to get the BrokerDeliverySpecDefaults")
3636
return

pkg/apis/broker/v1beta1/broker_defaults_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/google/go-cmp/cmp"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525

26-
"github.com/google/knative-gcp/pkg/apis/configs/broker"
26+
"github.com/google/knative-gcp/pkg/apis/configs/brokerdelivery"
2727
eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1"
2828
eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1"
2929
"knative.dev/pkg/apis"
@@ -39,11 +39,11 @@ var (
3939
nsDefaultedRetry int32 = 10
4040
customRetry int32 = 5
4141

42-
defaultConfig = &broker.Config{
43-
BrokerDeliverySpecDefaults: &broker.Defaults{
42+
defaultConfig = &brokerdelivery.Config{
43+
BrokerDeliverySpecDefaults: &brokerdelivery.Defaults{
4444
// NamespaceDefaultsConfig are the default Broker Configs for each namespace.
4545
// Namespace is the key, the value is the KReference to the config.
46-
NamespaceDefaults: map[string]broker.ScopedDefaults{
46+
NamespaceDefaults: map[string]brokerdelivery.ScopedDefaults{
4747
"mynamespace": {
4848
DeliverySpec: &eventingduckv1beta1.DeliverySpec{
4949
BackoffDelay: &nsDefaultedBackoffDelay,
@@ -80,7 +80,7 @@ var (
8080
},
8181
},
8282
},
83-
ClusterDefaults: broker.ScopedDefaults{
83+
ClusterDefaults: brokerdelivery.ScopedDefaults{
8484
DeliverySpec: &eventingduckv1beta1.DeliverySpec{
8585
BackoffDelay: &clusterDefaultedBackoffDelay,
8686
BackoffPolicy: &clusterDefaultedBackoffPolicy,
@@ -256,7 +256,7 @@ func TestBroker_SetDefaults(t *testing.T) {
256256
}
257257
for n, tc := range testCases {
258258
t.Run(n, func(t *testing.T) {
259-
tc.initial.SetDefaults(broker.ToContext(context.Background(), defaultConfig))
259+
tc.initial.SetDefaults(brokerdelivery.ToContext(context.Background(), defaultConfig))
260260
if diff := cmp.Diff(tc.expected, tc.initial); diff != "" {
261261
t.Fatalf("Unexpected defaults (-want, +got): %s", diff)
262262
}

pkg/apis/configs/broker/br_delivery_defaults.go renamed to pkg/apis/configs/brokerdelivery/br_delivery_defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package broker
17+
package brokerdelivery
1818

1919
import (
2020
"encoding/json"

pkg/apis/configs/broker/br_delivery_defaults_test.go renamed to pkg/apis/configs/brokerdelivery/br_delivery_defaults_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package broker
17+
package brokerdelivery
1818

1919
import (
2020
"testing"

0 commit comments

Comments
 (0)