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
6 changes: 6 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
"channels:v1alpha1 feeds:v1alpha1 flows:v1alpha1 eventing:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# Only deepcopy the Duck types, as they are not real resources.
${CODEGEN_PKG}/generate-groups.sh "deepcopy" \
github.com/knative/eventing/pkg/client github.com/knative/eventing/pkg/apis \
"duck:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# Make sure our dependencies are up-to-date
${REPO_ROOT_DIR}/hack/update-deps.sh
87 changes: 87 additions & 0 deletions pkg/apis/duck/v1alpha1/channelable_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2018 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 (
"github.com/knative/pkg/apis/duck"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// Channelable is the schema for the channelable portion of the spec
// section of the resource.
type Channelable struct {
// TODO: What is actually required here for Channel spec.
// This is the list of subscriptions for this channel.
Subscribers []ChannelSubscriberSpec `json:"subscribers,omitempty"`
}

// ChannelSubscriberSpec defines a single subscriber to a Channel.
// CallableURI is the endpoint for the call
// SinkableURI is the endpoint for the result
// At least one of them must be present
type ChannelSubscriberSpec struct {
// +optional
CallableURI string `json:"callableURI,omitempty"`
// +optional
SinkableURI string `json:"sinkableURI,omitempty"`
}

// DuckChannel is a skeleton type wrapping Channelable in the manner we expect resource writers
// defining compatible resources to embed it. We will typically use this type to deserialize
// Channelable ObjectReferences and access the Channelable data. This is not a real resource.
type Channel struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// ChannelSpec is the part where Channelable object is
// configured as to be compatible with Channelable contract.
Spec ChannelSpec `json:"spec"`
}

// DuckChannelSpec shows how we expect folks to embed Channelable in their Spec field.
type ChannelSpec struct {
Channelable *Channelable `json:"channelable,omitempty"`
}

// GetFullType implements duck.Implementable
func (_ *Channelable) GetFullType() duck.Populatable {
return &Channel{}
}

// Populate implements duck.Populatable
func (t *Channel) Populate() {
t.Spec.Channelable = &Channelable{
// Populate ALL fields
Subscribers: []ChannelSubscriberSpec{{"call1", "sink2"}, {"call2", "sink2"}},
}
}

// GetListType implements apis.Listable
func (r *Channel) GetListType() runtime.Object {
return &ChannelList{}
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ChannelList is a list of Channel resources
type ChannelList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []Channel `json:"items"`
}
20 changes: 20 additions & 0 deletions pkg/apis/duck/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2018 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.
*/

// Api versions allow the api contract for a resource to be changed while keeping
// backward compatibility by support multiple concurrent versions
// of the same resource

// +k8s:deepcopy-gen=package
// +groupName=duck.knative.dev
package v1alpha1
139 changes: 139 additions & 0 deletions pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go

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

3 changes: 2 additions & 1 deletion pkg/apis/eventing/v1alpha1/channel_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package v1alpha1

import (
eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1"
"github.com/knative/pkg/apis"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
"github.com/knative/pkg/webhook"
Expand Down Expand Up @@ -72,7 +73,7 @@ type ChannelSpec struct {
Arguments *runtime.RawExtension `json:"arguments,omitempty"`

// Channel conforms to Duck type Channelable.
Channelable *duckv1alpha1.Channelable `json:"channelable,omitempty"`
Channelable *eventingduck.Channelable `json:"channelable,omitempty"`
}

var chanCondSet = duckv1alpha1.NewLivingConditionSet(ChannelConditionProvisioned, ChannelConditionSinkable)
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/eventing/v1alpha1/channel_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (cs *ChannelSpec) Validate() *apis.FieldError {

if cs.Channelable != nil {
for i, subscriber := range cs.Channelable.Subscribers {
if subscriber.SinkableDomain == "" && subscriber.CallableDomain == "" {
fe := apis.ErrMissingField("sinkableDomain", "callableDomain")
if subscriber.SinkableURI == "" && subscriber.CallableURI == "" {
fe := apis.ErrMissingField("sinkableURI", "callableURI")
fe.Details = "expected at least one of, got none"
errs = errs.Also(fe.ViaField(fmt.Sprintf("subscriber[%d]", i)).ViaField("channelable"))
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/apis/eventing/v1alpha1/channel_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1"
"github.com/knative/pkg/apis"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand Down Expand Up @@ -56,10 +56,10 @@ func TestChannelValidation(t *testing.T) {
Name: "foo",
},
},
Channelable: &duckv1alpha1.Channelable{
Subscribers: []duckv1alpha1.ChannelSubscriberSpec{{
CallableDomain: "callableendpoint",
SinkableDomain: "resultendpoint",
Channelable: &eventingduck.Channelable{
Subscribers: []eventingduck.ChannelSubscriberSpec{{
CallableURI: "callableendpoint",
SinkableURI: "resultendpoint",
}},
}},
},
Expand All @@ -73,15 +73,15 @@ func TestChannelValidation(t *testing.T) {
Name: "foo",
},
},
Channelable: &duckv1alpha1.Channelable{
Subscribers: []duckv1alpha1.ChannelSubscriberSpec{{
CallableDomain: "callableendpoint",
SinkableDomain: "callableendpoint",
Channelable: &eventingduck.Channelable{
Subscribers: []eventingduck.ChannelSubscriberSpec{{
CallableURI: "callableendpoint",
SinkableURI: "callableendpoint",
}, {}},
}},
},
want: func() *apis.FieldError {
fe := apis.ErrMissingField("spec.channelable.subscriber[1].callableDomain", "spec.channelable.subscriber[1].sinkableDomain")
fe := apis.ErrMissingField("spec.channelable.subscriber[1].callableURI", "spec.channelable.subscriber[1].sinkableURI")
fe.Details = "expected at least one of, got none"
return fe
}(),
Expand All @@ -94,17 +94,17 @@ func TestChannelValidation(t *testing.T) {
Name: "foo",
},
},
Channelable: &duckv1alpha1.Channelable{
Subscribers: []duckv1alpha1.ChannelSubscriberSpec{{}, {}},
Channelable: &eventingduck.Channelable{
Subscribers: []eventingduck.ChannelSubscriberSpec{{}, {}},
},
},
},
want: func() *apis.FieldError {
var errs *apis.FieldError
fe := apis.ErrMissingField("spec.channelable.subscriber[0].callableDomain", "spec.channelable.subscriber[0].sinkableDomain")
fe := apis.ErrMissingField("spec.channelable.subscriber[0].callableURI", "spec.channelable.subscriber[0].sinkableURI")
fe.Details = "expected at least one of, got none"
errs = errs.Also(fe)
fe = apis.ErrMissingField("spec.channelable.subscriber[1].callableDomain", "spec.channelable.subscriber[1].sinkableDomain")
fe = apis.ErrMissingField("spec.channelable.subscriber[1].callableURI", "spec.channelable.subscriber[1].sinkableURI")
fe.Details = "expected at least one of, got none"
errs = errs.Also(fe)
return errs
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/eventing/v1alpha1/implements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package v1alpha1
import (
"testing"

eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1"
"github.com/knative/pkg/apis/duck"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
)
Expand All @@ -27,7 +28,7 @@ func TestTypesImplements(t *testing.T) {
}{
// Channel
{instance: &Channel{}, iface: &duckv1alpha1.Conditions{}},
{instance: &Channel{}, iface: &duckv1alpha1.Channelable{}},
{instance: &Channel{}, iface: &eventingduck.Channelable{}},
{instance: &Channel{}, iface: &duckv1alpha1.Sinkable{}},
// ClusterProvisioner
{instance: &ClusterProvisioner{}, iface: &duckv1alpha1.Conditions{}},
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/eventing/v1alpha1/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ type SubscriptionStatus struct {
// SubscriptionStatusPhysicalSubscription represents the fully resolved values for this
// Subscription.
type SubscriptionStatusPhysicalSubscription struct {
// CallDomain is the fully resolved domain for spec.callable.
CallDomain string `json:"callDomain,omitEmpty"`
// CallURI is the fully resolved URI for spec.callable.
CallURI string `json:"callURI,omitEmpty"`

// ResultDomain is the fully resolved domain for the spec.result.
ResultDomain string `json:"resultDomain,omitEmpty"`
// ResultURI is the fully resolved URI for the spec.result.
ResultURI string `json:"resultURI,omitEmpty"`
}

const (
Expand Down
Loading