diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 9301dc91d9d..6422e616532 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -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 diff --git a/pkg/apis/duck/v1alpha1/channelable_types.go b/pkg/apis/duck/v1alpha1/channelable_types.go new file mode 100644 index 00000000000..ab33f4db72b --- /dev/null +++ b/pkg/apis/duck/v1alpha1/channelable_types.go @@ -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"` +} diff --git a/pkg/apis/duck/v1alpha1/doc.go b/pkg/apis/duck/v1alpha1/doc.go new file mode 100644 index 00000000000..0dcbcff0129 --- /dev/null +++ b/pkg/apis/duck/v1alpha1/doc.go @@ -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 diff --git a/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..c3707fddd3d --- /dev/null +++ b/pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,139 @@ +// +build !ignore_autogenerated + +/* +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. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Channel) DeepCopyInto(out *Channel) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Channel. +func (in *Channel) DeepCopy() *Channel { + if in == nil { + return nil + } + out := new(Channel) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ChannelList) DeepCopyInto(out *ChannelList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Channel, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelList. +func (in *ChannelList) DeepCopy() *ChannelList { + if in == nil { + return nil + } + out := new(ChannelList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ChannelList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ChannelSpec) DeepCopyInto(out *ChannelSpec) { + *out = *in + if in.Channelable != nil { + in, out := &in.Channelable, &out.Channelable + if *in == nil { + *out = nil + } else { + *out = new(Channelable) + (*in).DeepCopyInto(*out) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelSpec. +func (in *ChannelSpec) DeepCopy() *ChannelSpec { + if in == nil { + return nil + } + out := new(ChannelSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ChannelSubscriberSpec) DeepCopyInto(out *ChannelSubscriberSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelSubscriberSpec. +func (in *ChannelSubscriberSpec) DeepCopy() *ChannelSubscriberSpec { + if in == nil { + return nil + } + out := new(ChannelSubscriberSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Channelable) DeepCopyInto(out *Channelable) { + *out = *in + if in.Subscribers != nil { + in, out := &in.Subscribers, &out.Subscribers + *out = make([]ChannelSubscriberSpec, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Channelable. +func (in *Channelable) DeepCopy() *Channelable { + if in == nil { + return nil + } + out := new(Channelable) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index 697dda0fb79..56702f56d00 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -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" @@ -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) diff --git a/pkg/apis/eventing/v1alpha1/channel_validation.go b/pkg/apis/eventing/v1alpha1/channel_validation.go index 1a41996e3ae..0840dbec25c 100644 --- a/pkg/apis/eventing/v1alpha1/channel_validation.go +++ b/pkg/apis/eventing/v1alpha1/channel_validation.go @@ -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")) } diff --git a/pkg/apis/eventing/v1alpha1/channel_validation_test.go b/pkg/apis/eventing/v1alpha1/channel_validation_test.go index e72623cf818..6255252a45d 100644 --- a/pkg/apis/eventing/v1alpha1/channel_validation_test.go +++ b/pkg/apis/eventing/v1alpha1/channel_validation_test.go @@ -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" ) @@ -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", }}, }}, }, @@ -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 }(), @@ -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 diff --git a/pkg/apis/eventing/v1alpha1/implements_test.go b/pkg/apis/eventing/v1alpha1/implements_test.go index 1e0198fe50c..1443a89a455 100644 --- a/pkg/apis/eventing/v1alpha1/implements_test.go +++ b/pkg/apis/eventing/v1alpha1/implements_test.go @@ -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" ) @@ -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{}}, diff --git a/pkg/apis/eventing/v1alpha1/subscription_types.go b/pkg/apis/eventing/v1alpha1/subscription_types.go index 567d156a468..226707d5f38 100644 --- a/pkg/apis/eventing/v1alpha1/subscription_types.go +++ b/pkg/apis/eventing/v1alpha1/subscription_types.go @@ -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 ( diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index 4f946e69bac..01a36278187 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -21,7 +21,8 @@ limitations under the License. package v1alpha1 import ( - duck_v1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" + duck_v1alpha1 "github.com/knative/eventing/pkg/apis/duck/v1alpha1" + apis_duck_v1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" v1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -136,7 +137,7 @@ func (in *ChannelStatus) DeepCopyInto(out *ChannelStatus) { out.Sinkable = in.Sinkable if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make(duck_v1alpha1.Conditions, len(*in)) + *out = make(apis_duck_v1alpha1.Conditions, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -237,7 +238,7 @@ func (in *ClusterProvisionerStatus) DeepCopyInto(out *ClusterProvisionerStatus) *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make(duck_v1alpha1.Conditions, len(*in)) + *out = make(apis_duck_v1alpha1.Conditions, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -440,7 +441,7 @@ func (in *SubscriptionStatus) DeepCopyInto(out *SubscriptionStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make(duck_v1alpha1.Conditions, len(*in)) + *out = make(apis_duck_v1alpha1.Conditions, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } diff --git a/pkg/controller/eventing/inmemory/channel/reconcile_test.go b/pkg/controller/eventing/inmemory/channel/reconcile_test.go index e1905b74570..1d31a9d02a6 100644 --- a/pkg/controller/eventing/inmemory/channel/reconcile_test.go +++ b/pkg/controller/eventing/inmemory/channel/reconcile_test.go @@ -24,12 +24,12 @@ import ( "testing" "github.com/google/go-cmp/cmp" + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" controllertesting "github.com/knative/eventing/pkg/controller/testing" "github.com/knative/eventing/pkg/sidecar/configmap" "github.com/knative/eventing/pkg/sidecar/fanout" "github.com/knative/eventing/pkg/sidecar/multichannelfanout" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" istiov1alpha3 "github.com/knative/pkg/apis/istio/v1alpha3" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -73,16 +73,16 @@ var ( Namespace: cNamespace, Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "foo", + CallableURI: "foo", }, { - SinkableDomain: "bar", + SinkableURI: "bar", }, { - CallableDomain: "baz", - SinkableDomain: "qux", + CallableURI: "baz", + SinkableURI: "qux", }, }, }, @@ -91,9 +91,9 @@ var ( Namespace: cNamespace, Name: "c3", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "steve", + CallableURI: "steve", }, }, }, @@ -116,17 +116,17 @@ var ( Name: cpName, }, }, - Channelable: &duckv1alpha1.Channelable{ - Subscribers: []duckv1alpha1.ChannelSubscriberSpec{ + Channelable: &eventingduck.Channelable{ + Subscribers: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "foo", + CallableURI: "foo", }, { - SinkableDomain: "bar", + SinkableURI: "bar", }, { - CallableDomain: "baz", - SinkableDomain: "qux", + CallableURI: "baz", + SinkableURI: "qux", }, }, }, @@ -146,10 +146,10 @@ var ( Name: "some-other-provisioner", }, }, - Channelable: &duckv1alpha1.Channelable{ - Subscribers: []duckv1alpha1.ChannelSubscriberSpec{ + Channelable: &eventingduck.Channelable{ + Subscribers: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "anything", + CallableURI: "anything", }, }, }, @@ -169,10 +169,10 @@ var ( Name: cpName, }, }, - Channelable: &duckv1alpha1.Channelable{ - Subscribers: []duckv1alpha1.ChannelSubscriberSpec{ + Channelable: &eventingduck.Channelable{ + Subscribers: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "steve", + CallableURI: "steve", }, }, }, diff --git a/pkg/controller/eventing/subscription/reconcile.go b/pkg/controller/eventing/subscription/reconcile.go index 759ec89f6c7..cea0c518c48 100644 --- a/pkg/controller/eventing/subscription/reconcile.go +++ b/pkg/controller/eventing/subscription/reconcile.go @@ -19,8 +19,10 @@ package subscription import ( "context" "fmt" + "net/url" "github.com/golang/glog" + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" "github.com/knative/eventing/pkg/controller" duckapis "github.com/knative/pkg/apis" @@ -93,33 +95,33 @@ func (r *reconciler) reconcile(subscription *v1alpha1.Subscription) error { return err } - callDomain := "" + callURI := "" if subscription.Spec.Call != nil { - callDomain, err = r.resolveEndpointSpec(subscription.Namespace, *subscription.Spec.Call) + callURI, err = r.resolveEndpointSpec(subscription.Namespace, *subscription.Spec.Call) if err != nil { glog.Warningf("Failed to resolve Call %+v : %s", *subscription.Spec.Call, err) return err } - if callDomain == "" { + if callURI == "" { return fmt.Errorf("could not get domain from call (is it not targetable?)") } - subscription.Status.PhysicalSubscription.CallDomain = callDomain - glog.Infof("Resolved call to: %q", callDomain) + subscription.Status.PhysicalSubscription.CallURI = callURI + glog.Infof("Resolved call to: %q", callURI) } - resultDomain := "" + resultURI := "" if subscription.Spec.Result != nil { - resultDomain, err = r.resolveResult(subscription.Namespace, *subscription.Spec.Result) + resultURI, err = r.resolveResult(subscription.Namespace, *subscription.Spec.Result) if err != nil { glog.Warningf("Failed to resolve Result %v : %v", subscription.Spec.Result, err) return err } - if resultDomain == "" { + if resultURI == "" { glog.Warningf("Failed to resolve result %v to actual domain", *subscription.Spec.Result) return err } - subscription.Status.PhysicalSubscription.ResultDomain = resultDomain - glog.Infof("Resolved result to: %q", resultDomain) + subscription.Status.PhysicalSubscription.ResultURI = resultURI + glog.Infof("Resolved result to: %q", resultURI) } // Everything that was supposed to be resolved was, so flip the status bit on that. @@ -179,7 +181,7 @@ func (r *reconciler) resolveEndpointSpec(namespace string, es v1alpha1.EndpointS glog.Warningf("Failed to fetch EndpointSpec target as a K8s Service %+v: %s", es.TargetRef, err) return "", err } - return controller.ServiceHostName(svc.Name, svc.Namespace), nil + return domainToURL(controller.ServiceHostName(svc.Name, svc.Namespace)), nil } obj, err := r.fetchObjectReference(namespace, es.TargetRef) @@ -195,7 +197,7 @@ func (r *reconciler) resolveEndpointSpec(namespace string, es v1alpha1.EndpointS } if t.Status.Targetable != nil { - return t.Status.Targetable.DomainInternal, nil + return domainToURL(t.Status.Targetable.DomainInternal), nil } return "", fmt.Errorf("status does not contain targetable") } @@ -214,7 +216,7 @@ func (r *reconciler) resolveResult(namespace string, resultStrategy v1alpha1.Res return "", err } if s.Status.Sinkable != nil { - return s.Status.Sinkable.DomainInternal, nil + return domainToURL(s.Status.Sinkable.DomainInternal), nil } return "", fmt.Errorf("status does not contain sinkable") } @@ -230,6 +232,15 @@ func (r *reconciler) fetchObjectReference(namespace string, ref *corev1.ObjectRe return resourceClient.Get(ref.Name, metav1.GetOptions{}) } +func domainToURL(domain string) string { + u := url.URL{ + Scheme: "http", + Host: domain, + Path: "/", + } + return u.String() +} + func (r *reconciler) syncPhysicalFromChannel(sub *v1alpha1.Subscription) error { glog.Infof("Reconciling Physical From Channel: %+v", sub) @@ -286,26 +297,26 @@ func (r *reconciler) listAllSubscriptionsWithPhysicalFrom(sub *v1alpha1.Subscrip } } -func (r *reconciler) createChannelable(subs []v1alpha1.Subscription) *duckv1alpha1.Channelable { - rv := &duckv1alpha1.Channelable{} +func (r *reconciler) createChannelable(subs []v1alpha1.Subscription) *eventingduck.Channelable { + rv := &eventingduck.Channelable{} for _, sub := range subs { - if sub.Status.PhysicalSubscription.CallDomain != "" || sub.Status.PhysicalSubscription.ResultDomain != "" { - rv.Subscribers = append(rv.Subscribers, duckv1alpha1.ChannelSubscriberSpec{ - CallableDomain: sub.Status.PhysicalSubscription.CallDomain, - SinkableDomain: sub.Status.PhysicalSubscription.ResultDomain, + if sub.Status.PhysicalSubscription.CallURI != "" || sub.Status.PhysicalSubscription.ResultURI != "" { + rv.Subscribers = append(rv.Subscribers, eventingduck.ChannelSubscriberSpec{ + CallableURI: sub.Status.PhysicalSubscription.CallURI, + SinkableURI: sub.Status.PhysicalSubscription.ResultURI, }) } } return rv } -func (r *reconciler) patchPhysicalFrom(namespace string, physicalFrom corev1.ObjectReference, subs *duckv1alpha1.Channelable) error { +func (r *reconciler) patchPhysicalFrom(namespace string, physicalFrom corev1.ObjectReference, subs *eventingduck.Channelable) error { // First get the original object and convert it to only the bits we care about s, err := r.fetchObjectReference(namespace, &physicalFrom) if err != nil { return err } - original := duckv1alpha1.Channel{} + original := eventingduck.Channel{} err = duck.FromUnstructured(s, &original) if err != nil { return err diff --git a/pkg/controller/eventing/subscription/reconcile_test.go b/pkg/controller/eventing/subscription/reconcile_test.go index dbc7d036c2d..d8dec2b7f7c 100644 --- a/pkg/controller/eventing/subscription/reconcile_test.go +++ b/pkg/controller/eventing/subscription/reconcile_test.go @@ -20,6 +20,7 @@ import ( "fmt" "testing" + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" controllertesting "github.com/knative/eventing/pkg/controller/testing" duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" @@ -646,8 +647,8 @@ func getNewChannel(name string) *eventingv1alpha1.Channel { func rename(sub *eventingv1alpha1.Subscription) *eventingv1alpha1.Subscription { sub.Name = "renamed" sub.UID = "renamed-UID" - sub.Status.PhysicalSubscription.CallDomain = "" - sub.Status.PhysicalSubscription.ResultDomain = otherSinkableDNS + sub.Status.PhysicalSubscription.CallURI = "" + sub.Status.PhysicalSubscription.ResultURI = otherSinkableDNS return sub } @@ -744,18 +745,17 @@ func getNewSubscriptionWithUnknownConditions() *eventingv1alpha1.Subscription { s.Status.InitializeConditions() return s } - func getNewSubscriptionWithUnknownConditionsAndPhysicalCall() *eventingv1alpha1.Subscription { s := getNewSubscriptionWithUnknownConditions() - s.Status.PhysicalSubscription.CallDomain = targetDNS + s.Status.PhysicalSubscription.CallURI = domainToURL(targetDNS) return s } func getNewSubscriptionWithReferencesResolvedAndPhysicalCallResult() *eventingv1alpha1.Subscription { s := getNewSubscriptionWithUnknownConditions() s.Status.MarkReferencesResolved() - s.Status.PhysicalSubscription.CallDomain = targetDNS - s.Status.PhysicalSubscription.ResultDomain = sinkableDNS + s.Status.PhysicalSubscription.CallURI = domainToURL(targetDNS) + s.Status.PhysicalSubscription.ResultURI = domainToURL(sinkableDNS) return s } @@ -764,8 +764,8 @@ func getNewSubscriptionToK8sServiceWithReferencesResolvedAndPhysicalFromCallResu s.Status.InitializeConditions() s.Status.MarkReferencesResolved() s.Status.PhysicalSubscription = eventingv1alpha1.SubscriptionStatusPhysicalSubscription{ - CallDomain: k8sServiceDNS, - ResultDomain: sinkableDNS, + CallURI: domainToURL(k8sServiceDNS), + ResultURI: domainToURL(sinkableDNS), } return s } @@ -775,8 +775,8 @@ func getNewSubscriptionWithSourceWithReferencesResolvedAndPhysicalFromCallResult s.Status.InitializeConditions() s.Status.MarkReferencesResolved() s.Status.PhysicalSubscription = eventingv1alpha1.SubscriptionStatusPhysicalSubscription{ - CallDomain: targetDNS, - ResultDomain: sinkableDNS, + CallURI: domainToURL(targetDNS), + ResultURI: domainToURL(sinkableDNS), } return s } @@ -791,7 +791,7 @@ func getSubscriptionWithDifferentChannel() *eventingv1alpha1.Subscription { s := getNewSubscriptionWithSourceWithReferencesResolvedAndPhysicalFromCallResult() s.Name = "different-channel" s.UID = "different-channel-UID" - s.Status.PhysicalSubscription.CallDomain = "some-other-domain" + s.Status.PhysicalSubscription.CallURI = "some-other-domain" return s } @@ -830,14 +830,14 @@ func getChannelWithMultipleSubscriptions() *eventingv1alpha1.Channel { }, ObjectMeta: om(testNS, fromChannelName), Spec: eventingv1alpha1.ChannelSpec{ - Channelable: &duckv1alpha1.Channelable{ - Subscribers: []duckv1alpha1.ChannelSubscriberSpec{ + Channelable: &eventingduck.Channelable{ + Subscribers: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: targetDNS, - SinkableDomain: sinkableDNS, + CallableURI: targetDNS, + SinkableURI: sinkableDNS, }, { - SinkableDomain: otherSinkableDNS, + SinkableURI: otherSinkableDNS, }, }, }, diff --git a/pkg/sidecar/configmap/filesystem/filesystem_watcher_test.go b/pkg/sidecar/configmap/filesystem/filesystem_watcher_test.go index f36e3275018..2e54aad92c8 100644 --- a/pkg/sidecar/configmap/filesystem/filesystem_watcher_test.go +++ b/pkg/sidecar/configmap/filesystem/filesystem_watcher_test.go @@ -27,10 +27,10 @@ import ( "time" "github.com/google/go-cmp/cmp" + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" "github.com/knative/eventing/pkg/sidecar/configmap" "github.com/knative/eventing/pkg/sidecar/fanout" "github.com/knative/eventing/pkg/sidecar/multichannelfanout" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" "go.uber.org/zap" yaml "gopkg.in/yaml.v2" ) @@ -83,20 +83,20 @@ func TestReadConfigMap(t *testing.T) { name: c1 fanoutConfig: subscriptions: - - callableDomain: event-changer.default.svc.cluster.local - sinkableDomain: message-dumper-bar.default.svc.cluster.local - - callableDomain: message-dumper-foo.default.svc.cluster.local - - sinkableDomain: message-dumper-bar.default.svc.cluster.local + - callableURI: event-changer.default.svc.cluster.local + sinkableURI: message-dumper-bar.default.svc.cluster.local + - callableURI: message-dumper-foo.default.svc.cluster.local + - sinkableURI: message-dumper-bar.default.svc.cluster.local - namespace: default name: c2 fanoutConfig: subscriptions: - - sinkableDomain: message-dumper-foo.default.svc.cluster.local + - sinkableURI: message-dumper-foo.default.svc.cluster.local - namespace: other name: c3 fanoutConfig: subscriptions: - - sinkableDomain: message-dumper-foo.default.svc.cluster.local + - sinkableURI: message-dumper-foo.default.svc.cluster.local `, expected: &multichannelfanout.Config{ ChannelConfigs: []multichannelfanout.ChannelConfig{ @@ -104,16 +104,16 @@ func TestReadConfigMap(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "event-changer.default.svc.cluster.local", - SinkableDomain: "message-dumper-bar.default.svc.cluster.local", + CallableURI: "event-changer.default.svc.cluster.local", + SinkableURI: "message-dumper-bar.default.svc.cluster.local", }, { - CallableDomain: "message-dumper-foo.default.svc.cluster.local", + CallableURI: "message-dumper-foo.default.svc.cluster.local", }, { - SinkableDomain: "message-dumper-bar.default.svc.cluster.local", + SinkableURI: "message-dumper-bar.default.svc.cluster.local", }, }, }, @@ -122,9 +122,9 @@ func TestReadConfigMap(t *testing.T) { Namespace: "default", Name: "c2", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "message-dumper-foo.default.svc.cluster.local", + SinkableURI: "message-dumper-foo.default.svc.cluster.local", }, }, }, @@ -133,9 +133,9 @@ func TestReadConfigMap(t *testing.T) { Namespace: "other", Name: "c3", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "message-dumper-foo.default.svc.cluster.local", + SinkableURI: "message-dumper-foo.default.svc.cluster.local", }, }, }, @@ -186,9 +186,9 @@ func TestWatch(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "foo.bar", + SinkableURI: "foo.bar", }, }, }, @@ -203,9 +203,9 @@ func TestWatch(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "foo.bar", + SinkableURI: "foo.bar", }, }, }, @@ -221,9 +221,9 @@ func TestWatch(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "foo.bar", + SinkableURI: "foo.bar", }, }, }, @@ -236,9 +236,9 @@ func TestWatch(t *testing.T) { Namespace: "default", Name: "new-channel", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "baz.qux", + CallableURI: "baz.qux", }, }, }, diff --git a/pkg/sidecar/configmap/parse_test.go b/pkg/sidecar/configmap/parse_test.go index 5cddb280b89..135f7620424 100644 --- a/pkg/sidecar/configmap/parse_test.go +++ b/pkg/sidecar/configmap/parse_test.go @@ -17,13 +17,14 @@ limitations under the License. package configmap import ( + "strings" + "testing" + "github.com/google/go-cmp/cmp" + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" "github.com/knative/eventing/pkg/sidecar/fanout" "github.com/knative/eventing/pkg/sidecar/multichannelfanout" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" "go.uber.org/zap" - "strings" - "testing" ) func TestNewFanoutConfig(t *testing.T) { @@ -64,20 +65,20 @@ func TestNewFanoutConfig(t *testing.T) { name: c1 fanoutConfig: subscriptions: - - callableDomain: event-changer.default.svc.cluster.local - sinkableDomain: message-dumper-bar.default.svc.cluster.local - - callableDomain: message-dumper-foo.default.svc.cluster.local - - sinkableDomain: message-dumper-bar.default.svc.cluster.local + - callableURI: event-changer.default.svc.cluster.local + sinkableURI: message-dumper-bar.default.svc.cluster.local + - callableURI: message-dumper-foo.default.svc.cluster.local + - sinkableURI: message-dumper-bar.default.svc.cluster.local - namespace: default name: c2 fanoutConfig: subscriptions: - - sinkableDomain: message-dumper-foo.default.svc.cluster.local + - sinkableURI: message-dumper-foo.default.svc.cluster.local - namespace: other name: c3 fanoutConfig: subscriptions: - - sinkableDomain: message-dumper-foo.default.svc.cluster.local + - sinkableURI: message-dumper-foo.default.svc.cluster.local `, expected: &multichannelfanout.Config{ ChannelConfigs: []multichannelfanout.ChannelConfig{ @@ -85,16 +86,16 @@ func TestNewFanoutConfig(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "event-changer.default.svc.cluster.local", - SinkableDomain: "message-dumper-bar.default.svc.cluster.local", + CallableURI: "event-changer.default.svc.cluster.local", + SinkableURI: "message-dumper-bar.default.svc.cluster.local", }, { - CallableDomain: "message-dumper-foo.default.svc.cluster.local", + CallableURI: "message-dumper-foo.default.svc.cluster.local", }, { - SinkableDomain: "message-dumper-bar.default.svc.cluster.local", + SinkableURI: "message-dumper-bar.default.svc.cluster.local", }, }, }, @@ -103,9 +104,9 @@ func TestNewFanoutConfig(t *testing.T) { Namespace: "default", Name: "c2", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "message-dumper-foo.default.svc.cluster.local", + SinkableURI: "message-dumper-foo.default.svc.cluster.local", }, }, }, @@ -114,9 +115,9 @@ func TestNewFanoutConfig(t *testing.T) { Namespace: "other", Name: "c3", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "message-dumper-foo.default.svc.cluster.local", + SinkableURI: "message-dumper-foo.default.svc.cluster.local", }, }, }, @@ -156,16 +157,16 @@ func TestSerializeConfig(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "foo.example.com", - SinkableDomain: "bar.example.com", + CallableURI: "foo.example.com", + SinkableURI: "bar.example.com", }, { - SinkableDomain: "qux.example.com", + SinkableURI: "qux.example.com", }, { - CallableDomain: "baz.example.com", + CallableURI: "baz.example.com", }, {}, }, @@ -175,7 +176,7 @@ func TestSerializeConfig(t *testing.T) { Namespace: "other", Name: "no-subs", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{}, + Subscriptions: []eventingduck.ChannelSubscriberSpec{}, }, }, }, diff --git a/pkg/sidecar/configmap/watcher/watcher_test.go b/pkg/sidecar/configmap/watcher/watcher_test.go index e6296e5f201..fd92d6e7ed1 100644 --- a/pkg/sidecar/configmap/watcher/watcher_test.go +++ b/pkg/sidecar/configmap/watcher/watcher_test.go @@ -18,16 +18,17 @@ package watcher import ( "errors" + "testing" + "github.com/google/go-cmp/cmp" + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" sidecarconfigmap "github.com/knative/eventing/pkg/sidecar/configmap" "github.com/knative/eventing/pkg/sidecar/fanout" "github.com/knative/eventing/pkg/sidecar/multichannelfanout" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" "github.com/knative/pkg/configmap" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "testing" ) const ( @@ -66,8 +67,8 @@ func TestReconcile(t *testing.T) { namespace: bar fanoutConfig: subscriptions: - - callableDomain: callable - sinkableDomain: sinkable`, + - callableURI: callable + sinkableURI: sinkable`, }, expectedConfig: &multichannelfanout.Config{ ChannelConfigs: []multichannelfanout.ChannelConfig{ @@ -75,10 +76,10 @@ func TestReconcile(t *testing.T) { Name: "foo", Namespace: "bar", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "callable", - SinkableDomain: "sinkable", + CallableURI: "callable", + SinkableURI: "sinkable", }, }, }, diff --git a/pkg/sidecar/fanout/fanout_handler.go b/pkg/sidecar/fanout/fanout_handler.go index 065a10d64f0..48ff82a5988 100644 --- a/pkg/sidecar/fanout/fanout_handler.go +++ b/pkg/sidecar/fanout/fanout_handler.go @@ -26,8 +26,8 @@ import ( "net/http" "time" + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" "github.com/knative/eventing/pkg/buses" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" "go.uber.org/zap" ) @@ -39,7 +39,7 @@ const ( // Configuration for a fanout.Handler. type Config struct { - Subscriptions []duckv1alpha1.ChannelSubscriberSpec `json:"subscriptions"` + Subscriptions []eventingduck.ChannelSubscriberSpec `json:"subscriptions"` } // http.Handler that takes a single request in and fans it out to N other servers. @@ -96,7 +96,7 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (f *Handler) dispatch(msg *buses.Message) error { errorCh := make(chan error, len(f.config.Subscriptions)) for _, sub := range f.config.Subscriptions { - go func(s duckv1alpha1.ChannelSubscriberSpec) { + go func(s eventingduck.ChannelSubscriberSpec) { errorCh <- f.makeFanoutRequest(*msg, s) }(sub) } @@ -119,6 +119,6 @@ func (f *Handler) dispatch(msg *buses.Message) error { // makeFanoutRequest sends the request to exactly one subscription. It handles both the `call` and // the `sink` portions of the subscription. -func (f *Handler) makeFanoutRequest(m buses.Message, sub duckv1alpha1.ChannelSubscriberSpec) error { - return f.dispatcher.DispatchMessage(&m, sub.CallableDomain, sub.SinkableDomain, buses.DispatchDefaults{}) +func (f *Handler) makeFanoutRequest(m buses.Message, sub eventingduck.ChannelSubscriberSpec) error { + return f.dispatcher.DispatchMessage(&m, sub.CallableURI, sub.SinkableURI, buses.DispatchDefaults{}) } diff --git a/pkg/sidecar/fanout/fanout_handler_test.go b/pkg/sidecar/fanout/fanout_handler_test.go index 9bdf020e544..b1d2376a408 100644 --- a/pkg/sidecar/fanout/fanout_handler_test.go +++ b/pkg/sidecar/fanout/fanout_handler_test.go @@ -18,10 +18,6 @@ package fanout import ( "errors" - "github.com/knative/eventing/pkg/buses" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" - "go.uber.org/atomic" - "go.uber.org/zap" "io" "io/ioutil" "net/http" @@ -29,6 +25,11 @@ import ( "strings" "testing" "time" + + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" + "github.com/knative/eventing/pkg/buses" + "go.uber.org/atomic" + "go.uber.org/zap" ) // Domains used in subscriptions, which will be replaced by the real domains of the started HTTP @@ -59,7 +60,7 @@ func TestFanoutHandler_ServeHTTP(t *testing.T) { testCases := map[string]struct { receiverFunc func(buses.ChannelReference, *buses.Message) error timeout time.Duration - subs []duckv1alpha1.ChannelSubscriberSpec + subs []eventingduck.ChannelSubscriberSpec callable func(http.ResponseWriter, *http.Request) sinkable func(http.ResponseWriter, *http.Request) expectedStatus int @@ -72,9 +73,9 @@ func TestFanoutHandler_ServeHTTP(t *testing.T) { }, "fanout times out": { timeout: time.Millisecond, - subs: []duckv1alpha1.ChannelSubscriberSpec{ + subs: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: replaceCallable, + CallableURI: replaceCallable, }, }, callable: func(writer http.ResponseWriter, _ *http.Request) { @@ -84,19 +85,19 @@ func TestFanoutHandler_ServeHTTP(t *testing.T) { expectedStatus: http.StatusInternalServerError, }, "zero subs succeed": { - subs: []duckv1alpha1.ChannelSubscriberSpec{}, + subs: []eventingduck.ChannelSubscriberSpec{}, expectedStatus: http.StatusAccepted, }, "empty sub succeeds": { - subs: []duckv1alpha1.ChannelSubscriberSpec{ + subs: []eventingduck.ChannelSubscriberSpec{ {}, }, expectedStatus: http.StatusAccepted, }, "sinkable fails": { - subs: []duckv1alpha1.ChannelSubscriberSpec{ + subs: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: replaceSinkable, + SinkableURI: replaceSinkable, }, }, sinkable: func(writer http.ResponseWriter, _ *http.Request) { @@ -105,9 +106,9 @@ func TestFanoutHandler_ServeHTTP(t *testing.T) { expectedStatus: http.StatusInternalServerError, }, "callable fails": { - subs: []duckv1alpha1.ChannelSubscriberSpec{ + subs: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: replaceCallable, + CallableURI: replaceCallable, }, }, callable: func(writer http.ResponseWriter, _ *http.Request) { @@ -116,10 +117,10 @@ func TestFanoutHandler_ServeHTTP(t *testing.T) { expectedStatus: http.StatusInternalServerError, }, "callable succeeds, sinkable fails": { - subs: []duckv1alpha1.ChannelSubscriberSpec{ + subs: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: replaceCallable, - SinkableDomain: replaceSinkable, + CallableURI: replaceCallable, + SinkableURI: replaceSinkable, }, }, callable: callableSucceed, @@ -129,10 +130,10 @@ func TestFanoutHandler_ServeHTTP(t *testing.T) { expectedStatus: http.StatusInternalServerError, }, "one sub succeeds": { - subs: []duckv1alpha1.ChannelSubscriberSpec{ + subs: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: replaceCallable, - SinkableDomain: replaceSinkable, + CallableURI: replaceCallable, + SinkableURI: replaceSinkable, }, }, callable: callableSucceed, @@ -142,14 +143,14 @@ func TestFanoutHandler_ServeHTTP(t *testing.T) { expectedStatus: http.StatusAccepted, }, "one sub succeeds, one sub fails": { - subs: []duckv1alpha1.ChannelSubscriberSpec{ + subs: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: replaceCallable, - SinkableDomain: replaceSinkable, + CallableURI: replaceCallable, + SinkableURI: replaceSinkable, }, { - CallableDomain: replaceCallable, - SinkableDomain: replaceSinkable, + CallableURI: replaceCallable, + SinkableURI: replaceSinkable, }, }, callable: callableSucceed, @@ -157,18 +158,18 @@ func TestFanoutHandler_ServeHTTP(t *testing.T) { expectedStatus: http.StatusInternalServerError, }, "all subs succeed": { - subs: []duckv1alpha1.ChannelSubscriberSpec{ + subs: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: replaceCallable, - SinkableDomain: replaceSinkable, + CallableURI: replaceCallable, + SinkableURI: replaceSinkable, }, { - CallableDomain: replaceCallable, - SinkableDomain: replaceSinkable, + CallableURI: replaceCallable, + SinkableURI: replaceSinkable, }, { - CallableDomain: replaceCallable, - SinkableDomain: replaceSinkable, + CallableURI: replaceCallable, + SinkableURI: replaceSinkable, }, }, callable: callableSucceed, @@ -193,13 +194,13 @@ func TestFanoutHandler_ServeHTTP(t *testing.T) { defer sinkableServer.Close() // Rewrite the subs to use the servers we just started. - subs := make([]duckv1alpha1.ChannelSubscriberSpec, 0) + subs := make([]eventingduck.ChannelSubscriberSpec, 0) for _, sub := range tc.subs { - if sub.CallableDomain == replaceCallable { - sub.CallableDomain = callableServer.URL[7:] // strip the leading 'http://' + if sub.CallableURI == replaceCallable { + sub.CallableURI = callableServer.URL[7:] // strip the leading 'http://' } - if sub.SinkableDomain == replaceSinkable { - sub.SinkableDomain = sinkableServer.URL[7:] // strip the leading 'http://' + if sub.SinkableURI == replaceSinkable { + sub.SinkableURI = sinkableServer.URL[7:] // strip the leading 'http://' } subs = append(subs, sub) } diff --git a/pkg/sidecar/multichannelfanout/multi_channel_fanout_handler_test.go b/pkg/sidecar/multichannelfanout/multi_channel_fanout_handler_test.go index 3bc5e6f0faf..82693b0c3a6 100644 --- a/pkg/sidecar/multichannelfanout/multi_channel_fanout_handler_test.go +++ b/pkg/sidecar/multichannelfanout/multi_channel_fanout_handler_test.go @@ -18,14 +18,15 @@ package multichannelfanout import ( "fmt" - "github.com/google/go-cmp/cmp" - "github.com/knative/eventing/pkg/sidecar/fanout" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" - "go.uber.org/zap" "net/http" "net/http/httptest" "strings" "testing" + + "github.com/google/go-cmp/cmp" + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" + "github.com/knative/eventing/pkg/sidecar/fanout" + "go.uber.org/zap" ) const ( @@ -108,9 +109,9 @@ func TestCopyWithNewConfig(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "callabledomain", + CallableURI: "callabledomain", }, }, }, @@ -123,9 +124,9 @@ func TestCopyWithNewConfig(t *testing.T) { Namespace: "default", Name: "somethingdifferent", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "sinkabledomain", + SinkableURI: "sinkabledomain", }, }, }, @@ -161,9 +162,9 @@ func TestConfigDiff(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "callabledomain", + CallableURI: "callabledomain", }, }, }, @@ -191,9 +192,9 @@ func TestConfigDiff(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "different", + CallableURI: "different", }, }, }, @@ -238,9 +239,9 @@ func TestServeHTTP(t *testing.T) { Namespace: "default", Name: "first-channel", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: replaceDomain, + SinkableURI: replaceDomain, }, }, }, @@ -258,9 +259,9 @@ func TestServeHTTP(t *testing.T) { Namespace: "default", Name: "first-channel", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "first-to-domain", + SinkableURI: "first-to-domain", }, }, }, @@ -269,9 +270,9 @@ func TestServeHTTP(t *testing.T) { Namespace: "default", Name: "second-channel", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: replaceDomain, + CallableURI: replaceDomain, }, }, }, @@ -317,11 +318,11 @@ func TestServeHTTP(t *testing.T) { func replaceDomains(config Config, replacement string) { for i, cc := range config.ChannelConfigs { for j, sub := range cc.FanoutConfig.Subscriptions { - if sub.CallableDomain == replaceDomain { - sub.CallableDomain = replacement + if sub.CallableURI == replaceDomain { + sub.CallableURI = replacement } - if sub.SinkableDomain == replaceDomain { - sub.SinkableDomain = replacement + if sub.SinkableURI == replaceDomain { + sub.SinkableURI = replacement } cc.FanoutConfig.Subscriptions[j] = sub } diff --git a/pkg/sidecar/multichannelfanout/parse_test.go b/pkg/sidecar/multichannelfanout/parse_test.go index 568ac7d3391..c510db6b890 100644 --- a/pkg/sidecar/multichannelfanout/parse_test.go +++ b/pkg/sidecar/multichannelfanout/parse_test.go @@ -17,12 +17,13 @@ limitations under the License. package multichannelfanout import ( + "strings" + "testing" + "github.com/google/go-cmp/cmp" + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" "github.com/knative/eventing/pkg/sidecar/fanout" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" "go.uber.org/zap" - "strings" - "testing" ) func TestConfigMapData(t *testing.T) { @@ -33,11 +34,11 @@ func TestConfigMapData(t *testing.T) { expectedErr bool }{ { - name: "no data", - expected: &Config {}, + name: "no data", + expected: &Config{}, }, { - name: "invalid YAML", + name: "invalid YAML", config: ` key: - value @@ -56,27 +57,27 @@ func TestConfigMapData(t *testing.T) { expectedErr: true, }, { - name: "valid", + name: "valid", config: ` channelConfigs: - namespace: default name: c1 fanoutConfig: subscriptions: - - callableDomain: event-changer.default.svc.cluster.local - sinkableDomain: message-dumper-bar.default.svc.cluster.local - - callableDomain: message-dumper-foo.default.svc.cluster.local - - sinkableDomain: message-dumper-bar.default.svc.cluster.local + - callableURI: event-changer.default.svc.cluster.local + sinkableURI: message-dumper-bar.default.svc.cluster.local + - callableURI: message-dumper-foo.default.svc.cluster.local + - sinkableURI: message-dumper-bar.default.svc.cluster.local - namespace: default name: c2 fanoutConfig: subscriptions: - - sinkableDomain: message-dumper-foo.default.svc.cluster.local + - sinkableURI: message-dumper-foo.default.svc.cluster.local - namespace: other name: c3 fanoutConfig: subscriptions: - - sinkableDomain: message-dumper-foo.default.svc.cluster.local + - sinkableURI: message-dumper-foo.default.svc.cluster.local `, expected: &Config{ ChannelConfigs: []ChannelConfig{ @@ -84,16 +85,16 @@ func TestConfigMapData(t *testing.T) { Namespace: "default", Name: "c1", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: "event-changer.default.svc.cluster.local", - SinkableDomain: "message-dumper-bar.default.svc.cluster.local", + CallableURI: "event-changer.default.svc.cluster.local", + SinkableURI: "message-dumper-bar.default.svc.cluster.local", }, { - CallableDomain: "message-dumper-foo.default.svc.cluster.local", + CallableURI: "message-dumper-foo.default.svc.cluster.local", }, { - SinkableDomain: "message-dumper-bar.default.svc.cluster.local", + SinkableURI: "message-dumper-bar.default.svc.cluster.local", }, }, }, @@ -102,9 +103,9 @@ func TestConfigMapData(t *testing.T) { Namespace: "default", Name: "c2", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "message-dumper-foo.default.svc.cluster.local", + SinkableURI: "message-dumper-foo.default.svc.cluster.local", }, }, }, @@ -113,9 +114,9 @@ func TestConfigMapData(t *testing.T) { Namespace: "other", Name: "c3", FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: "message-dumper-foo.default.svc.cluster.local", + SinkableURI: "message-dumper-foo.default.svc.cluster.local", }, }, }, @@ -126,7 +127,9 @@ func TestConfigMapData(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - if tc.name != "valid" { return } + if tc.name != "valid" { + return + } c, e := Parse(zap.NewNop(), formatData(tc.config)) if tc.expectedErr { if e == nil { diff --git a/pkg/sidecar/swappable/swappable_test.go b/pkg/sidecar/swappable/swappable_test.go index 2c663bf800b..13a8b7936f3 100644 --- a/pkg/sidecar/swappable/swappable_test.go +++ b/pkg/sidecar/swappable/swappable_test.go @@ -18,14 +18,15 @@ package swappable import ( "fmt" - "github.com/knative/eventing/pkg/sidecar/fanout" - "github.com/knative/eventing/pkg/sidecar/multichannelfanout" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" - "go.uber.org/zap" "net/http" "net/http/httptest" "strings" "testing" + + eventingduck "github.com/knative/eventing/pkg/apis/duck/v1alpha1" + "github.com/knative/eventing/pkg/sidecar/fanout" + "github.com/knative/eventing/pkg/sidecar/multichannelfanout" + "go.uber.org/zap" ) const ( @@ -46,9 +47,9 @@ func TestHandler(t *testing.T) { Namespace: namespace, Name: name, FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: replaceDomain, + CallableURI: replaceDomain, }, }, }, @@ -61,9 +62,9 @@ func TestHandler(t *testing.T) { Namespace: namespace, Name: name, FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - SinkableDomain: replaceDomain, + SinkableURI: replaceDomain, }, }, }, @@ -98,9 +99,9 @@ func TestHandler_InvalidConfigChange(t *testing.T) { Namespace: namespace, Name: name, FanoutConfig: fanout.Config{ - Subscriptions: []duckv1alpha1.ChannelSubscriberSpec{ + Subscriptions: []eventingduck.ChannelSubscriberSpec{ { - CallableDomain: replaceDomain, + CallableURI: replaceDomain, }, }, }, @@ -203,11 +204,11 @@ func makeRequest(namespace, name string) *http.Request { func replaceDomains(c multichannelfanout.Config, replacement string) multichannelfanout.Config { for i, cc := range c.ChannelConfigs { for j, sub := range cc.FanoutConfig.Subscriptions { - if sub.SinkableDomain == replaceDomain { - sub.SinkableDomain = replacement + if sub.SinkableURI == replaceDomain { + sub.SinkableURI = replacement } - if sub.CallableDomain == replaceDomain { - sub.CallableDomain = replacement + if sub.CallableURI == replaceDomain { + sub.CallableURI = replacement } cc.FanoutConfig.Subscriptions[j] = sub }