From f0945e7bd3a035a3c211319a258a8f1370cba089 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Mon, 13 Apr 2020 12:58:11 -0700 Subject: [PATCH] Create pkg/duck/{v1alpha1,v1beta1} (#811) * Move pkg/duck to pkg/duck/v1alpha1. * Create v1beta1 and change package name. --- .../v1alpha1/cloudauditlogssource_types.go | 2 +- .../events/v1alpha1/cloudbuildsource_types.go | 2 +- .../v1alpha1/cloudpubsubsource_types.go | 2 +- .../v1alpha1/cloudschedulersource_types.go | 2 +- .../v1alpha1/cloudstoragesource_types.go | 2 +- pkg/apis/messaging/v1alpha1/channel_types.go | 4 +-- pkg/duck/{ => v1alpha1}/identifiable.go | 2 +- pkg/duck/{ => v1alpha1}/pubsubable.go | 2 +- pkg/duck/v1beta1/identifiable.go | 34 +++++++++++++++++++ pkg/duck/v1beta1/pubsubable.go | 31 +++++++++++++++++ pkg/reconciler/identity/reconciler.go | 2 +- pkg/reconciler/pubsub/reconciler.go | 2 +- 12 files changed, 76 insertions(+), 11 deletions(-) rename pkg/duck/{ => v1alpha1}/identifiable.go (98%) rename pkg/duck/{ => v1alpha1}/pubsubable.go (98%) create mode 100644 pkg/duck/v1beta1/identifiable.go create mode 100644 pkg/duck/v1beta1/pubsubable.go diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_types.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_types.go index 00fdc88c14..c1e48c586a 100644 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_types.go +++ b/pkg/apis/events/v1alpha1/cloudauditlogssource_types.go @@ -28,7 +28,7 @@ import ( "knative.dev/pkg/webhook/resourcesemantics" duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck" + kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" duckv1 "knative.dev/pkg/apis/duck/v1" ) diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_types.go b/pkg/apis/events/v1alpha1/cloudbuildsource_types.go index 3cbbc2ed8b..9fa479ca77 100644 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_types.go +++ b/pkg/apis/events/v1alpha1/cloudbuildsource_types.go @@ -17,7 +17,7 @@ import ( "fmt" duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck" + kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis/duck" "knative.dev/pkg/kmeta" diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_types.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_types.go index 9599e769d8..7142c5bff8 100644 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_types.go +++ b/pkg/apis/events/v1alpha1/cloudpubsubsource_types.go @@ -21,7 +21,7 @@ import ( "time" duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck" + kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis/duck" "knative.dev/pkg/kmeta" diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_types.go b/pkg/apis/events/v1alpha1/cloudschedulersource_types.go index cd8681f210..5ec5c7d24a 100644 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_types.go +++ b/pkg/apis/events/v1alpha1/cloudschedulersource_types.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck" + kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_types.go b/pkg/apis/events/v1alpha1/cloudstoragesource_types.go index 010a5fa15f..76e0dbb4ce 100644 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_types.go +++ b/pkg/apis/events/v1alpha1/cloudstoragesource_types.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck" + kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" diff --git a/pkg/apis/messaging/v1alpha1/channel_types.go b/pkg/apis/messaging/v1alpha1/channel_types.go index afc60d3c8a..d224f533c1 100644 --- a/pkg/apis/messaging/v1alpha1/channel_types.go +++ b/pkg/apis/messaging/v1alpha1/channel_types.go @@ -27,7 +27,7 @@ import ( "knative.dev/pkg/webhook/resourcesemantics" duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/duck" + kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" ) // +genclient @@ -55,7 +55,7 @@ var ( _ apis.Defaultable = (*Channel)(nil) _ runtime.Object = (*Channel)(nil) _ resourcesemantics.GenericCRD = (*Channel)(nil) - _ duck.Identifiable = (*Channel)(nil) + _ kngcpduck.Identifiable = (*Channel)(nil) ) // ChannelSpec defines which subscribers have expressed interest in diff --git a/pkg/duck/identifiable.go b/pkg/duck/v1alpha1/identifiable.go similarity index 98% rename from pkg/duck/identifiable.go rename to pkg/duck/v1alpha1/identifiable.go index 371fc9ae08..9a7761abc4 100644 --- a/pkg/duck/identifiable.go +++ b/pkg/duck/v1alpha1/identifiable.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package duck +package v1alpha1 import ( "knative.dev/pkg/apis" diff --git a/pkg/duck/pubsubable.go b/pkg/duck/v1alpha1/pubsubable.go similarity index 98% rename from pkg/duck/pubsubable.go rename to pkg/duck/v1alpha1/pubsubable.go index 0e91d14a7d..d1888d46cb 100644 --- a/pkg/duck/pubsubable.go +++ b/pkg/duck/v1alpha1/pubsubable.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package duck +package v1alpha1 import ( duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" diff --git a/pkg/duck/v1beta1/identifiable.go b/pkg/duck/v1beta1/identifiable.go new file mode 100644 index 0000000000..9cdc66f9ec --- /dev/null +++ b/pkg/duck/v1beta1/identifiable.go @@ -0,0 +1,34 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + "knative.dev/pkg/apis" + "knative.dev/pkg/kmeta" + + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" +) + +type Identifiable interface { + kmeta.OwnerRefable + // IdentitySpec returns the IdentitySpec portion of the Spec. + IdentitySpec() *duckv1beta1.IdentitySpec + // IdentityStatus returns the IdentityStatus portion of the Status. + IdentityStatus() *duckv1beta1.IdentityStatus + // ConditionSet returns the apis.ConditionSet of the embedding object + ConditionSet() *apis.ConditionSet +} diff --git a/pkg/duck/v1beta1/pubsubable.go b/pkg/duck/v1beta1/pubsubable.go new file mode 100644 index 0000000000..19adacbd55 --- /dev/null +++ b/pkg/duck/v1beta1/pubsubable.go @@ -0,0 +1,31 @@ +/* +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 ( + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" +) + +// PubSubable is an interface that each duckv1beta1.PubSub duck type must +// support in order to get reconciled properly in a generic way. +type PubSubable interface { + Identifiable + // PubSubSpec returns the PubSubSpec portion of the Spec. + PubSubSpec() *duckv1beta1.PubSubSpec + // PubSubStatus returns the PubSubStatus portion of the Status. + PubSubStatus() *duckv1beta1.PubSubStatus +} diff --git a/pkg/reconciler/identity/reconciler.go b/pkg/reconciler/identity/reconciler.go index 7cbd307d63..b3a726ab27 100644 --- a/pkg/reconciler/identity/reconciler.go +++ b/pkg/reconciler/identity/reconciler.go @@ -36,7 +36,7 @@ import ( "knative.dev/pkg/logging" "knative.dev/pkg/ptr" - "github.com/google/knative-gcp/pkg/duck" + duck "github.com/google/knative-gcp/pkg/duck/v1alpha1" "github.com/google/knative-gcp/pkg/reconciler/identity/resources" "github.com/google/knative-gcp/pkg/utils" ) diff --git a/pkg/reconciler/pubsub/reconciler.go b/pkg/reconciler/pubsub/reconciler.go index 1f4f99a605..d2ea8ddd59 100644 --- a/pkg/reconciler/pubsub/reconciler.go +++ b/pkg/reconciler/pubsub/reconciler.go @@ -23,7 +23,7 @@ import ( duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" pubsubv1alpha1 "github.com/google/knative-gcp/pkg/apis/pubsub/v1alpha1" clientset "github.com/google/knative-gcp/pkg/client/clientset/versioned" - "github.com/google/knative-gcp/pkg/duck" + duck "github.com/google/knative-gcp/pkg/duck/v1alpha1" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/pubsub/resources" "go.uber.org/zap"