Skip to content
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
4 changes: 2 additions & 2 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ chmod +x ${CODEGEN_PKG}/generate-groups.sh
# instead of the $GOPATH directly. For normal projects this can be dropped.
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \
"eventing:v1beta1 eventing:v1 messaging:v1beta1 messaging:v1 flows:v1beta1 sources:v1alpha1 sources:v1alpha2 configs:v1alpha1" \
"eventing:v1beta1 eventing:v1 messaging:v1beta1 messaging:v1 flows:v1beta1 flows:v1 sources:v1alpha1 sources:v1alpha2 configs:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# Deep copy config
Expand All @@ -65,7 +65,7 @@ ${CODEGEN_PKG}/generate-groups.sh "deepcopy" \
chmod +x ${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh
${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh "injection" \
knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \
"eventing:v1beta1 eventing:v1 messaging:v1beta1 messaging:v1 flows:v1beta1 sources:v1alpha1 sources:v1alpha2 duck:v1alpha1 duck:v1beta1 duck:v1 configs:v1alpha1" \
"eventing:v1beta1 eventing:v1 messaging:v1beta1 messaging:v1 flows:v1beta1 flows:v1 sources:v1alpha1 sources:v1alpha2 duck:v1alpha1 duck:v1beta1 duck:v1 configs:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# Make sure our dependencies are up-to-date
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/flows/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2020 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 is the v1 version of the API.
// +k8s:deepcopy-gen=package
// +groupName=flows.knative.dev
package v1
41 changes: 41 additions & 0 deletions pkg/apis/flows/v1/implements_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2020 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 (
"testing"

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

func TestTypesImplements(t *testing.T) {
testCases := []struct {
instance interface{}
iface duck.Implementable
}{
// Sequence
{instance: &Sequence{}, iface: &duckv1.Conditions{}},
// Parallel
{instance: &Parallel{}, iface: &duckv1.Conditions{}},
}
for _, tc := range testCases {
if err := duck.VerifyType(tc.instance, tc.iface); err != nil {
t.Error(err)
}
}
}
34 changes: 34 additions & 0 deletions pkg/apis/flows/v1/parallel_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2020 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"
"fmt"

"knative.dev/pkg/apis"
)

// ConvertTo implements apis.Convertible
func (source *Parallel) ConvertTo(ctx context.Context, sink apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", sink)
}

// ConvertFrom implements apis.Convertible
func (sink *Parallel) ConvertFrom(ctx context.Context, source apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", source)
}
34 changes: 34 additions & 0 deletions pkg/apis/flows/v1/parallel_conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2020 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"
)

func TestParallelConversionBadType(t *testing.T) {
good, bad := &Parallel{}, &Parallel{}

if err := good.ConvertTo(context.Background(), bad); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", bad)
}

if err := good.ConvertFrom(context.Background(), bad); err == nil {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}
56 changes: 56 additions & 0 deletions pkg/apis/flows/v1/parallel_defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2020 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"

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

func (p *Parallel) SetDefaults(ctx context.Context) {
withNS := apis.WithinParent(ctx, p.ObjectMeta)
if p != nil && p.Spec.ChannelTemplate == nil {
cfg := config.FromContextOrDefaults(ctx)
c, err := cfg.ChannelDefaults.GetChannelConfig(apis.ParentMeta(ctx).Namespace)

if err == nil {
p.Spec.ChannelTemplate = &messagingv1.ChannelTemplateSpec{
TypeMeta: c.TypeMeta,
Spec: c.Spec,
}
}
}
p.Spec.SetDefaults(withNS)
}

func (ps *ParallelSpec) SetDefaults(ctx context.Context) {
for _, branch := range ps.Branches {
if branch.Filter != nil {
branch.Filter.SetDefaults(ctx)
}
branch.Subscriber.SetDefaults(ctx)
if branch.Reply != nil {
branch.Reply.SetDefaults(ctx)
}
}
if ps.Reply != nil {
ps.Reply.SetDefaults(ctx)
}
}
153 changes: 153 additions & 0 deletions pkg/apis/flows/v1/parallel_defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
Copyright 2020 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"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/google/go-cmp/cmp"
"knative.dev/eventing/pkg/apis/messaging/config"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

func TestParallelSetDefaults(t *testing.T) {
testCases := map[string]struct {
nilChannelDefaulter bool
channelTemplate *config.ChannelTemplateSpec
initial Parallel
expected Parallel
}{
"nil ChannelDefaulter": {
nilChannelDefaulter: true,
expected: Parallel{},
},
"unset ChannelDefaulter": {
expected: Parallel{},
},
"set ChannelDefaulter": {
channelTemplate: configDefaultChannelTemplate,
expected: Parallel{
Spec: ParallelSpec{
ChannelTemplate: defaultChannelTemplate,
},
},
},
"branches namespace defaulted": {
channelTemplate: configDefaultChannelTemplate,
initial: Parallel{
ObjectMeta: metav1.ObjectMeta{Namespace: testNS},
Spec: ParallelSpec{
Branches: []ParallelBranch{
{
Filter: &duckv1.Destination{
Ref: &duckv1.KReference{Name: "firstfilter"},
},
Subscriber: duckv1.Destination{
Ref: &duckv1.KReference{Name: "firstsub"},
},
Reply: &duckv1.Destination{
Ref: &duckv1.KReference{Name: "firstreply"},
},
}, {
Filter: &duckv1.Destination{
Ref: &duckv1.KReference{Name: "secondfilter"},
},
Subscriber: duckv1.Destination{
Ref: &duckv1.KReference{Name: "secondsub"},
},
Reply: &duckv1.Destination{
Ref: &duckv1.KReference{Name: "secondreply"},
},
}},
Reply: &duckv1.Destination{Ref: &duckv1.KReference{Name: "reply"}}},
},
expected: Parallel{
ObjectMeta: metav1.ObjectMeta{Namespace: testNS},
Spec: ParallelSpec{
ChannelTemplate: defaultChannelTemplate,
Branches: []ParallelBranch{
{
Filter: &duckv1.Destination{
Ref: &duckv1.KReference{Name: "firstfilter", Namespace: testNS},
},
Subscriber: duckv1.Destination{
Ref: &duckv1.KReference{Name: "firstsub", Namespace: testNS},
},
Reply: &duckv1.Destination{
Ref: &duckv1.KReference{Name: "firstreply", Namespace: testNS},
},
}, {
Filter: &duckv1.Destination{
Ref: &duckv1.KReference{Name: "secondfilter", Namespace: testNS},
},
Subscriber: duckv1.Destination{
Ref: &duckv1.KReference{Name: "secondsub", Namespace: testNS},
},
Reply: &duckv1.Destination{
Ref: &duckv1.KReference{Name: "secondreply", Namespace: testNS},
},
}},
Reply: &duckv1.Destination{Ref: &duckv1.KReference{Name: "reply", Namespace: testNS}},
},
},
},
"template already specified": {
channelTemplate: configDefaultChannelTemplate,
initial: Parallel{
Spec: ParallelSpec{
ChannelTemplate: &messagingv1.ChannelTemplateSpec{
TypeMeta: v1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: "OtherChannel",
},
},
},
},
expected: Parallel{
Spec: ParallelSpec{
ChannelTemplate: &messagingv1.ChannelTemplateSpec{
TypeMeta: v1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: "OtherChannel",
},
},
},
},
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
ctx := context.Background()
if !tc.nilChannelDefaulter {
ctx = config.ToContext(ctx, &config.Config{
ChannelDefaults: &config.ChannelDefaults{
ClusterDefault: tc.channelTemplate,
},
})
}
tc.initial.SetDefaults(ctx)
if diff := cmp.Diff(tc.expected, tc.initial); diff != "" {
t.Fatalf("Unexpected defaults (-want, +got): %s", diff)
}
})
}
}
Loading