Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ require (
k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29
knative.dev/caching v0.0.0-20200707200344-95a2aaeace0f
knative.dev/networking v0.0.0-20200707203944-725ec013d8a2
knative.dev/pkg v0.0.0-20200710163519-a0cb3d689532
knative.dev/test-infra v0.0.0-20200710160019-5b9732bc24f7
knative.dev/pkg v0.0.0-20200713031612-b09a159e12c9
knative.dev/test-infra v0.0.0-20200713045417-850e4e37918d
)

replace (
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1634,11 +1634,13 @@ knative.dev/networking v0.0.0-20200707203944-725ec013d8a2 h1:Co9j0Q4ZJxwkzVFKUc6
knative.dev/networking v0.0.0-20200707203944-725ec013d8a2/go.mod h1:e1NL29AarTcgaR240oc4GUzqHtTfTu62JNrUHN3kIG0=
knative.dev/pkg v0.0.0-20200207155214-fef852970f43/go.mod h1:pgODObA1dTyhNoFxPZTTjNWfx6F0aKsKzn+vaT9XO/Q=
knative.dev/pkg v0.0.0-20200707190344-0a8314b44495/go.mod h1:AqAJV6rYi8IGikDjJ/9ZQd9qKdkXVlesVnVjwx62YB8=
knative.dev/pkg v0.0.0-20200710163519-a0cb3d689532 h1:1dSRUstjueNPF06yxGlmeEzzMZpQJnlddA4VehDuTp8=
knative.dev/pkg v0.0.0-20200710163519-a0cb3d689532/go.mod h1:AqAJV6rYi8IGikDjJ/9ZQd9qKdkXVlesVnVjwx62YB8=
knative.dev/pkg v0.0.0-20200713031612-b09a159e12c9 h1:YSapebbZZbpH31YMSF0Egt7+IDi/og4S574eWqEXReo=
knative.dev/pkg v0.0.0-20200713031612-b09a159e12c9/go.mod h1:aWPsPIHISvZetAm/2pnz+v6Ro5EYaX704Z/Zd9rTZ4M=
knative.dev/test-infra v0.0.0-20200707183444-aed09e56ddc7/go.mod h1:RjYAhXnZqeHw9+B0zsbqSPlae0lCvjekO/nw5ZMpLCs=
knative.dev/test-infra v0.0.0-20200710160019-5b9732bc24f7 h1:fAl3pG2I323tie8kuuNlB88B7RB8WJtCrsXIKuNh1U8=
knative.dev/test-infra v0.0.0-20200710160019-5b9732bc24f7/go.mod h1:vtT6dLs/iNj8pKcfag8CSVqHKNMgyCFtU/g1pV7Bovs=
knative.dev/test-infra v0.0.0-20200713045417-850e4e37918d h1:Q3LrAYSi+Ii2yZVUiA5Y3Jr4TCU6g/XN9ClVosejpJk=
knative.dev/test-infra v0.0.0-20200713045417-850e4e37918d/go.mod h1:vtT6dLs/iNj8pKcfag8CSVqHKNMgyCFtU/g1pV7Bovs=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
Expand Down
43 changes: 43 additions & 0 deletions vendor/knative.dev/pkg/apis/duck/ducktypes/ducktypes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2020 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package ducktypes

import (
"knative.dev/pkg/apis"
)

// Implementable is implemented by the Fooable duck type that consumers
// are expected to embed as a `.status.fooable` field.
type Implementable interface {
// GetFullType returns an instance of a full resource wrapping
// an instance of this Implementable that can populate its fields
// to verify json roundtripping.
GetFullType() Populatable
}

// Populatable is implemented by a skeleton resource wrapping an Implementable
// duck type. It will generally have TypeMeta, ObjectMeta, and a Status field
// wrapping a Fooable field.
type Populatable interface {
apis.Listable

// Populate fills in all possible fields, so that we can verify that
// they roundtrip properly through JSON.
Populate()
}

const GroupName = "duck.knative.dev"
6 changes: 5 additions & 1 deletion vendor/knative.dev/pkg/apis/duck/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ limitations under the License.

package duck

import (
"knative.dev/pkg/apis/duck/ducktypes"
)

const (
GroupName = "duck.knative.dev"
GroupName = ducktypes.GroupName

// AddressableDuckVersionLabel is the label we use to declare
// that a type conforms to the Addressable duck type.
Expand Down
10 changes: 3 additions & 7 deletions vendor/knative.dev/pkg/apis/duck/v1/addressable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"

"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
"knative.dev/pkg/apis/duck/ducktypes"
)

// +genduck
Expand All @@ -40,8 +40,6 @@ type Addressable struct {
}

var (
// Addressable is an Implementable "duck type".
_ duck.Implementable = (*Addressable)(nil)
// Addressable is a Convertible type.
_ apis.Convertible = (*Addressable)(nil)
)
Expand All @@ -66,13 +64,11 @@ type AddressStatus struct {
}

var (
// Verify AddressableType resources meet duck contracts.
_ duck.Populatable = (*AddressableType)(nil)
_ apis.Listable = (*AddressableType)(nil)
_ apis.Listable = (*AddressableType)(nil)
)

// GetFullType implements duck.Implementable
func (*Addressable) GetFullType() duck.Populatable {
func (*Addressable) GetFullType() ducktypes.Populatable {
return &AddressableType{}
}

Expand Down
8 changes: 3 additions & 5 deletions vendor/knative.dev/pkg/apis/duck/v1/podspec_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"

"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
"knative.dev/pkg/apis/duck/ducktypes"
)

// +genduck
Expand Down Expand Up @@ -50,13 +50,11 @@ type WithPodSpec struct {
// Assert that we implement the interfaces necessary to
// use duck.VerifyType.
var (
_ duck.Populatable = (*WithPod)(nil)
_ duck.Implementable = (*PodSpecable)(nil)
_ apis.Listable = (*WithPod)(nil)
_ apis.Listable = (*WithPod)(nil)
)

// GetFullType implements duck.Implementable
func (*PodSpecable) GetFullType() duck.Populatable {
func (*PodSpecable) GetFullType() ducktypes.Populatable {
return &WithPod{}
}

Expand Down
5 changes: 3 additions & 2 deletions vendor/knative.dev/pkg/apis/duck/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis/duck"

"knative.dev/pkg/apis/duck/ducktypes"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: duck.GroupName, Version: "v1"}
var SchemeGroupVersion = schema.GroupVersion{Group: ducktypes.GroupName, Version: "v1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
Expand Down
11 changes: 3 additions & 8 deletions vendor/knative.dev/pkg/apis/duck/v1/source_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ import (
"k8s.io/apimachinery/pkg/runtime"

"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
"knative.dev/pkg/apis/duck/ducktypes"
)

// Source is an Implementable "duck type".
var _ duck.Implementable = (*Source)(nil)

// +genduck
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down Expand Up @@ -113,9 +110,7 @@ func (ss *SourceStatus) IsReady() bool {
}

var (
// Verify Source resources meet duck contracts.
_ duck.Populatable = (*Source)(nil)
_ apis.Listable = (*Source)(nil)
_ apis.Listable = (*Source)(nil)
)

const (
Expand All @@ -125,7 +120,7 @@ const (
)

// GetFullType implements duck.Implementable
func (*Source) GetFullType() duck.Populatable {
func (*Source) GetFullType() ducktypes.Populatable {
return &Source{}
}

Expand Down
10 changes: 2 additions & 8 deletions vendor/knative.dev/pkg/apis/duck/v1/status_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"

"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
"knative.dev/pkg/apis/duck/ducktypes"
"knative.dev/pkg/kmeta"
)

Expand All @@ -29,9 +29,6 @@ import (
// Conditions is a simple wrapper around apis.Conditions to implement duck.Implementable.
type Conditions apis.Conditions

// Conditions is an Implementable "duck type".
var _ duck.Implementable = (*Conditions)(nil)

// Status shows how we expect folks to embed Conditions in
// their Status field.
// WARNING: Adding fields to this struct will add them to all Knative resources.
Expand Down Expand Up @@ -66,14 +63,11 @@ func (s *Status) SetConditions(c apis.Conditions) {
s.Conditions = Conditions(c)
}

// In order for Conditions to be Implementable, KResource must be Populatable.
var _ duck.Populatable = (*KResource)(nil)

// Ensure KResource satisfies apis.Listable
var _ apis.Listable = (*KResource)(nil)

// GetFullType implements duck.Implementable
func (*Conditions) GetFullType() duck.Populatable {
func (*Conditions) GetFullType() ducktypes.Populatable {
return &KResource{}
}

Expand Down
78 changes: 78 additions & 0 deletions vendor/knative.dev/pkg/apis/duck/v1_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2020 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package duck

import (
"testing"

appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"

"knative.dev/pkg/apis/duck/v1"
)

// Conditions is an Implementable "duck type".
var _ Implementable = (*v1.Conditions)(nil)

// In order for Conditions to be Implementable, KResource must be Populatable.
var _ Populatable = (*v1.KResource)(nil)

// Source is an Implementable "duck type".
var _ Implementable = (*v1.Source)(nil)

// Verify Source resources meet duck contracts.
var _ Populatable = (*v1.Source)(nil)

var _ Populatable = (*v1.WithPod)(nil)
var _ Implementable = (*v1.PodSpecable)(nil)

func TestV1TypesImplements(t *testing.T) {
testCases := []struct {
instance interface{}
iface Implementable
}{
{instance: &v1.AddressableType{}, iface: &v1.Addressable{}},
{instance: &v1.KResource{}, iface: &v1.Conditions{}},
}
for _, tc := range testCases {
if err := VerifyType(tc.instance, tc.iface); err != nil {
t.Error(err)
}
}
}

func TestV1ImplementsPodSpecable(t *testing.T) {
instances := []interface{}{
&v1.WithPod{},
&appsv1.ReplicaSet{},
&appsv1.Deployment{},
&appsv1.StatefulSet{},
&appsv1.DaemonSet{},
&batchv1.Job{},
}
for _, instance := range instances {
if err := VerifyType(instance, &v1.PodSpecable{}); err != nil {
t.Error(err)
}
}
}

// Addressable is an Implementable "duck type".
var _ Implementable = (*v1.Addressable)(nil)

// Verify AddressableType resources meet duck contracts.
var _ Populatable = (*v1.AddressableType)(nil)
12 changes: 4 additions & 8 deletions vendor/knative.dev/pkg/apis/duck/v1beta1/addressable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"

"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
v1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/apis/duck/ducktypes"
"knative.dev/pkg/apis/duck/v1"
)

// +genduck
Expand All @@ -41,8 +41,6 @@ type Addressable struct {
}

var (
// Addressable is an Implementable "duck type".
_ duck.Implementable = (*Addressable)(nil)
// Addressable is a Convertible type.
_ apis.Convertible = (*Addressable)(nil)
)
Expand All @@ -67,13 +65,11 @@ type AddressStatus struct {
}

var (
// Verify AddressableType resources meet duck contracts.
_ duck.Populatable = (*AddressableType)(nil)
_ apis.Listable = (*AddressableType)(nil)
_ apis.Listable = (*AddressableType)(nil)
)

// GetFullType implements duck.Implementable
func (*Addressable) GetFullType() duck.Populatable {
func (*Addressable) GetFullType() ducktypes.Populatable {
return &AddressableType{}
}

Expand Down
5 changes: 3 additions & 2 deletions vendor/knative.dev/pkg/apis/duck/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis/duck"

"knative.dev/pkg/apis/duck/ducktypes"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: duck.GroupName, Version: "v1beta1"}
var SchemeGroupVersion = schema.GroupVersion{Group: ducktypes.GroupName, Version: "v1beta1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
Expand Down
11 changes: 3 additions & 8 deletions vendor/knative.dev/pkg/apis/duck/v1beta1/source_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ import (
"k8s.io/apimachinery/pkg/runtime"

"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
"knative.dev/pkg/apis/duck/ducktypes"
)

// Source is an Implementable "duck type".
var _ duck.Implementable = (*Source)(nil)

// +genduck
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down Expand Up @@ -98,9 +95,7 @@ func (ss *SourceStatus) IsReady() bool {
}

var (
// Verify Source resources meet duck contracts.
_ duck.Populatable = (*Source)(nil)
_ apis.Listable = (*Source)(nil)
_ apis.Listable = (*Source)(nil)
)

const (
Expand All @@ -110,7 +105,7 @@ const (
)

// GetFullType implements duck.Implementable
func (*Source) GetFullType() duck.Populatable {
func (*Source) GetFullType() ducktypes.Populatable {
return &Source{}
}

Expand Down
Loading