From 6cdd70816b255a6b9254313d578752cd8de2b63a Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Fri, 14 Sep 2018 09:53:33 -0700 Subject: [PATCH 01/15] Add a new Channel CRD to the eventing group This is intended to replace the existing Channel in the channels group. It doesn't include the array of subscription details yet. --- .../eventing/v1alpha1/channel_defaults.go | 26 +++ pkg/apis/eventing/v1alpha1/channel_types.go | 172 +++++++++++++++++ .../eventing/v1alpha1/channel_types_test.go | 107 +++++++++++ .../eventing/v1alpha1/channel_validation.go | 54 ++++++ .../v1alpha1/channel_validation_test.go | 179 ++++++++++++++++++ pkg/apis/eventing/v1alpha1/register.go | 2 + .../v1alpha1/zz_generated.deepcopy.go | 178 +++++++++++++++++ .../typed/eventing/v1alpha1/channel.go | 157 +++++++++++++++ .../eventing/v1alpha1/eventing_client.go | 5 + .../eventing/v1alpha1/fake/fake_channel.go | 128 +++++++++++++ .../v1alpha1/fake/fake_eventing_client.go | 4 + .../fake/fake_provisionerreference.go | 116 ++++++++++++ .../eventing/v1alpha1/generated_expansion.go | 2 + .../eventing/v1alpha1/provisionerreference.go | 157 +++++++++++++++ .../eventing/v1alpha1/channel.go | 89 +++++++++ .../eventing/v1alpha1/interface.go | 7 + .../eventing/v1alpha1/provisionerreference.go | 89 +++++++++ .../informers/externalversions/generic.go | 2 + .../listers/eventing/v1alpha1/channel.go | 94 +++++++++ .../eventing/v1alpha1/expansion_generated.go | 8 + .../eventing/v1alpha1/provisionerreference.go | 94 +++++++++ 21 files changed, 1670 insertions(+) create mode 100644 pkg/apis/eventing/v1alpha1/channel_defaults.go create mode 100644 pkg/apis/eventing/v1alpha1/channel_types.go create mode 100644 pkg/apis/eventing/v1alpha1/channel_types_test.go create mode 100644 pkg/apis/eventing/v1alpha1/channel_validation.go create mode 100644 pkg/apis/eventing/v1alpha1/channel_validation_test.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/channel.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_provisionerreference.go create mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/provisionerreference.go create mode 100644 pkg/client/informers/externalversions/eventing/v1alpha1/channel.go create mode 100644 pkg/client/informers/externalversions/eventing/v1alpha1/provisionerreference.go create mode 100644 pkg/client/listers/eventing/v1alpha1/channel.go create mode 100644 pkg/client/listers/eventing/v1alpha1/provisionerreference.go 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_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go new file mode 100644 index 00000000000..3a0b0f8dbcc --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -0,0 +1,172 @@ +/* + * 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/webhook" + corev1 "k8s.io/api/core/v1" + 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 represents a named endpoint on which a Bus accepts event delivery and +// corresponds to the channels.channels.knative.dev CRD. The Bus handles +// provisioning channels, delivering events to Channels, and delivering events +// from Channels to their 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) + +// 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"` +} + +// 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"` + + // A reference to the k8s Service backing this channel. + // +optional + Service *corev1.LocalObjectReference `json:"service,omitempty"` + + // A reference to the istio VirtualService backing this channel. + // +optional + VirtualService *corev1.LocalObjectReference `json:"virtualService,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 []ChannelCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` +} + +type ChannelConditionType string + +const ( + // ChannelConditionReady has status True when the Channel is ready to accept traffic. + ChannelConditionReady ChannelConditionType = "Ready" + + // ChannelConditionServiceable has status True when the service addressing the + // Channel exists. + // TODO should this be Sinkable? + ChannelConditionServiceable ChannelConditionType = "Serviceable" + + // ChannelConditionProvisioned has status True when the Channel's backing + // resources have been provisioned. + ChannelConditionProvisioned ChannelConditionType = "Provisioned" +) + +// ChannelCondition describes the state of a channel at a point in time. +type ChannelCondition struct { + // Type of channel condition. + Type ChannelConditionType `json:"type"` + // Status of the condition, one of True, False, Unknown. + Status corev1.ConditionStatus `json:"status"` + // LastTransitionTime from one status to another. + LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` + // Reason for the condition's last transition. + Reason string `json:"reason,omitempty"` + // Message is a human readable message indicating details about the + // last transition. + Message string `json:"message,omitempty"` +} + +//TODO move this to ClusterProvisioner types +// ProvisionerReference defines the strategy for selecting a Provisioner for a +// provisioned resource. +type ProvisionerReference struct { + // A reference to a specific Provisioner. + //TODO: +optional add selector + Ref *corev1.ObjectReference `json:"ref,omitempty"` +} + +func (cs *ChannelStatus) GetCondition(t ChannelConditionType) *ChannelCondition { + for _, cond := range cs.Conditions { + if cond.Type == t { + return &cond + } + } + return nil +} + +func (c *Channel) GetSpecJSON() ([]byte, error) { + return json.Marshal(c.Spec) +} + +// +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..06f68407712 --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_types_test.go @@ -0,0 +1,107 @@ +/* +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" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +var condReady = ChannelCondition{ + Type: ChannelConditionReady, + Status: corev1.ConditionTrue, +} + +var condUnprovisioned = ChannelCondition{ + Type: ChannelConditionProvisioned, + Status: corev1.ConditionFalse, +} + +func TestChannelGetCondition(t *testing.T) { + tests := []struct { + name string + cs *ChannelStatus + condType ChannelConditionType + want *ChannelCondition + }{{ + name: "single condition", + cs: &ChannelStatus{ + Conditions: []ChannelCondition{ + condReady, + }, + }, + condType: ChannelConditionReady, + want: &condReady, + }, { + name: "multiple conditions", + cs: &ChannelStatus{ + Conditions: []ChannelCondition{ + condReady, + condUnprovisioned, + }, + }, + condType: ChannelConditionProvisioned, + want: &condUnprovisioned, + }, { + name: "unknown condition", + cs: &ChannelStatus{ + Conditions: []ChannelCondition{ + condReady, + condUnprovisioned, + }, + }, + condType: ChannelConditionServiceable, + want: nil, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.cs.GetCondition(test.condType) + if diff := cmp.Diff(test.want, got); diff != "" { + t.Errorf("unexpected condition (-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..9a3b8f98521 --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_validation.go @@ -0,0 +1,54 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + "github.com/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") + } + + 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..1d957881627 --- /dev/null +++ b/pkg/apis/eventing/v1alpha1/channel_validation_test.go @@ -0,0 +1,179 @@ +/* +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" +) + +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"), + }} + + 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/register.go b/pkg/apis/eventing/v1alpha1/register.go index 3f24f758a88..41a20a58e40 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{}, &Subscription{}, &SubscriptionList{}, ) diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index a3678bad294..1eb9a73c87a 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -59,6 +59,184 @@ 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 *ChannelCondition) DeepCopyInto(out *ChannelCondition) { + *out = *in + in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelCondition. +func (in *ChannelCondition) DeepCopy() *ChannelCondition { + if in == nil { + return nil + } + out := new(ChannelCondition) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ChannelList) DeepCopyInto(out *ChannelList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Channel, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelList. +func (in *ChannelList) DeepCopy() *ChannelList { + if in == nil { + return nil + } + out := new(ChannelList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ChannelList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ChannelSpec) DeepCopyInto(out *ChannelSpec) { + *out = *in + if in.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) + } + } + 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.Service != nil { + in, out := &in.Service, &out.Service + if *in == nil { + *out = nil + } else { + *out = new(v1.LocalObjectReference) + **out = **in + } + } + if in.VirtualService != nil { + in, out := &in.VirtualService, &out.VirtualService + if *in == nil { + *out = nil + } else { + *out = new(v1.LocalObjectReference) + **out = **in + } + } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]ChannelCondition, 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 *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 362710dd220..09ae2d604a0 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 SubscriptionsGetter } @@ -35,6 +36,10 @@ type EventingV1alpha1Client struct { restClient rest.Interface } +func (c *EventingV1alpha1Client) Channels(namespace string) ChannelInterface { + return newChannels(c, namespace) +} + func (c *EventingV1alpha1Client) Subscriptions(namespace string) SubscriptionInterface { return newSubscriptions(c, namespace) } diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_channel.go new file mode 100644 index 00000000000..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 005dbd11327..b6c968d4943 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) Subscriptions(namespace string) v1alpha1.SubscriptionInterface { return &FakeSubscriptions{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_provisionerreference.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_provisionerreference.go new file mode 100644 index 00000000000..a8fc74e6964 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_provisionerreference.go @@ -0,0 +1,116 @@ +/* +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" + 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" +) + +// FakeProvisionerReferences implements ProvisionerReferenceInterface +type FakeProvisionerReferences struct { + Fake *FakeEventingV1alpha1 + ns string +} + +var provisionerreferencesResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "provisionerreferences"} + +var provisionerreferencesKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "ProvisionerReference"} + +// Get takes name of the provisionerReference, and returns the corresponding provisionerReference object, and an error if there is any. +func (c *FakeProvisionerReferences) Get(name string, options v1.GetOptions) (result *v1alpha1.ProvisionerReference, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(provisionerreferencesResource, c.ns, name), &v1alpha1.ProvisionerReference{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ProvisionerReference), err +} + +// List takes label and field selectors, and returns the list of ProvisionerReferences that match those selectors. +func (c *FakeProvisionerReferences) List(opts v1.ListOptions) (result *v1alpha1.ProvisionerReferenceList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(provisionerreferencesResource, provisionerreferencesKind, c.ns, opts), &v1alpha1.ProvisionerReferenceList{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ProvisionerReferenceList), err +} + +// Watch returns a watch.Interface that watches the requested provisionerReferences. +func (c *FakeProvisionerReferences) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(provisionerreferencesResource, c.ns, opts)) + +} + +// Create takes the representation of a provisionerReference and creates it. Returns the server's representation of the provisionerReference, and an error, if there is any. +func (c *FakeProvisionerReferences) Create(provisionerReference *v1alpha1.ProvisionerReference) (result *v1alpha1.ProvisionerReference, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(provisionerreferencesResource, c.ns, provisionerReference), &v1alpha1.ProvisionerReference{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ProvisionerReference), err +} + +// Update takes the representation of a provisionerReference and updates it. Returns the server's representation of the provisionerReference, and an error, if there is any. +func (c *FakeProvisionerReferences) Update(provisionerReference *v1alpha1.ProvisionerReference) (result *v1alpha1.ProvisionerReference, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(provisionerreferencesResource, c.ns, provisionerReference), &v1alpha1.ProvisionerReference{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ProvisionerReference), err +} + +// Delete takes name of the provisionerReference and deletes it. Returns an error if one occurs. +func (c *FakeProvisionerReferences) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(provisionerreferencesResource, c.ns, name), &v1alpha1.ProvisionerReference{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeProvisionerReferences) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(provisionerreferencesResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.ProvisionerReferenceList{}) + return err +} + +// Patch applies the patch and returns the patched provisionerReference. +func (c *FakeProvisionerReferences) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.ProvisionerReference, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(provisionerreferencesResource, c.ns, name, data, subresources...), &v1alpha1.ProvisionerReference{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ProvisionerReference), err +} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go index 9911c7c289f..7b784cc0547 100644 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/generated_expansion.go @@ -18,4 +18,6 @@ limitations under the License. package v1alpha1 +type ChannelExpansion interface{} + type SubscriptionExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/provisionerreference.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/provisionerreference.go new file mode 100644 index 00000000000..cd55105e813 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/provisionerreference.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" +) + +// ProvisionerReferencesGetter has a method to return a ProvisionerReferenceInterface. +// A group's client should implement this interface. +type ProvisionerReferencesGetter interface { + ProvisionerReferences(namespace string) ProvisionerReferenceInterface +} + +// ProvisionerReferenceInterface has methods to work with ProvisionerReference resources. +type ProvisionerReferenceInterface interface { + Create(*v1alpha1.ProvisionerReference) (*v1alpha1.ProvisionerReference, error) + Update(*v1alpha1.ProvisionerReference) (*v1alpha1.ProvisionerReference, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.ProvisionerReference, error) + List(opts v1.ListOptions) (*v1alpha1.ProvisionerReferenceList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.ProvisionerReference, err error) + ProvisionerReferenceExpansion +} + +// provisionerReferences implements ProvisionerReferenceInterface +type provisionerReferences struct { + client rest.Interface + ns string +} + +// newProvisionerReferences returns a ProvisionerReferences +func newProvisionerReferences(c *EventingV1alpha1Client, namespace string) *provisionerReferences { + return &provisionerReferences{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the provisionerReference, and returns the corresponding provisionerReference object, and an error if there is any. +func (c *provisionerReferences) Get(name string, options v1.GetOptions) (result *v1alpha1.ProvisionerReference, err error) { + result = &v1alpha1.ProvisionerReference{} + err = c.client.Get(). + Namespace(c.ns). + Resource("provisionerreferences"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of ProvisionerReferences that match those selectors. +func (c *provisionerReferences) List(opts v1.ListOptions) (result *v1alpha1.ProvisionerReferenceList, err error) { + result = &v1alpha1.ProvisionerReferenceList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("provisionerreferences"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested provisionerReferences. +func (c *provisionerReferences) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("provisionerreferences"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a provisionerReference and creates it. Returns the server's representation of the provisionerReference, and an error, if there is any. +func (c *provisionerReferences) Create(provisionerReference *v1alpha1.ProvisionerReference) (result *v1alpha1.ProvisionerReference, err error) { + result = &v1alpha1.ProvisionerReference{} + err = c.client.Post(). + Namespace(c.ns). + Resource("provisionerreferences"). + Body(provisionerReference). + Do(). + Into(result) + return +} + +// Update takes the representation of a provisionerReference and updates it. Returns the server's representation of the provisionerReference, and an error, if there is any. +func (c *provisionerReferences) Update(provisionerReference *v1alpha1.ProvisionerReference) (result *v1alpha1.ProvisionerReference, err error) { + result = &v1alpha1.ProvisionerReference{} + err = c.client.Put(). + Namespace(c.ns). + Resource("provisionerreferences"). + Name(provisionerReference.Name). + Body(provisionerReference). + Do(). + Into(result) + return +} + +// Delete takes name of the provisionerReference and deletes it. Returns an error if one occurs. +func (c *provisionerReferences) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("provisionerreferences"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *provisionerReferences) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("provisionerreferences"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched provisionerReference. +func (c *provisionerReferences) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.ProvisionerReference, err error) { + result = &v1alpha1.ProvisionerReference{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("provisionerreferences"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} 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 a6a55a02c9f..bc5ab868f21 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 // Subscriptions returns a SubscriptionInformer. Subscriptions() SubscriptionInformer } @@ -39,6 +41,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} +} + // Subscriptions returns a SubscriptionInformer. func (v *version) Subscriptions() SubscriptionInformer { return &subscriptionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/provisionerreference.go b/pkg/client/informers/externalversions/eventing/v1alpha1/provisionerreference.go new file mode 100644 index 00000000000..fe3a4e1a718 --- /dev/null +++ b/pkg/client/informers/externalversions/eventing/v1alpha1/provisionerreference.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" +) + +// ProvisionerReferenceInformer provides access to a shared informer and lister for +// ProvisionerReferences. +type ProvisionerReferenceInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.ProvisionerReferenceLister +} + +type provisionerReferenceInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewProvisionerReferenceInformer constructs a new informer for ProvisionerReference 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 NewProvisionerReferenceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredProvisionerReferenceInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredProvisionerReferenceInformer constructs a new informer for ProvisionerReference 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 NewFilteredProvisionerReferenceInformer(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().ProvisionerReferences(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventingV1alpha1().ProvisionerReferences(namespace).Watch(options) + }, + }, + &eventing_v1alpha1.ProvisionerReference{}, + resyncPeriod, + indexers, + ) +} + +func (f *provisionerReferenceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredProvisionerReferenceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *provisionerReferenceInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&eventing_v1alpha1.ProvisionerReference{}, f.defaultInformer) +} + +func (f *provisionerReferenceInformer) Lister() v1alpha1.ProvisionerReferenceLister { + return v1alpha1.NewProvisionerReferenceLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index ebec1b27cf0..32f84a59cb1 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("subscriptions"): return &genericInformer{resource: resource.GroupResource(), informer: f.Eventing().V1alpha1().Subscriptions().Informer()}, nil diff --git a/pkg/client/listers/eventing/v1alpha1/channel.go b/pkg/client/listers/eventing/v1alpha1/channel.go new file mode 100644 index 00000000000..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 68d69ebd2a4..51ac8e86e0f 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{} + // SubscriptionListerExpansion allows custom methods to be added to // SubscriptionLister. type SubscriptionListerExpansion interface{} diff --git a/pkg/client/listers/eventing/v1alpha1/provisionerreference.go b/pkg/client/listers/eventing/v1alpha1/provisionerreference.go new file mode 100644 index 00000000000..b6639aebf79 --- /dev/null +++ b/pkg/client/listers/eventing/v1alpha1/provisionerreference.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" +) + +// ProvisionerReferenceLister helps list ProvisionerReferences. +type ProvisionerReferenceLister interface { + // List lists all ProvisionerReferences in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.ProvisionerReference, err error) + // ProvisionerReferences returns an object that can list and get ProvisionerReferences. + ProvisionerReferences(namespace string) ProvisionerReferenceNamespaceLister + ProvisionerReferenceListerExpansion +} + +// provisionerReferenceLister implements the ProvisionerReferenceLister interface. +type provisionerReferenceLister struct { + indexer cache.Indexer +} + +// NewProvisionerReferenceLister returns a new ProvisionerReferenceLister. +func NewProvisionerReferenceLister(indexer cache.Indexer) ProvisionerReferenceLister { + return &provisionerReferenceLister{indexer: indexer} +} + +// List lists all ProvisionerReferences in the indexer. +func (s *provisionerReferenceLister) List(selector labels.Selector) (ret []*v1alpha1.ProvisionerReference, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.ProvisionerReference)) + }) + return ret, err +} + +// ProvisionerReferences returns an object that can list and get ProvisionerReferences. +func (s *provisionerReferenceLister) ProvisionerReferences(namespace string) ProvisionerReferenceNamespaceLister { + return provisionerReferenceNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// ProvisionerReferenceNamespaceLister helps list and get ProvisionerReferences. +type ProvisionerReferenceNamespaceLister interface { + // List lists all ProvisionerReferences in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.ProvisionerReference, err error) + // Get retrieves the ProvisionerReference from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.ProvisionerReference, error) + ProvisionerReferenceNamespaceListerExpansion +} + +// provisionerReferenceNamespaceLister implements the ProvisionerReferenceNamespaceLister +// interface. +type provisionerReferenceNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all ProvisionerReferences in the indexer for a given namespace. +func (s provisionerReferenceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.ProvisionerReference, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.ProvisionerReference)) + }) + return ret, err +} + +// Get retrieves the ProvisionerReference from the indexer for a given namespace and name. +func (s provisionerReferenceNamespaceLister) Get(name string) (*v1alpha1.ProvisionerReference, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("provisionerreference"), name) + } + return obj.(*v1alpha1.ProvisionerReference), nil +} From 5bd9843c3ca251e1f3dcc08ef16d261f9189d0a8 Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Fri, 14 Sep 2018 11:42:17 -0700 Subject: [PATCH 02/15] Add CRD yaml for Channel in eventing group --- config/300-channeleventing.yaml | 31 +++++++++++++++++++++ pkg/apis/eventing/v1alpha1/channel_types.go | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 config/300-channeleventing.yaml 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_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index 3a0b0f8dbcc..5722ab32fe3 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -73,6 +73,8 @@ type ChannelSpec struct { // this Channel. // +optional Arguments *runtime.RawExtension `json:"arguments,omitempty"` + + //TODO Subscription spec array } // ChannelStatus represents the current state of a Channel. From 9259abbfeae111b61bb5eb9eb61332ae80914a1e Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Fri, 14 Sep 2018 11:50:50 -0700 Subject: [PATCH 03/15] Add Channels and Subscriptions to webhook --- cmd/webhook/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 54bdf66fb42..26a5904efc0 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -28,6 +28,7 @@ import ( "github.com/knative/pkg/webhook" channelsv1alpha1 "github.com/knative/eventing/pkg/apis/channels/v1alpha1" + eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1" feedsv1alpha1 "github.com/knative/eventing/pkg/apis/feeds/v1alpha1" flowsv1alpha1 "github.com/knative/eventing/pkg/apis/flows/v1alpha1" "github.com/knative/eventing/pkg/logconfig" @@ -89,6 +90,10 @@ func main() { Client: kubeClient, Options: options, Handlers: map[schema.GroupVersionKind]runtime.Object{ + // For group eventing.knative.dev, + eventingv1alpha1.SchemeGroupVersion.WithKind("Channel"): &eventingv1alpha1.Channel{}, + eventingv1alpha1.SchemeGroupVersion.WithKind("Subscription"): &eventingv1alpha1.Subscription{}, + // For group channels.knative.dev, channelsv1alpha1.SchemeGroupVersion.WithKind("Bus"): &channelsv1alpha1.Bus{}, channelsv1alpha1.SchemeGroupVersion.WithKind("ClusterBus"): &channelsv1alpha1.ClusterBus{}, From 7a0586a4114227895027ba01819d5bc22f7ca44b Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Fri, 14 Sep 2018 14:03:06 -0700 Subject: [PATCH 04/15] Remove Service and VirtualService These fields are too specific to the implementation of the Channel. --- pkg/apis/eventing/v1alpha1/channel_types.go | 8 -------- .../eventing/v1alpha1/zz_generated.deepcopy.go | 18 ------------------ 2 files changed, 26 deletions(-) diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index 5722ab32fe3..27ee7914d71 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -87,14 +87,6 @@ type ChannelStatus struct { // +optional ObservedGeneration int64 `json:"observedGeneration,omitempty"` - // A reference to the k8s Service backing this channel. - // +optional - Service *corev1.LocalObjectReference `json:"service,omitempty"` - - // A reference to the istio VirtualService backing this channel. - // +optional - VirtualService *corev1.LocalObjectReference `json:"virtualService,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 diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index 1eb9a73c87a..e876447bdde 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -174,24 +174,6 @@ func (in *ChannelSpec) DeepCopy() *ChannelSpec { // 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.Service != nil { - in, out := &in.Service, &out.Service - if *in == nil { - *out = nil - } else { - *out = new(v1.LocalObjectReference) - **out = **in - } - } - if in.VirtualService != nil { - in, out := &in.VirtualService, &out.VirtualService - if *in == nil { - *out = nil - } else { - *out = new(v1.LocalObjectReference) - **out = **in - } - } if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions *out = make([]ChannelCondition, len(*in)) From c56ca484a6d48740f1fd15e6aaffa8e5a587fb26 Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Fri, 14 Sep 2018 14:03:34 -0700 Subject: [PATCH 05/15] Remove Serviceable condition The Serviceable/Sinkable condition is effectively the same as Ready. --- pkg/apis/eventing/v1alpha1/channel_types.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index 27ee7914d71..f80ab9e2147 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -105,14 +105,10 @@ type ChannelStatus struct { type ChannelConditionType string const ( - // ChannelConditionReady has status True when the Channel is ready to accept traffic. + // ChannelConditionReady has status True when the Channel is ready to accept + // traffic. ChannelConditionReady ChannelConditionType = "Ready" - // ChannelConditionServiceable has status True when the service addressing the - // Channel exists. - // TODO should this be Sinkable? - ChannelConditionServiceable ChannelConditionType = "Serviceable" - // ChannelConditionProvisioned has status True when the Channel's backing // resources have been provisioned. ChannelConditionProvisioned ChannelConditionType = "Provisioned" From 7b29db3887b83455ed125f83437f72d320c5b67c Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Fri, 14 Sep 2018 14:03:58 -0700 Subject: [PATCH 06/15] use apis.VolatileTime for LastTransitionTime Allows ignoring timestamps when comparing Statuses for equality. --- pkg/apis/eventing/v1alpha1/channel_types.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index f80ab9e2147..33fe975ae57 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -121,7 +121,9 @@ type ChannelCondition struct { // Status of the condition, one of True, False, Unknown. Status corev1.ConditionStatus `json:"status"` // LastTransitionTime from one status to another. - LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` + // We use VolatileTime in place of metav1.Time to exclude this from creating equality.Semantic + // differences (all other things held constant). + LastTransitionTime apis.VolatileTime `json:"lastTransitionTime,omitempty"` // Reason for the condition's last transition. Reason string `json:"reason,omitempty"` // Message is a human readable message indicating details about the From 34e68547974823bf4a0a720fd28db17283f9ed1f Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Mon, 17 Sep 2018 10:12:40 -0700 Subject: [PATCH 07/15] Remove reference to Serviceable condition in test --- .../eventing/v1alpha1/channel_types_test.go | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/apis/eventing/v1alpha1/channel_types_test.go b/pkg/apis/eventing/v1alpha1/channel_types_test.go index 06f68407712..90fb0ce03eb 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types_test.go +++ b/pkg/apis/eventing/v1alpha1/channel_types_test.go @@ -36,10 +36,10 @@ var condUnprovisioned = ChannelCondition{ func TestChannelGetCondition(t *testing.T) { tests := []struct { - name string - cs *ChannelStatus - condType ChannelConditionType - want *ChannelCondition + name string + cs *ChannelStatus + condQuery ChannelConditionType + want *ChannelCondition }{{ name: "single condition", cs: &ChannelStatus{ @@ -47,8 +47,8 @@ func TestChannelGetCondition(t *testing.T) { condReady, }, }, - condType: ChannelConditionReady, - want: &condReady, + condQuery: ChannelConditionReady, + want: &condReady, }, { name: "multiple conditions", cs: &ChannelStatus{ @@ -57,8 +57,8 @@ func TestChannelGetCondition(t *testing.T) { condUnprovisioned, }, }, - condType: ChannelConditionProvisioned, - want: &condUnprovisioned, + condQuery: ChannelConditionProvisioned, + want: &condUnprovisioned, }, { name: "unknown condition", cs: &ChannelStatus{ @@ -67,13 +67,13 @@ func TestChannelGetCondition(t *testing.T) { condUnprovisioned, }, }, - condType: ChannelConditionServiceable, - want: nil, + condQuery: ChannelConditionType("foo"), + want: nil, }} for _, test := range tests { t.Run(test.name, func(t *testing.T) { - got := test.cs.GetCondition(test.condType) + got := test.cs.GetCondition(test.condQuery) if diff := cmp.Diff(test.want, got); diff != "" { t.Errorf("unexpected condition (-want, +got) = %v", diff) } From 65f5b7e8a547f050f202587b5ee861d818457e3b Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Mon, 17 Sep 2018 10:23:01 -0700 Subject: [PATCH 08/15] Move ProvisionerReference to its own file Shared by Channel and Source so it shouldn't be buried in the types for either one. --- pkg/apis/eventing/v1alpha1/channel_types.go | 9 ------ .../v1alpha1/provisioner_reference.go | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 pkg/apis/eventing/v1alpha1/provisioner_reference.go diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index 33fe975ae57..5c2ec9b41a9 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -131,15 +131,6 @@ type ChannelCondition struct { Message string `json:"message,omitempty"` } -//TODO move this to ClusterProvisioner types -// ProvisionerReference defines the strategy for selecting a Provisioner for a -// provisioned resource. -type ProvisionerReference struct { - // A reference to a specific Provisioner. - //TODO: +optional add selector - Ref *corev1.ObjectReference `json:"ref,omitempty"` -} - func (cs *ChannelStatus) GetCondition(t ChannelConditionType) *ChannelCondition { for _, cond := range cs.Conditions { if cond.Type == t { 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"` +} From e6f892d47554a2e5c2d64baf7d99cf18df10e2f5 Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Mon, 17 Sep 2018 11:02:31 -0700 Subject: [PATCH 09/15] Add Subscribers array to Channel Includes the Call and Result fields from Subscription.Spec so the Subscription controller can copy those values directly. --- pkg/apis/eventing/v1alpha1/channel_types.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index 5c2ec9b41a9..dd1a6752be9 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -74,7 +74,23 @@ type ChannelSpec struct { // +optional Arguments *runtime.RawExtension `json:"arguments,omitempty"` - //TODO Subscription spec array + // 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. +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"` } // ChannelStatus represents the current state of a Channel. From 01310b82b19a89bd585ca7f03582018e61319297 Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Mon, 17 Sep 2018 11:49:54 -0700 Subject: [PATCH 10/15] Validate Channel.Spec.Subscribers Each Subscriber must have at least one of Call or Result. Currently the validation returns immediately upon encountering an empty Subscriber object due to a limitation in the knative/pkg validation helpers. This is probably fine for now since this field is not expected to be mutated by users. --- pkg/apis/eventing/v1alpha1/channel_types.go | 3 +- .../eventing/v1alpha1/channel_validation.go | 10 ++++ .../v1alpha1/channel_validation_test.go | 58 +++++++++++++++++++ .../v1alpha1/zz_generated.deepcopy.go | 41 +++++++++++++ 4 files changed, 111 insertions(+), 1 deletion(-) diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index dd1a6752be9..afd40878d0a 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -79,7 +79,8 @@ type ChannelSpec struct { Subscribers []ChannelSubscriberSpec `json:"subscribers,omitempty"` } -// ChannelSubscriberSpec defines a single subscriber to a Channel. +// 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 diff --git a/pkg/apis/eventing/v1alpha1/channel_validation.go b/pkg/apis/eventing/v1alpha1/channel_validation.go index 9a3b8f98521..ae6de32aa9a 100644 --- a/pkg/apis/eventing/v1alpha1/channel_validation.go +++ b/pkg/apis/eventing/v1alpha1/channel_validation.go @@ -17,6 +17,8 @@ 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" @@ -31,6 +33,14 @@ func (cs *ChannelSpec) Validate() *apis.FieldError { 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 } diff --git a/pkg/apis/eventing/v1alpha1/channel_validation_test.go b/pkg/apis/eventing/v1alpha1/channel_validation_test.go index 1d957881627..de46664d5eb 100644 --- a/pkg/apis/eventing/v1alpha1/channel_validation_test.go +++ b/pkg/apis/eventing/v1alpha1/channel_validation_test.go @@ -25,6 +25,8 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) +var targetURI = "https://example.com" + func TestChannelValidation(t *testing.T) { tests := []struct { name string @@ -48,6 +50,62 @@ func TestChannelValidation(t *testing.T) { 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 { diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index 2e6f32ddb0c..5f3d86c90a0 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -158,6 +158,13 @@ func (in *ChannelSpec) DeepCopyInto(out *ChannelSpec) { (*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 } @@ -194,6 +201,40 @@ func (in *ChannelStatus) DeepCopy() *ChannelStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *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 From 66cf283e6a7aa1f9ab2e18fd5ff8619c3a4d8726 Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Mon, 17 Sep 2018 14:35:39 -0700 Subject: [PATCH 11/15] Remove outdated codegen files ProvisionerReference was considered a top-level type at one point, apparently. --- .../fake/fake_provisionerreference.go | 116 ------------- .../eventing/v1alpha1/provisionerreference.go | 157 ------------------ .../eventing/v1alpha1/provisionerreference.go | 89 ---------- .../eventing/v1alpha1/provisionerreference.go | 94 ----------- 4 files changed, 456 deletions(-) delete mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_provisionerreference.go delete mode 100644 pkg/client/clientset/versioned/typed/eventing/v1alpha1/provisionerreference.go delete mode 100644 pkg/client/informers/externalversions/eventing/v1alpha1/provisionerreference.go delete mode 100644 pkg/client/listers/eventing/v1alpha1/provisionerreference.go diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_provisionerreference.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_provisionerreference.go deleted file mode 100644 index a8fc74e6964..00000000000 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/fake/fake_provisionerreference.go +++ /dev/null @@ -1,116 +0,0 @@ -/* -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" - 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" -) - -// FakeProvisionerReferences implements ProvisionerReferenceInterface -type FakeProvisionerReferences struct { - Fake *FakeEventingV1alpha1 - ns string -} - -var provisionerreferencesResource = schema.GroupVersionResource{Group: "eventing.knative.dev", Version: "v1alpha1", Resource: "provisionerreferences"} - -var provisionerreferencesKind = schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "ProvisionerReference"} - -// Get takes name of the provisionerReference, and returns the corresponding provisionerReference object, and an error if there is any. -func (c *FakeProvisionerReferences) Get(name string, options v1.GetOptions) (result *v1alpha1.ProvisionerReference, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(provisionerreferencesResource, c.ns, name), &v1alpha1.ProvisionerReference{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.ProvisionerReference), err -} - -// List takes label and field selectors, and returns the list of ProvisionerReferences that match those selectors. -func (c *FakeProvisionerReferences) List(opts v1.ListOptions) (result *v1alpha1.ProvisionerReferenceList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(provisionerreferencesResource, provisionerreferencesKind, c.ns, opts), &v1alpha1.ProvisionerReferenceList{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.ProvisionerReferenceList), err -} - -// Watch returns a watch.Interface that watches the requested provisionerReferences. -func (c *FakeProvisionerReferences) Watch(opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(provisionerreferencesResource, c.ns, opts)) - -} - -// Create takes the representation of a provisionerReference and creates it. Returns the server's representation of the provisionerReference, and an error, if there is any. -func (c *FakeProvisionerReferences) Create(provisionerReference *v1alpha1.ProvisionerReference) (result *v1alpha1.ProvisionerReference, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(provisionerreferencesResource, c.ns, provisionerReference), &v1alpha1.ProvisionerReference{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.ProvisionerReference), err -} - -// Update takes the representation of a provisionerReference and updates it. Returns the server's representation of the provisionerReference, and an error, if there is any. -func (c *FakeProvisionerReferences) Update(provisionerReference *v1alpha1.ProvisionerReference) (result *v1alpha1.ProvisionerReference, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(provisionerreferencesResource, c.ns, provisionerReference), &v1alpha1.ProvisionerReference{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.ProvisionerReference), err -} - -// Delete takes name of the provisionerReference and deletes it. Returns an error if one occurs. -func (c *FakeProvisionerReferences) Delete(name string, options *v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(provisionerreferencesResource, c.ns, name), &v1alpha1.ProvisionerReference{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeProvisionerReferences) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(provisionerreferencesResource, c.ns, listOptions) - - _, err := c.Fake.Invokes(action, &v1alpha1.ProvisionerReferenceList{}) - return err -} - -// Patch applies the patch and returns the patched provisionerReference. -func (c *FakeProvisionerReferences) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.ProvisionerReference, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(provisionerreferencesResource, c.ns, name, data, subresources...), &v1alpha1.ProvisionerReference{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.ProvisionerReference), err -} diff --git a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/provisionerreference.go b/pkg/client/clientset/versioned/typed/eventing/v1alpha1/provisionerreference.go deleted file mode 100644 index cd55105e813..00000000000 --- a/pkg/client/clientset/versioned/typed/eventing/v1alpha1/provisionerreference.go +++ /dev/null @@ -1,157 +0,0 @@ -/* -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" -) - -// ProvisionerReferencesGetter has a method to return a ProvisionerReferenceInterface. -// A group's client should implement this interface. -type ProvisionerReferencesGetter interface { - ProvisionerReferences(namespace string) ProvisionerReferenceInterface -} - -// ProvisionerReferenceInterface has methods to work with ProvisionerReference resources. -type ProvisionerReferenceInterface interface { - Create(*v1alpha1.ProvisionerReference) (*v1alpha1.ProvisionerReference, error) - Update(*v1alpha1.ProvisionerReference) (*v1alpha1.ProvisionerReference, error) - Delete(name string, options *v1.DeleteOptions) error - DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error - Get(name string, options v1.GetOptions) (*v1alpha1.ProvisionerReference, error) - List(opts v1.ListOptions) (*v1alpha1.ProvisionerReferenceList, error) - Watch(opts v1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.ProvisionerReference, err error) - ProvisionerReferenceExpansion -} - -// provisionerReferences implements ProvisionerReferenceInterface -type provisionerReferences struct { - client rest.Interface - ns string -} - -// newProvisionerReferences returns a ProvisionerReferences -func newProvisionerReferences(c *EventingV1alpha1Client, namespace string) *provisionerReferences { - return &provisionerReferences{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the provisionerReference, and returns the corresponding provisionerReference object, and an error if there is any. -func (c *provisionerReferences) Get(name string, options v1.GetOptions) (result *v1alpha1.ProvisionerReference, err error) { - result = &v1alpha1.ProvisionerReference{} - err = c.client.Get(). - Namespace(c.ns). - Resource("provisionerreferences"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ProvisionerReferences that match those selectors. -func (c *provisionerReferences) List(opts v1.ListOptions) (result *v1alpha1.ProvisionerReferenceList, err error) { - result = &v1alpha1.ProvisionerReferenceList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("provisionerreferences"). - VersionedParams(&opts, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested provisionerReferences. -func (c *provisionerReferences) Watch(opts v1.ListOptions) (watch.Interface, error) { - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("provisionerreferences"). - VersionedParams(&opts, scheme.ParameterCodec). - Watch() -} - -// Create takes the representation of a provisionerReference and creates it. Returns the server's representation of the provisionerReference, and an error, if there is any. -func (c *provisionerReferences) Create(provisionerReference *v1alpha1.ProvisionerReference) (result *v1alpha1.ProvisionerReference, err error) { - result = &v1alpha1.ProvisionerReference{} - err = c.client.Post(). - Namespace(c.ns). - Resource("provisionerreferences"). - Body(provisionerReference). - Do(). - Into(result) - return -} - -// Update takes the representation of a provisionerReference and updates it. Returns the server's representation of the provisionerReference, and an error, if there is any. -func (c *provisionerReferences) Update(provisionerReference *v1alpha1.ProvisionerReference) (result *v1alpha1.ProvisionerReference, err error) { - result = &v1alpha1.ProvisionerReference{} - err = c.client.Put(). - Namespace(c.ns). - Resource("provisionerreferences"). - Name(provisionerReference.Name). - Body(provisionerReference). - Do(). - Into(result) - return -} - -// Delete takes name of the provisionerReference and deletes it. Returns an error if one occurs. -func (c *provisionerReferences) Delete(name string, options *v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("provisionerreferences"). - Name(name). - Body(options). - Do(). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *provisionerReferences) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("provisionerreferences"). - VersionedParams(&listOptions, scheme.ParameterCodec). - Body(options). - Do(). - Error() -} - -// Patch applies the patch and returns the patched provisionerReference. -func (c *provisionerReferences) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.ProvisionerReference, err error) { - result = &v1alpha1.ProvisionerReference{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("provisionerreferences"). - SubResource(subresources...). - Name(name). - Body(data). - Do(). - Into(result) - return -} diff --git a/pkg/client/informers/externalversions/eventing/v1alpha1/provisionerreference.go b/pkg/client/informers/externalversions/eventing/v1alpha1/provisionerreference.go deleted file mode 100644 index fe3a4e1a718..00000000000 --- a/pkg/client/informers/externalversions/eventing/v1alpha1/provisionerreference.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -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" -) - -// ProvisionerReferenceInformer provides access to a shared informer and lister for -// ProvisionerReferences. -type ProvisionerReferenceInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.ProvisionerReferenceLister -} - -type provisionerReferenceInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewProvisionerReferenceInformer constructs a new informer for ProvisionerReference 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 NewProvisionerReferenceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredProvisionerReferenceInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredProvisionerReferenceInformer constructs a new informer for ProvisionerReference 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 NewFilteredProvisionerReferenceInformer(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().ProvisionerReferences(namespace).List(options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.EventingV1alpha1().ProvisionerReferences(namespace).Watch(options) - }, - }, - &eventing_v1alpha1.ProvisionerReference{}, - resyncPeriod, - indexers, - ) -} - -func (f *provisionerReferenceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredProvisionerReferenceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *provisionerReferenceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventing_v1alpha1.ProvisionerReference{}, f.defaultInformer) -} - -func (f *provisionerReferenceInformer) Lister() v1alpha1.ProvisionerReferenceLister { - return v1alpha1.NewProvisionerReferenceLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/listers/eventing/v1alpha1/provisionerreference.go b/pkg/client/listers/eventing/v1alpha1/provisionerreference.go deleted file mode 100644 index b6639aebf79..00000000000 --- a/pkg/client/listers/eventing/v1alpha1/provisionerreference.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -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" -) - -// ProvisionerReferenceLister helps list ProvisionerReferences. -type ProvisionerReferenceLister interface { - // List lists all ProvisionerReferences in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.ProvisionerReference, err error) - // ProvisionerReferences returns an object that can list and get ProvisionerReferences. - ProvisionerReferences(namespace string) ProvisionerReferenceNamespaceLister - ProvisionerReferenceListerExpansion -} - -// provisionerReferenceLister implements the ProvisionerReferenceLister interface. -type provisionerReferenceLister struct { - indexer cache.Indexer -} - -// NewProvisionerReferenceLister returns a new ProvisionerReferenceLister. -func NewProvisionerReferenceLister(indexer cache.Indexer) ProvisionerReferenceLister { - return &provisionerReferenceLister{indexer: indexer} -} - -// List lists all ProvisionerReferences in the indexer. -func (s *provisionerReferenceLister) List(selector labels.Selector) (ret []*v1alpha1.ProvisionerReference, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.ProvisionerReference)) - }) - return ret, err -} - -// ProvisionerReferences returns an object that can list and get ProvisionerReferences. -func (s *provisionerReferenceLister) ProvisionerReferences(namespace string) ProvisionerReferenceNamespaceLister { - return provisionerReferenceNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// ProvisionerReferenceNamespaceLister helps list and get ProvisionerReferences. -type ProvisionerReferenceNamespaceLister interface { - // List lists all ProvisionerReferences in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.ProvisionerReference, err error) - // Get retrieves the ProvisionerReference from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.ProvisionerReference, error) - ProvisionerReferenceNamespaceListerExpansion -} - -// provisionerReferenceNamespaceLister implements the ProvisionerReferenceNamespaceLister -// interface. -type provisionerReferenceNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all ProvisionerReferences in the indexer for a given namespace. -func (s provisionerReferenceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.ProvisionerReference, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.ProvisionerReference)) - }) - return ret, err -} - -// Get retrieves the ProvisionerReference from the indexer for a given namespace and name. -func (s provisionerReferenceNamespaceLister) Get(name string) (*v1alpha1.ProvisionerReference, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("provisionerreference"), name) - } - return obj.(*v1alpha1.ProvisionerReference), nil -} From 7bb4c7059166cf7d2078bd308a443804f462bbcc Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Mon, 17 Sep 2018 14:40:00 -0700 Subject: [PATCH 12/15] Add no-op test of SetDefaults method The SetDefaults method is required to exist by the webhook implementation, but we don't want it to negatively impact coverage stats. --- .../v1alpha1/channel_defaults_test.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 pkg/apis/eventing/v1alpha1/channel_defaults_test.go 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() +} From aebcad82ca6f995eea596911aca0de05817399a0 Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Tue, 18 Sep 2018 10:28:03 -0700 Subject: [PATCH 13/15] Switch to duck Conditions Encapsulates the happy/dependent condition behavior. --- Gopkg.lock | 1 + pkg/apis/eventing/v1alpha1/channel_types.go | 60 +++++++++---------- .../eventing/v1alpha1/channel_types_test.go | 33 ++++++---- .../v1alpha1/zz_generated.deepcopy.go | 19 +----- 4 files changed, 52 insertions(+), 61 deletions(-) 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/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index afd40878d0a..0b7f7ee7b12 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -20,8 +20,9 @@ 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" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -55,6 +56,12 @@ 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 Subscription 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 { @@ -94,6 +101,8 @@ type ChannelSubscriberSpec struct { 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. @@ -116,49 +125,34 @@ type ChannelStatus struct { // +optional // +patchMergeKey=type // +patchStrategy=merge - Conditions []ChannelCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` + Conditions duckv1alpha1.Conditions `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` } -type ChannelConditionType string - const ( - // ChannelConditionReady has status True when the Channel is ready to accept - // traffic. - ChannelConditionReady ChannelConditionType = "Ready" - // ChannelConditionProvisioned has status True when the Channel's backing // resources have been provisioned. - ChannelConditionProvisioned ChannelConditionType = "Provisioned" + ChannelConditionProvisioned duckv1alpha1.ConditionType = "Provisioned" ) -// ChannelCondition describes the state of a channel at a point in time. -type ChannelCondition struct { - // Type of channel condition. - Type ChannelConditionType `json:"type"` - // Status of the condition, one of True, False, Unknown. - Status corev1.ConditionStatus `json:"status"` - // LastTransitionTime from one status to another. - // We use VolatileTime in place of metav1.Time to exclude this from creating equality.Semantic - // differences (all other things held constant). - LastTransitionTime apis.VolatileTime `json:"lastTransitionTime,omitempty"` - // Reason for the condition's last transition. - Reason string `json:"reason,omitempty"` - // Message is a human readable message indicating details about the - // last transition. - Message string `json:"message,omitempty"` +func (c *Channel) GetSpecJSON() ([]byte, error) { + return json.Marshal(c.Spec) } -func (cs *ChannelStatus) GetCondition(t ChannelConditionType) *ChannelCondition { - for _, cond := range cs.Conditions { - if cond.Type == t { - return &cond - } - } - return nil +// 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) } -func (c *Channel) GetSpecJSON() ([]byte, error) { - return json.Marshal(c.Spec) +// 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 diff --git a/pkg/apis/eventing/v1alpha1/channel_types_test.go b/pkg/apis/eventing/v1alpha1/channel_types_test.go index 90fb0ce03eb..78f382ef4ca 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types_test.go +++ b/pkg/apis/eventing/v1alpha1/channel_types_test.go @@ -20,16 +20,17 @@ 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 = ChannelCondition{ - Type: ChannelConditionReady, +var condReady = duckv1alpha1.Condition{ + Type: duckv1alpha1.ConditionReady, Status: corev1.ConditionTrue, } -var condUnprovisioned = ChannelCondition{ +var condUnprovisioned = duckv1alpha1.Condition{ Type: ChannelConditionProvisioned, Status: corev1.ConditionFalse, } @@ -38,21 +39,21 @@ func TestChannelGetCondition(t *testing.T) { tests := []struct { name string cs *ChannelStatus - condQuery ChannelConditionType - want *ChannelCondition + condQuery duckv1alpha1.ConditionType + want *duckv1alpha1.Condition }{{ name: "single condition", cs: &ChannelStatus{ - Conditions: []ChannelCondition{ + Conditions: []duckv1alpha1.Condition{ condReady, }, }, - condQuery: ChannelConditionReady, + condQuery: duckv1alpha1.ConditionReady, want: &condReady, }, { name: "multiple conditions", cs: &ChannelStatus{ - Conditions: []ChannelCondition{ + Conditions: []duckv1alpha1.Condition{ condReady, condUnprovisioned, }, @@ -62,12 +63,12 @@ func TestChannelGetCondition(t *testing.T) { }, { name: "unknown condition", cs: &ChannelStatus{ - Conditions: []ChannelCondition{ + Conditions: []duckv1alpha1.Condition{ condReady, condUnprovisioned, }, }, - condQuery: ChannelConditionType("foo"), + condQuery: duckv1alpha1.ConditionType("foo"), want: nil, }} @@ -81,6 +82,18 @@ func TestChannelGetCondition(t *testing.T) { } } +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{ diff --git a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go index 7258ba1e636..ce044896091 100644 --- a/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/eventing/v1alpha1/zz_generated.deepcopy.go @@ -88,23 +88,6 @@ func (in *Channel) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelCondition) DeepCopyInto(out *ChannelCondition) { - *out = *in - in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelCondition. -func (in *ChannelCondition) DeepCopy() *ChannelCondition { - if in == nil { - return nil - } - out := new(ChannelCondition) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ChannelList) DeepCopyInto(out *ChannelList) { *out = *in @@ -184,7 +167,7 @@ func (in *ChannelStatus) DeepCopyInto(out *ChannelStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make([]ChannelCondition, len(*in)) + *out = make(duck_v1alpha1.Conditions, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } From 355ec67059c26bf4441ea85df5b0bc1b17e9f397 Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Tue, 18 Sep 2018 13:14:16 -0700 Subject: [PATCH 14/15] Correct some comments --- pkg/apis/eventing/v1alpha1/channel_types.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index 0b7f7ee7b12..1e9ed6d8801 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -31,10 +31,9 @@ import ( // +genclient:noStatus // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// Channel represents a named endpoint on which a Bus accepts event delivery and -// corresponds to the channels.channels.knative.dev CRD. The Bus handles -// provisioning channels, delivering events to Channels, and delivering events -// from Channels to their Subscriptions. +// 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 @@ -59,7 +58,7 @@ var _ webhook.GenericCRD = (*Channel)(nil) // Check that ConfigurationStatus may have its conditions managed. var _ duckv1alpha1.ConditionsAccessor = (*ChannelStatus)(nil) -// Check that Subscription implements the Conditions duck type. +// Check that Channel implements the Conditions duck type. var _ = duck.VerifyType(&Channel{}, &duckv1alpha1.Conditions{}) // ChannelSpec specifies the Provisioner backing a channel and the configuration @@ -108,7 +107,7 @@ 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 + // TODO: The above comment is only true once // https://github.com/kubernetes/kubernetes/issues/58778 is fixed. // +optional ObservedGeneration int64 `json:"observedGeneration,omitempty"` @@ -116,7 +115,7 @@ type ChannelStatus struct { // 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 + // TODO: move this to a struct that can be embedded similar to ObjectMeta and // TypeMeta. // +optional DomainInternal string `json:"domainInternal,omitempty"` From 940815b8fb5b9dd0c30070c53f93c8150f920642 Mon Sep 17 00:00:00 2001 From: Grant Rodgers Date: Tue, 18 Sep 2018 13:21:53 -0700 Subject: [PATCH 15/15] Bring back ChannelConditionReady for docs --- pkg/apis/eventing/v1alpha1/channel_types.go | 4 ++++ pkg/apis/eventing/v1alpha1/channel_types_test.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/apis/eventing/v1alpha1/channel_types.go b/pkg/apis/eventing/v1alpha1/channel_types.go index 1e9ed6d8801..4073e6b277c 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types.go +++ b/pkg/apis/eventing/v1alpha1/channel_types.go @@ -128,6 +128,10 @@ type ChannelStatus struct { } 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" diff --git a/pkg/apis/eventing/v1alpha1/channel_types_test.go b/pkg/apis/eventing/v1alpha1/channel_types_test.go index 78f382ef4ca..d177a8f5599 100644 --- a/pkg/apis/eventing/v1alpha1/channel_types_test.go +++ b/pkg/apis/eventing/v1alpha1/channel_types_test.go @@ -26,7 +26,7 @@ import ( ) var condReady = duckv1alpha1.Condition{ - Type: duckv1alpha1.ConditionReady, + Type: ChannelConditionReady, Status: corev1.ConditionTrue, }