Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1802578
adding messaging.channel resource
nachocano Jul 22, 2019
755ac4a
channel messaging
nachocano Jul 22, 2019
b1f91d8
using ChannelTemplateSpec
nachocano Jul 22, 2019
7d34bcf
updating channel controller
nachocano Jul 22, 2019
71187ba
channel validation
nachocano Jul 22, 2019
109e8c6
setting to channelTemplate
nachocano Jul 23, 2019
2b54e41
to json
nachocano Jul 23, 2019
eac06fe
channel defaulter
nachocano Jul 23, 2019
a7b0c63
working
nachocano Jul 23, 2019
b419077
removing logs
nachocano Jul 23, 2019
f5d4997
Merge remote-tracking branch 'upstream/master' into default-channel
nachocano Jul 23, 2019
4727ae3
patching subscriptions... infinite loop
nachocano Jul 23, 2019
d1723c1
updates
nachocano Jul 23, 2019
970ada4
immutable
nachocano Jul 23, 2019
870a146
problems with cyclic dependencies
nachocano Jul 23, 2019
5e5b8bd
moving channel defaulter to duck to avoid cyclic dependency
nachocano Jul 23, 2019
d0ebf80
channel defaulter test
nachocano Jul 23, 2019
5cdb7e1
updating UTs
nachocano Jul 23, 2019
9043e37
channel validation test
nachocano Jul 23, 2019
db7127b
updating validation
nachocano Jul 23, 2019
eee7e1d
updating lifecycle
nachocano Jul 23, 2019
e1925ac
updates to broker
nachocano Jul 23, 2019
c0e7af4
fixing sequence
nachocano Jul 23, 2019
4916884
broker types
nachocano Jul 24, 2019
ef016c5
updating deprecated message
nachocano Jul 24, 2019
dadac47
updating broker validation
nachocano Jul 24, 2019
961b0f1
cosmetic
nachocano Jul 24, 2019
d30d7ba
injection magic
nachocano Jul 24, 2019
4761836
update to broker test
nachocano Jul 24, 2019
42de64b
updating UTs
nachocano Jul 24, 2019
2734cb2
more UTs
nachocano Jul 24, 2019
b44c8dd
eventingchannel package
nachocano Jul 24, 2019
7c57d38
cosmetic
nachocano Jul 24, 2019
376a5b5
cosmetics
nachocano Jul 24, 2019
c018c2d
compilation, my bad...
nachocano Jul 24, 2019
025462e
hopefully the last one
nachocano Jul 24, 2019
678e589
Ville's comments
nachocano Jul 25, 2019
356ca7c
Adam's comments, plus cosmetic tests to try to make coverage pass.
nachocano Jul 25, 2019
0ee8679
sequence defaults
nachocano Jul 25, 2019
b77538b
Merge remote-tracking branch 'upstream/master' into default-channel-s…
nachocano Jul 25, 2019
2afd344
compiling tests... hopefully
nachocano Jul 25, 2019
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
17 changes: 13 additions & 4 deletions pkg/apis/messaging/v1alpha1/sequence_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ limitations under the License.

package v1alpha1

import "context"
import (
"context"
eventingduckv1alpha1 "github.com/knative/eventing/pkg/apis/duck/v1alpha1"
)

func (s *Sequence) SetDefaults(ctx context.Context) {
if s != nil && s.Spec.ChannelTemplate == nil {
// The singleton may not have been set, if so ignore it and validation will reject the
// Channel.
if cd := eventingduckv1alpha1.ChannelDefaulterSingleton; cd != nil {
channelTemplate := cd.GetDefault(s.Namespace)
s.Spec.ChannelTemplate = channelTemplate
}
}
s.Spec.SetDefaults(ctx)
}

func (ss *SequenceSpec) SetDefaults(ctx context.Context) {
// TODO anything?
}
func (ss *SequenceSpec) SetDefaults(ctx context.Context) {}
105 changes: 105 additions & 0 deletions pkg/apis/messaging/v1alpha1/sequence_defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
Copyright 2019 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 v1alpha1

import (
"context"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"

"github.com/google/go-cmp/cmp"
eventingduckv1alpha1 "github.com/knative/eventing/pkg/apis/duck/v1alpha1"
)

var (
defaultTemplate = &eventingduckv1alpha1.ChannelTemplateSpec{
TypeMeta: v1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: "InMemoryChannel",
},
}
)

func TestSequenceSetDefaults(t *testing.T) {
testCases := map[string]struct {
nilChannelDefaulter bool
channelTemplate *eventingduckv1alpha1.ChannelTemplateSpec
initial Sequence
expected Sequence
}{
"nil ChannelDefaulter": {
nilChannelDefaulter: true,
expected: Sequence{},
},
"unset ChannelDefaulter": {
expected: Sequence{},
},
"set ChannelDefaulter": {
channelTemplate: defaultChannelTemplate,
expected: Sequence{
Spec: SequenceSpec{
ChannelTemplate: defaultChannelTemplate,
},
},
},
"template already specified": {
channelTemplate: defaultChannelTemplate,
initial: Sequence{
Spec: SequenceSpec{
ChannelTemplate: &eventingduckv1alpha1.ChannelTemplateSpec{
TypeMeta: v1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: "OtherChannel",
},
},
},
},
expected: Sequence{
Spec: SequenceSpec{
ChannelTemplate: &eventingduckv1alpha1.ChannelTemplateSpec{
TypeMeta: v1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: "OtherChannel",
},
},
},
},
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
if !tc.nilChannelDefaulter {
eventingduckv1alpha1.ChannelDefaulterSingleton = &sequenceChannelDefaulter{
channelTemplate: tc.channelTemplate,
}
defer func() { eventingduckv1alpha1.ChannelDefaulterSingleton = nil }()
}
tc.initial.SetDefaults(context.TODO())
if diff := cmp.Diff(tc.expected, tc.initial); diff != "" {
t.Fatalf("Unexpected defaults (-want, +got): %s", diff)
}
})
}
}

type sequenceChannelDefaulter struct {
channelTemplate *eventingduckv1alpha1.ChannelTemplateSpec
}

func (cd *sequenceChannelDefaulter) GetDefault(_ string) *eventingduckv1alpha1.ChannelTemplateSpec {
return cd.channelTemplate
}
6 changes: 4 additions & 2 deletions pkg/apis/messaging/v1alpha1/sequence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ type SequenceSpec struct {
// provided.
Steps []eventingv1alpha1.SubscriberSpec `json:"steps"`

// ChannelTemplate specifies which Channel CRD to use
ChannelTemplate eventingduckv1alpha1.ChannelTemplateSpec `json:"channelTemplate"`
// ChannelTemplate specifies which Channel CRD to use. If left unspecified, it is set to the default Channel CRD
// for the namespace (or cluster, in case there are no defaults for the namespace).
// +optional
ChannelTemplate *eventingduckv1alpha1.ChannelTemplateSpec `json:"channelTemplate,omitempty"`

// Reply is a Reference to where the result of the last Subscriber gets sent to.
//
Expand Down
4 changes: 1 addition & 3 deletions pkg/apis/messaging/v1alpha1/sequence_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package v1alpha1

import (
"context"
eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1"
eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1"
"k8s.io/apimachinery/pkg/api/equality"
"knative.dev/pkg/apis"
)

Expand All @@ -41,7 +39,7 @@ func (ps *SequenceSpec) Validate(ctx context.Context) *apis.FieldError {
}
}

if equality.Semantic.DeepEqual(ps.ChannelTemplate, eventingduck.ChannelTemplateSpec{}) {
if ps.ChannelTemplate == nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if channelTemplate is set but empty?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you mean something like:

spec:
  channelTemplate: {}

It will fail because we validate en the next lines wether it has APIVersion and Kind.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ahh, it was below the fold, so I didn't notice it.

errs = errs.Also(apis.ErrMissingField("channelTemplate"))
return errs
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/messaging/v1alpha1/sequence_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func makeInvalidReply(channelName string) *corev1.ObjectReference {

func TestSequenceSpecValidation(t *testing.T) {
subscriberURI := "http://example.com"
validChannelTemplate := eventingduck.ChannelTemplateSpec{
validChannelTemplate := &eventingduck.ChannelTemplateSpec{
TypeMeta: metav1.TypeMeta{
Kind: "mykind",
APIVersion: "myapiversion",
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestSequenceSpecValidation(t *testing.T) {
}, {
name: "invalid channeltemplatespec missing APIVersion",
ts: &SequenceSpec{
ChannelTemplate: eventingduck.ChannelTemplateSpec{TypeMeta: metav1.TypeMeta{Kind: "mykind"}, Spec: &runtime.RawExtension{}},
ChannelTemplate: &eventingduck.ChannelTemplateSpec{TypeMeta: metav1.TypeMeta{Kind: "mykind"}, Spec: &runtime.RawExtension{}},
Steps: []eventingv1alpha1.SubscriberSpec{{URI: &subscriberURI}},
},
want: func() *apis.FieldError {
Expand All @@ -114,7 +114,7 @@ func TestSequenceSpecValidation(t *testing.T) {
}, {
name: "invalid channeltemplatespec missing Kind",
ts: &SequenceSpec{
ChannelTemplate: eventingduck.ChannelTemplateSpec{TypeMeta: metav1.TypeMeta{APIVersion: "myapiversion"}, Spec: &runtime.RawExtension{}},
ChannelTemplate: &eventingduck.ChannelTemplateSpec{TypeMeta: metav1.TypeMeta{APIVersion: "myapiversion"}, Spec: &runtime.RawExtension{}},
Steps: []eventingv1alpha1.SubscriberSpec{{URI: &subscriberURI}},
},
want: func() *apis.FieldError {
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/messaging/v1alpha1/zz_generated.deepcopy.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/sequence/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func createSubscriber(stepNumber int) eventingv1alpha1.SubscriberSpec {

func TestAllCases(t *testing.T) {
pKey := testNS + "/" + sequenceName
imc := eventingduckv1alpha1.ChannelTemplateSpec{
imc := &eventingduckv1alpha1.ChannelTemplateSpec{
TypeMeta: metav1.TypeMeta{
APIVersion: "messaging.knative.dev/v1alpha1",
Kind: "inmemorychannel",
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/testing/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func WithSequenceDeleted(p *v1alpha1.Sequence) {
p.ObjectMeta.SetDeletionTimestamp(&deleteTime)
}

func WithSequenceChannelTemplateSpec(cts eventingduckv1alpha1.ChannelTemplateSpec) SequenceOption {
func WithSequenceChannelTemplateSpec(cts *eventingduckv1alpha1.ChannelTemplateSpec) SequenceOption {
return func(p *v1alpha1.Sequence) {
p.Spec.ChannelTemplate = cts
}
Expand Down
2 changes: 1 addition & 1 deletion test/base/resources/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func WithReplyForSequence(name string, typemeta *metav1.TypeMeta) SequenceOption
func Sequence(
name string,
steps []eventingv1alpha1.SubscriberSpec,
channelTemplate eventingduckv1alpha1.ChannelTemplateSpec,
channelTemplate *eventingduckv1alpha1.ChannelTemplateSpec,
options ...SequenceOption,
) *messagingv1alpha1.Sequence {
sequence := &messagingv1alpha1.Sequence{
Expand Down
2 changes: 1 addition & 1 deletion test/common/creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (client *Client) CreateTriggerOrFail(name string, options ...resources.Trig
func (client *Client) CreateSequenceOrFail(
name string,
steps []eventingv1alpha1.SubscriberSpec,
channelTemplate eventingduckv1alpha1.ChannelTemplateSpec,
channelTemplate *eventingduckv1alpha1.ChannelTemplateSpec,
options ...resources.SequenceOption,
) {
namespace := client.Namespace
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestSequence(t *testing.T) {
}

// create channelTemplate for the Sequence
channelTemplate := eventingduckv1alpha1.ChannelTemplateSpec{
channelTemplate := &eventingduckv1alpha1.ChannelTemplateSpec{
TypeMeta: *(channelTypeMeta),
}

Expand Down