diff --git a/Gopkg.lock b/Gopkg.lock index 672fb0528ec..51ea05cf3a3 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1043,6 +1043,7 @@ "github.com/google/go-github/github", "github.com/google/uuid", "github.com/knative/pkg/apis", + "github.com/knative/pkg/apis/duck", "github.com/knative/pkg/apis/duck/v1alpha1", "github.com/knative/pkg/apis/istio/v1alpha3", "github.com/knative/pkg/client/clientset/versioned", diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index c915c39f407..8f8bd1bf49d 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -91,7 +91,9 @@ func main() { Options: options, Handlers: map[schema.GroupVersionKind]runtime.Object{ // For group eventing.knative.dev, + eventingv1alpha1.SchemeGroupVersion.WithKind("Channel"): &eventingv1alpha1.Channel{}, eventingv1alpha1.SchemeGroupVersion.WithKind("ClusterProvisioner"): &eventingv1alpha1.ClusterProvisioner{}, + eventingv1alpha1.SchemeGroupVersion.WithKind("Subscription"): &eventingv1alpha1.Subscription{}, // For group channels.knative.dev, channelsv1alpha1.SchemeGroupVersion.WithKind("Bus"): &channelsv1alpha1.Bus{}, diff --git a/config/300-channeleventing.yaml b/config/300-channeleventing.yaml new file mode 100644 index 00000000000..add65209481 --- /dev/null +++ b/config/300-channeleventing.yaml @@ -0,0 +1,31 @@ +# Copyright 2018 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: channels.eventing.knative.dev +spec: + group: eventing.knative.dev + version: v1alpha1 + names: + kind: Channel + plural: channels + singular: channel + categories: + - all + - knative + - eventing + shortNames: + - chan + scope: Namespaced diff --git a/pkg/apis/eventing/v1alpha1/channel_defaults.go b/pkg/apis/eventing/v1alpha1/channel_defaults.go new file mode 100644 index 00000000000..a95fb228dec --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_defaults.go @@ -0,0 +1,26 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +//TODO replace this with openapi defaults when +// https://github.com/kubernetes/features/issues/575 lands (scheduled for 1.13) +func (c *Channel) SetDefaults() { + c.Spec.SetDefaults() +} + +func (fs *ChannelSpec) SetDefaults() { +} diff --git a/pkg/apis/eventing/v1alpha1/channel_defaults_test.go b/pkg/apis/eventing/v1alpha1/channel_defaults_test.go new file mode 100644 index 00000000000..d6cb6abd80b --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_defaults_test.go @@ -0,0 +1,25 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import "testing" + +// No-op test because method does nothing. +func TestChannelSetDefaults(t *testing.T) { + c := Channel{} + c.SetDefaults() +} diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go new file mode 100644 index 00000000000..4073e6b277c --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -0,0 +1,169 @@ +/* + * Copyright 2018 The Knative Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v1alpha1 + +import ( + "encoding/json" + + "github.com/knative/pkg/apis" + "github.com/knative/pkg/apis/duck" + duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" + "github.com/knative/pkg/webhook" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Channel is an abstract resource that implements the Subscribable and Sinkable +// contracts. The Provisioner provisions infrastructure to accepts events and +// deliver to Subscriptions. +type Channel struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec defines the desired state of the Channel. + Spec ChannelSpec `json:"spec,omitempty"` + + // Status represents the current state of the Channel. This data may be out of + // date. + // +optional + Status ChannelStatus `json:"status,omitempty"` +} + +// Check that Channel can be validated, can be defaulted, and has immutable fields. +var _ apis.Validatable = (*Channel)(nil) +var _ apis.Defaultable = (*Channel)(nil) +var _ apis.Immutable = (*Channel)(nil) +var _ runtime.Object = (*Channel)(nil) +var _ webhook.GenericCRD = (*Channel)(nil) + +// Check that ConfigurationStatus may have its conditions managed. +var _ duckv1alpha1.ConditionsAccessor = (*ChannelStatus)(nil) + +// Check that Channel implements the Conditions duck type. +var _ = duck.VerifyType(&Channel{}, &duckv1alpha1.Conditions{}) + +// ChannelSpec specifies the Provisioner backing a channel and the configuration +// arguments for a Channel. +type ChannelSpec struct { + // TODO: Generation does not work correctly with CRD. They are scrubbed + // by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778) + // So, we add Generation here. Once that gets fixed, remove this and use + // ObjectMeta.Generation instead. + // +optional + Generation int64 `json:"generation,omitempty"` + + // Provisioner defines the name of the Provisioner backing this channel. + // TODO: +optional If missing, a default Provisioner may be selected for the Channel. + Provisioner *ProvisionerReference `json:"provisioner,omitempty"` + + // Arguments defines the arguments to pass to the Provisioner which provisions + // this Channel. + // +optional + Arguments *runtime.RawExtension `json:"arguments,omitempty"` + + // Subscribers is a list of the Subscribers to this channel. This is filled in + // by the Subscriptions controller. Users should not mutate this field. + Subscribers []ChannelSubscriberSpec `json:"subscribers,omitempty"` +} + +// ChannelSubscriberSpec defines a single subscriber to a Channel. At least one +// of Call or Result must be present. +type ChannelSubscriberSpec struct { + // Call is an optional reference to a function for processing events. + // Events from the From channel will be delivered here and replies + // are optionally handled by Result. + // +optional + Call *Callable `json:"call,omitempty"` + + // Result optionally specifies how to handle events received from the Call + // target. + // +optional + Result *ResultStrategy `json:"result,omitempty"` +} + +var chanCondSet = duckv1alpha1.NewLivingConditionSet(ChannelConditionProvisioned) + +// ChannelStatus represents the current state of a Channel. +type ChannelStatus struct { + // ObservedGeneration is the most recent generation observed for this Channel. + // It corresponds to the Channel's generation, which is updated on mutation by + // the API Server. + // TODO: The above comment is only true once + // https://github.com/kubernetes/kubernetes/issues/58778 is fixed. + // +optional + ObservedGeneration int64 `json:"observedGeneration,omitempty"` + + // DomainInternal holds the top-level domain that will distribute traffic + // over the provided targets from inside the cluster. It generally has the + // form {channel}.{namespace}.svc.cluster.local + // TODO: move this to a struct that can be embedded similar to ObjectMeta and + // TypeMeta. + // +optional + DomainInternal string `json:"domainInternal,omitempty"` + + // Represents the latest available observations of a channel's current state. + // +optional + // +patchMergeKey=type + // +patchStrategy=merge + Conditions duckv1alpha1.Conditions `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` +} + +const ( + // ChannelConditionReady has status True when the Channel is ready to accept + // traffic. + ChannelConditionReady = duckv1alpha1.ConditionReady + + // ChannelConditionProvisioned has status True when the Channel's backing + // resources have been provisioned. + ChannelConditionProvisioned duckv1alpha1.ConditionType = "Provisioned" +) + +func (c *Channel) GetSpecJSON() ([]byte, error) { + return json.Marshal(c.Spec) +} + +// GetCondition returns the condition currently associated with the given type, or nil. +func (cs *ChannelStatus) GetCondition(t duckv1alpha1.ConditionType) *duckv1alpha1.Condition { + return chanCondSet.Manage(cs).GetCondition(t) +} + +// GetConditions returns the Conditions array. This enables generic handling of +// conditions by implementing the duckv1alpha1.Conditions interface. +func (cs *ChannelStatus) GetConditions() duckv1alpha1.Conditions { + return cs.Conditions +} + +// SetConditions sets the Conditions array. This enables generic handling of +// conditions by implementing the duckv1alpha1.Conditions interface. +func (cs *ChannelStatus) SetConditions(conditions duckv1alpha1.Conditions) { + cs.Conditions = conditions +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ChannelList is a collection of Channels. +type ChannelList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + Items []Channel `json:"items"` +} diff --git a/pkg/apis/eventing/v1alpha1/channel_types_test.go b/pkg/apis/eventing/v1alpha1/channel_types_test.go new file mode 100644 index 00000000000..d177a8f5599 --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_types_test.go @@ -0,0 +1,120 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + "testing" + + "github.com/google/go-cmp/cmp" + duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +var condReady = duckv1alpha1.Condition{ + Type: ChannelConditionReady, + Status: corev1.ConditionTrue, +} + +var condUnprovisioned = duckv1alpha1.Condition{ + Type: ChannelConditionProvisioned, + Status: corev1.ConditionFalse, +} + +func TestChannelGetCondition(t *testing.T) { + tests := []struct { + name string + cs *ChannelStatus + condQuery duckv1alpha1.ConditionType + want *duckv1alpha1.Condition + }{{ + name: "single condition", + cs: &ChannelStatus{ + Conditions: []duckv1alpha1.Condition{ + condReady, + }, + }, + condQuery: duckv1alpha1.ConditionReady, + want: &condReady, + }, { + name: "multiple conditions", + cs: &ChannelStatus{ + Conditions: []duckv1alpha1.Condition{ + condReady, + condUnprovisioned, + }, + }, + condQuery: ChannelConditionProvisioned, + want: &condUnprovisioned, + }, { + name: "unknown condition", + cs: &ChannelStatus{ + Conditions: []duckv1alpha1.Condition{ + condReady, + condUnprovisioned, + }, + }, + condQuery: duckv1alpha1.ConditionType("foo"), + want: nil, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.cs.GetCondition(test.condQuery) + if diff := cmp.Diff(test.want, got); diff != "" { + t.Errorf("unexpected condition (-want, +got) = %v", diff) + } + }) + } +} + +func TestChannelSetConditions(t *testing.T) { + c := &Channel{ + Status: ChannelStatus{}, + } + want := duckv1alpha1.Conditions{condReady} + c.Status.SetConditions(want) + got := c.Status.GetConditions() + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("unexpected conditions (-want, +got) = %v", diff) + } +} + +func TestChannelGetSpecJSON(t *testing.T) { + c := &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + Arguments: &runtime.RawExtension{ + Raw: []byte(`{"foo":"baz"}`), + }, + }, + } + + want := `{"provisioner":{"ref":{"name":"foo"}},"arguments":{"foo":"baz"}}` + got, err := c.GetSpecJSON() + if err != nil { + t.Fatalf("unexpected spec JSON error: %v", err) + } + + if diff := cmp.Diff(want, string(got)); diff != "" { + t.Errorf("unexpected spec JSON (-want, +got) = %v", diff) + } +} diff --git a/pkg/apis/eventing/v1alpha1/channel_validation.go b/pkg/apis/eventing/v1alpha1/channel_validation.go new file mode 100644 index 00000000000..ae6de32aa9a --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_validation.go @@ -0,0 +1,64 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + "fmt" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/knative/pkg/apis" +) + +func (c *Channel) Validate() *apis.FieldError { + return c.Spec.Validate().ViaField("spec") +} + +func (cs *ChannelSpec) Validate() *apis.FieldError { + if cs.Provisioner == nil { + return apis.ErrMissingField("provisioner") + } + + for i, subscriber := range cs.Subscribers { + if subscriber.Call == nil && subscriber.Result == nil { + //TODO collect all errors instead of returning the first. This isn't + // possible yet with knative/pkg validation. + return apis.ErrMissingField("call", "result").ViaField(fmt.Sprintf("subscriber[%d]", i)) + } + } + + return nil +} + +func (current *Channel) CheckImmutableFields(og apis.Immutable) *apis.FieldError { + if og == nil { + return nil + } + + original, ok := og.(*Channel) + if !ok { + return &apis.FieldError{Message: "The provided resource was not a Channel"} + } + ignoreArguments := cmpopts.IgnoreFields(ChannelSpec{}, "Arguments") + if diff := cmp.Diff(original.Spec, current.Spec, ignoreArguments); diff != "" { + return &apis.FieldError{ + Message: "Immutable fields changed", + Paths: []string{"spec.provisioner"}, + } + } + return nil +} diff --git a/pkg/apis/eventing/v1alpha1/channel_validation_test.go b/pkg/apis/eventing/v1alpha1/channel_validation_test.go new file mode 100644 index 00000000000..de46664d5eb --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_validation_test.go @@ -0,0 +1,237 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/knative/pkg/apis" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +var targetURI = "https://example.com" + +func TestChannelValidation(t *testing.T) { + tests := []struct { + name string + c *Channel + want *apis.FieldError + }{{ + name: "valid", + c: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + }, + }, + want: nil, + }, { + name: "empty", + c: &Channel{ + Spec: ChannelSpec{}, + }, + want: apis.ErrMissingField("spec.provisioner"), + }, { + name: "subscribers array", + c: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + Subscribers: []ChannelSubscriberSpec{{ + Call: &Callable{ + TargetURI: &targetURI, + }, + }, { + Result: &ResultStrategy{ + Target: &corev1.ObjectReference{ + APIVersion: "eventing.knative.dev/v1alpha1", + Kind: "Channel", + Name: "to-chan", + }, + }, + }, { + Call: &Callable{ + TargetURI: &targetURI, + }, + Result: &ResultStrategy{ + Target: &corev1.ObjectReference{ + APIVersion: "eventing.knative.dev/v1alpha1", + Kind: "Channel", + Name: "to-chan", + }, + }, + }}, + }, + }, + want: nil, + }, { + name: "empty subscriber", + c: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + Subscribers: []ChannelSubscriberSpec{ + { + Call: &Callable{ + TargetURI: &targetURI, + }, + }, + {}, + }, + }, + }, + want: apis.ErrMissingField("spec.subscriber[1].call", "spec.subscriber[1].result"), + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.c.Validate() + if diff := cmp.Diff(test.want, got); diff != "" { + t.Errorf("validateChannel (-want, +got) = %v", diff) + } + }) + } +} + +func TestChannelImmutableFields(t *testing.T) { + tests := []struct { + name string + new apis.Immutable + old apis.Immutable + want *apis.FieldError + }{{ + name: "good (new)", + new: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + }, + }, + old: nil, + want: nil, + }, { + name: "good (no change)", + new: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + }, + }, + old: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + }, + }, + want: nil, + }, { + name: "good (arguments change)", + new: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + Arguments: &runtime.RawExtension{ + Raw: []byte("\"foo\":\"bar\""), + }, + }, + }, + old: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + Arguments: &runtime.RawExtension{ + Raw: []byte(`{"foo":"baz"}`), + }, + }, + }, + want: nil, + }, { + name: "bad (not channel)", + new: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + }, + }, + old: &Subscription{}, + want: &apis.FieldError{ + Message: "The provided resource was not a Channel", + }, + }, { + name: "bad (provisioner changes)", + new: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "foo", + }, + }, + }, + }, + old: &Channel{ + Spec: ChannelSpec{ + Provisioner: &ProvisionerReference{ + Ref: &corev1.ObjectReference{ + Name: "bar", + }, + }, + }, + }, + want: &apis.FieldError{ + Message: "Immutable fields changed", + Paths: []string{"spec.provisioner"}, + }, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.new.CheckImmutableFields(test.old) + if diff := cmp.Diff(test.want, got); diff != "" { + t.Errorf("Validate (-want, +got) = %v", diff) + } + }) + } +} diff --git a/pkg/apis/eventing/v1alpha1/provisioner_reference.go b/pkg/apis/eventing/v1alpha1/provisioner_reference.go new file mode 100644 index 00000000000..1d0bbca4cbe --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/provisioner_reference.go @@ -0,0 +1,29 @@ +/* + * Copyright 2018 The Knative Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v1alpha1 + +import ( + corev1 "k8s.io/api/core/v1" +) + +// ProvisionerReference defines the strategy for selecting a Provisioner for a +// provisioned resource. Shared by Channel and Source. +type ProvisionerReference struct { + // A reference to a specific Provisioner. + //TODO: +optional add selector + Ref *corev1.ObjectReference `json:"ref,omitempty"` +} diff --git a/pkg/apis/eventing/v1alpha1/register.go b/pkg/apis/eventing/v1alpha1/register.go index 3a438dd34a2..e3fb19db05d 100644 --- a/pkg/apis/eventing/v1alpha1/register.go +++ b/pkg/apis/eventing/v1alpha1/register.go @@ -45,6 +45,8 @@ var ( // Adds the list of known types to Scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, + &Channel{}, + &ChannelList{}, &ClusterProvisioner{}, &ClusterProvisionerList{}, &Subscription{}, diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index cd93dc8c5c4..ce044896091 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -60,6 +60,165 @@ func (in *Callable) DeepCopy() *Callable { 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) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + 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 + if in.Provisioner != nil { + in, out := &in.Provisioner, &out.Provisioner + if *in == nil { + *out = nil + } else { + *out = new(ProvisionerReference) + (*in).DeepCopyInto(*out) + } + } + if in.Arguments != nil { + in, out := &in.Arguments, &out.Arguments + if *in == nil { + *out = nil + } else { + *out = new(runtime.RawExtension) + (*in).DeepCopyInto(*out) + } + } + if in.Subscribers != nil { + in, out := &in.Subscribers, &out.Subscribers + *out = make([]ChannelSubscriberSpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + 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 + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make(duck_v1alpha1.Conditions, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + 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 *ChannelSubscriberSpec) DeepCopyInto(out *ChannelSubscriberSpec) { + *out = *in + if in.Call != nil { + in, out := &in.Call, &out.Call + if *in == nil { + *out = nil + } else { + *out = new(Callable) + (*in).DeepCopyInto(*out) + } + } + if in.Result != nil { + in, out := &in.Result, &out.Result + if *in == nil { + *out = nil + } else { + *out = new(ResultStrategy) + (*in).DeepCopyInto(*out) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelSubscriberSpec. +func (in *ChannelSubscriberSpec) DeepCopy() *ChannelSubscriberSpec { + if in == nil { + return nil + } + out := new(ChannelSubscriberSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterProvisioner) DeepCopyInto(out *ClusterProvisioner) { *out = *in @@ -161,6 +320,31 @@ func (in *ClusterProvisionerStatus) DeepCopy() *ClusterProvisionerStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ProvisionerReference) DeepCopyInto(out *ProvisionerReference) { + *out = *in + if in.Ref != nil { + in, out := &in.Ref, &out.Ref + if *in == nil { + *out = nil + } else { + *out = new(v1.ObjectReference) + **out = **in + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProvisionerReference. +func (in *ProvisionerReference) DeepCopy() *ProvisionerReference { + if in == nil { + return nil + } + out := new(ProvisionerReference) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResultStrategy) DeepCopyInto(out *ResultStrategy) { *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..71b1fe9cbf5 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/channel.go @@ -0,0 +1,157 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by 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 4dbc6cbf06c..3d84eebe8e4 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/eventing_client.go @@ -27,6 +27,7 @@ import ( type EventingV1alpha1Interface interface { RESTClient() rest.Interface + ChannelsGetter ClusterProvisionersGetter SubscriptionsGetter } @@ -36,6 +37,10 @@ type EventingV1alpha1Client struct { restClient rest.Interface } +func (c *EventingV1alpha1Client) Channels(namespace string) ChannelInterface { + return newChannels(c, namespace) +} + func (c *EventingV1alpha1Client) ClusterProvisioners() ClusterProvisionerInterface { return newClusterProvisioners(c) } 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..ef79d296a1e --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go @@ -0,0 +1,128 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by 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{ListMeta: obj.(*v1alpha1.ChannelList).ListMeta} + 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 d75e7ec71b1..0127acc10fb 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 @@ -28,6 +28,10 @@ type FakeEventingV1alpha1 struct { *testing.Fake } +func (c *FakeEventingV1alpha1) Channels(namespace string) v1alpha1.ChannelInterface { + return &FakeChannels{c, namespace} +} + func (c *FakeEventingV1alpha1) ClusterProvisioners() v1alpha1.ClusterProvisionerInterface { return &FakeClusterProvisioners{c} } 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 628a8e9c464..2d119a1cc27 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go @@ -18,6 +18,8 @@ limitations under the License. package v1alpha1 +type ChannelExpansion interface{} + type ClusterProvisionerExpansion interface{} type SubscriptionExpansion interface{} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/channel.go b/pkg/client/informers/externalversions/eventing/v1alpha1/channel.go new file mode 100644 index 00000000000..addf0d48b9f --- /dev/null +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/channel.go @@ -0,0 +1,89 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by 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" +) + +// ChannelInformer provides access to a shared informer and lister for +// Channels. +type ChannelInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.ChannelLister +} + +type channelInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// 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 NewChannelInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredChannelInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// 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 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().Channels(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventingV1alpha1().Channels(namespace).Watch(options) + }, + }, + &eventing_v1alpha1.Channel{}, + resyncPeriod, + indexers, + ) +} + +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 *channelInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&eventing_v1alpha1.Channel{}, f.defaultInformer) +} + +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 0087c3e6b4f..1fd4c99c7dc 100644 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/interface.go @@ -24,6 +24,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // Channels returns a ChannelInformer. + Channels() ChannelInformer // ClusterProvisioners returns a ClusterProvisionerInformer. ClusterProvisioners() ClusterProvisionerInformer // Subscriptions returns a SubscriptionInformer. @@ -41,6 +43,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// Channels returns a ChannelInformer. +func (v *version) Channels() ChannelInformer { + return &channelInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // ClusterProvisioners returns a ClusterProvisionerInformer. func (v *version) ClusterProvisioners() ClusterProvisionerInformer { return &clusterProvisionerInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 4c274ac9e27..521a45e5029 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -66,6 +66,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Channels().V1alpha1().Subscriptions().Informer()}, nil // Group=eventing.knative.dev, Version=v1alpha1 + case eventing_v1alpha1.SchemeGroupVersion.WithResource("channels"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Channels().Informer()}, nil case eventing_v1alpha1.SchemeGroupVersion.WithResource("clusterprovisioners"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().ClusterProvisioners().Informer()}, nil case eventing_v1alpha1.SchemeGroupVersion.WithResource("subscriptions"): diff --git a/pkg/client/listers/eventing/v1alpha1/channel.go b/pkg/client/listers/eventing/v1alpha1/channel.go new file mode 100644 index 00000000000..1572b0d8408 --- /dev/null +++ b/pkg/client/listers/eventing/v1alpha1/channel.go @@ -0,0 +1,94 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by 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 386c9a930a7..abc32a5ee74 100644 --- a/pkg/client/listers/eventing/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/eventing/v1alpha1/expansion_generated.go @@ -18,6 +18,14 @@ limitations under the License. package v1alpha1 +// ChannelListerExpansion allows custom methods to be added to +// ChannelLister. +type ChannelListerExpansion interface{} + +// ChannelNamespaceListerExpansion allows custom methods to be added to +// ChannelNamespaceLister. +type ChannelNamespaceListerExpansion interface{} + // ClusterProvisionerListerExpansion allows custom methods to be added to // ClusterProvisionerLister. type ClusterProvisionerListerExpansion interface{}