Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
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
1 change: 1 addition & 0 deletions config/core/resources/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ spec:
delivery:
description: Delivery contains the delivery spec for this specific trigger.
type: object
x-kubernetes-preserve-unknown-fields: true # This is necessary to enable the experimental feature delivery-timeout
properties:
backoffDelay:
description: 'BackoffDelay is the delay before retrying. More information on Duration format: - https://www.iso.org/iso-8601-date-and-time-format.html - https://en.wikipedia.org/wiki/ISO_8601 For linear policy, backoff delay is backoffDelay*<numberOfRetries>. For exponential policy, backoff delay is backoffDelay*2^<numberOfRetries>.'
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ require (
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
knative.dev/hack v0.0.0-20210622141627-e28525d8d260
knative.dev/hack/schema v0.0.0-20210622141627-e28525d8d260
knative.dev/pkg v0.0.0-20210803160015-21eb4c167cc5
knative.dev/pkg v0.0.0-20210902173607-844a6bc45596
knative.dev/reconciler-test v0.0.0-20210803183715-b61cc77c06f6
sigs.k8s.io/yaml v1.2.0
)
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,9 @@ knative.dev/hack v0.0.0-20210622141627-e28525d8d260 h1:f2eMtOubAOc/Q7JlvFPDKXiPl
knative.dev/hack v0.0.0-20210622141627-e28525d8d260/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack/schema v0.0.0-20210622141627-e28525d8d260 h1:YkMkZ7qdafyRHNIuKttYzEmM1ilKTGyEtPWeVLcLcDE=
knative.dev/hack/schema v0.0.0-20210622141627-e28525d8d260/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0=
knative.dev/pkg v0.0.0-20210803160015-21eb4c167cc5 h1:jpOTmAXg1oLS8u5HPBrFP1XsOSFCQIvlTRxP8TDGg2E=
knative.dev/pkg v0.0.0-20210803160015-21eb4c167cc5/go.mod h1:RPk5txNA3apR9X40D4MpUOP9/VqOG8CrtABWfOwGVS4=
knative.dev/pkg v0.0.0-20210902173607-844a6bc45596 h1:LCSg0O51V8I7sfnhw+j9WLBol8f2lCV5HkPyxJT9zzA=
knative.dev/pkg v0.0.0-20210902173607-844a6bc45596/go.mod h1:RPk5txNA3apR9X40D4MpUOP9/VqOG8CrtABWfOwGVS4=
knative.dev/reconciler-test v0.0.0-20210803183715-b61cc77c06f6 h1:jSz98FX9JfAMJX3qVeRF7RU7A3XLJJxBNz8GYU5z0bM=
knative.dev/reconciler-test v0.0.0-20210803183715-b61cc77c06f6/go.mod h1:+Kovy+G5zXZNcuO/uB+zfo37vFKZzsLIlWezt/nKMz0=
pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U=
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/config/zz_generated.deepcopy.go

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

28 changes: 28 additions & 0 deletions pkg/apis/duck/v1/delivery_defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2021 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import "context"

func (ds *DeliverySpec) SetDefaults(ctx context.Context) {
if ds == nil {
return
}
if ds.DeadLetterSink != nil {
ds.DeadLetterSink.SetDefaults(ctx)
}
}
85 changes: 85 additions & 0 deletions pkg/apis/duck/v1/delivery_defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2021 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

func TestDeliverySpecSetDefaults(t *testing.T) {
t.Parallel()

tt := []struct {
name string
given *DeliverySpec
want *DeliverySpec
ctx context.Context
}{
{
name: "nil",
ctx: context.Background(),
},
{
name: "deadLetterSink nil",
ctx: context.Background(),
given: &DeliverySpec{},
want: &DeliverySpec{},
},
{
name: "deadLetterSink.ref nil",
ctx: context.Background(),
given: &DeliverySpec{DeadLetterSink: &duckv1.Destination{}},
want: &DeliverySpec{DeadLetterSink: &duckv1.Destination{}},
},
{
name: "deadLetterSink.ref.namespace empty string",
ctx: apis.WithinParent(context.Background(), metav1.ObjectMeta{Name: "b", Namespace: "custom"}),
given: &DeliverySpec{DeadLetterSink: &duckv1.Destination{
Ref: &duckv1.KReference{
Kind: "Service",
Namespace: "",
Name: "svc",
APIVersion: "v1",
},
}},
want: &DeliverySpec{DeadLetterSink: &duckv1.Destination{
Ref: &duckv1.KReference{
Kind: "Service",
Namespace: "custom",
Name: "svc",
APIVersion: "v1",
},
}},
},
}

for _, tc := range tt {
tc := tc
t.Run(tc.name, func(t *testing.T) {
tc.given.SetDefaults(tc.ctx)
if diff := cmp.Diff(tc.want, tc.given); diff != "" {
t.Error("(-want, +got)", diff)
}
})
}
}
1 change: 1 addition & 0 deletions pkg/apis/duck/v1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions pkg/apis/duck/v1beta1/zz_generated.deepcopy.go

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

4 changes: 3 additions & 1 deletion pkg/apis/eventing/v1/broker_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (

eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1"

"knative.dev/pkg/apis"

"knative.dev/eventing/pkg/apis/config"
"knative.dev/eventing/pkg/apis/eventing"
"knative.dev/pkg/apis"
)

func (b *Broker) SetDefaults(ctx context.Context) {
Expand Down Expand Up @@ -53,4 +54,5 @@ func (bs *BrokerSpec) SetDefaults(ctx context.Context) {
if bs.Config != nil {
bs.Config.SetDefaults(ctx)
}
bs.Delivery.SetDefaults(ctx)
}
59 changes: 58 additions & 1 deletion pkg/apis/eventing/v1/broker_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import (
"testing"

"k8s.io/utils/pointer"

eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1"

"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

duckv1 "knative.dev/pkg/apis/duck/v1"

"knative.dev/eventing/pkg/apis/config"
"knative.dev/eventing/pkg/apis/eventing"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

var (
Expand Down Expand Up @@ -404,6 +406,61 @@ func TestBrokerSetDefaults(t *testing.T) {
},
},
},
"missing deadLetterSink.ref.namespace, defaulted": {
initial: Broker{
ObjectMeta: metav1.ObjectMeta{Name: "broker", Namespace: "custom"},
Spec: BrokerSpec{
Config: &duckv1.KReference{
Kind: "ConfigMap",
Name: "natss-channel",
Namespace: "custom1",
APIVersion: "v1",
},
Delivery: &eventingduckv1.DeliverySpec{
DeadLetterSink: &duckv1.Destination{
Ref: &duckv1.KReference{
Kind: "Service",
Name: "handle-error",
APIVersion: "serving.knative.dev/v1",
},
},
Retry: pointer.Int32Ptr(5),
BackoffPolicy: (*eventingduckv1.BackoffPolicyType)(pointer.StringPtr("linear")),
BackoffDelay: pointer.StringPtr("5s"),
},
},
},
expected: Broker{
ObjectMeta: metav1.ObjectMeta{
Name: "broker",
Namespace: "custom",
Annotations: map[string]string{
eventing.BrokerClassKey: "MTChannelBasedBroker",
},
},
Spec: BrokerSpec{
Config: &duckv1.KReference{
Kind: "ConfigMap",
Namespace: "custom1",
Name: "natss-channel",
APIVersion: "v1",
},
Delivery: &eventingduckv1.DeliverySpec{
DeadLetterSink: &duckv1.Destination{
Ref: &duckv1.KReference{
Kind: "Service",
Namespace: "custom",
Name: "handle-error",
APIVersion: "serving.knative.dev/v1",
},
},
Retry: pointer.Int32Ptr(5),
BackoffPolicy: (*eventingduckv1.BackoffPolicyType)(pointer.StringPtr("linear")),
BackoffDelay: pointer.StringPtr("5s"),
},
},
},
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/eventing/v1/trigger_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (ts *TriggerSpec) SetDefaults(ctx context.Context) {
}
// Default the Subscriber namespace
ts.Subscriber.SetDefaults(ctx)
ts.Delivery.SetDefaults(ctx)
}

func setLabels(t *Trigger) {
Expand Down
46 changes: 46 additions & 0 deletions pkg/apis/eventing/v1/trigger_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
duckv1 "knative.dev/pkg/apis/duck/v1"

"github.com/google/go-cmp/cmp"

eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1"
)

var (
Expand Down Expand Up @@ -80,6 +82,50 @@ func TestTriggerDefaults(t *testing.T) {
},
}},
},
"deadLetterSink, ns defaulted": {
initial: Trigger{
ObjectMeta: metav1.ObjectMeta{
Namespace: "custom",
},
Spec: TriggerSpec{
Delivery: &eventingduckv1.DeliverySpec{
DeadLetterSink: &duckv1.Destination{
Ref: &duckv1.KReference{
Name: "foo",
},
},
},
Broker: otherBroker,
Subscriber: duckv1.Destination{
Ref: &duckv1.KReference{
Name: "foo",
Namespace: "custom1",
},
}}},
expected: Trigger{
ObjectMeta: v1.ObjectMeta{
Namespace: "custom",
Labels: map[string]string{brokerLabel: otherBroker},
},
Spec: TriggerSpec{
Broker: otherBroker,
Filter: emptyTriggerFilter,
Delivery: &eventingduckv1.DeliverySpec{
DeadLetterSink: &duckv1.Destination{
Ref: &duckv1.KReference{
Name: "foo",
Namespace: "custom",
},
},
},
Subscriber: duckv1.Destination{
Ref: &duckv1.KReference{
Name: "foo",
Namespace: "custom1",
},
},
}},
},
"nil broker and nil filter": {
initial: Trigger{},
expected: defaultTrigger,
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/eventing/v1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions pkg/apis/eventing/v1beta1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions pkg/apis/flows/v1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions pkg/apis/messaging/config/zz_generated.deepcopy.go

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

4 changes: 3 additions & 1 deletion pkg/apis/messaging/v1/channel_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package v1
import (
"context"

"knative.dev/pkg/apis"

"knative.dev/eventing/pkg/apis/messaging"
"knative.dev/eventing/pkg/apis/messaging/config"
"knative.dev/pkg/apis"
)

func (c *Channel) SetDefaults(ctx context.Context) {
Expand All @@ -48,6 +49,7 @@ func (cs *ChannelSpec) SetDefaults(ctx context.Context) {
c.Spec,
}
}
cs.Delivery.SetDefaults(ctx)
}

// ChannelDefaulter sets the default Channel CRD and Arguments on Channels that do not
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/messaging/v1/channel_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func (cs *ChannelSpec) Validate(ctx context.Context) *apis.FieldError {
if len(cs.SubscribableSpec.Subscribers) > 0 {
errs = errs.Also(apis.ErrDisallowedFields("subscribers").ViaField("subscribable"))
}

if cs.Delivery != nil {
if fe := cs.Delivery.Validate(ctx); fe != nil {
errs = errs.Also(fe.ViaField("delivery"))
}
}

return errs
}

Expand Down
Loading