From 50856438bfcee8d248c67b00f1b16acd4b54ad1d Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Wed, 30 May 2018 18:08:38 -0400 Subject: [PATCH 01/21] Import Broker, Stream and Subscriptions CRDs - and Istio RouteRule CRD - generate go client for new CRDs --- config/broker.yaml | 12 + config/stream.yaml | 12 + config/subscription.yaml | 12 + hack/update-codegen.sh | 2 +- pkg/apis/eventing/v1alpha1/broker_types.go | 54 +++ pkg/apis/eventing/v1alpha1/register.go | 6 + pkg/apis/eventing/v1alpha1/stream_types.go | 54 +++ .../eventing/v1alpha1/subscription_types.go | 63 ++++ .../v1alpha1/zz_generated.deepcopy.go | 341 ++++++++++++++++++ pkg/apis/istio/register.go | 23 ++ pkg/apis/istio/v1alpha2/doc.go | 20 + pkg/apis/istio/v1alpha2/register.go | 56 +++ pkg/apis/istio/v1alpha2/routerule.go | 72 ++++ .../istio/v1alpha2/zz_generated.deepcopy.go | 182 ++++++++++ .../istio/v1alpha2/zz_generated.defaults.go | 32 ++ pkg/client/clientset/versioned/clientset.go | 22 ++ .../versioned/fake/clientset_generated.go | 12 + .../clientset/versioned/fake/register.go | 2 + .../clientset/versioned/scheme/register.go | 2 + .../typed/eventing/v1alpha1/broker.go | 157 ++++++++ .../eventing/v1alpha1/eventing_client.go | 15 + .../eventing/v1alpha1/fake/fake_broker.go | 128 +++++++ .../v1alpha1/fake/fake_eventing_client.go | 12 + .../eventing/v1alpha1/fake/fake_stream.go | 128 +++++++ .../v1alpha1/fake/fake_subscription.go | 128 +++++++ .../eventing/v1alpha1/generated_expansion.go | 6 + .../typed/eventing/v1alpha1/stream.go | 157 ++++++++ .../typed/eventing/v1alpha1/subscription.go | 157 ++++++++ .../versioned/typed/istio/v1alpha2/doc.go | 20 + .../typed/istio/v1alpha2/fake/doc.go | 20 + .../istio/v1alpha2/fake/fake_istio_client.go | 40 ++ .../istio/v1alpha2/fake/fake_routerule.go | 128 +++++++ .../istio/v1alpha2/generated_expansion.go | 21 ++ .../typed/istio/v1alpha2/istio_client.go | 90 +++++ .../typed/istio/v1alpha2/routerule.go | 157 ++++++++ .../eventing/v1alpha1/broker.go | 89 +++++ .../eventing/v1alpha1/interface.go | 21 ++ .../eventing/v1alpha1/stream.go | 89 +++++ .../eventing/v1alpha1/subscription.go | 89 +++++ .../informers/externalversions/factory.go | 6 + .../informers/externalversions/generic.go | 13 +- .../externalversions/istio/interface.go | 46 +++ .../istio/v1alpha2/interface.go | 45 +++ .../istio/v1alpha2/routerule.go | 89 +++++ .../listers/eventing/v1alpha1/broker.go | 94 +++++ .../eventing/v1alpha1/expansion_generated.go | 24 ++ .../listers/eventing/v1alpha1/stream.go | 94 +++++ .../listers/eventing/v1alpha1/subscription.go | 94 +++++ .../istio/v1alpha2/expansion_generated.go | 27 ++ .../listers/istio/v1alpha2/routerule.go | 94 +++++ 50 files changed, 3255 insertions(+), 2 deletions(-) create mode 100644 config/broker.yaml create mode 100644 config/stream.yaml create mode 100644 config/subscription.yaml create mode 100644 pkg/apis/eventing/v1alpha1/broker_types.go create mode 100644 pkg/apis/eventing/v1alpha1/stream_types.go create mode 100644 pkg/apis/eventing/v1alpha1/subscription_types.go create mode 100644 pkg/apis/istio/register.go create mode 100644 pkg/apis/istio/v1alpha2/doc.go create mode 100644 pkg/apis/istio/v1alpha2/register.go create mode 100644 pkg/apis/istio/v1alpha2/routerule.go create mode 100644 pkg/apis/istio/v1alpha2/zz_generated.deepcopy.go create mode 100644 pkg/apis/istio/v1alpha2/zz_generated.defaults.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/broker.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_broker.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_stream.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_subscription.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/stream.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/subscription.go create mode 100644 pkg/client/clientset/versioned/typed/istio/v1alpha2/doc.go create mode 100644 pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/doc.go create mode 100644 pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/fake_istio_client.go create mode 100644 pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/fake_routerule.go create mode 100644 pkg/client/clientset/versioned/typed/istio/v1alpha2/generated_expansion.go create mode 100644 pkg/client/clientset/versioned/typed/istio/v1alpha2/istio_client.go create mode 100644 pkg/client/clientset/versioned/typed/istio/v1alpha2/routerule.go create mode 100644 pkg/client/informers/externalversions/eventing/v1alpha1/broker.go create mode 100644 pkg/client/informers/externalversions/eventing/v1alpha1/stream.go create mode 100644 pkg/client/informers/externalversions/eventing/v1alpha1/subscription.go create mode 100644 pkg/client/informers/externalversions/istio/interface.go create mode 100644 pkg/client/informers/externalversions/istio/v1alpha2/interface.go create mode 100644 pkg/client/informers/externalversions/istio/v1alpha2/routerule.go create mode 100644 pkg/client/listers/eventing/v1alpha1/broker.go create mode 100644 pkg/client/listers/eventing/v1alpha1/stream.go create mode 100644 pkg/client/listers/eventing/v1alpha1/subscription.go create mode 100644 pkg/client/listers/istio/v1alpha2/expansion_generated.go create mode 100644 pkg/client/listers/istio/v1alpha2/routerule.go diff --git a/config/broker.yaml b/config/broker.yaml new file mode 100644 index 00000000000..b40dd0a3a57 --- /dev/null +++ b/config/broker.yaml @@ -0,0 +1,12 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: brokers.eventing.knative.dev +spec: + scope: Namespaced + group: eventing.knative.dev + version: v1alpha1 + names: + kind: Broker + plural: brokers + singular: broker diff --git a/config/stream.yaml b/config/stream.yaml new file mode 100644 index 00000000000..5a578cd6d64 --- /dev/null +++ b/config/stream.yaml @@ -0,0 +1,12 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: streams.eventing.knative.dev +spec: + scope: Namespaced + group: eventing.knative.dev + version: v1alpha1 + names: + kind: Stream + plural: streams + singular: stream diff --git a/config/subscription.yaml b/config/subscription.yaml new file mode 100644 index 00000000000..fa4cd57bd9f --- /dev/null +++ b/config/subscription.yaml @@ -0,0 +1,12 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: subscriptions.eventing.knative.dev +spec: + scope: Namespaced + group: eventing.knative.dev + version: v1alpha1 + names: + kind: Subscription + plural: subscriptions + singular: subscription diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 2469d497340..ad815b7d42d 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -27,7 +27,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-ge # instead of the $GOPATH directly. For normal projects this can be dropped. ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \ github.com/knative/eventing/pkg/client github.com/knative/eventing/pkg/apis \ - eventing:v1alpha1 \ + "eventing:v1alpha1 istio:v1alpha2" \ --go-header-file ${SCRIPT_ROOT}/hack/boilerplate/boilerplate.go.txt # Make sure our dependencies are up-to-date diff --git a/pkg/apis/eventing/v1alpha1/broker_types.go b/pkg/apis/eventing/v1alpha1/broker_types.go new file mode 100644 index 00000000000..1b87a0e6b78 --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/broker_types.go @@ -0,0 +1,54 @@ +/* + * Copyright 2018 the original author or 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 ( + kapi "k8s.io/api/core/v1" + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +k8s:defaulter-gen=true + +// Represents the brokers.eventing.dev CRD +type Broker struct { + meta_v1.TypeMeta `json:",inline"` + meta_v1.ObjectMeta `json:"metadata"` + Spec BrokerSpec `json:"spec"` + Status *BrokerStatus `json:"status,omitempty"` +} + +// Spec (what the user wants) for a broker +type BrokerSpec struct { + // Container definition to use for the broker. + Container kapi.Container `json:"container"` +} + +// Status (computed) for a broker +type BrokerStatus struct { +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Returned in list operations +type BrokerList struct { + meta_v1.TypeMeta `json:",inline"` + meta_v1.ListMeta `json:"metadata"` + Items []Broker `json:"items"` +} diff --git a/pkg/apis/eventing/v1alpha1/register.go b/pkg/apis/eventing/v1alpha1/register.go index 4434acff701..06cb83f374f 100644 --- a/pkg/apis/eventing/v1alpha1/register.go +++ b/pkg/apis/eventing/v1alpha1/register.go @@ -47,10 +47,16 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Bind{}, &BindList{}, + &Broker{}, + &BrokerList{}, &EventSource{}, &EventSourceList{}, &EventType{}, &EventTypeList{}, + &Stream{}, + &StreamList{}, + &Subscription{}, + &SubscriptionList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/apis/eventing/v1alpha1/stream_types.go b/pkg/apis/eventing/v1alpha1/stream_types.go new file mode 100644 index 00000000000..0fb16a31e91 --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/stream_types.go @@ -0,0 +1,54 @@ +/* + * Copyright 2018 the original author or 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 ( + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +k8s:defaulter-gen=true + +// Represents the streams.eventing.dev CRD +type Stream struct { + meta_v1.TypeMeta `json:",inline"` + meta_v1.ObjectMeta `json:"metadata"` + Spec StreamSpec `json:"spec"` + Status *StreamStatus `json:"status,omitempty"` +} + +// Spec (what the user wants) for a stream +type StreamSpec struct { + + // Name of the broker backing this stream (optional) + Broker string +} + +// Status (computed) for a stream +type StreamStatus struct { +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Returned in list operations +type StreamList struct { + meta_v1.TypeMeta `json:",inline"` + meta_v1.ListMeta `json:"metadata"` + Items []Stream `json:"items"` +} diff --git a/pkg/apis/eventing/v1alpha1/subscription_types.go b/pkg/apis/eventing/v1alpha1/subscription_types.go new file mode 100644 index 00000000000..0760a08c48a --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/subscription_types.go @@ -0,0 +1,63 @@ +/* + * Copyright 2018 the original author or 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 ( + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +k8s:defaulter-gen=true + +// Represents the subscriptions.eventing.dev CRD +type Subscription struct { + meta_v1.TypeMeta `json:",inline"` + meta_v1.ObjectMeta `json:"metadata"` + Spec SubscriptionSpec `json:"spec"` + Status *SubscriptionStatus `json:"status,omitempty"` +} + +// Spec (what the user wants) for a subscription +type SubscriptionSpec struct { + + // Name of the stream to subscribe to + Stream string `json:"stream"` + + // Name of the subscriber service + Subscriber string `json:"subscriber"` + + // Parameters for the subscription + Params *SubscriptionParams `json:"params,omitempty"` +} + +// Params (key-value pairs) for a subscription +type SubscriptionParams map[string]string + +// Status (computed) for a subscription +type SubscriptionStatus struct { +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Returned in list operations +type SubscriptionList struct { + meta_v1.TypeMeta `json:",inline"` + meta_v1.ListMeta `json:"metadata"` + Items []Subscription `json:"items"` +} diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index 4167f637307..63ecaf8a580 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -165,6 +165,108 @@ func (in *BindStatus) DeepCopy() *BindStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Broker) DeepCopyInto(out *Broker) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + if in.Status != nil { + in, out := &in.Status, &out.Status + if *in == nil { + *out = nil + } else { + *out = new(BrokerStatus) + **out = **in + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Broker. +func (in *Broker) DeepCopy() *Broker { + if in == nil { + return nil + } + out := new(Broker) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Broker) 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 *BrokerList) DeepCopyInto(out *BrokerList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Broker, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerList. +func (in *BrokerList) DeepCopy() *BrokerList { + if in == nil { + return nil + } + out := new(BrokerList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BrokerList) 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 *BrokerSpec) DeepCopyInto(out *BrokerSpec) { + *out = *in + in.Container.DeepCopyInto(&out.Container) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerSpec. +func (in *BrokerSpec) DeepCopy() *BrokerSpec { + if in == nil { + return nil + } + out := new(BrokerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BrokerStatus) DeepCopyInto(out *BrokerStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerStatus. +func (in *BrokerStatus) DeepCopy() *BrokerStatus { + if in == nil { + return nil + } + out := new(BrokerStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EventSource) DeepCopyInto(out *EventSource) { *out = *in @@ -492,3 +594,242 @@ func (in *SecretKeyReference) DeepCopy() *SecretKeyReference { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Stream) DeepCopyInto(out *Stream) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + if in.Status != nil { + in, out := &in.Status, &out.Status + if *in == nil { + *out = nil + } else { + *out = new(StreamStatus) + **out = **in + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Stream. +func (in *Stream) DeepCopy() *Stream { + if in == nil { + return nil + } + out := new(Stream) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Stream) 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 *StreamList) DeepCopyInto(out *StreamList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Stream, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StreamList. +func (in *StreamList) DeepCopy() *StreamList { + if in == nil { + return nil + } + out := new(StreamList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *StreamList) 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 *StreamSpec) DeepCopyInto(out *StreamSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StreamSpec. +func (in *StreamSpec) DeepCopy() *StreamSpec { + if in == nil { + return nil + } + out := new(StreamSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *StreamStatus) DeepCopyInto(out *StreamStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StreamStatus. +func (in *StreamStatus) DeepCopy() *StreamStatus { + if in == nil { + return nil + } + out := new(StreamStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Subscription) DeepCopyInto(out *Subscription) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + if in.Status != nil { + in, out := &in.Status, &out.Status + if *in == nil { + *out = nil + } else { + *out = new(SubscriptionStatus) + **out = **in + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Subscription. +func (in *Subscription) DeepCopy() *Subscription { + if in == nil { + return nil + } + out := new(Subscription) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Subscription) 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 *SubscriptionList) DeepCopyInto(out *SubscriptionList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Subscription, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionList. +func (in *SubscriptionList) DeepCopy() *SubscriptionList { + if in == nil { + return nil + } + out := new(SubscriptionList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SubscriptionList) 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 SubscriptionParams) DeepCopyInto(out *SubscriptionParams) { + { + in := &in + *out = make(SubscriptionParams, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + return + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionParams. +func (in SubscriptionParams) DeepCopy() SubscriptionParams { + if in == nil { + return nil + } + out := new(SubscriptionParams) + in.DeepCopyInto(out) + return *out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SubscriptionSpec) DeepCopyInto(out *SubscriptionSpec) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + if *in == nil { + *out = nil + } else { + *out = new(SubscriptionParams) + if **in != nil { + in, out := *in, *out + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionSpec. +func (in *SubscriptionSpec) DeepCopy() *SubscriptionSpec { + if in == nil { + return nil + } + out := new(SubscriptionSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SubscriptionStatus) DeepCopyInto(out *SubscriptionStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionStatus. +func (in *SubscriptionStatus) DeepCopy() *SubscriptionStatus { + if in == nil { + return nil + } + out := new(SubscriptionStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/istio/register.go b/pkg/apis/istio/register.go new file mode 100644 index 00000000000..5150162b9d0 --- /dev/null +++ b/pkg/apis/istio/register.go @@ -0,0 +1,23 @@ +/* + * Copyright 2018 the original author or 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 istio + +// TODO remove package after elafros/elafros#1002 + +const ( + GroupName = "config.istio.io" +) diff --git a/pkg/apis/istio/v1alpha2/doc.go b/pkg/apis/istio/v1alpha2/doc.go new file mode 100644 index 00000000000..424f9e1233d --- /dev/null +++ b/pkg/apis/istio/v1alpha2/doc.go @@ -0,0 +1,20 @@ +/* + * Copyright 2018 the original author or 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. + */ + +// +k8s:deepcopy-gen=package +// HACK to enable k8s go client for RouteRule resources +// +groupName=config.istio.io +package v1alpha2 diff --git a/pkg/apis/istio/v1alpha2/register.go b/pkg/apis/istio/v1alpha2/register.go new file mode 100644 index 00000000000..d65eae0097d --- /dev/null +++ b/pkg/apis/istio/v1alpha2/register.go @@ -0,0 +1,56 @@ +/* + * Copyright 2018 the original author or 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 v1alpha2 + +import ( + "github.com/knative/eventing/pkg/apis/istio" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: istio.GroupName, Version: "v1alpha2"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. + SchemeBuilder runtime.SchemeBuilder + localSchemeBuilder = &SchemeBuilder + AddToScheme = localSchemeBuilder.AddToScheme +) + +func init() { + // We only register manually written functions here. The registration of the + // generated functions takes place in the generated files. The separation + // makes the code compile even when the generated files are missing. + localSchemeBuilder.Register(addKnownTypes) +} + +// Adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &RouteRule{}, + &RouteRuleList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/istio/v1alpha2/routerule.go b/pkg/apis/istio/v1alpha2/routerule.go new file mode 100644 index 00000000000..3656dd1e42b --- /dev/null +++ b/pkg/apis/istio/v1alpha2/routerule.go @@ -0,0 +1,72 @@ +/* + * Copyright 2018 the original author or 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 v1alpha2 + +import ( + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +k8s:defaulter-gen=true + +// RouteRule HACK +type RouteRule struct { + meta_v1.TypeMeta `json:",inline"` + meta_v1.ObjectMeta `json:"metadata"` + Spec RouteRuleSpec `json:"spec"` + Status *RouteRuleStatus `json:"status,omitempty"` +} + +// RouteRuleSpec HACK +type RouteRuleSpec struct { + Destination IstioService `json:"destination"` + Route []DestinationWeight `json:"route"` + Rewrite HTTPRewrite `json:"rewrite"` +} + +// IstioService HACK +type IstioService struct { + Domain string `json:"domain"` + Name string `json:"name"` + Namespace string `json:"namespace"` +} + +// DestinationWeight HACK +type DestinationWeight struct { + Destination IstioService `json:"destination"` + Weight int32 `json:"weight"` +} + +// HTTPRewrite HACK +type HTTPRewrite struct { + Authority string `json:"authority"` +} + +// RouteRuleStatus HACK +type RouteRuleStatus struct { +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// HACK +type RouteRuleList struct { + meta_v1.TypeMeta `json:",inline"` + meta_v1.ListMeta `json:"metadata"` + Items []RouteRule `json:"items"` +} diff --git a/pkg/apis/istio/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/istio/v1alpha2/zz_generated.deepcopy.go new file mode 100644 index 00000000000..c66ed208c91 --- /dev/null +++ b/pkg/apis/istio/v1alpha2/zz_generated.deepcopy.go @@ -0,0 +1,182 @@ +// +build !ignore_autogenerated + +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 v1alpha2 + +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 *DestinationWeight) DeepCopyInto(out *DestinationWeight) { + *out = *in + out.Destination = in.Destination + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DestinationWeight. +func (in *DestinationWeight) DeepCopy() *DestinationWeight { + if in == nil { + return nil + } + out := new(DestinationWeight) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HTTPRewrite) DeepCopyInto(out *HTTPRewrite) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPRewrite. +func (in *HTTPRewrite) DeepCopy() *HTTPRewrite { + if in == nil { + return nil + } + out := new(HTTPRewrite) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IstioService) DeepCopyInto(out *IstioService) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IstioService. +func (in *IstioService) DeepCopy() *IstioService { + if in == nil { + return nil + } + out := new(IstioService) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RouteRule) DeepCopyInto(out *RouteRule) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + if in.Status != nil { + in, out := &in.Status, &out.Status + if *in == nil { + *out = nil + } else { + *out = new(RouteRuleStatus) + **out = **in + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteRule. +func (in *RouteRule) DeepCopy() *RouteRule { + if in == nil { + return nil + } + out := new(RouteRule) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RouteRule) 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 *RouteRuleList) DeepCopyInto(out *RouteRuleList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]RouteRule, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteRuleList. +func (in *RouteRuleList) DeepCopy() *RouteRuleList { + if in == nil { + return nil + } + out := new(RouteRuleList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RouteRuleList) 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 *RouteRuleSpec) DeepCopyInto(out *RouteRuleSpec) { + *out = *in + out.Destination = in.Destination + if in.Route != nil { + in, out := &in.Route, &out.Route + *out = make([]DestinationWeight, len(*in)) + copy(*out, *in) + } + out.Rewrite = in.Rewrite + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteRuleSpec. +func (in *RouteRuleSpec) DeepCopy() *RouteRuleSpec { + if in == nil { + return nil + } + out := new(RouteRuleSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RouteRuleStatus) DeepCopyInto(out *RouteRuleStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteRuleStatus. +func (in *RouteRuleStatus) DeepCopy() *RouteRuleStatus { + if in == nil { + return nil + } + out := new(RouteRuleStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/istio/v1alpha2/zz_generated.defaults.go b/pkg/apis/istio/v1alpha2/zz_generated.defaults.go new file mode 100644 index 00000000000..58996627546 --- /dev/null +++ b/pkg/apis/istio/v1alpha2/zz_generated.defaults.go @@ -0,0 +1,32 @@ +// +build !ignore_autogenerated + +/* + * Copyright 2018 the original author or 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. + */ + +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +package v1alpha2 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + return nil +} diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index 1eca9646858..5943ee427d5 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -21,6 +21,7 @@ package versioned import ( glog "github.com/golang/glog" eventingv1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1" + configv1alpha2 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/istio/v1alpha2" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -31,6 +32,9 @@ type Interface interface { EventingV1alpha1() eventingv1alpha1.EventingV1alpha1Interface // Deprecated: please explicitly pick a version if possible. Eventing() eventingv1alpha1.EventingV1alpha1Interface + ConfigV1alpha2() configv1alpha2.ConfigV1alpha2Interface + // Deprecated: please explicitly pick a version if possible. + Config() configv1alpha2.ConfigV1alpha2Interface } // Clientset contains the clients for groups. Each group has exactly one @@ -38,6 +42,7 @@ type Interface interface { type Clientset struct { *discovery.DiscoveryClient eventingV1alpha1 *eventingv1alpha1.EventingV1alpha1Client + configV1alpha2 *configv1alpha2.ConfigV1alpha2Client } // EventingV1alpha1 retrieves the EventingV1alpha1Client @@ -51,6 +56,17 @@ func (c *Clientset) Eventing() eventingv1alpha1.EventingV1alpha1Interface { return c.eventingV1alpha1 } +// ConfigV1alpha2 retrieves the ConfigV1alpha2Client +func (c *Clientset) ConfigV1alpha2() configv1alpha2.ConfigV1alpha2Interface { + return c.configV1alpha2 +} + +// Deprecated: Config retrieves the default version of ConfigClient. +// Please explicitly pick a version. +func (c *Clientset) Config() configv1alpha2.ConfigV1alpha2Interface { + return c.configV1alpha2 +} + // Discovery retrieves the DiscoveryClient func (c *Clientset) Discovery() discovery.DiscoveryInterface { if c == nil { @@ -71,6 +87,10 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { if err != nil { return nil, err } + cs.configV1alpha2, err = configv1alpha2.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) if err != nil { @@ -85,6 +105,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { func NewForConfigOrDie(c *rest.Config) *Clientset { var cs Clientset cs.eventingV1alpha1 = eventingv1alpha1.NewForConfigOrDie(c) + cs.configV1alpha2 = configv1alpha2.NewForConfigOrDie(c) cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) return &cs @@ -94,6 +115,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { func New(c rest.Interface) *Clientset { var cs Clientset cs.eventingV1alpha1 = eventingv1alpha1.New(c) + cs.configV1alpha2 = configv1alpha2.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index 3f19c238882..dd641224c41 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -22,6 +22,8 @@ import ( clientset "github.com/knative/eventing/pkg/client/clientset/versioned" eventingv1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1" fakeeventingv1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake" + configv1alpha2 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/istio/v1alpha2" + fakeconfigv1alpha2 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" @@ -79,3 +81,13 @@ func (c *Clientset) EventingV1alpha1() eventingv1alpha1.EventingV1alpha1Interfac func (c *Clientset) Eventing() eventingv1alpha1.EventingV1alpha1Interface { return &fakeeventingv1alpha1.FakeEventingV1alpha1{Fake: &c.Fake} } + +// ConfigV1alpha2 retrieves the ConfigV1alpha2Client +func (c *Clientset) ConfigV1alpha2() configv1alpha2.ConfigV1alpha2Interface { + return &fakeconfigv1alpha2.FakeConfigV1alpha2{Fake: &c.Fake} +} + +// Config retrieves the ConfigV1alpha2Client +func (c *Clientset) Config() configv1alpha2.ConfigV1alpha2Interface { + return &fakeconfigv1alpha2.FakeConfigV1alpha2{Fake: &c.Fake} +} diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index cb689bbac07..8c194421e54 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -20,6 +20,7 @@ package fake import ( eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + configv1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -51,4 +52,5 @@ func init() { // correctly. func AddToScheme(scheme *runtime.Scheme) { eventingv1alpha1.AddToScheme(scheme) + configv1alpha2.AddToScheme(scheme) } diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 139d97c28ba..d8de07afe8b 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -20,6 +20,7 @@ package scheme import ( eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + configv1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -51,4 +52,5 @@ func init() { // correctly. func AddToScheme(scheme *runtime.Scheme) { eventingv1alpha1.AddToScheme(scheme) + configv1alpha2.AddToScheme(scheme) } diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/broker.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/broker.go new file mode 100644 index 00000000000..5e1723031ba --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/broker.go @@ -0,0 +1,157 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// BrokersGetter has a method to return a BrokerInterface. +// A group's client should implement this interface. +type BrokersGetter interface { + Brokers(namespace string) BrokerInterface +} + +// BrokerInterface has methods to work with Broker resources. +type BrokerInterface interface { + Create(*v1alpha1.Broker) (*v1alpha1.Broker, error) + Update(*v1alpha1.Broker) (*v1alpha1.Broker, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.Broker, error) + List(opts v1.ListOptions) (*v1alpha1.BrokerList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Broker, err error) + BrokerExpansion +} + +// brokers implements BrokerInterface +type brokers struct { + client rest.Interface + ns string +} + +// newBrokers returns a Brokers +func newBrokers(c *EventingV1alpha1Client, namespace string) *brokers { + return &brokers{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the broker, and returns the corresponding broker object, and an error if there is any. +func (c *brokers) Get(name string, options v1.GetOptions) (result *v1alpha1.Broker, err error) { + result = &v1alpha1.Broker{} + err = c.client.Get(). + Namespace(c.ns). + Resource("brokers"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Brokers that match those selectors. +func (c *brokers) List(opts v1.ListOptions) (result *v1alpha1.BrokerList, err error) { + result = &v1alpha1.BrokerList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("brokers"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested brokers. +func (c *brokers) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("brokers"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a broker and creates it. Returns the server's representation of the broker, and an error, if there is any. +func (c *brokers) Create(broker *v1alpha1.Broker) (result *v1alpha1.Broker, err error) { + result = &v1alpha1.Broker{} + err = c.client.Post(). + Namespace(c.ns). + Resource("brokers"). + Body(broker). + Do(). + Into(result) + return +} + +// Update takes the representation of a broker and updates it. Returns the server's representation of the broker, and an error, if there is any. +func (c *brokers) Update(broker *v1alpha1.Broker) (result *v1alpha1.Broker, err error) { + result = &v1alpha1.Broker{} + err = c.client.Put(). + Namespace(c.ns). + Resource("brokers"). + Name(broker.Name). + Body(broker). + Do(). + Into(result) + return +} + +// Delete takes name of the broker and deletes it. Returns an error if one occurs. +func (c *brokers) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("brokers"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *brokers) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("brokers"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched broker. +func (c *brokers) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Broker, err error) { + result = &v1alpha1.Broker{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("brokers"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go index 0e91f1419bd..eeeb1290c98 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go @@ -28,8 +28,11 @@ import ( type EventingV1alpha1Interface interface { RESTClient() rest.Interface BindsGetter + BrokersGetter EventSourcesGetter EventTypesGetter + StreamsGetter + SubscriptionsGetter } // EventingV1alpha1Client is used to interact with features provided by the eventing.knative.dev group. @@ -41,6 +44,10 @@ func (c *EventingV1alpha1Client) Binds(namespace string) BindInterface { return newBinds(c, namespace) } +func (c *EventingV1alpha1Client) Brokers(namespace string) BrokerInterface { + return newBrokers(c, namespace) +} + func (c *EventingV1alpha1Client) EventSources(namespace string) EventSourceInterface { return newEventSources(c, namespace) } @@ -49,6 +56,14 @@ func (c *EventingV1alpha1Client) EventTypes(namespace string) EventTypeInterface return newEventTypes(c, namespace) } +func (c *EventingV1alpha1Client) Streams(namespace string) StreamInterface { + return newStreams(c, namespace) +} + +func (c *EventingV1alpha1Client) Subscriptions(namespace string) SubscriptionInterface { + return newSubscriptions(c, namespace) +} + // NewForConfig creates a new EventingV1alpha1Client for the given config. func NewForConfig(c *rest.Config) (*EventingV1alpha1Client, error) { config := *c diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_broker.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_broker.go new file mode 100644 index 00000000000..d1bc9c8b5b0 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_broker.go @@ -0,0 +1,128 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeBrokers implements BrokerInterface +type FakeBrokers struct { + Fake *FakeEventingV1alpha1 + ns string +} + +var brokersResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "brokers"} + +var brokersKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Broker"} + +// Get takes name of the broker, and returns the corresponding broker object, and an error if there is any. +func (c *FakeBrokers) Get(name string, options v1.GetOptions) (result *v1alpha1.Broker, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(brokersResource, c.ns, name), &v1alpha1.Broker{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Broker), err +} + +// List takes label and field selectors, and returns the list of Brokers that match those selectors. +func (c *FakeBrokers) List(opts v1.ListOptions) (result *v1alpha1.BrokerList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(brokersResource, brokersKind, c.ns, opts), &v1alpha1.BrokerList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.BrokerList{} + for _, item := range obj.(*v1alpha1.BrokerList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested brokers. +func (c *FakeBrokers) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(brokersResource, c.ns, opts)) + +} + +// Create takes the representation of a broker and creates it. Returns the server's representation of the broker, and an error, if there is any. +func (c *FakeBrokers) Create(broker *v1alpha1.Broker) (result *v1alpha1.Broker, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(brokersResource, c.ns, broker), &v1alpha1.Broker{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Broker), err +} + +// Update takes the representation of a broker and updates it. Returns the server's representation of the broker, and an error, if there is any. +func (c *FakeBrokers) Update(broker *v1alpha1.Broker) (result *v1alpha1.Broker, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(brokersResource, c.ns, broker), &v1alpha1.Broker{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Broker), err +} + +// Delete takes name of the broker and deletes it. Returns an error if one occurs. +func (c *FakeBrokers) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(brokersResource, c.ns, name), &v1alpha1.Broker{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeBrokers) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(brokersResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.BrokerList{}) + return err +} + +// Patch applies the patch and returns the patched broker. +func (c *FakeBrokers) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Broker, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(brokersResource, c.ns, name, data, subresources...), &v1alpha1.Broker{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Broker), err +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go index 4ae3da7e3d8..b8ea29cb152 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go @@ -32,6 +32,10 @@ func (c *FakeEventingV1alpha1) Binds(namespace string) v1alpha1.BindInterface { return &FakeBinds{c, namespace} } +func (c *FakeEventingV1alpha1) Brokers(namespace string) v1alpha1.BrokerInterface { + return &FakeBrokers{c, namespace} +} + func (c *FakeEventingV1alpha1) EventSources(namespace string) v1alpha1.EventSourceInterface { return &FakeEventSources{c, namespace} } @@ -40,6 +44,14 @@ func (c *FakeEventingV1alpha1) EventTypes(namespace string) v1alpha1.EventTypeIn return &FakeEventTypes{c, namespace} } +func (c *FakeEventingV1alpha1) Streams(namespace string) v1alpha1.StreamInterface { + return &FakeStreams{c, namespace} +} + +func (c *FakeEventingV1alpha1) Subscriptions(namespace string) v1alpha1.SubscriptionInterface { + return &FakeSubscriptions{c, namespace} +} + // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeEventingV1alpha1) RESTClient() rest.Interface { diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_stream.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_stream.go new file mode 100644 index 00000000000..3b4d5c50ec4 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_stream.go @@ -0,0 +1,128 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeStreams implements StreamInterface +type FakeStreams struct { + Fake *FakeEventingV1alpha1 + ns string +} + +var streamsResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "streams"} + +var streamsKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Stream"} + +// Get takes name of the stream, and returns the corresponding stream object, and an error if there is any. +func (c *FakeStreams) Get(name string, options v1.GetOptions) (result *v1alpha1.Stream, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(streamsResource, c.ns, name), &v1alpha1.Stream{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Stream), err +} + +// List takes label and field selectors, and returns the list of Streams that match those selectors. +func (c *FakeStreams) List(opts v1.ListOptions) (result *v1alpha1.StreamList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(streamsResource, streamsKind, c.ns, opts), &v1alpha1.StreamList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.StreamList{} + for _, item := range obj.(*v1alpha1.StreamList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested streams. +func (c *FakeStreams) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(streamsResource, c.ns, opts)) + +} + +// Create takes the representation of a stream and creates it. Returns the server's representation of the stream, and an error, if there is any. +func (c *FakeStreams) Create(stream *v1alpha1.Stream) (result *v1alpha1.Stream, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(streamsResource, c.ns, stream), &v1alpha1.Stream{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Stream), err +} + +// Update takes the representation of a stream and updates it. Returns the server's representation of the stream, and an error, if there is any. +func (c *FakeStreams) Update(stream *v1alpha1.Stream) (result *v1alpha1.Stream, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(streamsResource, c.ns, stream), &v1alpha1.Stream{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Stream), err +} + +// Delete takes name of the stream and deletes it. Returns an error if one occurs. +func (c *FakeStreams) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(streamsResource, c.ns, name), &v1alpha1.Stream{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeStreams) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(streamsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.StreamList{}) + return err +} + +// Patch applies the patch and returns the patched stream. +func (c *FakeStreams) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Stream, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(streamsResource, c.ns, name, data, subresources...), &v1alpha1.Stream{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Stream), err +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_subscription.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_subscription.go new file mode 100644 index 00000000000..16b34013f7d --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_subscription.go @@ -0,0 +1,128 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeSubscriptions implements SubscriptionInterface +type FakeSubscriptions struct { + Fake *FakeEventingV1alpha1 + ns string +} + +var subscriptionsResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "subscriptions"} + +var subscriptionsKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Subscription"} + +// Get takes name of the subscription, and returns the corresponding subscription object, and an error if there is any. +func (c *FakeSubscriptions) Get(name string, options v1.GetOptions) (result *v1alpha1.Subscription, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(subscriptionsResource, c.ns, name), &v1alpha1.Subscription{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Subscription), err +} + +// List takes label and field selectors, and returns the list of Subscriptions that match those selectors. +func (c *FakeSubscriptions) List(opts v1.ListOptions) (result *v1alpha1.SubscriptionList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(subscriptionsResource, subscriptionsKind, c.ns, opts), &v1alpha1.SubscriptionList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.SubscriptionList{} + for _, item := range obj.(*v1alpha1.SubscriptionList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested subscriptions. +func (c *FakeSubscriptions) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(subscriptionsResource, c.ns, opts)) + +} + +// Create takes the representation of a subscription and creates it. Returns the server's representation of the subscription, and an error, if there is any. +func (c *FakeSubscriptions) Create(subscription *v1alpha1.Subscription) (result *v1alpha1.Subscription, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(subscriptionsResource, c.ns, subscription), &v1alpha1.Subscription{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Subscription), err +} + +// Update takes the representation of a subscription and updates it. Returns the server's representation of the subscription, and an error, if there is any. +func (c *FakeSubscriptions) Update(subscription *v1alpha1.Subscription) (result *v1alpha1.Subscription, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(subscriptionsResource, c.ns, subscription), &v1alpha1.Subscription{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Subscription), err +} + +// Delete takes name of the subscription and deletes it. Returns an error if one occurs. +func (c *FakeSubscriptions) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(subscriptionsResource, c.ns, name), &v1alpha1.Subscription{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeSubscriptions) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(subscriptionsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.SubscriptionList{}) + return err +} + +// Patch applies the patch and returns the patched subscription. +func (c *FakeSubscriptions) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Subscription, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(subscriptionsResource, c.ns, name, data, subresources...), &v1alpha1.Subscription{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Subscription), err +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go index 3e46993d080..74c67fb4a34 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go @@ -20,6 +20,12 @@ package v1alpha1 type BindExpansion interface{} +type BrokerExpansion interface{} + type EventSourceExpansion interface{} type EventTypeExpansion interface{} + +type StreamExpansion interface{} + +type SubscriptionExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/stream.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/stream.go new file mode 100644 index 00000000000..39d3571b74a --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/stream.go @@ -0,0 +1,157 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// StreamsGetter has a method to return a StreamInterface. +// A group's client should implement this interface. +type StreamsGetter interface { + Streams(namespace string) StreamInterface +} + +// StreamInterface has methods to work with Stream resources. +type StreamInterface interface { + Create(*v1alpha1.Stream) (*v1alpha1.Stream, error) + Update(*v1alpha1.Stream) (*v1alpha1.Stream, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.Stream, error) + List(opts v1.ListOptions) (*v1alpha1.StreamList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Stream, err error) + StreamExpansion +} + +// streams implements StreamInterface +type streams struct { + client rest.Interface + ns string +} + +// newStreams returns a Streams +func newStreams(c *EventingV1alpha1Client, namespace string) *streams { + return &streams{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the stream, and returns the corresponding stream object, and an error if there is any. +func (c *streams) Get(name string, options v1.GetOptions) (result *v1alpha1.Stream, err error) { + result = &v1alpha1.Stream{} + err = c.client.Get(). + Namespace(c.ns). + Resource("streams"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Streams that match those selectors. +func (c *streams) List(opts v1.ListOptions) (result *v1alpha1.StreamList, err error) { + result = &v1alpha1.StreamList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("streams"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested streams. +func (c *streams) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("streams"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a stream and creates it. Returns the server's representation of the stream, and an error, if there is any. +func (c *streams) Create(stream *v1alpha1.Stream) (result *v1alpha1.Stream, err error) { + result = &v1alpha1.Stream{} + err = c.client.Post(). + Namespace(c.ns). + Resource("streams"). + Body(stream). + Do(). + Into(result) + return +} + +// Update takes the representation of a stream and updates it. Returns the server's representation of the stream, and an error, if there is any. +func (c *streams) Update(stream *v1alpha1.Stream) (result *v1alpha1.Stream, err error) { + result = &v1alpha1.Stream{} + err = c.client.Put(). + Namespace(c.ns). + Resource("streams"). + Name(stream.Name). + Body(stream). + Do(). + Into(result) + return +} + +// Delete takes name of the stream and deletes it. Returns an error if one occurs. +func (c *streams) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("streams"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *streams) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("streams"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched stream. +func (c *streams) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Stream, err error) { + result = &v1alpha1.Stream{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("streams"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/subscription.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/subscription.go new file mode 100644 index 00000000000..dc9b39b6179 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/subscription.go @@ -0,0 +1,157 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// SubscriptionsGetter has a method to return a SubscriptionInterface. +// A group's client should implement this interface. +type SubscriptionsGetter interface { + Subscriptions(namespace string) SubscriptionInterface +} + +// SubscriptionInterface has methods to work with Subscription resources. +type SubscriptionInterface interface { + Create(*v1alpha1.Subscription) (*v1alpha1.Subscription, error) + Update(*v1alpha1.Subscription) (*v1alpha1.Subscription, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.Subscription, error) + List(opts v1.ListOptions) (*v1alpha1.SubscriptionList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Subscription, err error) + SubscriptionExpansion +} + +// subscriptions implements SubscriptionInterface +type subscriptions struct { + client rest.Interface + ns string +} + +// newSubscriptions returns a Subscriptions +func newSubscriptions(c *EventingV1alpha1Client, namespace string) *subscriptions { + return &subscriptions{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the subscription, and returns the corresponding subscription object, and an error if there is any. +func (c *subscriptions) Get(name string, options v1.GetOptions) (result *v1alpha1.Subscription, err error) { + result = &v1alpha1.Subscription{} + err = c.client.Get(). + Namespace(c.ns). + Resource("subscriptions"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Subscriptions that match those selectors. +func (c *subscriptions) List(opts v1.ListOptions) (result *v1alpha1.SubscriptionList, err error) { + result = &v1alpha1.SubscriptionList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("subscriptions"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested subscriptions. +func (c *subscriptions) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("subscriptions"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a subscription and creates it. Returns the server's representation of the subscription, and an error, if there is any. +func (c *subscriptions) Create(subscription *v1alpha1.Subscription) (result *v1alpha1.Subscription, err error) { + result = &v1alpha1.Subscription{} + err = c.client.Post(). + Namespace(c.ns). + Resource("subscriptions"). + Body(subscription). + Do(). + Into(result) + return +} + +// Update takes the representation of a subscription and updates it. Returns the server's representation of the subscription, and an error, if there is any. +func (c *subscriptions) Update(subscription *v1alpha1.Subscription) (result *v1alpha1.Subscription, err error) { + result = &v1alpha1.Subscription{} + err = c.client.Put(). + Namespace(c.ns). + Resource("subscriptions"). + Name(subscription.Name). + Body(subscription). + Do(). + Into(result) + return +} + +// Delete takes name of the subscription and deletes it. Returns an error if one occurs. +func (c *subscriptions) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("subscriptions"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *subscriptions) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("subscriptions"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched subscription. +func (c *subscriptions) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Subscription, err error) { + result = &v1alpha1.Subscription{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("subscriptions"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/istio/v1alpha2/doc.go b/pkg/client/clientset/versioned/typed/istio/v1alpha2/doc.go new file mode 100644 index 00000000000..e38ac2cb44e --- /dev/null +++ b/pkg/client/clientset/versioned/typed/istio/v1alpha2/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha2 diff --git a/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/doc.go b/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/doc.go new file mode 100644 index 00000000000..2195046d473 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/fake_istio_client.go b/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/fake_istio_client.go new file mode 100644 index 00000000000..e6d53ea0f87 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/fake_istio_client.go @@ -0,0 +1,40 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha2 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/istio/v1alpha2" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeConfigV1alpha2 struct { + *testing.Fake +} + +func (c *FakeConfigV1alpha2) RouteRules(namespace string) v1alpha2.RouteRuleInterface { + return &FakeRouteRules{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeConfigV1alpha2) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/fake_routerule.go b/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/fake_routerule.go new file mode 100644 index 00000000000..2d3e2179751 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/istio/v1alpha2/fake/fake_routerule.go @@ -0,0 +1,128 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeRouteRules implements RouteRuleInterface +type FakeRouteRules struct { + Fake *FakeConfigV1alpha2 + ns string +} + +var routerulesResource = schema.GroupVersionResource{Group: "config.istio.io", Version: "v1alpha2", Resource: "routerules"} + +var routerulesKind = schema.GroupVersionKind{Group: "config.istio.io", Version: "v1alpha2", Kind: "RouteRule"} + +// Get takes name of the routeRule, and returns the corresponding routeRule object, and an error if there is any. +func (c *FakeRouteRules) Get(name string, options v1.GetOptions) (result *v1alpha2.RouteRule, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(routerulesResource, c.ns, name), &v1alpha2.RouteRule{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.RouteRule), err +} + +// List takes label and field selectors, and returns the list of RouteRules that match those selectors. +func (c *FakeRouteRules) List(opts v1.ListOptions) (result *v1alpha2.RouteRuleList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(routerulesResource, routerulesKind, c.ns, opts), &v1alpha2.RouteRuleList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha2.RouteRuleList{} + for _, item := range obj.(*v1alpha2.RouteRuleList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested routeRules. +func (c *FakeRouteRules) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(routerulesResource, c.ns, opts)) + +} + +// Create takes the representation of a routeRule and creates it. Returns the server's representation of the routeRule, and an error, if there is any. +func (c *FakeRouteRules) Create(routeRule *v1alpha2.RouteRule) (result *v1alpha2.RouteRule, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(routerulesResource, c.ns, routeRule), &v1alpha2.RouteRule{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.RouteRule), err +} + +// Update takes the representation of a routeRule and updates it. Returns the server's representation of the routeRule, and an error, if there is any. +func (c *FakeRouteRules) Update(routeRule *v1alpha2.RouteRule) (result *v1alpha2.RouteRule, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(routerulesResource, c.ns, routeRule), &v1alpha2.RouteRule{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.RouteRule), err +} + +// Delete takes name of the routeRule and deletes it. Returns an error if one occurs. +func (c *FakeRouteRules) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(routerulesResource, c.ns, name), &v1alpha2.RouteRule{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeRouteRules) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(routerulesResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha2.RouteRuleList{}) + return err +} + +// Patch applies the patch and returns the patched routeRule. +func (c *FakeRouteRules) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha2.RouteRule, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(routerulesResource, c.ns, name, data, subresources...), &v1alpha2.RouteRule{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.RouteRule), err +} diff --git a/pkg/client/clientset/versioned/typed/istio/v1alpha2/generated_expansion.go b/pkg/client/clientset/versioned/typed/istio/v1alpha2/generated_expansion.go new file mode 100644 index 00000000000..28db7e76e70 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/istio/v1alpha2/generated_expansion.go @@ -0,0 +1,21 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha2 + +type RouteRuleExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/istio/v1alpha2/istio_client.go b/pkg/client/clientset/versioned/typed/istio/v1alpha2/istio_client.go new file mode 100644 index 00000000000..a0e84b27121 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/istio/v1alpha2/istio_client.go @@ -0,0 +1,90 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + v1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" + "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + rest "k8s.io/client-go/rest" +) + +type ConfigV1alpha2Interface interface { + RESTClient() rest.Interface + RouteRulesGetter +} + +// ConfigV1alpha2Client is used to interact with features provided by the config.istio.io group. +type ConfigV1alpha2Client struct { + restClient rest.Interface +} + +func (c *ConfigV1alpha2Client) RouteRules(namespace string) RouteRuleInterface { + return newRouteRules(c, namespace) +} + +// NewForConfig creates a new ConfigV1alpha2Client for the given config. +func NewForConfig(c *rest.Config) (*ConfigV1alpha2Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &ConfigV1alpha2Client{client}, nil +} + +// NewForConfigOrDie creates a new ConfigV1alpha2Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ConfigV1alpha2Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new ConfigV1alpha2Client for the given RESTClient. +func New(c rest.Interface) *ConfigV1alpha2Client { + return &ConfigV1alpha2Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha2.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs} + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ConfigV1alpha2Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/clientset/versioned/typed/istio/v1alpha2/routerule.go b/pkg/client/clientset/versioned/typed/istio/v1alpha2/routerule.go new file mode 100644 index 00000000000..d6fbcc0da2e --- /dev/null +++ b/pkg/client/clientset/versioned/typed/istio/v1alpha2/routerule.go @@ -0,0 +1,157 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + v1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" + scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// RouteRulesGetter has a method to return a RouteRuleInterface. +// A group's client should implement this interface. +type RouteRulesGetter interface { + RouteRules(namespace string) RouteRuleInterface +} + +// RouteRuleInterface has methods to work with RouteRule resources. +type RouteRuleInterface interface { + Create(*v1alpha2.RouteRule) (*v1alpha2.RouteRule, error) + Update(*v1alpha2.RouteRule) (*v1alpha2.RouteRule, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha2.RouteRule, error) + List(opts v1.ListOptions) (*v1alpha2.RouteRuleList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha2.RouteRule, err error) + RouteRuleExpansion +} + +// routeRules implements RouteRuleInterface +type routeRules struct { + client rest.Interface + ns string +} + +// newRouteRules returns a RouteRules +func newRouteRules(c *ConfigV1alpha2Client, namespace string) *routeRules { + return &routeRules{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the routeRule, and returns the corresponding routeRule object, and an error if there is any. +func (c *routeRules) Get(name string, options v1.GetOptions) (result *v1alpha2.RouteRule, err error) { + result = &v1alpha2.RouteRule{} + err = c.client.Get(). + Namespace(c.ns). + Resource("routerules"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of RouteRules that match those selectors. +func (c *routeRules) List(opts v1.ListOptions) (result *v1alpha2.RouteRuleList, err error) { + result = &v1alpha2.RouteRuleList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("routerules"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested routeRules. +func (c *routeRules) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("routerules"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a routeRule and creates it. Returns the server's representation of the routeRule, and an error, if there is any. +func (c *routeRules) Create(routeRule *v1alpha2.RouteRule) (result *v1alpha2.RouteRule, err error) { + result = &v1alpha2.RouteRule{} + err = c.client.Post(). + Namespace(c.ns). + Resource("routerules"). + Body(routeRule). + Do(). + Into(result) + return +} + +// Update takes the representation of a routeRule and updates it. Returns the server's representation of the routeRule, and an error, if there is any. +func (c *routeRules) Update(routeRule *v1alpha2.RouteRule) (result *v1alpha2.RouteRule, err error) { + result = &v1alpha2.RouteRule{} + err = c.client.Put(). + Namespace(c.ns). + Resource("routerules"). + Name(routeRule.Name). + Body(routeRule). + Do(). + Into(result) + return +} + +// Delete takes name of the routeRule and deletes it. Returns an error if one occurs. +func (c *routeRules) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("routerules"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *routeRules) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("routerules"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched routeRule. +func (c *routeRules) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha2.RouteRule, err error) { + result = &v1alpha2.RouteRule{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("routerules"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/broker.go b/pkg/client/informers/externalversions/eventing/v1alpha1/broker.go new file mode 100644 index 00000000000..cdb1d10d701 --- /dev/null +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/broker.go @@ -0,0 +1,89 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + time "time" + + eventing_v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + versioned "github.com/knative/eventing/pkg/client/clientset/versioned" + internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// BrokerInformer provides access to a shared informer and lister for +// Brokers. +type BrokerInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.BrokerLister +} + +type brokerInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewBrokerInformer constructs a new informer for Broker type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewBrokerInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredBrokerInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredBrokerInformer constructs a new informer for Broker type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredBrokerInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventingV1alpha1().Brokers(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventingV1alpha1().Brokers(namespace).Watch(options) + }, + }, + &eventing_v1alpha1.Broker{}, + resyncPeriod, + indexers, + ) +} + +func (f *brokerInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredBrokerInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *brokerInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&eventing_v1alpha1.Broker{}, f.defaultInformer) +} + +func (f *brokerInformer) Lister() v1alpha1.BrokerLister { + return v1alpha1.NewBrokerLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go b/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go index 3190d7d9196..2c361ab6f07 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go @@ -26,10 +26,16 @@ import ( type Interface interface { // Binds returns a BindInformer. Binds() BindInformer + // Brokers returns a BrokerInformer. + Brokers() BrokerInformer // EventSources returns a EventSourceInformer. EventSources() EventSourceInformer // EventTypes returns a EventTypeInformer. EventTypes() EventTypeInformer + // Streams returns a StreamInformer. + Streams() StreamInformer + // Subscriptions returns a SubscriptionInformer. + Subscriptions() SubscriptionInformer } type version struct { @@ -48,6 +54,11 @@ func (v *version) Binds() BindInformer { return &bindInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } +// Brokers returns a BrokerInformer. +func (v *version) Brokers() BrokerInformer { + return &brokerInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // EventSources returns a EventSourceInformer. func (v *version) EventSources() EventSourceInformer { return &eventSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} @@ -57,3 +68,13 @@ func (v *version) EventSources() EventSourceInformer { func (v *version) EventTypes() EventTypeInformer { return &eventTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } + +// Streams returns a StreamInformer. +func (v *version) Streams() StreamInformer { + return &streamInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + +// Subscriptions returns a SubscriptionInformer. +func (v *version) Subscriptions() SubscriptionInformer { + return &subscriptionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/stream.go b/pkg/client/informers/externalversions/eventing/v1alpha1/stream.go new file mode 100644 index 00000000000..e73255c8836 --- /dev/null +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/stream.go @@ -0,0 +1,89 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + time "time" + + eventing_v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + versioned "github.com/knative/eventing/pkg/client/clientset/versioned" + internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// StreamInformer provides access to a shared informer and lister for +// Streams. +type StreamInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.StreamLister +} + +type streamInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewStreamInformer constructs a new informer for Stream type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewStreamInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredStreamInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredStreamInformer constructs a new informer for Stream type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredStreamInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventingV1alpha1().Streams(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventingV1alpha1().Streams(namespace).Watch(options) + }, + }, + &eventing_v1alpha1.Stream{}, + resyncPeriod, + indexers, + ) +} + +func (f *streamInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredStreamInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *streamInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&eventing_v1alpha1.Stream{}, f.defaultInformer) +} + +func (f *streamInformer) Lister() v1alpha1.StreamLister { + return v1alpha1.NewStreamLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/subscription.go b/pkg/client/informers/externalversions/eventing/v1alpha1/subscription.go new file mode 100644 index 00000000000..86009ab9845 --- /dev/null +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/subscription.go @@ -0,0 +1,89 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + time "time" + + eventing_v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + versioned "github.com/knative/eventing/pkg/client/clientset/versioned" + internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// SubscriptionInformer provides access to a shared informer and lister for +// Subscriptions. +type SubscriptionInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.SubscriptionLister +} + +type subscriptionInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewSubscriptionInformer constructs a new informer for Subscription type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewSubscriptionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredSubscriptionInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredSubscriptionInformer constructs a new informer for Subscription type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredSubscriptionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventingV1alpha1().Subscriptions(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventingV1alpha1().Subscriptions(namespace).Watch(options) + }, + }, + &eventing_v1alpha1.Subscription{}, + resyncPeriod, + indexers, + ) +} + +func (f *subscriptionInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredSubscriptionInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *subscriptionInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&eventing_v1alpha1.Subscription{}, f.defaultInformer) +} + +func (f *subscriptionInformer) Lister() v1alpha1.SubscriptionLister { + return v1alpha1.NewSubscriptionLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go index 8bdcd8c6332..3fef9a5ebd0 100644 --- a/pkg/client/informers/externalversions/factory.go +++ b/pkg/client/informers/externalversions/factory.go @@ -26,6 +26,7 @@ import ( versioned "github.com/knative/eventing/pkg/client/clientset/versioned" eventing "github.com/knative/eventing/pkg/client/informers/externalversions/eventing" internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" + istio "github.com/knative/eventing/pkg/client/informers/externalversions/istio" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -124,8 +125,13 @@ type SharedInformerFactory interface { WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool Eventing() eventing.Interface + Config() istio.Interface } func (f *sharedInformerFactory) Eventing() eventing.Interface { return eventing.New(f, f.namespace, f.tweakListOptions) } + +func (f *sharedInformerFactory) Config() istio.Interface { + return istio.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 0fd46a934e9..4bffd298e05 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -22,6 +22,7 @@ import ( "fmt" v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" ) @@ -52,13 +53,23 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { - // Group=eventing.knative.dev, Version=v1alpha1 + // Group=config.istio.io, Version=v1alpha2 + case v1alpha2.SchemeGroupVersion.WithResource("routerules"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Config().V1alpha2().RouteRules().Informer()}, nil + + // Group=eventing.knative.dev, Version=v1alpha1 case v1alpha1.SchemeGroupVersion.WithResource("binds"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Binds().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("brokers"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Brokers().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("eventsources"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().EventSources().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("eventtypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().EventTypes().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("streams"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Streams().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("subscriptions"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Subscriptions().Informer()}, nil } diff --git a/pkg/client/informers/externalversions/istio/interface.go b/pkg/client/informers/externalversions/istio/interface.go new file mode 100644 index 00000000000..b781c35e8a6 --- /dev/null +++ b/pkg/client/informers/externalversions/istio/interface.go @@ -0,0 +1,46 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 informer-gen. DO NOT EDIT. + +package config + +import ( + internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" + v1alpha2 "github.com/knative/eventing/pkg/client/informers/externalversions/istio/v1alpha2" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha2 provides access to shared informers for resources in V1alpha2. + V1alpha2() v1alpha2.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha2 returns a new v1alpha2.Interface. +func (g *group) V1alpha2() v1alpha2.Interface { + return v1alpha2.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/istio/v1alpha2/interface.go b/pkg/client/informers/externalversions/istio/v1alpha2/interface.go new file mode 100644 index 00000000000..c9df313ae30 --- /dev/null +++ b/pkg/client/informers/externalversions/istio/v1alpha2/interface.go @@ -0,0 +1,45 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 informer-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // RouteRules returns a RouteRuleInformer. + RouteRules() RouteRuleInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// RouteRules returns a RouteRuleInformer. +func (v *version) RouteRules() RouteRuleInformer { + return &routeRuleInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/istio/v1alpha2/routerule.go b/pkg/client/informers/externalversions/istio/v1alpha2/routerule.go new file mode 100644 index 00000000000..3c76a1930c3 --- /dev/null +++ b/pkg/client/informers/externalversions/istio/v1alpha2/routerule.go @@ -0,0 +1,89 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 informer-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + time "time" + + istio_v1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" + versioned "github.com/knative/eventing/pkg/client/clientset/versioned" + internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" + v1alpha2 "github.com/knative/eventing/pkg/client/listers/istio/v1alpha2" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// RouteRuleInformer provides access to a shared informer and lister for +// RouteRules. +type RouteRuleInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha2.RouteRuleLister +} + +type routeRuleInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewRouteRuleInformer constructs a new informer for RouteRule type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewRouteRuleInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredRouteRuleInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredRouteRuleInformer constructs a new informer for RouteRule type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredRouteRuleInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ConfigV1alpha2().RouteRules(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ConfigV1alpha2().RouteRules(namespace).Watch(options) + }, + }, + &istio_v1alpha2.RouteRule{}, + resyncPeriod, + indexers, + ) +} + +func (f *routeRuleInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredRouteRuleInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *routeRuleInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&istio_v1alpha2.RouteRule{}, f.defaultInformer) +} + +func (f *routeRuleInformer) Lister() v1alpha2.RouteRuleLister { + return v1alpha2.NewRouteRuleLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/listers/eventing/v1alpha1/broker.go b/pkg/client/listers/eventing/v1alpha1/broker.go new file mode 100644 index 00000000000..824857e555c --- /dev/null +++ b/pkg/client/listers/eventing/v1alpha1/broker.go @@ -0,0 +1,94 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// BrokerLister helps list Brokers. +type BrokerLister interface { + // List lists all Brokers in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.Broker, err error) + // Brokers returns an object that can list and get Brokers. + Brokers(namespace string) BrokerNamespaceLister + BrokerListerExpansion +} + +// brokerLister implements the BrokerLister interface. +type brokerLister struct { + indexer cache.Indexer +} + +// NewBrokerLister returns a new BrokerLister. +func NewBrokerLister(indexer cache.Indexer) BrokerLister { + return &brokerLister{indexer: indexer} +} + +// List lists all Brokers in the indexer. +func (s *brokerLister) List(selector labels.Selector) (ret []*v1alpha1.Broker, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Broker)) + }) + return ret, err +} + +// Brokers returns an object that can list and get Brokers. +func (s *brokerLister) Brokers(namespace string) BrokerNamespaceLister { + return brokerNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// BrokerNamespaceLister helps list and get Brokers. +type BrokerNamespaceLister interface { + // List lists all Brokers in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.Broker, err error) + // Get retrieves the Broker from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.Broker, error) + BrokerNamespaceListerExpansion +} + +// brokerNamespaceLister implements the BrokerNamespaceLister +// interface. +type brokerNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Brokers in the indexer for a given namespace. +func (s brokerNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Broker, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Broker)) + }) + return ret, err +} + +// Get retrieves the Broker from the indexer for a given namespace and name. +func (s brokerNamespaceLister) Get(name string) (*v1alpha1.Broker, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("broker"), name) + } + return obj.(*v1alpha1.Broker), nil +} diff --git a/pkg/client/listers/eventing/v1alpha1/expansion_generated.go b/pkg/client/listers/eventing/v1alpha1/expansion_generated.go index 4309fac0cca..e478cff6ffd 100644 --- a/pkg/client/listers/eventing/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/eventing/v1alpha1/expansion_generated.go @@ -26,6 +26,14 @@ type BindListerExpansion interface{} // BindNamespaceLister. type BindNamespaceListerExpansion interface{} +// BrokerListerExpansion allows custom methods to be added to +// BrokerLister. +type BrokerListerExpansion interface{} + +// BrokerNamespaceListerExpansion allows custom methods to be added to +// BrokerNamespaceLister. +type BrokerNamespaceListerExpansion interface{} + // EventSourceListerExpansion allows custom methods to be added to // EventSourceLister. type EventSourceListerExpansion interface{} @@ -41,3 +49,19 @@ type EventTypeListerExpansion interface{} // EventTypeNamespaceListerExpansion allows custom methods to be added to // EventTypeNamespaceLister. type EventTypeNamespaceListerExpansion interface{} + +// StreamListerExpansion allows custom methods to be added to +// StreamLister. +type StreamListerExpansion interface{} + +// StreamNamespaceListerExpansion allows custom methods to be added to +// StreamNamespaceLister. +type StreamNamespaceListerExpansion interface{} + +// SubscriptionListerExpansion allows custom methods to be added to +// SubscriptionLister. +type SubscriptionListerExpansion interface{} + +// SubscriptionNamespaceListerExpansion allows custom methods to be added to +// SubscriptionNamespaceLister. +type SubscriptionNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/eventing/v1alpha1/stream.go b/pkg/client/listers/eventing/v1alpha1/stream.go new file mode 100644 index 00000000000..f06bb31c7e0 --- /dev/null +++ b/pkg/client/listers/eventing/v1alpha1/stream.go @@ -0,0 +1,94 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// StreamLister helps list Streams. +type StreamLister interface { + // List lists all Streams in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.Stream, err error) + // Streams returns an object that can list and get Streams. + Streams(namespace string) StreamNamespaceLister + StreamListerExpansion +} + +// streamLister implements the StreamLister interface. +type streamLister struct { + indexer cache.Indexer +} + +// NewStreamLister returns a new StreamLister. +func NewStreamLister(indexer cache.Indexer) StreamLister { + return &streamLister{indexer: indexer} +} + +// List lists all Streams in the indexer. +func (s *streamLister) List(selector labels.Selector) (ret []*v1alpha1.Stream, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Stream)) + }) + return ret, err +} + +// Streams returns an object that can list and get Streams. +func (s *streamLister) Streams(namespace string) StreamNamespaceLister { + return streamNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// StreamNamespaceLister helps list and get Streams. +type StreamNamespaceLister interface { + // List lists all Streams in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.Stream, err error) + // Get retrieves the Stream from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.Stream, error) + StreamNamespaceListerExpansion +} + +// streamNamespaceLister implements the StreamNamespaceLister +// interface. +type streamNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Streams in the indexer for a given namespace. +func (s streamNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Stream, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Stream)) + }) + return ret, err +} + +// Get retrieves the Stream from the indexer for a given namespace and name. +func (s streamNamespaceLister) Get(name string) (*v1alpha1.Stream, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("stream"), name) + } + return obj.(*v1alpha1.Stream), nil +} diff --git a/pkg/client/listers/eventing/v1alpha1/subscription.go b/pkg/client/listers/eventing/v1alpha1/subscription.go new file mode 100644 index 00000000000..9ec0070dee6 --- /dev/null +++ b/pkg/client/listers/eventing/v1alpha1/subscription.go @@ -0,0 +1,94 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// SubscriptionLister helps list Subscriptions. +type SubscriptionLister interface { + // List lists all Subscriptions in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.Subscription, err error) + // Subscriptions returns an object that can list and get Subscriptions. + Subscriptions(namespace string) SubscriptionNamespaceLister + SubscriptionListerExpansion +} + +// subscriptionLister implements the SubscriptionLister interface. +type subscriptionLister struct { + indexer cache.Indexer +} + +// NewSubscriptionLister returns a new SubscriptionLister. +func NewSubscriptionLister(indexer cache.Indexer) SubscriptionLister { + return &subscriptionLister{indexer: indexer} +} + +// List lists all Subscriptions in the indexer. +func (s *subscriptionLister) List(selector labels.Selector) (ret []*v1alpha1.Subscription, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Subscription)) + }) + return ret, err +} + +// Subscriptions returns an object that can list and get Subscriptions. +func (s *subscriptionLister) Subscriptions(namespace string) SubscriptionNamespaceLister { + return subscriptionNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// SubscriptionNamespaceLister helps list and get Subscriptions. +type SubscriptionNamespaceLister interface { + // List lists all Subscriptions in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.Subscription, err error) + // Get retrieves the Subscription from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.Subscription, error) + SubscriptionNamespaceListerExpansion +} + +// subscriptionNamespaceLister implements the SubscriptionNamespaceLister +// interface. +type subscriptionNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Subscriptions in the indexer for a given namespace. +func (s subscriptionNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Subscription, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Subscription)) + }) + return ret, err +} + +// Get retrieves the Subscription from the indexer for a given namespace and name. +func (s subscriptionNamespaceLister) Get(name string) (*v1alpha1.Subscription, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("subscription"), name) + } + return obj.(*v1alpha1.Subscription), nil +} diff --git a/pkg/client/listers/istio/v1alpha2/expansion_generated.go b/pkg/client/listers/istio/v1alpha2/expansion_generated.go new file mode 100644 index 00000000000..381e18b6494 --- /dev/null +++ b/pkg/client/listers/istio/v1alpha2/expansion_generated.go @@ -0,0 +1,27 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 lister-gen. DO NOT EDIT. + +package v1alpha2 + +// RouteRuleListerExpansion allows custom methods to be added to +// RouteRuleLister. +type RouteRuleListerExpansion interface{} + +// RouteRuleNamespaceListerExpansion allows custom methods to be added to +// RouteRuleNamespaceLister. +type RouteRuleNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/istio/v1alpha2/routerule.go b/pkg/client/listers/istio/v1alpha2/routerule.go new file mode 100644 index 00000000000..f146e158be7 --- /dev/null +++ b/pkg/client/listers/istio/v1alpha2/routerule.go @@ -0,0 +1,94 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 lister-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + v1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// RouteRuleLister helps list RouteRules. +type RouteRuleLister interface { + // List lists all RouteRules in the indexer. + List(selector labels.Selector) (ret []*v1alpha2.RouteRule, err error) + // RouteRules returns an object that can list and get RouteRules. + RouteRules(namespace string) RouteRuleNamespaceLister + RouteRuleListerExpansion +} + +// routeRuleLister implements the RouteRuleLister interface. +type routeRuleLister struct { + indexer cache.Indexer +} + +// NewRouteRuleLister returns a new RouteRuleLister. +func NewRouteRuleLister(indexer cache.Indexer) RouteRuleLister { + return &routeRuleLister{indexer: indexer} +} + +// List lists all RouteRules in the indexer. +func (s *routeRuleLister) List(selector labels.Selector) (ret []*v1alpha2.RouteRule, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha2.RouteRule)) + }) + return ret, err +} + +// RouteRules returns an object that can list and get RouteRules. +func (s *routeRuleLister) RouteRules(namespace string) RouteRuleNamespaceLister { + return routeRuleNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// RouteRuleNamespaceLister helps list and get RouteRules. +type RouteRuleNamespaceLister interface { + // List lists all RouteRules in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha2.RouteRule, err error) + // Get retrieves the RouteRule from the indexer for a given namespace and name. + Get(name string) (*v1alpha2.RouteRule, error) + RouteRuleNamespaceListerExpansion +} + +// routeRuleNamespaceLister implements the RouteRuleNamespaceLister +// interface. +type routeRuleNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all RouteRules in the indexer for a given namespace. +func (s routeRuleNamespaceLister) List(selector labels.Selector) (ret []*v1alpha2.RouteRule, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha2.RouteRule)) + }) + return ret, err +} + +// Get retrieves the RouteRule from the indexer for a given namespace and name. +func (s routeRuleNamespaceLister) Get(name string) (*v1alpha2.RouteRule, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha2.Resource("routerule"), name) + } + return obj.(*v1alpha2.RouteRule), nil +} From b2b526c2ec577fc744bb666d1c8f9d5c65a96ca3 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Wed, 30 May 2018 21:35:07 -0400 Subject: [PATCH 02/21] Add controllers for new CRDs --- Gopkg.lock | 2 +- cmd/controller/main.go | 6 + pkg/controller/broker/controller.go | 512 +++++++++++++++++ pkg/controller/names.go | 43 ++ pkg/controller/stream/controller.go | 652 ++++++++++++++++++++++ pkg/controller/subscription/controller.go | 482 ++++++++++++++++ 6 files changed, 1696 insertions(+), 1 deletion(-) create mode 100644 pkg/controller/broker/controller.go create mode 100644 pkg/controller/names.go create mode 100644 pkg/controller/stream/controller.go create mode 100644 pkg/controller/subscription/controller.go diff --git a/Gopkg.lock b/Gopkg.lock index c27c9b974a9..2dadb4ad61f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -858,6 +858,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "644ecf30633e1cd3a8fbf54eb3ea9d249b9708c6d2df22c6913e50672c304b96" + inputs-digest = "af45ce432704d023cd07f040af17e202982be60efb9350e874ff78d5f66f4e70" solver-name = "gps-cdcl" solver-version = 1 diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 0f33973353e..cb82472d2aa 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -36,6 +36,9 @@ import ( informers "github.com/knative/eventing/pkg/client/informers/externalversions" "github.com/knative/eventing/pkg/controller" "github.com/knative/eventing/pkg/controller/bind" + "github.com/knative/eventing/pkg/controller/broker" + "github.com/knative/eventing/pkg/controller/stream" + "github.com/knative/eventing/pkg/controller/subscription" "github.com/knative/eventing/pkg/signals" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -85,6 +88,9 @@ func main() { // Add new controllers here. ctors := []controller.Constructor{ bind.NewController, + broker.NewController, + stream.NewController, + subscription.NewController, } // Build all of our controllers, with the clients constructed above. diff --git a/pkg/controller/broker/controller.go b/pkg/controller/broker/controller.go new file mode 100644 index 00000000000..8ceb0187b49 --- /dev/null +++ b/pkg/controller/broker/controller.go @@ -0,0 +1,512 @@ +/* +Copyright 2017 The Kubernetes 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 broker + +import ( + "fmt" + "reflect" + "time" + + "github.com/golang/glog" + "github.com/knative/eventing/pkg/controller" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/apimachinery/pkg/util/wait" + kubeinformers "k8s.io/client-go/informers" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/scheme" + typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" + appslisters "k8s.io/client-go/listers/apps/v1" + corelisters "k8s.io/client-go/listers/core/v1" + "k8s.io/client-go/tools/cache" + "k8s.io/client-go/tools/record" + "k8s.io/client-go/util/workqueue" + + elainformers "github.com/elafros/elafros/pkg/client/informers/externalversions" + clientset "github.com/knative/eventing/pkg/client/clientset/versioned" + streamscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + informers "github.com/knative/eventing/pkg/client/informers/externalversions" + listers "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + + eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" +) + +const controllerAgentName = "broker-controller" + +const ( + // SuccessSynced is used as part of the Event 'reason' when a Broker is synced + SuccessSynced = "Synced" + // ErrResourceExists is used as part of the Event 'reason' when a Broker fails + // to sync due to a Service of the same name already existing. + ErrResourceExists = "ErrResourceExists" + + // MessageResourceExists is the message used for Events when a resource + // fails to sync due to a Service already existing + MessageResourceExists = "Resource %q already exists and is not managed by Broker" + // MessageResourceSynced is the message used for an Event fired when a Broker + // is synced successfully + MessageResourceSynced = "Broker synced successfully" +) + +// Controller is the controller implementation for Broker resources +type Controller struct { + // kubeclientset is a standard kubernetes clientset + kubeclientset kubernetes.Interface + // brokerclientset is a clientset for our own API group + brokerclientset clientset.Interface + + deploymentsLister appslisters.DeploymentLister + deploymentsSynced cache.InformerSynced + servicesLister corelisters.ServiceLister + servicesSynced cache.InformerSynced + brokersLister listers.BrokerLister + brokersSynced cache.InformerSynced + + // workqueue is a rate limited work queue. This is used to queue work to be + // processed instead of performing it as soon as a change happens. This + // means we can ensure we only process a fixed amount of resources at a + // time, and makes it easy to ensure we are never processing the same item + // simultaneously in two different workers. + workqueue workqueue.RateLimitingInterface + // recorder is an event recorder for recording Event resources to the + // Kubernetes API. + recorder record.EventRecorder +} + +// NewController returns a new broker controller +func NewController( + kubeclientset kubernetes.Interface, + brokerclientset clientset.Interface, + kubeInformerFactory kubeinformers.SharedInformerFactory, + brokerInformerFactory informers.SharedInformerFactory, + routeInformerFactory elainformers.SharedInformerFactory) controller.Interface { + + // obtain references to shared index informers for the Broker, Deployment and Service + // types. + brokerInformer := brokerInformerFactory.Eventing().V1alpha1().Brokers() + deploymentInformer := kubeInformerFactory.Apps().V1().Deployments() + serviceInformer := kubeInformerFactory.Core().V1().Services() + + // Create event broadcaster + // Add broker-controller types to the default Kubernetes Scheme so Events can be + // logged for broker-controller types. + streamscheme.AddToScheme(scheme.Scheme) + glog.V(4).Info("Creating event broadcaster") + eventBroadcaster := record.NewBroadcaster() + eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")}) + recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName}) + + controller := &Controller{ + kubeclientset: kubeclientset, + brokerclientset: brokerclientset, + deploymentsLister: deploymentInformer.Lister(), + deploymentsSynced: deploymentInformer.Informer().HasSynced, + servicesLister: serviceInformer.Lister(), + servicesSynced: serviceInformer.Informer().HasSynced, + brokersLister: brokerInformer.Lister(), + brokersSynced: brokerInformer.Informer().HasSynced, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Brokers"), + recorder: recorder, + } + + glog.Info("Setting up event handlers") + // Set up an event handler for when Broker resources change + brokerInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.enqueueBroker, + UpdateFunc: func(old, new interface{}) { + controller.enqueueBroker(new) + }, + }) + // Set up an event handler for when Service resources change. This + // handler will lookup the owner of the given Service, and if it is + // owned by a Broker resource will enqueue that Broker resource for + // processing. This way, we don't need to implement custom logic for + // handling Service resources. More info on this pattern: + // https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md + serviceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.handleObject, + UpdateFunc: func(old, new interface{}) { + newService := new.(*corev1.Service) + oldService := old.(*corev1.Service) + if newService.ResourceVersion == oldService.ResourceVersion { + // Periodic resync will send update events for all known Services. + // Two different versions of the same Service will always have different RVs. + return + } + controller.handleObject(new) + }, + DeleteFunc: controller.handleObject, + }) + + return controller +} + +// Run will set up the event handlers for types we are interested in, as well +// as syncing informer caches and starting workers. It will block until stopCh +// is closed, at which point it will shutdown the workqueue and wait for +// workers to finish processing their current work items. +func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error { + defer runtime.HandleCrash() + defer c.workqueue.ShutDown() + + // Start the informer factories to begin populating the informer caches + glog.Info("Starting Broker controller") + + // Wait for the caches to be synced before starting workers + glog.Info("Waiting for informer caches to sync") + if ok := cache.WaitForCacheSync(stopCh, c.deploymentsSynced, c.servicesSynced, c.brokersSynced); !ok { + return fmt.Errorf("failed to wait for caches to sync") + } + + glog.Info("Starting workers") + // Launch two workers to process Broker resources + for i := 0; i < threadiness; i++ { + go wait.Until(c.runWorker, time.Second, stopCh) + } + + glog.Info("Started workers") + <-stopCh + glog.Info("Shutting down workers") + + return nil +} + +// runWorker is a long-running function that will continually call the +// processNextWorkItem function in order to read and process a message on the +// workqueue. +func (c *Controller) runWorker() { + for c.processNextWorkItem() { + } +} + +// processNextWorkItem will read a single work item off the workqueue and +// attempt to process it, by calling the syncHandler. +func (c *Controller) processNextWorkItem() bool { + obj, shutdown := c.workqueue.Get() + + if shutdown { + return false + } + + // We wrap this block in a func so we can defer c.workqueue.Done. + err := func(obj interface{}) error { + // We call Done here so the workqueue knows we have finished + // processing this item. We also must remember to call Forget if we + // do not want this work item being re-queued. For example, we do + // not call Forget if a transient error occurs, instead the item is + // put back on the workqueue and attempted again after a back-off + // period. + defer c.workqueue.Done(obj) + var key string + var ok bool + // We expect strings to come off the workqueue. These are of the + // form namespace/name. We do this as the delayed nature of the + // workqueue means the items in the informer cache may actually be + // more up to date that when the item was initially put onto the + // workqueue. + if key, ok = obj.(string); !ok { + // As the item in the workqueue is actually invalid, we call + // Forget here else we'd go into a loop of attempting to + // process a work item that is invalid. + c.workqueue.Forget(obj) + runtime.HandleError(fmt.Errorf("expected string in workqueue but got %#v", obj)) + return nil + } + // Run the syncHandler, passing it the namespace/name string of the + // Broker resource to be synced. + if err := c.syncHandler(key); err != nil { + return fmt.Errorf("error syncing '%s': %s", key, err.Error()) + } + // Finally, if no error occurs we Forget this item so it does not + // get queued again until another change happens. + c.workqueue.Forget(obj) + glog.Infof("Successfully synced '%s'", key) + return nil + }(obj) + + if err != nil { + runtime.HandleError(err) + return true + } + + return true +} + +// syncHandler compares the actual state with the desired, and attempts to +// converge the two. It then updates the Status block of the Broker resource +// with the current status of the resource. +func (c *Controller) syncHandler(key string) error { + // Convert the namespace/name string into a distinct namespace and name + namespace, name, err := cache.SplitMetaNamespaceKey(key) + if err != nil { + runtime.HandleError(fmt.Errorf("invalid resource key: %s", key)) + return nil + } + + // Get the Broker resource with this namespace/name + broker, err := c.brokersLister.Brokers(namespace).Get(name) + if err != nil { + // The Broker resource may no longer exist, in which case we stop + // processing. + if errors.IsNotFound(err) { + runtime.HandleError(fmt.Errorf("broker '%s' in work queue no longer exists", key)) + return nil + } + + return err + } + + // Sync Service derived from the Broker + service, err := c.syncBrokerService(broker) + if err != nil { + return err + } + + // Sync Deployment derived from the Broker + deployment, err := c.syncBrokerDeployment(broker) + if err != nil { + return err + } + + // Finally, we update the status block of the Broker resource to reflect the + // current state of the world + return c.updateBrokerStatus(broker, service, deployment) + + c.recorder.Event(broker, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) + return nil +} + +func (c *Controller) syncBrokerService(broker *eventingv1alpha1.Broker) (*corev1.Service, error) { + // Get the service with the specified service name + serviceName := controller.BrokerServiceName(broker.ObjectMeta.Name) + service, err := c.servicesLister.Services(broker.Namespace).Get(serviceName) + // If the resource doesn't exist, we'll create it + if errors.IsNotFound(err) { + service, err = c.kubeclientset.CoreV1().Services(broker.Namespace).Create(newService(broker)) + } + + // If an error occurs during Get/Create, we'll requeue the item so we can + // attempt processing again later. This could have been caused by a + // temporary network failure, or any other transient reason. + if err != nil { + return nil, err + } + + // If the Service is not controlled by this Broker resource, we should log + // a warning to the event recorder and return + if !metav1.IsControlledBy(service, broker) { + msg := fmt.Sprintf(MessageResourceExists, service.Name) + c.recorder.Event(broker, corev1.EventTypeWarning, ErrResourceExists, msg) + return nil, fmt.Errorf(msg) + } + + return service, nil +} + +func (c *Controller) syncBrokerDeployment(broker *eventingv1alpha1.Broker) (*appsv1.Deployment, error) { + // Get the deployment with the specified deployment name + deploymentName := controller.BrokerDeploymentName(broker.ObjectMeta.Name) + deployment, err := c.deploymentsLister.Deployments(broker.Namespace).Get(deploymentName) + // If the resource doesn't exist, we'll create it + if errors.IsNotFound(err) { + deployment, err = c.kubeclientset.AppsV1().Deployments(broker.Namespace).Create(newDeployment(broker)) + } + + // If an error occurs during Get/Create, we'll requeue the item so we can + // attempt processing again later. This could have been caused by a + // temporary network failure, or any other transient reason. + if err != nil { + return nil, err + } + + // If the Deployment is not controlled by this Broker resource, we should log + // a warning to the event recorder and return + if !metav1.IsControlledBy(deployment, broker) { + msg := fmt.Sprintf(MessageResourceExists, deployment.Name) + c.recorder.Event(broker, corev1.EventTypeWarning, ErrResourceExists, msg) + return nil, fmt.Errorf(msg) + } + + // If the Deployment does not match the Broker's proposed Deployment we should update + // the Deployment resource. + proposedDeployment := newDeployment(broker) + if !reflect.DeepEqual(proposedDeployment.Spec, deployment.Spec) { + glog.V(4).Infof("Broker %s container spec updated", broker.Name) + deployment, err = c.kubeclientset.AppsV1().Deployments(broker.Namespace).Update(proposedDeployment) + + if err != nil { + return nil, err + } + } + + return deployment, nil +} + +func (c *Controller) updateBrokerStatus(broker *eventingv1alpha1.Broker, service *corev1.Service, deployment *appsv1.Deployment) error { + // NEVER modify objects from the store. It's a read-only, local cache. + // You can use DeepCopy() to make a deep copy of original object and modify this copy + // Or create a copy manually for better performance + brokerCopy := broker.DeepCopy() + // If the CustomResourceSubresources feature gate is not enabled, + // we must use Update instead of UpdateStatus to update the Status block of the Broker resource. + // UpdateStatus will not allow changes to the Spec of the resource, + // which is ideal for ensuring nothing other than resource status has been updated. + _, err := c.brokerclientset.EventingV1alpha1().Brokers(broker.Namespace).Update(brokerCopy) + return err +} + +// enqueueBroker takes a Broker resource and converts it into a namespace/name +// string which is then put onto the work queue. This method should *not* be +// passed resources of any type other than Broker. +func (c *Controller) enqueueBroker(obj interface{}) { + var key string + var err error + if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil { + runtime.HandleError(err) + return + } + c.workqueue.AddRateLimited(key) +} + +// handleObject will take any resource implementing metav1.Object and attempt +// to find the Broker resource that 'owns' it. It does this by looking at the +// objects metadata.ownerReferences field for an appropriate OwnerReference. +// It then enqueues that Broker resource to be processed. If the object does not +// have an appropriate OwnerReference, it will simply be skipped. +func (c *Controller) handleObject(obj interface{}) { + var object metav1.Object + var ok bool + if object, ok = obj.(metav1.Object); !ok { + tombstone, ok := obj.(cache.DeletedFinalStateUnknown) + if !ok { + runtime.HandleError(fmt.Errorf("error decoding object, invalid type")) + return + } + object, ok = tombstone.Obj.(metav1.Object) + if !ok { + runtime.HandleError(fmt.Errorf("error decoding object tombstone, invalid type")) + return + } + glog.V(4).Infof("Recovered deleted object '%s' from tombstone", object.GetName()) + } + glog.V(4).Infof("Processing object: %s", object.GetName()) + if ownerRef := metav1.GetControllerOf(object); ownerRef != nil { + // If this object is not owned by a Broker, we should not do anything more + // with it. + if ownerRef.Kind != "Broker" { + return + } + + broker, err := c.brokersLister.Brokers(object.GetNamespace()).Get(ownerRef.Name) + if err != nil { + glog.V(4).Infof("ignoring orphaned object '%s' of broker '%s'", object.GetSelfLink(), ownerRef.Name) + return + } + + c.enqueueBroker(broker) + return + } +} + +// newService creates a new Service for a Broker resource. It also sets +// the appropriate OwnerReferences on the resource so handleObject can discover +// the Broker resource that 'owns' it. +func newService(broker *eventingv1alpha1.Broker) *corev1.Service { + labels := map[string]string{ + "broker": broker.Name, + } + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.BrokerServiceName(broker.ObjectMeta.Name), + Namespace: broker.Namespace, + Labels: labels, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(broker, schema.GroupVersionKind{ + Group: eventingv1alpha1.SchemeGroupVersion.Group, + Version: eventingv1alpha1.SchemeGroupVersion.Version, + Kind: "Broker", + }), + }, + }, + Spec: corev1.ServiceSpec{ + Selector: labels, + Ports: []corev1.ServicePort{ + { + Name: "http", + Port: 80, + TargetPort: intstr.FromInt(8080), + }, + }, + }, + } +} + +// newDeployment creates a new Deployment for a Broker resource. It also sets +// the appropriate OwnerReferences on the resource so handleObject can discover +// the Broker resource that 'owns' it. +func newDeployment(broker *eventingv1alpha1.Broker) *appsv1.Deployment { + labels := map[string]string{ + "broker": broker.Name, + } + one := int32(1) + container := broker.Spec.Container.DeepCopy() + container.Env = append(container.Env, + corev1.EnvVar{ + Name: "PORT", + Value: "8080", + }, + corev1.EnvVar{ + Name: "BROKER_NAME", + Value: broker.Name, + }, + ) + return &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.BrokerDeploymentName(broker.ObjectMeta.Name), + Namespace: broker.Namespace, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(broker, schema.GroupVersionKind{ + Group: eventingv1alpha1.SchemeGroupVersion.Group, + Version: eventingv1alpha1.SchemeGroupVersion.Version, + Kind: "Broker", + }), + }, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: &one, + Selector: &metav1.LabelSelector{ + MatchLabels: labels, + }, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: labels, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + *container, + }, + }, + }, + }, + } +} diff --git a/pkg/controller/names.go b/pkg/controller/names.go new file mode 100644 index 00000000000..8ae0a1d6fa8 --- /dev/null +++ b/pkg/controller/names.go @@ -0,0 +1,43 @@ +/* + * Copyright 2018 the original author or 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 controller + +import "fmt" + +func BrokerDeploymentName(brokerName string) string { + return fmt.Sprintf("%s-broker", brokerName) +} + +func BrokerServiceName(brokerName string) string { + return fmt.Sprintf("%s-broker", brokerName) +} + +func BrokeredStreamRouteRuleName(streamName string) string { + return fmt.Sprintf("%s-stream", streamName) +} + +func StreamIngressName(streamName string) string { + return fmt.Sprintf("%s-stream", streamName) +} + +func StreamServiceName(streamName string) string { + return fmt.Sprintf("%s-stream", streamName) +} + +func SubscriptionRouteRuleName(subscriptionName string) string { + return fmt.Sprintf("%s-subscription", subscriptionName) +} diff --git a/pkg/controller/stream/controller.go b/pkg/controller/stream/controller.go new file mode 100644 index 00000000000..10336b6014e --- /dev/null +++ b/pkg/controller/stream/controller.go @@ -0,0 +1,652 @@ +/* +Copyright 2017 The Kubernetes 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 stream + +import ( + "fmt" + "net/http" + "strings" + "time" + + "github.com/golang/glog" + istiolisters "github.com/knative/eventing/pkg/client/listers/istio/v1alpha2" + "github.com/knative/eventing/pkg/controller" + corev1 "k8s.io/api/core/v1" + extensionsv1beta1 "k8s.io/api/extensions/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/apimachinery/pkg/util/wait" + kubeinformers "k8s.io/client-go/informers" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/scheme" + typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" + corelisters "k8s.io/client-go/listers/core/v1" + extensionslisters "k8s.io/client-go/listers/extensions/v1beta1" + "k8s.io/client-go/tools/cache" + "k8s.io/client-go/tools/record" + "k8s.io/client-go/util/workqueue" + + elainformers "github.com/elafros/elafros/pkg/client/informers/externalversions" + clientset "github.com/knative/eventing/pkg/client/clientset/versioned" + streamscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + informers "github.com/knative/eventing/pkg/client/informers/externalversions" + listers "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + + eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + istiov1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" +) + +const controllerAgentName = "stream-controller" + +const ( + // SuccessSynced is used as part of the Event 'reason' when a Stream is synced + SuccessSynced = "Synced" + // ErrResourceExists is used as part of the Event 'reason' when a Stream fails + // to sync due to a Service of the same name already existing. + ErrResourceExists = "ErrResourceExists" + + // MessageResourceExists is the message used for Events when a resource + // fails to sync due to a Service already existing + MessageResourceExists = "Resource %q already exists and is not managed by Stream" + // MessageResourceSynced is the message used for an Event fired when a Stream + // is synced successfully + MessageResourceSynced = "Stream synced successfully" +) + +// Controller is the controller implementation for Stream resources +type Controller struct { + // kubeclientset is a standard kubernetes clientset + kubeclientset kubernetes.Interface + // streamclientset is a clientset for our own API group + streamclientset clientset.Interface + + ingressesLister extensionslisters.IngressLister + ingressesSynced cache.InformerSynced + routerulesLister istiolisters.RouteRuleLister + routerulesSynced cache.InformerSynced + servicesLister corelisters.ServiceLister + servicesSynced cache.InformerSynced + streamsLister listers.StreamLister + streamsSynced cache.InformerSynced + + // workqueue is a rate limited work queue. This is used to queue work to be + // processed instead of performing it as soon as a change happens. This + // means we can ensure we only process a fixed amount of resources at a + // time, and makes it easy to ensure we are never processing the same item + // simultaneously in two different workers. + workqueue workqueue.RateLimitingInterface + // recorder is an event recorder for recording Event resources to the + // Kubernetes API. + recorder record.EventRecorder +} + +// NewController returns a new stream controller +func NewController( + kubeclientset kubernetes.Interface, + streamclientset clientset.Interface, + kubeInformerFactory kubeinformers.SharedInformerFactory, + streamInformerFactory informers.SharedInformerFactory, + routeInformerFactory elainformers.SharedInformerFactory) controller.Interface { + + // obtain references to shared index informers for the Ingress, Service and Stream + // types. + ingressInformer := kubeInformerFactory.Extensions().V1beta1().Ingresses() + routeruleInformer := streamInformerFactory.Config().V1alpha2().RouteRules() + serviceInformer := kubeInformerFactory.Core().V1().Services() + streamInformer := streamInformerFactory.Eventing().V1alpha1().Streams() + + // Create event broadcaster + // Add stream-controller types to the default Kubernetes Scheme so Events can be + // logged for stream-controller types. + streamscheme.AddToScheme(scheme.Scheme) + glog.V(4).Info("Creating event broadcaster") + eventBroadcaster := record.NewBroadcaster() + eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")}) + recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName}) + + controller := &Controller{ + kubeclientset: kubeclientset, + streamclientset: streamclientset, + ingressesLister: ingressInformer.Lister(), + ingressesSynced: ingressInformer.Informer().HasSynced, + routerulesLister: routeruleInformer.Lister(), + routerulesSynced: routeruleInformer.Informer().HasSynced, + servicesLister: serviceInformer.Lister(), + servicesSynced: serviceInformer.Informer().HasSynced, + streamsLister: streamInformer.Lister(), + streamsSynced: streamInformer.Informer().HasSynced, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Streams"), + recorder: recorder, + } + + glog.Info("Setting up event handlers") + // Set up an event handler for when Stream resources change + streamInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.enqueueStream, + UpdateFunc: func(old, new interface{}) { + controller.enqueueStream(new) + }, + }) + // Set up an event handler for when Service resources change. This + // handler will lookup the owner of the given Service, and if it is + // owned by a Stream resource will enqueue that Stream resource for + // processing. This way, we don't need to implement custom logic for + // handling Service resources. More info on this pattern: + // https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md + serviceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.handleObject, + UpdateFunc: func(old, new interface{}) { + newService := new.(*corev1.Service) + oldService := old.(*corev1.Service) + if newService.ResourceVersion == oldService.ResourceVersion { + // Periodic resync will send update events for all known Services. + // Two different versions of the same Service will always have different RVs. + return + } + controller.handleObject(new) + }, + DeleteFunc: controller.handleObject, + }) + + return controller +} + +// Run will set up the event handlers for types we are interested in, as well +// as syncing informer caches and starting workers. It will block until stopCh +// is closed, at which point it will shutdown the workqueue and wait for +// workers to finish processing their current work items. +func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error { + defer runtime.HandleCrash() + defer c.workqueue.ShutDown() + + // Start the informer factories to begin populating the informer caches + glog.Info("Starting Stream controller") + + // Wait for the caches to be synced before starting workers + glog.Info("Waiting for informer caches to sync") + if ok := cache.WaitForCacheSync(stopCh, c.ingressesSynced, c.servicesSynced, c.streamsSynced); !ok { + return fmt.Errorf("failed to wait for caches to sync") + } + + glog.Info("Starting workers") + // Launch two workers to process Stream resources + for i := 0; i < threadiness; i++ { + go wait.Until(c.runWorker, time.Second, stopCh) + } + + glog.Info("Started workers") + <-stopCh + glog.Info("Shutting down workers") + + return nil +} + +// runWorker is a long-running function that will continually call the +// processNextWorkItem function in order to read and process a message on the +// workqueue. +func (c *Controller) runWorker() { + for c.processNextWorkItem() { + } +} + +// processNextWorkItem will read a single work item off the workqueue and +// attempt to process it, by calling the syncHandler. +func (c *Controller) processNextWorkItem() bool { + obj, shutdown := c.workqueue.Get() + + if shutdown { + return false + } + + // We wrap this block in a func so we can defer c.workqueue.Done. + err := func(obj interface{}) error { + // We call Done here so the workqueue knows we have finished + // processing this item. We also must remember to call Forget if we + // do not want this work item being re-queued. For example, we do + // not call Forget if a transient error occurs, instead the item is + // put back on the workqueue and attempted again after a back-off + // period. + defer c.workqueue.Done(obj) + var key string + var ok bool + // We expect strings to come off the workqueue. These are of the + // form namespace/name. We do this as the delayed nature of the + // workqueue means the items in the informer cache may actually be + // more up to date that when the item was initially put onto the + // workqueue. + if key, ok = obj.(string); !ok { + // As the item in the workqueue is actually invalid, we call + // Forget here else we'd go into a loop of attempting to + // process a work item that is invalid. + c.workqueue.Forget(obj) + runtime.HandleError(fmt.Errorf("expected string in workqueue but got %#v", obj)) + return nil + } + // Run the syncHandler, passing it the namespace/name string of the + // Stream resource to be synced. + if err := c.syncHandler(key); err != nil { + return fmt.Errorf("error syncing '%s': %s", key, err.Error()) + } + // Finally, if no error occurs we Forget this item so it does not + // get queued again until another change happens. + c.workqueue.Forget(obj) + glog.Infof("Successfully synced '%s'", key) + return nil + }(obj) + + if err != nil { + runtime.HandleError(err) + return true + } + + return true +} + +// syncHandler compares the actual state with the desired, and attempts to +// converge the two. It then updates the Status block of the Stream resource +// with the current status of the resource. +func (c *Controller) syncHandler(key string) error { + // Convert the namespace/name string into a distinct namespace and name + namespace, name, err := cache.SplitMetaNamespaceKey(key) + if err != nil { + runtime.HandleError(fmt.Errorf("invalid resource key: %s", key)) + return nil + } + + // Get the Stream resource with this namespace/name + stream, err := c.streamsLister.Streams(namespace).Get(name) + if err != nil { + // The Stream resource may no longer exist, in which case we stop + // processing. + if errors.IsNotFound(err) { + runtime.HandleError(fmt.Errorf("stream '%s' in work queue no longer exists", key)) + return nil + } + + return err + } + + // Sync Service derived from the Stream + service, err := c.syncStreamService(stream) + if err != nil { + return err + } + + // Sync RouteRule derived from a brokered Stream + brokeredStreamRouteRule, err := c.syncBrokeredStream(stream) + if err != nil { + return err + } + + // Sync Ingress derived from the Stream + ingress, err := c.syncStreamIngress(stream) + if err != nil { + return err + } + + // Finally, we update the status block of the Stream resource to reflect the + // current state of the world + err = c.updateStreamStatus(stream, service, ingress, brokeredStreamRouteRule) + if err != nil { + return err + } + + c.recorder.Event(stream, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) + return nil +} + +func (c *Controller) syncStreamService(stream *eventingv1alpha1.Stream) (*corev1.Service, error) { + // Get the service with the specified service name + serviceName := controller.StreamServiceName(stream.ObjectMeta.Name) + service, err := c.servicesLister.Services(stream.Namespace).Get(serviceName) + // If the resource doesn't exist, we'll create it + if errors.IsNotFound(err) { + service, err = c.kubeclientset.CoreV1().Services(stream.Namespace).Create(newService(stream)) + } + + // If an error occurs during Get/Create, we'll requeue the item so we can + // attempt processing again later. This could have been caused by a + // temporary network failure, or any other transient reason. + if err != nil { + return nil, err + } + + // If the Service is not controlled by this Stream resource, we should log + // a warning to the event recorder and return + if !metav1.IsControlledBy(service, stream) { + msg := fmt.Sprintf(MessageResourceExists, service.Name) + c.recorder.Event(stream, corev1.EventTypeWarning, ErrResourceExists, msg) + return nil, fmt.Errorf(msg) + } + + return service, nil +} + +func (c *Controller) syncBrokeredStream(stream *eventingv1alpha1.Stream) (*istiov1alpha2.RouteRule, error) { + // Get the RouteRule with the specified Stream name + routeruleName := controller.BrokeredStreamRouteRuleName(stream.ObjectMeta.Name) + routerule, err := c.routerulesLister.RouteRules(stream.Namespace).Get(routeruleName) + + if stream.Spec.Broker == "" { + // If the resource exists, delete it + if routerule != nil { + // Notify broker of stream removal + err = deleteBrokeredStream(routerule.Labels["broker"], stream) + if err != nil { + return routerule, err + } + + // Remove RouteRule + err = c.streamclientset.ConfigV1alpha2().RouteRules(stream.Namespace).Delete(routeruleName, nil) + if err != nil { + return routerule, err + } + } else { + // nothing to do + return routerule, nil + } + } + + // If the resource doesn't exist, we'll create it + if errors.IsNotFound(err) { + routerule, err = c.streamclientset.ConfigV1alpha2().RouteRules(stream.Namespace).Create(newBrokeredRouteRule(stream)) + } + + // If an error occurs during Get/Create, we'll requeue the item so we can + // attempt processing again later. This could have been caused by a + // temporary network failure, or any other transient reason. + if err != nil { + return nil, err + } + + // If the Service is not controlled by this Stream resource, we should log + // a warning to the event recorder and return + if !metav1.IsControlledBy(routerule, stream) { + msg := fmt.Sprintf(MessageResourceExists, routerule.Name) + c.recorder.Event(stream, corev1.EventTypeWarning, ErrResourceExists, msg) + return nil, fmt.Errorf(msg) + } + + // Notify broker of stream + err = provisionBrokeredStream(stream) + if err != nil { + return nil, err + } + + return routerule, nil +} + +func (c *Controller) syncStreamIngress(stream *eventingv1alpha1.Stream) (*extensionsv1beta1.Ingress, error) { + // TODO make ingress optional + + // Get the ingress with the specified ingress name + ingressName := controller.StreamIngressName(stream.ObjectMeta.Name) + ingress, err := c.ingressesLister.Ingresses(stream.Namespace).Get(ingressName) + // If the resource doesn't exist, we'll create it + if errors.IsNotFound(err) { + ingress, err = c.kubeclientset.ExtensionsV1beta1().Ingresses(stream.Namespace).Create(newIngress(stream)) + } + + // If an error occurs during Get/Create, we'll requeue the item so we can + // attempt processing again later. This could have been caused by a + // temporary network failure, or any other transient reason. + if err != nil { + return nil, err + } + + // If the Ingress is not controlled by this Stream resource, we should log + // a warning to the event recorder and return + if !metav1.IsControlledBy(ingress, stream) { + msg := fmt.Sprintf(MessageResourceExists, ingress.Name) + c.recorder.Event(stream, corev1.EventTypeWarning, ErrResourceExists, msg) + return nil, fmt.Errorf(msg) + } + + return ingress, nil +} + +func (c *Controller) updateStreamStatus(stream *eventingv1alpha1.Stream, service *corev1.Service, ingress *extensionsv1beta1.Ingress, brokeredStreamRouteRule *istiov1alpha2.RouteRule) error { + // NEVER modify objects from the store. It's a read-only, local cache. + // You can use DeepCopy() to make a deep copy of original object and modify this copy + // Or create a copy manually for better performance + streamCopy := stream.DeepCopy() + // If the CustomResourceSubresources feature gate is not enabled, + // we must use Update instead of UpdateStatus to update the Status block of the Stream resource. + // UpdateStatus will not allow changes to the Spec of the resource, + // which is ideal for ensuring nothing other than resource status has been updated. + _, err := c.streamclientset.EventingV1alpha1().Streams(stream.Namespace).Update(streamCopy) + return err +} + +// enqueueStream takes a Stream resource and converts it into a namespace/name +// string which is then put onto the work queue. This method should *not* be +// passed resources of any type other than Stream. +func (c *Controller) enqueueStream(obj interface{}) { + var key string + var err error + if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil { + runtime.HandleError(err) + return + } + c.workqueue.AddRateLimited(key) +} + +// handleObject will take any resource implementing metav1.Object and attempt +// to find the Stream resource that 'owns' it. It does this by looking at the +// objects metadata.ownerReferences field for an appropriate OwnerReference. +// It then enqueues that Stream resource to be processed. If the object does not +// have an appropriate OwnerReference, it will simply be skipped. +func (c *Controller) handleObject(obj interface{}) { + var object metav1.Object + var ok bool + if object, ok = obj.(metav1.Object); !ok { + tombstone, ok := obj.(cache.DeletedFinalStateUnknown) + if !ok { + runtime.HandleError(fmt.Errorf("error decoding object, invalid type")) + return + } + object, ok = tombstone.Obj.(metav1.Object) + if !ok { + runtime.HandleError(fmt.Errorf("error decoding object tombstone, invalid type")) + return + } + glog.V(4).Infof("Recovered deleted object '%s' from tombstone", object.GetName()) + } + glog.V(4).Infof("Processing object: %s", object.GetName()) + if ownerRef := metav1.GetControllerOf(object); ownerRef != nil { + // If this object is not owned by a Stream, we should not do anything more + // with it. + if ownerRef.Kind != "Stream" { + return + } + + stream, err := c.streamsLister.Streams(object.GetNamespace()).Get(ownerRef.Name) + if err != nil { + glog.V(4).Infof("ignoring orphaned object '%s' of stream '%s'", object.GetSelfLink(), ownerRef.Name) + return + } + + c.enqueueStream(stream) + return + } +} + +// newService creates a new Service for a Stream resource. It also sets +// the appropriate OwnerReferences on the resource so handleObject can discover +// the Stream resource that 'owns' it. +func newService(stream *eventingv1alpha1.Stream) *corev1.Service { + labels := map[string]string{ + "stream": stream.Name, + } + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.StreamServiceName(stream.ObjectMeta.Name), + Namespace: stream.Namespace, + Labels: labels, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(stream, schema.GroupVersionKind{ + Group: eventingv1alpha1.SchemeGroupVersion.Group, + Version: eventingv1alpha1.SchemeGroupVersion.Version, + Kind: "Stream", + }), + }, + }, + Spec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + {Name: "http", Port: 80}, + }, + }, + } +} + +// newBrokeredRouteRule creates a new RouteRule for a brokered Stream resource. It also sets +// the appropriate OwnerReferences on the resource so handleObject can discover +// the Stream resource that 'owns' it. +func newBrokeredRouteRule(stream *eventingv1alpha1.Stream) *istiov1alpha2.RouteRule { + labels := map[string]string{ + "broker": stream.Spec.Broker, + "stream": stream.Name, + } + return &istiov1alpha2.RouteRule{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.BrokeredStreamRouteRuleName(stream.Name), + Namespace: stream.Namespace, + Labels: labels, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(stream, schema.GroupVersionKind{ + Group: eventingv1alpha1.SchemeGroupVersion.Group, + Version: eventingv1alpha1.SchemeGroupVersion.Version, + Kind: "Stream", + }), + }, + }, + Spec: istiov1alpha2.RouteRuleSpec{ + Destination: istiov1alpha2.IstioService{ + Name: controller.StreamServiceName(stream.Name), + }, + Route: []istiov1alpha2.DestinationWeight{ + { + Destination: istiov1alpha2.IstioService{ + Name: controller.BrokerServiceName(stream.Spec.Broker), + }, + Weight: 100, + }, + }, + Rewrite: istiov1alpha2.HTTPRewrite{ + Authority: fmt.Sprintf("%s.%s.streams.cluster.local", stream.Name, stream.Namespace), + }, + }, + } +} + +// newIngress creates a new Ingress for a Stream resource. It also sets +// the appropriate OwnerReferences on the resource so handleObject can discover +// the Stream resource that 'owns' it. +func newIngress(stream *eventingv1alpha1.Stream) *extensionsv1beta1.Ingress { + labels := map[string]string{ + "stream": stream.Name, + } + annotations := map[string]string{ + "kubernetes.io/ingress.class": "istio", + } + return &extensionsv1beta1.Ingress{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.StreamIngressName(stream.ObjectMeta.Name), + Namespace: stream.Namespace, + Labels: labels, + Annotations: annotations, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(stream, schema.GroupVersionKind{ + Group: eventingv1alpha1.SchemeGroupVersion.Group, + Version: eventingv1alpha1.SchemeGroupVersion.Version, + Kind: "Stream", + }), + }, + }, + Spec: extensionsv1beta1.IngressSpec{ + Rules: []extensionsv1beta1.IngressRule{ + { + // TODO make host name configurable + Host: stream.ObjectMeta.Name, + IngressRuleValue: extensionsv1beta1.IngressRuleValue{ + HTTP: &extensionsv1beta1.HTTPIngressRuleValue{ + Paths: []extensionsv1beta1.HTTPIngressPath{ + { + Backend: extensionsv1beta1.IngressBackend{ + ServiceName: controller.StreamServiceName(stream.ObjectMeta.Name), + ServicePort: intstr.FromString("http"), + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func provisionBrokeredStream(stream *eventingv1alpha1.Stream) error { + streamName := stream.Name + namespace := stream.Namespace + brokerName := stream.Spec.Broker + brokerServiceName := controller.BrokerServiceName(brokerName) + + client := &http.Client{} + url := fmt.Sprintf("http://%s.%s.svc.cluster.local/streams/%s", brokerServiceName, namespace, streamName) + fmt.Printf("Create stream at %s\n", url) + request, err := http.NewRequest(http.MethodPut, url, strings.NewReader("")) + if err != nil { + return err + } + response, err := client.Do(request) + if err != nil { + return err + } + if response.StatusCode < 200 || response.StatusCode >= 300 { + return fmt.Errorf("Unable to provision brokered stream %s on %s", streamName, brokerName) + } + + return nil +} + +func deleteBrokeredStream(brokerName string, stream *eventingv1alpha1.Stream) error { + streamName := stream.Name + namespace := stream.Namespace + brokerServiceName := controller.BrokerServiceName(brokerName) + + client := &http.Client{} + url := fmt.Sprintf("http://%s.%s.svc.cluster.local/streams/%s", brokerServiceName, namespace, streamName) + fmt.Printf("Delete stream at %s\n", url) + request, err := http.NewRequest(http.MethodDelete, url, strings.NewReader("")) + if err != nil { + return err + } + response, err := client.Do(request) + if err != nil { + return err + } + if response.StatusCode < 200 || response.StatusCode >= 300 { + return fmt.Errorf("Unable to delete brokered stream %s on %s", streamName, brokerName) + } + + return nil +} diff --git a/pkg/controller/subscription/controller.go b/pkg/controller/subscription/controller.go new file mode 100644 index 00000000000..ff1f89e045d --- /dev/null +++ b/pkg/controller/subscription/controller.go @@ -0,0 +1,482 @@ +/* +Copyright 2017 The Kubernetes 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 subscription + +import ( + "fmt" + "net/http" + "strings" + "time" + + "github.com/golang/glog" + istiolisters "github.com/knative/eventing/pkg/client/listers/istio/v1alpha2" + "github.com/knative/eventing/pkg/controller" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/apimachinery/pkg/util/wait" + kubeinformers "k8s.io/client-go/informers" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/scheme" + typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" + "k8s.io/client-go/tools/cache" + "k8s.io/client-go/tools/record" + "k8s.io/client-go/util/workqueue" + + elainformers "github.com/elafros/elafros/pkg/client/informers/externalversions" + clientset "github.com/knative/eventing/pkg/client/clientset/versioned" + subscriptionscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + informers "github.com/knative/eventing/pkg/client/informers/externalversions" + listers "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + + eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + istiov1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" +) + +const controllerAgentName = "subscription-controller" + +const ( + // SuccessSynced is used as part of the Event 'reason' when a Subscription is synced + SuccessSynced = "Synced" + // ErrResourceExists is used as part of the Event 'reason' when a Subscription fails + // to sync due to a RouteRule of the same name already existing. + ErrResourceExists = "ErrResourceExists" + + // MessageResourceExists is the message used for Events when a resource + // fails to sync due to a RouteRule already existing + MessageResourceExists = "Resource %q already exists and is not managed by Subscription" + // MessageResourceSynced is the message used for an Event fired when a Subscription + // is synced successfully + MessageResourceSynced = "Subscription synced successfully" +) + +// Controller is the controller implementation for Subscription resources +type Controller struct { + // kubeclientset is a standard kubernetes clientset + kubeclientset kubernetes.Interface + // subscriptionclientset is a clientset for our own API group + subscriptionclientset clientset.Interface + + routerulesLister istiolisters.RouteRuleLister + routerulesSynced cache.InformerSynced + streamsLister listers.StreamLister + streamsSynced cache.InformerSynced + subscriptionsLister listers.SubscriptionLister + subscriptionsSynced cache.InformerSynced + + // workqueue is a rate limited work queue. This is used to queue work to be + // processed instead of performing it as soon as a change happens. This + // means we can ensure we only process a fixed amount of resources at a + // time, and makes it easy to ensure we are never processing the same item + // simultaneously in two different workers. + workqueue workqueue.RateLimitingInterface + // recorder is an event recorder for recording Event resources to the + // Kubernetes API. + recorder record.EventRecorder +} + +// NewController returns a new subscription controller +func NewController( + kubeclientset kubernetes.Interface, + subscriptionclientset clientset.Interface, + kubeInformerFactory kubeinformers.SharedInformerFactory, + subscriptionInformerFactory informers.SharedInformerFactory, + routeInformerFactory elainformers.SharedInformerFactory) controller.Interface { + + // obtain references to shared index informers for the RouteRule and Subscription + // types. + routeruleInformer := subscriptionInformerFactory.Config().V1alpha2().RouteRules() + streamInformer := subscriptionInformerFactory.Eventing().V1alpha1().Streams() + subscriptionInformer := subscriptionInformerFactory.Eventing().V1alpha1().Subscriptions() + + // Create event broadcaster + // Add subscription-controller types to the default Kubernetes Scheme so Events can be + // logged for subscription-controller types. + subscriptionscheme.AddToScheme(scheme.Scheme) + glog.V(4).Info("Creating event broadcaster") + eventBroadcaster := record.NewBroadcaster() + eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")}) + recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName}) + + controller := &Controller{ + kubeclientset: kubeclientset, + subscriptionclientset: subscriptionclientset, + routerulesLister: routeruleInformer.Lister(), + routerulesSynced: routeruleInformer.Informer().HasSynced, + streamsLister: streamInformer.Lister(), + streamsSynced: streamInformer.Informer().HasSynced, + subscriptionsLister: subscriptionInformer.Lister(), + subscriptionsSynced: subscriptionInformer.Informer().HasSynced, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Subscriptions"), + recorder: recorder, + } + + glog.Info("Setting up event handlers") + // Set up an event handler for when Subscription resources change + subscriptionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.enqueueSubscription, + UpdateFunc: func(old, new interface{}) { + controller.enqueueSubscription(new) + }, + }) + // Set up an event handler for when RouteRule resources change. This + // handler will lookup the owner of the given RouteRule, and if it is + // owned by a Subscription resource will enqueue that Subscription resource for + // processing. This way, we don't need to implement custom logic for + // handling RouteRule resources. More info on this pattern: + // https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md + routeruleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.handleObject, + UpdateFunc: func(old, new interface{}) { + newRouteRule := new.(*istiov1alpha2.RouteRule) + oldRouteRule := old.(*istiov1alpha2.RouteRule) + if newRouteRule.ResourceVersion == oldRouteRule.ResourceVersion { + // Periodic resync will send update events for all known RouteRules. + // Two different versions of the same RouteRule will always have different RVs. + return + } + controller.handleObject(new) + }, + DeleteFunc: controller.handleObject, + }) + + return controller +} + +// Run will set up the event handlers for types we are interested in, as well +// as syncing informer caches and starting workers. It will block until stopCh +// is closed, at which point it will shutdown the workqueue and wait for +// workers to finish processing their current work items. +func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error { + defer runtime.HandleCrash() + defer c.workqueue.ShutDown() + + // Start the informer factories to begin populating the informer caches + glog.Info("Starting Subscription controller") + + // Wait for the caches to be synced before starting workers + glog.Info("Waiting for informer caches to sync") + if ok := cache.WaitForCacheSync(stopCh, c.routerulesSynced, c.subscriptionsSynced); !ok { + return fmt.Errorf("failed to wait for caches to sync") + } + + glog.Info("Starting workers") + // Launch two workers to process Subscription resources + for i := 0; i < threadiness; i++ { + go wait.Until(c.runWorker, time.Second, stopCh) + } + + glog.Info("Started workers") + <-stopCh + glog.Info("Shutting down workers") + + return nil +} + +// runWorker is a long-running function that will continually call the +// processNextWorkItem function in order to read and process a message on the +// workqueue. +func (c *Controller) runWorker() { + for c.processNextWorkItem() { + } +} + +// processNextWorkItem will read a single work item off the workqueue and +// attempt to process it, by calling the syncHandler. +func (c *Controller) processNextWorkItem() bool { + obj, shutdown := c.workqueue.Get() + + if shutdown { + return false + } + + // We wrap this block in a func so we can defer c.workqueue.Done. + err := func(obj interface{}) error { + // We call Done here so the workqueue knows we have finished + // processing this item. We also must remember to call Forget if we + // do not want this work item being re-queued. For example, we do + // not call Forget if a transient error occurs, instead the item is + // put back on the workqueue and attempted again after a back-off + // period. + defer c.workqueue.Done(obj) + var key string + var ok bool + // We expect strings to come off the workqueue. These are of the + // form namespace/name. We do this as the delayed nature of the + // workqueue means the items in the informer cache may actually be + // more up to date that when the item was initially put onto the + // workqueue. + if key, ok = obj.(string); !ok { + // As the item in the workqueue is actually invalid, we call + // Forget here else we'd go into a loop of attempting to + // process a work item that is invalid. + c.workqueue.Forget(obj) + runtime.HandleError(fmt.Errorf("expected string in workqueue but got %#v", obj)) + return nil + } + // Run the syncHandler, passing it the namespace/name string of the + // Subscription resource to be synced. + if err := c.syncHandler(key); err != nil { + return fmt.Errorf("error syncing '%s': %s", key, err.Error()) + } + // Finally, if no error occurs we Forget this item so it does not + // get queued again until another change happens. + c.workqueue.Forget(obj) + glog.Infof("Successfully synced '%s'", key) + return nil + }(obj) + + if err != nil { + runtime.HandleError(err) + return true + } + + return true +} + +// syncHandler compares the actual state with the desired, and attempts to +// converge the two. It then updates the Status block of the Subscription resource +// with the current status of the resource. +func (c *Controller) syncHandler(key string) error { + // Convert the namespace/name string into a distinct namespace and name + namespace, name, err := cache.SplitMetaNamespaceKey(key) + if err != nil { + runtime.HandleError(fmt.Errorf("invalid resource key: %s", key)) + return nil + } + + // Get the Subscription resource with this namespace/name + subscription, err := c.subscriptionsLister.Subscriptions(namespace).Get(name) + if err != nil { + // The Subscription resource may no longer exist, in which case we stop + // processing. + if errors.IsNotFound(err) { + runtime.HandleError(fmt.Errorf("subscription '%s' in work queue no longer exists", key)) + return nil + } + + return err + } + + stream, err := c.streamsLister.Streams(namespace).Get(subscription.Spec.Stream) + + var brokerlessRouterule *istiov1alpha2.RouteRule + if stream.Spec.Broker != "" { + // TODO handle unsubscribe + err = subscribeBrokeredStream(stream.Spec.Broker, subscription) + if err != nil { + return err + } + } else { + brokerlessRouterule, err = c.syncBrokerlessRouteRule(subscription) + if err != nil { + return err + } + } + + // Finally, we update the status block of the Subscription resource to reflect the + // current state of the world + err = c.updateSubscriptionStatus(subscription, brokerlessRouterule) + if err != nil { + return err + } + + c.recorder.Event(subscription, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) + return nil +} + +func (c *Controller) syncBrokerlessRouteRule(subscription *eventingv1alpha1.Subscription) (*istiov1alpha2.RouteRule, error) { + + // Get the routerule with the name specified in Subscription.spec + routeruleName := controller.SubscriptionRouteRuleName(subscription.ObjectMeta.Name) + routerule, err := c.routerulesLister.RouteRules(subscription.Namespace).Get(routeruleName) + // If the resource doesn't exist, we'll create it + if errors.IsNotFound(err) { + routerule, err = c.subscriptionclientset.ConfigV1alpha2().RouteRules(subscription.Namespace).Create(newRouteRule(subscription)) + } + + // If an error occurs during Get/Create, we'll requeue the item so we can + // attempt processing again later. This could have been caused by a + // temporary network failure, or any other transient reason. + if err != nil { + return nil, err + } + + // If the RouteRule is not controlled by this Subscription resource, we should log + // a warning to the event recorder and ret + if !metav1.IsControlledBy(routerule, subscription) { + msg := fmt.Sprintf(MessageResourceExists, routerule.Name) + c.recorder.Event(subscription, corev1.EventTypeWarning, ErrResourceExists, msg) + return nil, fmt.Errorf(msg) + } + + return routerule, nil +} + +func (c *Controller) updateSubscriptionStatus(subscription *eventingv1alpha1.Subscription, brokerlessRouterule *istiov1alpha2.RouteRule) error { + // NEVER modify objects from the store. It's a read-only, local cache. + // You can use DeepCopy() to make a deep copy of original object and modify this copy + // Or create a copy manually for better performance + subscriptionCopy := subscription.DeepCopy() + // If the CustomResourceSubresources feature gate is not enabled, + // we must use Update instead of UpdateStatus to update the Status block of the Subscription resource. + // UpdateStatus will not allow changes to the Spec of the resource, + // which is ideal for ensuring nothing other than resource status has been updated. + _, err := c.subscriptionclientset.EventingV1alpha1().Subscriptions(subscription.Namespace).Update(subscriptionCopy) + return err +} + +// enqueueSubscription takes a Subscription resource and converts it into a namespace/name +// string which is then put onto the work queue. This method should *not* be +// passed resources of any type other than Subscription. +func (c *Controller) enqueueSubscription(obj interface{}) { + var key string + var err error + if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil { + runtime.HandleError(err) + return + } + c.workqueue.AddRateLimited(key) +} + +// handleObject will take any resource implementing metav1.Object and attempt +// to find the Subscription resource that 'owns' it. It does this by looking at the +// objects metadata.ownerReferences field for an appropriate OwnerReference. +// It then enqueues that Subscription resource to be processed. If the object does not +// have an appropriate OwnerReference, it will simply be skipped. +func (c *Controller) handleObject(obj interface{}) { + var object metav1.Object + var ok bool + if object, ok = obj.(metav1.Object); !ok { + tombstone, ok := obj.(cache.DeletedFinalStateUnknown) + if !ok { + runtime.HandleError(fmt.Errorf("error decoding object, invalid type")) + return + } + object, ok = tombstone.Obj.(metav1.Object) + if !ok { + runtime.HandleError(fmt.Errorf("error decoding object tombstone, invalid type")) + return + } + glog.V(4).Infof("Recovered deleted object '%s' from tombstone", object.GetName()) + } + glog.V(4).Infof("Processing object: %s", object.GetName()) + if ownerRef := metav1.GetControllerOf(object); ownerRef != nil { + // If this object is not owned by a Subscription, we should not do anything more + // with it. + if ownerRef.Kind != "Subscription" { + return + } + + subscription, err := c.subscriptionsLister.Subscriptions(object.GetNamespace()).Get(ownerRef.Name) + if err != nil { + glog.V(4).Infof("ignoring orphaned object '%s' of subscription '%s'", object.GetSelfLink(), ownerRef.Name) + return + } + + c.enqueueSubscription(subscription) + return + } +} + +// newRouteRule creates a new RouteRule for a Subscription resource. It also sets +// the appropriate OwnerReferences on the resource so handleObject can discover +// the Subscription resource that 'owns' it. +func newRouteRule(subscription *eventingv1alpha1.Subscription) *istiov1alpha2.RouteRule { + labels := map[string]string{ + "subscription": subscription.Name, + } + return &istiov1alpha2.RouteRule{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.SubscriptionRouteRuleName(subscription.ObjectMeta.Name), + Namespace: subscription.Namespace, + Labels: labels, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(subscription, schema.GroupVersionKind{ + Group: eventingv1alpha1.SchemeGroupVersion.Group, + Version: eventingv1alpha1.SchemeGroupVersion.Version, + Kind: "Subscription", + }), + }, + }, + Spec: istiov1alpha2.RouteRuleSpec{ + Destination: istiov1alpha2.IstioService{ + Name: controller.StreamServiceName(subscription.Spec.Stream), + }, + Route: []istiov1alpha2.DestinationWeight{ + { + Destination: istiov1alpha2.IstioService{ + Name: subscription.Spec.Subscriber, + }, + Weight: 100, + }, + }, + }, + } +} + +func subscribeBrokeredStream(brokerName string, subscription *eventingv1alpha1.Subscription) error { + streamName := subscription.Spec.Stream + subscriberName := subscription.Spec.Subscriber + namespace := subscription.Namespace + brokerServiceName := controller.BrokerServiceName(brokerName) + + client := &http.Client{} + // TODO pass subscriber and params in body, url should contain subscription name + url := fmt.Sprintf("http://%s.%s.svc.cluster.local/streams/%s/subscriptions/%s", brokerServiceName, namespace, streamName, subscriberName) + fmt.Printf("Subscribe %s to stream %s at %s\n", subscriberName, streamName, url) + request, err := http.NewRequest(http.MethodPut, url, strings.NewReader("")) + if err != nil { + return err + } + response, err := client.Do(request) + if err != nil { + return err + } + if response.StatusCode < 200 || response.StatusCode >= 300 { + return fmt.Errorf("Unable to subscribe %s to brokered stream %s on %s", subscriberName, streamName, brokerName) + } + + return nil +} + +func unsubscribeBrokeredStream(brokerName string, subscription *eventingv1alpha1.Subscription) error { + streamName := subscription.Spec.Stream + subscriberName := subscription.Spec.Subscriber + namespace := subscription.Namespace + brokerServiceName := controller.BrokerServiceName(brokerName) + + client := &http.Client{} + url := fmt.Sprintf("http://%s.%s.svc.cluster.local/streams/%s/subscriptions/%s", brokerServiceName, namespace, streamName, subscriberName) + fmt.Printf("Unsubscribe %s from stream %s at %s\n", subscriberName, streamName, url) + request, err := http.NewRequest(http.MethodDelete, url, strings.NewReader("")) + if err != nil { + return err + } + response, err := client.Do(request) + if err != nil { + return err + } + if response.StatusCode < 200 || response.StatusCode >= 300 { + return fmt.Errorf("Unable to unsubscribe %s from brokered stream %s on %s", subscriberName, streamName, brokerName) + } + + return nil +} From c819788fb3a5cfbffff422dce13783bf94033d11 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Wed, 30 May 2018 23:05:38 -0400 Subject: [PATCH 03/21] Stub broker implementation --- Gopkg.lock | 14 +- cmd/stub-broker/main.go | 150 +++++++ config/brokers/stub.yaml | 8 + vendor/github.com/codegangsta/inject/LICENSE | 20 + .../github.com/codegangsta/inject/inject.go | 187 +++++++++ vendor/github.com/go-martini/martini/LICENSE | 20 + vendor/github.com/go-martini/martini/env.go | 25 ++ .../go-martini/martini/go_version.go | 7 + .../github.com/go-martini/martini/logger.go | 29 ++ .../github.com/go-martini/martini/martini.go | 175 +++++++++ .../github.com/go-martini/martini/recovery.go | 142 +++++++ .../go-martini/martini/response_writer.go | 97 +++++ .../go-martini/martini/return_handler.go | 43 ++ .../github.com/go-martini/martini/router.go | 367 ++++++++++++++++++ .../github.com/go-martini/martini/static.go | 109 ++++++ 15 files changed, 1392 insertions(+), 1 deletion(-) create mode 100644 cmd/stub-broker/main.go create mode 100644 config/brokers/stub.yaml create mode 100644 vendor/github.com/codegangsta/inject/LICENSE create mode 100644 vendor/github.com/codegangsta/inject/inject.go create mode 100644 vendor/github.com/go-martini/martini/LICENSE create mode 100644 vendor/github.com/go-martini/martini/env.go create mode 100644 vendor/github.com/go-martini/martini/go_version.go create mode 100644 vendor/github.com/go-martini/martini/logger.go create mode 100644 vendor/github.com/go-martini/martini/martini.go create mode 100644 vendor/github.com/go-martini/martini/recovery.go create mode 100644 vendor/github.com/go-martini/martini/response_writer.go create mode 100644 vendor/github.com/go-martini/martini/return_handler.go create mode 100644 vendor/github.com/go-martini/martini/router.go create mode 100644 vendor/github.com/go-martini/martini/static.go diff --git a/Gopkg.lock b/Gopkg.lock index 2dadb4ad61f..68267c0abd3 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -26,6 +26,12 @@ packages = ["quantile"] revision = "4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9" +[[projects]] + name = "github.com/codegangsta/inject" + packages = ["."] + revision = "37d7f8432a3e684eef9b2edece76bdfa6ac85b39" + version = "v1.0-rc1" + [[projects]] name = "github.com/davecgh/go-spew" packages = ["spew"] @@ -121,6 +127,12 @@ revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" version = "v1.0.0" +[[projects]] + name = "github.com/go-martini/martini" + packages = ["."] + revision = "49411a5b646861ad29a6ddd5351717a0a9c49b94" + version = "v1.0" + [[projects]] name = "github.com/gogo/protobuf" packages = [ @@ -858,6 +870,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "af45ce432704d023cd07f040af17e202982be60efb9350e874ff78d5f66f4e70" + inputs-digest = "942beec00b4df3769bf57628f0f761bfd69128dac3d7009f4618a9c2a8666f5c" solver-name = "gps-cdcl" solver-version = 1 diff --git a/cmd/stub-broker/main.go b/cmd/stub-broker/main.go new file mode 100644 index 00000000000..1dabff705b6 --- /dev/null +++ b/cmd/stub-broker/main.go @@ -0,0 +1,150 @@ +/* + * Copyright 2018 the original author or 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 main + +import ( + "bytes" + "fmt" + "io/ioutil" + "net/http" + "os" + "strings" + + "github.com/go-martini/martini" +) + +var ( + // TODO make thread safe + subscriptions = make(map[string]map[string]struct{}) + exists = struct{}{} + broker = os.Getenv("BROKER_NAME") + forwardHeaders = []string{ + "content-type", + "x-request-id", + "x-b3-traceid", + "x-b3-spanid", + "x-b3-parentspanid", + "x-b3-sampled", + "x-b3-flags", + "x-ot-span-context", + } +) + +func splitStreamName(host string) string { + chunks := strings.Split(host, ".") + stream := chunks[0] + return stream +} + +func main() { + m := martini.Classic() + + m.Post("/", func(req *http.Request, res http.ResponseWriter) { + host := req.Host + fmt.Printf("Recieved request for %s\n", host) + stream := splitStreamName(host) + subscribers, ok := subscriptions[stream] + if !ok { + res.WriteHeader(http.StatusNotFound) + return + } + + body, err := ioutil.ReadAll(req.Body) + if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + res.WriteHeader(http.StatusAccepted) + go func() { + fmt.Printf("Making subscribed requests for %s\n", stream) + + // make upstream requests + client := &http.Client{} + + for subscribed := range subscribers { + go func(subscribed string) { + fmt.Printf("Making subscribed request to %s for %s\n", subscribed, stream) + + url := fmt.Sprintf("http://%s/", subscribed) + request, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body)) + if err != nil { + fmt.Printf("Unable to create subscriber request %v", err) + } + request.Header.Set("x-broker", broker) + request.Header.Set("x-stream", stream) + for _, header := range forwardHeaders { + if value := req.Header.Get(header); value != "" { + request.Header.Set(header, value) + } + } + _, err = client.Do(request) + if err != nil { + fmt.Printf("Unable to complete subscriber request %v", err) + } + }(subscribed) + } + }() + }) + + m.Group("/streams/:stream", func(r martini.Router) { + r.Put("", func(params martini.Params, res http.ResponseWriter) { + stream := params["stream"] + fmt.Printf("Create stream %s\n", stream) + if _, ok := subscriptions[stream]; !ok { + subscriptions[stream] = map[string]struct{}{} + } + res.WriteHeader(http.StatusAccepted) + }) + r.Delete("", func(params martini.Params, res http.ResponseWriter) { + stream := params["stream"] + fmt.Printf("Delete stream %s\n", stream) + delete(subscriptions, stream) + res.WriteHeader(http.StatusAccepted) + }) + + r.Group("/subscriptions/:subscription", func(r martini.Router) { + r.Put("", func(params martini.Params, res http.ResponseWriter) { + stream := params["stream"] + subscription := params["subscription"] + subscribers, ok := subscriptions[stream] + if !ok { + res.WriteHeader(http.StatusNotFound) + return + } + fmt.Printf("Create subscription %s for stream %s\n", subscription, stream) + // TODO store subscription params + subscribers[subscription] = exists + res.WriteHeader(http.StatusAccepted) + }) + r.Delete("", func(params martini.Params, res http.ResponseWriter) { + stream := params["stream"] + subscription := params["subscription"] + subscribers, ok := subscriptions[stream] + if !ok { + res.WriteHeader(http.StatusNotFound) + return + } + fmt.Printf("Delete subscription %s for stream %s\n", subscription, stream) + delete(subscribers, subscription) + res.WriteHeader(http.StatusAccepted) + }) + }) + }) + + m.Run() +} diff --git a/config/brokers/stub.yaml b/config/brokers/stub.yaml new file mode 100644 index 00000000000..245356afc87 --- /dev/null +++ b/config/brokers/stub.yaml @@ -0,0 +1,8 @@ +apiVersion: eventing.knative.dev/v1alpha1 +kind: Broker +metadata: + name: stub +spec: + container: + name: broker + image: github.com/knative/eventing/cmd/stub-broker diff --git a/vendor/github.com/codegangsta/inject/LICENSE b/vendor/github.com/codegangsta/inject/LICENSE new file mode 100644 index 00000000000..eb68a0e0585 --- /dev/null +++ b/vendor/github.com/codegangsta/inject/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Jeremy Saenz + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/codegangsta/inject/inject.go b/vendor/github.com/codegangsta/inject/inject.go new file mode 100644 index 00000000000..3ff713c8a85 --- /dev/null +++ b/vendor/github.com/codegangsta/inject/inject.go @@ -0,0 +1,187 @@ +// Package inject provides utilities for mapping and injecting dependencies in various ways. +package inject + +import ( + "fmt" + "reflect" +) + +// Injector represents an interface for mapping and injecting dependencies into structs +// and function arguments. +type Injector interface { + Applicator + Invoker + TypeMapper + // SetParent sets the parent of the injector. If the injector cannot find a + // dependency in its Type map it will check its parent before returning an + // error. + SetParent(Injector) +} + +// Applicator represents an interface for mapping dependencies to a struct. +type Applicator interface { + // Maps dependencies in the Type map to each field in the struct + // that is tagged with 'inject'. Returns an error if the injection + // fails. + Apply(interface{}) error +} + +// Invoker represents an interface for calling functions via reflection. +type Invoker interface { + // Invoke attempts to call the interface{} provided as a function, + // providing dependencies for function arguments based on Type. Returns + // a slice of reflect.Value representing the returned values of the function. + // Returns an error if the injection fails. + Invoke(interface{}) ([]reflect.Value, error) +} + +// TypeMapper represents an interface for mapping interface{} values based on type. +type TypeMapper interface { + // Maps the interface{} value based on its immediate type from reflect.TypeOf. + Map(interface{}) TypeMapper + // Maps the interface{} value based on the pointer of an Interface provided. + // This is really only useful for mapping a value as an interface, as interfaces + // cannot at this time be referenced directly without a pointer. + MapTo(interface{}, interface{}) TypeMapper + // Provides a possibility to directly insert a mapping based on type and value. + // This makes it possible to directly map type arguments not possible to instantiate + // with reflect like unidirectional channels. + Set(reflect.Type, reflect.Value) TypeMapper + // Returns the Value that is mapped to the current type. Returns a zeroed Value if + // the Type has not been mapped. + Get(reflect.Type) reflect.Value +} + +type injector struct { + values map[reflect.Type]reflect.Value + parent Injector +} + +// InterfaceOf dereferences a pointer to an Interface type. +// It panics if value is not an pointer to an interface. +func InterfaceOf(value interface{}) reflect.Type { + t := reflect.TypeOf(value) + + for t.Kind() == reflect.Ptr { + t = t.Elem() + } + + if t.Kind() != reflect.Interface { + panic("Called inject.InterfaceOf with a value that is not a pointer to an interface. (*MyInterface)(nil)") + } + + return t +} + +// New returns a new Injector. +func New() Injector { + return &injector{ + values: make(map[reflect.Type]reflect.Value), + } +} + +// Invoke attempts to call the interface{} provided as a function, +// providing dependencies for function arguments based on Type. +// Returns a slice of reflect.Value representing the returned values of the function. +// Returns an error if the injection fails. +// It panics if f is not a function +func (inj *injector) Invoke(f interface{}) ([]reflect.Value, error) { + t := reflect.TypeOf(f) + + var in = make([]reflect.Value, t.NumIn()) //Panic if t is not kind of Func + for i := 0; i < t.NumIn(); i++ { + argType := t.In(i) + val := inj.Get(argType) + if !val.IsValid() { + return nil, fmt.Errorf("Value not found for type %v", argType) + } + + in[i] = val + } + + return reflect.ValueOf(f).Call(in), nil +} + +// Maps dependencies in the Type map to each field in the struct +// that is tagged with 'inject'. +// Returns an error if the injection fails. +func (inj *injector) Apply(val interface{}) error { + v := reflect.ValueOf(val) + + for v.Kind() == reflect.Ptr { + v = v.Elem() + } + + if v.Kind() != reflect.Struct { + return nil // Should not panic here ? + } + + t := v.Type() + + for i := 0; i < v.NumField(); i++ { + f := v.Field(i) + structField := t.Field(i) + if f.CanSet() && (structField.Tag == "inject" || structField.Tag.Get("inject") != "") { + ft := f.Type() + v := inj.Get(ft) + if !v.IsValid() { + return fmt.Errorf("Value not found for type %v", ft) + } + + f.Set(v) + } + + } + + return nil +} + +// Maps the concrete value of val to its dynamic type using reflect.TypeOf, +// It returns the TypeMapper registered in. +func (i *injector) Map(val interface{}) TypeMapper { + i.values[reflect.TypeOf(val)] = reflect.ValueOf(val) + return i +} + +func (i *injector) MapTo(val interface{}, ifacePtr interface{}) TypeMapper { + i.values[InterfaceOf(ifacePtr)] = reflect.ValueOf(val) + return i +} + +// Maps the given reflect.Type to the given reflect.Value and returns +// the Typemapper the mapping has been registered in. +func (i *injector) Set(typ reflect.Type, val reflect.Value) TypeMapper { + i.values[typ] = val + return i +} + +func (i *injector) Get(t reflect.Type) reflect.Value { + val := i.values[t] + + if val.IsValid() { + return val + } + + // no concrete types found, try to find implementors + // if t is an interface + if t.Kind() == reflect.Interface { + for k, v := range i.values { + if k.Implements(t) { + val = v + break + } + } + } + + // Still no type found, try to look it up on the parent + if !val.IsValid() && i.parent != nil { + val = i.parent.Get(t) + } + + return val + +} + +func (i *injector) SetParent(parent Injector) { + i.parent = parent +} diff --git a/vendor/github.com/go-martini/martini/LICENSE b/vendor/github.com/go-martini/martini/LICENSE new file mode 100644 index 00000000000..eb68a0e0585 --- /dev/null +++ b/vendor/github.com/go-martini/martini/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Jeremy Saenz + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/go-martini/martini/env.go b/vendor/github.com/go-martini/martini/env.go new file mode 100644 index 00000000000..9bf15b5f61c --- /dev/null +++ b/vendor/github.com/go-martini/martini/env.go @@ -0,0 +1,25 @@ +package martini + +import ( + "os" +) + +// Envs +const ( + Dev string = "development" + Prod string = "production" + Test string = "test" +) + +// Env is the environment that Martini is executing in. The MARTINI_ENV is read on initialization to set this variable. +var Env = Dev + +func setENV(e string) { + if len(e) > 0 { + Env = e + } +} + +func init() { + setENV(os.Getenv("MARTINI_ENV")) +} diff --git a/vendor/github.com/go-martini/martini/go_version.go b/vendor/github.com/go-martini/martini/go_version.go new file mode 100644 index 00000000000..bd271a8cf44 --- /dev/null +++ b/vendor/github.com/go-martini/martini/go_version.go @@ -0,0 +1,7 @@ +// +build !go1.1 + +package martini + +func MartiniDoesNotSupportGo1Point0() { + "Martini requires Go 1.1 or greater." +} diff --git a/vendor/github.com/go-martini/martini/logger.go b/vendor/github.com/go-martini/martini/logger.go new file mode 100644 index 00000000000..d01107c3bf6 --- /dev/null +++ b/vendor/github.com/go-martini/martini/logger.go @@ -0,0 +1,29 @@ +package martini + +import ( + "log" + "net/http" + "time" +) + +// Logger returns a middleware handler that logs the request as it goes in and the response as it goes out. +func Logger() Handler { + return func(res http.ResponseWriter, req *http.Request, c Context, log *log.Logger) { + start := time.Now() + + addr := req.Header.Get("X-Real-IP") + if addr == "" { + addr = req.Header.Get("X-Forwarded-For") + if addr == "" { + addr = req.RemoteAddr + } + } + + log.Printf("Started %s %s for %s", req.Method, req.URL.Path, addr) + + rw := res.(ResponseWriter) + c.Next() + + log.Printf("Completed %v %s in %v\n", rw.Status(), http.StatusText(rw.Status()), time.Since(start)) + } +} diff --git a/vendor/github.com/go-martini/martini/martini.go b/vendor/github.com/go-martini/martini/martini.go new file mode 100644 index 00000000000..a9e4dbcb98f --- /dev/null +++ b/vendor/github.com/go-martini/martini/martini.go @@ -0,0 +1,175 @@ +// Package martini is a powerful package for quickly writing modular web applications/services in Golang. +// +// For a full guide visit http://github.com/go-martini/martini +// +// package main +// +// import "github.com/go-martini/martini" +// +// func main() { +// m := martini.Classic() +// +// m.Get("/", func() string { +// return "Hello world!" +// }) +// +// m.Run() +// } +package martini + +import ( + "log" + "net/http" + "os" + "reflect" + + "github.com/codegangsta/inject" +) + +// Martini represents the top level web application. inject.Injector methods can be invoked to map services on a global level. +type Martini struct { + inject.Injector + handlers []Handler + action Handler + logger *log.Logger +} + +// New creates a bare bones Martini instance. Use this method if you want to have full control over the middleware that is used. +func New() *Martini { + m := &Martini{Injector: inject.New(), action: func() {}, logger: log.New(os.Stdout, "[martini] ", 0)} + m.Map(m.logger) + m.Map(defaultReturnHandler()) + return m +} + +// Handlers sets the entire middleware stack with the given Handlers. This will clear any current middleware handlers. +// Will panic if any of the handlers is not a callable function +func (m *Martini) Handlers(handlers ...Handler) { + m.handlers = make([]Handler, 0) + for _, handler := range handlers { + m.Use(handler) + } +} + +// Action sets the handler that will be called after all the middleware has been invoked. This is set to martini.Router in a martini.Classic(). +func (m *Martini) Action(handler Handler) { + validateHandler(handler) + m.action = handler +} + +// Use adds a middleware Handler to the stack. Will panic if the handler is not a callable func. Middleware Handlers are invoked in the order that they are added. +func (m *Martini) Use(handler Handler) { + validateHandler(handler) + + m.handlers = append(m.handlers, handler) +} + +// ServeHTTP is the HTTP Entry point for a Martini instance. Useful if you want to control your own HTTP server. +func (m *Martini) ServeHTTP(res http.ResponseWriter, req *http.Request) { + m.createContext(res, req).run() +} + +// Run the http server. Listening on os.GetEnv("PORT") or 3000 by default. +func (m *Martini) Run() { + port := os.Getenv("PORT") + if port == "" { + port = "3000" + } + + host := os.Getenv("HOST") + + logger := m.Injector.Get(reflect.TypeOf(m.logger)).Interface().(*log.Logger) + + logger.Printf("listening on %s:%s (%s)\n", host, port, Env) + logger.Fatalln(http.ListenAndServe(host+":"+port, m)) +} + +func (m *Martini) createContext(res http.ResponseWriter, req *http.Request) *context { + c := &context{inject.New(), m.handlers, m.action, NewResponseWriter(res), 0} + c.SetParent(m) + c.MapTo(c, (*Context)(nil)) + c.MapTo(c.rw, (*http.ResponseWriter)(nil)) + c.Map(req) + return c +} + +// ClassicMartini represents a Martini with some reasonable defaults. Embeds the router functions for convenience. +type ClassicMartini struct { + *Martini + Router +} + +// Classic creates a classic Martini with some basic default middleware - martini.Logger, martini.Recovery and martini.Static. +// Classic also maps martini.Routes as a service. +func Classic() *ClassicMartini { + r := NewRouter() + m := New() + m.Use(Logger()) + m.Use(Recovery()) + m.Use(Static("public")) + m.MapTo(r, (*Routes)(nil)) + m.Action(r.Handle) + return &ClassicMartini{m, r} +} + +// Handler can be any callable function. Martini attempts to inject services into the handler's argument list. +// Martini will panic if an argument could not be fullfilled via dependency injection. +type Handler interface{} + +func validateHandler(handler Handler) { + if reflect.TypeOf(handler).Kind() != reflect.Func { + panic("martini handler must be a callable func") + } +} + +// Context represents a request context. Services can be mapped on the request level from this interface. +type Context interface { + inject.Injector + // Next is an optional function that Middleware Handlers can call to yield the until after + // the other Handlers have been executed. This works really well for any operations that must + // happen after an http request + Next() + // Written returns whether or not the response for this context has been written. + Written() bool +} + +type context struct { + inject.Injector + handlers []Handler + action Handler + rw ResponseWriter + index int +} + +func (c *context) handler() Handler { + if c.index < len(c.handlers) { + return c.handlers[c.index] + } + if c.index == len(c.handlers) { + return c.action + } + panic("invalid index for context handler") +} + +func (c *context) Next() { + c.index += 1 + c.run() +} + +func (c *context) Written() bool { + return c.rw.Written() +} + +func (c *context) run() { + for c.index <= len(c.handlers) { + _, err := c.Invoke(c.handler()) + if err != nil { + panic(err) + } + c.index += 1 + + if c.Written() { + return + } + } +} diff --git a/vendor/github.com/go-martini/martini/recovery.go b/vendor/github.com/go-martini/martini/recovery.go new file mode 100644 index 00000000000..722622acd74 --- /dev/null +++ b/vendor/github.com/go-martini/martini/recovery.go @@ -0,0 +1,142 @@ +package martini + +import ( + "bytes" + "fmt" + "io/ioutil" + "log" + "net/http" + "runtime" + + "github.com/codegangsta/inject" +) + +const ( + panicHtml = ` +PANIC: %s + + +

PANIC

+
%s
+
%s
+ +` +) + +var ( + dunno = []byte("???") + centerDot = []byte("·") + dot = []byte(".") + slash = []byte("/") +) + +// stack returns a nicely formated stack frame, skipping skip frames +func stack(skip int) []byte { + buf := new(bytes.Buffer) // the returned data + // As we loop, we open files and read them. These variables record the currently + // loaded file. + var lines [][]byte + var lastFile string + for i := skip; ; i++ { // Skip the expected number of frames + pc, file, line, ok := runtime.Caller(i) + if !ok { + break + } + // Print this much at least. If we can't find the source, it won't show. + fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc) + if file != lastFile { + data, err := ioutil.ReadFile(file) + if err != nil { + continue + } + lines = bytes.Split(data, []byte{'\n'}) + lastFile = file + } + fmt.Fprintf(buf, "\t%s: %s\n", function(pc), source(lines, line)) + } + return buf.Bytes() +} + +// source returns a space-trimmed slice of the n'th line. +func source(lines [][]byte, n int) []byte { + n-- // in stack trace, lines are 1-indexed but our array is 0-indexed + if n < 0 || n >= len(lines) { + return dunno + } + return bytes.TrimSpace(lines[n]) +} + +// function returns, if possible, the name of the function containing the PC. +func function(pc uintptr) []byte { + fn := runtime.FuncForPC(pc) + if fn == nil { + return dunno + } + name := []byte(fn.Name()) + // The name includes the path name to the package, which is unnecessary + // since the file name is already included. Plus, it has center dots. + // That is, we see + // runtime/debug.*T·ptrmethod + // and want + // *T.ptrmethod + // Also the package path might contains dot (e.g. code.google.com/...), + // so first eliminate the path prefix + if lastslash := bytes.LastIndex(name, slash); lastslash >= 0 { + name = name[lastslash+1:] + } + if period := bytes.Index(name, dot); period >= 0 { + name = name[period+1:] + } + name = bytes.Replace(name, centerDot, dot, -1) + return name +} + +// Recovery returns a middleware that recovers from any panics and writes a 500 if there was one. +// While Martini is in development mode, Recovery will also output the panic as HTML. +func Recovery() Handler { + return func(c Context, log *log.Logger) { + defer func() { + if err := recover(); err != nil { + stack := stack(3) + log.Printf("PANIC: %s\n%s", err, stack) + + // Lookup the current responsewriter + val := c.Get(inject.InterfaceOf((*http.ResponseWriter)(nil))) + res := val.Interface().(http.ResponseWriter) + + // respond with panic message while in development mode + var body []byte + if Env == Dev { + res.Header().Set("Content-Type", "text/html") + body = []byte(fmt.Sprintf(panicHtml, err, err, stack)) + } + + res.WriteHeader(http.StatusInternalServerError) + if nil != body { + res.Write(body) + } + } + }() + + c.Next() + } +} diff --git a/vendor/github.com/go-martini/martini/response_writer.go b/vendor/github.com/go-martini/martini/response_writer.go new file mode 100644 index 00000000000..fc161534884 --- /dev/null +++ b/vendor/github.com/go-martini/martini/response_writer.go @@ -0,0 +1,97 @@ +package martini + +import ( + "bufio" + "fmt" + "net" + "net/http" +) + +// ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about +// the response. It is recommended that middleware handlers use this construct to wrap a responsewriter +// if the functionality calls for it. +type ResponseWriter interface { + http.ResponseWriter + http.Flusher + // Status returns the status code of the response or 0 if the response has not been written. + Status() int + // Written returns whether or not the ResponseWriter has been written. + Written() bool + // Size returns the size of the response body. + Size() int + // Before allows for a function to be called before the ResponseWriter has been written to. This is + // useful for setting headers or any other operations that must happen before a response has been written. + Before(BeforeFunc) +} + +// BeforeFunc is a function that is called before the ResponseWriter has been written to. +type BeforeFunc func(ResponseWriter) + +// NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter +func NewResponseWriter(rw http.ResponseWriter) ResponseWriter { + return &responseWriter{rw, 0, 0, nil} +} + +type responseWriter struct { + http.ResponseWriter + status int + size int + beforeFuncs []BeforeFunc +} + +func (rw *responseWriter) WriteHeader(s int) { + rw.callBefore() + rw.ResponseWriter.WriteHeader(s) + rw.status = s +} + +func (rw *responseWriter) Write(b []byte) (int, error) { + if !rw.Written() { + // The status will be StatusOK if WriteHeader has not been called yet + rw.WriteHeader(http.StatusOK) + } + size, err := rw.ResponseWriter.Write(b) + rw.size += size + return size, err +} + +func (rw *responseWriter) Status() int { + return rw.status +} + +func (rw *responseWriter) Size() int { + return rw.size +} + +func (rw *responseWriter) Written() bool { + return rw.status != 0 +} + +func (rw *responseWriter) Before(before BeforeFunc) { + rw.beforeFuncs = append(rw.beforeFuncs, before) +} + +func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + hijacker, ok := rw.ResponseWriter.(http.Hijacker) + if !ok { + return nil, nil, fmt.Errorf("the ResponseWriter doesn't support the Hijacker interface") + } + return hijacker.Hijack() +} + +func (rw *responseWriter) CloseNotify() <-chan bool { + return rw.ResponseWriter.(http.CloseNotifier).CloseNotify() +} + +func (rw *responseWriter) callBefore() { + for i := len(rw.beforeFuncs) - 1; i >= 0; i-- { + rw.beforeFuncs[i](rw) + } +} + +func (rw *responseWriter) Flush() { + flusher, ok := rw.ResponseWriter.(http.Flusher) + if ok { + flusher.Flush() + } +} diff --git a/vendor/github.com/go-martini/martini/return_handler.go b/vendor/github.com/go-martini/martini/return_handler.go new file mode 100644 index 00000000000..4ea8f34b5e8 --- /dev/null +++ b/vendor/github.com/go-martini/martini/return_handler.go @@ -0,0 +1,43 @@ +package martini + +import ( + "github.com/codegangsta/inject" + "net/http" + "reflect" +) + +// ReturnHandler is a service that Martini provides that is called +// when a route handler returns something. The ReturnHandler is +// responsible for writing to the ResponseWriter based on the values +// that are passed into this function. +type ReturnHandler func(Context, []reflect.Value) + +func defaultReturnHandler() ReturnHandler { + return func(ctx Context, vals []reflect.Value) { + rv := ctx.Get(inject.InterfaceOf((*http.ResponseWriter)(nil))) + res := rv.Interface().(http.ResponseWriter) + var responseVal reflect.Value + if len(vals) > 1 && vals[0].Kind() == reflect.Int { + res.WriteHeader(int(vals[0].Int())) + responseVal = vals[1] + } else if len(vals) > 0 { + responseVal = vals[0] + } + if canDeref(responseVal) { + responseVal = responseVal.Elem() + } + if isByteSlice(responseVal) { + res.Write(responseVal.Bytes()) + } else { + res.Write([]byte(responseVal.String())) + } + } +} + +func isByteSlice(val reflect.Value) bool { + return val.Kind() == reflect.Slice && val.Type().Elem().Kind() == reflect.Uint8 +} + +func canDeref(val reflect.Value) bool { + return val.Kind() == reflect.Interface || val.Kind() == reflect.Ptr +} diff --git a/vendor/github.com/go-martini/martini/router.go b/vendor/github.com/go-martini/martini/router.go new file mode 100644 index 00000000000..034a7a2efe5 --- /dev/null +++ b/vendor/github.com/go-martini/martini/router.go @@ -0,0 +1,367 @@ +package martini + +import ( + "fmt" + "net/http" + "reflect" + "regexp" + "strconv" +) + +// Params is a map of name/value pairs for named routes. An instance of martini.Params is available to be injected into any route handler. +type Params map[string]string + +// Router is Martini's de-facto routing interface. Supports HTTP verbs, stacked handlers, and dependency injection. +type Router interface { + Routes + + // Group adds a group where related routes can be added. + Group(string, func(Router), ...Handler) + // Get adds a route for a HTTP GET request to the specified matching pattern. + Get(string, ...Handler) Route + // Patch adds a route for a HTTP PATCH request to the specified matching pattern. + Patch(string, ...Handler) Route + // Post adds a route for a HTTP POST request to the specified matching pattern. + Post(string, ...Handler) Route + // Put adds a route for a HTTP PUT request to the specified matching pattern. + Put(string, ...Handler) Route + // Delete adds a route for a HTTP DELETE request to the specified matching pattern. + Delete(string, ...Handler) Route + // Options adds a route for a HTTP OPTIONS request to the specified matching pattern. + Options(string, ...Handler) Route + // Head adds a route for a HTTP HEAD request to the specified matching pattern. + Head(string, ...Handler) Route + // Any adds a route for any HTTP method request to the specified matching pattern. + Any(string, ...Handler) Route + + // NotFound sets the handlers that are called when a no route matches a request. Throws a basic 404 by default. + NotFound(...Handler) + + // Handle is the entry point for routing. This is used as a martini.Handler + Handle(http.ResponseWriter, *http.Request, Context) +} + +type router struct { + routes []*route + notFounds []Handler + groups []group +} + +type group struct { + pattern string + handlers []Handler +} + +// NewRouter creates a new Router instance. +// If you aren't using ClassicMartini, then you can add Routes as a +// service with: +// +// m := martini.New() +// r := martini.NewRouter() +// m.MapTo(r, (*martini.Routes)(nil)) +// +// If you are using ClassicMartini, then this is done for you. +func NewRouter() Router { + return &router{notFounds: []Handler{http.NotFound}, groups: make([]group, 0)} +} + +func (r *router) Group(pattern string, fn func(Router), h ...Handler) { + r.groups = append(r.groups, group{pattern, h}) + fn(r) + r.groups = r.groups[:len(r.groups)-1] +} + +func (r *router) Get(pattern string, h ...Handler) Route { + return r.addRoute("GET", pattern, h) +} + +func (r *router) Patch(pattern string, h ...Handler) Route { + return r.addRoute("PATCH", pattern, h) +} + +func (r *router) Post(pattern string, h ...Handler) Route { + return r.addRoute("POST", pattern, h) +} + +func (r *router) Put(pattern string, h ...Handler) Route { + return r.addRoute("PUT", pattern, h) +} + +func (r *router) Delete(pattern string, h ...Handler) Route { + return r.addRoute("DELETE", pattern, h) +} + +func (r *router) Options(pattern string, h ...Handler) Route { + return r.addRoute("OPTIONS", pattern, h) +} + +func (r *router) Head(pattern string, h ...Handler) Route { + return r.addRoute("HEAD", pattern, h) +} + +func (r *router) Any(pattern string, h ...Handler) Route { + return r.addRoute("*", pattern, h) +} + +func (r *router) Handle(res http.ResponseWriter, req *http.Request, context Context) { + for _, route := range r.routes { + ok, vals := route.Match(req.Method, req.URL.Path) + if ok { + params := Params(vals) + context.Map(params) + route.Handle(context, res) + return + } + } + + // no routes exist, 404 + c := &routeContext{context, 0, r.notFounds} + context.MapTo(c, (*Context)(nil)) + c.run() +} + +func (r *router) NotFound(handler ...Handler) { + r.notFounds = handler +} + +func (r *router) addRoute(method string, pattern string, handlers []Handler) *route { + if len(r.groups) > 0 { + groupPattern := "" + h := make([]Handler, 0) + for _, g := range r.groups { + groupPattern += g.pattern + h = append(h, g.handlers...) + } + + pattern = groupPattern + pattern + h = append(h, handlers...) + handlers = h + } + + route := newRoute(method, pattern, handlers) + route.Validate() + r.routes = append(r.routes, route) + return route +} + +func (r *router) findRoute(name string) *route { + for _, route := range r.routes { + if route.name == name { + return route + } + } + + return nil +} + +// Route is an interface representing a Route in Martini's routing layer. +type Route interface { + // URLWith returns a rendering of the Route's url with the given string params. + URLWith([]string) string + // Name sets a name for the route. + Name(string) + // GetName returns the name of the route. + GetName() string + // Pattern returns the pattern of the route. + Pattern() string + // Method returns the method of the route. + Method() string +} + +type route struct { + method string + regex *regexp.Regexp + handlers []Handler + pattern string + name string +} + +func newRoute(method string, pattern string, handlers []Handler) *route { + route := route{method, nil, handlers, pattern, ""} + r := regexp.MustCompile(`:[^/#?()\.\\]+`) + pattern = r.ReplaceAllStringFunc(pattern, func(m string) string { + return fmt.Sprintf(`(?P<%s>[^/#?]+)`, m[1:]) + }) + r2 := regexp.MustCompile(`\*\*`) + var index int + pattern = r2.ReplaceAllStringFunc(pattern, func(m string) string { + index++ + return fmt.Sprintf(`(?P<_%d>[^#?]*)`, index) + }) + pattern += `\/?` + route.regex = regexp.MustCompile(pattern) + return &route +} + +func (r route) MatchMethod(method string) bool { + return r.method == "*" || method == r.method || (method == "HEAD" && r.method == "GET") +} + +func (r route) Match(method string, path string) (bool, map[string]string) { + // add Any method matching support + if !r.MatchMethod(method) { + return false, nil + } + + matches := r.regex.FindStringSubmatch(path) + if len(matches) > 0 && matches[0] == path { + params := make(map[string]string) + for i, name := range r.regex.SubexpNames() { + if len(name) > 0 { + params[name] = matches[i] + } + } + return true, params + } + return false, nil +} + +func (r *route) Validate() { + for _, handler := range r.handlers { + validateHandler(handler) + } +} + +func (r *route) Handle(c Context, res http.ResponseWriter) { + context := &routeContext{c, 0, r.handlers} + c.MapTo(context, (*Context)(nil)) + c.MapTo(r, (*Route)(nil)) + context.run() +} + +// URLWith returns the url pattern replacing the parameters for its values +func (r *route) URLWith(args []string) string { + if len(args) > 0 { + reg := regexp.MustCompile(`:[^/#?()\.\\]+`) + argCount := len(args) + i := 0 + url := reg.ReplaceAllStringFunc(r.pattern, func(m string) string { + var val interface{} + if i < argCount { + val = args[i] + } else { + val = m + } + i += 1 + return fmt.Sprintf(`%v`, val) + }) + + return url + } + return r.pattern +} + +func (r *route) Name(name string) { + r.name = name +} + +func (r *route) GetName() string { + return r.name +} + +func (r *route) Pattern() string { + return r.pattern +} + +func (r *route) Method() string { + return r.method +} + +// Routes is a helper service for Martini's routing layer. +type Routes interface { + // URLFor returns a rendered URL for the given route. Optional params can be passed to fulfill named parameters in the route. + URLFor(name string, params ...interface{}) string + // MethodsFor returns an array of methods available for the path + MethodsFor(path string) []string + // All returns an array with all the routes in the router. + All() []Route +} + +// URLFor returns the url for the given route name. +func (r *router) URLFor(name string, params ...interface{}) string { + route := r.findRoute(name) + + if route == nil { + panic("route not found") + } + + var args []string + for _, param := range params { + switch v := param.(type) { + case int: + args = append(args, strconv.FormatInt(int64(v), 10)) + case string: + args = append(args, v) + default: + if v != nil { + panic("Arguments passed to URLFor must be integers or strings") + } + } + } + + return route.URLWith(args) +} + +func (r *router) All() []Route { + var ri = make([]Route, len(r.routes)) + + for i, route := range r.routes { + ri[i] = Route(route) + } + + return ri +} + +func hasMethod(methods []string, method string) bool { + for _, v := range methods { + if v == method { + return true + } + } + return false +} + +// MethodsFor returns all methods available for path +func (r *router) MethodsFor(path string) []string { + methods := []string{} + for _, route := range r.routes { + matches := route.regex.FindStringSubmatch(path) + if len(matches) > 0 && matches[0] == path && !hasMethod(methods, route.method) { + methods = append(methods, route.method) + } + } + return methods +} + +type routeContext struct { + Context + index int + handlers []Handler +} + +func (r *routeContext) Next() { + r.index += 1 + r.run() +} + +func (r *routeContext) run() { + for r.index < len(r.handlers) { + handler := r.handlers[r.index] + vals, err := r.Invoke(handler) + if err != nil { + panic(err) + } + r.index += 1 + + // if the handler returned something, write it to the http response + if len(vals) > 0 { + ev := r.Get(reflect.TypeOf(ReturnHandler(nil))) + handleReturn := ev.Interface().(ReturnHandler) + handleReturn(r, vals) + } + + if r.Written() { + return + } + } +} diff --git a/vendor/github.com/go-martini/martini/static.go b/vendor/github.com/go-martini/martini/static.go new file mode 100644 index 00000000000..db527745198 --- /dev/null +++ b/vendor/github.com/go-martini/martini/static.go @@ -0,0 +1,109 @@ +package martini + +import ( + "log" + "net/http" + "path" + "strings" +) + +// StaticOptions is a struct for specifying configuration options for the martini.Static middleware. +type StaticOptions struct { + // Prefix is the optional prefix used to serve the static directory content + Prefix string + // SkipLogging will disable [Static] log messages when a static file is served. + SkipLogging bool + // IndexFile defines which file to serve as index if it exists. + IndexFile string + // Expires defines which user-defined function to use for producing a HTTP Expires Header + // https://developers.google.com/speed/docs/insights/LeverageBrowserCaching + Expires func() string +} + +func prepareStaticOptions(options []StaticOptions) StaticOptions { + var opt StaticOptions + if len(options) > 0 { + opt = options[0] + } + + // Defaults + if len(opt.IndexFile) == 0 { + opt.IndexFile = "index.html" + } + // Normalize the prefix if provided + if opt.Prefix != "" { + // Ensure we have a leading '/' + if opt.Prefix[0] != '/' { + opt.Prefix = "/" + opt.Prefix + } + // Remove any trailing '/' + opt.Prefix = strings.TrimRight(opt.Prefix, "/") + } + return opt +} + +// Static returns a middleware handler that serves static files in the given directory. +func Static(directory string, staticOpt ...StaticOptions) Handler { + dir := http.Dir(directory) + opt := prepareStaticOptions(staticOpt) + + return func(res http.ResponseWriter, req *http.Request, log *log.Logger) { + if req.Method != "GET" && req.Method != "HEAD" { + return + } + file := req.URL.Path + // if we have a prefix, filter requests by stripping the prefix + if opt.Prefix != "" { + if !strings.HasPrefix(file, opt.Prefix) { + return + } + file = file[len(opt.Prefix):] + if file != "" && file[0] != '/' { + return + } + } + f, err := dir.Open(file) + if err != nil { + // discard the error? + return + } + defer f.Close() + + fi, err := f.Stat() + if err != nil { + return + } + + // try to serve index file + if fi.IsDir() { + // redirect if missing trailing slash + if !strings.HasSuffix(req.URL.Path, "/") { + http.Redirect(res, req, req.URL.Path+"/", http.StatusFound) + return + } + + file = path.Join(file, opt.IndexFile) + f, err = dir.Open(file) + if err != nil { + return + } + defer f.Close() + + fi, err = f.Stat() + if err != nil || fi.IsDir() { + return + } + } + + if !opt.SkipLogging { + log.Println("[Static] Serving " + file) + } + + // Add an Expires header to the static content + if opt.Expires != nil { + res.Header().Set("Expires", opt.Expires()) + } + + http.ServeContent(res, req, file, fi.ModTime(), f) + } +} From 0cac79bae04a3aebfa8a5d1373c3b3da1cc99732 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Wed, 30 May 2018 22:53:06 -0400 Subject: [PATCH 04/21] Add hello and square samples --- sample/hello/Dockerfile | 3 ++ sample/hello/README.md | 19 +++++++++++ sample/hello/app.js | 25 ++++++++++++++ sample/hello/build.sh | 4 +++ sample/hello/hello-istio.yaml | 40 ++++++++++++++++++++++ sample/hello/hello-stream.yaml | 13 ++++++++ sample/hello/hello.yaml | 50 ++++++++++++++++++++++++++++ sample/square/Dockerfile | 3 ++ sample/square/README.md | 31 +++++++++++++++++ sample/square/build.sh | 4 +++ sample/square/square-brokered.yaml | 15 +++++++++ sample/square/square-brokerless.yaml | 13 ++++++++ sample/square/square.js | 5 +++ sample/square/square.yaml | 34 +++++++++++++++++++ 14 files changed, 259 insertions(+) create mode 100644 sample/hello/Dockerfile create mode 100644 sample/hello/README.md create mode 100644 sample/hello/app.js create mode 100755 sample/hello/build.sh create mode 100644 sample/hello/hello-istio.yaml create mode 100644 sample/hello/hello-stream.yaml create mode 100644 sample/hello/hello.yaml create mode 100644 sample/square/Dockerfile create mode 100644 sample/square/README.md create mode 100755 sample/square/build.sh create mode 100644 sample/square/square-brokered.yaml create mode 100644 sample/square/square-brokerless.yaml create mode 100644 sample/square/square.js create mode 100644 sample/square/square.yaml diff --git a/sample/hello/Dockerfile b/sample/hello/Dockerfile new file mode 100644 index 00000000000..5012d64d564 --- /dev/null +++ b/sample/hello/Dockerfile @@ -0,0 +1,3 @@ +FROM node:8 +ADD app.js /app.js +CMD node app.js diff --git a/sample/hello/README.md b/sample/hello/README.md new file mode 100644 index 00000000000..31caeb2d752 --- /dev/null +++ b/sample/hello/README.md @@ -0,0 +1,19 @@ +# Build + +``` +./build.sh +``` + +# Install + +``` +kubectl apply -f hello.yaml +``` + +# Invoke + +``` +export INGRESS_HOST=$(minikube ip) +export INGRESS_PORT=$(kubectl get svc istio-ingress -n istio-system -o jsonpath='{.spec.ports[0].nodePort}') +curl -X POST -H "Host: hello" $INGRESS_HOST:$INGRESS_PORT +``` diff --git a/sample/hello/app.js b/sample/hello/app.js new file mode 100644 index 00000000000..b625d64b0d6 --- /dev/null +++ b/sample/hello/app.js @@ -0,0 +1,25 @@ +const http = require('http'); +const os = require('os'); + +console.log("server starting..."); + +var handler = function(request, response) { + if (request.method !== 'POST') { + response.writeHead(405); + response.end(); + return; + } + if (request.url !== '/') { + response.writeHead(404); + response.end(); + return; + } + const hostname = os.hostname(); + console.log(`received request to ${hostname} from ${request.connection.remoteAddress}`); + response.writeHead(200); + response.end(`hello from ${hostname}\n`); +}; + +var www = http.createServer(handler); +www.listen(8080); + diff --git a/sample/hello/build.sh b/sample/hello/build.sh new file mode 100755 index 00000000000..a71457c5719 --- /dev/null +++ b/sample/hello/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +docker build . -t spike/hello:0.0.1 + diff --git a/sample/hello/hello-istio.yaml b/sample/hello/hello-istio.yaml new file mode 100644 index 00000000000..59c6b405e42 --- /dev/null +++ b/sample/hello/hello-istio.yaml @@ -0,0 +1,40 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: hola + annotations: + kubernetes.io/ingress.class: "istio" +spec: + rules: + - host: hola + http: + paths: + - backend: + serviceName: aloha + servicePort: http + +--- +apiVersion: v1 +kind: Service +metadata: + name: aloha +spec: + type: ClusterIP + ports: + - name: http + port: 80 + protocol: TCP + targetPort: 80 + +--- +apiVersion: config.istio.io/v1alpha2 +kind: RouteRule +metadata: + name: aloha2hello +spec: + destination: + name: aloha + route: + - destination: + name: hello + weight: 100 diff --git a/sample/hello/hello-stream.yaml b/sample/hello/hello-stream.yaml new file mode 100644 index 00000000000..068ce660fe2 --- /dev/null +++ b/sample/hello/hello-stream.yaml @@ -0,0 +1,13 @@ +apiVersion: eventing.elafros.dev/v1alpha1 +kind: Stream +metadata: + name: aloha + +--- +apiVersion: eventing.elafros.dev/v1alpha1 +kind: Subscription +metadata: + name: aloha2hello +spec: + stream: aloha + subscriber: hello diff --git a/sample/hello/hello.yaml b/sample/hello/hello.yaml new file mode 100644 index 00000000000..872e8be70bf --- /dev/null +++ b/sample/hello/hello.yaml @@ -0,0 +1,50 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: hello + labels: + app: hello +spec: + replicas: 3 + template: + metadata: + name: hello + labels: + app: hello + spec: + containers: + - image: spike/hello:0.0.1 + name: main + ports: + - containerPort: 8080 + protocol: TCP + +--- +apiVersion: v1 +kind: Service +metadata: + name: hello +spec: + type: NodePort + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + app: hello + +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: hello + annotations: + kubernetes.io/ingress.class: "istio" +spec: + rules: + - host: hello + http: + paths: + - backend: + serviceName: hello + servicePort: http diff --git a/sample/square/Dockerfile b/sample/square/Dockerfile new file mode 100644 index 00000000000..6b00a8fee28 --- /dev/null +++ b/sample/square/Dockerfile @@ -0,0 +1,3 @@ +FROM projectriff/node-function-invoker:0.0.8 +ENV FUNCTION_URI /functions/square.js +ADD square.js ${FUNCTION_URI} diff --git a/sample/square/README.md b/sample/square/README.md new file mode 100644 index 00000000000..483a7a2b80f --- /dev/null +++ b/sample/square/README.md @@ -0,0 +1,31 @@ +# Build + +``` +./build.sh +``` + +# Install + +Square can be run either with or without a broker. + +At this time, in order to switch between brokered and brokerless, it is recomended that you delete the previous resources and then apply the new resources. + +## Brokerless + +``` +kubectl apply -f square.yaml -f square-brokerless.yaml +``` + +## Brokered + +``` +kubectl apply -f square.yaml -f square-brokered.yaml +``` + +# Invoke + +``` +export INGRESS_HOST=$(minikube ip) +export INGRESS_PORT=$(kubectl get svc istio-ingress -n istio-system -o jsonpath='{.spec.ports[0].nodePort}') +curl -H "Host: square" -H "Content-Type: application/json" $INGRESS_HOST:$INGRESS_PORT -d "33" +``` diff --git a/sample/square/build.sh b/sample/square/build.sh new file mode 100755 index 00000000000..040bc7c00c2 --- /dev/null +++ b/sample/square/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +docker build . -t spike/square:0.0.1 + diff --git a/sample/square/square-brokered.yaml b/sample/square/square-brokered.yaml new file mode 100644 index 00000000000..2f8bd1ed0e4 --- /dev/null +++ b/sample/square/square-brokered.yaml @@ -0,0 +1,15 @@ +apiVersion: eventing.elafros.dev/v1alpha1 +kind: Stream +metadata: + name: square +spec: + broker: stub + +--- +apiVersion: eventing.elafros.dev/v1alpha1 +kind: Subscription +metadata: + name: square +spec: + stream: square + subscriber: square diff --git a/sample/square/square-brokerless.yaml b/sample/square/square-brokerless.yaml new file mode 100644 index 00000000000..9d152b037c0 --- /dev/null +++ b/sample/square/square-brokerless.yaml @@ -0,0 +1,13 @@ +apiVersion: eventing.elafros.dev/v1alpha1 +kind: Stream +metadata: + name: square + +--- +apiVersion: eventing.elafros.dev/v1alpha1 +kind: Subscription +metadata: + name: square +spec: + stream: square + subscriber: square diff --git a/sample/square/square.js b/sample/square/square.js new file mode 100644 index 00000000000..e6dc9e17a89 --- /dev/null +++ b/sample/square/square.js @@ -0,0 +1,5 @@ +module.exports = x => { + const sq = x ** 2 + console.log(`${x} squared is ${sq}`) + return sq +} diff --git a/sample/square/square.yaml b/sample/square/square.yaml new file mode 100644 index 00000000000..13cc50ac20f --- /dev/null +++ b/sample/square/square.yaml @@ -0,0 +1,34 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: square + labels: + app: square +spec: + replicas: 1 + template: + metadata: + name: square + labels: + app: square + spec: + containers: + - image: spike/square:0.0.1 + name: main + ports: + - containerPort: 8080 + protocol: TCP + +--- +apiVersion: v1 +kind: Service +metadata: + name: square +spec: + type: NodePort + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + app: square From 9bf905c544a0dacbe0764f1d2dd6f010ec95fa0d Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Wed, 30 May 2018 23:27:02 -0400 Subject: [PATCH 05/21] Add subscription monitor As an alternative to the subscription controller pushing new subscriptions to the broker. The monitor allows a broker to use the k8s api server to watch subscriptions. --- pkg/subscription/monitor.go | 141 ++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 pkg/subscription/monitor.go diff --git a/pkg/subscription/monitor.go b/pkg/subscription/monitor.go new file mode 100644 index 00000000000..e9e52e354b4 --- /dev/null +++ b/pkg/subscription/monitor.go @@ -0,0 +1,141 @@ +/* + * Copyright 2018 the original author or 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 subscription + +import ( + "sync" + + "github.com/golang/glog" + eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + informers "github.com/knative/eventing/pkg/client/informers/externalversions" + "k8s.io/client-go/tools/cache" +) + +type Monitor struct { + cache map[streamKey]map[subscriptionKey]eventingv1alpha1.SubscriptionSpec + mutex *sync.Mutex +} + +func NewMonitor(informerFactory informers.SharedInformerFactory) *Monitor { + + subscriptionInformer := informerFactory.Eventing().V1alpha1().Subscriptions() + + monitor := &Monitor{ + cache: make(map[streamKey]map[subscriptionKey]eventingv1alpha1.SubscriptionSpec), + mutex: &sync.Mutex{}, + } + + glog.Info("Setting up event handlers") + // Set up an event handler for when Subscription resources change + subscriptionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + subscription := obj.(eventingv1alpha1.Subscription) + monitor.createOrUpdateSubscription(subscription) + }, + UpdateFunc: func(old, new interface{}) { + oldSubscription := old.(eventingv1alpha1.Subscription) + newSubscription := new.(eventingv1alpha1.Subscription) + + if oldSubscription.ResourceVersion == newSubscription.ResourceVersion { + // Periodic resync will send update events for all known Subscriptions. + // Two different versions of the same Subscription will always have different RVs. + return + } + + monitor.createOrUpdateSubscription(newSubscription) + if oldSubscription.Spec.Stream != newSubscription.Spec.Stream { + monitor.removeSubscription(oldSubscription) + } + }, + DeleteFunc: func(obj interface{}) { + subscription := obj.(eventingv1alpha1.Subscription) + monitor.removeSubscription(subscription) + }, + }) + + return monitor +} + +// Subscriptions for a stream name and namespace +func (m *Monitor) Subscriptions(stream string, namespace string) []eventingv1alpha1.SubscriptionSpec { + streamKey := makeStreamKeyWithNames(stream, namespace) + subscriptionsCache := m.getOrCreateSubscriptionsCache(streamKey) + m.mutex.Lock() + subscriptions := make([]eventingv1alpha1.SubscriptionSpec, len(subscriptionsCache)) + for _, subscription := range subscriptionsCache { + subscriptions = append(subscriptions, subscription) + } + m.mutex.Unlock() + return subscriptions +} + +func (m *Monitor) getOrCreateSubscriptionsCache(key streamKey) map[subscriptionKey]eventingv1alpha1.SubscriptionSpec { + m.mutex.Lock() + subscriptionsCache, ok := m.cache[key] + if !ok { + subscriptionsCache = make(map[subscriptionKey]eventingv1alpha1.SubscriptionSpec) + m.cache[key] = subscriptionsCache + } + m.mutex.Unlock() + return subscriptionsCache +} + +func (m *Monitor) createOrUpdateSubscription(subscription eventingv1alpha1.Subscription) { + streamKey := makeStreamKey(subscription) + subscriptionsCache := m.getOrCreateSubscriptionsCache(streamKey) + subscriptionKey := makeSubscriptionKey(subscription) + m.mutex.Lock() + subscriptionsCache[subscriptionKey] = subscription.Spec + m.mutex.Unlock() +} + +func (m *Monitor) removeSubscription(subscription eventingv1alpha1.Subscription) { + streamKey := makeStreamKey(subscription) + subscriptionsCache := m.getOrCreateSubscriptionsCache(streamKey) + subscriptionKey := makeSubscriptionKey(subscription) + m.mutex.Lock() + delete(subscriptionsCache, subscriptionKey) + m.mutex.Unlock() +} + +type streamKey struct { + Name string + Namespace string +} + +func makeStreamKey(subscription eventingv1alpha1.Subscription) streamKey { + return makeStreamKeyWithNames(subscription.Spec.Stream, subscription.Namespace) +} + +func makeStreamKeyWithNames(name string, namespace string) streamKey { + return streamKey{ + Name: name, + Namespace: namespace, + } +} + +type subscriptionKey struct { + Name string + Namespace string +} + +func makeSubscriptionKey(subscription eventingv1alpha1.Subscription) subscriptionKey { + return subscriptionKey{ + Name: subscription.Name, + Namespace: subscription.Namespace, + } +} From e2d423a3bc91d76dc76ca1341cdfc501d946b82a Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Fri, 1 Jun 2018 17:44:12 -0400 Subject: [PATCH 06/21] Add Streams to the Subscription Monitor --- pkg/subscription/monitor.go | 151 ++++++++++++++++++++++++++++++------ 1 file changed, 127 insertions(+), 24 deletions(-) diff --git a/pkg/subscription/monitor.go b/pkg/subscription/monitor.go index e9e52e354b4..6c4bea22340 100644 --- a/pkg/subscription/monitor.go +++ b/pkg/subscription/monitor.go @@ -17,6 +17,7 @@ package subscription import ( + "reflect" "sync" "github.com/golang/glog" @@ -26,20 +27,69 @@ import ( ) type Monitor struct { - cache map[streamKey]map[subscriptionKey]eventingv1alpha1.SubscriptionSpec + brokerName string + handler MonitorEventHandlerFuncs + + cache map[streamKey]streamSummary mutex *sync.Mutex } -func NewMonitor(informerFactory informers.SharedInformerFactory) *Monitor { +type MonitorEventHandlerFuncs struct { + ProvisionFunc func(stream eventingv1alpha1.Stream) + UnprovisionFunc func(stream eventingv1alpha1.Stream) + SubscribeFunc func(subscription eventingv1alpha1.Subscription) + UnsubscribeFunc func(subscription eventingv1alpha1.Subscription) +} + +type streamSummary struct { + Stream *eventingv1alpha1.StreamSpec + Subscriptions map[subscriptionKey]subscriptionSummary +} + +type subscriptionSummary struct { + Subscription eventingv1alpha1.SubscriptionSpec +} + +func NewMonitor(brokerName string, informerFactory informers.SharedInformerFactory, handler MonitorEventHandlerFuncs) *Monitor { + streamInformer := informerFactory.Eventing().V1alpha1().Streams() subscriptionInformer := informerFactory.Eventing().V1alpha1().Subscriptions() monitor := &Monitor{ - cache: make(map[streamKey]map[subscriptionKey]eventingv1alpha1.SubscriptionSpec), + brokerName: brokerName, + handler: handler, + + cache: make(map[streamKey]streamSummary), mutex: &sync.Mutex{}, } glog.Info("Setting up event handlers") + // Set up an event handler for when Stream resources change + streamInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + stream := obj.(eventingv1alpha1.Stream) + monitor.createOrUpdateStream(stream) + }, + UpdateFunc: func(old, new interface{}) { + oldStream := old.(eventingv1alpha1.Stream) + newStream := new.(eventingv1alpha1.Stream) + + if oldStream.ResourceVersion == newStream.ResourceVersion { + // Periodic resync will send update events for all known Streams. + // Two different versions of the same Stream will always have different RVs. + return + } + + monitor.createOrUpdateStream(newStream) + if oldStream.Spec.Broker != newStream.Spec.Broker { + monitor.removeStream(oldStream) + } + }, + DeleteFunc: func(obj interface{}) { + stream := obj.(eventingv1alpha1.Stream) + monitor.removeStream(stream) + }, + }) // Set up an event handler for when Subscription resources change subscriptionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { @@ -71,45 +121,94 @@ func NewMonitor(informerFactory informers.SharedInformerFactory) *Monitor { } // Subscriptions for a stream name and namespace -func (m *Monitor) Subscriptions(stream string, namespace string) []eventingv1alpha1.SubscriptionSpec { +func (m *Monitor) Subscriptions(stream string, namespace string) *[]eventingv1alpha1.SubscriptionSpec { streamKey := makeStreamKeyWithNames(stream, namespace) - subscriptionsCache := m.getOrCreateSubscriptionsCache(streamKey) + summary := m.getOrCreateStreamSummary(streamKey) + + if summary.Stream.Broker != m.brokerName { + // the stream is not for this broker + return nil + } + m.mutex.Lock() - subscriptions := make([]eventingv1alpha1.SubscriptionSpec, len(subscriptionsCache)) - for _, subscription := range subscriptionsCache { - subscriptions = append(subscriptions, subscription) + subscriptions := make([]eventingv1alpha1.SubscriptionSpec, len(summary.Subscriptions)) + for _, subscription := range summary.Subscriptions { + subscriptions = append(subscriptions, subscription.Subscription) } m.mutex.Unlock() - return subscriptions + + return &subscriptions } -func (m *Monitor) getOrCreateSubscriptionsCache(key streamKey) map[subscriptionKey]eventingv1alpha1.SubscriptionSpec { +func (m *Monitor) getOrCreateStreamSummary(key streamKey) streamSummary { m.mutex.Lock() - subscriptionsCache, ok := m.cache[key] + summary, ok := m.cache[key] if !ok { - subscriptionsCache = make(map[subscriptionKey]eventingv1alpha1.SubscriptionSpec) - m.cache[key] = subscriptionsCache + summary = streamSummary{ + Stream: nil, + Subscriptions: make(map[subscriptionKey]subscriptionSummary), + } + m.cache[key] = summary } m.mutex.Unlock() - return subscriptionsCache + + return summary +} + +func (m *Monitor) createOrUpdateStream(stream eventingv1alpha1.Stream) { + streamKey := makeStreamKeyFromStream(stream) + summary := m.getOrCreateStreamSummary(streamKey) + + m.mutex.Lock() + old := summary.Stream + new := &stream.Spec + summary.Stream = new + m.mutex.Unlock() + + if !reflect.DeepEqual(old, new) { + m.handler.ProvisionFunc(stream) + } +} + +func (m *Monitor) removeStream(stream eventingv1alpha1.Stream) { + streamKey := makeStreamKeyFromStream(stream) + summary := m.getOrCreateStreamSummary(streamKey) + + m.mutex.Lock() + summary.Stream = nil + m.mutex.Unlock() + + m.handler.UnprovisionFunc(stream) } func (m *Monitor) createOrUpdateSubscription(subscription eventingv1alpha1.Subscription) { - streamKey := makeStreamKey(subscription) - subscriptionsCache := m.getOrCreateSubscriptionsCache(streamKey) - subscriptionKey := makeSubscriptionKey(subscription) + streamKey := makeStreamKeyFromSubscription(subscription) + summary := m.getOrCreateStreamSummary(streamKey) + subscriptionKey := makeSubscriptionKeyFromSubscription(subscription) + m.mutex.Lock() - subscriptionsCache[subscriptionKey] = subscription.Spec + old := summary.Subscriptions[subscriptionKey] + new := subscriptionSummary{ + Subscription: subscription.Spec, + } + summary.Subscriptions[subscriptionKey] = new m.mutex.Unlock() + + if !reflect.DeepEqual(old.Subscription, new.Subscription) { + m.handler.SubscribeFunc(subscription) + } } func (m *Monitor) removeSubscription(subscription eventingv1alpha1.Subscription) { - streamKey := makeStreamKey(subscription) - subscriptionsCache := m.getOrCreateSubscriptionsCache(streamKey) - subscriptionKey := makeSubscriptionKey(subscription) + streamKey := makeStreamKeyFromSubscription(subscription) + summary := m.getOrCreateStreamSummary(streamKey) + subscriptionKey := makeSubscriptionKeyFromSubscription(subscription) + m.mutex.Lock() - delete(subscriptionsCache, subscriptionKey) + delete(summary.Subscriptions, subscriptionKey) m.mutex.Unlock() + + m.handler.UnsubscribeFunc(subscription) } type streamKey struct { @@ -117,7 +216,11 @@ type streamKey struct { Namespace string } -func makeStreamKey(subscription eventingv1alpha1.Subscription) streamKey { +func makeStreamKeyFromStream(stream eventingv1alpha1.Stream) streamKey { + return makeStreamKeyWithNames(stream.Name, stream.Namespace) +} + +func makeStreamKeyFromSubscription(subscription eventingv1alpha1.Subscription) streamKey { return makeStreamKeyWithNames(subscription.Spec.Stream, subscription.Namespace) } @@ -133,7 +236,7 @@ type subscriptionKey struct { Namespace string } -func makeSubscriptionKey(subscription eventingv1alpha1.Subscription) subscriptionKey { +func makeSubscriptionKeyFromSubscription(subscription eventingv1alpha1.Subscription) subscriptionKey { return subscriptionKey{ Name: subscription.Name, Namespace: subscription.Namespace, From ad3970d3707b03f60d3aa18a113512b21a85a06b Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Fri, 1 Jun 2018 18:35:53 -0400 Subject: [PATCH 07/21] Shift burden of tracking subscriptions and stream to broker --- cmd/stub-broker/main.go | 122 +++++++++++----------- pkg/controller/stream/controller.go | 61 ----------- pkg/controller/subscription/controller.go | 59 +---------- 3 files changed, 64 insertions(+), 178 deletions(-) diff --git a/cmd/stub-broker/main.go b/cmd/stub-broker/main.go index 1dabff705b6..cfc753628db 100644 --- a/cmd/stub-broker/main.go +++ b/cmd/stub-broker/main.go @@ -18,19 +18,27 @@ package main import ( "bytes" + "flag" "fmt" "io/ioutil" "net/http" "os" "strings" + "time" "github.com/go-martini/martini" + "github.com/golang/glog" + eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + clientset "github.com/knative/eventing/pkg/client/clientset/versioned" + informers "github.com/knative/eventing/pkg/client/informers/externalversions" + "github.com/knative/eventing/pkg/subscription" + "k8s.io/client-go/tools/clientcmd" ) var ( - // TODO make thread safe - subscriptions = make(map[string]map[string]struct{}) - exists = struct{}{} + masterURL string + kubeconfig string + broker = os.Getenv("BROKER_NAME") forwardHeaders = []string{ "content-type", @@ -44,21 +52,55 @@ var ( } ) -func splitStreamName(host string) string { +func splitStreamName(host string) (string, string) { chunks := strings.Split(host, ".") stream := chunks[0] - return stream + namespace := chunks[1] + return stream, namespace } func main() { + flag.Parse() + + cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig) + if err != nil { + glog.Fatalf("Error building kubeconfig: %s", err.Error()) + } + + client, err := clientset.NewForConfig(cfg) + if err != nil { + glog.Fatalf("Error building clientset: %s", err.Error()) + } + + informerFactory := informers.NewSharedInformerFactory(client, time.Second*30) + monitor := subscription.NewMonitor(broker, informerFactory, subscription.MonitorEventHandlerFuncs{ + ProvisionFunc: func(stream eventingv1alpha1.Stream) { + fmt.Printf("Provision stream %q\n", stream.Name) + }, + UnprovisionFunc: func(stream eventingv1alpha1.Stream) { + fmt.Printf("Unprovision stream %q\n", stream.Name) + }, + SubscribeFunc: func(subscription eventingv1alpha1.Subscription) { + fmt.Printf("Subscribe %q to %q stream\n", subscription.Spec.Subscriber, subscription.Spec.Stream) + }, + UnsubscribeFunc: func(subscription eventingv1alpha1.Subscription) { + fmt.Printf("Unubscribe %q from %q stream\n", subscription.Spec.Subscriber, subscription.Spec.Stream) + }, + }) + + m := createServer(monitor) + m.Run() +} + +func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { m := martini.Classic() m.Post("/", func(req *http.Request, res http.ResponseWriter) { host := req.Host fmt.Printf("Recieved request for %s\n", host) - stream := splitStreamName(host) - subscribers, ok := subscriptions[stream] - if !ok { + stream, namespace := splitStreamName(host) + subscriptions := monitor.Subscriptions(stream, namespace) + if subscriptions == nil { res.WriteHeader(http.StatusNotFound) return } @@ -71,16 +113,18 @@ func main() { res.WriteHeader(http.StatusAccepted) go func() { - fmt.Printf("Making subscribed requests for %s\n", stream) + if len(*subscriptions) == 0 { + fmt.Printf("No subscribers for stream %q\n", stream) + } // make upstream requests client := &http.Client{} - for subscribed := range subscribers { - go func(subscribed string) { - fmt.Printf("Making subscribed request to %s for %s\n", subscribed, stream) + for _, subscription := range *subscriptions { + go func(subscriber string) { + fmt.Printf("Sending to %q for %q\n", subscriber, stream) - url := fmt.Sprintf("http://%s/", subscribed) + url := fmt.Sprintf("http://%s/", subscriber) request, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body)) if err != nil { fmt.Printf("Unable to create subscriber request %v", err) @@ -96,55 +140,15 @@ func main() { if err != nil { fmt.Printf("Unable to complete subscriber request %v", err) } - }(subscribed) + }(subscription.Subscriber) } }() }) - m.Group("/streams/:stream", func(r martini.Router) { - r.Put("", func(params martini.Params, res http.ResponseWriter) { - stream := params["stream"] - fmt.Printf("Create stream %s\n", stream) - if _, ok := subscriptions[stream]; !ok { - subscriptions[stream] = map[string]struct{}{} - } - res.WriteHeader(http.StatusAccepted) - }) - r.Delete("", func(params martini.Params, res http.ResponseWriter) { - stream := params["stream"] - fmt.Printf("Delete stream %s\n", stream) - delete(subscriptions, stream) - res.WriteHeader(http.StatusAccepted) - }) - - r.Group("/subscriptions/:subscription", func(r martini.Router) { - r.Put("", func(params martini.Params, res http.ResponseWriter) { - stream := params["stream"] - subscription := params["subscription"] - subscribers, ok := subscriptions[stream] - if !ok { - res.WriteHeader(http.StatusNotFound) - return - } - fmt.Printf("Create subscription %s for stream %s\n", subscription, stream) - // TODO store subscription params - subscribers[subscription] = exists - res.WriteHeader(http.StatusAccepted) - }) - r.Delete("", func(params martini.Params, res http.ResponseWriter) { - stream := params["stream"] - subscription := params["subscription"] - subscribers, ok := subscriptions[stream] - if !ok { - res.WriteHeader(http.StatusNotFound) - return - } - fmt.Printf("Delete subscription %s for stream %s\n", subscription, stream) - delete(subscribers, subscription) - res.WriteHeader(http.StatusAccepted) - }) - }) - }) + return m +} - m.Run() +func init() { + flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") + flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") } diff --git a/pkg/controller/stream/controller.go b/pkg/controller/stream/controller.go index b08ddfce1f7..194b8e16c5c 100644 --- a/pkg/controller/stream/controller.go +++ b/pkg/controller/stream/controller.go @@ -18,8 +18,6 @@ package stream import ( "fmt" - "net/http" - "strings" "time" "github.com/golang/glog" @@ -348,12 +346,6 @@ func (c *Controller) syncBrokeredStream(stream *eventingv1alpha1.Stream) (*istio if stream.Spec.Broker == "" { // If the resource exists, delete it if routerule != nil { - // Notify broker of stream removal - err = deleteBrokeredStream(routerule.Labels["broker"], stream) - if err != nil { - return routerule, err - } - // Remove RouteRule err = c.streamclientset.ConfigV1alpha2().RouteRules(stream.Namespace).Delete(routeruleName, nil) if err != nil { @@ -385,12 +377,6 @@ func (c *Controller) syncBrokeredStream(stream *eventingv1alpha1.Stream) (*istio return nil, fmt.Errorf(msg) } - // Notify broker of stream - err = provisionBrokeredStream(stream) - if err != nil { - return nil, err - } - return routerule, nil } @@ -603,50 +589,3 @@ func newIngress(stream *eventingv1alpha1.Stream) *extensionsv1beta1.Ingress { }, } } - -func provisionBrokeredStream(stream *eventingv1alpha1.Stream) error { - streamName := stream.Name - namespace := stream.Namespace - brokerName := stream.Spec.Broker - brokerServiceName := controller.BrokerServiceName(brokerName) - - client := &http.Client{} - url := fmt.Sprintf("http://%s.%s.svc.cluster.local/streams/%s", brokerServiceName, namespace, streamName) - fmt.Printf("Create stream at %s\n", url) - request, err := http.NewRequest(http.MethodPut, url, strings.NewReader("")) - if err != nil { - return err - } - response, err := client.Do(request) - if err != nil { - return err - } - if response.StatusCode < 200 || response.StatusCode >= 300 { - return fmt.Errorf("Unable to provision brokered stream %s on %s", streamName, brokerName) - } - - return nil -} - -func deleteBrokeredStream(brokerName string, stream *eventingv1alpha1.Stream) error { - streamName := stream.Name - namespace := stream.Namespace - brokerServiceName := controller.BrokerServiceName(brokerName) - - client := &http.Client{} - url := fmt.Sprintf("http://%s.%s.svc.cluster.local/streams/%s", brokerServiceName, namespace, streamName) - fmt.Printf("Delete stream at %s\n", url) - request, err := http.NewRequest(http.MethodDelete, url, strings.NewReader("")) - if err != nil { - return err - } - response, err := client.Do(request) - if err != nil { - return err - } - if response.StatusCode < 200 || response.StatusCode >= 300 { - return fmt.Errorf("Unable to delete brokered stream %s on %s", streamName, brokerName) - } - - return nil -} diff --git a/pkg/controller/subscription/controller.go b/pkg/controller/subscription/controller.go index 918f9ec60e9..b87330bd2b8 100644 --- a/pkg/controller/subscription/controller.go +++ b/pkg/controller/subscription/controller.go @@ -18,8 +18,6 @@ package subscription import ( "fmt" - "net/http" - "strings" "time" "github.com/golang/glog" @@ -278,13 +276,7 @@ func (c *Controller) syncHandler(key string) error { stream, err := c.streamsLister.Streams(namespace).Get(subscription.Spec.Stream) var brokerlessRouterule *istiov1alpha2.RouteRule - if stream.Spec.Broker != "" { - // TODO handle unsubscribe - err = subscribeBrokeredStream(stream.Spec.Broker, subscription) - if err != nil { - return err - } - } else { + if stream.Spec.Broker == "" { brokerlessRouterule, err = c.syncBrokerlessRouteRule(subscription) if err != nil { return err @@ -431,52 +423,3 @@ func newRouteRule(subscription *eventingv1alpha1.Subscription) *istiov1alpha2.Ro }, } } - -func subscribeBrokeredStream(brokerName string, subscription *eventingv1alpha1.Subscription) error { - streamName := subscription.Spec.Stream - subscriberName := subscription.Spec.Subscriber - namespace := subscription.Namespace - brokerServiceName := controller.BrokerServiceName(brokerName) - - client := &http.Client{} - // TODO pass subscriber and params in body, url should contain subscription name - url := fmt.Sprintf("http://%s.%s.svc.cluster.local/streams/%s/subscriptions/%s", brokerServiceName, namespace, streamName, subscriberName) - fmt.Printf("Subscribe %s to stream %s at %s\n", subscriberName, streamName, url) - request, err := http.NewRequest(http.MethodPut, url, strings.NewReader("")) - if err != nil { - return err - } - response, err := client.Do(request) - if err != nil { - return err - } - if response.StatusCode < 200 || response.StatusCode >= 300 { - return fmt.Errorf("Unable to subscribe %s to brokered stream %s on %s", subscriberName, streamName, brokerName) - } - - return nil -} - -func unsubscribeBrokeredStream(brokerName string, subscription *eventingv1alpha1.Subscription) error { - streamName := subscription.Spec.Stream - subscriberName := subscription.Spec.Subscriber - namespace := subscription.Namespace - brokerServiceName := controller.BrokerServiceName(brokerName) - - client := &http.Client{} - url := fmt.Sprintf("http://%s.%s.svc.cluster.local/streams/%s/subscriptions/%s", brokerServiceName, namespace, streamName, subscriberName) - fmt.Printf("Unsubscribe %s from stream %s at %s\n", subscriberName, streamName, url) - request, err := http.NewRequest(http.MethodDelete, url, strings.NewReader("")) - if err != nil { - return err - } - response, err := client.Do(request) - if err != nil { - return err - } - if response.StatusCode < 200 || response.StatusCode >= 300 { - return fmt.Errorf("Unable to unsubscribe %s from brokered stream %s on %s", subscriberName, streamName, brokerName) - } - - return nil -} From 1069cdaa73d201692425ca305d93baa3c890e8b3 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Tue, 5 Jun 2018 16:21:32 -0400 Subject: [PATCH 08/21] Cleanup lingering CRD group names --- sample/square/square-brokered.yaml | 4 ++-- sample/square/square-brokerless.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sample/square/square-brokered.yaml b/sample/square/square-brokered.yaml index 2f8bd1ed0e4..d9a18c79497 100644 --- a/sample/square/square-brokered.yaml +++ b/sample/square/square-brokered.yaml @@ -1,4 +1,4 @@ -apiVersion: eventing.elafros.dev/v1alpha1 +apiVersion: eventing.knative.dev/v1alpha1 kind: Stream metadata: name: square @@ -6,7 +6,7 @@ spec: broker: stub --- -apiVersion: eventing.elafros.dev/v1alpha1 +apiVersion: eventing.knative.dev/v1alpha1 kind: Subscription metadata: name: square diff --git a/sample/square/square-brokerless.yaml b/sample/square/square-brokerless.yaml index 9d152b037c0..8762b54281f 100644 --- a/sample/square/square-brokerless.yaml +++ b/sample/square/square-brokerless.yaml @@ -1,10 +1,10 @@ -apiVersion: eventing.elafros.dev/v1alpha1 +apiVersion: eventing.knative.dev/v1alpha1 kind: Stream metadata: name: square --- -apiVersion: eventing.elafros.dev/v1alpha1 +apiVersion: eventing.knative.dev/v1alpha1 kind: Subscription metadata: name: square From dcbab6a0743730d6ed1265ab21ea50cdd895d486 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Tue, 5 Jun 2018 16:47:04 -0400 Subject: [PATCH 09/21] Rename Stream to Channel --- cmd/controller/main.go | 4 +- cmd/stub-broker/main.go | 28 +-- config/stream.yaml | 8 +- .../{stream_types.go => channel_types.go} | 22 +- pkg/apis/eventing/v1alpha1/register.go | 4 +- .../eventing/v1alpha1/subscription_types.go | 4 +- .../v1alpha1/zz_generated.deepcopy.go | 202 +++++++-------- .../typed/eventing/v1alpha1/channel.go | 157 ++++++++++++ .../eventing/v1alpha1/eventing_client.go | 10 +- .../eventing/v1alpha1/fake/fake_channel.go | 128 ++++++++++ .../v1alpha1/fake/fake_eventing_client.go | 8 +- .../eventing/v1alpha1/fake/fake_stream.go | 128 ---------- .../eventing/v1alpha1/generated_expansion.go | 4 +- .../typed/eventing/v1alpha1/stream.go | 157 ------------ .../v1alpha1/{stream.go => channel.go} | 38 +-- .../eventing/v1alpha1/interface.go | 14 +- .../informers/externalversions/generic.go | 4 +- .../listers/eventing/v1alpha1/channel.go | 94 +++++++ .../eventing/v1alpha1/expansion_generated.go | 16 +- .../listers/eventing/v1alpha1/stream.go | 94 ------- pkg/controller/broker/controller.go | 4 +- .../{stream => channel}/controller.go | 234 +++++++++--------- pkg/controller/names.go | 12 +- pkg/controller/subscription/controller.go | 16 +- pkg/subscription/monitor.go | 108 ++++---- sample/hello/hello-channel.yaml | 13 + sample/hello/hello-stream.yaml | 13 - sample/square/square-brokered.yaml | 4 +- sample/square/square-brokerless.yaml | 4 +- 29 files changed, 766 insertions(+), 766 deletions(-) rename pkg/apis/eventing/v1alpha1/{stream_types.go => channel_types.go} (71%) create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/channel.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go delete mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_stream.go delete mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/stream.go rename pkg/client/informers/externalversions/eventing/v1alpha1/{stream.go => channel.go} (58%) create mode 100644 pkg/client/listers/eventing/v1alpha1/channel.go delete mode 100644 pkg/client/listers/eventing/v1alpha1/stream.go rename pkg/controller/{stream => channel}/controller.go (67%) create mode 100644 sample/hello/hello-channel.yaml delete mode 100644 sample/hello/hello-stream.yaml diff --git a/cmd/controller/main.go b/cmd/controller/main.go index be926c9d9e4..6cbd6409833 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -37,7 +37,7 @@ import ( "github.com/knative/eventing/pkg/controller" "github.com/knative/eventing/pkg/controller/bind" "github.com/knative/eventing/pkg/controller/broker" - "github.com/knative/eventing/pkg/controller/stream" + "github.com/knative/eventing/pkg/controller/channel" "github.com/knative/eventing/pkg/controller/subscription" "github.com/knative/eventing/pkg/signals" @@ -89,7 +89,7 @@ func main() { ctors := []controller.Constructor{ bind.NewController, broker.NewController, - stream.NewController, + channel.NewController, subscription.NewController, } diff --git a/cmd/stub-broker/main.go b/cmd/stub-broker/main.go index cfc753628db..032a467799e 100644 --- a/cmd/stub-broker/main.go +++ b/cmd/stub-broker/main.go @@ -52,11 +52,11 @@ var ( } ) -func splitStreamName(host string) (string, string) { +func splitChannelName(host string) (string, string) { chunks := strings.Split(host, ".") - stream := chunks[0] + channel := chunks[0] namespace := chunks[1] - return stream, namespace + return channel, namespace } func main() { @@ -74,17 +74,17 @@ func main() { informerFactory := informers.NewSharedInformerFactory(client, time.Second*30) monitor := subscription.NewMonitor(broker, informerFactory, subscription.MonitorEventHandlerFuncs{ - ProvisionFunc: func(stream eventingv1alpha1.Stream) { - fmt.Printf("Provision stream %q\n", stream.Name) + ProvisionFunc: func(channel eventingv1alpha1.Channel) { + fmt.Printf("Provision channel %q\n", channel.Name) }, - UnprovisionFunc: func(stream eventingv1alpha1.Stream) { - fmt.Printf("Unprovision stream %q\n", stream.Name) + UnprovisionFunc: func(channel eventingv1alpha1.Channel) { + fmt.Printf("Unprovision channel %q\n", channel.Name) }, SubscribeFunc: func(subscription eventingv1alpha1.Subscription) { - fmt.Printf("Subscribe %q to %q stream\n", subscription.Spec.Subscriber, subscription.Spec.Stream) + fmt.Printf("Subscribe %q to %q channel\n", subscription.Spec.Subscriber, subscription.Spec.Channel) }, UnsubscribeFunc: func(subscription eventingv1alpha1.Subscription) { - fmt.Printf("Unubscribe %q from %q stream\n", subscription.Spec.Subscriber, subscription.Spec.Stream) + fmt.Printf("Unubscribe %q from %q channel\n", subscription.Spec.Subscriber, subscription.Spec.Channel) }, }) @@ -98,8 +98,8 @@ func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { m.Post("/", func(req *http.Request, res http.ResponseWriter) { host := req.Host fmt.Printf("Recieved request for %s\n", host) - stream, namespace := splitStreamName(host) - subscriptions := monitor.Subscriptions(stream, namespace) + channel, namespace := splitChannelName(host) + subscriptions := monitor.Subscriptions(channel, namespace) if subscriptions == nil { res.WriteHeader(http.StatusNotFound) return @@ -114,7 +114,7 @@ func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { res.WriteHeader(http.StatusAccepted) go func() { if len(*subscriptions) == 0 { - fmt.Printf("No subscribers for stream %q\n", stream) + fmt.Printf("No subscribers for channel %q\n", channel) } // make upstream requests @@ -122,7 +122,7 @@ func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { for _, subscription := range *subscriptions { go func(subscriber string) { - fmt.Printf("Sending to %q for %q\n", subscriber, stream) + fmt.Printf("Sending to %q for %q\n", subscriber, channel) url := fmt.Sprintf("http://%s/", subscriber) request, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body)) @@ -130,7 +130,7 @@ func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { fmt.Printf("Unable to create subscriber request %v", err) } request.Header.Set("x-broker", broker) - request.Header.Set("x-stream", stream) + request.Header.Set("x-channel", channel) for _, header := range forwardHeaders { if value := req.Header.Get(header); value != "" { request.Header.Set(header, value) diff --git a/config/stream.yaml b/config/stream.yaml index 5a578cd6d64..692ebaf2c69 100644 --- a/config/stream.yaml +++ b/config/stream.yaml @@ -1,12 +1,12 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: streams.eventing.knative.dev + name: channels.eventing.knative.dev spec: scope: Namespaced group: eventing.knative.dev version: v1alpha1 names: - kind: Stream - plural: streams - singular: stream + kind: Channel + plural: channels + singular: channel diff --git a/pkg/apis/eventing/v1alpha1/stream_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go similarity index 71% rename from pkg/apis/eventing/v1alpha1/stream_types.go rename to pkg/apis/eventing/v1alpha1/channel_types.go index 0fb16a31e91..3fa6c221950 100644 --- a/pkg/apis/eventing/v1alpha1/stream_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -25,30 +25,30 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the streams.eventing.dev CRD -type Stream struct { +// Represents the channels.eventing.dev CRD +type Channel struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` - Spec StreamSpec `json:"spec"` - Status *StreamStatus `json:"status,omitempty"` + Spec ChannelSpec `json:"spec"` + Status *ChannelStatus `json:"status,omitempty"` } -// Spec (what the user wants) for a stream -type StreamSpec struct { +// Spec (what the user wants) for a channel +type ChannelSpec struct { - // Name of the broker backing this stream (optional) + // Name of the broker backing this channel (optional) Broker string } -// Status (computed) for a stream -type StreamStatus struct { +// Status (computed) for a channel +type ChannelStatus struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // Returned in list operations -type StreamList struct { +type ChannelList struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ListMeta `json:"metadata"` - Items []Stream `json:"items"` + Items []Channel `json:"items"` } diff --git a/pkg/apis/eventing/v1alpha1/register.go b/pkg/apis/eventing/v1alpha1/register.go index 06cb83f374f..fc9622f4655 100644 --- a/pkg/apis/eventing/v1alpha1/register.go +++ b/pkg/apis/eventing/v1alpha1/register.go @@ -49,12 +49,12 @@ func addKnownTypes(scheme *runtime.Scheme) error { &BindList{}, &Broker{}, &BrokerList{}, + &Channel{}, + &ChannelList{}, &EventSource{}, &EventSourceList{}, &EventType{}, &EventTypeList{}, - &Stream{}, - &StreamList{}, &Subscription{}, &SubscriptionList{}, ) diff --git a/pkg/apis/eventing/v1alpha1/subscription_types.go b/pkg/apis/eventing/v1alpha1/subscription_types.go index 0760a08c48a..12d4608f9f4 100644 --- a/pkg/apis/eventing/v1alpha1/subscription_types.go +++ b/pkg/apis/eventing/v1alpha1/subscription_types.go @@ -36,8 +36,8 @@ type Subscription struct { // Spec (what the user wants) for a subscription type SubscriptionSpec struct { - // Name of the stream to subscribe to - Stream string `json:"stream"` + // Name of the channel to subscribe to + Channel string `json:"channel"` // Name of the subscriber service Subscriber string `json:"subscriber"` diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index 63ecaf8a580..8d8348e61fb 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -267,6 +267,107 @@ func (in *BrokerStatus) DeepCopy() *BrokerStatus { return out } +// 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) + out.Spec = in.Spec + if in.Status != nil { + in, out := &in.Status, &out.Status + if *in == nil { + *out = nil + } else { + *out = new(ChannelStatus) + **out = **in + } + } + 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 +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Channel) 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 *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 + 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 *ChannelStatus) DeepCopyInto(out *ChannelStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelStatus. +func (in *ChannelStatus) DeepCopy() *ChannelStatus { + if in == nil { + return nil + } + out := new(ChannelStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EventSource) DeepCopyInto(out *EventSource) { *out = *in @@ -595,107 +696,6 @@ func (in *SecretKeyReference) DeepCopy() *SecretKeyReference { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Stream) DeepCopyInto(out *Stream) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - if in.Status != nil { - in, out := &in.Status, &out.Status - if *in == nil { - *out = nil - } else { - *out = new(StreamStatus) - **out = **in - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Stream. -func (in *Stream) DeepCopy() *Stream { - if in == nil { - return nil - } - out := new(Stream) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Stream) 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 *StreamList) DeepCopyInto(out *StreamList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Stream, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StreamList. -func (in *StreamList) DeepCopy() *StreamList { - if in == nil { - return nil - } - out := new(StreamList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *StreamList) 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 *StreamSpec) DeepCopyInto(out *StreamSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StreamSpec. -func (in *StreamSpec) DeepCopy() *StreamSpec { - if in == nil { - return nil - } - out := new(StreamSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StreamStatus) DeepCopyInto(out *StreamStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StreamStatus. -func (in *StreamStatus) DeepCopy() *StreamStatus { - if in == nil { - return nil - } - out := new(StreamStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Subscription) DeepCopyInto(out *Subscription) { *out = *in diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/channel.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/channel.go new file mode 100644 index 00000000000..44a20ab6d38 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/channel.go @@ -0,0 +1,157 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// ChannelsGetter has a method to return a ChannelInterface. +// A group's client should implement this interface. +type ChannelsGetter interface { + Channels(namespace string) ChannelInterface +} + +// ChannelInterface has methods to work with Channel resources. +type ChannelInterface interface { + Create(*v1alpha1.Channel) (*v1alpha1.Channel, error) + Update(*v1alpha1.Channel) (*v1alpha1.Channel, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.Channel, error) + List(opts v1.ListOptions) (*v1alpha1.ChannelList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Channel, err error) + ChannelExpansion +} + +// channels implements ChannelInterface +type channels struct { + client rest.Interface + ns string +} + +// newChannels returns a Channels +func newChannels(c *EventingV1alpha1Client, namespace string) *channels { + return &channels{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the channel, and returns the corresponding channel object, and an error if there is any. +func (c *channels) Get(name string, options v1.GetOptions) (result *v1alpha1.Channel, err error) { + result = &v1alpha1.Channel{} + err = c.client.Get(). + Namespace(c.ns). + Resource("channels"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Channels that match those selectors. +func (c *channels) List(opts v1.ListOptions) (result *v1alpha1.ChannelList, err error) { + result = &v1alpha1.ChannelList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("channels"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested channels. +func (c *channels) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("channels"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a channel and creates it. Returns the server's representation of the channel, and an error, if there is any. +func (c *channels) Create(channel *v1alpha1.Channel) (result *v1alpha1.Channel, err error) { + result = &v1alpha1.Channel{} + err = c.client.Post(). + Namespace(c.ns). + Resource("channels"). + Body(channel). + Do(). + Into(result) + return +} + +// Update takes the representation of a channel and updates it. Returns the server's representation of the channel, and an error, if there is any. +func (c *channels) Update(channel *v1alpha1.Channel) (result *v1alpha1.Channel, err error) { + result = &v1alpha1.Channel{} + err = c.client.Put(). + Namespace(c.ns). + Resource("channels"). + Name(channel.Name). + Body(channel). + Do(). + Into(result) + return +} + +// Delete takes name of the channel and deletes it. Returns an error if one occurs. +func (c *channels) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("channels"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *channels) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("channels"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched channel. +func (c *channels) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Channel, err error) { + result = &v1alpha1.Channel{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("channels"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go index eeeb1290c98..60066f9b70e 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go @@ -29,9 +29,9 @@ type EventingV1alpha1Interface interface { RESTClient() rest.Interface BindsGetter BrokersGetter + ChannelsGetter EventSourcesGetter EventTypesGetter - StreamsGetter SubscriptionsGetter } @@ -48,6 +48,10 @@ func (c *EventingV1alpha1Client) Brokers(namespace string) BrokerInterface { return newBrokers(c, namespace) } +func (c *EventingV1alpha1Client) Channels(namespace string) ChannelInterface { + return newChannels(c, namespace) +} + func (c *EventingV1alpha1Client) EventSources(namespace string) EventSourceInterface { return newEventSources(c, namespace) } @@ -56,10 +60,6 @@ func (c *EventingV1alpha1Client) EventTypes(namespace string) EventTypeInterface return newEventTypes(c, namespace) } -func (c *EventingV1alpha1Client) Streams(namespace string) StreamInterface { - return newStreams(c, namespace) -} - func (c *EventingV1alpha1Client) Subscriptions(namespace string) SubscriptionInterface { return newSubscriptions(c, namespace) } diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go new file mode 100644 index 00000000000..a048fd78be2 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go @@ -0,0 +1,128 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeChannels implements ChannelInterface +type FakeChannels struct { + Fake *FakeEventingV1alpha1 + ns string +} + +var channelsResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "channels"} + +var channelsKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Channel"} + +// Get takes name of the channel, and returns the corresponding channel object, and an error if there is any. +func (c *FakeChannels) Get(name string, options v1.GetOptions) (result *v1alpha1.Channel, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(channelsResource, c.ns, name), &v1alpha1.Channel{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Channel), err +} + +// List takes label and field selectors, and returns the list of Channels that match those selectors. +func (c *FakeChannels) List(opts v1.ListOptions) (result *v1alpha1.ChannelList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(channelsResource, channelsKind, c.ns, opts), &v1alpha1.ChannelList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.ChannelList{} + for _, item := range obj.(*v1alpha1.ChannelList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested channels. +func (c *FakeChannels) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(channelsResource, c.ns, opts)) + +} + +// Create takes the representation of a channel and creates it. Returns the server's representation of the channel, and an error, if there is any. +func (c *FakeChannels) Create(channel *v1alpha1.Channel) (result *v1alpha1.Channel, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(channelsResource, c.ns, channel), &v1alpha1.Channel{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Channel), err +} + +// Update takes the representation of a channel and updates it. Returns the server's representation of the channel, and an error, if there is any. +func (c *FakeChannels) Update(channel *v1alpha1.Channel) (result *v1alpha1.Channel, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(channelsResource, c.ns, channel), &v1alpha1.Channel{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Channel), err +} + +// Delete takes name of the channel and deletes it. Returns an error if one occurs. +func (c *FakeChannels) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(channelsResource, c.ns, name), &v1alpha1.Channel{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeChannels) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(channelsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.ChannelList{}) + return err +} + +// Patch applies the patch and returns the patched channel. +func (c *FakeChannels) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Channel, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(channelsResource, c.ns, name, data, subresources...), &v1alpha1.Channel{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Channel), err +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go index b8ea29cb152..ca0f1e21270 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go @@ -36,6 +36,10 @@ func (c *FakeEventingV1alpha1) Brokers(namespace string) v1alpha1.BrokerInterfac return &FakeBrokers{c, namespace} } +func (c *FakeEventingV1alpha1) Channels(namespace string) v1alpha1.ChannelInterface { + return &FakeChannels{c, namespace} +} + func (c *FakeEventingV1alpha1) EventSources(namespace string) v1alpha1.EventSourceInterface { return &FakeEventSources{c, namespace} } @@ -44,10 +48,6 @@ func (c *FakeEventingV1alpha1) EventTypes(namespace string) v1alpha1.EventTypeIn return &FakeEventTypes{c, namespace} } -func (c *FakeEventingV1alpha1) Streams(namespace string) v1alpha1.StreamInterface { - return &FakeStreams{c, namespace} -} - func (c *FakeEventingV1alpha1) Subscriptions(namespace string) v1alpha1.SubscriptionInterface { return &FakeSubscriptions{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_stream.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_stream.go deleted file mode 100644 index 3b4d5c50ec4..00000000000 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_stream.go +++ /dev/null @@ -1,128 +0,0 @@ -/* -Copyright 2018 Google, Inc. All rights reserved. - -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 client-gen. DO NOT EDIT. - -package fake - -import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakeStreams implements StreamInterface -type FakeStreams struct { - Fake *FakeEventingV1alpha1 - ns string -} - -var streamsResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "streams"} - -var streamsKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Stream"} - -// Get takes name of the stream, and returns the corresponding stream object, and an error if there is any. -func (c *FakeStreams) Get(name string, options v1.GetOptions) (result *v1alpha1.Stream, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(streamsResource, c.ns, name), &v1alpha1.Stream{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Stream), err -} - -// List takes label and field selectors, and returns the list of Streams that match those selectors. -func (c *FakeStreams) List(opts v1.ListOptions) (result *v1alpha1.StreamList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(streamsResource, streamsKind, c.ns, opts), &v1alpha1.StreamList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.StreamList{} - for _, item := range obj.(*v1alpha1.StreamList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested streams. -func (c *FakeStreams) Watch(opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(streamsResource, c.ns, opts)) - -} - -// Create takes the representation of a stream and creates it. Returns the server's representation of the stream, and an error, if there is any. -func (c *FakeStreams) Create(stream *v1alpha1.Stream) (result *v1alpha1.Stream, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(streamsResource, c.ns, stream), &v1alpha1.Stream{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Stream), err -} - -// Update takes the representation of a stream and updates it. Returns the server's representation of the stream, and an error, if there is any. -func (c *FakeStreams) Update(stream *v1alpha1.Stream) (result *v1alpha1.Stream, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(streamsResource, c.ns, stream), &v1alpha1.Stream{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Stream), err -} - -// Delete takes name of the stream and deletes it. Returns an error if one occurs. -func (c *FakeStreams) Delete(name string, options *v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(streamsResource, c.ns, name), &v1alpha1.Stream{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeStreams) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(streamsResource, c.ns, listOptions) - - _, err := c.Fake.Invokes(action, &v1alpha1.StreamList{}) - return err -} - -// Patch applies the patch and returns the patched stream. -func (c *FakeStreams) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Stream, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(streamsResource, c.ns, name, data, subresources...), &v1alpha1.Stream{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Stream), err -} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go index 74c67fb4a34..25501bae84e 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go @@ -22,10 +22,10 @@ type BindExpansion interface{} type BrokerExpansion interface{} +type ChannelExpansion interface{} + type EventSourceExpansion interface{} type EventTypeExpansion interface{} -type StreamExpansion interface{} - type SubscriptionExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/stream.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/stream.go deleted file mode 100644 index 39d3571b74a..00000000000 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/stream.go +++ /dev/null @@ -1,157 +0,0 @@ -/* -Copyright 2018 Google, Inc. All rights reserved. - -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 client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" - scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" -) - -// StreamsGetter has a method to return a StreamInterface. -// A group's client should implement this interface. -type StreamsGetter interface { - Streams(namespace string) StreamInterface -} - -// StreamInterface has methods to work with Stream resources. -type StreamInterface interface { - Create(*v1alpha1.Stream) (*v1alpha1.Stream, error) - Update(*v1alpha1.Stream) (*v1alpha1.Stream, error) - Delete(name string, options *v1.DeleteOptions) error - DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error - Get(name string, options v1.GetOptions) (*v1alpha1.Stream, error) - List(opts v1.ListOptions) (*v1alpha1.StreamList, error) - Watch(opts v1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Stream, err error) - StreamExpansion -} - -// streams implements StreamInterface -type streams struct { - client rest.Interface - ns string -} - -// newStreams returns a Streams -func newStreams(c *EventingV1alpha1Client, namespace string) *streams { - return &streams{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the stream, and returns the corresponding stream object, and an error if there is any. -func (c *streams) Get(name string, options v1.GetOptions) (result *v1alpha1.Stream, err error) { - result = &v1alpha1.Stream{} - err = c.client.Get(). - Namespace(c.ns). - Resource("streams"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Streams that match those selectors. -func (c *streams) List(opts v1.ListOptions) (result *v1alpha1.StreamList, err error) { - result = &v1alpha1.StreamList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("streams"). - VersionedParams(&opts, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested streams. -func (c *streams) Watch(opts v1.ListOptions) (watch.Interface, error) { - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("streams"). - VersionedParams(&opts, scheme.ParameterCodec). - Watch() -} - -// Create takes the representation of a stream and creates it. Returns the server's representation of the stream, and an error, if there is any. -func (c *streams) Create(stream *v1alpha1.Stream) (result *v1alpha1.Stream, err error) { - result = &v1alpha1.Stream{} - err = c.client.Post(). - Namespace(c.ns). - Resource("streams"). - Body(stream). - Do(). - Into(result) - return -} - -// Update takes the representation of a stream and updates it. Returns the server's representation of the stream, and an error, if there is any. -func (c *streams) Update(stream *v1alpha1.Stream) (result *v1alpha1.Stream, err error) { - result = &v1alpha1.Stream{} - err = c.client.Put(). - Namespace(c.ns). - Resource("streams"). - Name(stream.Name). - Body(stream). - Do(). - Into(result) - return -} - -// Delete takes name of the stream and deletes it. Returns an error if one occurs. -func (c *streams) Delete(name string, options *v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("streams"). - Name(name). - Body(options). - Do(). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *streams) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("streams"). - VersionedParams(&listOptions, scheme.ParameterCodec). - Body(options). - Do(). - Error() -} - -// Patch applies the patch and returns the patched stream. -func (c *streams) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Stream, err error) { - result = &v1alpha1.Stream{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("streams"). - SubResource(subresources...). - Name(name). - Body(data). - Do(). - Into(result) - return -} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/stream.go b/pkg/client/informers/externalversions/eventing/v1alpha1/channel.go similarity index 58% rename from pkg/client/informers/externalversions/eventing/v1alpha1/stream.go rename to pkg/client/informers/externalversions/eventing/v1alpha1/channel.go index e73255c8836..4655635cbb6 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/stream.go +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/channel.go @@ -31,59 +31,59 @@ import ( cache "k8s.io/client-go/tools/cache" ) -// StreamInformer provides access to a shared informer and lister for -// Streams. -type StreamInformer interface { +// ChannelInformer provides access to a shared informer and lister for +// Channels. +type ChannelInformer interface { Informer() cache.SharedIndexInformer - Lister() v1alpha1.StreamLister + Lister() v1alpha1.ChannelLister } -type streamInformer struct { +type channelInformer struct { factory internalinterfaces.SharedInformerFactory tweakListOptions internalinterfaces.TweakListOptionsFunc namespace string } -// NewStreamInformer constructs a new informer for Stream type. +// NewChannelInformer constructs a new informer for Channel type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewStreamInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredStreamInformer(client, namespace, resyncPeriod, indexers, nil) +func NewChannelInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredChannelInformer(client, namespace, resyncPeriod, indexers, nil) } -// NewFilteredStreamInformer constructs a new informer for Stream type. +// NewFilteredChannelInformer constructs a new informer for Channel type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredStreamInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredChannelInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Streams(namespace).List(options) + return client.EventingV1alpha1().Channels(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Streams(namespace).Watch(options) + return client.EventingV1alpha1().Channels(namespace).Watch(options) }, }, - &eventing_v1alpha1.Stream{}, + &eventing_v1alpha1.Channel{}, resyncPeriod, indexers, ) } -func (f *streamInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredStreamInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +func (f *channelInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredChannelInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) } -func (f *streamInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventing_v1alpha1.Stream{}, f.defaultInformer) +func (f *channelInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&eventing_v1alpha1.Channel{}, f.defaultInformer) } -func (f *streamInformer) Lister() v1alpha1.StreamLister { - return v1alpha1.NewStreamLister(f.Informer().GetIndexer()) +func (f *channelInformer) Lister() v1alpha1.ChannelLister { + return v1alpha1.NewChannelLister(f.Informer().GetIndexer()) } diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go b/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go index 2c361ab6f07..d0ad39ab74b 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go @@ -28,12 +28,12 @@ type Interface interface { Binds() BindInformer // Brokers returns a BrokerInformer. Brokers() BrokerInformer + // Channels returns a ChannelInformer. + Channels() ChannelInformer // EventSources returns a EventSourceInformer. EventSources() EventSourceInformer // EventTypes returns a EventTypeInformer. EventTypes() EventTypeInformer - // Streams returns a StreamInformer. - Streams() StreamInformer // Subscriptions returns a SubscriptionInformer. Subscriptions() SubscriptionInformer } @@ -59,6 +59,11 @@ func (v *version) Brokers() BrokerInformer { return &brokerInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } +// Channels returns a ChannelInformer. +func (v *version) Channels() ChannelInformer { + return &channelInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // EventSources returns a EventSourceInformer. func (v *version) EventSources() EventSourceInformer { return &eventSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} @@ -69,11 +74,6 @@ func (v *version) EventTypes() EventTypeInformer { return &eventTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } -// Streams returns a StreamInformer. -func (v *version) Streams() StreamInformer { - return &streamInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - // Subscriptions returns a SubscriptionInformer. func (v *version) Subscriptions() SubscriptionInformer { return &subscriptionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 4bffd298e05..1319d2aafe0 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -62,12 +62,12 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Binds().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("brokers"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Brokers().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("channels"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Channels().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("eventsources"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().EventSources().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("eventtypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().EventTypes().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("streams"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Streams().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("subscriptions"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Subscriptions().Informer()}, nil diff --git a/pkg/client/listers/eventing/v1alpha1/channel.go b/pkg/client/listers/eventing/v1alpha1/channel.go new file mode 100644 index 00000000000..35eeeb81475 --- /dev/null +++ b/pkg/client/listers/eventing/v1alpha1/channel.go @@ -0,0 +1,94 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// ChannelLister helps list Channels. +type ChannelLister interface { + // List lists all Channels in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.Channel, err error) + // Channels returns an object that can list and get Channels. + Channels(namespace string) ChannelNamespaceLister + ChannelListerExpansion +} + +// channelLister implements the ChannelLister interface. +type channelLister struct { + indexer cache.Indexer +} + +// NewChannelLister returns a new ChannelLister. +func NewChannelLister(indexer cache.Indexer) ChannelLister { + return &channelLister{indexer: indexer} +} + +// List lists all Channels in the indexer. +func (s *channelLister) List(selector labels.Selector) (ret []*v1alpha1.Channel, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Channel)) + }) + return ret, err +} + +// Channels returns an object that can list and get Channels. +func (s *channelLister) Channels(namespace string) ChannelNamespaceLister { + return channelNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// ChannelNamespaceLister helps list and get Channels. +type ChannelNamespaceLister interface { + // List lists all Channels in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.Channel, err error) + // Get retrieves the Channel from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.Channel, error) + ChannelNamespaceListerExpansion +} + +// channelNamespaceLister implements the ChannelNamespaceLister +// interface. +type channelNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Channels in the indexer for a given namespace. +func (s channelNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Channel, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Channel)) + }) + return ret, err +} + +// Get retrieves the Channel from the indexer for a given namespace and name. +func (s channelNamespaceLister) Get(name string) (*v1alpha1.Channel, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("channel"), name) + } + return obj.(*v1alpha1.Channel), nil +} diff --git a/pkg/client/listers/eventing/v1alpha1/expansion_generated.go b/pkg/client/listers/eventing/v1alpha1/expansion_generated.go index e478cff6ffd..36c399412ab 100644 --- a/pkg/client/listers/eventing/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/eventing/v1alpha1/expansion_generated.go @@ -34,6 +34,14 @@ type BrokerListerExpansion interface{} // BrokerNamespaceLister. type BrokerNamespaceListerExpansion interface{} +// ChannelListerExpansion allows custom methods to be added to +// ChannelLister. +type ChannelListerExpansion interface{} + +// ChannelNamespaceListerExpansion allows custom methods to be added to +// ChannelNamespaceLister. +type ChannelNamespaceListerExpansion interface{} + // EventSourceListerExpansion allows custom methods to be added to // EventSourceLister. type EventSourceListerExpansion interface{} @@ -50,14 +58,6 @@ type EventTypeListerExpansion interface{} // EventTypeNamespaceLister. type EventTypeNamespaceListerExpansion interface{} -// StreamListerExpansion allows custom methods to be added to -// StreamLister. -type StreamListerExpansion interface{} - -// StreamNamespaceListerExpansion allows custom methods to be added to -// StreamNamespaceLister. -type StreamNamespaceListerExpansion interface{} - // SubscriptionListerExpansion allows custom methods to be added to // SubscriptionLister. type SubscriptionListerExpansion interface{} diff --git a/pkg/client/listers/eventing/v1alpha1/stream.go b/pkg/client/listers/eventing/v1alpha1/stream.go deleted file mode 100644 index f06bb31c7e0..00000000000 --- a/pkg/client/listers/eventing/v1alpha1/stream.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2018 Google, Inc. All rights reserved. - -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 lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// StreamLister helps list Streams. -type StreamLister interface { - // List lists all Streams in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.Stream, err error) - // Streams returns an object that can list and get Streams. - Streams(namespace string) StreamNamespaceLister - StreamListerExpansion -} - -// streamLister implements the StreamLister interface. -type streamLister struct { - indexer cache.Indexer -} - -// NewStreamLister returns a new StreamLister. -func NewStreamLister(indexer cache.Indexer) StreamLister { - return &streamLister{indexer: indexer} -} - -// List lists all Streams in the indexer. -func (s *streamLister) List(selector labels.Selector) (ret []*v1alpha1.Stream, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Stream)) - }) - return ret, err -} - -// Streams returns an object that can list and get Streams. -func (s *streamLister) Streams(namespace string) StreamNamespaceLister { - return streamNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// StreamNamespaceLister helps list and get Streams. -type StreamNamespaceLister interface { - // List lists all Streams in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.Stream, err error) - // Get retrieves the Stream from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.Stream, error) - StreamNamespaceListerExpansion -} - -// streamNamespaceLister implements the StreamNamespaceLister -// interface. -type streamNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Streams in the indexer for a given namespace. -func (s streamNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Stream, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Stream)) - }) - return ret, err -} - -// Get retrieves the Stream from the indexer for a given namespace and name. -func (s streamNamespaceLister) Get(name string) (*v1alpha1.Stream, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("stream"), name) - } - return obj.(*v1alpha1.Stream), nil -} diff --git a/pkg/controller/broker/controller.go b/pkg/controller/broker/controller.go index 15a3f1ef580..0e2535abab5 100644 --- a/pkg/controller/broker/controller.go +++ b/pkg/controller/broker/controller.go @@ -42,7 +42,7 @@ import ( "k8s.io/client-go/util/workqueue" clientset "github.com/knative/eventing/pkg/client/clientset/versioned" - streamscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + channelscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" informers "github.com/knative/eventing/pkg/client/informers/externalversions" listers "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" elainformers "github.com/knative/serving/pkg/client/informers/externalversions" @@ -109,7 +109,7 @@ func NewController( // Create event broadcaster // Add broker-controller types to the default Kubernetes Scheme so Events can be // logged for broker-controller types. - streamscheme.AddToScheme(scheme.Scheme) + channelscheme.AddToScheme(scheme.Scheme) glog.V(4).Info("Creating event broadcaster") eventBroadcaster := record.NewBroadcaster() eventBroadcaster.StartLogging(glog.Infof) diff --git a/pkg/controller/stream/controller.go b/pkg/controller/channel/controller.go similarity index 67% rename from pkg/controller/stream/controller.go rename to pkg/controller/channel/controller.go index 194b8e16c5c..c4282546ca7 100644 --- a/pkg/controller/stream/controller.go +++ b/pkg/controller/channel/controller.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package stream +package channel import ( "fmt" @@ -42,7 +42,7 @@ import ( "k8s.io/client-go/util/workqueue" clientset "github.com/knative/eventing/pkg/client/clientset/versioned" - streamscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + channelscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" informers "github.com/knative/eventing/pkg/client/informers/externalversions" listers "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" elainformers "github.com/knative/serving/pkg/client/informers/externalversions" @@ -51,29 +51,29 @@ import ( istiov1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" ) -const controllerAgentName = "stream-controller" +const controllerAgentName = "channel-controller" const ( - // SuccessSynced is used as part of the Event 'reason' when a Stream is synced + // SuccessSynced is used as part of the Event 'reason' when a Channel is synced SuccessSynced = "Synced" - // ErrResourceExists is used as part of the Event 'reason' when a Stream fails + // ErrResourceExists is used as part of the Event 'reason' when a Channel fails // to sync due to a Service of the same name already existing. ErrResourceExists = "ErrResourceExists" // MessageResourceExists is the message used for Events when a resource // fails to sync due to a Service already existing - MessageResourceExists = "Resource %q already exists and is not managed by Stream" - // MessageResourceSynced is the message used for an Event fired when a Stream + MessageResourceExists = "Resource %q already exists and is not managed by Channel" + // MessageResourceSynced is the message used for an Event fired when a Channel // is synced successfully - MessageResourceSynced = "Stream synced successfully" + MessageResourceSynced = "Channel synced successfully" ) -// Controller is the controller implementation for Stream resources +// Controller is the controller implementation for Channel resources type Controller struct { // kubeclientset is a standard kubernetes clientset kubeclientset kubernetes.Interface - // streamclientset is a clientset for our own API group - streamclientset clientset.Interface + // channelclientset is a clientset for our own API group + channelclientset clientset.Interface ingressesLister extensionslisters.IngressLister ingressesSynced cache.InformerSynced @@ -81,8 +81,8 @@ type Controller struct { routerulesSynced cache.InformerSynced servicesLister corelisters.ServiceLister servicesSynced cache.InformerSynced - streamsLister listers.StreamLister - streamsSynced cache.InformerSynced + channelsLister listers.ChannelLister + channelsSynced cache.InformerSynced // workqueue is a rate limited work queue. This is used to queue work to be // processed instead of performing it as soon as a change happens. This @@ -95,25 +95,25 @@ type Controller struct { recorder record.EventRecorder } -// NewController returns a new stream controller +// NewController returns a new channel controller func NewController( kubeclientset kubernetes.Interface, - streamclientset clientset.Interface, + channelclientset clientset.Interface, kubeInformerFactory kubeinformers.SharedInformerFactory, - streamInformerFactory informers.SharedInformerFactory, + channelInformerFactory informers.SharedInformerFactory, routeInformerFactory elainformers.SharedInformerFactory) controller.Interface { - // obtain references to shared index informers for the Ingress, Service and Stream + // obtain references to shared index informers for the Ingress, Service and Channel // types. ingressInformer := kubeInformerFactory.Extensions().V1beta1().Ingresses() - routeruleInformer := streamInformerFactory.Config().V1alpha2().RouteRules() + routeruleInformer := channelInformerFactory.Config().V1alpha2().RouteRules() serviceInformer := kubeInformerFactory.Core().V1().Services() - streamInformer := streamInformerFactory.Eventing().V1alpha1().Streams() + channelInformer := channelInformerFactory.Eventing().V1alpha1().Channels() // Create event broadcaster - // Add stream-controller types to the default Kubernetes Scheme so Events can be - // logged for stream-controller types. - streamscheme.AddToScheme(scheme.Scheme) + // Add channel-controller types to the default Kubernetes Scheme so Events can be + // logged for channel-controller types. + channelscheme.AddToScheme(scheme.Scheme) glog.V(4).Info("Creating event broadcaster") eventBroadcaster := record.NewBroadcaster() eventBroadcaster.StartLogging(glog.Infof) @@ -122,30 +122,30 @@ func NewController( controller := &Controller{ kubeclientset: kubeclientset, - streamclientset: streamclientset, + channelclientset: channelclientset, ingressesLister: ingressInformer.Lister(), ingressesSynced: ingressInformer.Informer().HasSynced, routerulesLister: routeruleInformer.Lister(), routerulesSynced: routeruleInformer.Informer().HasSynced, servicesLister: serviceInformer.Lister(), servicesSynced: serviceInformer.Informer().HasSynced, - streamsLister: streamInformer.Lister(), - streamsSynced: streamInformer.Informer().HasSynced, - workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Streams"), + channelsLister: channelInformer.Lister(), + channelsSynced: channelInformer.Informer().HasSynced, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Channels"), recorder: recorder, } glog.Info("Setting up event handlers") - // Set up an event handler for when Stream resources change - streamInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: controller.enqueueStream, + // Set up an event handler for when Channel resources change + channelInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.enqueueChannel, UpdateFunc: func(old, new interface{}) { - controller.enqueueStream(new) + controller.enqueueChannel(new) }, }) // Set up an event handler for when Service resources change. This // handler will lookup the owner of the given Service, and if it is - // owned by a Stream resource will enqueue that Stream resource for + // owned by a Channel resource will enqueue that Channel resource for // processing. This way, we don't need to implement custom logic for // handling Service resources. More info on this pattern: // https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md @@ -176,16 +176,16 @@ func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error { defer c.workqueue.ShutDown() // Start the informer factories to begin populating the informer caches - glog.Info("Starting Stream controller") + glog.Info("Starting Channel controller") // Wait for the caches to be synced before starting workers glog.Info("Waiting for informer caches to sync") - if ok := cache.WaitForCacheSync(stopCh, c.ingressesSynced, c.servicesSynced, c.streamsSynced); !ok { + if ok := cache.WaitForCacheSync(stopCh, c.ingressesSynced, c.servicesSynced, c.channelsSynced); !ok { return fmt.Errorf("failed to wait for caches to sync") } glog.Info("Starting workers") - // Launch two workers to process Stream resources + // Launch two workers to process Channel resources for i := 0; i < threadiness; i++ { go wait.Until(c.runWorker, time.Second, stopCh) } @@ -239,7 +239,7 @@ func (c *Controller) processNextWorkItem() bool { return nil } // Run the syncHandler, passing it the namespace/name string of the - // Stream resource to be synced. + // Channel resource to be synced. if err := c.syncHandler(key); err != nil { return fmt.Errorf("error syncing '%s': %s", key, err.Error()) } @@ -259,7 +259,7 @@ func (c *Controller) processNextWorkItem() bool { } // syncHandler compares the actual state with the desired, and attempts to -// converge the two. It then updates the Status block of the Stream resource +// converge the two. It then updates the Status block of the Channel resource // with the current status of the resource. func (c *Controller) syncHandler(key string) error { // Convert the namespace/name string into a distinct namespace and name @@ -269,55 +269,55 @@ func (c *Controller) syncHandler(key string) error { return nil } - // Get the Stream resource with this namespace/name - stream, err := c.streamsLister.Streams(namespace).Get(name) + // Get the Channel resource with this namespace/name + channel, err := c.channelsLister.Channels(namespace).Get(name) if err != nil { - // The Stream resource may no longer exist, in which case we stop + // The Channel resource may no longer exist, in which case we stop // processing. if errors.IsNotFound(err) { - runtime.HandleError(fmt.Errorf("stream '%s' in work queue no longer exists", key)) + runtime.HandleError(fmt.Errorf("channel '%s' in work queue no longer exists", key)) return nil } return err } - // Sync Service derived from the Stream - service, err := c.syncStreamService(stream) + // Sync Service derived from the Channel + service, err := c.syncChannelService(channel) if err != nil { return err } - // Sync RouteRule derived from a brokered Stream - brokeredStreamRouteRule, err := c.syncBrokeredStream(stream) + // Sync RouteRule derived from a brokered Channel + brokeredChannelRouteRule, err := c.syncBrokeredChannel(channel) if err != nil { return err } - // Sync Ingress derived from the Stream - ingress, err := c.syncStreamIngress(stream) + // Sync Ingress derived from the Channel + ingress, err := c.syncChannelIngress(channel) if err != nil { return err } - // Finally, we update the status block of the Stream resource to reflect the + // Finally, we update the status block of the Channel resource to reflect the // current state of the world - err = c.updateStreamStatus(stream, service, ingress, brokeredStreamRouteRule) + err = c.updateChannelStatus(channel, service, ingress, brokeredChannelRouteRule) if err != nil { return err } - c.recorder.Event(stream, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) + c.recorder.Event(channel, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) return nil } -func (c *Controller) syncStreamService(stream *eventingv1alpha1.Stream) (*corev1.Service, error) { +func (c *Controller) syncChannelService(channel *eventingv1alpha1.Channel) (*corev1.Service, error) { // Get the service with the specified service name - serviceName := controller.StreamServiceName(stream.ObjectMeta.Name) - service, err := c.servicesLister.Services(stream.Namespace).Get(serviceName) + serviceName := controller.ChannelServiceName(channel.ObjectMeta.Name) + service, err := c.servicesLister.Services(channel.Namespace).Get(serviceName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - service, err = c.kubeclientset.CoreV1().Services(stream.Namespace).Create(newService(stream)) + service, err = c.kubeclientset.CoreV1().Services(channel.Namespace).Create(newService(channel)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -327,27 +327,27 @@ func (c *Controller) syncStreamService(stream *eventingv1alpha1.Stream) (*corev1 return nil, err } - // If the Service is not controlled by this Stream resource, we should log + // If the Service is not controlled by this Channel resource, we should log // a warning to the event recorder and return - if !metav1.IsControlledBy(service, stream) { + if !metav1.IsControlledBy(service, channel) { msg := fmt.Sprintf(MessageResourceExists, service.Name) - c.recorder.Event(stream, corev1.EventTypeWarning, ErrResourceExists, msg) + c.recorder.Event(channel, corev1.EventTypeWarning, ErrResourceExists, msg) return nil, fmt.Errorf(msg) } return service, nil } -func (c *Controller) syncBrokeredStream(stream *eventingv1alpha1.Stream) (*istiov1alpha2.RouteRule, error) { - // Get the RouteRule with the specified Stream name - routeruleName := controller.BrokeredStreamRouteRuleName(stream.ObjectMeta.Name) - routerule, err := c.routerulesLister.RouteRules(stream.Namespace).Get(routeruleName) +func (c *Controller) syncBrokeredChannel(channel *eventingv1alpha1.Channel) (*istiov1alpha2.RouteRule, error) { + // Get the RouteRule with the specified Channel name + routeruleName := controller.BrokeredChannelRouteRuleName(channel.ObjectMeta.Name) + routerule, err := c.routerulesLister.RouteRules(channel.Namespace).Get(routeruleName) - if stream.Spec.Broker == "" { + if channel.Spec.Broker == "" { // If the resource exists, delete it if routerule != nil { // Remove RouteRule - err = c.streamclientset.ConfigV1alpha2().RouteRules(stream.Namespace).Delete(routeruleName, nil) + err = c.channelclientset.ConfigV1alpha2().RouteRules(channel.Namespace).Delete(routeruleName, nil) if err != nil { return routerule, err } @@ -359,7 +359,7 @@ func (c *Controller) syncBrokeredStream(stream *eventingv1alpha1.Stream) (*istio // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - routerule, err = c.streamclientset.ConfigV1alpha2().RouteRules(stream.Namespace).Create(newBrokeredRouteRule(stream)) + routerule, err = c.channelclientset.ConfigV1alpha2().RouteRules(channel.Namespace).Create(newBrokeredRouteRule(channel)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -369,26 +369,26 @@ func (c *Controller) syncBrokeredStream(stream *eventingv1alpha1.Stream) (*istio return nil, err } - // If the Service is not controlled by this Stream resource, we should log + // If the Service is not controlled by this Channel resource, we should log // a warning to the event recorder and return - if !metav1.IsControlledBy(routerule, stream) { + if !metav1.IsControlledBy(routerule, channel) { msg := fmt.Sprintf(MessageResourceExists, routerule.Name) - c.recorder.Event(stream, corev1.EventTypeWarning, ErrResourceExists, msg) + c.recorder.Event(channel, corev1.EventTypeWarning, ErrResourceExists, msg) return nil, fmt.Errorf(msg) } return routerule, nil } -func (c *Controller) syncStreamIngress(stream *eventingv1alpha1.Stream) (*extensionsv1beta1.Ingress, error) { +func (c *Controller) syncChannelIngress(channel *eventingv1alpha1.Channel) (*extensionsv1beta1.Ingress, error) { // TODO make ingress optional // Get the ingress with the specified ingress name - ingressName := controller.StreamIngressName(stream.ObjectMeta.Name) - ingress, err := c.ingressesLister.Ingresses(stream.Namespace).Get(ingressName) + ingressName := controller.ChannelIngressName(channel.ObjectMeta.Name) + ingress, err := c.ingressesLister.Ingresses(channel.Namespace).Get(ingressName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - ingress, err = c.kubeclientset.ExtensionsV1beta1().Ingresses(stream.Namespace).Create(newIngress(stream)) + ingress, err = c.kubeclientset.ExtensionsV1beta1().Ingresses(channel.Namespace).Create(newIngress(channel)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -398,34 +398,34 @@ func (c *Controller) syncStreamIngress(stream *eventingv1alpha1.Stream) (*extens return nil, err } - // If the Ingress is not controlled by this Stream resource, we should log + // If the Ingress is not controlled by this Channel resource, we should log // a warning to the event recorder and return - if !metav1.IsControlledBy(ingress, stream) { + if !metav1.IsControlledBy(ingress, channel) { msg := fmt.Sprintf(MessageResourceExists, ingress.Name) - c.recorder.Event(stream, corev1.EventTypeWarning, ErrResourceExists, msg) + c.recorder.Event(channel, corev1.EventTypeWarning, ErrResourceExists, msg) return nil, fmt.Errorf(msg) } return ingress, nil } -func (c *Controller) updateStreamStatus(stream *eventingv1alpha1.Stream, service *corev1.Service, ingress *extensionsv1beta1.Ingress, brokeredStreamRouteRule *istiov1alpha2.RouteRule) error { +func (c *Controller) updateChannelStatus(channel *eventingv1alpha1.Channel, service *corev1.Service, ingress *extensionsv1beta1.Ingress, brokeredChannelRouteRule *istiov1alpha2.RouteRule) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance - streamCopy := stream.DeepCopy() + channelCopy := channel.DeepCopy() // If the CustomResourceSubresources feature gate is not enabled, - // we must use Update instead of UpdateStatus to update the Status block of the Stream resource. + // we must use Update instead of UpdateStatus to update the Status block of the Channel resource. // UpdateStatus will not allow changes to the Spec of the resource, // which is ideal for ensuring nothing other than resource status has been updated. - _, err := c.streamclientset.EventingV1alpha1().Streams(stream.Namespace).Update(streamCopy) + _, err := c.channelclientset.EventingV1alpha1().Channels(channel.Namespace).Update(channelCopy) return err } -// enqueueStream takes a Stream resource and converts it into a namespace/name +// enqueueChannel takes a Channel resource and converts it into a namespace/name // string which is then put onto the work queue. This method should *not* be -// passed resources of any type other than Stream. -func (c *Controller) enqueueStream(obj interface{}) { +// passed resources of any type other than Channel. +func (c *Controller) enqueueChannel(obj interface{}) { var key string var err error if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil { @@ -436,9 +436,9 @@ func (c *Controller) enqueueStream(obj interface{}) { } // handleObject will take any resource implementing metav1.Object and attempt -// to find the Stream resource that 'owns' it. It does this by looking at the +// to find the Channel resource that 'owns' it. It does this by looking at the // objects metadata.ownerReferences field for an appropriate OwnerReference. -// It then enqueues that Stream resource to be processed. If the object does not +// It then enqueues that Channel resource to be processed. If the object does not // have an appropriate OwnerReference, it will simply be skipped. func (c *Controller) handleObject(obj interface{}) { var object metav1.Object @@ -458,40 +458,40 @@ func (c *Controller) handleObject(obj interface{}) { } glog.V(4).Infof("Processing object: %s", object.GetName()) if ownerRef := metav1.GetControllerOf(object); ownerRef != nil { - // If this object is not owned by a Stream, we should not do anything more + // If this object is not owned by a Channel, we should not do anything more // with it. - if ownerRef.Kind != "Stream" { + if ownerRef.Kind != "Channel" { return } - stream, err := c.streamsLister.Streams(object.GetNamespace()).Get(ownerRef.Name) + channel, err := c.channelsLister.Channels(object.GetNamespace()).Get(ownerRef.Name) if err != nil { - glog.V(4).Infof("ignoring orphaned object '%s' of stream '%s'", object.GetSelfLink(), ownerRef.Name) + glog.V(4).Infof("ignoring orphaned object '%s' of channel '%s'", object.GetSelfLink(), ownerRef.Name) return } - c.enqueueStream(stream) + c.enqueueChannel(channel) return } } -// newService creates a new Service for a Stream resource. It also sets +// newService creates a new Service for a Channel resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover -// the Stream resource that 'owns' it. -func newService(stream *eventingv1alpha1.Stream) *corev1.Service { +// the Channel resource that 'owns' it. +func newService(channel *eventingv1alpha1.Channel) *corev1.Service { labels := map[string]string{ - "stream": stream.Name, + "channel": channel.Name, } return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.StreamServiceName(stream.ObjectMeta.Name), - Namespace: stream.Namespace, + Name: controller.ChannelServiceName(channel.ObjectMeta.Name), + Namespace: channel.Namespace, Labels: labels, OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(stream, schema.GroupVersionKind{ + *metav1.NewControllerRef(channel, schema.GroupVersionKind{ Group: eventingv1alpha1.SchemeGroupVersion.Group, Version: eventingv1alpha1.SchemeGroupVersion.Version, - Kind: "Stream", + Kind: "Channel", }), }, }, @@ -503,67 +503,67 @@ func newService(stream *eventingv1alpha1.Stream) *corev1.Service { } } -// newBrokeredRouteRule creates a new RouteRule for a brokered Stream resource. It also sets +// newBrokeredRouteRule creates a new RouteRule for a brokered Channel resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover -// the Stream resource that 'owns' it. -func newBrokeredRouteRule(stream *eventingv1alpha1.Stream) *istiov1alpha2.RouteRule { +// the Channel resource that 'owns' it. +func newBrokeredRouteRule(channel *eventingv1alpha1.Channel) *istiov1alpha2.RouteRule { labels := map[string]string{ - "broker": stream.Spec.Broker, - "stream": stream.Name, + "broker": channel.Spec.Broker, + "channel": channel.Name, } return &istiov1alpha2.RouteRule{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.BrokeredStreamRouteRuleName(stream.Name), - Namespace: stream.Namespace, + Name: controller.BrokeredChannelRouteRuleName(channel.Name), + Namespace: channel.Namespace, Labels: labels, OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(stream, schema.GroupVersionKind{ + *metav1.NewControllerRef(channel, schema.GroupVersionKind{ Group: eventingv1alpha1.SchemeGroupVersion.Group, Version: eventingv1alpha1.SchemeGroupVersion.Version, - Kind: "Stream", + Kind: "Channel", }), }, }, Spec: istiov1alpha2.RouteRuleSpec{ Destination: istiov1alpha2.IstioService{ - Name: controller.StreamServiceName(stream.Name), + Name: controller.ChannelServiceName(channel.Name), }, Route: []istiov1alpha2.DestinationWeight{ { Destination: istiov1alpha2.IstioService{ - Name: controller.BrokerServiceName(stream.Spec.Broker), + Name: controller.BrokerServiceName(channel.Spec.Broker), }, Weight: 100, }, }, Rewrite: istiov1alpha2.HTTPRewrite{ - Authority: fmt.Sprintf("%s.%s.streams.cluster.local", stream.Name, stream.Namespace), + Authority: fmt.Sprintf("%s.%s.channels.cluster.local", channel.Name, channel.Namespace), }, }, } } -// newIngress creates a new Ingress for a Stream resource. It also sets +// newIngress creates a new Ingress for a Channel resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover -// the Stream resource that 'owns' it. -func newIngress(stream *eventingv1alpha1.Stream) *extensionsv1beta1.Ingress { +// the Channel resource that 'owns' it. +func newIngress(channel *eventingv1alpha1.Channel) *extensionsv1beta1.Ingress { labels := map[string]string{ - "stream": stream.Name, + "channel": channel.Name, } annotations := map[string]string{ "kubernetes.io/ingress.class": "istio", } return &extensionsv1beta1.Ingress{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.StreamIngressName(stream.ObjectMeta.Name), - Namespace: stream.Namespace, + Name: controller.ChannelIngressName(channel.ObjectMeta.Name), + Namespace: channel.Namespace, Labels: labels, Annotations: annotations, OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(stream, schema.GroupVersionKind{ + *metav1.NewControllerRef(channel, schema.GroupVersionKind{ Group: eventingv1alpha1.SchemeGroupVersion.Group, Version: eventingv1alpha1.SchemeGroupVersion.Version, - Kind: "Stream", + Kind: "Channel", }), }, }, @@ -571,13 +571,13 @@ func newIngress(stream *eventingv1alpha1.Stream) *extensionsv1beta1.Ingress { Rules: []extensionsv1beta1.IngressRule{ { // TODO make host name configurable - Host: stream.ObjectMeta.Name, + Host: channel.ObjectMeta.Name, IngressRuleValue: extensionsv1beta1.IngressRuleValue{ HTTP: &extensionsv1beta1.HTTPIngressRuleValue{ Paths: []extensionsv1beta1.HTTPIngressPath{ { Backend: extensionsv1beta1.IngressBackend{ - ServiceName: controller.StreamServiceName(stream.ObjectMeta.Name), + ServiceName: controller.ChannelServiceName(channel.ObjectMeta.Name), ServicePort: intstr.FromString("http"), }, }, diff --git a/pkg/controller/names.go b/pkg/controller/names.go index 8ae0a1d6fa8..606a5888b89 100644 --- a/pkg/controller/names.go +++ b/pkg/controller/names.go @@ -26,16 +26,16 @@ func BrokerServiceName(brokerName string) string { return fmt.Sprintf("%s-broker", brokerName) } -func BrokeredStreamRouteRuleName(streamName string) string { - return fmt.Sprintf("%s-stream", streamName) +func BrokeredChannelRouteRuleName(channelName string) string { + return fmt.Sprintf("%s-channel", channelName) } -func StreamIngressName(streamName string) string { - return fmt.Sprintf("%s-stream", streamName) +func ChannelIngressName(channelName string) string { + return fmt.Sprintf("%s-channel", channelName) } -func StreamServiceName(streamName string) string { - return fmt.Sprintf("%s-stream", streamName) +func ChannelServiceName(channelName string) string { + return fmt.Sprintf("%s-channel", channelName) } func SubscriptionRouteRuleName(subscriptionName string) string { diff --git a/pkg/controller/subscription/controller.go b/pkg/controller/subscription/controller.go index b87330bd2b8..8da2fc72d1c 100644 --- a/pkg/controller/subscription/controller.go +++ b/pkg/controller/subscription/controller.go @@ -73,8 +73,8 @@ type Controller struct { routerulesLister istiolisters.RouteRuleLister routerulesSynced cache.InformerSynced - streamsLister listers.StreamLister - streamsSynced cache.InformerSynced + channelsLister listers.ChannelLister + channelsSynced cache.InformerSynced subscriptionsLister listers.SubscriptionLister subscriptionsSynced cache.InformerSynced @@ -100,7 +100,7 @@ func NewController( // obtain references to shared index informers for the RouteRule and Subscription // types. routeruleInformer := subscriptionInformerFactory.Config().V1alpha2().RouteRules() - streamInformer := subscriptionInformerFactory.Eventing().V1alpha1().Streams() + channelInformer := subscriptionInformerFactory.Eventing().V1alpha1().Channels() subscriptionInformer := subscriptionInformerFactory.Eventing().V1alpha1().Subscriptions() // Create event broadcaster @@ -118,8 +118,8 @@ func NewController( subscriptionclientset: subscriptionclientset, routerulesLister: routeruleInformer.Lister(), routerulesSynced: routeruleInformer.Informer().HasSynced, - streamsLister: streamInformer.Lister(), - streamsSynced: streamInformer.Informer().HasSynced, + channelsLister: channelInformer.Lister(), + channelsSynced: channelInformer.Informer().HasSynced, subscriptionsLister: subscriptionInformer.Lister(), subscriptionsSynced: subscriptionInformer.Informer().HasSynced, workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Subscriptions"), @@ -273,10 +273,10 @@ func (c *Controller) syncHandler(key string) error { return err } - stream, err := c.streamsLister.Streams(namespace).Get(subscription.Spec.Stream) + channel, err := c.channelsLister.Channels(namespace).Get(subscription.Spec.Channel) var brokerlessRouterule *istiov1alpha2.RouteRule - if stream.Spec.Broker == "" { + if channel.Spec.Broker == "" { brokerlessRouterule, err = c.syncBrokerlessRouteRule(subscription) if err != nil { return err @@ -410,7 +410,7 @@ func newRouteRule(subscription *eventingv1alpha1.Subscription) *istiov1alpha2.Ro }, Spec: istiov1alpha2.RouteRuleSpec{ Destination: istiov1alpha2.IstioService{ - Name: controller.StreamServiceName(subscription.Spec.Stream), + Name: controller.ChannelServiceName(subscription.Spec.Channel), }, Route: []istiov1alpha2.DestinationWeight{ { diff --git a/pkg/subscription/monitor.go b/pkg/subscription/monitor.go index 6c4bea22340..6742d6a3c9d 100644 --- a/pkg/subscription/monitor.go +++ b/pkg/subscription/monitor.go @@ -30,19 +30,19 @@ type Monitor struct { brokerName string handler MonitorEventHandlerFuncs - cache map[streamKey]streamSummary + cache map[channelKey]channelSummary mutex *sync.Mutex } type MonitorEventHandlerFuncs struct { - ProvisionFunc func(stream eventingv1alpha1.Stream) - UnprovisionFunc func(stream eventingv1alpha1.Stream) + ProvisionFunc func(channel eventingv1alpha1.Channel) + UnprovisionFunc func(channel eventingv1alpha1.Channel) SubscribeFunc func(subscription eventingv1alpha1.Subscription) UnsubscribeFunc func(subscription eventingv1alpha1.Subscription) } -type streamSummary struct { - Stream *eventingv1alpha1.StreamSpec +type channelSummary struct { + Channel *eventingv1alpha1.ChannelSpec Subscriptions map[subscriptionKey]subscriptionSummary } @@ -52,42 +52,42 @@ type subscriptionSummary struct { func NewMonitor(brokerName string, informerFactory informers.SharedInformerFactory, handler MonitorEventHandlerFuncs) *Monitor { - streamInformer := informerFactory.Eventing().V1alpha1().Streams() + channelInformer := informerFactory.Eventing().V1alpha1().Channels() subscriptionInformer := informerFactory.Eventing().V1alpha1().Subscriptions() monitor := &Monitor{ brokerName: brokerName, handler: handler, - cache: make(map[streamKey]streamSummary), + cache: make(map[channelKey]channelSummary), mutex: &sync.Mutex{}, } glog.Info("Setting up event handlers") - // Set up an event handler for when Stream resources change - streamInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + // Set up an event handler for when Channel resources change + channelInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - stream := obj.(eventingv1alpha1.Stream) - monitor.createOrUpdateStream(stream) + channel := obj.(eventingv1alpha1.Channel) + monitor.createOrUpdateChannel(channel) }, UpdateFunc: func(old, new interface{}) { - oldStream := old.(eventingv1alpha1.Stream) - newStream := new.(eventingv1alpha1.Stream) + oldChannel := old.(eventingv1alpha1.Channel) + newChannel := new.(eventingv1alpha1.Channel) - if oldStream.ResourceVersion == newStream.ResourceVersion { - // Periodic resync will send update events for all known Streams. - // Two different versions of the same Stream will always have different RVs. + if oldChannel.ResourceVersion == newChannel.ResourceVersion { + // Periodic resync will send update events for all known Channels. + // Two different versions of the same Channel will always have different RVs. return } - monitor.createOrUpdateStream(newStream) - if oldStream.Spec.Broker != newStream.Spec.Broker { - monitor.removeStream(oldStream) + monitor.createOrUpdateChannel(newChannel) + if oldChannel.Spec.Broker != newChannel.Spec.Broker { + monitor.removeChannel(oldChannel) } }, DeleteFunc: func(obj interface{}) { - stream := obj.(eventingv1alpha1.Stream) - monitor.removeStream(stream) + channel := obj.(eventingv1alpha1.Channel) + monitor.removeChannel(channel) }, }) // Set up an event handler for when Subscription resources change @@ -107,7 +107,7 @@ func NewMonitor(brokerName string, informerFactory informers.SharedInformerFacto } monitor.createOrUpdateSubscription(newSubscription) - if oldSubscription.Spec.Stream != newSubscription.Spec.Stream { + if oldSubscription.Spec.Channel != newSubscription.Spec.Channel { monitor.removeSubscription(oldSubscription) } }, @@ -120,13 +120,13 @@ func NewMonitor(brokerName string, informerFactory informers.SharedInformerFacto return monitor } -// Subscriptions for a stream name and namespace -func (m *Monitor) Subscriptions(stream string, namespace string) *[]eventingv1alpha1.SubscriptionSpec { - streamKey := makeStreamKeyWithNames(stream, namespace) - summary := m.getOrCreateStreamSummary(streamKey) +// Subscriptions for a channel name and namespace +func (m *Monitor) Subscriptions(channel string, namespace string) *[]eventingv1alpha1.SubscriptionSpec { + channelKey := makeChannelKeyWithNames(channel, namespace) + summary := m.getOrCreateChannelSummary(channelKey) - if summary.Stream.Broker != m.brokerName { - // the stream is not for this broker + if summary.Channel.Broker != m.brokerName { + // the channel is not for this broker return nil } @@ -140,12 +140,12 @@ func (m *Monitor) Subscriptions(stream string, namespace string) *[]eventingv1al return &subscriptions } -func (m *Monitor) getOrCreateStreamSummary(key streamKey) streamSummary { +func (m *Monitor) getOrCreateChannelSummary(key channelKey) channelSummary { m.mutex.Lock() summary, ok := m.cache[key] if !ok { - summary = streamSummary{ - Stream: nil, + summary = channelSummary{ + Channel: nil, Subscriptions: make(map[subscriptionKey]subscriptionSummary), } m.cache[key] = summary @@ -155,35 +155,35 @@ func (m *Monitor) getOrCreateStreamSummary(key streamKey) streamSummary { return summary } -func (m *Monitor) createOrUpdateStream(stream eventingv1alpha1.Stream) { - streamKey := makeStreamKeyFromStream(stream) - summary := m.getOrCreateStreamSummary(streamKey) +func (m *Monitor) createOrUpdateChannel(channel eventingv1alpha1.Channel) { + channelKey := makeChannelKeyFromChannel(channel) + summary := m.getOrCreateChannelSummary(channelKey) m.mutex.Lock() - old := summary.Stream - new := &stream.Spec - summary.Stream = new + old := summary.Channel + new := &channel.Spec + summary.Channel = new m.mutex.Unlock() if !reflect.DeepEqual(old, new) { - m.handler.ProvisionFunc(stream) + m.handler.ProvisionFunc(channel) } } -func (m *Monitor) removeStream(stream eventingv1alpha1.Stream) { - streamKey := makeStreamKeyFromStream(stream) - summary := m.getOrCreateStreamSummary(streamKey) +func (m *Monitor) removeChannel(channel eventingv1alpha1.Channel) { + channelKey := makeChannelKeyFromChannel(channel) + summary := m.getOrCreateChannelSummary(channelKey) m.mutex.Lock() - summary.Stream = nil + summary.Channel = nil m.mutex.Unlock() - m.handler.UnprovisionFunc(stream) + m.handler.UnprovisionFunc(channel) } func (m *Monitor) createOrUpdateSubscription(subscription eventingv1alpha1.Subscription) { - streamKey := makeStreamKeyFromSubscription(subscription) - summary := m.getOrCreateStreamSummary(streamKey) + channelKey := makeChannelKeyFromSubscription(subscription) + summary := m.getOrCreateChannelSummary(channelKey) subscriptionKey := makeSubscriptionKeyFromSubscription(subscription) m.mutex.Lock() @@ -200,8 +200,8 @@ func (m *Monitor) createOrUpdateSubscription(subscription eventingv1alpha1.Subsc } func (m *Monitor) removeSubscription(subscription eventingv1alpha1.Subscription) { - streamKey := makeStreamKeyFromSubscription(subscription) - summary := m.getOrCreateStreamSummary(streamKey) + channelKey := makeChannelKeyFromSubscription(subscription) + summary := m.getOrCreateChannelSummary(channelKey) subscriptionKey := makeSubscriptionKeyFromSubscription(subscription) m.mutex.Lock() @@ -211,21 +211,21 @@ func (m *Monitor) removeSubscription(subscription eventingv1alpha1.Subscription) m.handler.UnsubscribeFunc(subscription) } -type streamKey struct { +type channelKey struct { Name string Namespace string } -func makeStreamKeyFromStream(stream eventingv1alpha1.Stream) streamKey { - return makeStreamKeyWithNames(stream.Name, stream.Namespace) +func makeChannelKeyFromChannel(channel eventingv1alpha1.Channel) channelKey { + return makeChannelKeyWithNames(channel.Name, channel.Namespace) } -func makeStreamKeyFromSubscription(subscription eventingv1alpha1.Subscription) streamKey { - return makeStreamKeyWithNames(subscription.Spec.Stream, subscription.Namespace) +func makeChannelKeyFromSubscription(subscription eventingv1alpha1.Subscription) channelKey { + return makeChannelKeyWithNames(subscription.Spec.Channel, subscription.Namespace) } -func makeStreamKeyWithNames(name string, namespace string) streamKey { - return streamKey{ +func makeChannelKeyWithNames(name string, namespace string) channelKey { + return channelKey{ Name: name, Namespace: namespace, } diff --git a/sample/hello/hello-channel.yaml b/sample/hello/hello-channel.yaml new file mode 100644 index 00000000000..dd199eeda75 --- /dev/null +++ b/sample/hello/hello-channel.yaml @@ -0,0 +1,13 @@ +apiVersion: eventing.knative.dev/v1alpha1 +kind: Channel +metadata: + name: aloha + +--- +apiVersion: eventing.knative.dev/v1alpha1 +kind: Subscription +metadata: + name: aloha2hello +spec: + channel: aloha + subscriber: hello diff --git a/sample/hello/hello-stream.yaml b/sample/hello/hello-stream.yaml deleted file mode 100644 index 068ce660fe2..00000000000 --- a/sample/hello/hello-stream.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: eventing.elafros.dev/v1alpha1 -kind: Stream -metadata: - name: aloha - ---- -apiVersion: eventing.elafros.dev/v1alpha1 -kind: Subscription -metadata: - name: aloha2hello -spec: - stream: aloha - subscriber: hello diff --git a/sample/square/square-brokered.yaml b/sample/square/square-brokered.yaml index d9a18c79497..6769eb9b1ed 100644 --- a/sample/square/square-brokered.yaml +++ b/sample/square/square-brokered.yaml @@ -1,5 +1,5 @@ apiVersion: eventing.knative.dev/v1alpha1 -kind: Stream +kind: Channel metadata: name: square spec: @@ -11,5 +11,5 @@ kind: Subscription metadata: name: square spec: - stream: square + channel: square subscriber: square diff --git a/sample/square/square-brokerless.yaml b/sample/square/square-brokerless.yaml index 8762b54281f..f62fa427e57 100644 --- a/sample/square/square-brokerless.yaml +++ b/sample/square/square-brokerless.yaml @@ -1,5 +1,5 @@ apiVersion: eventing.knative.dev/v1alpha1 -kind: Stream +kind: Channel metadata: name: square @@ -9,5 +9,5 @@ kind: Subscription metadata: name: square spec: - stream: square + channel: square subscriber: square From e39fd2609f0b26f657ae0894cb013ac296c24973 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Tue, 5 Jun 2018 17:06:29 -0400 Subject: [PATCH 10/21] Rename Broker to Bus --- cmd/controller/main.go | 4 +- cmd/{stub-broker => stub-bus}/main.go | 6 +- config/{broker.yaml => bus.yaml} | 8 +- config/{brokers => buses}/stub.yaml | 6 +- .../{broker_types.go => bus_types.go} | 22 +- pkg/apis/eventing/v1alpha1/channel_types.go | 4 +- pkg/apis/eventing/v1alpha1/register.go | 4 +- .../v1alpha1/zz_generated.deepcopy.go | 40 ++-- .../typed/eventing/v1alpha1/broker.go | 157 --------------- .../versioned/typed/eventing/v1alpha1/bus.go | 157 +++++++++++++++ .../eventing/v1alpha1/eventing_client.go | 6 +- .../eventing/v1alpha1/fake/fake_broker.go | 128 ------------ .../typed/eventing/v1alpha1/fake/fake_bus.go | 128 ++++++++++++ .../v1alpha1/fake/fake_eventing_client.go | 4 +- .../eventing/v1alpha1/generated_expansion.go | 2 +- .../eventing/v1alpha1/{broker.go => bus.go} | 38 ++-- .../eventing/v1alpha1/interface.go | 10 +- .../informers/externalversions/generic.go | 4 +- .../listers/eventing/v1alpha1/broker.go | 94 --------- pkg/client/listers/eventing/v1alpha1/bus.go | 94 +++++++++ .../eventing/v1alpha1/expansion_generated.go | 12 +- pkg/controller/{broker => bus}/controller.go | 190 +++++++++--------- pkg/controller/channel/controller.go | 26 +-- pkg/controller/names.go | 10 +- pkg/controller/subscription/controller.go | 12 +- pkg/subscription/monitor.go | 16 +- sample/square/README.md | 12 +- ...square-brokered.yaml => square-bused.yaml} | 2 +- ...re-brokerless.yaml => square-busless.yaml} | 0 29 files changed, 598 insertions(+), 598 deletions(-) rename cmd/{stub-broker => stub-bus}/main.go (95%) rename config/{broker.yaml => bus.yaml} (63%) rename config/{brokers => buses}/stub.yaml (50%) rename pkg/apis/eventing/v1alpha1/{broker_types.go => bus_types.go} (73%) delete mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/broker.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/bus.go delete mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_broker.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_bus.go rename pkg/client/informers/externalversions/eventing/v1alpha1/{broker.go => bus.go} (58%) delete mode 100644 pkg/client/listers/eventing/v1alpha1/broker.go create mode 100644 pkg/client/listers/eventing/v1alpha1/bus.go rename pkg/controller/{broker => bus}/controller.go (71%) rename sample/square/{square-brokered.yaml => square-bused.yaml} (93%) rename sample/square/{square-brokerless.yaml => square-busless.yaml} (100%) diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 6cbd6409833..a289ff2ecb5 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -36,7 +36,7 @@ import ( informers "github.com/knative/eventing/pkg/client/informers/externalversions" "github.com/knative/eventing/pkg/controller" "github.com/knative/eventing/pkg/controller/bind" - "github.com/knative/eventing/pkg/controller/broker" + "github.com/knative/eventing/pkg/controller/bus" "github.com/knative/eventing/pkg/controller/channel" "github.com/knative/eventing/pkg/controller/subscription" "github.com/knative/eventing/pkg/signals" @@ -88,7 +88,7 @@ func main() { // Add new controllers here. ctors := []controller.Constructor{ bind.NewController, - broker.NewController, + bus.NewController, channel.NewController, subscription.NewController, } diff --git a/cmd/stub-broker/main.go b/cmd/stub-bus/main.go similarity index 95% rename from cmd/stub-broker/main.go rename to cmd/stub-bus/main.go index 032a467799e..d8c3ba061e9 100644 --- a/cmd/stub-broker/main.go +++ b/cmd/stub-bus/main.go @@ -39,7 +39,7 @@ var ( masterURL string kubeconfig string - broker = os.Getenv("BROKER_NAME") + bus = os.Getenv("BUS_NAME") forwardHeaders = []string{ "content-type", "x-request-id", @@ -73,7 +73,7 @@ func main() { } informerFactory := informers.NewSharedInformerFactory(client, time.Second*30) - monitor := subscription.NewMonitor(broker, informerFactory, subscription.MonitorEventHandlerFuncs{ + monitor := subscription.NewMonitor(bus, informerFactory, subscription.MonitorEventHandlerFuncs{ ProvisionFunc: func(channel eventingv1alpha1.Channel) { fmt.Printf("Provision channel %q\n", channel.Name) }, @@ -129,7 +129,7 @@ func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { if err != nil { fmt.Printf("Unable to create subscriber request %v", err) } - request.Header.Set("x-broker", broker) + request.Header.Set("x-bus", bus) request.Header.Set("x-channel", channel) for _, header := range forwardHeaders { if value := req.Header.Get(header); value != "" { diff --git a/config/broker.yaml b/config/bus.yaml similarity index 63% rename from config/broker.yaml rename to config/bus.yaml index b40dd0a3a57..dc031ae0769 100644 --- a/config/broker.yaml +++ b/config/bus.yaml @@ -1,12 +1,12 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: brokers.eventing.knative.dev + name: buses.eventing.knative.dev spec: scope: Namespaced group: eventing.knative.dev version: v1alpha1 names: - kind: Broker - plural: brokers - singular: broker + kind: Bus + plural: buses + singular: bus diff --git a/config/brokers/stub.yaml b/config/buses/stub.yaml similarity index 50% rename from config/brokers/stub.yaml rename to config/buses/stub.yaml index 245356afc87..744c5c7cb0e 100644 --- a/config/brokers/stub.yaml +++ b/config/buses/stub.yaml @@ -1,8 +1,8 @@ apiVersion: eventing.knative.dev/v1alpha1 -kind: Broker +kind: Bus metadata: name: stub spec: container: - name: broker - image: github.com/knative/eventing/cmd/stub-broker + name: bus + image: github.com/knative/eventing/cmd/stub-bus diff --git a/pkg/apis/eventing/v1alpha1/broker_types.go b/pkg/apis/eventing/v1alpha1/bus_types.go similarity index 73% rename from pkg/apis/eventing/v1alpha1/broker_types.go rename to pkg/apis/eventing/v1alpha1/bus_types.go index 1b87a0e6b78..b4f5696b757 100644 --- a/pkg/apis/eventing/v1alpha1/broker_types.go +++ b/pkg/apis/eventing/v1alpha1/bus_types.go @@ -26,29 +26,29 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the brokers.eventing.dev CRD -type Broker struct { +// Represents the buses.eventing.dev CRD +type Bus struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` - Spec BrokerSpec `json:"spec"` - Status *BrokerStatus `json:"status,omitempty"` + Spec BusSpec `json:"spec"` + Status *BusStatus `json:"status,omitempty"` } -// Spec (what the user wants) for a broker -type BrokerSpec struct { - // Container definition to use for the broker. +// Spec (what the user wants) for a bus +type BusSpec struct { + // Container definition to use for the bus. Container kapi.Container `json:"container"` } -// Status (computed) for a broker -type BrokerStatus struct { +// Status (computed) for a bus +type BusStatus struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // Returned in list operations -type BrokerList struct { +type BusList struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ListMeta `json:"metadata"` - Items []Broker `json:"items"` + Items []Bus `json:"items"` } diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index 3fa6c221950..7a08a7ddf58 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -36,8 +36,8 @@ type Channel struct { // Spec (what the user wants) for a channel type ChannelSpec struct { - // Name of the broker backing this channel (optional) - Broker string + // Name of the bus backing this channel (optional) + Bus string } // Status (computed) for a channel diff --git a/pkg/apis/eventing/v1alpha1/register.go b/pkg/apis/eventing/v1alpha1/register.go index fc9622f4655..b32db09a259 100644 --- a/pkg/apis/eventing/v1alpha1/register.go +++ b/pkg/apis/eventing/v1alpha1/register.go @@ -47,8 +47,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Bind{}, &BindList{}, - &Broker{}, - &BrokerList{}, + &Bus{}, + &BusList{}, &Channel{}, &ChannelList{}, &EventSource{}, diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index 8d8348e61fb..1390e25123f 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -166,7 +166,7 @@ func (in *BindStatus) DeepCopy() *BindStatus { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Broker) DeepCopyInto(out *Broker) { +func (in *Bus) DeepCopyInto(out *Bus) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -176,25 +176,25 @@ func (in *Broker) DeepCopyInto(out *Broker) { if *in == nil { *out = nil } else { - *out = new(BrokerStatus) + *out = new(BusStatus) **out = **in } } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Broker. -func (in *Broker) DeepCopy() *Broker { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Bus. +func (in *Bus) DeepCopy() *Bus { if in == nil { return nil } - out := new(Broker) + out := new(Bus) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Broker) DeepCopyObject() runtime.Object { +func (in *Bus) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -202,13 +202,13 @@ func (in *Broker) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BrokerList) DeepCopyInto(out *BrokerList) { +func (in *BusList) DeepCopyInto(out *BusList) { *out = *in out.TypeMeta = in.TypeMeta out.ListMeta = in.ListMeta if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]Broker, len(*in)) + *out = make([]Bus, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -216,18 +216,18 @@ func (in *BrokerList) DeepCopyInto(out *BrokerList) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerList. -func (in *BrokerList) DeepCopy() *BrokerList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BusList. +func (in *BusList) DeepCopy() *BusList { if in == nil { return nil } - out := new(BrokerList) + out := new(BusList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *BrokerList) DeepCopyObject() runtime.Object { +func (in *BusList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -235,34 +235,34 @@ func (in *BrokerList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BrokerSpec) DeepCopyInto(out *BrokerSpec) { +func (in *BusSpec) DeepCopyInto(out *BusSpec) { *out = *in in.Container.DeepCopyInto(&out.Container) return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerSpec. -func (in *BrokerSpec) DeepCopy() *BrokerSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BusSpec. +func (in *BusSpec) DeepCopy() *BusSpec { if in == nil { return nil } - out := new(BrokerSpec) + out := new(BusSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BrokerStatus) DeepCopyInto(out *BrokerStatus) { +func (in *BusStatus) DeepCopyInto(out *BusStatus) { *out = *in return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BrokerStatus. -func (in *BrokerStatus) DeepCopy() *BrokerStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BusStatus. +func (in *BusStatus) DeepCopy() *BusStatus { if in == nil { return nil } - out := new(BrokerStatus) + out := new(BusStatus) in.DeepCopyInto(out) return out } diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/broker.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/broker.go deleted file mode 100644 index 5e1723031ba..00000000000 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/broker.go +++ /dev/null @@ -1,157 +0,0 @@ -/* -Copyright 2018 Google, Inc. All rights reserved. - -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 client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" - scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" -) - -// BrokersGetter has a method to return a BrokerInterface. -// A group's client should implement this interface. -type BrokersGetter interface { - Brokers(namespace string) BrokerInterface -} - -// BrokerInterface has methods to work with Broker resources. -type BrokerInterface interface { - Create(*v1alpha1.Broker) (*v1alpha1.Broker, error) - Update(*v1alpha1.Broker) (*v1alpha1.Broker, error) - Delete(name string, options *v1.DeleteOptions) error - DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error - Get(name string, options v1.GetOptions) (*v1alpha1.Broker, error) - List(opts v1.ListOptions) (*v1alpha1.BrokerList, error) - Watch(opts v1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Broker, err error) - BrokerExpansion -} - -// brokers implements BrokerInterface -type brokers struct { - client rest.Interface - ns string -} - -// newBrokers returns a Brokers -func newBrokers(c *EventingV1alpha1Client, namespace string) *brokers { - return &brokers{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the broker, and returns the corresponding broker object, and an error if there is any. -func (c *brokers) Get(name string, options v1.GetOptions) (result *v1alpha1.Broker, err error) { - result = &v1alpha1.Broker{} - err = c.client.Get(). - Namespace(c.ns). - Resource("brokers"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Brokers that match those selectors. -func (c *brokers) List(opts v1.ListOptions) (result *v1alpha1.BrokerList, err error) { - result = &v1alpha1.BrokerList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("brokers"). - VersionedParams(&opts, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested brokers. -func (c *brokers) Watch(opts v1.ListOptions) (watch.Interface, error) { - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("brokers"). - VersionedParams(&opts, scheme.ParameterCodec). - Watch() -} - -// Create takes the representation of a broker and creates it. Returns the server's representation of the broker, and an error, if there is any. -func (c *brokers) Create(broker *v1alpha1.Broker) (result *v1alpha1.Broker, err error) { - result = &v1alpha1.Broker{} - err = c.client.Post(). - Namespace(c.ns). - Resource("brokers"). - Body(broker). - Do(). - Into(result) - return -} - -// Update takes the representation of a broker and updates it. Returns the server's representation of the broker, and an error, if there is any. -func (c *brokers) Update(broker *v1alpha1.Broker) (result *v1alpha1.Broker, err error) { - result = &v1alpha1.Broker{} - err = c.client.Put(). - Namespace(c.ns). - Resource("brokers"). - Name(broker.Name). - Body(broker). - Do(). - Into(result) - return -} - -// Delete takes name of the broker and deletes it. Returns an error if one occurs. -func (c *brokers) Delete(name string, options *v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("brokers"). - Name(name). - Body(options). - Do(). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *brokers) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("brokers"). - VersionedParams(&listOptions, scheme.ParameterCodec). - Body(options). - Do(). - Error() -} - -// Patch applies the patch and returns the patched broker. -func (c *brokers) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Broker, err error) { - result = &v1alpha1.Broker{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("brokers"). - SubResource(subresources...). - Name(name). - Body(data). - Do(). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/bus.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/bus.go new file mode 100644 index 00000000000..447452e7e3e --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/bus.go @@ -0,0 +1,157 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// BusesGetter has a method to return a BusInterface. +// A group's client should implement this interface. +type BusesGetter interface { + Buses(namespace string) BusInterface +} + +// BusInterface has methods to work with Bus resources. +type BusInterface interface { + Create(*v1alpha1.Bus) (*v1alpha1.Bus, error) + Update(*v1alpha1.Bus) (*v1alpha1.Bus, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.Bus, error) + List(opts v1.ListOptions) (*v1alpha1.BusList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Bus, err error) + BusExpansion +} + +// buses implements BusInterface +type buses struct { + client rest.Interface + ns string +} + +// newBuses returns a Buses +func newBuses(c *EventingV1alpha1Client, namespace string) *buses { + return &buses{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the bus, and returns the corresponding bus object, and an error if there is any. +func (c *buses) Get(name string, options v1.GetOptions) (result *v1alpha1.Bus, err error) { + result = &v1alpha1.Bus{} + err = c.client.Get(). + Namespace(c.ns). + Resource("buses"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Buses that match those selectors. +func (c *buses) List(opts v1.ListOptions) (result *v1alpha1.BusList, err error) { + result = &v1alpha1.BusList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("buses"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested buses. +func (c *buses) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("buses"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a bus and creates it. Returns the server's representation of the bus, and an error, if there is any. +func (c *buses) Create(bus *v1alpha1.Bus) (result *v1alpha1.Bus, err error) { + result = &v1alpha1.Bus{} + err = c.client.Post(). + Namespace(c.ns). + Resource("buses"). + Body(bus). + Do(). + Into(result) + return +} + +// Update takes the representation of a bus and updates it. Returns the server's representation of the bus, and an error, if there is any. +func (c *buses) Update(bus *v1alpha1.Bus) (result *v1alpha1.Bus, err error) { + result = &v1alpha1.Bus{} + err = c.client.Put(). + Namespace(c.ns). + Resource("buses"). + Name(bus.Name). + Body(bus). + Do(). + Into(result) + return +} + +// Delete takes name of the bus and deletes it. Returns an error if one occurs. +func (c *buses) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("buses"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *buses) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("buses"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched bus. +func (c *buses) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Bus, err error) { + result = &v1alpha1.Bus{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("buses"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go index 60066f9b70e..07dc34eaefd 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go @@ -28,7 +28,7 @@ import ( type EventingV1alpha1Interface interface { RESTClient() rest.Interface BindsGetter - BrokersGetter + BusesGetter ChannelsGetter EventSourcesGetter EventTypesGetter @@ -44,8 +44,8 @@ func (c *EventingV1alpha1Client) Binds(namespace string) BindInterface { return newBinds(c, namespace) } -func (c *EventingV1alpha1Client) Brokers(namespace string) BrokerInterface { - return newBrokers(c, namespace) +func (c *EventingV1alpha1Client) Buses(namespace string) BusInterface { + return newBuses(c, namespace) } func (c *EventingV1alpha1Client) Channels(namespace string) ChannelInterface { diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_broker.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_broker.go deleted file mode 100644 index d1bc9c8b5b0..00000000000 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_broker.go +++ /dev/null @@ -1,128 +0,0 @@ -/* -Copyright 2018 Google, Inc. All rights reserved. - -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 client-gen. DO NOT EDIT. - -package fake - -import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakeBrokers implements BrokerInterface -type FakeBrokers struct { - Fake *FakeEventingV1alpha1 - ns string -} - -var brokersResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "brokers"} - -var brokersKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Broker"} - -// Get takes name of the broker, and returns the corresponding broker object, and an error if there is any. -func (c *FakeBrokers) Get(name string, options v1.GetOptions) (result *v1alpha1.Broker, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(brokersResource, c.ns, name), &v1alpha1.Broker{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Broker), err -} - -// List takes label and field selectors, and returns the list of Brokers that match those selectors. -func (c *FakeBrokers) List(opts v1.ListOptions) (result *v1alpha1.BrokerList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(brokersResource, brokersKind, c.ns, opts), &v1alpha1.BrokerList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.BrokerList{} - for _, item := range obj.(*v1alpha1.BrokerList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested brokers. -func (c *FakeBrokers) Watch(opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(brokersResource, c.ns, opts)) - -} - -// Create takes the representation of a broker and creates it. Returns the server's representation of the broker, and an error, if there is any. -func (c *FakeBrokers) Create(broker *v1alpha1.Broker) (result *v1alpha1.Broker, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(brokersResource, c.ns, broker), &v1alpha1.Broker{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Broker), err -} - -// Update takes the representation of a broker and updates it. Returns the server's representation of the broker, and an error, if there is any. -func (c *FakeBrokers) Update(broker *v1alpha1.Broker) (result *v1alpha1.Broker, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(brokersResource, c.ns, broker), &v1alpha1.Broker{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Broker), err -} - -// Delete takes name of the broker and deletes it. Returns an error if one occurs. -func (c *FakeBrokers) Delete(name string, options *v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(brokersResource, c.ns, name), &v1alpha1.Broker{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeBrokers) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(brokersResource, c.ns, listOptions) - - _, err := c.Fake.Invokes(action, &v1alpha1.BrokerList{}) - return err -} - -// Patch applies the patch and returns the patched broker. -func (c *FakeBrokers) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Broker, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(brokersResource, c.ns, name, data, subresources...), &v1alpha1.Broker{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Broker), err -} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_bus.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_bus.go new file mode 100644 index 00000000000..a5501b78102 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_bus.go @@ -0,0 +1,128 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeBuses implements BusInterface +type FakeBuses struct { + Fake *FakeEventingV1alpha1 + ns string +} + +var busesResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "buses"} + +var busesKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Bus"} + +// Get takes name of the bus, and returns the corresponding bus object, and an error if there is any. +func (c *FakeBuses) Get(name string, options v1.GetOptions) (result *v1alpha1.Bus, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(busesResource, c.ns, name), &v1alpha1.Bus{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Bus), err +} + +// List takes label and field selectors, and returns the list of Buses that match those selectors. +func (c *FakeBuses) List(opts v1.ListOptions) (result *v1alpha1.BusList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(busesResource, busesKind, c.ns, opts), &v1alpha1.BusList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.BusList{} + for _, item := range obj.(*v1alpha1.BusList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested buses. +func (c *FakeBuses) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(busesResource, c.ns, opts)) + +} + +// Create takes the representation of a bus and creates it. Returns the server's representation of the bus, and an error, if there is any. +func (c *FakeBuses) Create(bus *v1alpha1.Bus) (result *v1alpha1.Bus, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(busesResource, c.ns, bus), &v1alpha1.Bus{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Bus), err +} + +// Update takes the representation of a bus and updates it. Returns the server's representation of the bus, and an error, if there is any. +func (c *FakeBuses) Update(bus *v1alpha1.Bus) (result *v1alpha1.Bus, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(busesResource, c.ns, bus), &v1alpha1.Bus{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Bus), err +} + +// Delete takes name of the bus and deletes it. Returns an error if one occurs. +func (c *FakeBuses) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(busesResource, c.ns, name), &v1alpha1.Bus{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeBuses) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(busesResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.BusList{}) + return err +} + +// Patch applies the patch and returns the patched bus. +func (c *FakeBuses) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Bus, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(busesResource, c.ns, name, data, subresources...), &v1alpha1.Bus{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Bus), err +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go index ca0f1e21270..98f3bca729a 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go @@ -32,8 +32,8 @@ func (c *FakeEventingV1alpha1) Binds(namespace string) v1alpha1.BindInterface { return &FakeBinds{c, namespace} } -func (c *FakeEventingV1alpha1) Brokers(namespace string) v1alpha1.BrokerInterface { - return &FakeBrokers{c, namespace} +func (c *FakeEventingV1alpha1) Buses(namespace string) v1alpha1.BusInterface { + return &FakeBuses{c, namespace} } func (c *FakeEventingV1alpha1) Channels(namespace string) v1alpha1.ChannelInterface { diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go index 25501bae84e..d662a9ba4d6 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go @@ -20,7 +20,7 @@ package v1alpha1 type BindExpansion interface{} -type BrokerExpansion interface{} +type BusExpansion interface{} type ChannelExpansion interface{} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/broker.go b/pkg/client/informers/externalversions/eventing/v1alpha1/bus.go similarity index 58% rename from pkg/client/informers/externalversions/eventing/v1alpha1/broker.go rename to pkg/client/informers/externalversions/eventing/v1alpha1/bus.go index cdb1d10d701..509e1d4ff5a 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/broker.go +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/bus.go @@ -31,59 +31,59 @@ import ( cache "k8s.io/client-go/tools/cache" ) -// BrokerInformer provides access to a shared informer and lister for -// Brokers. -type BrokerInformer interface { +// BusInformer provides access to a shared informer and lister for +// Buses. +type BusInformer interface { Informer() cache.SharedIndexInformer - Lister() v1alpha1.BrokerLister + Lister() v1alpha1.BusLister } -type brokerInformer struct { +type busInformer struct { factory internalinterfaces.SharedInformerFactory tweakListOptions internalinterfaces.TweakListOptionsFunc namespace string } -// NewBrokerInformer constructs a new informer for Broker type. +// NewBusInformer constructs a new informer for Bus type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewBrokerInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredBrokerInformer(client, namespace, resyncPeriod, indexers, nil) +func NewBusInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredBusInformer(client, namespace, resyncPeriod, indexers, nil) } -// NewFilteredBrokerInformer constructs a new informer for Broker type. +// NewFilteredBusInformer constructs a new informer for Bus type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredBrokerInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredBusInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Brokers(namespace).List(options) + return client.EventingV1alpha1().Buses(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Brokers(namespace).Watch(options) + return client.EventingV1alpha1().Buses(namespace).Watch(options) }, }, - &eventing_v1alpha1.Broker{}, + &eventing_v1alpha1.Bus{}, resyncPeriod, indexers, ) } -func (f *brokerInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredBrokerInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +func (f *busInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredBusInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) } -func (f *brokerInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventing_v1alpha1.Broker{}, f.defaultInformer) +func (f *busInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&eventing_v1alpha1.Bus{}, f.defaultInformer) } -func (f *brokerInformer) Lister() v1alpha1.BrokerLister { - return v1alpha1.NewBrokerLister(f.Informer().GetIndexer()) +func (f *busInformer) Lister() v1alpha1.BusLister { + return v1alpha1.NewBusLister(f.Informer().GetIndexer()) } diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go b/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go index d0ad39ab74b..8f1543b40b2 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go @@ -26,8 +26,8 @@ import ( type Interface interface { // Binds returns a BindInformer. Binds() BindInformer - // Brokers returns a BrokerInformer. - Brokers() BrokerInformer + // Buses returns a BusInformer. + Buses() BusInformer // Channels returns a ChannelInformer. Channels() ChannelInformer // EventSources returns a EventSourceInformer. @@ -54,9 +54,9 @@ func (v *version) Binds() BindInformer { return &bindInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } -// Brokers returns a BrokerInformer. -func (v *version) Brokers() BrokerInformer { - return &brokerInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +// Buses returns a BusInformer. +func (v *version) Buses() BusInformer { + return &busInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } // Channels returns a ChannelInformer. diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 1319d2aafe0..7df54feeeba 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -60,8 +60,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource // Group=eventing.knative.dev, Version=v1alpha1 case v1alpha1.SchemeGroupVersion.WithResource("binds"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Binds().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("brokers"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Brokers().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("buses"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Buses().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("channels"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Channels().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("eventsources"): diff --git a/pkg/client/listers/eventing/v1alpha1/broker.go b/pkg/client/listers/eventing/v1alpha1/broker.go deleted file mode 100644 index 824857e555c..00000000000 --- a/pkg/client/listers/eventing/v1alpha1/broker.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2018 Google, Inc. All rights reserved. - -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 lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// BrokerLister helps list Brokers. -type BrokerLister interface { - // List lists all Brokers in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.Broker, err error) - // Brokers returns an object that can list and get Brokers. - Brokers(namespace string) BrokerNamespaceLister - BrokerListerExpansion -} - -// brokerLister implements the BrokerLister interface. -type brokerLister struct { - indexer cache.Indexer -} - -// NewBrokerLister returns a new BrokerLister. -func NewBrokerLister(indexer cache.Indexer) BrokerLister { - return &brokerLister{indexer: indexer} -} - -// List lists all Brokers in the indexer. -func (s *brokerLister) List(selector labels.Selector) (ret []*v1alpha1.Broker, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Broker)) - }) - return ret, err -} - -// Brokers returns an object that can list and get Brokers. -func (s *brokerLister) Brokers(namespace string) BrokerNamespaceLister { - return brokerNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// BrokerNamespaceLister helps list and get Brokers. -type BrokerNamespaceLister interface { - // List lists all Brokers in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.Broker, err error) - // Get retrieves the Broker from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.Broker, error) - BrokerNamespaceListerExpansion -} - -// brokerNamespaceLister implements the BrokerNamespaceLister -// interface. -type brokerNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Brokers in the indexer for a given namespace. -func (s brokerNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Broker, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Broker)) - }) - return ret, err -} - -// Get retrieves the Broker from the indexer for a given namespace and name. -func (s brokerNamespaceLister) Get(name string) (*v1alpha1.Broker, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("broker"), name) - } - return obj.(*v1alpha1.Broker), nil -} diff --git a/pkg/client/listers/eventing/v1alpha1/bus.go b/pkg/client/listers/eventing/v1alpha1/bus.go new file mode 100644 index 00000000000..9483e1c8fd3 --- /dev/null +++ b/pkg/client/listers/eventing/v1alpha1/bus.go @@ -0,0 +1,94 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// BusLister helps list Buses. +type BusLister interface { + // List lists all Buses in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.Bus, err error) + // Buses returns an object that can list and get Buses. + Buses(namespace string) BusNamespaceLister + BusListerExpansion +} + +// busLister implements the BusLister interface. +type busLister struct { + indexer cache.Indexer +} + +// NewBusLister returns a new BusLister. +func NewBusLister(indexer cache.Indexer) BusLister { + return &busLister{indexer: indexer} +} + +// List lists all Buses in the indexer. +func (s *busLister) List(selector labels.Selector) (ret []*v1alpha1.Bus, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Bus)) + }) + return ret, err +} + +// Buses returns an object that can list and get Buses. +func (s *busLister) Buses(namespace string) BusNamespaceLister { + return busNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// BusNamespaceLister helps list and get Buses. +type BusNamespaceLister interface { + // List lists all Buses in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.Bus, err error) + // Get retrieves the Bus from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.Bus, error) + BusNamespaceListerExpansion +} + +// busNamespaceLister implements the BusNamespaceLister +// interface. +type busNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Buses in the indexer for a given namespace. +func (s busNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Bus, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Bus)) + }) + return ret, err +} + +// Get retrieves the Bus from the indexer for a given namespace and name. +func (s busNamespaceLister) Get(name string) (*v1alpha1.Bus, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("bus"), name) + } + return obj.(*v1alpha1.Bus), nil +} diff --git a/pkg/client/listers/eventing/v1alpha1/expansion_generated.go b/pkg/client/listers/eventing/v1alpha1/expansion_generated.go index 36c399412ab..ce1340cbe21 100644 --- a/pkg/client/listers/eventing/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/eventing/v1alpha1/expansion_generated.go @@ -26,13 +26,13 @@ type BindListerExpansion interface{} // BindNamespaceLister. type BindNamespaceListerExpansion interface{} -// BrokerListerExpansion allows custom methods to be added to -// BrokerLister. -type BrokerListerExpansion interface{} +// BusListerExpansion allows custom methods to be added to +// BusLister. +type BusListerExpansion interface{} -// BrokerNamespaceListerExpansion allows custom methods to be added to -// BrokerNamespaceLister. -type BrokerNamespaceListerExpansion interface{} +// BusNamespaceListerExpansion allows custom methods to be added to +// BusNamespaceLister. +type BusNamespaceListerExpansion interface{} // ChannelListerExpansion allows custom methods to be added to // ChannelLister. diff --git a/pkg/controller/broker/controller.go b/pkg/controller/bus/controller.go similarity index 71% rename from pkg/controller/broker/controller.go rename to pkg/controller/bus/controller.go index 0e2535abab5..b513703e577 100644 --- a/pkg/controller/broker/controller.go +++ b/pkg/controller/bus/controller.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package broker +package bus import ( "fmt" @@ -50,36 +50,36 @@ import ( eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" ) -const controllerAgentName = "broker-controller" +const controllerAgentName = "bus-controller" const ( - // SuccessSynced is used as part of the Event 'reason' when a Broker is synced + // SuccessSynced is used as part of the Event 'reason' when a Bus is synced SuccessSynced = "Synced" - // ErrResourceExists is used as part of the Event 'reason' when a Broker fails + // ErrResourceExists is used as part of the Event 'reason' when a Bus fails // to sync due to a Service of the same name already existing. ErrResourceExists = "ErrResourceExists" // MessageResourceExists is the message used for Events when a resource // fails to sync due to a Service already existing - MessageResourceExists = "Resource %q already exists and is not managed by Broker" - // MessageResourceSynced is the message used for an Event fired when a Broker + MessageResourceExists = "Resource %q already exists and is not managed by Bus" + // MessageResourceSynced is the message used for an Event fired when a Bus // is synced successfully - MessageResourceSynced = "Broker synced successfully" + MessageResourceSynced = "Bus synced successfully" ) -// Controller is the controller implementation for Broker resources +// Controller is the controller implementation for Bus resources type Controller struct { // kubeclientset is a standard kubernetes clientset kubeclientset kubernetes.Interface - // brokerclientset is a clientset for our own API group - brokerclientset clientset.Interface + // busclientset is a clientset for our own API group + busclientset clientset.Interface deploymentsLister appslisters.DeploymentLister deploymentsSynced cache.InformerSynced servicesLister corelisters.ServiceLister servicesSynced cache.InformerSynced - brokersLister listers.BrokerLister - brokersSynced cache.InformerSynced + busesLister listers.BusLister + busesSynced cache.InformerSynced // workqueue is a rate limited work queue. This is used to queue work to be // processed instead of performing it as soon as a change happens. This @@ -92,23 +92,23 @@ type Controller struct { recorder record.EventRecorder } -// NewController returns a new broker controller +// NewController returns a new bus controller func NewController( kubeclientset kubernetes.Interface, - brokerclientset clientset.Interface, + busclientset clientset.Interface, kubeInformerFactory kubeinformers.SharedInformerFactory, - brokerInformerFactory informers.SharedInformerFactory, + busInformerFactory informers.SharedInformerFactory, routeInformerFactory elainformers.SharedInformerFactory) controller.Interface { - // obtain references to shared index informers for the Broker, Deployment and Service + // obtain references to shared index informers for the Bus, Deployment and Service // types. - brokerInformer := brokerInformerFactory.Eventing().V1alpha1().Brokers() + busInformer := busInformerFactory.Eventing().V1alpha1().Buses() deploymentInformer := kubeInformerFactory.Apps().V1().Deployments() serviceInformer := kubeInformerFactory.Core().V1().Services() // Create event broadcaster - // Add broker-controller types to the default Kubernetes Scheme so Events can be - // logged for broker-controller types. + // Add bus-controller types to the default Kubernetes Scheme so Events can be + // logged for bus-controller types. channelscheme.AddToScheme(scheme.Scheme) glog.V(4).Info("Creating event broadcaster") eventBroadcaster := record.NewBroadcaster() @@ -118,28 +118,28 @@ func NewController( controller := &Controller{ kubeclientset: kubeclientset, - brokerclientset: brokerclientset, + busclientset: busclientset, deploymentsLister: deploymentInformer.Lister(), deploymentsSynced: deploymentInformer.Informer().HasSynced, servicesLister: serviceInformer.Lister(), servicesSynced: serviceInformer.Informer().HasSynced, - brokersLister: brokerInformer.Lister(), - brokersSynced: brokerInformer.Informer().HasSynced, - workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Brokers"), + busesLister: busInformer.Lister(), + busesSynced: busInformer.Informer().HasSynced, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Buses"), recorder: recorder, } glog.Info("Setting up event handlers") - // Set up an event handler for when Broker resources change - brokerInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: controller.enqueueBroker, + // Set up an event handler for when Bus resources change + busInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.enqueueBus, UpdateFunc: func(old, new interface{}) { - controller.enqueueBroker(new) + controller.enqueueBus(new) }, }) // Set up an event handler for when Service resources change. This // handler will lookup the owner of the given Service, and if it is - // owned by a Broker resource will enqueue that Broker resource for + // owned by a Bus resource will enqueue that Bus resource for // processing. This way, we don't need to implement custom logic for // handling Service resources. More info on this pattern: // https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md @@ -170,16 +170,16 @@ func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error { defer c.workqueue.ShutDown() // Start the informer factories to begin populating the informer caches - glog.Info("Starting Broker controller") + glog.Info("Starting Bus controller") // Wait for the caches to be synced before starting workers glog.Info("Waiting for informer caches to sync") - if ok := cache.WaitForCacheSync(stopCh, c.deploymentsSynced, c.servicesSynced, c.brokersSynced); !ok { + if ok := cache.WaitForCacheSync(stopCh, c.deploymentsSynced, c.servicesSynced, c.busesSynced); !ok { return fmt.Errorf("failed to wait for caches to sync") } glog.Info("Starting workers") - // Launch two workers to process Broker resources + // Launch two workers to process Bus resources for i := 0; i < threadiness; i++ { go wait.Until(c.runWorker, time.Second, stopCh) } @@ -233,7 +233,7 @@ func (c *Controller) processNextWorkItem() bool { return nil } // Run the syncHandler, passing it the namespace/name string of the - // Broker resource to be synced. + // Bus resource to be synced. if err := c.syncHandler(key); err != nil { return fmt.Errorf("error syncing '%s': %s", key, err.Error()) } @@ -253,7 +253,7 @@ func (c *Controller) processNextWorkItem() bool { } // syncHandler compares the actual state with the desired, and attempts to -// converge the two. It then updates the Status block of the Broker resource +// converge the two. It then updates the Status block of the Bus resource // with the current status of the resource. func (c *Controller) syncHandler(key string) error { // Convert the namespace/name string into a distinct namespace and name @@ -263,46 +263,46 @@ func (c *Controller) syncHandler(key string) error { return nil } - // Get the Broker resource with this namespace/name - broker, err := c.brokersLister.Brokers(namespace).Get(name) + // Get the Bus resource with this namespace/name + bus, err := c.busesLister.Buses(namespace).Get(name) if err != nil { - // The Broker resource may no longer exist, in which case we stop + // The Bus resource may no longer exist, in which case we stop // processing. if errors.IsNotFound(err) { - runtime.HandleError(fmt.Errorf("broker '%s' in work queue no longer exists", key)) + runtime.HandleError(fmt.Errorf("bus '%s' in work queue no longer exists", key)) return nil } return err } - // Sync Service derived from the Broker - service, err := c.syncBrokerService(broker) + // Sync Service derived from the Bus + service, err := c.syncBusService(bus) if err != nil { return err } - // Sync Deployment derived from the Broker - deployment, err := c.syncBrokerDeployment(broker) + // Sync Deployment derived from the Bus + deployment, err := c.syncBusDeployment(bus) if err != nil { return err } - // Finally, we update the status block of the Broker resource to reflect the + // Finally, we update the status block of the Bus resource to reflect the // current state of the world - return c.updateBrokerStatus(broker, service, deployment) + return c.updateBusStatus(bus, service, deployment) - c.recorder.Event(broker, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) + c.recorder.Event(bus, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) return nil } -func (c *Controller) syncBrokerService(broker *eventingv1alpha1.Broker) (*corev1.Service, error) { +func (c *Controller) syncBusService(bus *eventingv1alpha1.Bus) (*corev1.Service, error) { // Get the service with the specified service name - serviceName := controller.BrokerServiceName(broker.ObjectMeta.Name) - service, err := c.servicesLister.Services(broker.Namespace).Get(serviceName) + serviceName := controller.BusServiceName(bus.ObjectMeta.Name) + service, err := c.servicesLister.Services(bus.Namespace).Get(serviceName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - service, err = c.kubeclientset.CoreV1().Services(broker.Namespace).Create(newService(broker)) + service, err = c.kubeclientset.CoreV1().Services(bus.Namespace).Create(newService(bus)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -312,24 +312,24 @@ func (c *Controller) syncBrokerService(broker *eventingv1alpha1.Broker) (*corev1 return nil, err } - // If the Service is not controlled by this Broker resource, we should log + // If the Service is not controlled by this Bus resource, we should log // a warning to the event recorder and return - if !metav1.IsControlledBy(service, broker) { + if !metav1.IsControlledBy(service, bus) { msg := fmt.Sprintf(MessageResourceExists, service.Name) - c.recorder.Event(broker, corev1.EventTypeWarning, ErrResourceExists, msg) + c.recorder.Event(bus, corev1.EventTypeWarning, ErrResourceExists, msg) return nil, fmt.Errorf(msg) } return service, nil } -func (c *Controller) syncBrokerDeployment(broker *eventingv1alpha1.Broker) (*appsv1.Deployment, error) { +func (c *Controller) syncBusDeployment(bus *eventingv1alpha1.Bus) (*appsv1.Deployment, error) { // Get the deployment with the specified deployment name - deploymentName := controller.BrokerDeploymentName(broker.ObjectMeta.Name) - deployment, err := c.deploymentsLister.Deployments(broker.Namespace).Get(deploymentName) + deploymentName := controller.BusDeploymentName(bus.ObjectMeta.Name) + deployment, err := c.deploymentsLister.Deployments(bus.Namespace).Get(deploymentName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - deployment, err = c.kubeclientset.AppsV1().Deployments(broker.Namespace).Create(newDeployment(broker)) + deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Create(newDeployment(bus)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -339,20 +339,20 @@ func (c *Controller) syncBrokerDeployment(broker *eventingv1alpha1.Broker) (*app return nil, err } - // If the Deployment is not controlled by this Broker resource, we should log + // If the Deployment is not controlled by this Bus resource, we should log // a warning to the event recorder and return - if !metav1.IsControlledBy(deployment, broker) { + if !metav1.IsControlledBy(deployment, bus) { msg := fmt.Sprintf(MessageResourceExists, deployment.Name) - c.recorder.Event(broker, corev1.EventTypeWarning, ErrResourceExists, msg) + c.recorder.Event(bus, corev1.EventTypeWarning, ErrResourceExists, msg) return nil, fmt.Errorf(msg) } - // If the Deployment does not match the Broker's proposed Deployment we should update + // If the Deployment does not match the Bus's proposed Deployment we should update // the Deployment resource. - proposedDeployment := newDeployment(broker) + proposedDeployment := newDeployment(bus) if !reflect.DeepEqual(proposedDeployment.Spec, deployment.Spec) { - glog.V(4).Infof("Broker %s container spec updated", broker.Name) - deployment, err = c.kubeclientset.AppsV1().Deployments(broker.Namespace).Update(proposedDeployment) + glog.V(4).Infof("Bus %s container spec updated", bus.Name) + deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Update(proposedDeployment) if err != nil { return nil, err @@ -362,23 +362,23 @@ func (c *Controller) syncBrokerDeployment(broker *eventingv1alpha1.Broker) (*app return deployment, nil } -func (c *Controller) updateBrokerStatus(broker *eventingv1alpha1.Broker, service *corev1.Service, deployment *appsv1.Deployment) error { +func (c *Controller) updateBusStatus(bus *eventingv1alpha1.Bus, service *corev1.Service, deployment *appsv1.Deployment) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance - brokerCopy := broker.DeepCopy() + busCopy := bus.DeepCopy() // If the CustomResourceSubresources feature gate is not enabled, - // we must use Update instead of UpdateStatus to update the Status block of the Broker resource. + // we must use Update instead of UpdateStatus to update the Status block of the Bus resource. // UpdateStatus will not allow changes to the Spec of the resource, // which is ideal for ensuring nothing other than resource status has been updated. - _, err := c.brokerclientset.EventingV1alpha1().Brokers(broker.Namespace).Update(brokerCopy) + _, err := c.busclientset.EventingV1alpha1().Buses(bus.Namespace).Update(busCopy) return err } -// enqueueBroker takes a Broker resource and converts it into a namespace/name +// enqueueBus takes a Bus resource and converts it into a namespace/name // string which is then put onto the work queue. This method should *not* be -// passed resources of any type other than Broker. -func (c *Controller) enqueueBroker(obj interface{}) { +// passed resources of any type other than Bus. +func (c *Controller) enqueueBus(obj interface{}) { var key string var err error if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil { @@ -389,9 +389,9 @@ func (c *Controller) enqueueBroker(obj interface{}) { } // handleObject will take any resource implementing metav1.Object and attempt -// to find the Broker resource that 'owns' it. It does this by looking at the +// to find the Bus resource that 'owns' it. It does this by looking at the // objects metadata.ownerReferences field for an appropriate OwnerReference. -// It then enqueues that Broker resource to be processed. If the object does not +// It then enqueues that Bus resource to be processed. If the object does not // have an appropriate OwnerReference, it will simply be skipped. func (c *Controller) handleObject(obj interface{}) { var object metav1.Object @@ -411,40 +411,40 @@ func (c *Controller) handleObject(obj interface{}) { } glog.V(4).Infof("Processing object: %s", object.GetName()) if ownerRef := metav1.GetControllerOf(object); ownerRef != nil { - // If this object is not owned by a Broker, we should not do anything more + // If this object is not owned by a Bus, we should not do anything more // with it. - if ownerRef.Kind != "Broker" { + if ownerRef.Kind != "Bus" { return } - broker, err := c.brokersLister.Brokers(object.GetNamespace()).Get(ownerRef.Name) + bus, err := c.busesLister.Buses(object.GetNamespace()).Get(ownerRef.Name) if err != nil { - glog.V(4).Infof("ignoring orphaned object '%s' of broker '%s'", object.GetSelfLink(), ownerRef.Name) + glog.V(4).Infof("ignoring orphaned object '%s' of bus '%s'", object.GetSelfLink(), ownerRef.Name) return } - c.enqueueBroker(broker) + c.enqueueBus(bus) return } } -// newService creates a new Service for a Broker resource. It also sets +// newService creates a new Service for a Bus resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover -// the Broker resource that 'owns' it. -func newService(broker *eventingv1alpha1.Broker) *corev1.Service { +// the Bus resource that 'owns' it. +func newService(bus *eventingv1alpha1.Bus) *corev1.Service { labels := map[string]string{ - "broker": broker.Name, + "bus": bus.Name, } return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.BrokerServiceName(broker.ObjectMeta.Name), - Namespace: broker.Namespace, + Name: controller.BusServiceName(bus.ObjectMeta.Name), + Namespace: bus.Namespace, Labels: labels, OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(broker, schema.GroupVersionKind{ + *metav1.NewControllerRef(bus, schema.GroupVersionKind{ Group: eventingv1alpha1.SchemeGroupVersion.Group, Version: eventingv1alpha1.SchemeGroupVersion.Version, - Kind: "Broker", + Kind: "Bus", }), }, }, @@ -461,34 +461,34 @@ func newService(broker *eventingv1alpha1.Broker) *corev1.Service { } } -// newDeployment creates a new Deployment for a Broker resource. It also sets +// newDeployment creates a new Deployment for a Bus resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover -// the Broker resource that 'owns' it. -func newDeployment(broker *eventingv1alpha1.Broker) *appsv1.Deployment { +// the Bus resource that 'owns' it. +func newDeployment(bus *eventingv1alpha1.Bus) *appsv1.Deployment { labels := map[string]string{ - "broker": broker.Name, + "bus": bus.Name, } one := int32(1) - container := broker.Spec.Container.DeepCopy() + container := bus.Spec.Container.DeepCopy() container.Env = append(container.Env, corev1.EnvVar{ Name: "PORT", Value: "8080", }, corev1.EnvVar{ - Name: "BROKER_NAME", - Value: broker.Name, + Name: "BUS_NAME", + Value: bus.Name, }, ) return &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.BrokerDeploymentName(broker.ObjectMeta.Name), - Namespace: broker.Namespace, + Name: controller.BusDeploymentName(bus.ObjectMeta.Name), + Namespace: bus.Namespace, OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(broker, schema.GroupVersionKind{ + *metav1.NewControllerRef(bus, schema.GroupVersionKind{ Group: eventingv1alpha1.SchemeGroupVersion.Group, Version: eventingv1alpha1.SchemeGroupVersion.Version, - Kind: "Broker", + Kind: "Bus", }), }, }, diff --git a/pkg/controller/channel/controller.go b/pkg/controller/channel/controller.go index c4282546ca7..0f4c570f6cf 100644 --- a/pkg/controller/channel/controller.go +++ b/pkg/controller/channel/controller.go @@ -288,8 +288,8 @@ func (c *Controller) syncHandler(key string) error { return err } - // Sync RouteRule derived from a brokered Channel - brokeredChannelRouteRule, err := c.syncBrokeredChannel(channel) + // Sync RouteRule derived from a bused Channel + busedChannelRouteRule, err := c.syncBusedChannel(channel) if err != nil { return err } @@ -302,7 +302,7 @@ func (c *Controller) syncHandler(key string) error { // Finally, we update the status block of the Channel resource to reflect the // current state of the world - err = c.updateChannelStatus(channel, service, ingress, brokeredChannelRouteRule) + err = c.updateChannelStatus(channel, service, ingress, busedChannelRouteRule) if err != nil { return err } @@ -338,12 +338,12 @@ func (c *Controller) syncChannelService(channel *eventingv1alpha1.Channel) (*cor return service, nil } -func (c *Controller) syncBrokeredChannel(channel *eventingv1alpha1.Channel) (*istiov1alpha2.RouteRule, error) { +func (c *Controller) syncBusedChannel(channel *eventingv1alpha1.Channel) (*istiov1alpha2.RouteRule, error) { // Get the RouteRule with the specified Channel name - routeruleName := controller.BrokeredChannelRouteRuleName(channel.ObjectMeta.Name) + routeruleName := controller.BusedChannelRouteRuleName(channel.ObjectMeta.Name) routerule, err := c.routerulesLister.RouteRules(channel.Namespace).Get(routeruleName) - if channel.Spec.Broker == "" { + if channel.Spec.Bus == "" { // If the resource exists, delete it if routerule != nil { // Remove RouteRule @@ -359,7 +359,7 @@ func (c *Controller) syncBrokeredChannel(channel *eventingv1alpha1.Channel) (*is // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - routerule, err = c.channelclientset.ConfigV1alpha2().RouteRules(channel.Namespace).Create(newBrokeredRouteRule(channel)) + routerule, err = c.channelclientset.ConfigV1alpha2().RouteRules(channel.Namespace).Create(newBusedRouteRule(channel)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -409,7 +409,7 @@ func (c *Controller) syncChannelIngress(channel *eventingv1alpha1.Channel) (*ext return ingress, nil } -func (c *Controller) updateChannelStatus(channel *eventingv1alpha1.Channel, service *corev1.Service, ingress *extensionsv1beta1.Ingress, brokeredChannelRouteRule *istiov1alpha2.RouteRule) error { +func (c *Controller) updateChannelStatus(channel *eventingv1alpha1.Channel, service *corev1.Service, ingress *extensionsv1beta1.Ingress, busedChannelRouteRule *istiov1alpha2.RouteRule) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance @@ -503,17 +503,17 @@ func newService(channel *eventingv1alpha1.Channel) *corev1.Service { } } -// newBrokeredRouteRule creates a new RouteRule for a brokered Channel resource. It also sets +// newBusedRouteRule creates a new RouteRule for a bused Channel resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Channel resource that 'owns' it. -func newBrokeredRouteRule(channel *eventingv1alpha1.Channel) *istiov1alpha2.RouteRule { +func newBusedRouteRule(channel *eventingv1alpha1.Channel) *istiov1alpha2.RouteRule { labels := map[string]string{ - "broker": channel.Spec.Broker, + "bus": channel.Spec.Bus, "channel": channel.Name, } return &istiov1alpha2.RouteRule{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.BrokeredChannelRouteRuleName(channel.Name), + Name: controller.BusedChannelRouteRuleName(channel.Name), Namespace: channel.Namespace, Labels: labels, OwnerReferences: []metav1.OwnerReference{ @@ -531,7 +531,7 @@ func newBrokeredRouteRule(channel *eventingv1alpha1.Channel) *istiov1alpha2.Rout Route: []istiov1alpha2.DestinationWeight{ { Destination: istiov1alpha2.IstioService{ - Name: controller.BrokerServiceName(channel.Spec.Broker), + Name: controller.BusServiceName(channel.Spec.Bus), }, Weight: 100, }, diff --git a/pkg/controller/names.go b/pkg/controller/names.go index 606a5888b89..65cbb6da9f9 100644 --- a/pkg/controller/names.go +++ b/pkg/controller/names.go @@ -18,15 +18,15 @@ package controller import "fmt" -func BrokerDeploymentName(brokerName string) string { - return fmt.Sprintf("%s-broker", brokerName) +func BusDeploymentName(busName string) string { + return fmt.Sprintf("%s-bus", busName) } -func BrokerServiceName(brokerName string) string { - return fmt.Sprintf("%s-broker", brokerName) +func BusServiceName(busName string) string { + return fmt.Sprintf("%s-bus", busName) } -func BrokeredChannelRouteRuleName(channelName string) string { +func BusedChannelRouteRuleName(channelName string) string { return fmt.Sprintf("%s-channel", channelName) } diff --git a/pkg/controller/subscription/controller.go b/pkg/controller/subscription/controller.go index 8da2fc72d1c..fd95b49cc92 100644 --- a/pkg/controller/subscription/controller.go +++ b/pkg/controller/subscription/controller.go @@ -275,9 +275,9 @@ func (c *Controller) syncHandler(key string) error { channel, err := c.channelsLister.Channels(namespace).Get(subscription.Spec.Channel) - var brokerlessRouterule *istiov1alpha2.RouteRule - if channel.Spec.Broker == "" { - brokerlessRouterule, err = c.syncBrokerlessRouteRule(subscription) + var buslessRouterule *istiov1alpha2.RouteRule + if channel.Spec.Bus == "" { + buslessRouterule, err = c.syncBuslessRouteRule(subscription) if err != nil { return err } @@ -285,7 +285,7 @@ func (c *Controller) syncHandler(key string) error { // Finally, we update the status block of the Subscription resource to reflect the // current state of the world - err = c.updateSubscriptionStatus(subscription, brokerlessRouterule) + err = c.updateSubscriptionStatus(subscription, buslessRouterule) if err != nil { return err } @@ -294,7 +294,7 @@ func (c *Controller) syncHandler(key string) error { return nil } -func (c *Controller) syncBrokerlessRouteRule(subscription *eventingv1alpha1.Subscription) (*istiov1alpha2.RouteRule, error) { +func (c *Controller) syncBuslessRouteRule(subscription *eventingv1alpha1.Subscription) (*istiov1alpha2.RouteRule, error) { // Get the routerule with the name specified in Subscription.spec routeruleName := controller.SubscriptionRouteRuleName(subscription.ObjectMeta.Name) @@ -322,7 +322,7 @@ func (c *Controller) syncBrokerlessRouteRule(subscription *eventingv1alpha1.Subs return routerule, nil } -func (c *Controller) updateSubscriptionStatus(subscription *eventingv1alpha1.Subscription, brokerlessRouterule *istiov1alpha2.RouteRule) error { +func (c *Controller) updateSubscriptionStatus(subscription *eventingv1alpha1.Subscription, buslessRouterule *istiov1alpha2.RouteRule) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance diff --git a/pkg/subscription/monitor.go b/pkg/subscription/monitor.go index 6742d6a3c9d..d5d99ddb6d1 100644 --- a/pkg/subscription/monitor.go +++ b/pkg/subscription/monitor.go @@ -27,8 +27,8 @@ import ( ) type Monitor struct { - brokerName string - handler MonitorEventHandlerFuncs + busName string + handler MonitorEventHandlerFuncs cache map[channelKey]channelSummary mutex *sync.Mutex @@ -50,14 +50,14 @@ type subscriptionSummary struct { Subscription eventingv1alpha1.SubscriptionSpec } -func NewMonitor(brokerName string, informerFactory informers.SharedInformerFactory, handler MonitorEventHandlerFuncs) *Monitor { +func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, handler MonitorEventHandlerFuncs) *Monitor { channelInformer := informerFactory.Eventing().V1alpha1().Channels() subscriptionInformer := informerFactory.Eventing().V1alpha1().Subscriptions() monitor := &Monitor{ - brokerName: brokerName, - handler: handler, + busName: busName, + handler: handler, cache: make(map[channelKey]channelSummary), mutex: &sync.Mutex{}, @@ -81,7 +81,7 @@ func NewMonitor(brokerName string, informerFactory informers.SharedInformerFacto } monitor.createOrUpdateChannel(newChannel) - if oldChannel.Spec.Broker != newChannel.Spec.Broker { + if oldChannel.Spec.Bus != newChannel.Spec.Bus { monitor.removeChannel(oldChannel) } }, @@ -125,8 +125,8 @@ func (m *Monitor) Subscriptions(channel string, namespace string) *[]eventingv1a channelKey := makeChannelKeyWithNames(channel, namespace) summary := m.getOrCreateChannelSummary(channelKey) - if summary.Channel.Broker != m.brokerName { - // the channel is not for this broker + if summary.Channel.Bus != m.busName { + // the channel is not for this bus return nil } diff --git a/sample/square/README.md b/sample/square/README.md index 483a7a2b80f..9b9ff665809 100644 --- a/sample/square/README.md +++ b/sample/square/README.md @@ -6,20 +6,20 @@ # Install -Square can be run either with or without a broker. +Square can be run either with or without a bus. -At this time, in order to switch between brokered and brokerless, it is recomended that you delete the previous resources and then apply the new resources. +At this time, in order to switch between bused and busless, it is recomended that you delete the previous resources and then apply the new resources. -## Brokerless +## Busless ``` -kubectl apply -f square.yaml -f square-brokerless.yaml +kubectl apply -f square.yaml -f square-busless.yaml ``` -## Brokered +## Bused ``` -kubectl apply -f square.yaml -f square-brokered.yaml +kubectl apply -f square.yaml -f square-bused.yaml ``` # Invoke diff --git a/sample/square/square-brokered.yaml b/sample/square/square-bused.yaml similarity index 93% rename from sample/square/square-brokered.yaml rename to sample/square/square-bused.yaml index 6769eb9b1ed..c0773f83481 100644 --- a/sample/square/square-brokered.yaml +++ b/sample/square/square-bused.yaml @@ -3,7 +3,7 @@ kind: Channel metadata: name: square spec: - broker: stub + bus: stub --- apiVersion: eventing.knative.dev/v1alpha1 diff --git a/sample/square/square-brokerless.yaml b/sample/square/square-busless.yaml similarity index 100% rename from sample/square/square-brokerless.yaml rename to sample/square/square-busless.yaml From efd068eb61359e60d0ff12dce8901e4388e79676 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Tue, 5 Jun 2018 17:23:02 -0400 Subject: [PATCH 11/21] Drop 'Busless' support --- cmd/controller/main.go | 2 - pkg/controller/channel/controller.go | 34 +- pkg/controller/names.go | 6 +- pkg/controller/subscription/controller.go | 425 ---------------------- sample/square/README.md | 14 +- sample/square/square-bused.yaml | 15 - sample/square/square-busless.yaml | 13 - sample/square/square.yaml | 17 + 8 files changed, 29 insertions(+), 497 deletions(-) delete mode 100644 pkg/controller/subscription/controller.go delete mode 100644 sample/square/square-bused.yaml delete mode 100644 sample/square/square-busless.yaml diff --git a/cmd/controller/main.go b/cmd/controller/main.go index a289ff2ecb5..d4ba762c0b8 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -38,7 +38,6 @@ import ( "github.com/knative/eventing/pkg/controller/bind" "github.com/knative/eventing/pkg/controller/bus" "github.com/knative/eventing/pkg/controller/channel" - "github.com/knative/eventing/pkg/controller/subscription" "github.com/knative/eventing/pkg/signals" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -90,7 +89,6 @@ func main() { bind.NewController, bus.NewController, channel.NewController, - subscription.NewController, } // Build all of our controllers, with the clients constructed above. diff --git a/pkg/controller/channel/controller.go b/pkg/controller/channel/controller.go index 0f4c570f6cf..f130101b318 100644 --- a/pkg/controller/channel/controller.go +++ b/pkg/controller/channel/controller.go @@ -288,8 +288,8 @@ func (c *Controller) syncHandler(key string) error { return err } - // Sync RouteRule derived from a bused Channel - busedChannelRouteRule, err := c.syncBusedChannel(channel) + // Sync RouteRule derived from a Channel + routeRule, err := c.syncChannelRouteRule(channel) if err != nil { return err } @@ -302,7 +302,7 @@ func (c *Controller) syncHandler(key string) error { // Finally, we update the status block of the Channel resource to reflect the // current state of the world - err = c.updateChannelStatus(channel, service, ingress, busedChannelRouteRule) + err = c.updateChannelStatus(channel, service, ingress, routeRule) if err != nil { return err } @@ -338,28 +338,14 @@ func (c *Controller) syncChannelService(channel *eventingv1alpha1.Channel) (*cor return service, nil } -func (c *Controller) syncBusedChannel(channel *eventingv1alpha1.Channel) (*istiov1alpha2.RouteRule, error) { +func (c *Controller) syncChannelRouteRule(channel *eventingv1alpha1.Channel) (*istiov1alpha2.RouteRule, error) { // Get the RouteRule with the specified Channel name - routeruleName := controller.BusedChannelRouteRuleName(channel.ObjectMeta.Name) + routeruleName := controller.ChannelRouteRuleName(channel.ObjectMeta.Name) routerule, err := c.routerulesLister.RouteRules(channel.Namespace).Get(routeruleName) - if channel.Spec.Bus == "" { - // If the resource exists, delete it - if routerule != nil { - // Remove RouteRule - err = c.channelclientset.ConfigV1alpha2().RouteRules(channel.Namespace).Delete(routeruleName, nil) - if err != nil { - return routerule, err - } - } else { - // nothing to do - return routerule, nil - } - } - // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - routerule, err = c.channelclientset.ConfigV1alpha2().RouteRules(channel.Namespace).Create(newBusedRouteRule(channel)) + routerule, err = c.channelclientset.ConfigV1alpha2().RouteRules(channel.Namespace).Create(newRouteRule(channel)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -409,7 +395,7 @@ func (c *Controller) syncChannelIngress(channel *eventingv1alpha1.Channel) (*ext return ingress, nil } -func (c *Controller) updateChannelStatus(channel *eventingv1alpha1.Channel, service *corev1.Service, ingress *extensionsv1beta1.Ingress, busedChannelRouteRule *istiov1alpha2.RouteRule) error { +func (c *Controller) updateChannelStatus(channel *eventingv1alpha1.Channel, service *corev1.Service, ingress *extensionsv1beta1.Ingress, routeRule *istiov1alpha2.RouteRule) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance @@ -503,17 +489,17 @@ func newService(channel *eventingv1alpha1.Channel) *corev1.Service { } } -// newBusedRouteRule creates a new RouteRule for a bused Channel resource. It also sets +// newRouteRule creates a new RouteRule for a Channel resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Channel resource that 'owns' it. -func newBusedRouteRule(channel *eventingv1alpha1.Channel) *istiov1alpha2.RouteRule { +func newRouteRule(channel *eventingv1alpha1.Channel) *istiov1alpha2.RouteRule { labels := map[string]string{ "bus": channel.Spec.Bus, "channel": channel.Name, } return &istiov1alpha2.RouteRule{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.BusedChannelRouteRuleName(channel.Name), + Name: controller.ChannelRouteRuleName(channel.Name), Namespace: channel.Namespace, Labels: labels, OwnerReferences: []metav1.OwnerReference{ diff --git a/pkg/controller/names.go b/pkg/controller/names.go index 65cbb6da9f9..9281e703473 100644 --- a/pkg/controller/names.go +++ b/pkg/controller/names.go @@ -26,7 +26,7 @@ func BusServiceName(busName string) string { return fmt.Sprintf("%s-bus", busName) } -func BusedChannelRouteRuleName(channelName string) string { +func ChannelRouteRuleName(channelName string) string { return fmt.Sprintf("%s-channel", channelName) } @@ -37,7 +37,3 @@ func ChannelIngressName(channelName string) string { func ChannelServiceName(channelName string) string { return fmt.Sprintf("%s-channel", channelName) } - -func SubscriptionRouteRuleName(subscriptionName string) string { - return fmt.Sprintf("%s-subscription", subscriptionName) -} diff --git a/pkg/controller/subscription/controller.go b/pkg/controller/subscription/controller.go deleted file mode 100644 index fd95b49cc92..00000000000 --- a/pkg/controller/subscription/controller.go +++ /dev/null @@ -1,425 +0,0 @@ -/* -Copyright 2017 The Kubernetes 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 subscription - -import ( - "fmt" - "time" - - "github.com/golang/glog" - istiolisters "github.com/knative/eventing/pkg/client/listers/istio/v1alpha2" - "github.com/knative/eventing/pkg/controller" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/util/wait" - kubeinformers "k8s.io/client-go/informers" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/kubernetes/scheme" - typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" - "k8s.io/client-go/tools/cache" - "k8s.io/client-go/tools/record" - "k8s.io/client-go/util/workqueue" - - clientset "github.com/knative/eventing/pkg/client/clientset/versioned" - subscriptionscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" - informers "github.com/knative/eventing/pkg/client/informers/externalversions" - listers "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" - elainformers "github.com/knative/serving/pkg/client/informers/externalversions" - - eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" - istiov1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" -) - -const controllerAgentName = "subscription-controller" - -const ( - // SuccessSynced is used as part of the Event 'reason' when a Subscription is synced - SuccessSynced = "Synced" - // ErrResourceExists is used as part of the Event 'reason' when a Subscription fails - // to sync due to a RouteRule of the same name already existing. - ErrResourceExists = "ErrResourceExists" - - // MessageResourceExists is the message used for Events when a resource - // fails to sync due to a RouteRule already existing - MessageResourceExists = "Resource %q already exists and is not managed by Subscription" - // MessageResourceSynced is the message used for an Event fired when a Subscription - // is synced successfully - MessageResourceSynced = "Subscription synced successfully" -) - -// Controller is the controller implementation for Subscription resources -type Controller struct { - // kubeclientset is a standard kubernetes clientset - kubeclientset kubernetes.Interface - // subscriptionclientset is a clientset for our own API group - subscriptionclientset clientset.Interface - - routerulesLister istiolisters.RouteRuleLister - routerulesSynced cache.InformerSynced - channelsLister listers.ChannelLister - channelsSynced cache.InformerSynced - subscriptionsLister listers.SubscriptionLister - subscriptionsSynced cache.InformerSynced - - // workqueue is a rate limited work queue. This is used to queue work to be - // processed instead of performing it as soon as a change happens. This - // means we can ensure we only process a fixed amount of resources at a - // time, and makes it easy to ensure we are never processing the same item - // simultaneously in two different workers. - workqueue workqueue.RateLimitingInterface - // recorder is an event recorder for recording Event resources to the - // Kubernetes API. - recorder record.EventRecorder -} - -// NewController returns a new subscription controller -func NewController( - kubeclientset kubernetes.Interface, - subscriptionclientset clientset.Interface, - kubeInformerFactory kubeinformers.SharedInformerFactory, - subscriptionInformerFactory informers.SharedInformerFactory, - routeInformerFactory elainformers.SharedInformerFactory) controller.Interface { - - // obtain references to shared index informers for the RouteRule and Subscription - // types. - routeruleInformer := subscriptionInformerFactory.Config().V1alpha2().RouteRules() - channelInformer := subscriptionInformerFactory.Eventing().V1alpha1().Channels() - subscriptionInformer := subscriptionInformerFactory.Eventing().V1alpha1().Subscriptions() - - // Create event broadcaster - // Add subscription-controller types to the default Kubernetes Scheme so Events can be - // logged for subscription-controller types. - subscriptionscheme.AddToScheme(scheme.Scheme) - glog.V(4).Info("Creating event broadcaster") - eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) - eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")}) - recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName}) - - controller := &Controller{ - kubeclientset: kubeclientset, - subscriptionclientset: subscriptionclientset, - routerulesLister: routeruleInformer.Lister(), - routerulesSynced: routeruleInformer.Informer().HasSynced, - channelsLister: channelInformer.Lister(), - channelsSynced: channelInformer.Informer().HasSynced, - subscriptionsLister: subscriptionInformer.Lister(), - subscriptionsSynced: subscriptionInformer.Informer().HasSynced, - workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Subscriptions"), - recorder: recorder, - } - - glog.Info("Setting up event handlers") - // Set up an event handler for when Subscription resources change - subscriptionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: controller.enqueueSubscription, - UpdateFunc: func(old, new interface{}) { - controller.enqueueSubscription(new) - }, - }) - // Set up an event handler for when RouteRule resources change. This - // handler will lookup the owner of the given RouteRule, and if it is - // owned by a Subscription resource will enqueue that Subscription resource for - // processing. This way, we don't need to implement custom logic for - // handling RouteRule resources. More info on this pattern: - // https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md - routeruleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: controller.handleObject, - UpdateFunc: func(old, new interface{}) { - newRouteRule := new.(*istiov1alpha2.RouteRule) - oldRouteRule := old.(*istiov1alpha2.RouteRule) - if newRouteRule.ResourceVersion == oldRouteRule.ResourceVersion { - // Periodic resync will send update events for all known RouteRules. - // Two different versions of the same RouteRule will always have different RVs. - return - } - controller.handleObject(new) - }, - DeleteFunc: controller.handleObject, - }) - - return controller -} - -// Run will set up the event handlers for types we are interested in, as well -// as syncing informer caches and starting workers. It will block until stopCh -// is closed, at which point it will shutdown the workqueue and wait for -// workers to finish processing their current work items. -func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error { - defer runtime.HandleCrash() - defer c.workqueue.ShutDown() - - // Start the informer factories to begin populating the informer caches - glog.Info("Starting Subscription controller") - - // Wait for the caches to be synced before starting workers - glog.Info("Waiting for informer caches to sync") - if ok := cache.WaitForCacheSync(stopCh, c.routerulesSynced, c.subscriptionsSynced); !ok { - return fmt.Errorf("failed to wait for caches to sync") - } - - glog.Info("Starting workers") - // Launch two workers to process Subscription resources - for i := 0; i < threadiness; i++ { - go wait.Until(c.runWorker, time.Second, stopCh) - } - - glog.Info("Started workers") - <-stopCh - glog.Info("Shutting down workers") - - return nil -} - -// runWorker is a long-running function that will continually call the -// processNextWorkItem function in order to read and process a message on the -// workqueue. -func (c *Controller) runWorker() { - for c.processNextWorkItem() { - } -} - -// processNextWorkItem will read a single work item off the workqueue and -// attempt to process it, by calling the syncHandler. -func (c *Controller) processNextWorkItem() bool { - obj, shutdown := c.workqueue.Get() - - if shutdown { - return false - } - - // We wrap this block in a func so we can defer c.workqueue.Done. - err := func(obj interface{}) error { - // We call Done here so the workqueue knows we have finished - // processing this item. We also must remember to call Forget if we - // do not want this work item being re-queued. For example, we do - // not call Forget if a transient error occurs, instead the item is - // put back on the workqueue and attempted again after a back-off - // period. - defer c.workqueue.Done(obj) - var key string - var ok bool - // We expect strings to come off the workqueue. These are of the - // form namespace/name. We do this as the delayed nature of the - // workqueue means the items in the informer cache may actually be - // more up to date that when the item was initially put onto the - // workqueue. - if key, ok = obj.(string); !ok { - // As the item in the workqueue is actually invalid, we call - // Forget here else we'd go into a loop of attempting to - // process a work item that is invalid. - c.workqueue.Forget(obj) - runtime.HandleError(fmt.Errorf("expected string in workqueue but got %#v", obj)) - return nil - } - // Run the syncHandler, passing it the namespace/name string of the - // Subscription resource to be synced. - if err := c.syncHandler(key); err != nil { - return fmt.Errorf("error syncing '%s': %s", key, err.Error()) - } - // Finally, if no error occurs we Forget this item so it does not - // get queued again until another change happens. - c.workqueue.Forget(obj) - glog.Infof("Successfully synced '%s'", key) - return nil - }(obj) - - if err != nil { - runtime.HandleError(err) - return true - } - - return true -} - -// syncHandler compares the actual state with the desired, and attempts to -// converge the two. It then updates the Status block of the Subscription resource -// with the current status of the resource. -func (c *Controller) syncHandler(key string) error { - // Convert the namespace/name string into a distinct namespace and name - namespace, name, err := cache.SplitMetaNamespaceKey(key) - if err != nil { - runtime.HandleError(fmt.Errorf("invalid resource key: %s", key)) - return nil - } - - // Get the Subscription resource with this namespace/name - subscription, err := c.subscriptionsLister.Subscriptions(namespace).Get(name) - if err != nil { - // The Subscription resource may no longer exist, in which case we stop - // processing. - if errors.IsNotFound(err) { - runtime.HandleError(fmt.Errorf("subscription '%s' in work queue no longer exists", key)) - return nil - } - - return err - } - - channel, err := c.channelsLister.Channels(namespace).Get(subscription.Spec.Channel) - - var buslessRouterule *istiov1alpha2.RouteRule - if channel.Spec.Bus == "" { - buslessRouterule, err = c.syncBuslessRouteRule(subscription) - if err != nil { - return err - } - } - - // Finally, we update the status block of the Subscription resource to reflect the - // current state of the world - err = c.updateSubscriptionStatus(subscription, buslessRouterule) - if err != nil { - return err - } - - c.recorder.Event(subscription, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) - return nil -} - -func (c *Controller) syncBuslessRouteRule(subscription *eventingv1alpha1.Subscription) (*istiov1alpha2.RouteRule, error) { - - // Get the routerule with the name specified in Subscription.spec - routeruleName := controller.SubscriptionRouteRuleName(subscription.ObjectMeta.Name) - routerule, err := c.routerulesLister.RouteRules(subscription.Namespace).Get(routeruleName) - // If the resource doesn't exist, we'll create it - if errors.IsNotFound(err) { - routerule, err = c.subscriptionclientset.ConfigV1alpha2().RouteRules(subscription.Namespace).Create(newRouteRule(subscription)) - } - - // If an error occurs during Get/Create, we'll requeue the item so we can - // attempt processing again later. This could have been caused by a - // temporary network failure, or any other transient reason. - if err != nil { - return nil, err - } - - // If the RouteRule is not controlled by this Subscription resource, we should log - // a warning to the event recorder and ret - if !metav1.IsControlledBy(routerule, subscription) { - msg := fmt.Sprintf(MessageResourceExists, routerule.Name) - c.recorder.Event(subscription, corev1.EventTypeWarning, ErrResourceExists, msg) - return nil, fmt.Errorf(msg) - } - - return routerule, nil -} - -func (c *Controller) updateSubscriptionStatus(subscription *eventingv1alpha1.Subscription, buslessRouterule *istiov1alpha2.RouteRule) error { - // NEVER modify objects from the store. It's a read-only, local cache. - // You can use DeepCopy() to make a deep copy of original object and modify this copy - // Or create a copy manually for better performance - subscriptionCopy := subscription.DeepCopy() - // If the CustomResourceSubresources feature gate is not enabled, - // we must use Update instead of UpdateStatus to update the Status block of the Subscription resource. - // UpdateStatus will not allow changes to the Spec of the resource, - // which is ideal for ensuring nothing other than resource status has been updated. - _, err := c.subscriptionclientset.EventingV1alpha1().Subscriptions(subscription.Namespace).Update(subscriptionCopy) - return err -} - -// enqueueSubscription takes a Subscription resource and converts it into a namespace/name -// string which is then put onto the work queue. This method should *not* be -// passed resources of any type other than Subscription. -func (c *Controller) enqueueSubscription(obj interface{}) { - var key string - var err error - if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil { - runtime.HandleError(err) - return - } - c.workqueue.AddRateLimited(key) -} - -// handleObject will take any resource implementing metav1.Object and attempt -// to find the Subscription resource that 'owns' it. It does this by looking at the -// objects metadata.ownerReferences field for an appropriate OwnerReference. -// It then enqueues that Subscription resource to be processed. If the object does not -// have an appropriate OwnerReference, it will simply be skipped. -func (c *Controller) handleObject(obj interface{}) { - var object metav1.Object - var ok bool - if object, ok = obj.(metav1.Object); !ok { - tombstone, ok := obj.(cache.DeletedFinalStateUnknown) - if !ok { - runtime.HandleError(fmt.Errorf("error decoding object, invalid type")) - return - } - object, ok = tombstone.Obj.(metav1.Object) - if !ok { - runtime.HandleError(fmt.Errorf("error decoding object tombstone, invalid type")) - return - } - glog.V(4).Infof("Recovered deleted object '%s' from tombstone", object.GetName()) - } - glog.V(4).Infof("Processing object: %s", object.GetName()) - if ownerRef := metav1.GetControllerOf(object); ownerRef != nil { - // If this object is not owned by a Subscription, we should not do anything more - // with it. - if ownerRef.Kind != "Subscription" { - return - } - - subscription, err := c.subscriptionsLister.Subscriptions(object.GetNamespace()).Get(ownerRef.Name) - if err != nil { - glog.V(4).Infof("ignoring orphaned object '%s' of subscription '%s'", object.GetSelfLink(), ownerRef.Name) - return - } - - c.enqueueSubscription(subscription) - return - } -} - -// newRouteRule creates a new RouteRule for a Subscription resource. It also sets -// the appropriate OwnerReferences on the resource so handleObject can discover -// the Subscription resource that 'owns' it. -func newRouteRule(subscription *eventingv1alpha1.Subscription) *istiov1alpha2.RouteRule { - labels := map[string]string{ - "subscription": subscription.Name, - } - return &istiov1alpha2.RouteRule{ - ObjectMeta: metav1.ObjectMeta{ - Name: controller.SubscriptionRouteRuleName(subscription.ObjectMeta.Name), - Namespace: subscription.Namespace, - Labels: labels, - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(subscription, schema.GroupVersionKind{ - Group: eventingv1alpha1.SchemeGroupVersion.Group, - Version: eventingv1alpha1.SchemeGroupVersion.Version, - Kind: "Subscription", - }), - }, - }, - Spec: istiov1alpha2.RouteRuleSpec{ - Destination: istiov1alpha2.IstioService{ - Name: controller.ChannelServiceName(subscription.Spec.Channel), - }, - Route: []istiov1alpha2.DestinationWeight{ - { - Destination: istiov1alpha2.IstioService{ - Name: subscription.Spec.Subscriber, - }, - Weight: 100, - }, - }, - }, - } -} diff --git a/sample/square/README.md b/sample/square/README.md index 9b9ff665809..31e6b4b159f 100644 --- a/sample/square/README.md +++ b/sample/square/README.md @@ -6,20 +6,8 @@ # Install -Square can be run either with or without a bus. - -At this time, in order to switch between bused and busless, it is recomended that you delete the previous resources and then apply the new resources. - -## Busless - -``` -kubectl apply -f square.yaml -f square-busless.yaml -``` - -## Bused - ``` -kubectl apply -f square.yaml -f square-bused.yaml +kubectl apply -f square.yaml ``` # Invoke diff --git a/sample/square/square-bused.yaml b/sample/square/square-bused.yaml deleted file mode 100644 index c0773f83481..00000000000 --- a/sample/square/square-bused.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: eventing.knative.dev/v1alpha1 -kind: Channel -metadata: - name: square -spec: - bus: stub - ---- -apiVersion: eventing.knative.dev/v1alpha1 -kind: Subscription -metadata: - name: square -spec: - channel: square - subscriber: square diff --git a/sample/square/square-busless.yaml b/sample/square/square-busless.yaml deleted file mode 100644 index f62fa427e57..00000000000 --- a/sample/square/square-busless.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: eventing.knative.dev/v1alpha1 -kind: Channel -metadata: - name: square - ---- -apiVersion: eventing.knative.dev/v1alpha1 -kind: Subscription -metadata: - name: square -spec: - channel: square - subscriber: square diff --git a/sample/square/square.yaml b/sample/square/square.yaml index 13cc50ac20f..029ec30f9fc 100644 --- a/sample/square/square.yaml +++ b/sample/square/square.yaml @@ -32,3 +32,20 @@ spec: targetPort: 8080 selector: app: square + +--- +apiVersion: eventing.knative.dev/v1alpha1 +kind: Channel +metadata: + name: square +spec: + bus: stub + +--- +apiVersion: eventing.knative.dev/v1alpha1 +kind: Subscription +metadata: + name: square +spec: + channel: square + subscriber: square From 4b5eb8fe6f1d6d13cf9af4ff2fc2392a433e8c4d Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Tue, 5 Jun 2018 18:55:04 -0400 Subject: [PATCH 12/21] Move channel CRDs into channels.eventing.knative.dev group --- config/bus.yaml | 4 +- config/buses/stub.yaml | 2 +- config/{stream.yaml => channel.yaml} | 4 +- config/subscription.yaml | 4 +- hack/update-codegen.sh | 2 +- pkg/apis/channels/register.go | 21 + .../v1alpha1/bus_types.go | 2 +- .../v1alpha1/channel_types.go | 2 +- pkg/apis/channels/v1alpha1/doc.go | 16 + pkg/apis/channels/v1alpha1/register.go | 57 +++ .../v1alpha1/subscription_types.go | 2 +- .../v1alpha1/zz_generated.deepcopy.go | 366 ++++++++++++++++++ pkg/apis/eventing/v1alpha1/register.go | 6 - .../v1alpha1/zz_generated.deepcopy.go | 341 ---------------- pkg/client/clientset/versioned/clientset.go | 22 ++ .../versioned/fake/clientset_generated.go | 12 + .../clientset/versioned/fake/register.go | 2 + .../clientset/versioned/scheme/register.go | 2 + .../{eventing => channels}/v1alpha1/bus.go | 4 +- .../v1alpha1/channel.go | 4 +- .../channels/v1alpha1/channels_client.go | 100 +++++ .../versioned/typed/channels/v1alpha1/doc.go | 20 + .../typed/channels/v1alpha1/fake/doc.go | 20 + .../v1alpha1/fake/fake_bus.go | 8 +- .../v1alpha1/fake/fake_channel.go | 8 +- .../v1alpha1/fake/fake_channels_client.go | 48 +++ .../v1alpha1/fake/fake_subscription.go | 8 +- .../channels/v1alpha1/generated_expansion.go | 25 ++ .../v1alpha1/subscription.go | 4 +- .../eventing/v1alpha1/eventing_client.go | 15 - .../v1alpha1/fake/fake_eventing_client.go | 12 - .../eventing/v1alpha1/generated_expansion.go | 6 - .../externalversions/channels/interface.go | 46 +++ .../{eventing => channels}/v1alpha1/bus.go | 12 +- .../v1alpha1/channel.go | 12 +- .../channels/v1alpha1/interface.go | 59 +++ .../v1alpha1/subscription.go | 12 +- .../eventing/v1alpha1/interface.go | 21 - .../informers/externalversions/factory.go | 6 + .../informers/externalversions/generic.go | 25 +- .../{eventing => channels}/v1alpha1/bus.go | 2 +- .../v1alpha1/channel.go | 2 +- .../channels/v1alpha1/expansion_generated.go | 43 ++ .../v1alpha1/subscription.go | 2 +- .../eventing/v1alpha1/expansion_generated.go | 24 -- pkg/controller/bus/controller.go | 26 +- pkg/controller/channel/controller.go | 34 +- pkg/subscription/monitor.go | 52 +-- sample/hello/hello-channel.yaml | 4 +- sample/square/square.yaml | 4 +- 50 files changed, 989 insertions(+), 546 deletions(-) rename config/{stream.yaml => channel.yaml} (69%) create mode 100644 pkg/apis/channels/register.go rename pkg/apis/{eventing => channels}/v1alpha1/bus_types.go (96%) rename pkg/apis/{eventing => channels}/v1alpha1/channel_types.go (96%) create mode 100644 pkg/apis/channels/v1alpha1/doc.go create mode 100644 pkg/apis/channels/v1alpha1/register.go rename pkg/apis/{eventing => channels}/v1alpha1/subscription_types.go (96%) create mode 100644 pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go rename pkg/client/clientset/versioned/typed/{eventing => channels}/v1alpha1/bus.go (97%) rename pkg/client/clientset/versioned/typed/{eventing => channels}/v1alpha1/channel.go (97%) create mode 100644 pkg/client/clientset/versioned/typed/channels/v1alpha1/channels_client.go create mode 100644 pkg/client/clientset/versioned/typed/channels/v1alpha1/doc.go create mode 100644 pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/doc.go rename pkg/client/clientset/versioned/typed/{eventing => channels}/v1alpha1/fake/fake_bus.go (92%) rename pkg/client/clientset/versioned/typed/{eventing => channels}/v1alpha1/fake/fake_channel.go (92%) create mode 100644 pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channels_client.go rename pkg/client/clientset/versioned/typed/{eventing => channels}/v1alpha1/fake/fake_subscription.go (93%) create mode 100644 pkg/client/clientset/versioned/typed/channels/v1alpha1/generated_expansion.go rename pkg/client/clientset/versioned/typed/{eventing => channels}/v1alpha1/subscription.go (97%) create mode 100644 pkg/client/informers/externalversions/channels/interface.go rename pkg/client/informers/externalversions/{eventing => channels}/v1alpha1/bus.go (89%) rename pkg/client/informers/externalversions/{eventing => channels}/v1alpha1/channel.go (89%) create mode 100644 pkg/client/informers/externalversions/channels/v1alpha1/interface.go rename pkg/client/informers/externalversions/{eventing => channels}/v1alpha1/subscription.go (89%) rename pkg/client/listers/{eventing => channels}/v1alpha1/bus.go (97%) rename pkg/client/listers/{eventing => channels}/v1alpha1/channel.go (97%) create mode 100644 pkg/client/listers/channels/v1alpha1/expansion_generated.go rename pkg/client/listers/{eventing => channels}/v1alpha1/subscription.go (98%) diff --git a/config/bus.yaml b/config/bus.yaml index dc031ae0769..d31bb77cd21 100644 --- a/config/bus.yaml +++ b/config/bus.yaml @@ -1,10 +1,10 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: buses.eventing.knative.dev + name: buses.channels.eventing.knative.dev spec: scope: Namespaced - group: eventing.knative.dev + group: channels.eventing.knative.dev version: v1alpha1 names: kind: Bus diff --git a/config/buses/stub.yaml b/config/buses/stub.yaml index 744c5c7cb0e..38da64ae3e4 100644 --- a/config/buses/stub.yaml +++ b/config/buses/stub.yaml @@ -1,4 +1,4 @@ -apiVersion: eventing.knative.dev/v1alpha1 +apiVersion: channels.eventing.knative.dev/v1alpha1 kind: Bus metadata: name: stub diff --git a/config/stream.yaml b/config/channel.yaml similarity index 69% rename from config/stream.yaml rename to config/channel.yaml index 692ebaf2c69..3fdc40c51e7 100644 --- a/config/stream.yaml +++ b/config/channel.yaml @@ -1,10 +1,10 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: channels.eventing.knative.dev + name: channels.channels.eventing.knative.dev spec: scope: Namespaced - group: eventing.knative.dev + group: channels.eventing.knative.dev version: v1alpha1 names: kind: Channel diff --git a/config/subscription.yaml b/config/subscription.yaml index fa4cd57bd9f..2a9b02dc5cc 100644 --- a/config/subscription.yaml +++ b/config/subscription.yaml @@ -1,10 +1,10 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: subscriptions.eventing.knative.dev + name: subscriptions.channels.eventing.knative.dev spec: scope: Namespaced - group: eventing.knative.dev + group: channels.eventing.knative.dev version: v1alpha1 names: kind: Subscription diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index ad815b7d42d..5a475a7cddd 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -27,7 +27,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-ge # instead of the $GOPATH directly. For normal projects this can be dropped. ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \ github.com/knative/eventing/pkg/client github.com/knative/eventing/pkg/apis \ - "eventing:v1alpha1 istio:v1alpha2" \ + "channels:v1alpha1 eventing:v1alpha1 istio:v1alpha2" \ --go-header-file ${SCRIPT_ROOT}/hack/boilerplate/boilerplate.go.txt # Make sure our dependencies are up-to-date diff --git a/pkg/apis/channels/register.go b/pkg/apis/channels/register.go new file mode 100644 index 00000000000..e33d29980b1 --- /dev/null +++ b/pkg/apis/channels/register.go @@ -0,0 +1,21 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 channels + +const ( + GroupName = "channels.eventing.knative.dev" +) diff --git a/pkg/apis/eventing/v1alpha1/bus_types.go b/pkg/apis/channels/v1alpha1/bus_types.go similarity index 96% rename from pkg/apis/eventing/v1alpha1/bus_types.go rename to pkg/apis/channels/v1alpha1/bus_types.go index b4f5696b757..56a012920c8 100644 --- a/pkg/apis/eventing/v1alpha1/bus_types.go +++ b/pkg/apis/channels/v1alpha1/bus_types.go @@ -26,7 +26,7 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the buses.eventing.dev CRD +// Represents the buses.channels.eventing.knative.dev CRD type Bus struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/channels/v1alpha1/channel_types.go similarity index 96% rename from pkg/apis/eventing/v1alpha1/channel_types.go rename to pkg/apis/channels/v1alpha1/channel_types.go index 7a08a7ddf58..1875d2a59cd 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/channels/v1alpha1/channel_types.go @@ -25,7 +25,7 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the channels.eventing.dev CRD +// Represents the channels.channels.eventing.knative.dev CRD type Channel struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` diff --git a/pkg/apis/channels/v1alpha1/doc.go b/pkg/apis/channels/v1alpha1/doc.go new file mode 100644 index 00000000000..bb8aa2dca6d --- /dev/null +++ b/pkg/apis/channels/v1alpha1/doc.go @@ -0,0 +1,16 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. +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. +*/ +// +k8s:deepcopy-gen=package +// Package v1alpha1 is the v1alpha1 version of the API. +// +groupName=channels.eventing.knative.dev +package v1alpha1 diff --git a/pkg/apis/channels/v1alpha1/register.go b/pkg/apis/channels/v1alpha1/register.go new file mode 100644 index 00000000000..8367d9dab86 --- /dev/null +++ b/pkg/apis/channels/v1alpha1/register.go @@ -0,0 +1,57 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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/eventing/pkg/apis/channels" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: channels.GroupName, Version: "v1alpha1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &Bus{}, + &BusList{}, + &Channel{}, + &ChannelList{}, + &Subscription{}, + &SubscriptionList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/eventing/v1alpha1/subscription_types.go b/pkg/apis/channels/v1alpha1/subscription_types.go similarity index 96% rename from pkg/apis/eventing/v1alpha1/subscription_types.go rename to pkg/apis/channels/v1alpha1/subscription_types.go index 12d4608f9f4..1a400006a3e 100644 --- a/pkg/apis/eventing/v1alpha1/subscription_types.go +++ b/pkg/apis/channels/v1alpha1/subscription_types.go @@ -25,7 +25,7 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the subscriptions.eventing.dev CRD +// Represents the subscriptions.channels.eventing.knative.dev CRD type Subscription struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` diff --git a/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..7eb1c4a948f --- /dev/null +++ b/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,366 @@ +// +build !ignore_autogenerated + +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 *Bus) DeepCopyInto(out *Bus) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + if in.Status != nil { + in, out := &in.Status, &out.Status + if *in == nil { + *out = nil + } else { + *out = new(BusStatus) + **out = **in + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Bus. +func (in *Bus) DeepCopy() *Bus { + if in == nil { + return nil + } + out := new(Bus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Bus) 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 *BusList) DeepCopyInto(out *BusList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Bus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BusList. +func (in *BusList) DeepCopy() *BusList { + if in == nil { + return nil + } + out := new(BusList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BusList) 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 *BusSpec) DeepCopyInto(out *BusSpec) { + *out = *in + in.Container.DeepCopyInto(&out.Container) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BusSpec. +func (in *BusSpec) DeepCopy() *BusSpec { + if in == nil { + return nil + } + out := new(BusSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BusStatus) DeepCopyInto(out *BusStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BusStatus. +func (in *BusStatus) DeepCopy() *BusStatus { + if in == nil { + return nil + } + out := new(BusStatus) + in.DeepCopyInto(out) + return out +} + +// 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) + out.Spec = in.Spec + if in.Status != nil { + in, out := &in.Status, &out.Status + if *in == nil { + *out = nil + } else { + *out = new(ChannelStatus) + **out = **in + } + } + 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 +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Channel) 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 *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 + 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 *ChannelStatus) DeepCopyInto(out *ChannelStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelStatus. +func (in *ChannelStatus) DeepCopy() *ChannelStatus { + if in == nil { + return nil + } + out := new(ChannelStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Subscription) DeepCopyInto(out *Subscription) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + if in.Status != nil { + in, out := &in.Status, &out.Status + if *in == nil { + *out = nil + } else { + *out = new(SubscriptionStatus) + **out = **in + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Subscription. +func (in *Subscription) DeepCopy() *Subscription { + if in == nil { + return nil + } + out := new(Subscription) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Subscription) 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 *SubscriptionList) DeepCopyInto(out *SubscriptionList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Subscription, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionList. +func (in *SubscriptionList) DeepCopy() *SubscriptionList { + if in == nil { + return nil + } + out := new(SubscriptionList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SubscriptionList) 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 SubscriptionParams) DeepCopyInto(out *SubscriptionParams) { + { + in := &in + *out = make(SubscriptionParams, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + return + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionParams. +func (in SubscriptionParams) DeepCopy() SubscriptionParams { + if in == nil { + return nil + } + out := new(SubscriptionParams) + in.DeepCopyInto(out) + return *out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SubscriptionSpec) DeepCopyInto(out *SubscriptionSpec) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + if *in == nil { + *out = nil + } else { + *out = new(SubscriptionParams) + if **in != nil { + in, out := *in, *out + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionSpec. +func (in *SubscriptionSpec) DeepCopy() *SubscriptionSpec { + if in == nil { + return nil + } + out := new(SubscriptionSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SubscriptionStatus) DeepCopyInto(out *SubscriptionStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionStatus. +func (in *SubscriptionStatus) DeepCopy() *SubscriptionStatus { + if in == nil { + return nil + } + out := new(SubscriptionStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/eventing/v1alpha1/register.go b/pkg/apis/eventing/v1alpha1/register.go index b32db09a259..4434acff701 100644 --- a/pkg/apis/eventing/v1alpha1/register.go +++ b/pkg/apis/eventing/v1alpha1/register.go @@ -47,16 +47,10 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Bind{}, &BindList{}, - &Bus{}, - &BusList{}, - &Channel{}, - &ChannelList{}, &EventSource{}, &EventSourceList{}, &EventType{}, &EventTypeList{}, - &Subscription{}, - &SubscriptionList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index 1390e25123f..4167f637307 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -165,209 +165,6 @@ func (in *BindStatus) DeepCopy() *BindStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Bus) DeepCopyInto(out *Bus) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - if in.Status != nil { - in, out := &in.Status, &out.Status - if *in == nil { - *out = nil - } else { - *out = new(BusStatus) - **out = **in - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Bus. -func (in *Bus) DeepCopy() *Bus { - if in == nil { - return nil - } - out := new(Bus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Bus) 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 *BusList) DeepCopyInto(out *BusList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Bus, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BusList. -func (in *BusList) DeepCopy() *BusList { - if in == nil { - return nil - } - out := new(BusList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *BusList) 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 *BusSpec) DeepCopyInto(out *BusSpec) { - *out = *in - in.Container.DeepCopyInto(&out.Container) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BusSpec. -func (in *BusSpec) DeepCopy() *BusSpec { - if in == nil { - return nil - } - out := new(BusSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BusStatus) DeepCopyInto(out *BusStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BusStatus. -func (in *BusStatus) DeepCopy() *BusStatus { - if in == nil { - return nil - } - out := new(BusStatus) - in.DeepCopyInto(out) - return out -} - -// 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) - out.Spec = in.Spec - if in.Status != nil { - in, out := &in.Status, &out.Status - if *in == nil { - *out = nil - } else { - *out = new(ChannelStatus) - **out = **in - } - } - 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 -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Channel) 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 *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 - 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 *ChannelStatus) DeepCopyInto(out *ChannelStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelStatus. -func (in *ChannelStatus) DeepCopy() *ChannelStatus { - if in == nil { - return nil - } - out := new(ChannelStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EventSource) DeepCopyInto(out *EventSource) { *out = *in @@ -695,141 +492,3 @@ func (in *SecretKeyReference) DeepCopy() *SecretKeyReference { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Subscription) DeepCopyInto(out *Subscription) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - if in.Status != nil { - in, out := &in.Status, &out.Status - if *in == nil { - *out = nil - } else { - *out = new(SubscriptionStatus) - **out = **in - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Subscription. -func (in *Subscription) DeepCopy() *Subscription { - if in == nil { - return nil - } - out := new(Subscription) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Subscription) 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 *SubscriptionList) DeepCopyInto(out *SubscriptionList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Subscription, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionList. -func (in *SubscriptionList) DeepCopy() *SubscriptionList { - if in == nil { - return nil - } - out := new(SubscriptionList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *SubscriptionList) 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 SubscriptionParams) DeepCopyInto(out *SubscriptionParams) { - { - in := &in - *out = make(SubscriptionParams, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - return - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionParams. -func (in SubscriptionParams) DeepCopy() SubscriptionParams { - if in == nil { - return nil - } - out := new(SubscriptionParams) - in.DeepCopyInto(out) - return *out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscriptionSpec) DeepCopyInto(out *SubscriptionSpec) { - *out = *in - if in.Params != nil { - in, out := &in.Params, &out.Params - if *in == nil { - *out = nil - } else { - *out = new(SubscriptionParams) - if **in != nil { - in, out := *in, *out - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionSpec. -func (in *SubscriptionSpec) DeepCopy() *SubscriptionSpec { - if in == nil { - return nil - } - out := new(SubscriptionSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscriptionStatus) DeepCopyInto(out *SubscriptionStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionStatus. -func (in *SubscriptionStatus) DeepCopy() *SubscriptionStatus { - if in == nil { - return nil - } - out := new(SubscriptionStatus) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index 5943ee427d5..9d648ef43ac 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -20,6 +20,7 @@ package versioned import ( glog "github.com/golang/glog" + channelsv1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/channels/v1alpha1" eventingv1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1" configv1alpha2 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/istio/v1alpha2" discovery "k8s.io/client-go/discovery" @@ -29,6 +30,9 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface + ChannelsV1alpha1() channelsv1alpha1.ChannelsV1alpha1Interface + // Deprecated: please explicitly pick a version if possible. + Channels() channelsv1alpha1.ChannelsV1alpha1Interface EventingV1alpha1() eventingv1alpha1.EventingV1alpha1Interface // Deprecated: please explicitly pick a version if possible. Eventing() eventingv1alpha1.EventingV1alpha1Interface @@ -41,10 +45,22 @@ type Interface interface { // version included in a Clientset. type Clientset struct { *discovery.DiscoveryClient + channelsV1alpha1 *channelsv1alpha1.ChannelsV1alpha1Client eventingV1alpha1 *eventingv1alpha1.EventingV1alpha1Client configV1alpha2 *configv1alpha2.ConfigV1alpha2Client } +// ChannelsV1alpha1 retrieves the ChannelsV1alpha1Client +func (c *Clientset) ChannelsV1alpha1() channelsv1alpha1.ChannelsV1alpha1Interface { + return c.channelsV1alpha1 +} + +// Deprecated: Channels retrieves the default version of ChannelsClient. +// Please explicitly pick a version. +func (c *Clientset) Channels() channelsv1alpha1.ChannelsV1alpha1Interface { + return c.channelsV1alpha1 +} + // EventingV1alpha1 retrieves the EventingV1alpha1Client func (c *Clientset) EventingV1alpha1() eventingv1alpha1.EventingV1alpha1Interface { return c.eventingV1alpha1 @@ -83,6 +99,10 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { } var cs Clientset var err error + cs.channelsV1alpha1, err = channelsv1alpha1.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } cs.eventingV1alpha1, err = eventingv1alpha1.NewForConfig(&configShallowCopy) if err != nil { return nil, err @@ -104,6 +124,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { // panics if there is an error in the config. func NewForConfigOrDie(c *rest.Config) *Clientset { var cs Clientset + cs.channelsV1alpha1 = channelsv1alpha1.NewForConfigOrDie(c) cs.eventingV1alpha1 = eventingv1alpha1.NewForConfigOrDie(c) cs.configV1alpha2 = configv1alpha2.NewForConfigOrDie(c) @@ -114,6 +135,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { // New creates a new Clientset for the given RESTClient. func New(c rest.Interface) *Clientset { var cs Clientset + cs.channelsV1alpha1 = channelsv1alpha1.New(c) cs.eventingV1alpha1 = eventingv1alpha1.New(c) cs.configV1alpha2 = configv1alpha2.New(c) diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index dd641224c41..01ebdaa37e6 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -20,6 +20,8 @@ package fake import ( clientset "github.com/knative/eventing/pkg/client/clientset/versioned" + channelsv1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/channels/v1alpha1" + fakechannelsv1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake" eventingv1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1" fakeeventingv1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake" configv1alpha2 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/istio/v1alpha2" @@ -72,6 +74,16 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { var _ clientset.Interface = &Clientset{} +// ChannelsV1alpha1 retrieves the ChannelsV1alpha1Client +func (c *Clientset) ChannelsV1alpha1() channelsv1alpha1.ChannelsV1alpha1Interface { + return &fakechannelsv1alpha1.FakeChannelsV1alpha1{Fake: &c.Fake} +} + +// Channels retrieves the ChannelsV1alpha1Client +func (c *Clientset) Channels() channelsv1alpha1.ChannelsV1alpha1Interface { + return &fakechannelsv1alpha1.FakeChannelsV1alpha1{Fake: &c.Fake} +} + // EventingV1alpha1 retrieves the EventingV1alpha1Client func (c *Clientset) EventingV1alpha1() eventingv1alpha1.EventingV1alpha1Interface { return &fakeeventingv1alpha1.FakeEventingV1alpha1{Fake: &c.Fake} diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 8c194421e54..d45b20c775a 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -19,6 +19,7 @@ limitations under the License. package fake import ( + channelsv1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" configv1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -51,6 +52,7 @@ func init() { // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. func AddToScheme(scheme *runtime.Scheme) { + channelsv1alpha1.AddToScheme(scheme) eventingv1alpha1.AddToScheme(scheme) configv1alpha2.AddToScheme(scheme) } diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index d8de07afe8b..e2e77206114 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -19,6 +19,7 @@ limitations under the License. package scheme import ( + channelsv1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" configv1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -51,6 +52,7 @@ func init() { // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. func AddToScheme(scheme *runtime.Scheme) { + channelsv1alpha1.AddToScheme(scheme) eventingv1alpha1.AddToScheme(scheme) configv1alpha2.AddToScheme(scheme) } diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/bus.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/bus.go similarity index 97% rename from pkg/client/clientset/versioned/typed/eventing/v1alpha1/bus.go rename to pkg/client/clientset/versioned/typed/channels/v1alpha1/bus.go index 447452e7e3e..fa493dbdf16 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/bus.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/bus.go @@ -19,7 +19,7 @@ limitations under the License. package v1alpha1 import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" @@ -53,7 +53,7 @@ type buses struct { } // newBuses returns a Buses -func newBuses(c *EventingV1alpha1Client, namespace string) *buses { +func newBuses(c *ChannelsV1alpha1Client, namespace string) *buses { return &buses{ client: c.RESTClient(), ns: namespace, diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/channel.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/channel.go similarity index 97% rename from pkg/client/clientset/versioned/typed/eventing/v1alpha1/channel.go rename to pkg/client/clientset/versioned/typed/channels/v1alpha1/channel.go index 44a20ab6d38..f388a2bf52f 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/channel.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/channel.go @@ -19,7 +19,7 @@ limitations under the License. package v1alpha1 import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" @@ -53,7 +53,7 @@ type channels struct { } // newChannels returns a Channels -func newChannels(c *EventingV1alpha1Client, namespace string) *channels { +func newChannels(c *ChannelsV1alpha1Client, namespace string) *channels { return &channels{ client: c.RESTClient(), ns: namespace, diff --git a/pkg/client/clientset/versioned/typed/channels/v1alpha1/channels_client.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/channels_client.go new file mode 100644 index 00000000000..ca2b6ed467b --- /dev/null +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/channels_client.go @@ -0,0 +1,100 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" + "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + rest "k8s.io/client-go/rest" +) + +type ChannelsV1alpha1Interface interface { + RESTClient() rest.Interface + BusesGetter + ChannelsGetter + SubscriptionsGetter +} + +// ChannelsV1alpha1Client is used to interact with features provided by the channels.eventing.knative.dev group. +type ChannelsV1alpha1Client struct { + restClient rest.Interface +} + +func (c *ChannelsV1alpha1Client) Buses(namespace string) BusInterface { + return newBuses(c, namespace) +} + +func (c *ChannelsV1alpha1Client) Channels(namespace string) ChannelInterface { + return newChannels(c, namespace) +} + +func (c *ChannelsV1alpha1Client) Subscriptions(namespace string) SubscriptionInterface { + return newSubscriptions(c, namespace) +} + +// NewForConfig creates a new ChannelsV1alpha1Client for the given config. +func NewForConfig(c *rest.Config) (*ChannelsV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &ChannelsV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new ChannelsV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ChannelsV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new ChannelsV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *ChannelsV1alpha1Client { + return &ChannelsV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs} + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ChannelsV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/clientset/versioned/typed/channels/v1alpha1/doc.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/doc.go new file mode 100644 index 00000000000..1d8f2a89974 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/doc.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/doc.go new file mode 100644 index 00000000000..2195046d473 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_bus.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_bus.go similarity index 92% rename from pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_bus.go rename to pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_bus.go index a5501b78102..555083df926 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_bus.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_bus.go @@ -19,7 +19,7 @@ limitations under the License. package fake import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -30,13 +30,13 @@ import ( // FakeBuses implements BusInterface type FakeBuses struct { - Fake *FakeEventingV1alpha1 + Fake *FakeChannelsV1alpha1 ns string } -var busesResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "buses"} +var busesResource = schema.GroupVersionResource{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Resource: "buses"} -var busesKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Bus"} +var busesKind = schema.GroupVersionKind{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Kind: "Bus"} // Get takes name of the bus, and returns the corresponding bus object, and an error if there is any. func (c *FakeBuses) Get(name string, options v1.GetOptions) (result *v1alpha1.Bus, err error) { diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channel.go similarity index 92% rename from pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go rename to pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channel.go index a048fd78be2..c78cf2ffb18 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channel.go @@ -19,7 +19,7 @@ limitations under the License. package fake import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -30,13 +30,13 @@ import ( // FakeChannels implements ChannelInterface type FakeChannels struct { - Fake *FakeEventingV1alpha1 + Fake *FakeChannelsV1alpha1 ns string } -var channelsResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "channels"} +var channelsResource = schema.GroupVersionResource{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Resource: "channels"} -var channelsKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Channel"} +var channelsKind = schema.GroupVersionKind{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Kind: "Channel"} // Get takes name of the channel, and returns the corresponding channel object, and an error if there is any. func (c *FakeChannels) Get(name string, options v1.GetOptions) (result *v1alpha1.Channel, err error) { diff --git a/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channels_client.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channels_client.go new file mode 100644 index 00000000000..6451375d5ce --- /dev/null +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channels_client.go @@ -0,0 +1,48 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/knative/eventing/pkg/client/clientset/versioned/typed/channels/v1alpha1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeChannelsV1alpha1 struct { + *testing.Fake +} + +func (c *FakeChannelsV1alpha1) Buses(namespace string) v1alpha1.BusInterface { + return &FakeBuses{c, namespace} +} + +func (c *FakeChannelsV1alpha1) Channels(namespace string) v1alpha1.ChannelInterface { + return &FakeChannels{c, namespace} +} + +func (c *FakeChannelsV1alpha1) Subscriptions(namespace string) v1alpha1.SubscriptionInterface { + return &FakeSubscriptions{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeChannelsV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_subscription.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_subscription.go similarity index 93% rename from pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_subscription.go rename to pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_subscription.go index 16b34013f7d..e4a8a156343 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_subscription.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_subscription.go @@ -19,7 +19,7 @@ limitations under the License. package fake import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -30,13 +30,13 @@ import ( // FakeSubscriptions implements SubscriptionInterface type FakeSubscriptions struct { - Fake *FakeEventingV1alpha1 + Fake *FakeChannelsV1alpha1 ns string } -var subscriptionsResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "subscriptions"} +var subscriptionsResource = schema.GroupVersionResource{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Resource: "subscriptions"} -var subscriptionsKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Subscription"} +var subscriptionsKind = schema.GroupVersionKind{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Kind: "Subscription"} // Get takes name of the subscription, and returns the corresponding subscription object, and an error if there is any. func (c *FakeSubscriptions) Get(name string, options v1.GetOptions) (result *v1alpha1.Subscription, err error) { diff --git a/pkg/client/clientset/versioned/typed/channels/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/generated_expansion.go new file mode 100644 index 00000000000..003509217f6 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/generated_expansion.go @@ -0,0 +1,25 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 client-gen. DO NOT EDIT. + +package v1alpha1 + +type BusExpansion interface{} + +type ChannelExpansion interface{} + +type SubscriptionExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/subscription.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/subscription.go similarity index 97% rename from pkg/client/clientset/versioned/typed/eventing/v1alpha1/subscription.go rename to pkg/client/clientset/versioned/typed/channels/v1alpha1/subscription.go index dc9b39b6179..178561aaee4 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/subscription.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/subscription.go @@ -19,7 +19,7 @@ limitations under the License. package v1alpha1 import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" scheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" @@ -53,7 +53,7 @@ type subscriptions struct { } // newSubscriptions returns a Subscriptions -func newSubscriptions(c *EventingV1alpha1Client, namespace string) *subscriptions { +func newSubscriptions(c *ChannelsV1alpha1Client, namespace string) *subscriptions { return &subscriptions{ client: c.RESTClient(), ns: namespace, diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go index 07dc34eaefd..0e91f1419bd 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go @@ -28,11 +28,8 @@ import ( type EventingV1alpha1Interface interface { RESTClient() rest.Interface BindsGetter - BusesGetter - ChannelsGetter EventSourcesGetter EventTypesGetter - SubscriptionsGetter } // EventingV1alpha1Client is used to interact with features provided by the eventing.knative.dev group. @@ -44,14 +41,6 @@ func (c *EventingV1alpha1Client) Binds(namespace string) BindInterface { return newBinds(c, namespace) } -func (c *EventingV1alpha1Client) Buses(namespace string) BusInterface { - return newBuses(c, namespace) -} - -func (c *EventingV1alpha1Client) Channels(namespace string) ChannelInterface { - return newChannels(c, namespace) -} - func (c *EventingV1alpha1Client) EventSources(namespace string) EventSourceInterface { return newEventSources(c, namespace) } @@ -60,10 +49,6 @@ func (c *EventingV1alpha1Client) EventTypes(namespace string) EventTypeInterface return newEventTypes(c, namespace) } -func (c *EventingV1alpha1Client) Subscriptions(namespace string) SubscriptionInterface { - return newSubscriptions(c, namespace) -} - // NewForConfig creates a new EventingV1alpha1Client for the given config. func NewForConfig(c *rest.Config) (*EventingV1alpha1Client, error) { config := *c diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go index 98f3bca729a..4ae3da7e3d8 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_eventing_client.go @@ -32,14 +32,6 @@ func (c *FakeEventingV1alpha1) Binds(namespace string) v1alpha1.BindInterface { return &FakeBinds{c, namespace} } -func (c *FakeEventingV1alpha1) Buses(namespace string) v1alpha1.BusInterface { - return &FakeBuses{c, namespace} -} - -func (c *FakeEventingV1alpha1) Channels(namespace string) v1alpha1.ChannelInterface { - return &FakeChannels{c, namespace} -} - func (c *FakeEventingV1alpha1) EventSources(namespace string) v1alpha1.EventSourceInterface { return &FakeEventSources{c, namespace} } @@ -48,10 +40,6 @@ func (c *FakeEventingV1alpha1) EventTypes(namespace string) v1alpha1.EventTypeIn return &FakeEventTypes{c, namespace} } -func (c *FakeEventingV1alpha1) Subscriptions(namespace string) v1alpha1.SubscriptionInterface { - return &FakeSubscriptions{c, namespace} -} - // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeEventingV1alpha1) RESTClient() rest.Interface { diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go index d662a9ba4d6..3e46993d080 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go @@ -20,12 +20,6 @@ package v1alpha1 type BindExpansion interface{} -type BusExpansion interface{} - -type ChannelExpansion interface{} - type EventSourceExpansion interface{} type EventTypeExpansion interface{} - -type SubscriptionExpansion interface{} diff --git a/pkg/client/informers/externalversions/channels/interface.go b/pkg/client/informers/externalversions/channels/interface.go new file mode 100644 index 00000000000..6818771fa4b --- /dev/null +++ b/pkg/client/informers/externalversions/channels/interface.go @@ -0,0 +1,46 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 informer-gen. DO NOT EDIT. + +package channels + +import ( + v1alpha1 "github.com/knative/eventing/pkg/client/informers/externalversions/channels/v1alpha1" + internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/bus.go b/pkg/client/informers/externalversions/channels/v1alpha1/bus.go similarity index 89% rename from pkg/client/informers/externalversions/eventing/v1alpha1/bus.go rename to pkg/client/informers/externalversions/channels/v1alpha1/bus.go index 509e1d4ff5a..f5ef24ee2d4 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/bus.go +++ b/pkg/client/informers/externalversions/channels/v1alpha1/bus.go @@ -21,10 +21,10 @@ package v1alpha1 import ( time "time" - eventing_v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + channels_v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" versioned "github.com/knative/eventing/pkg/client/clientset/versioned" internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/client/listers/channels/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" @@ -61,16 +61,16 @@ func NewFilteredBusInformer(client versioned.Interface, namespace string, resync if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Buses(namespace).List(options) + return client.ChannelsV1alpha1().Buses(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Buses(namespace).Watch(options) + return client.ChannelsV1alpha1().Buses(namespace).Watch(options) }, }, - &eventing_v1alpha1.Bus{}, + &channels_v1alpha1.Bus{}, resyncPeriod, indexers, ) @@ -81,7 +81,7 @@ func (f *busInformer) defaultInformer(client versioned.Interface, resyncPeriod t } func (f *busInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventing_v1alpha1.Bus{}, f.defaultInformer) + return f.factory.InformerFor(&channels_v1alpha1.Bus{}, f.defaultInformer) } func (f *busInformer) Lister() v1alpha1.BusLister { diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/channel.go b/pkg/client/informers/externalversions/channels/v1alpha1/channel.go similarity index 89% rename from pkg/client/informers/externalversions/eventing/v1alpha1/channel.go rename to pkg/client/informers/externalversions/channels/v1alpha1/channel.go index 4655635cbb6..054a61cfca8 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/channel.go +++ b/pkg/client/informers/externalversions/channels/v1alpha1/channel.go @@ -21,10 +21,10 @@ package v1alpha1 import ( time "time" - eventing_v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + channels_v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" versioned "github.com/knative/eventing/pkg/client/clientset/versioned" internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/client/listers/channels/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" @@ -61,16 +61,16 @@ func NewFilteredChannelInformer(client versioned.Interface, namespace string, re if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Channels(namespace).List(options) + return client.ChannelsV1alpha1().Channels(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Channels(namespace).Watch(options) + return client.ChannelsV1alpha1().Channels(namespace).Watch(options) }, }, - &eventing_v1alpha1.Channel{}, + &channels_v1alpha1.Channel{}, resyncPeriod, indexers, ) @@ -81,7 +81,7 @@ func (f *channelInformer) defaultInformer(client versioned.Interface, resyncPeri } func (f *channelInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventing_v1alpha1.Channel{}, f.defaultInformer) + return f.factory.InformerFor(&channels_v1alpha1.Channel{}, f.defaultInformer) } func (f *channelInformer) Lister() v1alpha1.ChannelLister { diff --git a/pkg/client/informers/externalversions/channels/v1alpha1/interface.go b/pkg/client/informers/externalversions/channels/v1alpha1/interface.go new file mode 100644 index 00000000000..8a3fed2ce7c --- /dev/null +++ b/pkg/client/informers/externalversions/channels/v1alpha1/interface.go @@ -0,0 +1,59 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // Buses returns a BusInformer. + Buses() BusInformer + // Channels returns a ChannelInformer. + Channels() ChannelInformer + // Subscriptions returns a SubscriptionInformer. + Subscriptions() SubscriptionInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// Buses returns a BusInformer. +func (v *version) Buses() BusInformer { + return &busInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + +// Channels returns a ChannelInformer. +func (v *version) Channels() ChannelInformer { + return &channelInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + +// Subscriptions returns a SubscriptionInformer. +func (v *version) Subscriptions() SubscriptionInformer { + return &subscriptionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/subscription.go b/pkg/client/informers/externalversions/channels/v1alpha1/subscription.go similarity index 89% rename from pkg/client/informers/externalversions/eventing/v1alpha1/subscription.go rename to pkg/client/informers/externalversions/channels/v1alpha1/subscription.go index 86009ab9845..dc2a476e2e5 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/subscription.go +++ b/pkg/client/informers/externalversions/channels/v1alpha1/subscription.go @@ -21,10 +21,10 @@ package v1alpha1 import ( time "time" - eventing_v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + channels_v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" versioned "github.com/knative/eventing/pkg/client/clientset/versioned" internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/client/listers/channels/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" @@ -61,16 +61,16 @@ func NewFilteredSubscriptionInformer(client versioned.Interface, namespace strin if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Subscriptions(namespace).List(options) + return client.ChannelsV1alpha1().Subscriptions(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.EventingV1alpha1().Subscriptions(namespace).Watch(options) + return client.ChannelsV1alpha1().Subscriptions(namespace).Watch(options) }, }, - &eventing_v1alpha1.Subscription{}, + &channels_v1alpha1.Subscription{}, resyncPeriod, indexers, ) @@ -81,7 +81,7 @@ func (f *subscriptionInformer) defaultInformer(client versioned.Interface, resyn } func (f *subscriptionInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventing_v1alpha1.Subscription{}, f.defaultInformer) + return f.factory.InformerFor(&channels_v1alpha1.Subscription{}, f.defaultInformer) } func (f *subscriptionInformer) Lister() v1alpha1.SubscriptionLister { diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go b/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go index 8f1543b40b2..3190d7d9196 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go @@ -26,16 +26,10 @@ import ( type Interface interface { // Binds returns a BindInformer. Binds() BindInformer - // Buses returns a BusInformer. - Buses() BusInformer - // Channels returns a ChannelInformer. - Channels() ChannelInformer // EventSources returns a EventSourceInformer. EventSources() EventSourceInformer // EventTypes returns a EventTypeInformer. EventTypes() EventTypeInformer - // Subscriptions returns a SubscriptionInformer. - Subscriptions() SubscriptionInformer } type version struct { @@ -54,16 +48,6 @@ func (v *version) Binds() BindInformer { return &bindInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } -// Buses returns a BusInformer. -func (v *version) Buses() BusInformer { - return &busInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// Channels returns a ChannelInformer. -func (v *version) Channels() ChannelInformer { - return &channelInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - // EventSources returns a EventSourceInformer. func (v *version) EventSources() EventSourceInformer { return &eventSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} @@ -73,8 +57,3 @@ func (v *version) EventSources() EventSourceInformer { func (v *version) EventTypes() EventTypeInformer { return &eventTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } - -// Subscriptions returns a SubscriptionInformer. -func (v *version) Subscriptions() SubscriptionInformer { - return &subscriptionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go index 3fef9a5ebd0..6729ddfce5c 100644 --- a/pkg/client/informers/externalversions/factory.go +++ b/pkg/client/informers/externalversions/factory.go @@ -24,6 +24,7 @@ import ( time "time" versioned "github.com/knative/eventing/pkg/client/clientset/versioned" + channels "github.com/knative/eventing/pkg/client/informers/externalversions/channels" eventing "github.com/knative/eventing/pkg/client/informers/externalversions/eventing" internalinterfaces "github.com/knative/eventing/pkg/client/informers/externalversions/internalinterfaces" istio "github.com/knative/eventing/pkg/client/informers/externalversions/istio" @@ -124,10 +125,15 @@ type SharedInformerFactory interface { ForResource(resource schema.GroupVersionResource) (GenericInformer, error) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + Channels() channels.Interface Eventing() eventing.Interface Config() istio.Interface } +func (f *sharedInformerFactory) Channels() channels.Interface { + return channels.New(f, f.namespace, f.tweakListOptions) +} + func (f *sharedInformerFactory) Eventing() eventing.Interface { return eventing.New(f, f.namespace, f.tweakListOptions) } diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 7df54feeeba..0b78bea663f 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -21,7 +21,8 @@ package externalversions import ( "fmt" - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" + eventing_v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" v1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" @@ -53,23 +54,25 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { - // Group=config.istio.io, Version=v1alpha2 + // Group=channels.eventing.knative.dev, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("buses"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Channels().V1alpha1().Buses().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("channels"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Channels().V1alpha1().Channels().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("subscriptions"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Channels().V1alpha1().Subscriptions().Informer()}, nil + + // Group=config.istio.io, Version=v1alpha2 case v1alpha2.SchemeGroupVersion.WithResource("routerules"): return &genericInformer{resource: resource.GroupResource(), informer: f.Config().V1alpha2().RouteRules().Informer()}, nil // Group=eventing.knative.dev, Version=v1alpha1 - case v1alpha1.SchemeGroupVersion.WithResource("binds"): + case eventing_v1alpha1.SchemeGroupVersion.WithResource("binds"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Binds().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("buses"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Buses().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("channels"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Channels().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("eventsources"): + case eventing_v1alpha1.SchemeGroupVersion.WithResource("eventsources"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().EventSources().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("eventtypes"): + case eventing_v1alpha1.SchemeGroupVersion.WithResource("eventtypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().EventTypes().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("subscriptions"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Subscriptions().Informer()}, nil } diff --git a/pkg/client/listers/eventing/v1alpha1/bus.go b/pkg/client/listers/channels/v1alpha1/bus.go similarity index 97% rename from pkg/client/listers/eventing/v1alpha1/bus.go rename to pkg/client/listers/channels/v1alpha1/bus.go index 9483e1c8fd3..d6096d74641 100644 --- a/pkg/client/listers/eventing/v1alpha1/bus.go +++ b/pkg/client/listers/channels/v1alpha1/bus.go @@ -19,7 +19,7 @@ limitations under the License. package v1alpha1 import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/pkg/client/listers/eventing/v1alpha1/channel.go b/pkg/client/listers/channels/v1alpha1/channel.go similarity index 97% rename from pkg/client/listers/eventing/v1alpha1/channel.go rename to pkg/client/listers/channels/v1alpha1/channel.go index 35eeeb81475..7e70e49916f 100644 --- a/pkg/client/listers/eventing/v1alpha1/channel.go +++ b/pkg/client/listers/channels/v1alpha1/channel.go @@ -19,7 +19,7 @@ limitations under the License. package v1alpha1 import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/pkg/client/listers/channels/v1alpha1/expansion_generated.go b/pkg/client/listers/channels/v1alpha1/expansion_generated.go new file mode 100644 index 00000000000..792426e9fcc --- /dev/null +++ b/pkg/client/listers/channels/v1alpha1/expansion_generated.go @@ -0,0 +1,43 @@ +/* +Copyright 2018 Google, Inc. All rights reserved. + +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 lister-gen. DO NOT EDIT. + +package v1alpha1 + +// BusListerExpansion allows custom methods to be added to +// BusLister. +type BusListerExpansion interface{} + +// BusNamespaceListerExpansion allows custom methods to be added to +// BusNamespaceLister. +type BusNamespaceListerExpansion interface{} + +// ChannelListerExpansion allows custom methods to be added to +// ChannelLister. +type ChannelListerExpansion interface{} + +// ChannelNamespaceListerExpansion allows custom methods to be added to +// ChannelNamespaceLister. +type ChannelNamespaceListerExpansion interface{} + +// SubscriptionListerExpansion allows custom methods to be added to +// SubscriptionLister. +type SubscriptionListerExpansion interface{} + +// SubscriptionNamespaceListerExpansion allows custom methods to be added to +// SubscriptionNamespaceLister. +type SubscriptionNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/eventing/v1alpha1/subscription.go b/pkg/client/listers/channels/v1alpha1/subscription.go similarity index 98% rename from pkg/client/listers/eventing/v1alpha1/subscription.go rename to pkg/client/listers/channels/v1alpha1/subscription.go index 9ec0070dee6..b79680fcdb1 100644 --- a/pkg/client/listers/eventing/v1alpha1/subscription.go +++ b/pkg/client/listers/channels/v1alpha1/subscription.go @@ -19,7 +19,7 @@ limitations under the License. package v1alpha1 import ( - v1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + v1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" diff --git a/pkg/client/listers/eventing/v1alpha1/expansion_generated.go b/pkg/client/listers/eventing/v1alpha1/expansion_generated.go index ce1340cbe21..4309fac0cca 100644 --- a/pkg/client/listers/eventing/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/eventing/v1alpha1/expansion_generated.go @@ -26,22 +26,6 @@ type BindListerExpansion interface{} // BindNamespaceLister. type BindNamespaceListerExpansion interface{} -// BusListerExpansion allows custom methods to be added to -// BusLister. -type BusListerExpansion interface{} - -// BusNamespaceListerExpansion allows custom methods to be added to -// BusNamespaceLister. -type BusNamespaceListerExpansion interface{} - -// ChannelListerExpansion allows custom methods to be added to -// ChannelLister. -type ChannelListerExpansion interface{} - -// ChannelNamespaceListerExpansion allows custom methods to be added to -// ChannelNamespaceLister. -type ChannelNamespaceListerExpansion interface{} - // EventSourceListerExpansion allows custom methods to be added to // EventSourceLister. type EventSourceListerExpansion interface{} @@ -57,11 +41,3 @@ type EventTypeListerExpansion interface{} // EventTypeNamespaceListerExpansion allows custom methods to be added to // EventTypeNamespaceLister. type EventTypeNamespaceListerExpansion interface{} - -// SubscriptionListerExpansion allows custom methods to be added to -// SubscriptionLister. -type SubscriptionListerExpansion interface{} - -// SubscriptionNamespaceListerExpansion allows custom methods to be added to -// SubscriptionNamespaceLister. -type SubscriptionNamespaceListerExpansion interface{} diff --git a/pkg/controller/bus/controller.go b/pkg/controller/bus/controller.go index b513703e577..26cd7258727 100644 --- a/pkg/controller/bus/controller.go +++ b/pkg/controller/bus/controller.go @@ -44,10 +44,10 @@ import ( clientset "github.com/knative/eventing/pkg/client/clientset/versioned" channelscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" informers "github.com/knative/eventing/pkg/client/informers/externalversions" - listers "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + listers "github.com/knative/eventing/pkg/client/listers/channels/v1alpha1" elainformers "github.com/knative/serving/pkg/client/informers/externalversions" - eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + channelsv1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" ) const controllerAgentName = "bus-controller" @@ -102,7 +102,7 @@ func NewController( // obtain references to shared index informers for the Bus, Deployment and Service // types. - busInformer := busInformerFactory.Eventing().V1alpha1().Buses() + busInformer := busInformerFactory.Channels().V1alpha1().Buses() deploymentInformer := kubeInformerFactory.Apps().V1().Deployments() serviceInformer := kubeInformerFactory.Core().V1().Services() @@ -296,7 +296,7 @@ func (c *Controller) syncHandler(key string) error { return nil } -func (c *Controller) syncBusService(bus *eventingv1alpha1.Bus) (*corev1.Service, error) { +func (c *Controller) syncBusService(bus *channelsv1alpha1.Bus) (*corev1.Service, error) { // Get the service with the specified service name serviceName := controller.BusServiceName(bus.ObjectMeta.Name) service, err := c.servicesLister.Services(bus.Namespace).Get(serviceName) @@ -323,7 +323,7 @@ func (c *Controller) syncBusService(bus *eventingv1alpha1.Bus) (*corev1.Service, return service, nil } -func (c *Controller) syncBusDeployment(bus *eventingv1alpha1.Bus) (*appsv1.Deployment, error) { +func (c *Controller) syncBusDeployment(bus *channelsv1alpha1.Bus) (*appsv1.Deployment, error) { // Get the deployment with the specified deployment name deploymentName := controller.BusDeploymentName(bus.ObjectMeta.Name) deployment, err := c.deploymentsLister.Deployments(bus.Namespace).Get(deploymentName) @@ -362,7 +362,7 @@ func (c *Controller) syncBusDeployment(bus *eventingv1alpha1.Bus) (*appsv1.Deplo return deployment, nil } -func (c *Controller) updateBusStatus(bus *eventingv1alpha1.Bus, service *corev1.Service, deployment *appsv1.Deployment) error { +func (c *Controller) updateBusStatus(bus *channelsv1alpha1.Bus, service *corev1.Service, deployment *appsv1.Deployment) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance @@ -371,7 +371,7 @@ func (c *Controller) updateBusStatus(bus *eventingv1alpha1.Bus, service *corev1. // we must use Update instead of UpdateStatus to update the Status block of the Bus resource. // UpdateStatus will not allow changes to the Spec of the resource, // which is ideal for ensuring nothing other than resource status has been updated. - _, err := c.busclientset.EventingV1alpha1().Buses(bus.Namespace).Update(busCopy) + _, err := c.busclientset.ChannelsV1alpha1().Buses(bus.Namespace).Update(busCopy) return err } @@ -431,7 +431,7 @@ func (c *Controller) handleObject(obj interface{}) { // newService creates a new Service for a Bus resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Bus resource that 'owns' it. -func newService(bus *eventingv1alpha1.Bus) *corev1.Service { +func newService(bus *channelsv1alpha1.Bus) *corev1.Service { labels := map[string]string{ "bus": bus.Name, } @@ -442,8 +442,8 @@ func newService(bus *eventingv1alpha1.Bus) *corev1.Service { Labels: labels, OwnerReferences: []metav1.OwnerReference{ *metav1.NewControllerRef(bus, schema.GroupVersionKind{ - Group: eventingv1alpha1.SchemeGroupVersion.Group, - Version: eventingv1alpha1.SchemeGroupVersion.Version, + Group: channelsv1alpha1.SchemeGroupVersion.Group, + Version: channelsv1alpha1.SchemeGroupVersion.Version, Kind: "Bus", }), }, @@ -464,7 +464,7 @@ func newService(bus *eventingv1alpha1.Bus) *corev1.Service { // newDeployment creates a new Deployment for a Bus resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Bus resource that 'owns' it. -func newDeployment(bus *eventingv1alpha1.Bus) *appsv1.Deployment { +func newDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { labels := map[string]string{ "bus": bus.Name, } @@ -486,8 +486,8 @@ func newDeployment(bus *eventingv1alpha1.Bus) *appsv1.Deployment { Namespace: bus.Namespace, OwnerReferences: []metav1.OwnerReference{ *metav1.NewControllerRef(bus, schema.GroupVersionKind{ - Group: eventingv1alpha1.SchemeGroupVersion.Group, - Version: eventingv1alpha1.SchemeGroupVersion.Version, + Group: channelsv1alpha1.SchemeGroupVersion.Group, + Version: channelsv1alpha1.SchemeGroupVersion.Version, Kind: "Bus", }), }, diff --git a/pkg/controller/channel/controller.go b/pkg/controller/channel/controller.go index f130101b318..aef0a6c7ee8 100644 --- a/pkg/controller/channel/controller.go +++ b/pkg/controller/channel/controller.go @@ -44,10 +44,10 @@ import ( clientset "github.com/knative/eventing/pkg/client/clientset/versioned" channelscheme "github.com/knative/eventing/pkg/client/clientset/versioned/scheme" informers "github.com/knative/eventing/pkg/client/informers/externalversions" - listers "github.com/knative/eventing/pkg/client/listers/eventing/v1alpha1" + listers "github.com/knative/eventing/pkg/client/listers/channels/v1alpha1" elainformers "github.com/knative/serving/pkg/client/informers/externalversions" - eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + channelsv1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" istiov1alpha2 "github.com/knative/eventing/pkg/apis/istio/v1alpha2" ) @@ -108,7 +108,7 @@ func NewController( ingressInformer := kubeInformerFactory.Extensions().V1beta1().Ingresses() routeruleInformer := channelInformerFactory.Config().V1alpha2().RouteRules() serviceInformer := kubeInformerFactory.Core().V1().Services() - channelInformer := channelInformerFactory.Eventing().V1alpha1().Channels() + channelInformer := channelInformerFactory.Channels().V1alpha1().Channels() // Create event broadcaster // Add channel-controller types to the default Kubernetes Scheme so Events can be @@ -311,7 +311,7 @@ func (c *Controller) syncHandler(key string) error { return nil } -func (c *Controller) syncChannelService(channel *eventingv1alpha1.Channel) (*corev1.Service, error) { +func (c *Controller) syncChannelService(channel *channelsv1alpha1.Channel) (*corev1.Service, error) { // Get the service with the specified service name serviceName := controller.ChannelServiceName(channel.ObjectMeta.Name) service, err := c.servicesLister.Services(channel.Namespace).Get(serviceName) @@ -338,7 +338,7 @@ func (c *Controller) syncChannelService(channel *eventingv1alpha1.Channel) (*cor return service, nil } -func (c *Controller) syncChannelRouteRule(channel *eventingv1alpha1.Channel) (*istiov1alpha2.RouteRule, error) { +func (c *Controller) syncChannelRouteRule(channel *channelsv1alpha1.Channel) (*istiov1alpha2.RouteRule, error) { // Get the RouteRule with the specified Channel name routeruleName := controller.ChannelRouteRuleName(channel.ObjectMeta.Name) routerule, err := c.routerulesLister.RouteRules(channel.Namespace).Get(routeruleName) @@ -366,7 +366,7 @@ func (c *Controller) syncChannelRouteRule(channel *eventingv1alpha1.Channel) (*i return routerule, nil } -func (c *Controller) syncChannelIngress(channel *eventingv1alpha1.Channel) (*extensionsv1beta1.Ingress, error) { +func (c *Controller) syncChannelIngress(channel *channelsv1alpha1.Channel) (*extensionsv1beta1.Ingress, error) { // TODO make ingress optional // Get the ingress with the specified ingress name @@ -395,7 +395,7 @@ func (c *Controller) syncChannelIngress(channel *eventingv1alpha1.Channel) (*ext return ingress, nil } -func (c *Controller) updateChannelStatus(channel *eventingv1alpha1.Channel, service *corev1.Service, ingress *extensionsv1beta1.Ingress, routeRule *istiov1alpha2.RouteRule) error { +func (c *Controller) updateChannelStatus(channel *channelsv1alpha1.Channel, service *corev1.Service, ingress *extensionsv1beta1.Ingress, routeRule *istiov1alpha2.RouteRule) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance @@ -404,7 +404,7 @@ func (c *Controller) updateChannelStatus(channel *eventingv1alpha1.Channel, serv // we must use Update instead of UpdateStatus to update the Status block of the Channel resource. // UpdateStatus will not allow changes to the Spec of the resource, // which is ideal for ensuring nothing other than resource status has been updated. - _, err := c.channelclientset.EventingV1alpha1().Channels(channel.Namespace).Update(channelCopy) + _, err := c.channelclientset.ChannelsV1alpha1().Channels(channel.Namespace).Update(channelCopy) return err } @@ -464,7 +464,7 @@ func (c *Controller) handleObject(obj interface{}) { // newService creates a new Service for a Channel resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Channel resource that 'owns' it. -func newService(channel *eventingv1alpha1.Channel) *corev1.Service { +func newService(channel *channelsv1alpha1.Channel) *corev1.Service { labels := map[string]string{ "channel": channel.Name, } @@ -475,8 +475,8 @@ func newService(channel *eventingv1alpha1.Channel) *corev1.Service { Labels: labels, OwnerReferences: []metav1.OwnerReference{ *metav1.NewControllerRef(channel, schema.GroupVersionKind{ - Group: eventingv1alpha1.SchemeGroupVersion.Group, - Version: eventingv1alpha1.SchemeGroupVersion.Version, + Group: channelsv1alpha1.SchemeGroupVersion.Group, + Version: channelsv1alpha1.SchemeGroupVersion.Version, Kind: "Channel", }), }, @@ -492,7 +492,7 @@ func newService(channel *eventingv1alpha1.Channel) *corev1.Service { // newRouteRule creates a new RouteRule for a Channel resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Channel resource that 'owns' it. -func newRouteRule(channel *eventingv1alpha1.Channel) *istiov1alpha2.RouteRule { +func newRouteRule(channel *channelsv1alpha1.Channel) *istiov1alpha2.RouteRule { labels := map[string]string{ "bus": channel.Spec.Bus, "channel": channel.Name, @@ -504,8 +504,8 @@ func newRouteRule(channel *eventingv1alpha1.Channel) *istiov1alpha2.RouteRule { Labels: labels, OwnerReferences: []metav1.OwnerReference{ *metav1.NewControllerRef(channel, schema.GroupVersionKind{ - Group: eventingv1alpha1.SchemeGroupVersion.Group, - Version: eventingv1alpha1.SchemeGroupVersion.Version, + Group: channelsv1alpha1.SchemeGroupVersion.Group, + Version: channelsv1alpha1.SchemeGroupVersion.Version, Kind: "Channel", }), }, @@ -532,7 +532,7 @@ func newRouteRule(channel *eventingv1alpha1.Channel) *istiov1alpha2.RouteRule { // newIngress creates a new Ingress for a Channel resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Channel resource that 'owns' it. -func newIngress(channel *eventingv1alpha1.Channel) *extensionsv1beta1.Ingress { +func newIngress(channel *channelsv1alpha1.Channel) *extensionsv1beta1.Ingress { labels := map[string]string{ "channel": channel.Name, } @@ -547,8 +547,8 @@ func newIngress(channel *eventingv1alpha1.Channel) *extensionsv1beta1.Ingress { Annotations: annotations, OwnerReferences: []metav1.OwnerReference{ *metav1.NewControllerRef(channel, schema.GroupVersionKind{ - Group: eventingv1alpha1.SchemeGroupVersion.Group, - Version: eventingv1alpha1.SchemeGroupVersion.Version, + Group: channelsv1alpha1.SchemeGroupVersion.Group, + Version: channelsv1alpha1.SchemeGroupVersion.Version, Kind: "Channel", }), }, diff --git a/pkg/subscription/monitor.go b/pkg/subscription/monitor.go index d5d99ddb6d1..97e60d09bb1 100644 --- a/pkg/subscription/monitor.go +++ b/pkg/subscription/monitor.go @@ -21,7 +21,7 @@ import ( "sync" "github.com/golang/glog" - eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + channelsv1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" informers "github.com/knative/eventing/pkg/client/informers/externalversions" "k8s.io/client-go/tools/cache" ) @@ -35,25 +35,25 @@ type Monitor struct { } type MonitorEventHandlerFuncs struct { - ProvisionFunc func(channel eventingv1alpha1.Channel) - UnprovisionFunc func(channel eventingv1alpha1.Channel) - SubscribeFunc func(subscription eventingv1alpha1.Subscription) - UnsubscribeFunc func(subscription eventingv1alpha1.Subscription) + ProvisionFunc func(channel channelsv1alpha1.Channel) + UnprovisionFunc func(channel channelsv1alpha1.Channel) + SubscribeFunc func(subscription channelsv1alpha1.Subscription) + UnsubscribeFunc func(subscription channelsv1alpha1.Subscription) } type channelSummary struct { - Channel *eventingv1alpha1.ChannelSpec + Channel *channelsv1alpha1.ChannelSpec Subscriptions map[subscriptionKey]subscriptionSummary } type subscriptionSummary struct { - Subscription eventingv1alpha1.SubscriptionSpec + Subscription channelsv1alpha1.SubscriptionSpec } func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, handler MonitorEventHandlerFuncs) *Monitor { - channelInformer := informerFactory.Eventing().V1alpha1().Channels() - subscriptionInformer := informerFactory.Eventing().V1alpha1().Subscriptions() + channelInformer := informerFactory.Channels().V1alpha1().Channels() + subscriptionInformer := informerFactory.Channels().V1alpha1().Subscriptions() monitor := &Monitor{ busName: busName, @@ -67,12 +67,12 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, // Set up an event handler for when Channel resources change channelInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - channel := obj.(eventingv1alpha1.Channel) + channel := obj.(channelsv1alpha1.Channel) monitor.createOrUpdateChannel(channel) }, UpdateFunc: func(old, new interface{}) { - oldChannel := old.(eventingv1alpha1.Channel) - newChannel := new.(eventingv1alpha1.Channel) + oldChannel := old.(channelsv1alpha1.Channel) + newChannel := new.(channelsv1alpha1.Channel) if oldChannel.ResourceVersion == newChannel.ResourceVersion { // Periodic resync will send update events for all known Channels. @@ -86,19 +86,19 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, } }, DeleteFunc: func(obj interface{}) { - channel := obj.(eventingv1alpha1.Channel) + channel := obj.(channelsv1alpha1.Channel) monitor.removeChannel(channel) }, }) // Set up an event handler for when Subscription resources change subscriptionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - subscription := obj.(eventingv1alpha1.Subscription) + subscription := obj.(channelsv1alpha1.Subscription) monitor.createOrUpdateSubscription(subscription) }, UpdateFunc: func(old, new interface{}) { - oldSubscription := old.(eventingv1alpha1.Subscription) - newSubscription := new.(eventingv1alpha1.Subscription) + oldSubscription := old.(channelsv1alpha1.Subscription) + newSubscription := new.(channelsv1alpha1.Subscription) if oldSubscription.ResourceVersion == newSubscription.ResourceVersion { // Periodic resync will send update events for all known Subscriptions. @@ -112,7 +112,7 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, } }, DeleteFunc: func(obj interface{}) { - subscription := obj.(eventingv1alpha1.Subscription) + subscription := obj.(channelsv1alpha1.Subscription) monitor.removeSubscription(subscription) }, }) @@ -121,7 +121,7 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, } // Subscriptions for a channel name and namespace -func (m *Monitor) Subscriptions(channel string, namespace string) *[]eventingv1alpha1.SubscriptionSpec { +func (m *Monitor) Subscriptions(channel string, namespace string) *[]channelsv1alpha1.SubscriptionSpec { channelKey := makeChannelKeyWithNames(channel, namespace) summary := m.getOrCreateChannelSummary(channelKey) @@ -131,7 +131,7 @@ func (m *Monitor) Subscriptions(channel string, namespace string) *[]eventingv1a } m.mutex.Lock() - subscriptions := make([]eventingv1alpha1.SubscriptionSpec, len(summary.Subscriptions)) + subscriptions := make([]channelsv1alpha1.SubscriptionSpec, len(summary.Subscriptions)) for _, subscription := range summary.Subscriptions { subscriptions = append(subscriptions, subscription.Subscription) } @@ -155,7 +155,7 @@ func (m *Monitor) getOrCreateChannelSummary(key channelKey) channelSummary { return summary } -func (m *Monitor) createOrUpdateChannel(channel eventingv1alpha1.Channel) { +func (m *Monitor) createOrUpdateChannel(channel channelsv1alpha1.Channel) { channelKey := makeChannelKeyFromChannel(channel) summary := m.getOrCreateChannelSummary(channelKey) @@ -170,7 +170,7 @@ func (m *Monitor) createOrUpdateChannel(channel eventingv1alpha1.Channel) { } } -func (m *Monitor) removeChannel(channel eventingv1alpha1.Channel) { +func (m *Monitor) removeChannel(channel channelsv1alpha1.Channel) { channelKey := makeChannelKeyFromChannel(channel) summary := m.getOrCreateChannelSummary(channelKey) @@ -181,7 +181,7 @@ func (m *Monitor) removeChannel(channel eventingv1alpha1.Channel) { m.handler.UnprovisionFunc(channel) } -func (m *Monitor) createOrUpdateSubscription(subscription eventingv1alpha1.Subscription) { +func (m *Monitor) createOrUpdateSubscription(subscription channelsv1alpha1.Subscription) { channelKey := makeChannelKeyFromSubscription(subscription) summary := m.getOrCreateChannelSummary(channelKey) subscriptionKey := makeSubscriptionKeyFromSubscription(subscription) @@ -199,7 +199,7 @@ func (m *Monitor) createOrUpdateSubscription(subscription eventingv1alpha1.Subsc } } -func (m *Monitor) removeSubscription(subscription eventingv1alpha1.Subscription) { +func (m *Monitor) removeSubscription(subscription channelsv1alpha1.Subscription) { channelKey := makeChannelKeyFromSubscription(subscription) summary := m.getOrCreateChannelSummary(channelKey) subscriptionKey := makeSubscriptionKeyFromSubscription(subscription) @@ -216,11 +216,11 @@ type channelKey struct { Namespace string } -func makeChannelKeyFromChannel(channel eventingv1alpha1.Channel) channelKey { +func makeChannelKeyFromChannel(channel channelsv1alpha1.Channel) channelKey { return makeChannelKeyWithNames(channel.Name, channel.Namespace) } -func makeChannelKeyFromSubscription(subscription eventingv1alpha1.Subscription) channelKey { +func makeChannelKeyFromSubscription(subscription channelsv1alpha1.Subscription) channelKey { return makeChannelKeyWithNames(subscription.Spec.Channel, subscription.Namespace) } @@ -236,7 +236,7 @@ type subscriptionKey struct { Namespace string } -func makeSubscriptionKeyFromSubscription(subscription eventingv1alpha1.Subscription) subscriptionKey { +func makeSubscriptionKeyFromSubscription(subscription channelsv1alpha1.Subscription) subscriptionKey { return subscriptionKey{ Name: subscription.Name, Namespace: subscription.Namespace, diff --git a/sample/hello/hello-channel.yaml b/sample/hello/hello-channel.yaml index dd199eeda75..f22f64e25d4 100644 --- a/sample/hello/hello-channel.yaml +++ b/sample/hello/hello-channel.yaml @@ -1,10 +1,10 @@ -apiVersion: eventing.knative.dev/v1alpha1 +apiVersion: channels.eventing.knative.dev/v1alpha1 kind: Channel metadata: name: aloha --- -apiVersion: eventing.knative.dev/v1alpha1 +apiVersion: channels.eventing.knative.dev/v1alpha1 kind: Subscription metadata: name: aloha2hello diff --git a/sample/square/square.yaml b/sample/square/square.yaml index 029ec30f9fc..d6071bccb9c 100644 --- a/sample/square/square.yaml +++ b/sample/square/square.yaml @@ -34,7 +34,7 @@ spec: app: square --- -apiVersion: eventing.knative.dev/v1alpha1 +apiVersion: channels.eventing.knative.dev/v1alpha1 kind: Channel metadata: name: square @@ -42,7 +42,7 @@ spec: bus: stub --- -apiVersion: eventing.knative.dev/v1alpha1 +apiVersion: channels.eventing.knative.dev/v1alpha1 kind: Subscription metadata: name: square From c9118fa9793de532cb285b75a7a93cfa91527a03 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Wed, 6 Jun 2018 22:50:44 -0400 Subject: [PATCH 13/21] polish --- cmd/stub-bus/main.go | 35 +++++++++++++---------- config/bus-clusterrolebinding.yaml | 25 +++++++++++++++++ config/bus-serviceaccount.yaml | 18 ++++++++++++ config/buses/stub.yaml | 1 + pkg/controller/bus/controller.go | 1 + pkg/subscription/monitor.go | 45 +++++++++++++++++------------- 6 files changed, 91 insertions(+), 34 deletions(-) create mode 100644 config/bus-clusterrolebinding.yaml create mode 100644 config/bus-serviceaccount.yaml diff --git a/cmd/stub-bus/main.go b/cmd/stub-bus/main.go index d8c3ba061e9..c7009378f03 100644 --- a/cmd/stub-bus/main.go +++ b/cmd/stub-bus/main.go @@ -28,9 +28,10 @@ import ( "github.com/go-martini/martini" "github.com/golang/glog" - eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" + channelsv1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" clientset "github.com/knative/eventing/pkg/client/clientset/versioned" informers "github.com/knative/eventing/pkg/client/informers/externalversions" + "github.com/knative/eventing/pkg/signals" "github.com/knative/eventing/pkg/subscription" "k8s.io/client-go/tools/clientcmd" ) @@ -62,6 +63,9 @@ func splitChannelName(host string) (string, string) { func main() { flag.Parse() + // set up signals so we handle the first shutdown signal gracefully + stopCh := signals.SetupSignalHandler() + cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig) if err != nil { glog.Fatalf("Error building kubeconfig: %s", err.Error()) @@ -74,22 +78,25 @@ func main() { informerFactory := informers.NewSharedInformerFactory(client, time.Second*30) monitor := subscription.NewMonitor(bus, informerFactory, subscription.MonitorEventHandlerFuncs{ - ProvisionFunc: func(channel eventingv1alpha1.Channel) { - fmt.Printf("Provision channel %q\n", channel.Name) + ProvisionFunc: func(channel channelsv1alpha1.Channel) { + glog.Infof("Provision channel %q\n", channel.Name) }, - UnprovisionFunc: func(channel eventingv1alpha1.Channel) { - fmt.Printf("Unprovision channel %q\n", channel.Name) + UnprovisionFunc: func(channel channelsv1alpha1.Channel) { + glog.Infof("Unprovision channel %q\n", channel.Name) }, - SubscribeFunc: func(subscription eventingv1alpha1.Subscription) { - fmt.Printf("Subscribe %q to %q channel\n", subscription.Spec.Subscriber, subscription.Spec.Channel) + SubscribeFunc: func(subscription channelsv1alpha1.Subscription) { + glog.Infof("Subscribe %q to %q channel\n", subscription.Spec.Subscriber, subscription.Spec.Channel) }, - UnsubscribeFunc: func(subscription eventingv1alpha1.Subscription) { - fmt.Printf("Unubscribe %q from %q channel\n", subscription.Spec.Subscriber, subscription.Spec.Channel) + UnsubscribeFunc: func(subscription channelsv1alpha1.Subscription) { + glog.Infof("Unubscribe %q from %q channel\n", subscription.Spec.Subscriber, subscription.Spec.Channel) }, }) + go informerFactory.Start(stopCh) m := createServer(monitor) m.Run() + + glog.Flush() } func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { @@ -97,7 +104,7 @@ func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { m.Post("/", func(req *http.Request, res http.ResponseWriter) { host := req.Host - fmt.Printf("Recieved request for %s\n", host) + glog.Infof("Recieved request for %s\n", host) channel, namespace := splitChannelName(host) subscriptions := monitor.Subscriptions(channel, namespace) if subscriptions == nil { @@ -114,7 +121,7 @@ func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { res.WriteHeader(http.StatusAccepted) go func() { if len(*subscriptions) == 0 { - fmt.Printf("No subscribers for channel %q\n", channel) + glog.Warningf("No subscribers for channel %q\n", channel) } // make upstream requests @@ -122,12 +129,12 @@ func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { for _, subscription := range *subscriptions { go func(subscriber string) { - fmt.Printf("Sending to %q for %q\n", subscriber, channel) + glog.Infof("Sending to %q for %q\n", subscriber, channel) url := fmt.Sprintf("http://%s/", subscriber) request, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body)) if err != nil { - fmt.Printf("Unable to create subscriber request %v", err) + glog.Errorf("Unable to create subscriber request %v", err) } request.Header.Set("x-bus", bus) request.Header.Set("x-channel", channel) @@ -138,7 +145,7 @@ func createServer(monitor *subscription.Monitor) *martini.ClassicMartini { } _, err = client.Do(request) if err != nil { - fmt.Printf("Unable to complete subscriber request %v", err) + glog.Errorf("Unable to complete subscriber request %v", err) } }(subscription.Subscriber) } diff --git a/config/bus-clusterrolebinding.yaml b/config/bus-clusterrolebinding.yaml new file mode 100644 index 00000000000..9e63755a130 --- /dev/null +++ b/config/bus-clusterrolebinding.yaml @@ -0,0 +1,25 @@ +# Copyright 2018 Google, Inc. All rights reserved. +# +# 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. +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRoleBinding +metadata: + name: bus-provisioner-admin +subjects: + - kind: ServiceAccount + name: bus-provisioner + namespace: knative-eventing-system +roleRef: + kind: ClusterRole + name: cluster-admin + apiGroup: rbac.authorization.k8s.io diff --git a/config/bus-serviceaccount.yaml b/config/bus-serviceaccount.yaml new file mode 100644 index 00000000000..48d557325ca --- /dev/null +++ b/config/bus-serviceaccount.yaml @@ -0,0 +1,18 @@ +# Copyright 2018 Google, Inc. All rights reserved. +# +# 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. +apiVersion: v1 +kind: ServiceAccount +metadata: + name: bus-provisioner + namespace: knative-eventing-system diff --git a/config/buses/stub.yaml b/config/buses/stub.yaml index 38da64ae3e4..2c760916ee8 100644 --- a/config/buses/stub.yaml +++ b/config/buses/stub.yaml @@ -2,6 +2,7 @@ apiVersion: channels.eventing.knative.dev/v1alpha1 kind: Bus metadata: name: stub + namespace: knative-eventing-system spec: container: name: bus diff --git a/pkg/controller/bus/controller.go b/pkg/controller/bus/controller.go index 26cd7258727..7ed3bfe6667 100644 --- a/pkg/controller/bus/controller.go +++ b/pkg/controller/bus/controller.go @@ -502,6 +502,7 @@ func newDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { Labels: labels, }, Spec: corev1.PodSpec{ + ServiceAccountName: "bus-provisioner", Containers: []corev1.Container{ *container, }, diff --git a/pkg/subscription/monitor.go b/pkg/subscription/monitor.go index 97e60d09bb1..eeddf4fdca0 100644 --- a/pkg/subscription/monitor.go +++ b/pkg/subscription/monitor.go @@ -30,7 +30,7 @@ type Monitor struct { busName string handler MonitorEventHandlerFuncs - cache map[channelKey]channelSummary + cache map[channelKey]*channelSummary mutex *sync.Mutex } @@ -59,7 +59,7 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, busName: busName, handler: handler, - cache: make(map[channelKey]channelSummary), + cache: make(map[channelKey]*channelSummary), mutex: &sync.Mutex{}, } @@ -67,12 +67,12 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, // Set up an event handler for when Channel resources change channelInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - channel := obj.(channelsv1alpha1.Channel) - monitor.createOrUpdateChannel(channel) + channel := obj.(*channelsv1alpha1.Channel) + monitor.createOrUpdateChannel(*channel) }, UpdateFunc: func(old, new interface{}) { - oldChannel := old.(channelsv1alpha1.Channel) - newChannel := new.(channelsv1alpha1.Channel) + oldChannel := old.(*channelsv1alpha1.Channel) + newChannel := new.(*channelsv1alpha1.Channel) if oldChannel.ResourceVersion == newChannel.ResourceVersion { // Periodic resync will send update events for all known Channels. @@ -80,25 +80,25 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, return } - monitor.createOrUpdateChannel(newChannel) + monitor.createOrUpdateChannel(*newChannel) if oldChannel.Spec.Bus != newChannel.Spec.Bus { - monitor.removeChannel(oldChannel) + monitor.removeChannel(*oldChannel) } }, DeleteFunc: func(obj interface{}) { - channel := obj.(channelsv1alpha1.Channel) - monitor.removeChannel(channel) + channel := obj.(*channelsv1alpha1.Channel) + monitor.removeChannel(*channel) }, }) // Set up an event handler for when Subscription resources change subscriptionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - subscription := obj.(channelsv1alpha1.Subscription) - monitor.createOrUpdateSubscription(subscription) + subscription := obj.(*channelsv1alpha1.Subscription) + monitor.createOrUpdateSubscription(*subscription) }, UpdateFunc: func(old, new interface{}) { - oldSubscription := old.(channelsv1alpha1.Subscription) - newSubscription := new.(channelsv1alpha1.Subscription) + oldSubscription := old.(*channelsv1alpha1.Subscription) + newSubscription := new.(*channelsv1alpha1.Subscription) if oldSubscription.ResourceVersion == newSubscription.ResourceVersion { // Periodic resync will send update events for all known Subscriptions. @@ -106,14 +106,14 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, return } - monitor.createOrUpdateSubscription(newSubscription) + monitor.createOrUpdateSubscription(*newSubscription) if oldSubscription.Spec.Channel != newSubscription.Spec.Channel { - monitor.removeSubscription(oldSubscription) + monitor.removeSubscription(*oldSubscription) } }, DeleteFunc: func(obj interface{}) { - subscription := obj.(channelsv1alpha1.Subscription) - monitor.removeSubscription(subscription) + subscription := obj.(*channelsv1alpha1.Subscription) + monitor.removeSubscription(*subscription) }, }) @@ -125,6 +125,11 @@ func (m *Monitor) Subscriptions(channel string, namespace string) *[]channelsv1a channelKey := makeChannelKeyWithNames(channel, namespace) summary := m.getOrCreateChannelSummary(channelKey) + if summary.Channel == nil { + // the channel is unknown + return nil + } + if summary.Channel.Bus != m.busName { // the channel is not for this bus return nil @@ -140,11 +145,11 @@ func (m *Monitor) Subscriptions(channel string, namespace string) *[]channelsv1a return &subscriptions } -func (m *Monitor) getOrCreateChannelSummary(key channelKey) channelSummary { +func (m *Monitor) getOrCreateChannelSummary(key channelKey) *channelSummary { m.mutex.Lock() summary, ok := m.cache[key] if !ok { - summary = channelSummary{ + summary = &channelSummary{ Channel: nil, Subscriptions: make(map[subscriptionKey]subscriptionSummary), } From 9f3fa72280c9d709a465472f6b4240f809be9312 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Thu, 7 Jun 2018 00:03:41 -0400 Subject: [PATCH 14/21] Split bus provissioner from event handler A Bus may specify a provisioner. The provisioner is expected to listen for new Channel resources for the Bus and provision them on the underlying broker. The container remains expected to handle and produce events for subscribers. TODO: - lock down the clusterrolebinding for the provisioner and event serviceaccounts for the role. --- config/bus-clusterrolebinding.yaml | 19 ++- config/bus-serviceaccount.yaml | 7 + config/buses/stub.yaml | 1 - pkg/apis/channels/v1alpha1/bus_types.go | 14 +- .../v1alpha1/zz_generated.deepcopy.go | 10 ++ pkg/controller/bus/controller.go | 145 +++++++++++++++--- pkg/controller/channel/controller.go | 2 +- pkg/controller/names.go | 8 +- 8 files changed, 177 insertions(+), 29 deletions(-) diff --git a/config/bus-clusterrolebinding.yaml b/config/bus-clusterrolebinding.yaml index 9e63755a130..46dd7389afe 100644 --- a/config/bus-clusterrolebinding.yaml +++ b/config/bus-clusterrolebinding.yaml @@ -11,10 +11,13 @@ # 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. + +# TODO lock down access to least privilege + apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: - name: bus-provisioner-admin + name: bus-provisioner subjects: - kind: ServiceAccount name: bus-provisioner @@ -23,3 +26,17 @@ roleRef: kind: ClusterRole name: cluster-admin apiGroup: rbac.authorization.k8s.io + +--- +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRoleBinding +metadata: + name: bus-events +subjects: + - kind: ServiceAccount + name: bus-data + namespace: knative-eventing-system +roleRef: + kind: ClusterRole + name: cluster-admin + apiGroup: rbac.authorization.k8s.io \ No newline at end of file diff --git a/config/bus-serviceaccount.yaml b/config/bus-serviceaccount.yaml index 48d557325ca..401fb2f0de0 100644 --- a/config/bus-serviceaccount.yaml +++ b/config/bus-serviceaccount.yaml @@ -16,3 +16,10 @@ kind: ServiceAccount metadata: name: bus-provisioner namespace: knative-eventing-system + +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: bus-events + namespace: knative-eventing-system diff --git a/config/buses/stub.yaml b/config/buses/stub.yaml index 2c760916ee8..38da64ae3e4 100644 --- a/config/buses/stub.yaml +++ b/config/buses/stub.yaml @@ -2,7 +2,6 @@ apiVersion: channels.eventing.knative.dev/v1alpha1 kind: Bus metadata: name: stub - namespace: knative-eventing-system spec: container: name: bus diff --git a/pkg/apis/channels/v1alpha1/bus_types.go b/pkg/apis/channels/v1alpha1/bus_types.go index 56a012920c8..51d47aaee9a 100644 --- a/pkg/apis/channels/v1alpha1/bus_types.go +++ b/pkg/apis/channels/v1alpha1/bus_types.go @@ -26,7 +26,7 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the buses.channels.eventing.knative.dev CRD +// Bus represents the buses.channels.eventing.knative.dev CRD type Bus struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` @@ -34,19 +34,23 @@ type Bus struct { Status *BusStatus `json:"status,omitempty"` } -// Spec (what the user wants) for a bus +// BusSpec (what the user wants) for a bus type BusSpec struct { - // Container definition to use for the bus. + + // Provisioner container definition to manage channels on the bus. + Provisioner *kapi.Container `json:"provisioner,omitempty"` + + // Container definition to use for the bus data plane. Container kapi.Container `json:"container"` } -// Status (computed) for a bus +// BusStatus (computed) for a bus type BusStatus struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// Returned in list operations +// BusList returned in list operations type BusList struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ListMeta `json:"metadata"` diff --git a/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go index 7eb1c4a948f..dd8fcffa918 100644 --- a/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go @@ -21,6 +21,7 @@ limitations under the License. package v1alpha1 import ( + v1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -96,6 +97,15 @@ func (in *BusList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BusSpec) DeepCopyInto(out *BusSpec) { *out = *in + if in.Provisioner != nil { + in, out := &in.Provisioner, &out.Provisioner + if *in == nil { + *out = nil + } else { + *out = new(v1.Container) + (*in).DeepCopyInto(*out) + } + } in.Container.DeepCopyInto(&out.Container) return } diff --git a/pkg/controller/bus/controller.go b/pkg/controller/bus/controller.go index 7ed3bfe6667..b761e52263f 100644 --- a/pkg/controller/bus/controller.go +++ b/pkg/controller/bus/controller.go @@ -277,32 +277,38 @@ func (c *Controller) syncHandler(key string) error { } // Sync Service derived from the Bus - service, err := c.syncBusService(bus) + eventService, err := c.syncBusEventService(bus) if err != nil { return err } // Sync Deployment derived from the Bus - deployment, err := c.syncBusDeployment(bus) + eventDeployment, err := c.syncBusEventDeployment(bus) + if err != nil { + return err + } + + // Sync Deployment derived from the Bus + provisionerDeployment, err := c.syncBusProvisionerDeployment(bus) if err != nil { return err } // Finally, we update the status block of the Bus resource to reflect the // current state of the world - return c.updateBusStatus(bus, service, deployment) + return c.updateBusStatus(bus, eventService, eventDeployment, provisionerDeployment) c.recorder.Event(bus, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) return nil } -func (c *Controller) syncBusService(bus *channelsv1alpha1.Bus) (*corev1.Service, error) { +func (c *Controller) syncBusEventService(bus *channelsv1alpha1.Bus) (*corev1.Service, error) { // Get the service with the specified service name - serviceName := controller.BusServiceName(bus.ObjectMeta.Name) + serviceName := controller.BusEventServiceName(bus.ObjectMeta.Name) service, err := c.servicesLister.Services(bus.Namespace).Get(serviceName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - service, err = c.kubeclientset.CoreV1().Services(bus.Namespace).Create(newService(bus)) + service, err = c.kubeclientset.CoreV1().Services(bus.Namespace).Create(newEventService(bus)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -323,13 +329,13 @@ func (c *Controller) syncBusService(bus *channelsv1alpha1.Bus) (*corev1.Service, return service, nil } -func (c *Controller) syncBusDeployment(bus *channelsv1alpha1.Bus) (*appsv1.Deployment, error) { +func (c *Controller) syncBusEventDeployment(bus *channelsv1alpha1.Bus) (*appsv1.Deployment, error) { // Get the deployment with the specified deployment name - deploymentName := controller.BusDeploymentName(bus.ObjectMeta.Name) + deploymentName := controller.BusEventDeploymentName(bus.ObjectMeta.Name) deployment, err := c.deploymentsLister.Deployments(bus.Namespace).Get(deploymentName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Create(newDeployment(bus)) + deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Create(newEventDeployment(bus)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -349,7 +355,7 @@ func (c *Controller) syncBusDeployment(bus *channelsv1alpha1.Bus) (*appsv1.Deplo // If the Deployment does not match the Bus's proposed Deployment we should update // the Deployment resource. - proposedDeployment := newDeployment(bus) + proposedDeployment := newEventDeployment(bus) if !reflect.DeepEqual(proposedDeployment.Spec, deployment.Spec) { glog.V(4).Infof("Bus %s container spec updated", bus.Name) deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Update(proposedDeployment) @@ -362,7 +368,58 @@ func (c *Controller) syncBusDeployment(bus *channelsv1alpha1.Bus) (*appsv1.Deplo return deployment, nil } -func (c *Controller) updateBusStatus(bus *channelsv1alpha1.Bus, service *corev1.Service, deployment *appsv1.Deployment) error { +func (c *Controller) syncBusProvisionerDeployment(bus *channelsv1alpha1.Bus) (*appsv1.Deployment, error) { + provisioner := bus.Spec.Provisioner + + // Get the deployment with the specified deployment name + deploymentName := controller.BusProvisionerDeploymentName(bus.ObjectMeta.Name) + deployment, err := c.deploymentsLister.Deployments(bus.Namespace).Get(deploymentName) + + // If the resource shouldn't exists + if provisioner == nil { + // If the resource exists, we'll delete it + if err == nil { + err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Delete(deploymentName, nil) + } + return nil, err + } + + // If the resource doesn't exist, we'll create it + if errors.IsNotFound(err) { + deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Create(newProvisionerDeployment(bus)) + } + + // If an error occurs during Get/Create, we'll requeue the item so we can + // attempt processing again later. This could have been caused by a + // temporary network failure, or any other transient reason. + if err != nil { + return nil, err + } + + // If the Deployment is not controlled by this Bus resource, we should log + // a warning to the event recorder and return + if !metav1.IsControlledBy(deployment, bus) { + msg := fmt.Sprintf(MessageResourceExists, deployment.Name) + c.recorder.Event(bus, corev1.EventTypeWarning, ErrResourceExists, msg) + return nil, fmt.Errorf(msg) + } + + // If the Deployment does not match the Bus's proposed Deployment we should update + // the Deployment resource. + proposedDeployment := newProvisionerDeployment(bus) + if !reflect.DeepEqual(proposedDeployment.Spec, deployment.Spec) { + glog.V(4).Infof("Bus %s container spec updated", bus.Name) + deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Update(proposedDeployment) + + if err != nil { + return nil, err + } + } + + return deployment, nil +} + +func (c *Controller) updateBusStatus(bus *channelsv1alpha1.Bus, eventService *corev1.Service, eventDeployment *appsv1.Deployment, provisionerDeployment *appsv1.Deployment) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance @@ -428,16 +485,17 @@ func (c *Controller) handleObject(obj interface{}) { } } -// newService creates a new Service for a Bus resource. It also sets +// newEventService creates a new Service for a Bus resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Bus resource that 'owns' it. -func newService(bus *channelsv1alpha1.Bus) *corev1.Service { +func newEventService(bus *channelsv1alpha1.Bus) *corev1.Service { labels := map[string]string{ - "bus": bus.Name, + "bus": bus.Name, + "role": "event", } return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.BusServiceName(bus.ObjectMeta.Name), + Name: controller.BusEventServiceName(bus.ObjectMeta.Name), Namespace: bus.Namespace, Labels: labels, OwnerReferences: []metav1.OwnerReference{ @@ -461,12 +519,13 @@ func newService(bus *channelsv1alpha1.Bus) *corev1.Service { } } -// newDeployment creates a new Deployment for a Bus resource. It also sets +// newEventDeployment creates a new Deployment for a Bus resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Bus resource that 'owns' it. -func newDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { +func newEventDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { labels := map[string]string{ - "bus": bus.Name, + "bus": bus.Name, + "role": "event", } one := int32(1) container := bus.Spec.Container.DeepCopy() @@ -482,7 +541,55 @@ func newDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { ) return &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.BusDeploymentName(bus.ObjectMeta.Name), + Name: controller.BusEventDeploymentName(bus.ObjectMeta.Name), + Namespace: bus.Namespace, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(bus, schema.GroupVersionKind{ + Group: channelsv1alpha1.SchemeGroupVersion.Group, + Version: channelsv1alpha1.SchemeGroupVersion.Version, + Kind: "Bus", + }), + }, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: &one, + Selector: &metav1.LabelSelector{ + MatchLabels: labels, + }, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: labels, + }, + Spec: corev1.PodSpec{ + ServiceAccountName: "bus-events", + Containers: []corev1.Container{ + *container, + }, + }, + }, + }, + } +} + +// newProvisionerDeployment creates a new Deployment for a Bus resource. It also sets +// the appropriate OwnerReferences on the resource so handleObject can discover +// the Bus resource that 'owns' it. +func newProvisionerDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { + labels := map[string]string{ + "bus": bus.Name, + "role": "provisioner", + } + one := int32(1) + container := bus.Spec.Provisioner.DeepCopy() + container.Env = append(container.Env, + corev1.EnvVar{ + Name: "BUS_NAME", + Value: bus.Name, + }, + ) + return &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.BusProvisionerDeploymentName(bus.ObjectMeta.Name), Namespace: bus.Namespace, OwnerReferences: []metav1.OwnerReference{ *metav1.NewControllerRef(bus, schema.GroupVersionKind{ diff --git a/pkg/controller/channel/controller.go b/pkg/controller/channel/controller.go index aef0a6c7ee8..8941d3c66bc 100644 --- a/pkg/controller/channel/controller.go +++ b/pkg/controller/channel/controller.go @@ -517,7 +517,7 @@ func newRouteRule(channel *channelsv1alpha1.Channel) *istiov1alpha2.RouteRule { Route: []istiov1alpha2.DestinationWeight{ { Destination: istiov1alpha2.IstioService{ - Name: controller.BusServiceName(channel.Spec.Bus), + Name: controller.BusEventServiceName(channel.Spec.Bus), }, Weight: 100, }, diff --git a/pkg/controller/names.go b/pkg/controller/names.go index 9281e703473..090dbe2631b 100644 --- a/pkg/controller/names.go +++ b/pkg/controller/names.go @@ -18,11 +18,15 @@ package controller import "fmt" -func BusDeploymentName(busName string) string { +func BusProvisionerDeploymentName(busName string) string { + return fmt.Sprintf("%s-bus-provisioner", busName) +} + +func BusEventDeploymentName(busName string) string { return fmt.Sprintf("%s-bus", busName) } -func BusServiceName(busName string) string { +func BusEventServiceName(busName string) string { return fmt.Sprintf("%s-bus", busName) } From de07ce852ff49d1d08b3f25b7387587c9d9b779b Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Thu, 7 Jun 2018 15:33:21 -0400 Subject: [PATCH 15/21] Provisioner polish --- config/bus-clusterrolebinding.yaml | 4 +- config/bus-serviceaccount.yaml | 2 +- config/buses/stub.yaml | 4 +- pkg/apis/channels/v1alpha1/bus_types.go | 4 +- .../v1alpha1/zz_generated.deepcopy.go | 2 +- pkg/controller/bus/controller.go | 51 ++++++++++--------- pkg/controller/channel/controller.go | 2 +- pkg/controller/names.go | 4 +- 8 files changed, 38 insertions(+), 35 deletions(-) diff --git a/config/bus-clusterrolebinding.yaml b/config/bus-clusterrolebinding.yaml index 46dd7389afe..ca25e319cc7 100644 --- a/config/bus-clusterrolebinding.yaml +++ b/config/bus-clusterrolebinding.yaml @@ -31,10 +31,10 @@ roleRef: apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: - name: bus-events + name: bus-dispatcher subjects: - kind: ServiceAccount - name: bus-data + name: bus-dispatcher namespace: knative-eventing-system roleRef: kind: ClusterRole diff --git a/config/bus-serviceaccount.yaml b/config/bus-serviceaccount.yaml index 401fb2f0de0..276e8bed9d4 100644 --- a/config/bus-serviceaccount.yaml +++ b/config/bus-serviceaccount.yaml @@ -21,5 +21,5 @@ metadata: apiVersion: v1 kind: ServiceAccount metadata: - name: bus-events + name: bus-dispatcher namespace: knative-eventing-system diff --git a/config/buses/stub.yaml b/config/buses/stub.yaml index 38da64ae3e4..dc940b5ddb8 100644 --- a/config/buses/stub.yaml +++ b/config/buses/stub.yaml @@ -3,6 +3,6 @@ kind: Bus metadata: name: stub spec: - container: - name: bus + dispatcher: + name: dispatcher image: github.com/knative/eventing/cmd/stub-bus diff --git a/pkg/apis/channels/v1alpha1/bus_types.go b/pkg/apis/channels/v1alpha1/bus_types.go index 51d47aaee9a..e9834712724 100644 --- a/pkg/apis/channels/v1alpha1/bus_types.go +++ b/pkg/apis/channels/v1alpha1/bus_types.go @@ -40,8 +40,8 @@ type BusSpec struct { // Provisioner container definition to manage channels on the bus. Provisioner *kapi.Container `json:"provisioner,omitempty"` - // Container definition to use for the bus data plane. - Container kapi.Container `json:"container"` + // Dispatcher container definition to use for the bus data plane. + Dispatcher kapi.Container `json:"dispatcher"` } // BusStatus (computed) for a bus diff --git a/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go index dd8fcffa918..b9c1317199e 100644 --- a/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go @@ -106,7 +106,7 @@ func (in *BusSpec) DeepCopyInto(out *BusSpec) { (*in).DeepCopyInto(*out) } } - in.Container.DeepCopyInto(&out.Container) + in.Dispatcher.DeepCopyInto(&out.Dispatcher) return } diff --git a/pkg/controller/bus/controller.go b/pkg/controller/bus/controller.go index b761e52263f..34541d01035 100644 --- a/pkg/controller/bus/controller.go +++ b/pkg/controller/bus/controller.go @@ -277,13 +277,13 @@ func (c *Controller) syncHandler(key string) error { } // Sync Service derived from the Bus - eventService, err := c.syncBusEventService(bus) + dispatcherService, err := c.syncBusDispatcherService(bus) if err != nil { return err } // Sync Deployment derived from the Bus - eventDeployment, err := c.syncBusEventDeployment(bus) + dispatcherDeployment, err := c.syncBusDispatcherDeployment(bus) if err != nil { return err } @@ -296,19 +296,19 @@ func (c *Controller) syncHandler(key string) error { // Finally, we update the status block of the Bus resource to reflect the // current state of the world - return c.updateBusStatus(bus, eventService, eventDeployment, provisionerDeployment) + return c.updateBusStatus(bus, dispatcherService, dispatcherDeployment, provisionerDeployment) c.recorder.Event(bus, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) return nil } -func (c *Controller) syncBusEventService(bus *channelsv1alpha1.Bus) (*corev1.Service, error) { +func (c *Controller) syncBusDispatcherService(bus *channelsv1alpha1.Bus) (*corev1.Service, error) { // Get the service with the specified service name - serviceName := controller.BusEventServiceName(bus.ObjectMeta.Name) + serviceName := controller.BusDispatcherServiceName(bus.ObjectMeta.Name) service, err := c.servicesLister.Services(bus.Namespace).Get(serviceName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - service, err = c.kubeclientset.CoreV1().Services(bus.Namespace).Create(newEventService(bus)) + service, err = c.kubeclientset.CoreV1().Services(bus.Namespace).Create(newDispatcherService(bus)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -329,13 +329,13 @@ func (c *Controller) syncBusEventService(bus *channelsv1alpha1.Bus) (*corev1.Ser return service, nil } -func (c *Controller) syncBusEventDeployment(bus *channelsv1alpha1.Bus) (*appsv1.Deployment, error) { +func (c *Controller) syncBusDispatcherDeployment(bus *channelsv1alpha1.Bus) (*appsv1.Deployment, error) { // Get the deployment with the specified deployment name - deploymentName := controller.BusEventDeploymentName(bus.ObjectMeta.Name) + deploymentName := controller.BusDispatcherDeploymentName(bus.ObjectMeta.Name) deployment, err := c.deploymentsLister.Deployments(bus.Namespace).Get(deploymentName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { - deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Create(newEventDeployment(bus)) + deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Create(newDispatcherDeployment(bus)) } // If an error occurs during Get/Create, we'll requeue the item so we can @@ -355,9 +355,9 @@ func (c *Controller) syncBusEventDeployment(bus *channelsv1alpha1.Bus) (*appsv1. // If the Deployment does not match the Bus's proposed Deployment we should update // the Deployment resource. - proposedDeployment := newEventDeployment(bus) + proposedDeployment := newDispatcherDeployment(bus) if !reflect.DeepEqual(proposedDeployment.Spec, deployment.Spec) { - glog.V(4).Infof("Bus %s container spec updated", bus.Name) + glog.V(4).Infof("Bus %s dispatcher spec updated", bus.Name) deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Update(proposedDeployment) if err != nil { @@ -378,9 +378,12 @@ func (c *Controller) syncBusProvisionerDeployment(bus *channelsv1alpha1.Bus) (*a // If the resource shouldn't exists if provisioner == nil { // If the resource exists, we'll delete it - if err == nil { + if deployment != nil { err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Delete(deploymentName, nil) } + if errors.IsNotFound(err) { + return nil, nil + } return nil, err } @@ -408,7 +411,7 @@ func (c *Controller) syncBusProvisionerDeployment(bus *channelsv1alpha1.Bus) (*a // the Deployment resource. proposedDeployment := newProvisionerDeployment(bus) if !reflect.DeepEqual(proposedDeployment.Spec, deployment.Spec) { - glog.V(4).Infof("Bus %s container spec updated", bus.Name) + glog.V(4).Infof("Bus %s provisioner spec updated", bus.Name) deployment, err = c.kubeclientset.AppsV1().Deployments(bus.Namespace).Update(proposedDeployment) if err != nil { @@ -419,7 +422,7 @@ func (c *Controller) syncBusProvisionerDeployment(bus *channelsv1alpha1.Bus) (*a return deployment, nil } -func (c *Controller) updateBusStatus(bus *channelsv1alpha1.Bus, eventService *corev1.Service, eventDeployment *appsv1.Deployment, provisionerDeployment *appsv1.Deployment) error { +func (c *Controller) updateBusStatus(bus *channelsv1alpha1.Bus, dispatcherService *corev1.Service, dispatcherDeployment *appsv1.Deployment, provisionerDeployment *appsv1.Deployment) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance @@ -485,17 +488,17 @@ func (c *Controller) handleObject(obj interface{}) { } } -// newEventService creates a new Service for a Bus resource. It also sets +// newDispatcherService creates a new Service for a Bus resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Bus resource that 'owns' it. -func newEventService(bus *channelsv1alpha1.Bus) *corev1.Service { +func newDispatcherService(bus *channelsv1alpha1.Bus) *corev1.Service { labels := map[string]string{ "bus": bus.Name, - "role": "event", + "role": "dispatcher", } return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.BusEventServiceName(bus.ObjectMeta.Name), + Name: controller.BusDispatcherServiceName(bus.ObjectMeta.Name), Namespace: bus.Namespace, Labels: labels, OwnerReferences: []metav1.OwnerReference{ @@ -519,16 +522,16 @@ func newEventService(bus *channelsv1alpha1.Bus) *corev1.Service { } } -// newEventDeployment creates a new Deployment for a Bus resource. It also sets +// newDispatcherDeployment creates a new Deployment for a Bus resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Bus resource that 'owns' it. -func newEventDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { +func newDispatcherDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { labels := map[string]string{ "bus": bus.Name, - "role": "event", + "role": "dispatcher", } one := int32(1) - container := bus.Spec.Container.DeepCopy() + container := bus.Spec.Dispatcher.DeepCopy() container.Env = append(container.Env, corev1.EnvVar{ Name: "PORT", @@ -541,7 +544,7 @@ func newEventDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { ) return &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ - Name: controller.BusEventDeploymentName(bus.ObjectMeta.Name), + Name: controller.BusDispatcherDeploymentName(bus.ObjectMeta.Name), Namespace: bus.Namespace, OwnerReferences: []metav1.OwnerReference{ *metav1.NewControllerRef(bus, schema.GroupVersionKind{ @@ -561,7 +564,7 @@ func newEventDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { Labels: labels, }, Spec: corev1.PodSpec{ - ServiceAccountName: "bus-events", + ServiceAccountName: "bus-dispatcher", Containers: []corev1.Container{ *container, }, diff --git a/pkg/controller/channel/controller.go b/pkg/controller/channel/controller.go index 8941d3c66bc..b09e10c24df 100644 --- a/pkg/controller/channel/controller.go +++ b/pkg/controller/channel/controller.go @@ -517,7 +517,7 @@ func newRouteRule(channel *channelsv1alpha1.Channel) *istiov1alpha2.RouteRule { Route: []istiov1alpha2.DestinationWeight{ { Destination: istiov1alpha2.IstioService{ - Name: controller.BusEventServiceName(channel.Spec.Bus), + Name: controller.BusDispatcherServiceName(channel.Spec.Bus), }, Weight: 100, }, diff --git a/pkg/controller/names.go b/pkg/controller/names.go index 090dbe2631b..c995586e2c7 100644 --- a/pkg/controller/names.go +++ b/pkg/controller/names.go @@ -22,11 +22,11 @@ func BusProvisionerDeploymentName(busName string) string { return fmt.Sprintf("%s-bus-provisioner", busName) } -func BusEventDeploymentName(busName string) string { +func BusDispatcherDeploymentName(busName string) string { return fmt.Sprintf("%s-bus", busName) } -func BusEventServiceName(busName string) string { +func BusDispatcherServiceName(busName string) string { return fmt.Sprintf("%s-bus", busName) } From a45911d93198e935b576e2368262fd87cdd492f5 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Thu, 7 Jun 2018 17:36:44 -0400 Subject: [PATCH 16/21] Descope bus service account to read-only for bus, channel and subscription --- config/bus-clusterrolebinding.yaml | 42 ---- config/buses/stub.yaml | 4 + ...s-serviceaccount.yaml => clusterrole.yaml} | 18 +- pkg/controller/bus/controller.go | 192 ++++++++++++++++-- pkg/controller/channel/controller.go | 4 +- pkg/controller/names.go | 8 + 6 files changed, 191 insertions(+), 77 deletions(-) delete mode 100644 config/bus-clusterrolebinding.yaml rename config/{bus-serviceaccount.yaml => clusterrole.yaml} (72%) diff --git a/config/bus-clusterrolebinding.yaml b/config/bus-clusterrolebinding.yaml deleted file mode 100644 index ca25e319cc7..00000000000 --- a/config/bus-clusterrolebinding.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2018 Google, Inc. All rights reserved. -# -# 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. - -# TODO lock down access to least privilege - -apiVersion: rbac.authorization.k8s.io/v1beta1 -kind: ClusterRoleBinding -metadata: - name: bus-provisioner -subjects: - - kind: ServiceAccount - name: bus-provisioner - namespace: knative-eventing-system -roleRef: - kind: ClusterRole - name: cluster-admin - apiGroup: rbac.authorization.k8s.io - ---- -apiVersion: rbac.authorization.k8s.io/v1beta1 -kind: ClusterRoleBinding -metadata: - name: bus-dispatcher -subjects: - - kind: ServiceAccount - name: bus-dispatcher - namespace: knative-eventing-system -roleRef: - kind: ClusterRole - name: cluster-admin - apiGroup: rbac.authorization.k8s.io \ No newline at end of file diff --git a/config/buses/stub.yaml b/config/buses/stub.yaml index dc940b5ddb8..2643e2c71e7 100644 --- a/config/buses/stub.yaml +++ b/config/buses/stub.yaml @@ -6,3 +6,7 @@ spec: dispatcher: name: dispatcher image: github.com/knative/eventing/cmd/stub-bus + args: [ + "-logtostderr", + "-stderrthreshold", "INFO", + ] diff --git a/config/bus-serviceaccount.yaml b/config/clusterrole.yaml similarity index 72% rename from config/bus-serviceaccount.yaml rename to config/clusterrole.yaml index 276e8bed9d4..a1d70b9d20a 100644 --- a/config/bus-serviceaccount.yaml +++ b/config/clusterrole.yaml @@ -11,15 +11,11 @@ # 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. -apiVersion: v1 -kind: ServiceAccount +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 metadata: - name: bus-provisioner - namespace: knative-eventing-system - ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: bus-dispatcher - namespace: knative-eventing-system + name: knative-eventing-bus +rules: +- apiGroups: ["channels.eventing.knative.dev"] + resources: ["buses", "channels", "subscriptions"] + verbs: ["get", "watch", "list"] \ No newline at end of file diff --git a/pkg/controller/bus/controller.go b/pkg/controller/bus/controller.go index 34541d01035..25171779b7b 100644 --- a/pkg/controller/bus/controller.go +++ b/pkg/controller/bus/controller.go @@ -25,6 +25,7 @@ import ( "github.com/knative/eventing/pkg/controller" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + rbacv1beta1 "k8s.io/api/rbac/v1beta1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" @@ -37,6 +38,7 @@ import ( typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" appslisters "k8s.io/client-go/listers/apps/v1" corelisters "k8s.io/client-go/listers/core/v1" + rbaclisters "k8s.io/client-go/listers/rbac/v1beta1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" "k8s.io/client-go/util/workqueue" @@ -74,12 +76,16 @@ type Controller struct { // busclientset is a clientset for our own API group busclientset clientset.Interface - deploymentsLister appslisters.DeploymentLister - deploymentsSynced cache.InformerSynced - servicesLister corelisters.ServiceLister - servicesSynced cache.InformerSynced - busesLister listers.BusLister - busesSynced cache.InformerSynced + deploymentsLister appslisters.DeploymentLister + deploymentsSynced cache.InformerSynced + servicesLister corelisters.ServiceLister + servicesSynced cache.InformerSynced + serviceAccountsLister corelisters.ServiceAccountLister + serviceAccountsSynced cache.InformerSynced + clusterRoleBindingsLister rbaclisters.ClusterRoleBindingLister + clusterRoleBindingsSynced cache.InformerSynced + busesLister listers.BusLister + busesSynced cache.InformerSynced // workqueue is a rate limited work queue. This is used to queue work to be // processed instead of performing it as soon as a change happens. This @@ -105,6 +111,8 @@ func NewController( busInformer := busInformerFactory.Channels().V1alpha1().Buses() deploymentInformer := kubeInformerFactory.Apps().V1().Deployments() serviceInformer := kubeInformerFactory.Core().V1().Services() + serviceAccountInformer := kubeInformerFactory.Core().V1().ServiceAccounts() + clusterRoleBindingInformer := kubeInformerFactory.Rbac().V1beta1().ClusterRoleBindings() // Create event broadcaster // Add bus-controller types to the default Kubernetes Scheme so Events can be @@ -117,16 +125,20 @@ func NewController( recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName}) controller := &Controller{ - kubeclientset: kubeclientset, - busclientset: busclientset, - deploymentsLister: deploymentInformer.Lister(), - deploymentsSynced: deploymentInformer.Informer().HasSynced, - servicesLister: serviceInformer.Lister(), - servicesSynced: serviceInformer.Informer().HasSynced, - busesLister: busInformer.Lister(), - busesSynced: busInformer.Informer().HasSynced, - workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Buses"), - recorder: recorder, + kubeclientset: kubeclientset, + busclientset: busclientset, + deploymentsLister: deploymentInformer.Lister(), + deploymentsSynced: deploymentInformer.Informer().HasSynced, + servicesLister: serviceInformer.Lister(), + servicesSynced: serviceInformer.Informer().HasSynced, + serviceAccountsLister: serviceAccountInformer.Lister(), + serviceAccountsSynced: serviceAccountInformer.Informer().HasSynced, + clusterRoleBindingsLister: clusterRoleBindingInformer.Lister(), + clusterRoleBindingsSynced: clusterRoleBindingInformer.Informer().HasSynced, + busesLister: busInformer.Lister(), + busesSynced: busInformer.Informer().HasSynced, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Buses"), + recorder: recorder, } glog.Info("Setting up event handlers") @@ -235,12 +247,12 @@ func (c *Controller) processNextWorkItem() bool { // Run the syncHandler, passing it the namespace/name string of the // Bus resource to be synced. if err := c.syncHandler(key); err != nil { - return fmt.Errorf("error syncing '%s': %s", key, err.Error()) + return fmt.Errorf("error syncing bus '%s': %s", key, err.Error()) } // Finally, if no error occurs we Forget this item so it does not // get queued again until another change happens. c.workqueue.Forget(obj) - glog.Infof("Successfully synced '%s'", key) + glog.Infof("Successfully synced bus '%s'", key) return nil }(obj) @@ -276,6 +288,18 @@ func (c *Controller) syncHandler(key string) error { return err } + // Sync ServiceAccount derived from the Bus + serviceAccount, err := c.syncBusServiceAccount(bus) + if err != nil { + return err + } + + // Sync ClusterRoleBinding derived from the Bus + clusterRoleBinding, err := c.syncBusClusterRoleBinding(bus) + if err != nil { + return err + } + // Sync Service derived from the Bus dispatcherService, err := c.syncBusDispatcherService(bus) if err != nil { @@ -296,7 +320,7 @@ func (c *Controller) syncHandler(key string) error { // Finally, we update the status block of the Bus resource to reflect the // current state of the world - return c.updateBusStatus(bus, dispatcherService, dispatcherDeployment, provisionerDeployment) + return c.updateBusStatus(bus, dispatcherService, dispatcherDeployment, provisionerDeployment, serviceAccount, clusterRoleBinding) c.recorder.Event(bus, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) return nil @@ -368,6 +392,73 @@ func (c *Controller) syncBusDispatcherDeployment(bus *channelsv1alpha1.Bus) (*ap return deployment, nil } +func (c *Controller) syncBusServiceAccount(bus *channelsv1alpha1.Bus) (*corev1.ServiceAccount, error) { + // Get the serviceAccount with the specified serviceAccount name + serviceAccountName := controller.BusServiceAccountName(bus.ObjectMeta.Name) + serviceAccount, err := c.serviceAccountsLister.ServiceAccounts(bus.Namespace).Get(serviceAccountName) + // If the resource doesn't exist, we'll create it + if errors.IsNotFound(err) { + serviceAccount, err = c.kubeclientset.CoreV1().ServiceAccounts(bus.Namespace).Create(newServiceAccount(bus)) + } + + // If an error occurs during Get/Create, we'll requeue the item so we can + // attempt processing again later. This could have been caused by a + // temporary network failure, or any other transient reason. + if err != nil { + return nil, err + } + + // If the ServiceAccount is not controlled by this Bus resource, we should log + // a warning to the event recorder and return + if !metav1.IsControlledBy(serviceAccount, bus) { + msg := fmt.Sprintf(MessageResourceExists, serviceAccount.Name) + c.recorder.Event(bus, corev1.EventTypeWarning, ErrResourceExists, msg) + return nil, fmt.Errorf(msg) + } + + return serviceAccount, nil +} + +func (c *Controller) syncBusClusterRoleBinding(bus *channelsv1alpha1.Bus) (*rbacv1beta1.ClusterRoleBinding, error) { + // Get the clusterRoleBinding with the specified clusterRoleBinding name + clusterRoleBindingName := controller.BusClusterRoleBindingName(bus.ObjectMeta.Name) + clusterRoleBinding, err := c.clusterRoleBindingsLister.Get(clusterRoleBindingName) + // If the resource doesn't exist, we'll create it + if errors.IsNotFound(err) { + clusterRoleBinding, err = c.kubeclientset.RbacV1beta1().ClusterRoleBindings().Create(newClusterRoleBinding(bus)) + } + + // If an error occurs during Get/Create, we'll requeue the item so we can + // attempt processing again later. This could have been caused by a + // temporary network failure, or any other transient reason. + if err != nil { + return nil, err + } + + // If the ClusterRoleBinding is not controlled by this Bus resource, we should log + // a warning to the event recorder and return + if !metav1.IsControlledBy(clusterRoleBinding, bus) { + msg := fmt.Sprintf(MessageResourceExists, clusterRoleBinding.Name) + c.recorder.Event(bus, corev1.EventTypeWarning, ErrResourceExists, msg) + return nil, fmt.Errorf(msg) + } + + // If the ClusterRoleBinding does not match the Bus's proposed ClusterRoleBinding we + // should update the ClusterRoleBinding resource. + proposedClusterRoleBinding := newClusterRoleBinding(bus) + if !reflect.DeepEqual(proposedClusterRoleBinding.Subjects, clusterRoleBinding.Subjects) && + !reflect.DeepEqual(proposedClusterRoleBinding.RoleRef, clusterRoleBinding.RoleRef) { + glog.V(4).Infof("Bus %s provisioner spec updated", bus.Name) + clusterRoleBinding, err = c.kubeclientset.RbacV1beta1().ClusterRoleBindings().Update(proposedClusterRoleBinding) + + if err != nil { + return nil, err + } + } + + return clusterRoleBinding, nil +} + func (c *Controller) syncBusProvisionerDeployment(bus *channelsv1alpha1.Bus) (*appsv1.Deployment, error) { provisioner := bus.Spec.Provisioner @@ -422,7 +513,14 @@ func (c *Controller) syncBusProvisionerDeployment(bus *channelsv1alpha1.Bus) (*a return deployment, nil } -func (c *Controller) updateBusStatus(bus *channelsv1alpha1.Bus, dispatcherService *corev1.Service, dispatcherDeployment *appsv1.Deployment, provisionerDeployment *appsv1.Deployment) error { +func (c *Controller) updateBusStatus( + bus *channelsv1alpha1.Bus, + dispatcherService *corev1.Service, + dispatcherDeployment *appsv1.Deployment, + provisionerDeployment *appsv1.Deployment, + serviceAccount *corev1.ServiceAccount, + clusterRoleBinding *rbacv1beta1.ClusterRoleBinding, +) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance @@ -564,7 +662,7 @@ func newDispatcherDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { Labels: labels, }, Spec: corev1.PodSpec{ - ServiceAccountName: "bus-dispatcher", + ServiceAccountName: controller.BusServiceAccountName(bus.Name), Containers: []corev1.Container{ *container, }, @@ -574,6 +672,56 @@ func newDispatcherDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { } } +// newServiceAccount creates a new ServiceAccount for a Bus resource. It also sets +// the appropriate OwnerReferences on the resource so handleObject can discover +// the Bus resource that 'owns' it. +func newServiceAccount(bus *channelsv1alpha1.Bus) *corev1.ServiceAccount { + return &corev1.ServiceAccount{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.BusServiceAccountName(bus.ObjectMeta.Name), + Namespace: bus.Namespace, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(bus, schema.GroupVersionKind{ + Group: channelsv1alpha1.SchemeGroupVersion.Group, + Version: channelsv1alpha1.SchemeGroupVersion.Version, + Kind: "Bus", + }), + }, + }, + } +} + +// newClusterRoleBinding creates a new ClusterRoleBinding for a Bus resource. It also sets +// the appropriate OwnerReferences on the resource so handleObject can discover +// the Bus resource that 'owns' it. +func newClusterRoleBinding(bus *channelsv1alpha1.Bus) *rbacv1beta1.ClusterRoleBinding { + return &rbacv1beta1.ClusterRoleBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.BusClusterRoleBindingName(bus.ObjectMeta.Name), + Namespace: bus.Namespace, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(bus, schema.GroupVersionKind{ + Group: channelsv1alpha1.SchemeGroupVersion.Group, + Version: channelsv1alpha1.SchemeGroupVersion.Version, + Kind: "Bus", + }), + }, + }, + Subjects: []rbacv1beta1.Subject{ + { + Kind: "ServiceAccount", + Name: controller.BusServiceAccountName(bus.ObjectMeta.Name), + Namespace: bus.Namespace, + }, + }, + RoleRef: rbacv1beta1.RoleRef{ + Kind: "ClusterRole", + Name: "knative-eventing-bus", + APIGroup: "rbac.authorization.k8s.io", + }, + } +} + // newProvisionerDeployment creates a new Deployment for a Bus resource. It also sets // the appropriate OwnerReferences on the resource so handleObject can discover // the Bus resource that 'owns' it. @@ -612,7 +760,7 @@ func newProvisionerDeployment(bus *channelsv1alpha1.Bus) *appsv1.Deployment { Labels: labels, }, Spec: corev1.PodSpec{ - ServiceAccountName: "bus-provisioner", + ServiceAccountName: controller.BusServiceAccountName(bus.Name), Containers: []corev1.Container{ *container, }, diff --git a/pkg/controller/channel/controller.go b/pkg/controller/channel/controller.go index b09e10c24df..5156380f6af 100644 --- a/pkg/controller/channel/controller.go +++ b/pkg/controller/channel/controller.go @@ -241,12 +241,12 @@ func (c *Controller) processNextWorkItem() bool { // Run the syncHandler, passing it the namespace/name string of the // Channel resource to be synced. if err := c.syncHandler(key); err != nil { - return fmt.Errorf("error syncing '%s': %s", key, err.Error()) + return fmt.Errorf("error syncing channel '%s': %s", key, err.Error()) } // Finally, if no error occurs we Forget this item so it does not // get queued again until another change happens. c.workqueue.Forget(obj) - glog.Infof("Successfully synced '%s'", key) + glog.Infof("Successfully synced channel '%s'", key) return nil }(obj) diff --git a/pkg/controller/names.go b/pkg/controller/names.go index c995586e2c7..587d151e13a 100644 --- a/pkg/controller/names.go +++ b/pkg/controller/names.go @@ -26,6 +26,14 @@ func BusDispatcherDeploymentName(busName string) string { return fmt.Sprintf("%s-bus", busName) } +func BusServiceAccountName(busName string) string { + return fmt.Sprintf("%s-bus", busName) +} + +func BusClusterRoleBindingName(busName string) string { + return fmt.Sprintf("%s-bus", busName) +} + func BusDispatcherServiceName(busName string) string { return fmt.Sprintf("%s-bus", busName) } From 0972a9300bd38d09eca0c3985ce20bd1d6580e2a Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Thu, 7 Jun 2018 19:02:37 -0400 Subject: [PATCH 17/21] Parameters/arguments for bus->channel->subscription relationships A bus can now define parameters that a channel provides as arguments, and a channel can define parameters that a subscription provides as arguments. This allows for custom configuration of channels and subscriptions according to the capabilities of the bus. --- Gopkg.lock | 2 +- pkg/apis/channels/v1alpha1/bus_types.go | 3 + pkg/apis/channels/v1alpha1/channel_types.go | 6 + pkg/apis/channels/v1alpha1/param_types.go | 37 ++++++ .../channels/v1alpha1/subscription_types.go | 7 +- .../v1alpha1/zz_generated.deepcopy.go | 120 +++++++++++++----- pkg/subscription/monitor.go | 102 ++++++++++++++- 7 files changed, 238 insertions(+), 39 deletions(-) create mode 100644 pkg/apis/channels/v1alpha1/param_types.go diff --git a/Gopkg.lock b/Gopkg.lock index 1ff11010dfb..ebe347a97c4 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -873,6 +873,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "aa1c748ed9d39fc49606edff48c0a9f9227e71cee50906405edf7820013e7359" + inputs-digest = "909eb15dbf4a019750628971a06bf6d44b9bbdad666373472c2f5f08538c3b50" solver-name = "gps-cdcl" solver-version = 1 diff --git a/pkg/apis/channels/v1alpha1/bus_types.go b/pkg/apis/channels/v1alpha1/bus_types.go index e9834712724..96fd277655b 100644 --- a/pkg/apis/channels/v1alpha1/bus_types.go +++ b/pkg/apis/channels/v1alpha1/bus_types.go @@ -37,6 +37,9 @@ type Bus struct { // BusSpec (what the user wants) for a bus type BusSpec struct { + // Parameters configuration params for the bus + Parameters *[]Parameter `json:"parameters,omitempty"` + // Provisioner container definition to manage channels on the bus. Provisioner *kapi.Container `json:"provisioner,omitempty"` diff --git a/pkg/apis/channels/v1alpha1/channel_types.go b/pkg/apis/channels/v1alpha1/channel_types.go index 1875d2a59cd..ca9f21c7410 100644 --- a/pkg/apis/channels/v1alpha1/channel_types.go +++ b/pkg/apis/channels/v1alpha1/channel_types.go @@ -38,6 +38,12 @@ type ChannelSpec struct { // Name of the bus backing this channel (optional) Bus string + + // Arguments configuration arguments for the bus + Arguments *[]Argument `json:"arguments,omitempty"` + + // Parameters configuration params for the channel + Parameters *[]Parameter `json:"parameters,omitempty"` } // Status (computed) for a channel diff --git a/pkg/apis/channels/v1alpha1/param_types.go b/pkg/apis/channels/v1alpha1/param_types.go new file mode 100644 index 00000000000..fbababf4ee5 --- /dev/null +++ b/pkg/apis/channels/v1alpha1/param_types.go @@ -0,0 +1,37 @@ +/* + * Copyright 2018 the original author or 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 + +// inspired by the parameter/argument from buildtemplate/build + +// Parameter a named parameter that may be defined +type Parameter struct { + // Name parameter to apply + Name string `json:"name"` + + // Description human friendly description of the parameter + Description string `json:"description"` + + // Default (optional) value to use if not explicitly set + Default *string `json:"default,omitempty"` +} + +// Argument a value for a named parameter +type Argument struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/pkg/apis/channels/v1alpha1/subscription_types.go b/pkg/apis/channels/v1alpha1/subscription_types.go index 1a400006a3e..d75fcda9111 100644 --- a/pkg/apis/channels/v1alpha1/subscription_types.go +++ b/pkg/apis/channels/v1alpha1/subscription_types.go @@ -42,13 +42,10 @@ type SubscriptionSpec struct { // Name of the subscriber service Subscriber string `json:"subscriber"` - // Parameters for the subscription - Params *SubscriptionParams `json:"params,omitempty"` + // Arguments for the channel + Arguments *[]Argument `json:"arguments,omitempty"` } -// Params (key-value pairs) for a subscription -type SubscriptionParams map[string]string - // Status (computed) for a subscription type SubscriptionStatus struct { } diff --git a/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go index b9c1317199e..33aac9e1ee5 100644 --- a/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/channels/v1alpha1/zz_generated.deepcopy.go @@ -25,6 +25,22 @@ 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 *Argument) DeepCopyInto(out *Argument) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Argument. +func (in *Argument) DeepCopy() *Argument { + if in == nil { + return nil + } + out := new(Argument) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Bus) DeepCopyInto(out *Bus) { *out = *in @@ -97,6 +113,21 @@ func (in *BusList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BusSpec) DeepCopyInto(out *BusSpec) { *out = *in + if in.Parameters != nil { + in, out := &in.Parameters, &out.Parameters + if *in == nil { + *out = nil + } else { + *out = new([]Parameter) + if **in != nil { + in, out := *in, *out + *out = make([]Parameter, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + } + } if in.Provisioner != nil { in, out := &in.Provisioner, &out.Provisioner if *in == nil { @@ -141,7 +172,7 @@ func (in *Channel) DeepCopyInto(out *Channel) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) if in.Status != nil { in, out := &in.Status, &out.Status if *in == nil { @@ -208,6 +239,34 @@ func (in *ChannelList) DeepCopyObject() runtime.Object { // 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.Arguments != nil { + in, out := &in.Arguments, &out.Arguments + if *in == nil { + *out = nil + } else { + *out = new([]Argument) + if **in != nil { + in, out := *in, *out + *out = make([]Argument, len(*in)) + copy(*out, *in) + } + } + } + if in.Parameters != nil { + in, out := &in.Parameters, &out.Parameters + if *in == nil { + *out = nil + } else { + *out = new([]Parameter) + if **in != nil { + in, out := *in, *out + *out = make([]Parameter, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + } + } return } @@ -237,6 +296,31 @@ func (in *ChannelStatus) DeepCopy() *ChannelStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Parameter) DeepCopyInto(out *Parameter) { + *out = *in + if in.Default != nil { + in, out := &in.Default, &out.Default + if *in == nil { + *out = nil + } else { + *out = new(string) + **out = **in + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Parameter. +func (in *Parameter) DeepCopy() *Parameter { + if in == nil { + return nil + } + out := new(Parameter) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Subscription) DeepCopyInto(out *Subscription) { *out = *in @@ -306,43 +390,19 @@ func (in *SubscriptionList) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in SubscriptionParams) DeepCopyInto(out *SubscriptionParams) { - { - in := &in - *out = make(SubscriptionParams, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - return - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionParams. -func (in SubscriptionParams) DeepCopy() SubscriptionParams { - if in == nil { - return nil - } - out := new(SubscriptionParams) - in.DeepCopyInto(out) - return *out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SubscriptionSpec) DeepCopyInto(out *SubscriptionSpec) { *out = *in - if in.Params != nil { - in, out := &in.Params, &out.Params + if in.Arguments != nil { + in, out := &in.Arguments, &out.Arguments if *in == nil { *out = nil } else { - *out = new(SubscriptionParams) + *out = new([]Argument) if **in != nil { in, out := *in, *out - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } + *out = make([]Argument, len(*in)) + copy(*out, *in) } } } diff --git a/pkg/subscription/monitor.go b/pkg/subscription/monitor.go index eeddf4fdca0..48600cba6af 100644 --- a/pkg/subscription/monitor.go +++ b/pkg/subscription/monitor.go @@ -30,6 +30,7 @@ type Monitor struct { busName string handler MonitorEventHandlerFuncs + bus *channelsv1alpha1.BusSpec cache map[channelKey]*channelSummary mutex *sync.Mutex } @@ -52,6 +53,7 @@ type subscriptionSummary struct { func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, handler MonitorEventHandlerFuncs) *Monitor { + busInformer := informerFactory.Channels().V1alpha1().Buses() channelInformer := informerFactory.Channels().V1alpha1().Channels() subscriptionInformer := informerFactory.Channels().V1alpha1().Subscriptions() @@ -59,11 +61,31 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, busName: busName, handler: handler, + bus: nil, cache: make(map[channelKey]*channelSummary), mutex: &sync.Mutex{}, } glog.Info("Setting up event handlers") + // Set up an event handler for when Bus resources change + busInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + bus := obj.(*channelsv1alpha1.Bus) + monitor.createOrUpdateBus(*bus) + }, + UpdateFunc: func(old, new interface{}) { + oldBus := old.(*channelsv1alpha1.Bus) + newBus := new.(*channelsv1alpha1.Bus) + + if oldBus.ResourceVersion == newBus.ResourceVersion { + // Periodic resync will send update events for all known Buses. + // Two different versions of the same Bus will always have different RVs. + return + } + + monitor.createOrUpdateBus(*newBus) + }, + }) // Set up an event handler for when Channel resources change channelInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { @@ -120,12 +142,23 @@ func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, return monitor } +// Channel for a channel name and namespace +func (m *Monitor) Channel(channel string, namespace string) *channelsv1alpha1.ChannelSpec { + channelKey := makeChannelKeyWithNames(channel, namespace) + summary := m.getChannelSummary(channelKey) + + if summary == nil { + return nil + } + return summary.Channel +} + // Subscriptions for a channel name and namespace func (m *Monitor) Subscriptions(channel string, namespace string) *[]channelsv1alpha1.SubscriptionSpec { channelKey := makeChannelKeyWithNames(channel, namespace) - summary := m.getOrCreateChannelSummary(channelKey) + summary := m.getChannelSummary(channelKey) - if summary.Channel == nil { + if summary == nil || summary.Channel == nil { // the channel is unknown return nil } @@ -136,7 +169,7 @@ func (m *Monitor) Subscriptions(channel string, namespace string) *[]channelsv1a } m.mutex.Lock() - subscriptions := make([]channelsv1alpha1.SubscriptionSpec, len(summary.Subscriptions)) + subscriptions := make([]channelsv1alpha1.SubscriptionSpec, len(summary.Subscriptions)-1) for _, subscription := range summary.Subscriptions { subscriptions = append(subscriptions, subscription.Subscription) } @@ -145,6 +178,59 @@ func (m *Monitor) Subscriptions(channel string, namespace string) *[]channelsv1a return &subscriptions } +// ChannelParams resolve parameters for a channel +func (m *Monitor) ChannelParams(channel channelsv1alpha1.ChannelSpec) map[string]string { + params := make(map[string]string) + + // apply bus defaults + if m.bus.Parameters != nil { + for _, param := range *m.bus.Parameters { + if param.Default != nil { + params[param.Name] = *param.Default + } + } + } + // apply channel arguments + if channel.Arguments != nil { + for _, arg := range *channel.Arguments { + // TODO ignore arguments not defined by parameters + params[arg.Name] = arg.Value + } + } + + return params +} + +// SubscriptionParams resolve parameters for a subscription +func (m *Monitor) SubscriptionParams( + channel channelsv1alpha1.ChannelSpec, + subscription channelsv1alpha1.SubscriptionSpec, +) map[string]string { + params := m.ChannelParams(channel) + + // apply channel defaults + if channel.Parameters != nil { + for _, param := range *channel.Parameters { + if _, ok := params[param.Name]; !ok && param.Default != nil { + params[param.Name] = *param.Default + } + } + } + // apply subscription arguments + if subscription.Arguments != nil { + for _, arg := range *subscription.Arguments { + // TODO ignore arguments not defined by parameters + params[arg.Name] = arg.Value + } + } + + return params +} + +func (m *Monitor) getChannelSummary(key channelKey) *channelSummary { + return m.cache[key] +} + func (m *Monitor) getOrCreateChannelSummary(key channelKey) *channelSummary { m.mutex.Lock() summary, ok := m.cache[key] @@ -160,6 +246,16 @@ func (m *Monitor) getOrCreateChannelSummary(key channelKey) *channelSummary { return summary } +func (m *Monitor) createOrUpdateBus(bus channelsv1alpha1.Bus) { + if bus.Name != m.busName { + // this is not our bus + return + } + if !reflect.DeepEqual(m.bus, bus.Spec) { + m.bus = &bus.Spec + } +} + func (m *Monitor) createOrUpdateChannel(channel channelsv1alpha1.Channel) { channelKey := makeChannelKeyFromChannel(channel) summary := m.getOrCreateChannelSummary(channelKey) From 9262da317effa0ca142d4ce295984abe01d5d967 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Fri, 8 Jun 2018 10:49:01 -0400 Subject: [PATCH 18/21] Add missing license headers --- config/bus.yaml | 13 +++++++++++++ config/buses/stub.yaml | 13 +++++++++++++ config/channel.yaml | 13 +++++++++++++ config/subscription.yaml | 13 +++++++++++++ 4 files changed, 52 insertions(+) diff --git a/config/bus.yaml b/config/bus.yaml index d31bb77cd21..ae44e33eea5 100644 --- a/config/bus.yaml +++ b/config/bus.yaml @@ -1,3 +1,16 @@ +# Copyright 2018 Google, Inc. All rights reserved. +# +# 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. apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: diff --git a/config/buses/stub.yaml b/config/buses/stub.yaml index 2643e2c71e7..cb8f9ec9f0b 100644 --- a/config/buses/stub.yaml +++ b/config/buses/stub.yaml @@ -1,3 +1,16 @@ +# Copyright 2018 Google, Inc. All rights reserved. +# +# 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. apiVersion: channels.eventing.knative.dev/v1alpha1 kind: Bus metadata: diff --git a/config/channel.yaml b/config/channel.yaml index 3fdc40c51e7..44826b67a4e 100644 --- a/config/channel.yaml +++ b/config/channel.yaml @@ -1,3 +1,16 @@ +# Copyright 2018 Google, Inc. All rights reserved. +# +# 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. apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: diff --git a/config/subscription.yaml b/config/subscription.yaml index 2a9b02dc5cc..06329184800 100644 --- a/config/subscription.yaml +++ b/config/subscription.yaml @@ -1,3 +1,16 @@ +# Copyright 2018 Google, Inc. All rights reserved. +# +# 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. apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: From ac6c8ff36c5aed817f470f921daaa4e45d00a921 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Fri, 8 Jun 2018 11:00:18 -0400 Subject: [PATCH 19/21] Rename group channels.eventing.knative.dev to channels.knative.dev --- config/bus.yaml | 4 ++-- config/buses/stub.yaml | 2 +- config/channel.yaml | 4 ++-- config/clusterrole.yaml | 4 ++-- config/subscription.yaml | 4 ++-- pkg/apis/channels/register.go | 2 +- pkg/apis/channels/v1alpha1/bus_types.go | 2 +- pkg/apis/channels/v1alpha1/channel_types.go | 2 +- pkg/apis/channels/v1alpha1/doc.go | 2 +- pkg/apis/channels/v1alpha1/subscription_types.go | 2 +- .../versioned/typed/channels/v1alpha1/channels_client.go | 2 +- .../versioned/typed/channels/v1alpha1/fake/fake_bus.go | 4 ++-- .../versioned/typed/channels/v1alpha1/fake/fake_channel.go | 4 ++-- .../typed/channels/v1alpha1/fake/fake_subscription.go | 4 ++-- pkg/client/informers/externalversions/generic.go | 2 +- pkg/controller/bus/controller.go | 2 +- sample/hello/hello-channel.yaml | 6 ++++-- sample/square/square.yaml | 4 ++-- 18 files changed, 29 insertions(+), 27 deletions(-) diff --git a/config/bus.yaml b/config/bus.yaml index ae44e33eea5..70a192772af 100644 --- a/config/bus.yaml +++ b/config/bus.yaml @@ -14,10 +14,10 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: buses.channels.eventing.knative.dev + name: buses.channels.knative.dev spec: scope: Namespaced - group: channels.eventing.knative.dev + group: channels.knative.dev version: v1alpha1 names: kind: Bus diff --git a/config/buses/stub.yaml b/config/buses/stub.yaml index cb8f9ec9f0b..80d39ac2c01 100644 --- a/config/buses/stub.yaml +++ b/config/buses/stub.yaml @@ -11,7 +11,7 @@ # 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. -apiVersion: channels.eventing.knative.dev/v1alpha1 +apiVersion: channels.knative.dev/v1alpha1 kind: Bus metadata: name: stub diff --git a/config/channel.yaml b/config/channel.yaml index 44826b67a4e..c56a3489226 100644 --- a/config/channel.yaml +++ b/config/channel.yaml @@ -14,10 +14,10 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: channels.channels.eventing.knative.dev + name: channels.channels.knative.dev spec: scope: Namespaced - group: channels.eventing.knative.dev + group: channels.knative.dev version: v1alpha1 names: kind: Channel diff --git a/config/clusterrole.yaml b/config/clusterrole.yaml index a1d70b9d20a..5e37fa384c5 100644 --- a/config/clusterrole.yaml +++ b/config/clusterrole.yaml @@ -14,8 +14,8 @@ kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: - name: knative-eventing-bus + name: knative-channels-bus rules: -- apiGroups: ["channels.eventing.knative.dev"] +- apiGroups: ["channels.knative.dev"] resources: ["buses", "channels", "subscriptions"] verbs: ["get", "watch", "list"] \ No newline at end of file diff --git a/config/subscription.yaml b/config/subscription.yaml index 06329184800..8b98f72dafe 100644 --- a/config/subscription.yaml +++ b/config/subscription.yaml @@ -14,10 +14,10 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: subscriptions.channels.eventing.knative.dev + name: subscriptions.channels.knative.dev spec: scope: Namespaced - group: channels.eventing.knative.dev + group: channels.knative.dev version: v1alpha1 names: kind: Subscription diff --git a/pkg/apis/channels/register.go b/pkg/apis/channels/register.go index e33d29980b1..cf684d5ac44 100644 --- a/pkg/apis/channels/register.go +++ b/pkg/apis/channels/register.go @@ -17,5 +17,5 @@ limitations under the License. package channels const ( - GroupName = "channels.eventing.knative.dev" + GroupName = "channels.knative.dev" ) diff --git a/pkg/apis/channels/v1alpha1/bus_types.go b/pkg/apis/channels/v1alpha1/bus_types.go index 96fd277655b..de9635baa7f 100644 --- a/pkg/apis/channels/v1alpha1/bus_types.go +++ b/pkg/apis/channels/v1alpha1/bus_types.go @@ -26,7 +26,7 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Bus represents the buses.channels.eventing.knative.dev CRD +// Bus represents the buses.channels.knative.dev CRD type Bus struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` diff --git a/pkg/apis/channels/v1alpha1/channel_types.go b/pkg/apis/channels/v1alpha1/channel_types.go index ca9f21c7410..759c1c86a42 100644 --- a/pkg/apis/channels/v1alpha1/channel_types.go +++ b/pkg/apis/channels/v1alpha1/channel_types.go @@ -25,7 +25,7 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the channels.channels.eventing.knative.dev CRD +// Represents the channels.channels.knative.dev CRD type Channel struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` diff --git a/pkg/apis/channels/v1alpha1/doc.go b/pkg/apis/channels/v1alpha1/doc.go index bb8aa2dca6d..6433304c238 100644 --- a/pkg/apis/channels/v1alpha1/doc.go +++ b/pkg/apis/channels/v1alpha1/doc.go @@ -12,5 +12,5 @@ limitations under the License. */ // +k8s:deepcopy-gen=package // Package v1alpha1 is the v1alpha1 version of the API. -// +groupName=channels.eventing.knative.dev +// +groupName=channels.knative.dev package v1alpha1 diff --git a/pkg/apis/channels/v1alpha1/subscription_types.go b/pkg/apis/channels/v1alpha1/subscription_types.go index d75fcda9111..a591f98fca1 100644 --- a/pkg/apis/channels/v1alpha1/subscription_types.go +++ b/pkg/apis/channels/v1alpha1/subscription_types.go @@ -25,7 +25,7 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the subscriptions.channels.eventing.knative.dev CRD +// Represents the subscriptions.channels.knative.dev CRD type Subscription struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` diff --git a/pkg/client/clientset/versioned/typed/channels/v1alpha1/channels_client.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/channels_client.go index ca2b6ed467b..bb5776fa3b5 100644 --- a/pkg/client/clientset/versioned/typed/channels/v1alpha1/channels_client.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/channels_client.go @@ -32,7 +32,7 @@ type ChannelsV1alpha1Interface interface { SubscriptionsGetter } -// ChannelsV1alpha1Client is used to interact with features provided by the channels.eventing.knative.dev group. +// ChannelsV1alpha1Client is used to interact with features provided by the channels.knative.dev group. type ChannelsV1alpha1Client struct { restClient rest.Interface } diff --git a/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_bus.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_bus.go index 555083df926..e7e85412d6d 100644 --- a/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_bus.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_bus.go @@ -34,9 +34,9 @@ type FakeBuses struct { ns string } -var busesResource = schema.GroupVersionResource{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Resource: "buses"} +var busesResource = schema.GroupVersionResource{Group: "channels.knative.dev", Version: "v1alpha1", Resource: "buses"} -var busesKind = schema.GroupVersionKind{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Kind: "Bus"} +var busesKind = schema.GroupVersionKind{Group: "channels.knative.dev", Version: "v1alpha1", Kind: "Bus"} // Get takes name of the bus, and returns the corresponding bus object, and an error if there is any. func (c *FakeBuses) Get(name string, options v1.GetOptions) (result *v1alpha1.Bus, err error) { diff --git a/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channel.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channel.go index c78cf2ffb18..2b816cbcefd 100644 --- a/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channel.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_channel.go @@ -34,9 +34,9 @@ type FakeChannels struct { ns string } -var channelsResource = schema.GroupVersionResource{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Resource: "channels"} +var channelsResource = schema.GroupVersionResource{Group: "channels.knative.dev", Version: "v1alpha1", Resource: "channels"} -var channelsKind = schema.GroupVersionKind{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Kind: "Channel"} +var channelsKind = schema.GroupVersionKind{Group: "channels.knative.dev", Version: "v1alpha1", Kind: "Channel"} // Get takes name of the channel, and returns the corresponding channel object, and an error if there is any. func (c *FakeChannels) Get(name string, options v1.GetOptions) (result *v1alpha1.Channel, err error) { diff --git a/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_subscription.go b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_subscription.go index e4a8a156343..a4ef34488ca 100644 --- a/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_subscription.go +++ b/pkg/client/clientset/versioned/typed/channels/v1alpha1/fake/fake_subscription.go @@ -34,9 +34,9 @@ type FakeSubscriptions struct { ns string } -var subscriptionsResource = schema.GroupVersionResource{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Resource: "subscriptions"} +var subscriptionsResource = schema.GroupVersionResource{Group: "channels.knative.dev", Version: "v1alpha1", Resource: "subscriptions"} -var subscriptionsKind = schema.GroupVersionKind{Group: "channels.eventing.knative.dev", Version: "v1alpha1", Kind: "Subscription"} +var subscriptionsKind = schema.GroupVersionKind{Group: "channels.knative.dev", Version: "v1alpha1", Kind: "Subscription"} // Get takes name of the subscription, and returns the corresponding subscription object, and an error if there is any. func (c *FakeSubscriptions) Get(name string, options v1.GetOptions) (result *v1alpha1.Subscription, err error) { diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 7a950f735ac..5a7cbb84ed2 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -54,7 +54,7 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { - // Group=channels.eventing.knative.dev, Version=v1alpha1 + // Group=channels.knative.dev, Version=v1alpha1 case v1alpha1.SchemeGroupVersion.WithResource("buses"): return &genericInformer{resource: resource.GroupResource(), informer: f.Channels().V1alpha1().Buses().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("channels"): diff --git a/pkg/controller/bus/controller.go b/pkg/controller/bus/controller.go index 25171779b7b..30191ae7fab 100644 --- a/pkg/controller/bus/controller.go +++ b/pkg/controller/bus/controller.go @@ -716,7 +716,7 @@ func newClusterRoleBinding(bus *channelsv1alpha1.Bus) *rbacv1beta1.ClusterRoleBi }, RoleRef: rbacv1beta1.RoleRef{ Kind: "ClusterRole", - Name: "knative-eventing-bus", + Name: "knative-channels-bus", APIGroup: "rbac.authorization.k8s.io", }, } diff --git a/sample/hello/hello-channel.yaml b/sample/hello/hello-channel.yaml index f22f64e25d4..7f17626a615 100644 --- a/sample/hello/hello-channel.yaml +++ b/sample/hello/hello-channel.yaml @@ -1,10 +1,12 @@ -apiVersion: channels.eventing.knative.dev/v1alpha1 +apiVersion: channels.knative.dev/v1alpha1 kind: Channel metadata: name: aloha +spec: + bus: stub --- -apiVersion: channels.eventing.knative.dev/v1alpha1 +apiVersion: channels.knative.dev/v1alpha1 kind: Subscription metadata: name: aloha2hello diff --git a/sample/square/square.yaml b/sample/square/square.yaml index d6071bccb9c..b96784127a2 100644 --- a/sample/square/square.yaml +++ b/sample/square/square.yaml @@ -34,7 +34,7 @@ spec: app: square --- -apiVersion: channels.eventing.knative.dev/v1alpha1 +apiVersion: channels.knative.dev/v1alpha1 kind: Channel metadata: name: square @@ -42,7 +42,7 @@ spec: bus: stub --- -apiVersion: channels.eventing.knative.dev/v1alpha1 +apiVersion: channels.knative.dev/v1alpha1 kind: Subscription metadata: name: square From 41887ee3fd873b360e488baf8bc1ed97174cd76a Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Fri, 8 Jun 2018 13:53:22 -0400 Subject: [PATCH 20/21] Create a single sample that subscribes an Knative serivce to a channel --- sample/hello/Dockerfile | 3 -- sample/hello/README.md | 80 ++++++++++++++++++++++++++++++--- sample/hello/app.js | 25 ----------- sample/hello/build.sh | 4 -- sample/hello/hello-channel.yaml | 2 +- sample/hello/hello-istio.yaml | 40 ----------------- sample/hello/hello-service.yaml | 35 +++++++++++++++ sample/hello/hello.yaml | 50 --------------------- sample/square/Dockerfile | 3 -- sample/square/README.md | 19 -------- sample/square/build.sh | 4 -- sample/square/square.js | 5 --- sample/square/square.yaml | 51 --------------------- 13 files changed, 109 insertions(+), 212 deletions(-) delete mode 100644 sample/hello/Dockerfile delete mode 100644 sample/hello/app.js delete mode 100755 sample/hello/build.sh delete mode 100644 sample/hello/hello-istio.yaml create mode 100644 sample/hello/hello-service.yaml delete mode 100644 sample/hello/hello.yaml delete mode 100644 sample/square/Dockerfile delete mode 100644 sample/square/README.md delete mode 100755 sample/square/build.sh delete mode 100644 sample/square/square.js delete mode 100644 sample/square/square.yaml diff --git a/sample/hello/Dockerfile b/sample/hello/Dockerfile deleted file mode 100644 index 5012d64d564..00000000000 --- a/sample/hello/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM node:8 -ADD app.js /app.js -CMD node app.js diff --git a/sample/hello/README.md b/sample/hello/README.md index 31caeb2d752..56515b1b695 100644 --- a/sample/hello/README.md +++ b/sample/hello/README.md @@ -1,19 +1,85 @@ -# Build +The hello sample includes a Knative Service, Channel and Subscription. +# Deploy + +First, install the Stub bus, if not already installed: + +``` +ko apply -f config/buses/stub.yaml +``` + +Then, install the Buildpack build template if not already installed: + +```shell +kubectl apply -f https://github.com/knative/build-templates/raw/master/buildpack/buildpack.yaml ``` -./build.sh + +Then, deploy the hello function, channel and subscription: + +```shell +# Replace the token string with a suitable registry +REPO="gcr.io/" +perl -pi -e "s@DOCKER_REPO_OVERRIDE@$REPO@g" sample/hello/hello-service.yaml + +kubectl apply -f sample/hello/ ``` -# Install +The service will build and deploy the function and expose an ingress for the function and channel. It may take a minute, but eventually you should see something similar to: ``` -kubectl apply -f hello.yaml +$ watch -n1 kubectl get ing +NAME HOSTS ADDRESS PORTS +aloha-channel aloha 1.2.3.4 80 +hello-ingress hello.default.demo-domain.com,*.hello.default.demo-domain.com 1.2.3.4 80 ``` # Invoke +The hello function is reachable either directly via the route created by the hello service, or by the aloha channel. + +We can use kail to watch the log output for the function. In a separte shell run: + +``` +kail -d hello-00001-deployment ``` -export INGRESS_HOST=$(minikube ip) -export INGRESS_PORT=$(kubectl get svc istio-ingress -n istio-system -o jsonpath='{.spec.ports[0].nodePort}') -curl -X POST -H "Host: hello" $INGRESS_HOST:$INGRESS_PORT + +To invoke the function directly: + ``` +# Put the Ingress Host name into an environment variable. +$ export SERVICE_HOST=`kubectl get route hello -o jsonpath="{.status.domain}"` + +# Put the Ingress IP into an environment variable. +$ export SERVICE_IP=`kubectl get ingress hello-ingress -o jsonpath="{.status.loadBalancer.ingress[*]['ip']}"` + +# Curl the Ingress IP "as-if" DNS were properly configured. +$ curl -H "Host: $SERVICE_HOST" -H "Content-Type: text/plain" $SERVICE_IP -d "Knative" +[response] +``` + +You should see a response like: + +> hello knative from hello-00001-deployment-5fb4b845fd-7h2lc + +Unlike with direct access, when invoking over the channel, the caller will not recieve a response directly. + +We can use kail to watch the log output from the bus. In a separte shell run: + +``` +kail -d stub-bus -c dispatcher +``` + +To invoke the function via the channel: + +``` +# Put the Ingress Host name into an environment variable. +$ export SERVICE_HOST=`kubectl get ingress aloha-channel -o jsonpath="{.spec.rules[0].host}"` + +# Put the Ingress IP into an environment variable. +$ export SERVICE_IP=`kubectl get ingress aloha-channel -o jsonpath="{.status.loadBalancer.ingress[*]['ip']}"` + +# Curl the Ingress IP "as-if" DNS were properly configured. +$ curl -H "Host: $SERVICE_HOST" -H "Content-Type: text/plain" $SERVICE_IP -d "Knative" +``` + +This time there should be no response via curl, but you should see logging from the bus and the function indicating it received the request. diff --git a/sample/hello/app.js b/sample/hello/app.js deleted file mode 100644 index b625d64b0d6..00000000000 --- a/sample/hello/app.js +++ /dev/null @@ -1,25 +0,0 @@ -const http = require('http'); -const os = require('os'); - -console.log("server starting..."); - -var handler = function(request, response) { - if (request.method !== 'POST') { - response.writeHead(405); - response.end(); - return; - } - if (request.url !== '/') { - response.writeHead(404); - response.end(); - return; - } - const hostname = os.hostname(); - console.log(`received request to ${hostname} from ${request.connection.remoteAddress}`); - response.writeHead(200); - response.end(`hello from ${hostname}\n`); -}; - -var www = http.createServer(handler); -www.listen(8080); - diff --git a/sample/hello/build.sh b/sample/hello/build.sh deleted file mode 100755 index a71457c5719..00000000000 --- a/sample/hello/build.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -docker build . -t spike/hello:0.0.1 - diff --git a/sample/hello/hello-channel.yaml b/sample/hello/hello-channel.yaml index 7f17626a615..482f12da2de 100644 --- a/sample/hello/hello-channel.yaml +++ b/sample/hello/hello-channel.yaml @@ -12,4 +12,4 @@ metadata: name: aloha2hello spec: channel: aloha - subscriber: hello + subscriber: hello-00001-service diff --git a/sample/hello/hello-istio.yaml b/sample/hello/hello-istio.yaml deleted file mode 100644 index 59c6b405e42..00000000000 --- a/sample/hello/hello-istio.yaml +++ /dev/null @@ -1,40 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Ingress -metadata: - name: hola - annotations: - kubernetes.io/ingress.class: "istio" -spec: - rules: - - host: hola - http: - paths: - - backend: - serviceName: aloha - servicePort: http - ---- -apiVersion: v1 -kind: Service -metadata: - name: aloha -spec: - type: ClusterIP - ports: - - name: http - port: 80 - protocol: TCP - targetPort: 80 - ---- -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: aloha2hello -spec: - destination: - name: aloha - route: - - destination: - name: hello - weight: 100 diff --git a/sample/hello/hello-service.yaml b/sample/hello/hello-service.yaml new file mode 100644 index 00000000000..8f09a605638 --- /dev/null +++ b/sample/hello/hello-service.yaml @@ -0,0 +1,35 @@ +apiVersion: serving.knative.dev/v1alpha1 +kind: Service +metadata: + name: hello +spec: + runLatest: + configuration: + build: + source: + git: + url: https://github.com/projectriff-samples/node-hello + branch: master + template: + name: buildpack + arguments: + - name: IMAGE + value: &image DOCKER_REPO_OVERRIDE/hello + - name: BUILDPACK_ORDER + value: https://github.com/projectriff/node-function-invoker.git#buildpack + - name: SKIP_DETECT + value: "true" + # - name: CACHE + # value: buildpack-function-cache + # volumes: + # - name: buildpack-function-cache + # persistentVolumeClaim: + # claimName: buildpack-function-cache + + revisionTemplate: + metadata: + labels: + knative.dev/type: function + spec: + container: + image: *image diff --git a/sample/hello/hello.yaml b/sample/hello/hello.yaml deleted file mode 100644 index 872e8be70bf..00000000000 --- a/sample/hello/hello.yaml +++ /dev/null @@ -1,50 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: hello - labels: - app: hello -spec: - replicas: 3 - template: - metadata: - name: hello - labels: - app: hello - spec: - containers: - - image: spike/hello:0.0.1 - name: main - ports: - - containerPort: 8080 - protocol: TCP - ---- -apiVersion: v1 -kind: Service -metadata: - name: hello -spec: - type: NodePort - ports: - - name: http - port: 80 - targetPort: 8080 - selector: - app: hello - ---- -apiVersion: extensions/v1beta1 -kind: Ingress -metadata: - name: hello - annotations: - kubernetes.io/ingress.class: "istio" -spec: - rules: - - host: hello - http: - paths: - - backend: - serviceName: hello - servicePort: http diff --git a/sample/square/Dockerfile b/sample/square/Dockerfile deleted file mode 100644 index 6b00a8fee28..00000000000 --- a/sample/square/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM projectriff/node-function-invoker:0.0.8 -ENV FUNCTION_URI /functions/square.js -ADD square.js ${FUNCTION_URI} diff --git a/sample/square/README.md b/sample/square/README.md deleted file mode 100644 index 31e6b4b159f..00000000000 --- a/sample/square/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Build - -``` -./build.sh -``` - -# Install - -``` -kubectl apply -f square.yaml -``` - -# Invoke - -``` -export INGRESS_HOST=$(minikube ip) -export INGRESS_PORT=$(kubectl get svc istio-ingress -n istio-system -o jsonpath='{.spec.ports[0].nodePort}') -curl -H "Host: square" -H "Content-Type: application/json" $INGRESS_HOST:$INGRESS_PORT -d "33" -``` diff --git a/sample/square/build.sh b/sample/square/build.sh deleted file mode 100755 index 040bc7c00c2..00000000000 --- a/sample/square/build.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -docker build . -t spike/square:0.0.1 - diff --git a/sample/square/square.js b/sample/square/square.js deleted file mode 100644 index e6dc9e17a89..00000000000 --- a/sample/square/square.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = x => { - const sq = x ** 2 - console.log(`${x} squared is ${sq}`) - return sq -} diff --git a/sample/square/square.yaml b/sample/square/square.yaml deleted file mode 100644 index b96784127a2..00000000000 --- a/sample/square/square.yaml +++ /dev/null @@ -1,51 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: square - labels: - app: square -spec: - replicas: 1 - template: - metadata: - name: square - labels: - app: square - spec: - containers: - - image: spike/square:0.0.1 - name: main - ports: - - containerPort: 8080 - protocol: TCP - ---- -apiVersion: v1 -kind: Service -metadata: - name: square -spec: - type: NodePort - ports: - - name: http - port: 80 - targetPort: 8080 - selector: - app: square - ---- -apiVersion: channels.knative.dev/v1alpha1 -kind: Channel -metadata: - name: square -spec: - bus: stub - ---- -apiVersion: channels.knative.dev/v1alpha1 -kind: Subscription -metadata: - name: square -spec: - channel: square - subscriber: square From 0695c254d9d6a5c1fc199144547f03fc9b76a3ce Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Fri, 8 Jun 2018 14:08:44 -0400 Subject: [PATCH 21/21] polish --- pkg/apis/channels/v1alpha1/channel_types.go | 8 ++++---- pkg/apis/channels/v1alpha1/subscription_types.go | 8 ++++---- pkg/controller/bus/controller.go | 5 ++++- pkg/subscription/monitor.go | 3 +++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pkg/apis/channels/v1alpha1/channel_types.go b/pkg/apis/channels/v1alpha1/channel_types.go index 759c1c86a42..85d0d8adabe 100644 --- a/pkg/apis/channels/v1alpha1/channel_types.go +++ b/pkg/apis/channels/v1alpha1/channel_types.go @@ -25,7 +25,7 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the channels.channels.knative.dev CRD +// Channel represents the channels.channels.knative.dev CRD type Channel struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` @@ -33,7 +33,7 @@ type Channel struct { Status *ChannelStatus `json:"status,omitempty"` } -// Spec (what the user wants) for a channel +// ChannelSpec (what the user wants) for a channel type ChannelSpec struct { // Name of the bus backing this channel (optional) @@ -46,13 +46,13 @@ type ChannelSpec struct { Parameters *[]Parameter `json:"parameters,omitempty"` } -// Status (computed) for a channel +// ChannelStatus (computed) for a channel type ChannelStatus struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// Returned in list operations +// ChannelList returned in list operations type ChannelList struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ListMeta `json:"metadata"` diff --git a/pkg/apis/channels/v1alpha1/subscription_types.go b/pkg/apis/channels/v1alpha1/subscription_types.go index a591f98fca1..19ea529978b 100644 --- a/pkg/apis/channels/v1alpha1/subscription_types.go +++ b/pkg/apis/channels/v1alpha1/subscription_types.go @@ -25,7 +25,7 @@ import ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:defaulter-gen=true -// Represents the subscriptions.channels.knative.dev CRD +// Subscription represents the subscriptions.channels.knative.dev CRD type Subscription struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ObjectMeta `json:"metadata"` @@ -33,7 +33,7 @@ type Subscription struct { Status *SubscriptionStatus `json:"status,omitempty"` } -// Spec (what the user wants) for a subscription +// SubscriptionSpec (what the user wants) for a subscription type SubscriptionSpec struct { // Name of the channel to subscribe to @@ -46,13 +46,13 @@ type SubscriptionSpec struct { Arguments *[]Argument `json:"arguments,omitempty"` } -// Status (computed) for a subscription +// SubscriptionStatus (computed) for a subscription type SubscriptionStatus struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// Returned in list operations +// SubscriptionList returned in list operations type SubscriptionList struct { meta_v1.TypeMeta `json:",inline"` meta_v1.ListMeta `json:"metadata"` diff --git a/pkg/controller/bus/controller.go b/pkg/controller/bus/controller.go index 30191ae7fab..823d969f1e3 100644 --- a/pkg/controller/bus/controller.go +++ b/pkg/controller/bus/controller.go @@ -320,7 +320,10 @@ func (c *Controller) syncHandler(key string) error { // Finally, we update the status block of the Bus resource to reflect the // current state of the world - return c.updateBusStatus(bus, dispatcherService, dispatcherDeployment, provisionerDeployment, serviceAccount, clusterRoleBinding) + err = c.updateBusStatus(bus, dispatcherService, dispatcherDeployment, provisionerDeployment, serviceAccount, clusterRoleBinding) + if err != nil { + return err + } c.recorder.Event(bus, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) return nil diff --git a/pkg/subscription/monitor.go b/pkg/subscription/monitor.go index 48600cba6af..ff41aea1ab0 100644 --- a/pkg/subscription/monitor.go +++ b/pkg/subscription/monitor.go @@ -26,6 +26,7 @@ import ( "k8s.io/client-go/tools/cache" ) +// Monitor utility to manage channels and subscriptions for a bus type Monitor struct { busName string handler MonitorEventHandlerFuncs @@ -35,6 +36,7 @@ type Monitor struct { mutex *sync.Mutex } +// MonitorEventHandlerFuncs handler functions for channel and subscription provisioning type MonitorEventHandlerFuncs struct { ProvisionFunc func(channel channelsv1alpha1.Channel) UnprovisionFunc func(channel channelsv1alpha1.Channel) @@ -51,6 +53,7 @@ type subscriptionSummary struct { Subscription channelsv1alpha1.SubscriptionSpec } +// NewMonitor creates a monitor for a bus func NewMonitor(busName string, informerFactory informers.SharedInformerFactory, handler MonitorEventHandlerFuncs) *Monitor { busInformer := informerFactory.Channels().V1alpha1().Buses()