Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not allow brokers to be created with channeltemplatespec #3083

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pkg/apis/eventing/v1alpha1/broker_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ func (b *Broker) Validate(ctx context.Context) *apis.FieldError {
func (bs *BrokerSpec) Validate(ctx context.Context) *apis.FieldError {
var errs *apis.FieldError

// Validate the new channelTemplate.
// TODO: As part of https://github.com/knative/eventing/issues/2128
// Also make sure this gets rejected. It would break our tests
// and assumptions to do this right now.
// if bs.ChannelTemplate == nil {
// errs = errs.Also(apis.ErrMissingField("channelTemplateSpec"))
// } else
if bs.ChannelTemplate != nil {
if cte := messagingv1beta1.IsValidChannelTemplate(bs.ChannelTemplate); cte != nil {
errs = errs.Also(cte.ViaField("channelTemplateSpec"))
// As of v0.15 do not allow creation of new Brokers with the channel template.
if apis.IsInCreate(ctx) {
if bs.ChannelTemplate != nil {
errs = errs.Also(apis.ErrDisallowedFields("channelTemplate"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log something? that the field is no loger allowed? not sure how known this really is?

}
} else {
if bs.ChannelTemplate != nil {
if cte := messagingv1beta1.IsValidChannelTemplate(bs.ChannelTemplate); cte != nil {
errs = errs.Also(cte.ViaField("channelTemplateSpec"))
}
}
}

Expand Down
37 changes: 37 additions & 0 deletions pkg/apis/eventing/v1alpha1/broker_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,43 @@ func TestBrokerImmutableFields(t *testing.T) {
}
}

func TestBrokerValidationFailsWithCreateChannelTemplate(t *testing.T) {
b := &Broker{
Spec: BrokerSpec{
ChannelTemplate: &messagingv1beta1.ChannelTemplateSpec{
TypeMeta: metav1.TypeMeta{APIVersion: "myapiversion", Kind: "mykind"},
},
},
}
tests := map[string]struct {
ctx context.Context
wantErr *apis.FieldError
}{
"create fails": {
ctx: apis.WithinCreate(context.Background()),
wantErr: apis.ErrDisallowedFields("channelTemplate").ViaField("spec"),
},
"delete works": {
ctx: apis.WithinDelete(context.Background()),
wantErr: nil,
},
"update works": {
ctx: apis.WithinUpdate(context.Background(), b),
wantErr: nil,
},
"no context, works": {
ctx: context.Background(),
wantErr: nil,
},
}
for name, tc := range tests {
gotErr := b.Validate(tc.ctx)
if diff := cmp.Diff(tc.wantErr.Error(), gotErr.Error()); diff != "" {
t.Errorf("%s Broker.Validate (-want, +got) = %v", name, diff)
}
}
}

func TestBrokerValidation(t *testing.T) {
/* This test should fail: TODO: https://github.com/knative/eventing/issues/2128
name: "invalid empty, missing channeltemplatespec",
Expand Down
9 changes: 6 additions & 3 deletions test/conformance/helpers/broker_tracing_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@ func setupBrokerTracing(brokerClass string) SetupInfrastructureFunc {
client.CreateConfigMapPropagationOrFail(defaultCMPName)
client.CreateRBACResourcesForBrokers()
}
broker := client.CreateBrokerOrFail(
// Create a configmap used by the broker.
client.CreateBrokerConfigMapOrFail("br", channel)

broker := client.CreateBrokerV1Beta1OrFail(
"br",
resources.WithBrokerClassForBroker(brokerClass),
resources.WithChannelTemplateForBroker(channel),
resources.WithBrokerClassForBrokerV1Beta1(brokerClass),
resources.WithConfigMapForBrokerConfig(),
)

// Create a logger (EventRecord) Pod and a K8s Service that points to it.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/broker_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"knative.dev/eventing/test/e2e/helpers"
)

// TestBrokerDeadLetterSink tests Broker's DeadLetterSink
// TestBrokerWithConfig tests Broker using Config instead of channel templates.
func TestBrokerWithConfig(t *testing.T) {
helpers.TestBrokerWithConfig(t, brokerClass, channelTestRunner)
}
10 changes: 6 additions & 4 deletions test/e2e/helpers/broker_channel_flow_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ func BrokerChannelFlowTestHelper(t *testing.T,
defer lib.TearDown(client)

if brokerClass == eventing.ChannelBrokerClassValue {
// create required RBAC resources including ServiceAccounts and ClusterRoleBindings for Brokers
// create required RBAC resources including ServiceAccounts and ClusterRoleBindings for Brokers
client.CreateRBACResourcesForBrokers()
}

// Create a configmap used by the broker.
client.CreateBrokerConfigMapOrFail(brokerName, &channel)

// create a new broker
client.CreateBrokerOrFail(brokerName,
resources.WithBrokerClassForBroker(brokerClass),
resources.WithChannelTemplateForBroker(&channel))
client.CreateBrokerV1Beta1OrFail(brokerName,
resources.WithBrokerClassForBrokerV1Beta1(brokerClass),
resources.WithConfigMapForBrokerConfig())
client.WaitForResourceReadyOrFail(brokerName, lib.BrokerTypeMeta)

// create the event we want to transform to
Expand Down
11 changes: 7 additions & 4 deletions test/e2e/helpers/broker_dls_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ func BrokerDeadLetterSinkTestHelper(t *testing.T,

delivery := resources.Delivery(resources.WithDeadLetterSinkForDelivery(loggerPodName))

// Create a configmap used by the broker.
client.CreateBrokerConfigMapOrFail(brokerName, &channel)

// create a new broker
client.CreateBrokerOrFail(brokerName,
resources.WithBrokerClassForBroker(brokerClass),
resources.WithChannelTemplateForBroker(&channel),
resources.WithDeliveryForBroker(delivery))
client.CreateBrokerV1Beta1OrFail(brokerName,
resources.WithBrokerClassForBrokerV1Beta1(brokerClass),
resources.WithConfigMapForBrokerConfig(),
resources.WithDeliveryForBrokerV1Beta1(delivery))

client.WaitForResourceReadyOrFail(brokerName, lib.BrokerTypeMeta)

Expand Down
5 changes: 4 additions & 1 deletion test/e2e/helpers/broker_event_transformation_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ func EventTransformationForTriggerTestHelper(t *testing.T,
client.CreateRBACResourcesForBrokers()
}

// Create a configmap used by the broker.
config := client.CreateBrokerConfigMapOrFail(brokerName, &channel)

// create a new broker
client.CreateBrokerOrFail(brokerName, resources.WithBrokerClassForBroker(brokerClass), resources.WithChannelTemplateForBroker(&channel))
client.CreateBrokerV1Beta1OrFail(brokerName, resources.WithBrokerClassForBrokerV1Beta1(brokerClass), resources.WithConfigForBrokerV1Beta1(config))
client.WaitForResourceReadyOrFail(brokerName, lib.BrokerTypeMeta)

// create the event we want to transform to
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helpers/broker_with_config_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestBrokerWithConfig(t *testing.T,
//&channel

// create a new broker
client.CreateBrokerV1Beta1OrFail(brokerName, resources.WithBrokerClassForBrokerV1Beta1(brokerClass), resources.WithChannelTemplateForBrokerV1Beta1(config))
client.CreateBrokerV1Beta1OrFail(brokerName, resources.WithBrokerClassForBrokerV1Beta1(brokerClass), resources.WithConfigForBrokerV1Beta1(config))
client.WaitForResourceReadyOrFail(brokerName, lib.BrokerTypeMeta)

// create the event we want to transform to
Expand Down
38 changes: 31 additions & 7 deletions test/lib/resources/eventing.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,29 @@ func WithChannelTemplateForBroker(channelTypeMeta *metav1.TypeMeta) BrokerOption
}
}

// WithConfigMapForBrokerConfig returns a function that configures the ConfigMap
// for the Spec.Config for a given Broker. Note that the CM must exist and has
// to be in the same namespace as the Broker and have the same Name. Typically
// you'd do this by calling client.CreateBrokerConfigMapOrFail and then call this
// method.
// If those don't apply to your ConfigMap, look at WithConfigForBrokerV1Beta1
func WithConfigMapForBrokerConfig() BrokerV1Beta1Option {
return func(b *eventingv1beta1.Broker) {
b.Spec.Config = &duckv1.KReference{
Name: b.Name,
Namespace: b.Namespace,
Kind: "ConfigMap",
APIVersion: "v1",
}
}
}

func WithConfigForBrokerV1Beta1(config *duckv1.KReference) BrokerV1Beta1Option {
return func(b *eventingv1beta1.Broker) {
b.Spec.Config = config
}
}

// WithBrokerClassForBrokerV1Beta1 returns a function that adds a brokerClass
// annotation to the given Broker.
func WithBrokerClassForBrokerV1Beta1(brokerClass string) BrokerV1Beta1Option {
Expand All @@ -200,20 +223,21 @@ func WithBrokerClassForBrokerV1Beta1(brokerClass string) BrokerV1Beta1Option {
}
}

// WithChannelTemplateForBrokerV1Beta1 returns a function that adds a Config to the given Broker.
func WithChannelTemplateForBrokerV1Beta1(config *duckv1.KReference) BrokerV1Beta1Option {
return func(b *eventingv1beta1.Broker) {
b.Spec.Config = config
}
}

// WithDeliveryForBroker returns a function that adds a Delivery for the given Broker.
func WithDeliveryForBroker(delivery *eventingduckv1beta1.DeliverySpec) BrokerOption {
return func(b *eventingv1alpha1.Broker) {
b.Spec.Delivery = delivery
}
}

// WithDeliveryForBrokerV1Beta1 returns a function that adds a Delivery for the given
// v1beta1 Broker.
func WithDeliveryForBrokerV1Beta1(delivery *eventingduckv1beta1.DeliverySpec) BrokerV1Beta1Option {
return func(b *eventingv1beta1.Broker) {
b.Spec.Delivery = delivery
}
}

// WithBrokerClassForBroker returns a function that adds a brokerClass
// annotation to the given Broker.
func WithBrokerClassForBroker(brokerClass string) BrokerOption {
Expand Down