diff --git a/apis/duck/v1alpha1/addressable_types.go b/apis/duck/v1alpha1/addressable_types.go index a31e8ee23..48f9f99dd 100644 --- a/apis/duck/v1alpha1/addressable_types.go +++ b/apis/duck/v1alpha1/addressable_types.go @@ -22,18 +22,18 @@ import ( "github.com/knative/pkg/apis" "github.com/knative/pkg/apis/duck" + "github.com/knative/pkg/apis/duck/v1beta1" ) // Addressable provides a generic mechanism for a custom resource // definition to indicate a destination for message delivery. -// (Currently, only hostname is supported, and HTTP is implied. In the -// future, additional schemes may be supported, and path components -// ala UI may also be supported.) // Addressable is the schema for the destination information. This is // typically stored in the object's `status`, as this information may // be generated by the controller. type Addressable struct { + v1beta1.Addressable `json:",omitempty"` + Hostname string `json:"hostname,omitempty"` } diff --git a/apis/duck/v1alpha1/implements_test.go b/apis/duck/v1alpha1/implements_test.go index 1e9baad25..b8fe1edc8 100644 --- a/apis/duck/v1alpha1/implements_test.go +++ b/apis/duck/v1alpha1/implements_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/knative/pkg/apis/duck" + "github.com/knative/pkg/apis/duck/v1beta1" ) func TestTypesImplements(t *testing.T) { @@ -28,6 +29,7 @@ func TestTypesImplements(t *testing.T) { iface duck.Implementable }{ {instance: &AddressableType{}, iface: &Addressable{}}, + {instance: &AddressableType{}, iface: &v1beta1.Addressable{}}, {instance: &KResource{}, iface: &Conditions{}}, {instance: &LegacyTarget{}, iface: &LegacyTargetable{}}, {instance: &Target{}, iface: &Targetable{}}, diff --git a/apis/duck/v1alpha1/zz_generated.deepcopy.go b/apis/duck/v1alpha1/zz_generated.deepcopy.go index 80011413b..a59e67ce3 100644 --- a/apis/duck/v1alpha1/zz_generated.deepcopy.go +++ b/apis/duck/v1alpha1/zz_generated.deepcopy.go @@ -30,7 +30,7 @@ func (in *AddressStatus) DeepCopyInto(out *AddressStatus) { if in.Address != nil { in, out := &in.Address, &out.Address *out = new(Addressable) - **out = **in + (*in).DeepCopyInto(*out) } return } @@ -48,6 +48,7 @@ func (in *AddressStatus) DeepCopy() *AddressStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Addressable) DeepCopyInto(out *Addressable) { *out = *in + in.Addressable.DeepCopyInto(&out.Addressable) return } diff --git a/apis/duck/v1beta1/addressable_types.go b/apis/duck/v1beta1/addressable_types.go new file mode 100644 index 000000000..379098e7f --- /dev/null +++ b/apis/duck/v1beta1/addressable_types.go @@ -0,0 +1,97 @@ +/* +Copyright 2019 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + + "github.com/knative/pkg/apis" + "github.com/knative/pkg/apis/duck" +) + +// Addressable provides a generic mechanism for a custom resource +// definition to indicate a destination for message delivery. + +// Addressable is the schema for the destination information. This is +// typically stored in the object's `status`, as this information may +// be generated by the controller. +type Addressable struct { + URL *apis.URL `json:"url,omitempty"` +} + +// Addressable is an Implementable "duck type". +var _ duck.Implementable = (*Addressable)(nil) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// AddressableType is a skeleton type wrapping Addressable in the manner we expect +// resource writers defining compatible resources to embed it. We will +// typically use this type to deserialize Addressable ObjectReferences and +// access the Addressable data. This is not a real resource. +type AddressableType struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Status AddressStatus `json:"status"` +} + +// AddressStatus shows how we expect folks to embed Addressable in +// their Status field. +type AddressStatus struct { + Address *Addressable `json:"address,omitempty"` +} + +var ( + // Verify AddressableType resources meet duck contracts. + _ duck.Populatable = (*AddressableType)(nil) + _ apis.Listable = (*AddressableType)(nil) +) + +// GetFullType implements duck.Implementable +func (*Addressable) GetFullType() duck.Populatable { + return &AddressableType{} +} + +// Populate implements duck.Populatable +func (t *AddressableType) Populate() { + t.Status = AddressStatus{ + &Addressable{ + // Populate ALL fields + URL: &apis.URL{ + Scheme: "http", + Host: "foo.com", + }, + }, + } +} + +// GetListType implements apis.Listable +func (*AddressableType) GetListType() runtime.Object { + return &AddressableTypeList{} +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// AddressableTypeList is a list of AddressableType resources +type AddressableTypeList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []AddressableType `json:"items"` +} diff --git a/apis/duck/v1beta1/implements_test.go b/apis/duck/v1beta1/implements_test.go new file mode 100644 index 000000000..8b5e31be5 --- /dev/null +++ b/apis/duck/v1beta1/implements_test.go @@ -0,0 +1,38 @@ +/* +Copyright 2019 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + "testing" + + "github.com/knative/pkg/apis/duck" +) + +func TestTypesImplements(t *testing.T) { + testCases := []struct { + instance interface{} + iface duck.Implementable + }{ + {instance: &AddressableType{}, iface: &Addressable{}}, + {instance: &KResource{}, iface: &Conditions{}}, + } + for _, tc := range testCases { + if err := duck.VerifyType(tc.instance, tc.iface); err != nil { + t.Error(err) + } + } +} diff --git a/apis/duck/v1beta1/register.go b/apis/duck/v1beta1/register.go index b3e38c404..c337e4a61 100644 --- a/apis/duck/v1beta1/register.go +++ b/apis/duck/v1beta1/register.go @@ -47,6 +47,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { SchemeGroupVersion, &KResource{}, (&KResource{}).GetListType(), + &AddressableType{}, + (&AddressableType{}).GetListType(), ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/apis/duck/v1beta1/status_types_test.go b/apis/duck/v1beta1/status_types_test.go index 8b3c95ef0..f01983877 100644 --- a/apis/duck/v1beta1/status_types_test.go +++ b/apis/duck/v1beta1/status_types_test.go @@ -22,24 +22,9 @@ import ( "github.com/google/go-cmp/cmp" "github.com/knative/pkg/apis" - "github.com/knative/pkg/apis/duck" corev1 "k8s.io/api/core/v1" ) -func TestTypesImplements(t *testing.T) { - testCases := []struct { - instance interface{} - iface duck.Implementable - }{ - {instance: &KResource{}, iface: &Conditions{}}, - } - for _, tc := range testCases { - if err := duck.VerifyType(tc.instance, tc.iface); err != nil { - t.Error(err) - } - } -} - func TestStatusGetCondition(t *testing.T) { foo := &apis.Condition{ Type: "Foo", diff --git a/apis/duck/v1beta1/zz_generated.deepcopy.go b/apis/duck/v1beta1/zz_generated.deepcopy.go index bdbc0471c..791c06d96 100644 --- a/apis/duck/v1beta1/zz_generated.deepcopy.go +++ b/apis/duck/v1beta1/zz_generated.deepcopy.go @@ -21,9 +21,112 @@ limitations under the License. package v1beta1 import ( + apis "github.com/knative/pkg/apis" runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AddressStatus) DeepCopyInto(out *AddressStatus) { + *out = *in + if in.Address != nil { + in, out := &in.Address, &out.Address + *out = new(Addressable) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddressStatus. +func (in *AddressStatus) DeepCopy() *AddressStatus { + if in == nil { + return nil + } + out := new(AddressStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Addressable) DeepCopyInto(out *Addressable) { + *out = *in + if in.URL != nil { + in, out := &in.URL, &out.URL + *out = new(apis.URL) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Addressable. +func (in *Addressable) DeepCopy() *Addressable { + if in == nil { + return nil + } + out := new(Addressable) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AddressableType) DeepCopyInto(out *AddressableType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddressableType. +func (in *AddressableType) DeepCopy() *AddressableType { + if in == nil { + return nil + } + out := new(AddressableType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AddressableType) 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 *AddressableTypeList) DeepCopyInto(out *AddressableTypeList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]AddressableType, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddressableTypeList. +func (in *AddressableTypeList) DeepCopy() *AddressableTypeList { + if in == nil { + return nil + } + out := new(AddressableTypeList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AddressableTypeList) 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 Conditions) DeepCopyInto(out *Conditions) { {