From 8f075439463f8c19e20b776ab97b62836e70e347 Mon Sep 17 00:00:00 2001 From: Ville Aikas <11279988+vaikas@users.noreply.github.com> Date: Thu, 30 Jan 2020 07:26:27 -0800 Subject: [PATCH] Broker v1beta1 (#2449) * v1beta1 Broker type initial cut * first cut of broker that supports alternate impls not tied to messaging constructs * address pr comments * add validation * validate + test * brokerClassAnnotationKey -> BrokerClassAnnotationKey --- pkg/apis/duck/v1beta1/delivery_types.go | 29 +++ pkg/apis/duck/v1beta1/delivery_types_test.go | 64 +++++ pkg/apis/eventing/v1beta1/broker_defaults.go | 30 +++ pkg/apis/eventing/v1beta1/broker_types.go | 111 +++++++++ .../eventing/v1beta1/broker_validation.go | 98 ++++++++ .../v1beta1/broker_validation_test.go | 233 ++++++++++++++++++ pkg/apis/eventing/v1beta1/register.go | 2 + .../eventing/v1beta1/zz_generated.deepcopy.go | 107 ++++++++ .../typed/eventing/v1beta1/broker.go | 191 ++++++++++++++ .../typed/eventing/v1beta1/eventing_client.go | 5 + .../eventing/v1beta1/fake/fake_broker.go | 140 +++++++++++ .../v1beta1/fake/fake_eventing_client.go | 4 + .../eventing/v1beta1/generated_expansion.go | 2 + .../eventing/v1beta1/broker.go | 89 +++++++ .../eventing/v1beta1/interface.go | 7 + .../informers/externalversions/generic.go | 2 + .../eventing/v1beta1/broker/broker.go | 52 ++++ .../eventing/v1beta1/broker/fake/fake.go | 40 +++ pkg/client/listers/eventing/v1beta1/broker.go | 94 +++++++ .../eventing/v1beta1/expansion_generated.go | 8 + 20 files changed, 1308 insertions(+) create mode 100644 pkg/apis/duck/v1beta1/delivery_types_test.go create mode 100644 pkg/apis/eventing/v1beta1/broker_defaults.go create mode 100644 pkg/apis/eventing/v1beta1/broker_types.go create mode 100644 pkg/apis/eventing/v1beta1/broker_validation.go create mode 100644 pkg/apis/eventing/v1beta1/broker_validation_test.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1beta1/broker.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1beta1/fake/fake_broker.go create mode 100644 pkg/client/informers/externalversions/eventing/v1beta1/broker.go create mode 100644 pkg/client/injection/informers/eventing/v1beta1/broker/broker.go create mode 100644 pkg/client/injection/informers/eventing/v1beta1/broker/fake/fake.go create mode 100644 pkg/client/listers/eventing/v1beta1/broker.go diff --git a/pkg/apis/duck/v1beta1/delivery_types.go b/pkg/apis/duck/v1beta1/delivery_types.go index ed9103e9b1b..bbf28ecc854 100644 --- a/pkg/apis/duck/v1beta1/delivery_types.go +++ b/pkg/apis/duck/v1beta1/delivery_types.go @@ -17,7 +17,11 @@ limitations under the License. package v1beta1 import ( + "context" + "time" + corev1 "k8s.io/api/core/v1" + "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" ) @@ -47,6 +51,31 @@ type DeliverySpec struct { BackoffDelay *string `json:"backoffDelay,omitempty"` } +func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError { + if ds == nil { + return nil + } + var errs *apis.FieldError + if dlse := ds.DeadLetterSink.Validate(ctx); dlse != nil { + errs = errs.Also(dlse).ViaField("deadLetterSink") + } + if ds.BackoffPolicy != nil { + switch *ds.BackoffPolicy { + case BackoffPolicyExponential, BackoffPolicyLinear: + // nothing + default: + errs = errs.Also(apis.ErrInvalidValue(*ds.BackoffPolicy, "backoffPolicy")) + } + } + if ds.BackoffDelay != nil { + _, te := time.Parse(time.RFC3339, *ds.BackoffDelay) + if te != nil { + errs = errs.Also(apis.ErrInvalidValue(*ds.BackoffDelay, "backoffDelay")) + } + } + return errs +} + // BackoffPolicyType is the type for backoff policies type BackoffPolicyType string diff --git a/pkg/apis/duck/v1beta1/delivery_types_test.go b/pkg/apis/duck/v1beta1/delivery_types_test.go new file mode 100644 index 00000000000..e30f66ec981 --- /dev/null +++ b/pkg/apis/duck/v1beta1/delivery_types_test.go @@ -0,0 +1,64 @@ +/* +Copyright 2020 The Knative Authors. 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 v1beta1 + +import ( + "context" + "testing" + + "github.com/google/go-cmp/cmp" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +func TestDeliverySpecValidation(t *testing.T) { + invalidString := "invalid time" + bop := BackoffPolicyExponential + tests := []struct { + name string + spec *DeliverySpec + want *apis.FieldError + }{{ + name: "nil is valid", + spec: nil, + want: nil, + }, { + name: "invalid time format", + spec: &DeliverySpec{BackoffDelay: &invalidString}, + want: func() *apis.FieldError { + return apis.ErrInvalidValue(invalidString, "backoffDelay") + }(), + }, { + name: "invalid deadLetterSink", + spec: &DeliverySpec{DeadLetterSink: &duckv1.Destination{}}, + want: func() *apis.FieldError { + return apis.ErrGeneric("expected at least one, got none", "ref", "uri").ViaField("deadLetterSink") + }(), + }, { + name: "valid backoffPolicy", + spec: &DeliverySpec{BackoffPolicy: &bop}, + want: nil, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.spec.Validate(context.TODO()) + if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { + t.Errorf("DeliverySpec.Validate (-want, +got) = %v", diff) + } + }) + } +} diff --git a/pkg/apis/eventing/v1beta1/broker_defaults.go b/pkg/apis/eventing/v1beta1/broker_defaults.go new file mode 100644 index 00000000000..c06862fc0df --- /dev/null +++ b/pkg/apis/eventing/v1beta1/broker_defaults.go @@ -0,0 +1,30 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + "context" +) + +func (b *Broker) SetDefaults(ctx context.Context) { + // TODO(vaikas): Set the default class annotation if not specified + b.Spec.SetDefaults(ctx) +} + +func (bs *BrokerSpec) SetDefaults(ctx context.Context) { + // None +} diff --git a/pkg/apis/eventing/v1beta1/broker_types.go b/pkg/apis/eventing/v1beta1/broker_types.go new file mode 100644 index 00000000000..8fb140acf14 --- /dev/null +++ b/pkg/apis/eventing/v1beta1/broker_types.go @@ -0,0 +1,111 @@ +/* + * Copyright 2020 The Knative Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v1beta1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + + eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/pkg/kmeta" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Broker collects a pool of events that are consumable using Triggers. Brokers +// provide a well-known endpoint for event delivery that senders can use with +// minimal knowledge of the event routing strategy. Receivers use Triggers to +// request delivery of events from a Broker's pool to a specific URL or +// Addressable endpoint. +type Broker struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec defines the desired state of the Broker. + Spec BrokerSpec `json:"spec,omitempty"` + + // Status represents the current state of the Broker. This data may be out of + // date. + // +optional + Status BrokerStatus `json:"status,omitempty"` +} + +var ( + // Check that Broker can be validated, can be defaulted, and has immutable fields. + _ apis.Validatable = (*Broker)(nil) + _ apis.Defaultable = (*Broker)(nil) + + // Check that Broker can return its spec untyped. + _ apis.HasSpec = (*Broker)(nil) + + _ runtime.Object = (*Broker)(nil) + + // Check that we can create OwnerReferences to a Broker. + _ kmeta.OwnerRefable = (*Broker)(nil) +) + +type BrokerSpec struct { + // Config is an ObjectReference to the configuration that specifies + // configuration options for this Broker. For example, this could be + // a pointer to a ConfigMap. + // +optional + Config *corev1.ObjectReference `json:"config,omitempty"` + + // Delivery is the delivery specification for Events within the Broker mesh. + // This includes things like retries, DLQ, etc. + // +optional + Delivery *eventingduckv1beta1.DeliverySpec `json:"delivery,omitempty"` +} + +// BrokerStatus represents the current state of a Broker. +type BrokerStatus struct { + // inherits duck/v1 Status, which currently provides: + // * ObservedGeneration - the 'Generation' of the Service that was last processed by the controller. + // * Conditions - the latest available observations of a resource's current state. + duckv1.Status `json:",inline"` + + // Broker is Addressable. It exposes the endpoint as an URI to get events + // delivered into the Broker mesh. + Address duckv1.Addressable `json:"address,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// BrokerList is a collection of Brokers. +type BrokerList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []Broker `json:"items"` +} + +// GetGroupVersionKind returns GroupVersionKind for Brokers +func (t *Broker) GetGroupVersionKind() schema.GroupVersionKind { + return SchemeGroupVersion.WithKind("Broker") +} + +// GetUntypedSpec returns the spec of the Broker. +func (b *Broker) GetUntypedSpec() interface{} { + return b.Spec +} diff --git a/pkg/apis/eventing/v1beta1/broker_validation.go b/pkg/apis/eventing/v1beta1/broker_validation.go new file mode 100644 index 00000000000..89e99e508dc --- /dev/null +++ b/pkg/apis/eventing/v1beta1/broker_validation.go @@ -0,0 +1,98 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + "context" + + corev1 "k8s.io/api/core/v1" + "knative.dev/pkg/apis" + "knative.dev/pkg/kmp" +) + +const ( + BrokerClassAnnotationKey = "eventing.knative.dev/broker.class" +) + +func (b *Broker) Validate(ctx context.Context) *apis.FieldError { + return b.Spec.Validate(ctx).ViaField("spec") +} + +func (bs *BrokerSpec) Validate(ctx context.Context) *apis.FieldError { + var errs *apis.FieldError + + // Validate the Config + if bs.Config != nil { + if ce := isValidConfig(bs.Config); ce != nil { + errs = errs.Also(ce.ViaField("config")) + } + } + + if bs.Delivery != nil { + if de := bs.Delivery.Validate(ctx); de != nil { + errs = errs.Also(de.ViaField("delivery")) + } + } + return errs +} + +func isValidConfig(ref *corev1.ObjectReference) *apis.FieldError { + if ref == nil { + return nil + } + // Check the object. + var errs *apis.FieldError + if ref.Name == "" { + errs = errs.Also(apis.ErrMissingField("name")) + } + if ref.Namespace == "" { + errs = errs.Also(apis.ErrMissingField("namespace")) + } + if ref.APIVersion == "" { + errs = errs.Also(apis.ErrMissingField("apiVersion")) + } + if ref.Kind == "" { + errs = errs.Also(apis.ErrMissingField("kind")) + } + + return errs +} + +func (b *Broker) CheckImmutableFields(ctx context.Context, original *Broker) *apis.FieldError { + if original == nil { + return nil + } + + // Make sure you can't change the class annotation. + diff, err := kmp.ShortDiff(original.GetAnnotations()[BrokerClassAnnotationKey], b.GetAnnotations()[BrokerClassAnnotationKey]) + + if err != nil { + return &apis.FieldError{ + Message: "couldn't diff the Broker objects", + Details: err.Error(), + } + } + + if diff != "" { + return &apis.FieldError{ + Message: "Immutable fields changed (-old +new)", + Paths: []string{"annotations"}, + Details: diff, + } + } + return nil +} diff --git a/pkg/apis/eventing/v1beta1/broker_validation_test.go b/pkg/apis/eventing/v1beta1/broker_validation_test.go new file mode 100644 index 00000000000..021405ddeec --- /dev/null +++ b/pkg/apis/eventing/v1beta1/broker_validation_test.go @@ -0,0 +1,233 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + "context" + "testing" + + "github.com/google/go-cmp/cmp" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" + "knative.dev/pkg/apis" +) + +func TestBrokerImmutableFields(t *testing.T) { + original := &Broker{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{"eventing.knative.dev/broker.class": "original"}, + }, + } + current := &Broker{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{"eventing.knative.dev/broker.class": "current"}, + }, + } + + tests := map[string]struct { + og *Broker + wantErr *apis.FieldError + }{ + "nil original": { + wantErr: nil, + }, + "no ChannelTemplateSpec mutation": { + og: current, + wantErr: nil, + }, + "ChannelTemplateSpec mutated": { + og: original, + wantErr: &apis.FieldError{ + Message: "Immutable fields changed (-old +new)", + Paths: []string{"annotations"}, + Details: `{string}: + -: "original" + +: "current" +`, + }, + }, + } + + for n, test := range tests { + t.Run(n, func(t *testing.T) { + gotErr := current.CheckImmutableFields(context.Background(), test.og) + if diff := cmp.Diff(test.wantErr.Error(), gotErr.Error()); diff != "" { + t.Errorf("Broker.CheckImmutableFields (-want, +got) = %v", diff) + } + }) + } +} + +func TestValidate(t *testing.T) { + invalidString := "invalid time" + tests := []struct { + name string + b Broker + want *apis.FieldError + }{{ + name: "valid empty", + b: Broker{}, + want: nil, + }, { + name: "valid config", + b: Broker{ + Spec: BrokerSpec{ + Config: &corev1.ObjectReference{ + Namespace: "namespace", + Name: "name", + Kind: "kind", + APIVersion: "apiversion", + }, + }, + }, + want: nil, + }, { + name: "invalid config, missing namespace", + b: Broker{ + Spec: BrokerSpec{ + Config: &corev1.ObjectReference{ + Name: "name", + Kind: "kind", + APIVersion: "apiversion", + }, + }, + }, + want: func() *apis.FieldError { + var errs *apis.FieldError + fe := apis.ErrMissingField("spec.config.namespace") + errs = errs.Also(fe) + return errs + }(), + }, { + name: "invalid config, missing name", + b: Broker{ + Spec: BrokerSpec{ + Config: &corev1.ObjectReference{ + Namespace: "namespace", + Kind: "kind", + APIVersion: "apiversion", + }, + }, + }, + want: func() *apis.FieldError { + var errs *apis.FieldError + fe := apis.ErrMissingField("spec.config.name") + errs = errs.Also(fe) + return errs + }(), + }, { + name: "invalid config, missing apiVersion", + b: Broker{ + Spec: BrokerSpec{ + Config: &corev1.ObjectReference{ + Namespace: "namespace", + Name: "name", + Kind: "kind", + }, + }, + }, + want: func() *apis.FieldError { + var errs *apis.FieldError + fe := apis.ErrMissingField("spec.config.apiVersion") + errs = errs.Also(fe) + return errs + }(), + }, { + name: "invalid config, missing kind", + b: Broker{ + Spec: BrokerSpec{ + Config: &corev1.ObjectReference{ + Namespace: "namespace", + Name: "name", + APIVersion: "apiversion", + }, + }, + }, + want: func() *apis.FieldError { + var errs *apis.FieldError + fe := apis.ErrMissingField("spec.config.kind") + errs = errs.Also(fe) + return errs + }(), + }, { + name: "invalid delivery, invalid delay string", + b: Broker{ + Spec: BrokerSpec{ + Delivery: &eventingduckv1beta1.DeliverySpec{ + BackoffDelay: &invalidString, + }, + }, + }, + want: func() *apis.FieldError { + return apis.ErrInvalidValue(invalidString, "spec.delivery.backoffDelay") + }(), + }, {}} + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.b.Validate(context.Background()) + if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { + t.Errorf("BrokerSpec.Validate (-want, +got) = %v", diff) + } + }) + } +} + +func TestValidSpec(t *testing.T) { + bop := eventingduckv1beta1.BackoffPolicyExponential + tests := []struct { + name string + spec BrokerSpec + want *apis.FieldError + }{{ + name: "valid empty", + spec: BrokerSpec{}, + want: nil, + }, { + name: "valid config", + spec: BrokerSpec{ + Config: &corev1.ObjectReference{ + Namespace: "namespace", + Name: "name", + Kind: "kind", + APIVersion: "apiversion", + }, + }, + want: nil, + }, { + name: "valid delivery", + spec: BrokerSpec{ + Config: &corev1.ObjectReference{ + Namespace: "namespace", + Name: "name", + Kind: "kind", + APIVersion: "apiversion", + }, + Delivery: &eventingduckv1beta1.DeliverySpec{BackoffPolicy: &bop}, + }, + want: nil, + }, {}} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.spec.Validate(context.Background()) + if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { + t.Errorf("BrokerSpec.Validate (-want, +got) = %v", diff) + } + }) + } +} diff --git a/pkg/apis/eventing/v1beta1/register.go b/pkg/apis/eventing/v1beta1/register.go index aaa9d4a2577..f7d1f32f203 100644 --- a/pkg/apis/eventing/v1beta1/register.go +++ b/pkg/apis/eventing/v1beta1/register.go @@ -45,6 +45,8 @@ var ( // Adds the list of known types to Scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, + &Broker{}, + &BrokerList{}, // &EventType{}, // &EventTypeList{}, &Trigger{}, diff --git a/pkg/apis/eventing/v1beta1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1beta1/zz_generated.deepcopy.go index 09bce9a21e5..3b563c1c734 100644 --- a/pkg/apis/eventing/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1beta1/zz_generated.deepcopy.go @@ -21,10 +21,117 @@ limitations under the License. package v1beta1 import ( + v1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" + duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" apis "knative.dev/pkg/apis" ) +// 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) + in.Status.DeepCopyInto(&out.Status) + 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 + in.ListMeta.DeepCopyInto(&out.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 + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = new(v1.ObjectReference) + **out = **in + } + if in.Delivery != nil { + in, out := &in.Delivery, &out.Delivery + *out = new(duckv1beta1.DeliverySpec) + (*in).DeepCopyInto(*out) + } + 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 + in.Status.DeepCopyInto(&out.Status) + in.Address.DeepCopyInto(&out.Address) + 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 *Trigger) DeepCopyInto(out *Trigger) { *out = *in diff --git a/pkg/client/clientset/versioned/typed/eventing/v1beta1/broker.go b/pkg/client/clientset/versioned/typed/eventing/v1beta1/broker.go new file mode 100644 index 00000000000..d7a1c9f5160 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1beta1/broker.go @@ -0,0 +1,191 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "time" + + 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" + v1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" + scheme "knative.dev/eventing/pkg/client/clientset/versioned/scheme" +) + +// 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(*v1beta1.Broker) (*v1beta1.Broker, error) + Update(*v1beta1.Broker) (*v1beta1.Broker, error) + UpdateStatus(*v1beta1.Broker) (*v1beta1.Broker, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1beta1.Broker, error) + List(opts v1.ListOptions) (*v1beta1.BrokerList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1beta1.Broker, err error) + BrokerExpansion +} + +// brokers implements BrokerInterface +type brokers struct { + client rest.Interface + ns string +} + +// newBrokers returns a Brokers +func newBrokers(c *EventingV1beta1Client, 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 *v1beta1.Broker, err error) { + result = &v1beta1.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 *v1beta1.BrokerList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.BrokerList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("brokers"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested brokers. +func (c *brokers) Watch(opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("brokers"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + 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 *v1beta1.Broker) (result *v1beta1.Broker, err error) { + result = &v1beta1.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 *v1beta1.Broker) (result *v1beta1.Broker, err error) { + result = &v1beta1.Broker{} + err = c.client.Put(). + Namespace(c.ns). + Resource("brokers"). + Name(broker.Name). + Body(broker). + Do(). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + +func (c *brokers) UpdateStatus(broker *v1beta1.Broker) (result *v1beta1.Broker, err error) { + result = &v1beta1.Broker{} + err = c.client.Put(). + Namespace(c.ns). + Resource("brokers"). + Name(broker.Name). + SubResource("status"). + 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 { + var timeout time.Duration + if listOptions.TimeoutSeconds != nil { + timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("brokers"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Timeout(timeout). + 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 *v1beta1.Broker, err error) { + result = &v1beta1.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/v1beta1/eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1beta1/eventing_client.go index e108a002529..c89dd72d9f2 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1beta1/eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1beta1/eventing_client.go @@ -26,6 +26,7 @@ import ( type EventingV1beta1Interface interface { RESTClient() rest.Interface + BrokersGetter TriggersGetter } @@ -34,6 +35,10 @@ type EventingV1beta1Client struct { restClient rest.Interface } +func (c *EventingV1beta1Client) Brokers(namespace string) BrokerInterface { + return newBrokers(c, namespace) +} + func (c *EventingV1beta1Client) Triggers(namespace string) TriggerInterface { return newTriggers(c, namespace) } diff --git a/pkg/client/clientset/versioned/typed/eventing/v1beta1/fake/fake_broker.go b/pkg/client/clientset/versioned/typed/eventing/v1beta1/fake/fake_broker.go new file mode 100644 index 00000000000..3332d880a48 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1beta1/fake/fake_broker.go @@ -0,0 +1,140 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + 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" + v1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" +) + +// FakeBrokers implements BrokerInterface +type FakeBrokers struct { + Fake *FakeEventingV1beta1 + ns string +} + +var brokersResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1beta1", Resource: "brokers"} + +var brokersKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1beta1", 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 *v1beta1.Broker, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(brokersResource, c.ns, name), &v1beta1.Broker{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.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 *v1beta1.BrokerList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(brokersResource, brokersKind, c.ns, opts), &v1beta1.BrokerList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.BrokerList{ListMeta: obj.(*v1beta1.BrokerList).ListMeta} + for _, item := range obj.(*v1beta1.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 *v1beta1.Broker) (result *v1beta1.Broker, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(brokersResource, c.ns, broker), &v1beta1.Broker{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.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 *v1beta1.Broker) (result *v1beta1.Broker, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(brokersResource, c.ns, broker), &v1beta1.Broker{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Broker), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeBrokers) UpdateStatus(broker *v1beta1.Broker) (*v1beta1.Broker, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(brokersResource, "status", c.ns, broker), &v1beta1.Broker{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.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), &v1beta1.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, &v1beta1.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 *v1beta1.Broker, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(brokersResource, c.ns, name, pt, data, subresources...), &v1beta1.Broker{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Broker), err +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1beta1/fake/fake_eventing_client.go b/pkg/client/clientset/versioned/typed/eventing/v1beta1/fake/fake_eventing_client.go index 090d512066a..946b0323c78 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1beta1/fake/fake_eventing_client.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1beta1/fake/fake_eventing_client.go @@ -28,6 +28,10 @@ type FakeEventingV1beta1 struct { *testing.Fake } +func (c *FakeEventingV1beta1) Brokers(namespace string) v1beta1.BrokerInterface { + return &FakeBrokers{c, namespace} +} + func (c *FakeEventingV1beta1) Triggers(namespace string) v1beta1.TriggerInterface { return &FakeTriggers{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/eventing/v1beta1/generated_expansion.go b/pkg/client/clientset/versioned/typed/eventing/v1beta1/generated_expansion.go index bf12ef69a72..1fb6fcec994 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1beta1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1beta1/generated_expansion.go @@ -18,4 +18,6 @@ limitations under the License. package v1beta1 +type BrokerExpansion interface{} + type TriggerExpansion interface{} diff --git a/pkg/client/informers/externalversions/eventing/v1beta1/broker.go b/pkg/client/informers/externalversions/eventing/v1beta1/broker.go new file mode 100644 index 00000000000..ce88b4da852 --- /dev/null +++ b/pkg/client/informers/externalversions/eventing/v1beta1/broker.go @@ -0,0 +1,89 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + time "time" + + 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" + eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" + versioned "knative.dev/eventing/pkg/client/clientset/versioned" + internalinterfaces "knative.dev/eventing/pkg/client/informers/externalversions/internalinterfaces" + v1beta1 "knative.dev/eventing/pkg/client/listers/eventing/v1beta1" +) + +// BrokerInformer provides access to a shared informer and lister for +// Brokers. +type BrokerInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.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.EventingV1beta1().Brokers(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventingV1beta1().Brokers(namespace).Watch(options) + }, + }, + &eventingv1beta1.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(&eventingv1beta1.Broker{}, f.defaultInformer) +} + +func (f *brokerInformer) Lister() v1beta1.BrokerLister { + return v1beta1.NewBrokerLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/eventing/v1beta1/interface.go b/pkg/client/informers/externalversions/eventing/v1beta1/interface.go index b5d7bffbd5b..d79127971c9 100644 --- a/pkg/client/informers/externalversions/eventing/v1beta1/interface.go +++ b/pkg/client/informers/externalversions/eventing/v1beta1/interface.go @@ -24,6 +24,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // Brokers returns a BrokerInformer. + Brokers() BrokerInformer // Triggers returns a TriggerInformer. Triggers() TriggerInformer } @@ -39,6 +41,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// Brokers returns a BrokerInformer. +func (v *version) Brokers() BrokerInformer { + return &brokerInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // Triggers returns a TriggerInformer. func (v *version) Triggers() TriggerInformer { return &triggerInformer{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 d242d8da8d7..abf561518b7 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -72,6 +72,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Triggers().Informer()}, nil // Group=eventing.knative.dev, Version=v1beta1 + case v1beta1.SchemeGroupVersion.WithResource("brokers"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1beta1().Brokers().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("triggers"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1beta1().Triggers().Informer()}, nil diff --git a/pkg/client/injection/informers/eventing/v1beta1/broker/broker.go b/pkg/client/injection/informers/eventing/v1beta1/broker/broker.go new file mode 100644 index 00000000000..8b9f3a61d2c --- /dev/null +++ b/pkg/client/injection/informers/eventing/v1beta1/broker/broker.go @@ -0,0 +1,52 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package broker + +import ( + "context" + + v1beta1 "knative.dev/eventing/pkg/client/informers/externalversions/eventing/v1beta1" + factory "knative.dev/eventing/pkg/client/injection/informers/factory" + controller "knative.dev/pkg/controller" + injection "knative.dev/pkg/injection" + logging "knative.dev/pkg/logging" +) + +func init() { + injection.Default.RegisterInformer(withInformer) +} + +// Key is used for associating the Informer inside the context.Context. +type Key struct{} + +func withInformer(ctx context.Context) (context.Context, controller.Informer) { + f := factory.Get(ctx) + inf := f.Eventing().V1beta1().Brokers() + return context.WithValue(ctx, Key{}, inf), inf.Informer() +} + +// Get extracts the typed informer from the context. +func Get(ctx context.Context) v1beta1.BrokerInformer { + untyped := ctx.Value(Key{}) + if untyped == nil { + logging.FromContext(ctx).Panic( + "Unable to fetch knative.dev/eventing/pkg/client/informers/externalversions/eventing/v1beta1.BrokerInformer from context.") + } + return untyped.(v1beta1.BrokerInformer) +} diff --git a/pkg/client/injection/informers/eventing/v1beta1/broker/fake/fake.go b/pkg/client/injection/informers/eventing/v1beta1/broker/fake/fake.go new file mode 100644 index 00000000000..bbd60472813 --- /dev/null +++ b/pkg/client/injection/informers/eventing/v1beta1/broker/fake/fake.go @@ -0,0 +1,40 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + broker "knative.dev/eventing/pkg/client/injection/informers/eventing/v1beta1/broker" + fake "knative.dev/eventing/pkg/client/injection/informers/factory/fake" + controller "knative.dev/pkg/controller" + injection "knative.dev/pkg/injection" +) + +var Get = broker.Get + +func init() { + injection.Fake.RegisterInformer(withInformer) +} + +func withInformer(ctx context.Context) (context.Context, controller.Informer) { + f := fake.Get(ctx) + inf := f.Eventing().V1beta1().Brokers() + return context.WithValue(ctx, broker.Key{}, inf), inf.Informer() +} diff --git a/pkg/client/listers/eventing/v1beta1/broker.go b/pkg/client/listers/eventing/v1beta1/broker.go new file mode 100644 index 00000000000..ac520da2ecf --- /dev/null +++ b/pkg/client/listers/eventing/v1beta1/broker.go @@ -0,0 +1,94 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" +) + +// BrokerLister helps list Brokers. +type BrokerLister interface { + // List lists all Brokers in the indexer. + List(selector labels.Selector) (ret []*v1beta1.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 []*v1beta1.Broker, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.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 []*v1beta1.Broker, err error) + // Get retrieves the Broker from the indexer for a given namespace and name. + Get(name string) (*v1beta1.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 []*v1beta1.Broker, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.Broker)) + }) + return ret, err +} + +// Get retrieves the Broker from the indexer for a given namespace and name. +func (s brokerNamespaceLister) Get(name string) (*v1beta1.Broker, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("broker"), name) + } + return obj.(*v1beta1.Broker), nil +} diff --git a/pkg/client/listers/eventing/v1beta1/expansion_generated.go b/pkg/client/listers/eventing/v1beta1/expansion_generated.go index 8375e6796d9..1462c32e6b5 100644 --- a/pkg/client/listers/eventing/v1beta1/expansion_generated.go +++ b/pkg/client/listers/eventing/v1beta1/expansion_generated.go @@ -18,6 +18,14 @@ limitations under the License. package v1beta1 +// BrokerListerExpansion allows custom methods to be added to +// BrokerLister. +type BrokerListerExpansion interface{} + +// BrokerNamespaceListerExpansion allows custom methods to be added to +// BrokerNamespaceLister. +type BrokerNamespaceListerExpansion interface{} + // TriggerListerExpansion allows custom methods to be added to // TriggerLister. type TriggerListerExpansion interface{}