From 9b9bde18923ad2f6e731ad3c66825ad420cbb4be Mon Sep 17 00:00:00 2001 From: Lu Dang Date: Mon, 26 Oct 2020 15:43:42 -0400 Subject: [PATCH] Remove v1alpha1 support for knative-gcp sources and Pub/Sub core resources (#1858) the following resources are affected: - CloudPubSubSource - CloudStorageSource - CloudSchedulerSource - CloudAuditLogsSource - CloudBuildSource - Topic - PullSubscription --- cmd/webhook/main.go | 97 +- config/core/resources/channel.yaml | 2 + .../core/resources/cloudauditlogssource.yaml | 4 +- config/core/resources/cloudbuildsource.yaml | 4 +- config/core/resources/cloudpubsubsource.yaml | 4 +- .../core/resources/cloudschedulersource.yaml | 4 +- config/core/resources/cloudstoragesource.yaml | 4 +- config/core/resources/pullsubscription.yaml | 4 +- config/core/resources/topic.yaml | 4 +- hack/update-codegen.sh | 4 +- .../cloudauditlogssource_conversion.go | 65 -- .../cloudauditlogssource_conversion_test.go | 180 ---- .../v1alpha1/cloudauditlogssource_defaults.go | 33 - .../cloudauditlogssource_defaults_test.go | 110 --- .../cloudauditlogssource_lifecycle.go | 51 -- .../cloudauditlogssource_lifecycle_test.go | 198 ----- .../v1alpha1/cloudauditlogssource_types.go | 129 --- .../cloudauditlogssource_types_test.go | 99 --- .../cloudauditlogssource_validation.go | 90 -- .../cloudauditlogssource_validation_test.go | 508 ----------- .../v1alpha1/cloudbuildsource_conversion.go | 59 -- .../cloudbuildsource_conversion_test.go | 119 --- .../v1alpha1/cloudbuildsource_defaults.go | 47 - .../cloudbuildsource_defaults_test.go | 142 --- .../v1alpha1/cloudbuildsource_lifecycle.go | 41 - .../cloudbuildsource_lifecycle_test.go | 158 ---- .../events/v1alpha1/cloudbuildsource_types.go | 127 --- .../v1alpha1/cloudbuildsource_types_test.go | 102 --- .../v1alpha1/cloudbuildsource_validation.go | 81 -- .../cloudbuildsource_validation_test.go | 507 ----------- .../v1alpha1/cloudpubsubsource_conversion.go | 65 -- .../cloudpubsubsource_conversion_test.go | 181 ---- .../v1alpha1/cloudpubsubsource_defaults.go | 49 -- .../cloudpubsubsource_defaults_test.go | 152 ---- .../v1alpha1/cloudpubsubsource_lifecycle.go | 41 - .../cloudpubsubsource_lifecycle_test.go | 157 ---- .../v1alpha1/cloudpubsubsource_types.go | 168 ---- .../v1alpha1/cloudpubsubsource_types_test.go | 139 --- .../v1alpha1/cloudpubsubsource_validation.go | 105 --- .../cloudpubsubsource_validation_test.go | 657 -------------- .../cloudschedulersource_conversion.go | 65 -- .../cloudschedulersource_conversion_test.go | 181 ---- .../v1alpha1/cloudschedulersource_defaults.go | 33 - .../cloudschedulersource_defaults_test.go | 109 --- .../cloudschedulersource_lifecycle.go | 54 -- .../cloudschedulersource_lifecycle_test.go | 201 ----- .../v1alpha1/cloudschedulersource_types.go | 136 --- .../cloudschedulersource_types_test.go | 99 --- .../cloudschedulersource_validation.go | 94 -- .../cloudschedulersource_validation_test.go | 679 -------------- .../v1alpha1/cloudstoragesource_conversion.go | 70 -- .../cloudstoragesource_conversion_test.go | 184 ---- .../v1alpha1/cloudstoragesource_defaults.go | 48 - .../cloudstoragesource_defaults_test.go | 176 ---- .../v1alpha1/cloudstoragesource_lifecycle.go | 52 -- .../cloudstoragesource_lifecycle_test.go | 200 ----- .../v1alpha1/cloudstoragesource_types.go | 144 --- .../v1alpha1/cloudstoragesource_types_test.go | 98 --- .../v1alpha1/cloudstoragesource_validation.go | 85 -- .../cloudstoragesource_validation_test.go | 689 --------------- pkg/apis/events/v1alpha1/doc.go | 23 - pkg/apis/events/v1alpha1/implements_test.go | 42 - pkg/apis/events/v1alpha1/register.go | 61 -- pkg/apis/events/v1alpha1/register_test.go | 71 -- .../events/v1alpha1/zz_generated.deepcopy.go | 520 ----------- .../v1beta1/cloudpubsubsource_conversion.go | 4 +- .../cloudschedulersource_conversion.go | 4 +- .../intevents/v1alpha1/implements_test.go | 41 - .../v1alpha1/pullsubscription_conversion.go | 114 --- .../pullsubscription_conversion_test.go | 187 ---- .../v1alpha1/pullsubscription_defaults.go | 57 -- .../pullsubscription_defaults_test.go | 233 ----- .../v1alpha1/pullsubscription_lifecycle.go | 105 --- .../pullsubscription_lifecycle_test.go | 457 ---------- .../v1alpha1/pullsubscription_types.go | 217 ----- .../v1alpha1/pullsubscription_types_test.go | 155 ---- .../v1alpha1/pullsubscription_validation.go | 137 --- .../pullsubscription_validation_test.go | 828 ------------------ pkg/apis/intevents/v1alpha1/register.go | 4 - pkg/apis/intevents/v1alpha1/register_test.go | 16 - .../intevents/v1alpha1/topic_conversion.go | 121 --- .../v1alpha1/topic_conversion_test.go | 237 ----- pkg/apis/intevents/v1alpha1/topic_defaults.go | 62 -- .../intevents/v1alpha1/topic_defaults_test.go | 92 -- .../intevents/v1alpha1/topic_lifecycle.go | 126 --- .../v1alpha1/topic_lifecycle_test.go | 211 ----- pkg/apis/intevents/v1alpha1/topic_types.go | 183 ---- .../intevents/v1alpha1/topic_types_test.go | 93 -- .../intevents/v1alpha1/topic_validation.go | 81 -- .../v1alpha1/topic_validation_test.go | 294 ------- .../v1alpha1/zz_generated.deepcopy.go | 224 ----- .../v1beta1/pullsubscription_conversion.go | 2 +- pkg/client/clientset/versioned/clientset.go | 14 - .../versioned/fake/clientset_generated.go | 7 - .../clientset/versioned/fake/register.go | 2 - .../clientset/versioned/scheme/register.go | 2 - .../events/v1alpha1/cloudauditlogssource.go | 195 ----- .../typed/events/v1alpha1/cloudbuildsource.go | 195 ----- .../events/v1alpha1/cloudpubsubsource.go | 195 ----- .../events/v1alpha1/cloudschedulersource.go | 195 ----- .../events/v1alpha1/cloudstoragesource.go | 195 ----- .../versioned/typed/events/v1alpha1/doc.go | 20 - .../typed/events/v1alpha1/events_client.go | 109 --- .../typed/events/v1alpha1/fake/doc.go | 20 - .../fake/fake_cloudauditlogssource.go | 142 --- .../v1alpha1/fake/fake_cloudbuildsource.go | 142 --- .../v1alpha1/fake/fake_cloudpubsubsource.go | 142 --- .../fake/fake_cloudschedulersource.go | 142 --- .../v1alpha1/fake/fake_cloudstoragesource.go | 142 --- .../v1alpha1/fake/fake_events_client.go | 56 -- .../events/v1alpha1/generated_expansion.go | 29 - .../v1alpha1/fake/fake_intevents_client.go | 8 - .../v1alpha1/fake/fake_pullsubscription.go | 142 --- .../intevents/v1alpha1/fake/fake_topic.go | 142 --- .../intevents/v1alpha1/generated_expansion.go | 4 - .../intevents/v1alpha1/intevents_client.go | 10 - .../intevents/v1alpha1/pullsubscription.go | 195 ----- .../typed/intevents/v1alpha1/topic.go | 195 ----- .../externalversions/events/interface.go | 8 - .../events/v1alpha1/cloudauditlogssource.go | 90 -- .../events/v1alpha1/cloudbuildsource.go | 90 -- .../events/v1alpha1/cloudpubsubsource.go | 90 -- .../events/v1alpha1/cloudschedulersource.go | 90 -- .../events/v1alpha1/cloudstoragesource.go | 90 -- .../events/v1alpha1/interface.go | 73 -- .../informers/externalversions/generic.go | 21 +- .../intevents/v1alpha1/interface.go | 14 - .../intevents/v1alpha1/pullsubscription.go | 90 -- .../intevents/v1alpha1/topic.go | 90 -- .../cloudauditlogssource.go | 52 -- .../cloudauditlogssource/fake/fake.go | 40 - .../cloudbuildsource/cloudbuildsource.go | 52 -- .../v1alpha1/cloudbuildsource/fake/fake.go | 40 - .../cloudpubsubsource/cloudpubsubsource.go | 52 -- .../v1alpha1/cloudpubsubsource/fake/fake.go | 40 - .../cloudschedulersource.go | 52 -- .../cloudschedulersource/fake/fake.go | 40 - .../cloudstoragesource/cloudstoragesource.go | 52 -- .../v1alpha1/cloudstoragesource/fake/fake.go | 40 - .../v1alpha1/pullsubscription/fake/fake.go | 40 - .../pullsubscription/pullsubscription.go | 52 -- .../intevents/v1alpha1/topic/fake/fake.go | 40 - .../intevents/v1alpha1/topic/topic.go | 52 -- .../events/v1alpha1/cloudauditlogssource.go | 94 -- .../events/v1alpha1/cloudbuildsource.go | 94 -- .../events/v1alpha1/cloudpubsubsource.go | 94 -- .../events/v1alpha1/cloudschedulersource.go | 94 -- .../events/v1alpha1/cloudstoragesource.go | 94 -- .../intevents/v1alpha1/expansion_generated.go | 16 - .../intevents/v1alpha1/pullsubscription.go | 94 -- .../listers/intevents/v1alpha1/topic.go | 94 -- pkg/reconciler/deployment/deployment_test.go | 4 +- pkg/reconciler/testing/v1alpha1/auditlogs.go | 82 -- pkg/reconciler/testing/v1alpha1/build.go | 63 -- pkg/reconciler/testing/v1alpha1/pubsub.go | 68 -- .../testing/v1alpha1/pullsubscription.go | 76 -- pkg/reconciler/testing/v1alpha1/scheduler.go | 81 -- pkg/reconciler/testing/v1alpha1/storage.go | 238 ----- test/e2e/e2e_test.go | 50 +- test/e2e/test_auditlogs.go | 4 +- test/e2e/test_build.go | 4 +- test/e2e/test_pubsub.go | 4 +- test/e2e/test_pullsubscription.go | 4 +- test/e2e/test_scheduler.go | 4 +- test/e2e/test_storage.go | 4 +- test/lib/auditlogs.go | 17 - test/lib/build.go | 14 - test/lib/creation.go | 74 -- test/lib/pubsub.go | 13 - test/lib/pullsubscription.go | 14 - test/lib/scheduler.go | 17 - test/lib/storage.go | 14 - 172 files changed, 74 insertions(+), 18569 deletions(-) delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_conversion.go delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_conversion_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_defaults.go delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_defaults_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_lifecycle.go delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_lifecycle_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_types.go delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_types_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_validation.go delete mode 100644 pkg/apis/events/v1alpha1/cloudauditlogssource_validation_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_defaults.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_defaults_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_lifecycle.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_lifecycle_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_types.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_types_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_validation.go delete mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_validation_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_conversion.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_conversion_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_defaults.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_defaults_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_lifecycle.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_lifecycle_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_types.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_types_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_validation.go delete mode 100644 pkg/apis/events/v1alpha1/cloudpubsubsource_validation_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_conversion.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_conversion_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_defaults.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_defaults_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_lifecycle.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_lifecycle_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_types.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_types_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_validation.go delete mode 100644 pkg/apis/events/v1alpha1/cloudschedulersource_validation_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_conversion.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_conversion_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_defaults.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_defaults_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_lifecycle.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_lifecycle_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_types.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_types_test.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_validation.go delete mode 100644 pkg/apis/events/v1alpha1/cloudstoragesource_validation_test.go delete mode 100644 pkg/apis/events/v1alpha1/doc.go delete mode 100644 pkg/apis/events/v1alpha1/implements_test.go delete mode 100644 pkg/apis/events/v1alpha1/register.go delete mode 100644 pkg/apis/events/v1alpha1/register_test.go delete mode 100644 pkg/apis/events/v1alpha1/zz_generated.deepcopy.go delete mode 100644 pkg/apis/intevents/v1alpha1/implements_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_conversion.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_conversion_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_defaults.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_defaults_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_lifecycle.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_lifecycle_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_types.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_types_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_validation.go delete mode 100644 pkg/apis/intevents/v1alpha1/pullsubscription_validation_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_conversion.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_conversion_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_defaults.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_defaults_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_lifecycle.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_lifecycle_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_types.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_types_test.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_validation.go delete mode 100644 pkg/apis/intevents/v1alpha1/topic_validation_test.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/cloudauditlogssource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/cloudbuildsource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/cloudpubsubsource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/cloudschedulersource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/cloudstoragesource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/doc.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/events_client.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/fake/doc.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudauditlogssource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudbuildsource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudpubsubsource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudschedulersource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudstoragesource.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_events_client.go delete mode 100644 pkg/client/clientset/versioned/typed/events/v1alpha1/generated_expansion.go delete mode 100644 pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_pullsubscription.go delete mode 100644 pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_topic.go delete mode 100644 pkg/client/clientset/versioned/typed/intevents/v1alpha1/pullsubscription.go delete mode 100644 pkg/client/clientset/versioned/typed/intevents/v1alpha1/topic.go delete mode 100644 pkg/client/informers/externalversions/events/v1alpha1/cloudauditlogssource.go delete mode 100644 pkg/client/informers/externalversions/events/v1alpha1/cloudbuildsource.go delete mode 100644 pkg/client/informers/externalversions/events/v1alpha1/cloudpubsubsource.go delete mode 100644 pkg/client/informers/externalversions/events/v1alpha1/cloudschedulersource.go delete mode 100644 pkg/client/informers/externalversions/events/v1alpha1/cloudstoragesource.go delete mode 100644 pkg/client/informers/externalversions/events/v1alpha1/interface.go delete mode 100644 pkg/client/informers/externalversions/intevents/v1alpha1/pullsubscription.go delete mode 100644 pkg/client/informers/externalversions/intevents/v1alpha1/topic.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource/cloudauditlogssource.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource/fake/fake.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudbuildsource/cloudbuildsource.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudbuildsource/fake/fake.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource/cloudpubsubsource.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource/fake/fake.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudschedulersource/cloudschedulersource.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudschedulersource/fake/fake.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudstoragesource/cloudstoragesource.go delete mode 100644 pkg/client/injection/informers/events/v1alpha1/cloudstoragesource/fake/fake.go delete mode 100644 pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake/fake.go delete mode 100644 pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/pullsubscription.go delete mode 100644 pkg/client/injection/informers/intevents/v1alpha1/topic/fake/fake.go delete mode 100644 pkg/client/injection/informers/intevents/v1alpha1/topic/topic.go delete mode 100644 pkg/client/listers/events/v1alpha1/cloudauditlogssource.go delete mode 100644 pkg/client/listers/events/v1alpha1/cloudbuildsource.go delete mode 100644 pkg/client/listers/events/v1alpha1/cloudpubsubsource.go delete mode 100644 pkg/client/listers/events/v1alpha1/cloudschedulersource.go delete mode 100644 pkg/client/listers/events/v1alpha1/cloudstoragesource.go delete mode 100644 pkg/client/listers/intevents/v1alpha1/pullsubscription.go delete mode 100644 pkg/client/listers/intevents/v1alpha1/topic.go delete mode 100644 pkg/reconciler/testing/v1alpha1/auditlogs.go delete mode 100644 pkg/reconciler/testing/v1alpha1/build.go delete mode 100644 pkg/reconciler/testing/v1alpha1/pubsub.go delete mode 100644 pkg/reconciler/testing/v1alpha1/pullsubscription.go delete mode 100644 pkg/reconciler/testing/v1alpha1/scheduler.go delete mode 100644 pkg/reconciler/testing/v1alpha1/storage.go diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index adc3205402..8debd2e4b1 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -26,7 +26,6 @@ import ( "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" "github.com/google/knative-gcp/pkg/apis/events" eventsv1 "github.com/google/knative-gcp/pkg/apis/events/v1" - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" eventsv1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" "github.com/google/knative-gcp/pkg/apis/intevents" inteventsv1 "github.com/google/knative-gcp/pkg/apis/intevents/v1" @@ -60,30 +59,23 @@ var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{ messagingv1beta1.SchemeGroupVersion.WithKind("Channel"): &messagingv1beta1.Channel{}, // For group events.cloud.google.com. - eventsv1alpha1.SchemeGroupVersion.WithKind("CloudStorageSource"): &eventsv1alpha1.CloudStorageSource{}, - eventsv1alpha1.SchemeGroupVersion.WithKind("CloudSchedulerSource"): &eventsv1alpha1.CloudSchedulerSource{}, - eventsv1alpha1.SchemeGroupVersion.WithKind("CloudPubSubSource"): &eventsv1alpha1.CloudPubSubSource{}, - eventsv1alpha1.SchemeGroupVersion.WithKind("CloudAuditLogsSource"): &eventsv1alpha1.CloudAuditLogsSource{}, - eventsv1alpha1.SchemeGroupVersion.WithKind("CloudBuildSource"): &eventsv1alpha1.CloudBuildSource{}, - eventsv1beta1.SchemeGroupVersion.WithKind("CloudStorageSource"): &eventsv1beta1.CloudStorageSource{}, - eventsv1beta1.SchemeGroupVersion.WithKind("CloudSchedulerSource"): &eventsv1beta1.CloudSchedulerSource{}, - eventsv1beta1.SchemeGroupVersion.WithKind("CloudPubSubSource"): &eventsv1beta1.CloudPubSubSource{}, - eventsv1beta1.SchemeGroupVersion.WithKind("CloudAuditLogsSource"): &eventsv1beta1.CloudAuditLogsSource{}, - eventsv1beta1.SchemeGroupVersion.WithKind("CloudBuildSource"): &eventsv1beta1.CloudBuildSource{}, - eventsv1.SchemeGroupVersion.WithKind("CloudStorageSource"): &eventsv1.CloudStorageSource{}, - eventsv1.SchemeGroupVersion.WithKind("CloudSchedulerSource"): &eventsv1.CloudSchedulerSource{}, - eventsv1.SchemeGroupVersion.WithKind("CloudPubSubSource"): &eventsv1.CloudPubSubSource{}, - eventsv1.SchemeGroupVersion.WithKind("CloudAuditLogsSource"): &eventsv1.CloudAuditLogsSource{}, - eventsv1.SchemeGroupVersion.WithKind("CloudBuildSource"): &eventsv1.CloudBuildSource{}, + eventsv1beta1.SchemeGroupVersion.WithKind("CloudStorageSource"): &eventsv1beta1.CloudStorageSource{}, + eventsv1beta1.SchemeGroupVersion.WithKind("CloudSchedulerSource"): &eventsv1beta1.CloudSchedulerSource{}, + eventsv1beta1.SchemeGroupVersion.WithKind("CloudPubSubSource"): &eventsv1beta1.CloudPubSubSource{}, + eventsv1beta1.SchemeGroupVersion.WithKind("CloudAuditLogsSource"): &eventsv1beta1.CloudAuditLogsSource{}, + eventsv1beta1.SchemeGroupVersion.WithKind("CloudBuildSource"): &eventsv1beta1.CloudBuildSource{}, + eventsv1.SchemeGroupVersion.WithKind("CloudStorageSource"): &eventsv1.CloudStorageSource{}, + eventsv1.SchemeGroupVersion.WithKind("CloudSchedulerSource"): &eventsv1.CloudSchedulerSource{}, + eventsv1.SchemeGroupVersion.WithKind("CloudPubSubSource"): &eventsv1.CloudPubSubSource{}, + eventsv1.SchemeGroupVersion.WithKind("CloudAuditLogsSource"): &eventsv1.CloudAuditLogsSource{}, + eventsv1.SchemeGroupVersion.WithKind("CloudBuildSource"): &eventsv1.CloudBuildSource{}, // For group internal.events.cloud.google.com. - inteventsv1alpha1.SchemeGroupVersion.WithKind("PullSubscription"): &inteventsv1alpha1.PullSubscription{}, - inteventsv1alpha1.SchemeGroupVersion.WithKind("Topic"): &inteventsv1alpha1.Topic{}, - inteventsv1beta1.SchemeGroupVersion.WithKind("PullSubscription"): &inteventsv1beta1.PullSubscription{}, - inteventsv1beta1.SchemeGroupVersion.WithKind("Topic"): &inteventsv1beta1.Topic{}, - inteventsv1.SchemeGroupVersion.WithKind("PullSubscription"): &inteventsv1.PullSubscription{}, - inteventsv1.SchemeGroupVersion.WithKind("Topic"): &inteventsv1.Topic{}, - inteventsv1alpha1.SchemeGroupVersion.WithKind("BrokerCell"): &inteventsv1alpha1.BrokerCell{}, + inteventsv1beta1.SchemeGroupVersion.WithKind("PullSubscription"): &inteventsv1beta1.PullSubscription{}, + inteventsv1beta1.SchemeGroupVersion.WithKind("Topic"): &inteventsv1beta1.Topic{}, + inteventsv1.SchemeGroupVersion.WithKind("PullSubscription"): &inteventsv1.PullSubscription{}, + inteventsv1.SchemeGroupVersion.WithKind("Topic"): &inteventsv1.Topic{}, + inteventsv1alpha1.SchemeGroupVersion.WithKind("BrokerCell"): &inteventsv1alpha1.BrokerCell{}, } type defaultingAdmissionController func(context.Context, configmap.Watcher) *controller.Impl @@ -185,12 +177,10 @@ func newConversionConstructor(brokers *broker.StoreSingleton, gcpas *gcpauth.Sto func newConversionController(ctx context.Context, cmw configmap.Watcher, brokers *broker.Store, gcpas *gcpauth.Store) *controller.Impl { var ( - eventsv1alpha1_ = eventsv1alpha1.SchemeGroupVersion.Version - eventsv1beta1_ = eventsv1beta1.SchemeGroupVersion.Version - eventsv1_ = eventsv1.SchemeGroupVersion.Version - inteventsv1alpha1_ = inteventsv1alpha1.SchemeGroupVersion.Version - inteventsv1beta1_ = inteventsv1beta1.SchemeGroupVersion.Version - inteventsv1_ = inteventsv1.SchemeGroupVersion.Version + eventsv1beta1_ = eventsv1beta1.SchemeGroupVersion.Version + eventsv1_ = eventsv1.SchemeGroupVersion.Version + inteventsv1beta1_ = inteventsv1beta1.SchemeGroupVersion.Version + inteventsv1_ = inteventsv1.SchemeGroupVersion.Version ) // Decorate contexts with the current state of the config. @@ -207,66 +197,59 @@ func newConversionController(ctx context.Context, cmw configmap.Watcher, brokers // events eventsv1.Kind("CloudAuditLogsSource"): { DefinitionName: events.CloudAuditLogsSourcesResource.String(), - HubVersion: eventsv1alpha1_, + HubVersion: eventsv1beta1_, Zygotes: map[string]conversion.ConvertibleObject{ - eventsv1alpha1_: &eventsv1alpha1.CloudAuditLogsSource{}, - eventsv1beta1_: &eventsv1beta1.CloudAuditLogsSource{}, - eventsv1_: &eventsv1.CloudAuditLogsSource{}, + eventsv1beta1_: &eventsv1beta1.CloudAuditLogsSource{}, + eventsv1_: &eventsv1.CloudAuditLogsSource{}, }, }, eventsv1.Kind("CloudPubSubSource"): { DefinitionName: events.CloudPubSubSourcesResource.String(), - HubVersion: eventsv1alpha1_, + HubVersion: eventsv1beta1_, Zygotes: map[string]conversion.ConvertibleObject{ - eventsv1alpha1_: &eventsv1alpha1.CloudPubSubSource{}, - eventsv1beta1_: &eventsv1beta1.CloudPubSubSource{}, - eventsv1_: &eventsv1.CloudPubSubSource{}, + eventsv1beta1_: &eventsv1beta1.CloudPubSubSource{}, + eventsv1_: &eventsv1.CloudPubSubSource{}, }, }, eventsv1.Kind("CloudSchedulerSource"): { DefinitionName: events.CloudSchedulerSourcesResource.String(), - HubVersion: eventsv1alpha1_, + HubVersion: eventsv1beta1_, Zygotes: map[string]conversion.ConvertibleObject{ - eventsv1alpha1_: &eventsv1alpha1.CloudSchedulerSource{}, - eventsv1beta1_: &eventsv1beta1.CloudSchedulerSource{}, - eventsv1_: &eventsv1.CloudSchedulerSource{}, + eventsv1beta1_: &eventsv1beta1.CloudSchedulerSource{}, + eventsv1_: &eventsv1.CloudSchedulerSource{}, }, }, eventsv1.Kind("CloudStorageSource"): { DefinitionName: events.CloudStorageSourcesResource.String(), - HubVersion: eventsv1alpha1_, + HubVersion: eventsv1beta1_, Zygotes: map[string]conversion.ConvertibleObject{ - eventsv1alpha1_: &eventsv1alpha1.CloudStorageSource{}, - eventsv1beta1_: &eventsv1beta1.CloudStorageSource{}, - eventsv1_: &eventsv1.CloudStorageSource{}, + eventsv1beta1_: &eventsv1beta1.CloudStorageSource{}, + eventsv1_: &eventsv1.CloudStorageSource{}, }, }, eventsv1.Kind("CloudBuildSource"): { DefinitionName: events.CloudBuildSourcesResource.String(), - HubVersion: eventsv1alpha1_, + HubVersion: eventsv1beta1_, Zygotes: map[string]conversion.ConvertibleObject{ - eventsv1alpha1_: &eventsv1alpha1.CloudBuildSource{}, - eventsv1beta1_: &eventsv1beta1.CloudBuildSource{}, - eventsv1_: &eventsv1.CloudBuildSource{}, + eventsv1beta1_: &eventsv1beta1.CloudBuildSource{}, + eventsv1_: &eventsv1.CloudBuildSource{}, }, }, // intevents inteventsv1.Kind("PullSubscription"): { DefinitionName: intevents.PullSubscriptionsResource.String(), - HubVersion: inteventsv1alpha1_, + HubVersion: inteventsv1beta1_, Zygotes: map[string]conversion.ConvertibleObject{ - inteventsv1alpha1_: &inteventsv1alpha1.PullSubscription{}, - inteventsv1beta1_: &inteventsv1beta1.PullSubscription{}, - inteventsv1_: &inteventsv1.PullSubscription{}, + inteventsv1beta1_: &inteventsv1beta1.PullSubscription{}, + inteventsv1_: &inteventsv1.PullSubscription{}, }, }, inteventsv1.Kind("Topic"): { DefinitionName: intevents.TopicsResource.String(), - HubVersion: inteventsv1alpha1_, + HubVersion: inteventsv1beta1_, Zygotes: map[string]conversion.ConvertibleObject{ - inteventsv1alpha1_: &inteventsv1alpha1.Topic{}, - inteventsv1beta1_: &inteventsv1beta1.Topic{}, - inteventsv1_: &inteventsv1.Topic{}, + inteventsv1beta1_: &inteventsv1beta1.Topic{}, + inteventsv1_: &inteventsv1.Topic{}, }, }, }, diff --git a/config/core/resources/channel.yaml b/config/core/resources/channel.yaml index c45ab384fe..de4bcff371 100644 --- a/config/core/resources/channel.yaml +++ b/config/core/resources/channel.yaml @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# TODO: merge v1alpha1 schema into v1beta1 then remove v1alpha1 schema from CRD + apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: diff --git a/config/core/resources/cloudauditlogssource.yaml b/config/core/resources/cloudauditlogssource.yaml index ba071aa460..62c65bf725 100644 --- a/config/core/resources/cloudauditlogssource.yaml +++ b/config/core/resources/cloudauditlogssource.yaml @@ -194,9 +194,9 @@ spec: description: > ID of the Stackdriver sink used to publish audit log messages. - <<: *version + # TODO: remove v1alpha1 schema from CRD name: v1alpha1 - # TODO: Flip served bit of v1alpha1 in https://github.com/google/knative-gcp/issues/1544. - served: true + served: false storage: false # v1alpha1 and v1beta have status.properties.serviceAccountName in the schema schema: &v1alpha1Schema diff --git a/config/core/resources/cloudbuildsource.yaml b/config/core/resources/cloudbuildsource.yaml index e86186a312..719a56fab4 100644 --- a/config/core/resources/cloudbuildsource.yaml +++ b/config/core/resources/cloudbuildsource.yaml @@ -191,9 +191,9 @@ spec: storage: false schema: *v1Schema - <<: *version + # TODO: remove v1alpha1 schema from CRD name: v1alpha1 - # TODO: Flip served bit of v1alpha1 in https://github.com/google/knative-gcp/issues/1544. - served: true + served: false storage: false # v1alpha1 have status.properties.serviceAccountName in the schema schema: diff --git a/config/core/resources/cloudpubsubsource.yaml b/config/core/resources/cloudpubsubsource.yaml index 8bb22b2381..479aab516d 100644 --- a/config/core/resources/cloudpubsubsource.yaml +++ b/config/core/resources/cloudpubsubsource.yaml @@ -209,9 +209,9 @@ spec: subscriptionId: type: string - <<: *version + # TODO: remove v1alpha1 schema from CRD name: v1alpha1 - # TODO: Flip served bit of v1alpha1 in https://github.com/google/knative-gcp/issues/1544. - served: true + served: false storage: false # v1alpha1 and v1beta have status.properties.serviceAccountName in the schema schema: &v1alpha1Schema diff --git a/config/core/resources/cloudschedulersource.yaml b/config/core/resources/cloudschedulersource.yaml index c06f24e28f..7e7054fc44 100644 --- a/config/core/resources/cloudschedulersource.yaml +++ b/config/core/resources/cloudschedulersource.yaml @@ -199,9 +199,9 @@ spec: jobName: type: string - << : *version + # TODO: remove v1alpha1 schema from CRD name: v1alpha1 - # TODO: Flip served bit of v1alpha1 in https://github.com/google/knative-gcp/issues/1544. - served: true + served: false storage: false # v1alpha1 and v1beta have status.properties.serviceAccountName in the schema schema: &v1alpha1Schema diff --git a/config/core/resources/cloudstoragesource.yaml b/config/core/resources/cloudstoragesource.yaml index eba4c9eaad..d3da557f14 100644 --- a/config/core/resources/cloudstoragesource.yaml +++ b/config/core/resources/cloudstoragesource.yaml @@ -205,9 +205,9 @@ spec: notificationId: type: string - << : *version + # TODO: remove v1alpha1 schema from CRD name: v1alpha1 - # TODO: Flip served bit of v1alpha1 in https://github.com/google/knative-gcp/issues/1544. - served: true + served: false storage: false # v1alpha1 and v1beta have spec.properties.payloadFormat and status.properties.serviceAccountName in the schema schema: &v1alpha1Schema diff --git a/config/core/resources/pullsubscription.yaml b/config/core/resources/pullsubscription.yaml index 64e756ce9e..8745202aca 100644 --- a/config/core/resources/pullsubscription.yaml +++ b/config/core/resources/pullsubscription.yaml @@ -186,9 +186,9 @@ spec: transformerUri: type: string - << : *version + # TODO: remove v1alpha1 schema from CRD name: v1alpha1 - # TODO: Flip served bit of v1alpha1 in https://github.com/google/knative-gcp/issues/1544. - served: true + served: false storage: false # v1alpha1 and v1beta have spec.properties.mode and status.properties.serviceAccountName in the schema schema: &v1alpha1Schema diff --git a/config/core/resources/topic.yaml b/config/core/resources/topic.yaml index bdee0aedf4..32f25616ad 100644 --- a/config/core/resources/topic.yaml +++ b/config/core/resources/topic.yaml @@ -136,9 +136,9 @@ spec: url: type: string - << : *version + # TODO: remove v1alpha1 schema from CRD name: v1alpha1 - # TODO: Flip served bit of v1alpha1 in https://github.com/google/knative-gcp/issues/1544. - served: true + served: false storage: false # v1alpha1 and v1beta1 have serviceAccountName in status.properties in the schema schema: &v1alpha1Schema diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 5981bb8fe8..1eca7d3a1a 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -61,14 +61,14 @@ chmod +x "${CODEGEN_PKG}"/generate-groups.sh # instead of the $GOPATH directly. For normal projects this can be dropped. "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \ github.com/google/knative-gcp/pkg/client github.com/google/knative-gcp/pkg/apis \ - "messaging:v1beta1 events:v1alpha1 events:v1beta1 events:v1 broker:v1beta1 intevents:v1alpha1 intevents:v1beta1 intevents:v1" \ + "messaging:v1beta1 events:v1beta1 events:v1 broker:v1beta1 intevents:v1alpha1 intevents:v1beta1 intevents:v1" \ --go-header-file "${REPO_ROOT_DIR}"/hack/boilerplate/boilerplate.go.txt # Knative Injection chmod +x "${KNATIVE_CODEGEN_PKG}"/hack/generate-knative.sh "${KNATIVE_CODEGEN_PKG}"/hack/generate-knative.sh "injection" \ github.com/google/knative-gcp/pkg/client github.com/google/knative-gcp/pkg/apis \ - "messaging:v1beta1 events:v1alpha1 events:v1beta1 events:v1 duck:v1alpha1 duck:v1beta1 duck:v1 broker:v1beta1 intevents:v1alpha1 intevents:v1beta1 intevents:v1" \ + "messaging:v1beta1 events:v1beta1 events:v1 duck:v1alpha1 duck:v1beta1 duck:v1 broker:v1beta1 intevents:v1alpha1 intevents:v1beta1 intevents:v1" \ --go-header-file "${REPO_ROOT_DIR}"/hack/boilerplate/boilerplate.go.txt # Deep copy configs. diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_conversion.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_conversion.go deleted file mode 100644 index cedc3328ec..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_conversion.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - "github.com/google/knative-gcp/pkg/apis/convert" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - "knative.dev/pkg/apis" -) - -// ConvertTo implements apis.Convertible. -// Converts from a v1alpha1.CloudAuditLogsSource to a higher version of CloudAuditLogsSource. -func (source *CloudAuditLogsSource) ConvertTo(ctx context.Context, to apis.Convertible) error { - switch sink := to.(type) { - case *v1beta1.CloudAuditLogsSource: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.ToV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.ServiceName = source.Spec.ServiceName - sink.Spec.MethodName = source.Spec.MethodName - sink.Spec.ResourceName = source.Spec.ResourceName - sink.Status.PubSubStatus = convert.ToV1beta1PubSubStatus(source.Status.PubSubStatus) - sink.Status.StackdriverSink = source.Status.StackdriverSink - // Remove v1alpha1 as deprecated from the Status Condition when converting to a higher version. - convert.RemoveV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertToViaProxy(ctx, source, &v1beta1.CloudAuditLogsSource{}, sink) - } -} - -// ConvertFrom implements apis.Convertible. -// Converts from a higher version of CloudAuditLogsSource to a v1alpha1.CloudAuditLogsSource. -func (sink *CloudAuditLogsSource) ConvertFrom(ctx context.Context, from apis.Convertible) error { - switch source := from.(type) { - case *v1beta1.CloudAuditLogsSource: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.FromV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.ServiceName = source.Spec.ServiceName - sink.Spec.MethodName = source.Spec.MethodName - sink.Spec.ResourceName = source.Spec.ResourceName - sink.Status.PubSubStatus = convert.FromV1beta1PubSubStatus(source.Status.PubSubStatus) - sink.Status.StackdriverSink = source.Status.StackdriverSink - // Mark v1alpha1 as deprecated as a Status Condition when converting to v1alpha1. - convert.MarkV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertFromViaProxy(ctx, source, &v1beta1.CloudAuditLogsSource{}, sink) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_conversion_test.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_conversion_test.go deleted file mode 100644 index 9e7fbcda2a..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_conversion_test.go +++ /dev/null @@ -1,180 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "net/url" - "testing" - - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/convert" - - "github.com/google/go-cmp/cmp" - v1 "github.com/google/knative-gcp/pkg/apis/events/v1" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - gcptesting "github.com/google/knative-gcp/pkg/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -// These variables are used to create a 'complete' version of CloudAuditLogsSource where every field is -// filled in. -var ( - // completeCloudAuditLogsSource is a CloudAuditLogsSource with every field filled in, except TypeMeta. - // TypeMeta is excluded because conversions do not convert it and this variable was created to - // test conversions. - completeCloudAuditLogsSource = &CloudAuditLogsSource{ - ObjectMeta: gcptesting.CompleteObjectMeta, - Spec: CloudAuditLogsSourceSpec{ - PubSubSpec: gcptesting.CompleteV1alpha1PubSubSpec, - ServiceName: "serviceName", - MethodName: "methodName", - ResourceName: "resourceName", - }, - Status: CloudAuditLogsSourceStatus{ - PubSubStatus: gcptesting.CompleteV1alpha1PubSubStatus, - StackdriverSink: "stackdriverSink", - }, - } -) - -func TestCloudAuditLogsSourceConversionBadType(t *testing.T) { - good, bad := &CloudAuditLogsSource{}, &CloudStorageSource{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestCloudAuditLogsSourceConversionBetweenV1beta1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.CloudAuditLogsSource{}} - - tests := []struct { - name string - in *CloudAuditLogsSource - }{{ - name: "min configuration", - in: &CloudAuditLogsSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: CloudAuditLogsSourceSpec{}, - }, - }, { - name: "full configuration", - in: completeCloudAuditLogsSource, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &CloudAuditLogsSource{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - if diff := cmp.Diff(test.in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} - -func TestCloudAuditLogsSourceConversionBetweenV1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1.CloudAuditLogsSource{}} - - tests := []struct { - name string - in *CloudAuditLogsSource - }{{ - name: "min configuration", - in: &CloudAuditLogsSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: CloudAuditLogsSourceSpec{}, - }, - }, { - name: "full configuration", - in: completeCloudAuditLogsSource, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - // DeepCopy because we will edit it below. - in := test.in.DeepCopy() - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &CloudAuditLogsSource{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - // IdentityStatus.ServiceAccountName in v1alpha1 and v1beta1, it doesn't exist in v1. - // So this is not a round trip, the field will be silently removed. - in.Status.ServiceAccountName = "" - if diff := cmp.Diff(in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_defaults.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_defaults.go deleted file mode 100644 index a357721386..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_defaults.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2019 Google LLC. - -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 ( - "context" - - "knative.dev/pkg/apis" - - "github.com/google/knative-gcp/pkg/apis/duck" - metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" -) - -func (s *CloudAuditLogsSource) SetDefaults(ctx context.Context) { - ctx = apis.WithinParent(ctx, s.ObjectMeta) - s.Spec.SetPubSubDefaults(ctx) - duck.SetClusterNameAnnotation(&s.ObjectMeta, metadataClient.NewDefaultMetadataClient()) - duck.SetAutoscalingAnnotationsDefaults(ctx, &s.ObjectMeta) -} diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_defaults_test.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_defaults_test.go deleted file mode 100644 index 59e49be273..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_defaults_test.go +++ /dev/null @@ -1,110 +0,0 @@ -/* -Copyright 2019 Google LLC. - -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" - - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - - "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestCloudAuditLogsSource_SetDefaults(t *testing.T) { - testCases := map[string]struct { - orig *CloudAuditLogsSource - expected *CloudAuditLogsSource - }{ - // Due to the limitation mentioned in https://github.com/google/knative-gcp/issues/1037, specifying the cluster name annotation. - "missing defaults, except cluster name annotations": { - orig: &CloudAuditLogsSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - }, - expected: &CloudAuditLogsSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "google-cloud-key", - }, - Key: "key.json", - }, - }, - }, - }, - }, - "defaults present": { - orig: &CloudAuditLogsSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key.json", - }, - }, - }, - }, - expected: &CloudAuditLogsSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key.json", - }, - }, - }, - }, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - tc.orig.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - if diff := cmp.Diff(tc.expected, tc.orig); diff != "" { - t.Errorf("Unexpected differences (-want +got): %v", diff) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_lifecycle.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_lifecycle.go deleted file mode 100644 index 6f8ea64fb7..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_lifecycle.go +++ /dev/null @@ -1,51 +0,0 @@ -/* -Copyright 2019 Google LLC. - -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 ( - "knative.dev/pkg/apis" -) - -// GetCondition returns the condition currently associated with the given type, or nil. -func (s *CloudAuditLogsSourceStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return auditLogsSourceCondSet.Manage(s).GetCondition(t) -} - -// GetTopLevelCondition returns the top level condition. -func (s *CloudAuditLogsSourceStatus) GetTopLevelCondition() *apis.Condition { - return auditLogsSourceCondSet.Manage(s).GetTopLevelCondition() -} - -// IsReady returns true if the resource is ready overall. -func (s *CloudAuditLogsSourceStatus) IsReady() bool { - return auditLogsSourceCondSet.Manage(s).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (s *CloudAuditLogsSourceStatus) InitializeConditions() { - auditLogsSourceCondSet.Manage(s).InitializeConditions() -} - -// MarkSinkNotReady sets the condition that a CloudAuditLogsSource pubsub sink -// has not been configured and why. -func (s *CloudAuditLogsSourceStatus) MarkSinkNotReady(reason, messageFormat string, messageA ...interface{}) { - auditLogsSourceCondSet.Manage(s).MarkFalse(SinkReady, reason, messageFormat, messageA...) -} - -func (s *CloudAuditLogsSourceStatus) MarkSinkReady() { - auditLogsSourceCondSet.Manage(s).MarkTrue(SinkReady) -} diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_lifecycle_test.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_lifecycle_test.go deleted file mode 100644 index 45baef0746..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_lifecycle_test.go +++ /dev/null @@ -1,198 +0,0 @@ -/* -Copyright 2019 Google LLC. - -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/google/go-cmp/cmp/cmpopts" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" -) - -func TestCloudAuditLogsSourceStatusIsReady(t *testing.T) { - tests := []struct { - name string - s *CloudAuditLogsSourceStatus - wantConditionStatus corev1.ConditionStatus - want bool - }{{ - name: "uninitialized", - s: &CloudAuditLogsSourceStatus{}, - want: false, - }, { - name: "initialized", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSourceStatus{} - s.InitializeConditions() - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "the status of topic is false", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkSinkReady() - s.Status.MarkTopicFailed(s.ConditionSet(), "test", "the status of topic is false") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, { - name: "the status of topic is unknown", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkSinkReady() - s.Status.MarkTopicUnknown(s.ConditionSet(), "test", "the status of topic is unknown") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, - { - name: "the status of pullsubscription is false", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkSinkReady() - s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), "test", "the status of pullsubscription is false") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - }, { - name: "the status of pullsubscription is unknown", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkSinkReady() - s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), "test", "the status of pullsubscription is unknown") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, - { - name: "sink is not ready", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkSinkNotReady("test", "sink is not ready") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, { - name: "ready", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkSinkReady() - return &s.Status - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - if test.wantConditionStatus != "" { - gotConditionStatus := test.s.GetTopLevelCondition().Status - if gotConditionStatus != test.wantConditionStatus { - t.Errorf("unexpected condition status: want %v, got %v", test.wantConditionStatus, gotConditionStatus) - } - } - got := test.s.IsReady() - if got != test.want { - t.Errorf("unexpected readiness: want %v, got %v", test.want, got) - } - }) - } -} -func TestCloudAuditLogsSourceGetCondition(t *testing.T) { - tests := []struct { - name string - s *CloudAuditLogsSourceStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "uninitialized", - s: &CloudAuditLogsSourceStatus{}, - condQuery: SinkReady, - want: nil, - }, { - name: "initialized", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSourceStatus{} - s.InitializeConditions() - return s - }(), - condQuery: SinkReady, - want: &apis.Condition{ - Type: SinkReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "not ready", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSourceStatus{} - s.InitializeConditions() - s.MarkSinkNotReady("NotReady", "test message") - return s - }(), - condQuery: SinkReady, - want: &apis.Condition{ - Type: SinkReady, - Status: corev1.ConditionFalse, - Reason: "NotReady", - Message: "test message", - }, - }, { - name: "ready", - s: func() *CloudAuditLogsSourceStatus { - s := &CloudAuditLogsSourceStatus{} - s.InitializeConditions() - s.MarkSinkReady() - return s - }(), - condQuery: SinkReady, - want: &apis.Condition{ - Type: SinkReady, - Status: corev1.ConditionTrue, - }, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.s.GetCondition(test.condQuery) - ignoreTime := cmpopts.IgnoreFields(apis.Condition{}, - "LastTransitionTime", "Severity") - if diff := cmp.Diff(test.want, got, ignoreTime); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_types.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_types.go deleted file mode 100644 index ddb61c0e53..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_types.go +++ /dev/null @@ -1,129 +0,0 @@ -/* -Copyright 2019 Google LLC. - -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 ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" - "knative.dev/pkg/kmeta" - "knative.dev/pkg/webhook/resourcesemantics" - - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// CloudAuditLogsSource is a specification for a Cloud Audit Log event source. -type CloudAuditLogsSource struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec CloudAuditLogsSourceSpec `json:"spec"` - Status CloudAuditLogsSourceStatus `json:"status"` -} - -// Verify that CloudAuditLogsSource matches various duck types. -var ( - _ apis.Convertible = (*CloudAuditLogsSource)(nil) - _ apis.Defaultable = (*CloudAuditLogsSource)(nil) - _ apis.Validatable = (*CloudAuditLogsSource)(nil) - _ runtime.Object = (*CloudAuditLogsSource)(nil) - _ kmeta.OwnerRefable = (*CloudAuditLogsSource)(nil) - _ resourcesemantics.GenericCRD = (*CloudAuditLogsSource)(nil) - _ kngcpduck.Identifiable = (*CloudAuditLogsSource)(nil) - _ kngcpduck.PubSubable = (*CloudAuditLogsSource)(nil) -) - -const ( - // SinkReady has status True when CloudAuditLogsSource sink is ready. - SinkReady apis.ConditionType = "SinkReady" -) - -var auditLogsSourceCondSet = apis.NewLivingConditionSet( - duckv1alpha1.PullSubscriptionReady, - duckv1alpha1.TopicReady, - SinkReady, -) - -type CloudAuditLogsSourceSpec struct { - // This brings in the PubSub based Source Specs. Includes: - duckv1alpha1.PubSubSpec `json:",inline"` - - // The CloudAuditLogsSource will pull events matching the following - // parameters: - - // The GCP service providing audit logs. Required. - ServiceName string `json:"serviceName"` - // The name of the service method or operation. For API calls, - // this should be the name of the API method. Required. - MethodName string `json:"methodName"` - // The resource or collection that is the target of the - // operation. The name is a scheme-less URI, not including the - // API service name. - ResourceName string `json:"resourceName,omitempty"` -} - -type CloudAuditLogsSourceStatus struct { - duckv1alpha1.PubSubStatus `json:",inline"` - - // ID of the Stackdriver sink used to publish audit log messages. - StackdriverSink string `json:"stackdriverSink,omitempty"` -} - -func (*CloudAuditLogsSource) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("CloudAuditLogsSource") -} - -// Methods for identifiable interface. -// IdentitySpec returns the IdentitySpec portion of the Spec. -func (s *CloudAuditLogsSource) IdentitySpec() *duckv1alpha1.IdentitySpec { - return &s.Spec.IdentitySpec -} - -// IdentityStatus returns the IdentityStatus portion of the Status. -func (s *CloudAuditLogsSource) IdentityStatus() *duckv1alpha1.IdentityStatus { - return &s.Status.IdentityStatus -} - -// ConditionSet returns the apis.ConditionSet of the embedding object. -func (*CloudAuditLogsSource) ConditionSet() *apis.ConditionSet { - return &auditLogsSourceCondSet -} - -///Methods for pubsubable interface. - -// PubSubSpec returns the PubSubSpec portion of the Spec. -func (s *CloudAuditLogsSource) PubSubSpec() *duckv1alpha1.PubSubSpec { - return &s.Spec.PubSubSpec -} - -// PubSubStatus returns the PubSubStatus portion of the Status. -func (s *CloudAuditLogsSource) PubSubStatus() *duckv1alpha1.PubSubStatus { - return &s.Status.PubSubStatus -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type CloudAuditLogsSourceList struct { - metav1.TypeMeta - metav1.ListMeta - - Items []CloudAuditLogsSource `json:"items"` -} diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_types_test.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_types_test.go deleted file mode 100644 index cb77ac4083..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_types_test.go +++ /dev/null @@ -1,99 +0,0 @@ -/* -Copyright 2019 Google LLC. - -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/google/go-cmp/cmp/cmpopts" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" -) - -func TestAuditLogsGetGroupVersionKind(t *testing.T) { - want := schema.GroupVersionKind{ - Group: "events.cloud.google.com", - Version: "v1alpha1", - Kind: "CloudAuditLogsSource", - } - - c := &CloudAuditLogsSource{} - - got := c.GetGroupVersionKind() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestAuditLogsConditionSet(t *testing.T) { - want := []apis.Condition{{ - Type: SinkReady, - }, { - Type: duckv1alpha1.TopicReady, - }, { - Type: duckv1alpha1.PullSubscriptionReady, - }, { - Type: apis.ConditionReady, - }} - c := &CloudAuditLogsSource{} - - c.ConditionSet().Manage(&c.Status).InitializeConditions() - var got []apis.Condition = c.Status.GetConditions() - - compareConditionTypes := cmp.Transformer("ConditionType", func(c apis.Condition) apis.ConditionType { - return c.Type - }) - sortConditionTypes := cmpopts.SortSlices(func(a, b apis.Condition) bool { - return a.Type < b.Type - }) - if diff := cmp.Diff(want, got, sortConditionTypes, compareConditionTypes); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudAuditLogsSourceIdentitySpec(t *testing.T) { - s := &CloudAuditLogsSource{ - Spec: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "test", - }, - }, - }, - } - want := "test" - got := s.IdentitySpec().ServiceAccountName - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudAuditLogsSourceIdentityStatus(t *testing.T) { - s := &CloudAuditLogsSource{ - Status: CloudAuditLogsSourceStatus{ - PubSubStatus: duckv1alpha1.PubSubStatus{}, - }, - } - want := &duckv1alpha1.IdentityStatus{} - got := s.IdentityStatus() - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_validation.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_validation.go deleted file mode 100644 index 4db0abc38c..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_validation.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck" -) - -func (current *CloudAuditLogsSource) Validate(ctx context.Context) *apis.FieldError { - err := current.Spec.Validate(ctx).ViaField("spec") - - if apis.IsInUpdate(ctx) { - original := apis.GetBaseline(ctx).(*CloudAuditLogsSource) - err = err.Also(current.CheckImmutableFields(ctx, original)) - } - return err -} - -func (current *CloudAuditLogsSourceSpec) Validate(ctx context.Context) *apis.FieldError { - var errs *apis.FieldError - - // Sink [required] - if equality.Semantic.DeepEqual(current.Sink, duckv1.Destination{}) { - errs = errs.Also(apis.ErrMissingField("sink")) - } else if err := current.Sink.Validate(ctx); err != nil { - errs = errs.Also(err.ViaField("sink")) - } - - // ServiceName [required] - if current.ServiceName == "" { - errs = errs.Also(apis.ErrMissingField("serviceName")) - } - // MethodName [required] - if current.MethodName == "" { - errs = errs.Also(apis.ErrMissingField("methodName")) - } - - if err := duck.ValidateCredential(current.Secret, current.ServiceAccountName); err != nil { - errs = errs.Also(err) - } - - return errs -} - -func (current *CloudAuditLogsSource) CheckImmutableFields(ctx context.Context, original *CloudAuditLogsSource) *apis.FieldError { - if original == nil { - return nil - } - - var errs *apis.FieldError - // Modification of Topic, Secret, ServiceAccountName, Project, ServiceName, MethodName and ResourceName are not allowed. - // Everything else is mutable. - if diff := cmp.Diff(original.Spec, current.Spec, - cmpopts.IgnoreFields(CloudAuditLogsSourceSpec{}, - "Sink", "CloudEventOverrides")); diff != "" { - errs = errs.Also( - &apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - }) - } - // Modification of AutoscalingClassAnnotations is not allowed. - errs = duck.CheckImmutableAutoscalingClassAnnotations(¤t.ObjectMeta, &original.ObjectMeta, errs) - - // Modification of non-empty cluster name annotation is not allowed. - return duck.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) -} diff --git a/pkg/apis/events/v1alpha1/cloudauditlogssource_validation_test.go b/pkg/apis/events/v1alpha1/cloudauditlogssource_validation_test.go deleted file mode 100644 index 474b0ad68d..0000000000 --- a/pkg/apis/events/v1alpha1/cloudauditlogssource_validation_test.go +++ /dev/null @@ -1,508 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "testing" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -var ( - auditLogsSourceSpec = CloudAuditLogsSourceSpec{ - ServiceName: "foo", - MethodName: "bar", - ResourceName: "baz", - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key", - }, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Project: "my-eventing-project", - }, - } - - auditLogsSourceSpecWithKSA = CloudAuditLogsSourceSpec{ - ServiceName: "foo", - MethodName: "bar", - ResourceName: "baz", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - Project: "my-eventing-project", - }, - } - - validServiceAccountName = "test" - invalidServiceAccountName = "@test" -) - -func TestCloudAuditLogsSourceValidationFields(t *testing.T) { - testCases := map[string]struct { - spec CloudAuditLogsSourceSpec - error bool - }{ - "ok": { - spec: auditLogsSourceSpec, - error: false, - }, - "bad ServiceName": { - spec: func() CloudAuditLogsSourceSpec { - obj := auditLogsSourceSpec.DeepCopy() - obj.ServiceName = "" - return *obj - }(), - error: true, - }, - "bad MethodName": { - spec: func() CloudAuditLogsSourceSpec { - obj := auditLogsSourceSpec.DeepCopy() - obj.MethodName = "" - return *obj - }(), - error: true, - }, - "bad sink, name": { - spec: func() CloudAuditLogsSourceSpec { - obj := auditLogsSourceSpec.DeepCopy() - obj.Sink.Ref.Name = "" - return *obj - }(), - error: true, - }, - "bad sink, empty": { - spec: func() CloudAuditLogsSourceSpec { - obj := auditLogsSourceSpec.DeepCopy() - obj.Sink = duckv1.Destination{} - return *obj - }(), - error: true, - }, - "nil secret": { - spec: func() CloudAuditLogsSourceSpec { - obj := auditLogsSourceSpec.DeepCopy() - return *obj - }(), - error: false, - }, - "invalid scheduler secret, missing key": { - spec: func() CloudAuditLogsSourceSpec { - obj := auditLogsSourceSpec.DeepCopy() - obj.Secret = &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{Name: "test-secret"}, - } - return *obj - }(), - error: true, - }, - "invalid k8s service account": { - spec: func() CloudAuditLogsSourceSpec { - obj := auditLogsSourceSpec.DeepCopy() - obj.ServiceAccountName = invalidServiceAccountName - return *obj - }(), - error: true, - }, - "have k8s service account and secret at the same time": { - spec: func() CloudAuditLogsSourceSpec { - obj := auditLogsSourceSpec.DeepCopy() - obj.ServiceAccountName = validServiceAccountName - obj.Secret = &gcpauthtesthelper.Secret - return *obj - }(), - error: true, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - err := tc.spec.Validate(context.TODO()) - if tc.error != (err != nil) { - t.Fatalf("Unexpected validation failure. Got %v", err) - } - }) - } -} - -func TestCloudAuditLogsSourceCheckImmutableFields(t *testing.T) { - testCases := map[string]struct { - orig interface{} - updated CloudAuditLogsSourceSpec - origAnnotation map[string]string - updatedAnnotation map[string]string - allowed bool - }{ - "nil orig": { - updated: auditLogsSourceSpec, - allowed: true, - }, - "ClusterName annotation changed": { - origAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", - }, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: false, - }, - "AnnotationClass annotation changed": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA + "new", - }, - allowed: false, - }, - "AnnotationClass annotation added": { - origAnnotation: map[string]string{}, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - allowed: false, - }, - "AnnotationClass annotation deleted": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{}, - allowed: false, - }, - "ServiceName changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - MethodName: auditLogsSourceSpec.MethodName, - PubSubSpec: auditLogsSourceSpec.PubSubSpec, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: "some-other-name", - }, - allowed: false, - }, - "MethodName changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - MethodName: "some-other-name", - PubSubSpec: auditLogsSourceSpec.PubSubSpec, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: false, - }, - "ResourceName changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - MethodName: auditLogsSourceSpec.MethodName, - PubSubSpec: auditLogsSourceSpec.PubSubSpec, - ResourceName: "some-other-name", - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: false, - }, - "Project changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: auditLogsSourceSpec.PubSubSpec.Secret.Name, - }, - Key: auditLogsSourceSpec.PubSubSpec.Secret.Key, - }, - Project: "some-other-project", - SourceSpec: duckv1.SourceSpec{ - Sink: auditLogsSourceSpec.PubSubSpec.Sink, - }, - }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: false, - }, - "ServiceAccountName changed": { - orig: &auditLogsSourceSpecWithKSA, - updated: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "new-service-account", - }, - SourceSpec: duckv1.SourceSpec{ - Sink: auditLogsSourceSpecWithKSA.PubSubSpec.Sink, - }, - Project: auditLogsSourceSpecWithKSA.Project, - }, - MethodName: auditLogsSourceSpecWithKSA.MethodName, - ResourceName: auditLogsSourceSpecWithKSA.ResourceName, - ServiceName: auditLogsSourceSpecWithKSA.ServiceName, - }, - allowed: false, - }, - "Secret.Name changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "some-other-name", - }, - Key: auditLogsSourceSpec.PubSubSpec.Secret.Key, - }, - Project: auditLogsSourceSpec.PubSubSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: auditLogsSourceSpec.PubSubSpec.Sink, - }, - }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: false, - }, - "Secret.Key changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: auditLogsSourceSpec.PubSubSpec.Secret.Name, - }, - Key: "some-other-key", - }, - Project: auditLogsSourceSpec.PubSubSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: auditLogsSourceSpec.PubSubSpec.Sink, - }, - }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: false, - }, - "ServiceAccountName added": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: auditLogsSourceSpec.Secret.Name, - }, - Key: auditLogsSourceSpec.Secret.Key, - }, - Project: auditLogsSourceSpec.Project, - SourceSpec: auditLogsSourceSpec.SourceSpec, - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: false, - }, - "ClusterName annotation added": { - origAnnotation: nil, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: true, - }, - "Sink.APIVersion changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: auditLogsSourceSpec.Secret.Name, - }, - Key: auditLogsSourceSpec.Secret.Key, - }, - Project: auditLogsSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: auditLogsSourceSpec.Sink.Ref.Kind, - Namespace: auditLogsSourceSpec.Sink.Ref.Namespace, - Name: auditLogsSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: true, - }, - "Sink.Kind changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: auditLogsSourceSpec.Secret.Name, - }, - Key: auditLogsSourceSpec.Secret.Key, - }, - Project: auditLogsSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: auditLogsSourceSpec.Sink.Ref.APIVersion, - Kind: "some-other-kind", - Namespace: auditLogsSourceSpec.Sink.Ref.Namespace, - Name: auditLogsSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: true, - }, - "Sink.Namespace changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: auditLogsSourceSpec.Secret.Name, - }, - Key: auditLogsSourceSpec.Secret.Key, - }, - Project: auditLogsSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: auditLogsSourceSpec.Sink.Ref.APIVersion, - Kind: auditLogsSourceSpec.Sink.Ref.Kind, - Namespace: "some-other-namespace", - Name: auditLogsSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: true, - }, - "Sink.Name changed": { - orig: &auditLogsSourceSpec, - updated: CloudAuditLogsSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: auditLogsSourceSpec.Secret.Name, - }, - Key: auditLogsSourceSpec.Secret.Key, - }, - Project: auditLogsSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: auditLogsSourceSpec.Sink.Ref.APIVersion, - Kind: auditLogsSourceSpec.Sink.Ref.Kind, - Namespace: auditLogsSourceSpec.Sink.Ref.Namespace, - Name: "some-other-name", - }, - }, - }, - }, - MethodName: auditLogsSourceSpec.MethodName, - ResourceName: auditLogsSourceSpec.ResourceName, - ServiceName: auditLogsSourceSpec.ServiceName, - }, - allowed: true, - }, - "no change": { - orig: &auditLogsSourceSpec, - updated: auditLogsSourceSpec, - allowed: true, - }, - "no spec": { - orig: []string{"wrong"}, - updated: auditLogsSourceSpec, - allowed: true, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - var orig *CloudAuditLogsSource - - if tc.origAnnotation != nil { - orig = &CloudAuditLogsSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.origAnnotation, - }, - } - } else if tc.orig != nil { - if spec, ok := tc.orig.(*CloudAuditLogsSourceSpec); ok { - orig = &CloudAuditLogsSource{ - Spec: *spec, - } - } - } - updated := &CloudAuditLogsSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.updatedAnnotation, - }, - Spec: tc.updated, - } - err := updated.CheckImmutableFields(context.TODO(), orig) - if tc.allowed != (err == nil) { - t.Fatalf("Unexpected immutable field check. Expected %v. Actual %v", tc.allowed, err) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go deleted file mode 100644 index db3466e67c..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - "github.com/google/knative-gcp/pkg/apis/convert" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - "knative.dev/pkg/apis" -) - -// ConvertTo implements apis.Convertible. -// Converts source (from v1beta1.CloudBuildSource) into v1alpha1.CloudBuildSource. -func (source *CloudBuildSource) ConvertTo(ctx context.Context, to apis.Convertible) error { - switch sink := to.(type) { - case *v1beta1.CloudBuildSource: - sink.ObjectMeta = source.ObjectMeta - // v1beta1 CloudBuildSource implements duck v1 PubSubable - sink.Spec.PubSubSpec = convert.FromV1alpha1ToV1PubSubSpec(source.Spec.PubSubSpec) - sink.Status.PubSubStatus = convert.FromV1alpha1ToV1PubSubStatus(source.Status.PubSubStatus) - // Remove v1alpha1 as deprecated from the Status Condition when converting to a higher version. - convert.RemoveV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertToViaProxy(ctx, source, &v1beta1.CloudBuildSource{}, sink) - } -} - -// ConvertFrom implements apis.Convertible. -// Converts obj from v1alpha1.CloudBuildSource into v1beta1.CloudBuildSource. -func (sink *CloudBuildSource) ConvertFrom(ctx context.Context, from apis.Convertible) error { - switch source := from.(type) { - case *v1beta1.CloudBuildSource: - sink.ObjectMeta = source.ObjectMeta - // v1beta1 CloudBuildSource implements duck v1 PubSubable - sink.Spec.PubSubSpec = convert.FromV1ToV1alpha1PubSubSpec(source.Spec.PubSubSpec) - sink.Status.PubSubStatus = convert.FromV1ToV1alpha1PubSubStatus(source.Status.PubSubStatus) - // Mark v1alpha1 as deprecated as a Status Condition when converting to v1alpha1. - convert.MarkV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertFromViaProxy(ctx, source, &v1beta1.CloudBuildSource{}, sink) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go deleted file mode 100644 index 4ecc7d53f2..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go +++ /dev/null @@ -1,119 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "net/url" - "testing" - - v1 "github.com/google/knative-gcp/pkg/apis/events/v1" - - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/convert" - - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - - "github.com/google/go-cmp/cmp" - gcptesting "github.com/google/knative-gcp/pkg/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -// These variables are used to create a 'complete' version of CloudBuildSource where every field is -// filled in. -var ( - // completeCloudBuildSource is a CloudBuildSource with every field filled in, except TypeMeta. - // TypeMeta is excluded because conversions do not convert it and this variable was created to - // test conversions. - completeCloudBuildSource = &CloudBuildSource{ - ObjectMeta: gcptesting.CompleteObjectMeta, - Spec: CloudBuildSourceSpec{ - PubSubSpec: gcptesting.CompleteV1alpha1PubSubSpec, - }, - Status: CloudBuildSourceStatus{ - PubSubStatus: gcptesting.CompleteV1alpha1PubSubStatusWithoutServiceAccountName, - }, - } -) - -func TestCloudBuildSourceConversionBadType(t *testing.T) { - good, bad := &CloudBuildSource{}, &CloudStorageSource{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestClouBuildSourceConversion(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.CloudBuildSource{}, &v1.CloudBuildSource{}} - - tests := []struct { - name string - in *CloudBuildSource - }{{ - name: "min configuration", - in: &CloudBuildSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: CloudBuildSourceSpec{}, - }, - }, { - name: "full configuration", - in: completeCloudBuildSource, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &CloudBuildSource{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - if diff := cmp.Diff(test.in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_defaults.go b/pkg/apis/events/v1alpha1/cloudbuildsource_defaults.go deleted file mode 100644 index 86da07c455..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_defaults.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2020 Google LLC. - -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 ( - "context" - - "github.com/google/knative-gcp/pkg/apis/duck" - metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" - - "knative.dev/pkg/apis" - "knative.dev/pkg/ptr" -) - -const ( - DefaultTopic = "cloud-builds" -) - -func (bs *CloudBuildSource) SetDefaults(ctx context.Context) { - ctx = apis.WithinParent(ctx, bs.ObjectMeta) - bs.Spec.SetDefaults(ctx) - duck.SetClusterNameAnnotation(&bs.ObjectMeta, metadataClient.NewDefaultMetadataClient()) - duck.SetAutoscalingAnnotationsDefaults(ctx, &bs.ObjectMeta) -} - -func (bss *CloudBuildSourceSpec) SetDefaults(ctx context.Context) { - bss.SetPubSubDefaults(ctx) - if bss.Topic == nil { - topic := DefaultTopic - bss.Topic = ptr.String(topic) - } - -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_defaults_test.go b/pkg/apis/events/v1alpha1/cloudbuildsource_defaults_test.go deleted file mode 100644 index b37335082d..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_defaults_test.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright 2020 Google LLC. - -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" - - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - - "knative.dev/pkg/ptr" - - "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestBuildSourceDefaults(t *testing.T) { - defaultTopic := DefaultTopic - tests := []struct { - name string - start *CloudBuildSource - want *CloudBuildSource - }{{ - name: "defaults present", - start: &CloudBuildSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "my-cloud-key", - }, - Key: "test.json", - }, - }, - Topic: ptr.String(defaultTopic), - }, - }, - want: &CloudBuildSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "my-cloud-key", - }, - Key: "test.json", - }, - }, - Topic: ptr.String(defaultTopic), - }, - }, - }, { - // Due to the limitation mentioned in https://github.com/google/knative-gcp/issues/1037, specifying the cluster name annotation. - name: "missing defaults, except cluster name annotations", - start: &CloudBuildSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudBuildSourceSpec{}, - }, - want: &CloudBuildSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &gcpauthtesthelper.Secret, - }, - Topic: ptr.String(defaultTopic), - }, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.start - got.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } - }) - } -} - -func TestCloudBuildSourceDefaults_NoChange(t *testing.T) { - want := &CloudBuildSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "my-cloud-key", - }, - Key: "test.json", - }, - }, - Topic: ptr.String(DefaultTopic), - }, - } - - got := want.DeepCopy() - got.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_lifecycle.go b/pkg/apis/events/v1alpha1/cloudbuildsource_lifecycle.go deleted file mode 100644 index a1133f551f..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_lifecycle.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2020 Google LLC. - -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 ( - "knative.dev/pkg/apis" -) - -// GetCondition returns the condition currently associated with the given type, or nil. -func (bs *CloudBuildSourceStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return buildCondSet.Manage(bs).GetCondition(t) -} - -// GetTopLevelCondition returns the top level condition. -func (bs *CloudBuildSourceStatus) GetTopLevelCondition() *apis.Condition { - return buildCondSet.Manage(bs).GetTopLevelCondition() -} - -// IsReady returns true if the resource is ready overall. -func (bs *CloudBuildSourceStatus) IsReady() bool { - return buildCondSet.Manage(bs).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (bs *CloudBuildSourceStatus) InitializeConditions() { - buildCondSet.Manage(bs).InitializeConditions() -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_lifecycle_test.go b/pkg/apis/events/v1alpha1/cloudbuildsource_lifecycle_test.go deleted file mode 100644 index 755743ec28..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_lifecycle_test.go +++ /dev/null @@ -1,158 +0,0 @@ -/* -Copyright 2020 Google LLC. - -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/google/go-cmp/cmp/cmpopts" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" -) - -func TestCloudBuildSourceStatusIsReady(t *testing.T) { - tests := []struct { - name string - s *CloudBuildSourceStatus - wantConditionStatus corev1.ConditionStatus - want bool - }{ - { - name: "uninitialized", - s: &CloudBuildSourceStatus{}, - want: false, - }, { - name: "initialized", - s: func() *CloudBuildSourceStatus { - s := &CloudBuildSource{} - s.Status.InitializeConditions() - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, - { - name: "the status of pullsubscription is false", - s: func() *CloudBuildSourceStatus { - s := &CloudBuildSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), "PullSubscriptionFalse", "status false test message") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - }, { - name: "the status of pullsubscription is unknown", - s: func() *CloudBuildSourceStatus { - s := &CloudBuildSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), "PullSubscriptionUnknonw", "status unknown test message") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - }, - { - name: "ready", - s: func() *CloudBuildSourceStatus { - s := &CloudBuildSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - return &s.Status - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - if test.wantConditionStatus != "" { - gotConditionStatus := test.s.GetTopLevelCondition().Status - if gotConditionStatus != test.wantConditionStatus { - t.Errorf("unexpected condition status: want %v, got %v", test.wantConditionStatus, gotConditionStatus) - } - } - got := test.s.IsReady() - if got != test.want { - t.Errorf("unexpected readiness: want %v, got %v", test.want, got) - } - }) - } -} -func TestCloudBuildSourceStatusGetCondition(t *testing.T) { - tests := []struct { - name string - s *CloudBuildSourceStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "uninitialized", - s: &CloudBuildSourceStatus{}, - condQuery: CloudBuildSourceConditionReady, - want: nil, - }, { - name: "initialized", - s: func() *CloudBuildSourceStatus { - s := &CloudBuildSourceStatus{} - s.InitializeConditions() - return s - }(), - condQuery: CloudBuildSourceConditionReady, - want: &apis.Condition{ - Type: CloudBuildSourceConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "not ready", - - s: func() *CloudBuildSourceStatus { - s := &CloudBuildSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), "NotReady", "test message") - return &s.Status - }(), - condQuery: duckv1alpha1.PullSubscriptionReady, - want: &apis.Condition{ - Type: duckv1alpha1.PullSubscriptionReady, - Status: corev1.ConditionFalse, - Reason: "NotReady", - Message: "test message", - }, - }, { - name: "ready", - s: func() *CloudBuildSourceStatus { - s := &CloudBuildSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - return &s.Status - }(), - condQuery: duckv1alpha1.PullSubscriptionReady, - want: &apis.Condition{ - Type: duckv1alpha1.PullSubscriptionReady, - Status: corev1.ConditionTrue, - }, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.s.GetCondition(test.condQuery) - ignoreTime := cmpopts.IgnoreFields(apis.Condition{}, - "LastTransitionTime", "Severity") - if diff := cmp.Diff(test.want, got, ignoreTime); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_types.go b/pkg/apis/events/v1alpha1/cloudbuildsource_types.go deleted file mode 100644 index 54ba5c08b9..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_types.go +++ /dev/null @@ -1,127 +0,0 @@ -/* -Copyright 2020 Google LLC -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 ( - "fmt" - - "k8s.io/apimachinery/pkg/runtime" - - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/kmeta" - "knative.dev/pkg/webhook/resourcesemantics" - - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" -) - -// CloudBuildSource is a specification for a CloudBuildSource resource. -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type CloudBuildSource struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec CloudBuildSourceSpec `json:"spec,omitempty"` - Status CloudBuildSourceStatus `json:"status,omitempty"` -} - -// Verify that CloudBuildSource matches various duck types. -var ( - _ apis.Convertible = (*CloudBuildSource)(nil) - _ apis.Defaultable = (*CloudBuildSource)(nil) - _ apis.Validatable = (*CloudBuildSource)(nil) - _ runtime.Object = (*CloudBuildSource)(nil) - _ kmeta.OwnerRefable = (*CloudBuildSource)(nil) - _ resourcesemantics.GenericCRD = (*CloudBuildSource)(nil) - _ kngcpduck.Identifiable = (*CloudBuildSource)(nil) - _ kngcpduck.PubSubable = (*CloudBuildSource)(nil) -) - -// CloudBuildSourceSpec defines the desired state of the CloudBuildSource. -type CloudBuildSourceSpec struct { - // This brings in the PubSub based Source Specs. Includes: - // Sink, CloudEventOverrides, Secret and Project - duckv1alpha1.PubSubSpec `json:",inline"` - - // Topic is the ID of the PubSub Topic to Subscribe to. It must - // be in the form of the unique identifier within the project, not the - // entire name. E.g. it must be 'laconia', not - // 'projects/my-proj/topics/laconia'. - // It is optional. Defaults to 'cloud-builds' and the topic must be 'cloud-builds' - // +optional - Topic *string `json:"topic,omitempty"` -} - -// CloudBuildSourceEventSource returns the Cloud Build CloudEvent source value. -func CloudBuildSourceEventSource(googleCloudProject, buildId string) string { - return fmt.Sprintf("//cloudbuild.googleapis.com/projects/%s/builds/%s", googleCloudProject, buildId) -} - -const ( - // CloudBuildSourceConditionReady has status True when the CloudBuildSource is - // ready to send events. - CloudBuildSourceConditionReady = apis.ConditionReady -) - -var buildCondSet = apis.NewLivingConditionSet( - duckv1alpha1.PullSubscriptionReady, -) - -// CloudBuildSourceStatus defines the observed state of CloudBuildSource. -type CloudBuildSourceStatus struct { - duckv1alpha1.PubSubStatus `json:",inline"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// CloudBuildSourceList contains a list of CloudBuildSources. -type CloudBuildSourceList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []CloudBuildSource `json:"items"` -} - -// Methods for pubsubable interface -func (*CloudBuildSource) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("CloudBuildSource") -} - -// Methods for identifiable interface. -// IdentitySpec returns the IdentitySpec portion of the Spec. -func (s *CloudBuildSource) IdentitySpec() *duckv1alpha1.IdentitySpec { - return &s.Spec.IdentitySpec -} - -// IdentityStatus returns the IdentityStatus portion of the Status. -func (s *CloudBuildSource) IdentityStatus() *duckv1alpha1.IdentityStatus { - return &s.Status.IdentityStatus -} - -// CloudBuildSourceSpec returns the CloudBuildSourceSpec portion of the Spec. -func (bs *CloudBuildSource) PubSubSpec() *duckv1alpha1.PubSubSpec { - return &bs.Spec.PubSubSpec -} - -// PubSubStatus returns the PubSubStatus portion of the Status. -func (bs *CloudBuildSource) PubSubStatus() *duckv1alpha1.PubSubStatus { - return &bs.Status.PubSubStatus -} - -// ConditionSet returns the apis.ConditionSet of the embedding object. -func (bs *CloudBuildSource) ConditionSet() *apis.ConditionSet { - return &buildCondSet -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_types_test.go b/pkg/apis/events/v1alpha1/cloudbuildsource_types_test.go deleted file mode 100644 index 72412f0b3d..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_types_test.go +++ /dev/null @@ -1,102 +0,0 @@ -/* -Copyright 2020 Google LLC -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/cmpopts" - "knative.dev/pkg/apis" - - "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -func TestCloudBuildSourceEventSource(t *testing.T) { - want := "//cloudbuild.googleapis.com/projects/PROJECT/builds/BUILD_ID" - - got := CloudBuildSourceEventSource("PROJECT", "BUILD_ID") - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudBuildSourceGetGroupVersionKind(t *testing.T) { - want := schema.GroupVersionKind{ - Group: "events.cloud.google.com", - Version: "v1alpha1", - Kind: "CloudBuildSource", - } - - c := &CloudBuildSource{} - got := c.GetGroupVersionKind() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudBuildSourceIdentitySpec(t *testing.T) { - s := &CloudBuildSource{ - Spec: CloudBuildSourceSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "test", - }, - }, - }, - } - want := "test" - got := s.IdentitySpec().ServiceAccountName - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudBuildSourceIdentityStatus(t *testing.T) { - s := &CloudBuildSource{ - Status: CloudBuildSourceStatus{ - PubSubStatus: v1alpha1.PubSubStatus{}, - }, - } - want := &v1alpha1.IdentityStatus{} - got := s.IdentityStatus() - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudBuildSourceConditionSet(t *testing.T) { - want := []apis.Condition{{ - Type: v1alpha1.PullSubscriptionReady, - }, { - Type: apis.ConditionReady, - }} - c := &CloudBuildSource{} - - c.ConditionSet().Manage(&c.Status).InitializeConditions() - var got []apis.Condition = c.Status.GetConditions() - - compareConditionTypes := cmp.Transformer("ConditionType", func(c apis.Condition) apis.ConditionType { - return c.Type - }) - sortConditionTypes := cmpopts.SortSlices(func(a, b apis.Condition) bool { - return a.Type < b.Type - }) - if diff := cmp.Diff(want, got, sortConditionTypes, compareConditionTypes); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_validation.go b/pkg/apis/events/v1alpha1/cloudbuildsource_validation.go deleted file mode 100644 index 29d24cb3aa..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_validation.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright 2020 Google LLC -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 ( - "context" - "fmt" - - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck" -) - -func (current *CloudBuildSource) Validate(ctx context.Context) *apis.FieldError { - errs := current.Spec.Validate(ctx).ViaField("spec") - - if apis.IsInUpdate(ctx) { - original := apis.GetBaseline(ctx).(*CloudBuildSource) - errs = errs.Also(current.CheckImmutableFields(ctx, original)) - } - return duck.ValidateAutoscalingAnnotations(ctx, current.Annotations, errs) -} - -func (current *CloudBuildSourceSpec) Validate(ctx context.Context) *apis.FieldError { - var errs *apis.FieldError - - if current.Topic != nil && (!equality.Semantic.DeepEqual(*current.Topic, DefaultTopic)) { - errs = errs.Also(apis.ErrGeneric(fmt.Sprintf("topic should be omitted or must be equal to %q", DefaultTopic), "topic")) - } - - // Sink [required] - if equality.Semantic.DeepEqual(current.Sink, duckv1.Destination{}) { - errs = errs.Also(apis.ErrMissingField("sink")) - } else if err := current.Sink.Validate(ctx); err != nil { - errs = errs.Also(err.ViaField("sink")) - } - - if err := duck.ValidateCredential(current.Secret, current.ServiceAccountName); err != nil { - errs = errs.Also(err) - } - - return errs -} - -func (current *CloudBuildSource) CheckImmutableFields(ctx context.Context, original *CloudBuildSource) *apis.FieldError { - if original == nil { - return nil - } - - var errs *apis.FieldError - // Modification of Topic, Secret and Project are not allowed. Everything else is mutable. - if diff := cmp.Diff(original.Spec, current.Spec, - cmpopts.IgnoreFields(CloudBuildSourceSpec{}, - "Sink", "CloudEventOverrides")); diff != "" { - errs = errs.Also(&apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - }) - } - // Modification of AutoscalingClassAnnotations is not allowed. - errs = duck.CheckImmutableAutoscalingClassAnnotations(¤t.ObjectMeta, &original.ObjectMeta, errs) - - // Modification of non-empty cluster name annotation is not allowed. - return duck.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) -} diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_validation_test.go b/pkg/apis/events/v1alpha1/cloudbuildsource_validation_test.go deleted file mode 100644 index 3c47473fd5..0000000000 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_validation_test.go +++ /dev/null @@ -1,507 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "testing" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/ptr" -) - -var ( - topic = DefaultTopic - buildSourceSpec = CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key", - }, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Project: "my-eventing-project", - }, - Topic: ptr.String(topic), - } - - buildSourceSpecWithKSA = CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - Project: "my-eventing-project", - }, - } -) - -func TestCloudBuildSourceCheckValidationFields(t *testing.T) { - testCases := map[string]struct { - spec CloudBuildSourceSpec - error bool - }{ - "ok": { - spec: buildSourceSpec, - error: false, - }, - "no topic": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Topic = nil - return *obj - }(), - error: false, - }, - "bad topic": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Topic = ptr.String("test-build") - return *obj - }(), - error: true, - }, - "bad sink, name": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Sink.Ref.Name = "" - return *obj - }(), - error: true, - }, - "bad sink, apiVersion": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Sink.Ref.APIVersion = "" - return *obj - }(), - error: true, - }, - "bad sink, kind": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Sink.Ref.Kind = "" - return *obj - }(), - error: true, - }, - "bad sink, empty": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Sink = duckv1.Destination{} - return *obj - }(), - error: true, - }, - "bad sink, uri scheme": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Sink = duckv1.Destination{ - URI: &apis.URL{ - Host: "example.com", - }, - } - return *obj - }(), - error: true, - }, - "bad sink, uri host": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Sink = duckv1.Destination{ - URI: &apis.URL{ - Scheme: "http", - }, - } - return *obj - }(), - error: true, - }, - "bad sink, uri and ref": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Sink = duckv1.Destination{ - URI: &apis.URL{ - Scheme: "http", - Host: "example.com", - }, - Ref: &duckv1.KReference{ - Name: "foo", - }, - } - return *obj - }(), - error: true, - }, - "invalid secret, missing key": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.Secret = &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "name", - }, - } - return *obj - }(), - error: true, - }, - "nil service account": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - return *obj - }(), - error: false, - }, - "invalid k8s service account": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.ServiceAccountName = invalidServiceAccountName - return *obj - }(), - error: true, - }, - "have k8s service account and secret at the same time": { - spec: func() CloudBuildSourceSpec { - obj := buildSourceSpec.DeepCopy() - obj.ServiceAccountName = validServiceAccountName - obj.Secret = &gcpauthtesthelper.Secret - return *obj - }(), - error: true, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - err := tc.spec.Validate(context.TODO()) - if tc.error != (err != nil) { - t.Fatalf("Unexpected validation failure. Got %v", err) - } - }) - } -} - -func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { - testCases := map[string]struct { - orig interface{} - updated CloudBuildSourceSpec - origAnnotation map[string]string - updatedAnnotation map[string]string - allowed bool - }{ - "nil orig": { - updated: buildSourceSpec, - allowed: true, - }, - "ClusterName annotation changed": { - origAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", - }, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: false, - }, - "AnnotationClass annotation changed": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA + "new", - }, - allowed: false, - }, - "AnnotationClass annotation added": { - origAnnotation: map[string]string{}, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - allowed: false, - }, - "AnnotationClass annotation deleted": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{}, - allowed: false, - }, - "Secret.Name changed": { - orig: &buildSourceSpec, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "some-other-name", - }, - Key: buildSourceSpec.Secret.Key, - }, - Project: buildSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: buildSourceSpec.Sink, - }, - }, - Topic: buildSourceSpec.Topic, - }, - allowed: false, - }, - "Secret.Key changed": { - orig: &buildSourceSpec, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: buildSourceSpec.Secret.Name, - }, - Key: "some-other-key", - }, - Project: buildSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: buildSourceSpec.Sink, - }, - }, - Topic: buildSourceSpec.Topic, - }, - allowed: false, - }, - "Project changed": { - orig: &buildSourceSpec, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: buildSourceSpec.Secret.Name, - }, - Key: buildSourceSpec.Secret.Key, - }, - Project: "some-other-project", - SourceSpec: duckv1.SourceSpec{ - Sink: buildSourceSpec.Sink, - }, - }, - Topic: buildSourceSpec.Topic, - }, - allowed: false, - }, - "ServiceAccountName changed": { - orig: &buildSourceSpecWithKSA, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "new-service-account", - }, - SourceSpec: duckv1.SourceSpec{ - Sink: buildSourceSpecWithKSA.Sink, - }, - Project: buildSourceSpecWithKSA.Project, - }, - Topic: buildSourceSpecWithKSA.Topic, - }, - allowed: false, - }, - "Topic changed": { - orig: &buildSourceSpec, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: buildSourceSpec.Secret.Name, - }, - Key: buildSourceSpec.Secret.Key, - }, - Project: buildSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: buildSourceSpec.Sink, - }, - }, - Topic: ptr.String("test-build"), - }, - allowed: false, - }, - "Sink.APIVersion changed": { - orig: &buildSourceSpec, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: buildSourceSpec.Secret.Name, - }, - Key: buildSourceSpec.Secret.Key, - }, - Project: buildSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: buildSourceSpec.Sink.Ref.Kind, - Namespace: buildSourceSpec.Sink.Ref.Namespace, - Name: buildSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - Topic: buildSourceSpec.Topic, - }, - allowed: true, - }, - "Sink.Kind changed": { - orig: &buildSourceSpec, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: buildSourceSpec.Secret.Name, - }, - Key: buildSourceSpec.Secret.Key, - }, - Project: buildSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: buildSourceSpec.Sink.Ref.APIVersion, - Kind: "some-other-kind", - Namespace: buildSourceSpec.Sink.Ref.Namespace, - Name: buildSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - Topic: buildSourceSpec.Topic, - }, - allowed: true, - }, - "Sink.Namespace changed": { - orig: &buildSourceSpec, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: buildSourceSpec.Secret.Name, - }, - Key: buildSourceSpec.Secret.Key, - }, - Project: buildSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: buildSourceSpec.Sink.Ref.APIVersion, - Kind: buildSourceSpec.Sink.Ref.Kind, - Namespace: "some-other-namespace", - Name: buildSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - Topic: buildSourceSpec.Topic, - }, - allowed: true, - }, - "Sink.Name changed": { - orig: &buildSourceSpec, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: buildSourceSpec.Secret.Name, - }, - Key: buildSourceSpec.Secret.Key, - }, - Project: buildSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: buildSourceSpec.Sink.Ref.APIVersion, - Kind: buildSourceSpec.Sink.Ref.Kind, - Namespace: buildSourceSpec.Sink.Ref.Namespace, - Name: "some-other-name", - }, - }, - }, - }, - Topic: buildSourceSpec.Topic, - }, - allowed: true, - }, - "no change": { - orig: &buildSourceSpec, - updated: buildSourceSpec, - allowed: true, - }, - "no spec": { - orig: []string{"wrong"}, - updated: buildSourceSpec, - allowed: true, - }, - } - - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - var orig *CloudBuildSource - - if tc.origAnnotation != nil { - orig = &CloudBuildSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.origAnnotation, - }, - } - } else if tc.orig != nil { - if spec, ok := tc.orig.(*CloudBuildSourceSpec); ok { - orig = &CloudBuildSource{ - Spec: *spec, - } - } - } - updated := &CloudBuildSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.updatedAnnotation, - }, - Spec: tc.updated, - } - err := updated.CheckImmutableFields(context.TODO(), orig) - if tc.allowed != (err == nil) { - t.Fatalf("Unexpected immutable field check. Expected %v. Actual %v", tc.allowed, err) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_conversion.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_conversion.go deleted file mode 100644 index dcb22fa19e..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_conversion.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - "github.com/google/knative-gcp/pkg/apis/convert" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - "knative.dev/pkg/apis" -) - -// ConvertTo implements apis.Convertible. -// Converts from a v1alpha1.CloudPubSubSource to a higher version of CloudPubSubSource. -func (source *CloudPubSubSource) ConvertTo(ctx context.Context, to apis.Convertible) error { - switch sink := to.(type) { - case *v1beta1.CloudPubSubSource: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.ToV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.Topic = source.Spec.Topic - sink.Spec.AckDeadline = source.Spec.AckDeadline - sink.Spec.RetainAckedMessages = source.Spec.RetainAckedMessages - sink.Spec.RetentionDuration = source.Spec.RetentionDuration - sink.Status.PubSubStatus = convert.ToV1beta1PubSubStatus(source.Status.PubSubStatus) - // Remove v1alpha1 as deprecated from the Status Condition when converting to a higher version. - convert.RemoveV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertToViaProxy(ctx, source, &v1beta1.CloudPubSubSource{}, sink) - } -} - -// ConvertFrom implements apis.Convertible. -// Converts from a higher version of CloudPubSubSource to a v1alpha1.CloudPubSubSource. -func (sink *CloudPubSubSource) ConvertFrom(ctx context.Context, from apis.Convertible) error { - switch source := from.(type) { - case *v1beta1.CloudPubSubSource: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.FromV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.Topic = source.Spec.Topic - sink.Spec.AckDeadline = source.Spec.AckDeadline - sink.Spec.RetainAckedMessages = source.Spec.RetainAckedMessages - sink.Spec.RetentionDuration = source.Spec.RetentionDuration - sink.Status.PubSubStatus = convert.FromV1beta1PubSubStatus(source.Status.PubSubStatus) - // Mark v1alpha1 as deprecated as a Status Condition when converting to v1alpha1. - convert.MarkV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertFromViaProxy(ctx, source, &v1beta1.CloudPubSubSource{}, sink) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_conversion_test.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_conversion_test.go deleted file mode 100644 index f30b207d62..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_conversion_test.go +++ /dev/null @@ -1,181 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "net/url" - "testing" - - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/convert" - - "github.com/google/go-cmp/cmp" - v1 "github.com/google/knative-gcp/pkg/apis/events/v1" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - gcptesting "github.com/google/knative-gcp/pkg/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -// These variables are used to create a 'complete' version of CloudPubSubSource where every field is -// filled in. -var ( - // completeCloudPubSubSource is a CloudPubSubSource with every field filled in, except TypeMeta. - // TypeMeta is excluded because conversions do not convert it and this variable was created to - // test conversions. - completeCloudPubSubSource = &CloudPubSubSource{ - ObjectMeta: gcptesting.CompleteObjectMeta, - Spec: CloudPubSubSourceSpec{ - PubSubSpec: gcptesting.CompleteV1alpha1PubSubSpec, - Topic: "topic", - AckDeadline: &gcptesting.AckDeadline, - RetainAckedMessages: true, - RetentionDuration: &gcptesting.RetentionDuration, - }, - Status: CloudPubSubSourceStatus{ - PubSubStatus: gcptesting.CompleteV1alpha1PubSubStatus, - }, - } -) - -func TestCloudPubSubSourceConversionBadType(t *testing.T) { - good, bad := &CloudPubSubSource{}, &CloudStorageSource{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestCloudPubSubSourceConversionBetweenV1beta1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.CloudPubSubSource{}} - - tests := []struct { - name string - in *CloudPubSubSource - }{{ - name: "min configuration", - in: &CloudPubSubSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: CloudPubSubSourceSpec{}, - }, - }, { - name: "full configuration", - in: completeCloudPubSubSource, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &CloudPubSubSource{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - if diff := cmp.Diff(test.in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} - -func TestCloudPubSubSourceConversionBetweenV1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1.CloudPubSubSource{}} - - tests := []struct { - name string - in *CloudPubSubSource - }{{ - name: "min configuration", - in: &CloudPubSubSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: CloudPubSubSourceSpec{}, - }, - }, { - name: "full configuration", - in: completeCloudPubSubSource, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - // DeepCopy because we will edit it below. - in := test.in.DeepCopy() - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &CloudPubSubSource{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - // IdentityStatus.ServiceAccountName in v1alpha1 and v1beta1, it doesn't exist in v1. - // So this is not a round trip, the field will be silently removed. - in.Status.ServiceAccountName = "" - if diff := cmp.Diff(in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_defaults.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_defaults.go deleted file mode 100644 index 46b311ba9c..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_defaults.go +++ /dev/null @@ -1,49 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - - "knative.dev/pkg/apis" - "knative.dev/pkg/ptr" - - "github.com/google/knative-gcp/pkg/apis/duck" - "github.com/google/knative-gcp/pkg/apis/intevents" - metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" -) - -func (ps *CloudPubSubSource) SetDefaults(ctx context.Context) { - ctx = apis.WithinParent(ctx, ps.ObjectMeta) - ps.Spec.SetDefaults(ctx) - duck.SetClusterNameAnnotation(&ps.ObjectMeta, metadataClient.NewDefaultMetadataClient()) - duck.SetAutoscalingAnnotationsDefaults(ctx, &ps.ObjectMeta) -} - -func (pss *CloudPubSubSourceSpec) SetDefaults(ctx context.Context) { - pss.SetPubSubDefaults(ctx) - - if pss.AckDeadline == nil { - ackDeadline := intevents.DefaultAckDeadline - pss.AckDeadline = ptr.String(ackDeadline.String()) - } - - if pss.RetentionDuration == nil { - retentionDuration := intevents.DefaultRetentionDuration - pss.RetentionDuration = ptr.String(retentionDuration.String()) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_defaults_test.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_defaults_test.go deleted file mode 100644 index 91dcc263f6..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_defaults_test.go +++ /dev/null @@ -1,152 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - "time" - - "knative.dev/pkg/ptr" - - "github.com/google/go-cmp/cmp" - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents" - testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestCloudPubSubSourceDefaults(t *testing.T) { - - defaultRetentionDuration := intevents.DefaultRetentionDuration - defaultAckDeadline := intevents.DefaultAckDeadline - - tests := []struct { - name string - start *CloudPubSubSource - want *CloudPubSubSource - }{{ - name: "non-nil", - start: &CloudPubSubSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudPubSubSourceSpec{ - RetentionDuration: ptr.String(defaultRetentionDuration.String()), - AckDeadline: ptr.String(defaultAckDeadline.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "my-cloud-key", - }, - Key: "test.json", - }, - }, - }, - }, - want: &CloudPubSubSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudPubSubSourceSpec{ - RetentionDuration: ptr.String(defaultRetentionDuration.String()), - AckDeadline: ptr.String(defaultAckDeadline.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "my-cloud-key", - }, - Key: "test.json", - }, - }, - }, - }, - }, { - // Due to the limitation mentioned in https://github.com/google/knative-gcp/issues/1037, specifying the cluster name annotation. - name: "nil, except cluster name annotations", - start: &CloudPubSubSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudPubSubSourceSpec{}, - }, - want: &CloudPubSubSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudPubSubSourceSpec{ - RetentionDuration: ptr.String(defaultRetentionDuration.String()), - AckDeadline: ptr.String(defaultAckDeadline.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &gcpauthtesthelper.Secret, - }, - }, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.start - got.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } - }) - } -} - -func TestCloudPubSubSourceDefaults_NoChange(t *testing.T) { - days2 := 2 * 24 * time.Hour - secs60 := 60 * time.Second - want := &CloudPubSubSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudPubSubSourceSpec{ - AckDeadline: ptr.String(secs60.String()), - RetentionDuration: ptr.String(days2.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "my-cloud-key", - }, - Key: "test.json", - }, - }, - }, - } - - got := want.DeepCopy() - got.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_lifecycle.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_lifecycle.go deleted file mode 100644 index 8b2a13c4ce..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_lifecycle.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "knative.dev/pkg/apis" -) - -// GetCondition returns the condition currently associated with the given type, or nil. -func (ps *CloudPubSubSourceStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return pubSubCondSet.Manage(ps).GetCondition(t) -} - -// GetTopLevelCondition returns the top level condition. -func (ps *CloudPubSubSourceStatus) GetTopLevelCondition() *apis.Condition { - return pubSubCondSet.Manage(ps).GetTopLevelCondition() -} - -// IsReady returns true if the resource is ready overall. -func (ps *CloudPubSubSourceStatus) IsReady() bool { - return pubSubCondSet.Manage(ps).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (ps *CloudPubSubSourceStatus) InitializeConditions() { - pubSubCondSet.Manage(ps).InitializeConditions() -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_lifecycle_test.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_lifecycle_test.go deleted file mode 100644 index 262864511f..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_lifecycle_test.go +++ /dev/null @@ -1,157 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/go-cmp/cmp/cmpopts" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" -) - -func TestCloudPubSubSourceStatusIsReady(t *testing.T) { - tests := []struct { - name string - s *CloudPubSubSourceStatus - wantConditionStatus corev1.ConditionStatus - want bool - }{ - { - name: "uninitialized", - s: &CloudPubSubSourceStatus{}, - want: false, - }, { - name: "initialized", - s: func() *CloudPubSubSourceStatus { - s := &CloudPubSubSource{} - s.Status.InitializeConditions() - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, - { - name: "the status of pullsubscription is false", - s: func() *CloudPubSubSourceStatus { - s := &CloudPubSubSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), "PullSubscriptionFalse", "status false test message") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - }, { - name: "the status of pullsubscription is unknown", - s: func() *CloudPubSubSourceStatus { - s := &CloudPubSubSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), "PullSubscriptionUnknonw", "status unknown test message") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - }, - { - name: "ready", - s: func() *CloudPubSubSourceStatus { - s := &CloudPubSubSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - return &s.Status - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - if test.wantConditionStatus != "" { - gotConditionStatus := test.s.GetTopLevelCondition().Status - if gotConditionStatus != test.wantConditionStatus { - t.Errorf("unexpected condition status: want %v, got %v", test.wantConditionStatus, gotConditionStatus) - } - } - got := test.s.IsReady() - if got != test.want { - t.Errorf("unexpected readiness: want %v, got %v", test.want, got) - } - }) - } -} -func TestCloudPubSubSourceStatusGetCondition(t *testing.T) { - tests := []struct { - name string - s *CloudPubSubSourceStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "uninitialized", - s: &CloudPubSubSourceStatus{}, - condQuery: CloudPubSubSourceConditionReady, - want: nil, - }, { - name: "initialized", - s: func() *CloudPubSubSourceStatus { - s := &CloudPubSubSourceStatus{} - s.InitializeConditions() - return s - }(), - condQuery: CloudPubSubSourceConditionReady, - want: &apis.Condition{ - Type: CloudPubSubSourceConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "not ready", - s: func() *CloudPubSubSourceStatus { - s := &CloudPubSubSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), "NotReady", "test message") - return &s.Status - }(), - condQuery: duckv1alpha1.PullSubscriptionReady, - want: &apis.Condition{ - Type: duckv1alpha1.PullSubscriptionReady, - Status: corev1.ConditionFalse, - Reason: "NotReady", - Message: "test message", - }, - }, { - name: "ready", - s: func() *CloudPubSubSourceStatus { - s := &CloudPubSubSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - return &s.Status - }(), - condQuery: duckv1alpha1.PullSubscriptionReady, - want: &apis.Condition{ - Type: duckv1alpha1.PullSubscriptionReady, - Status: corev1.ConditionTrue, - }, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.s.GetCondition(test.condQuery) - ignoreTime := cmpopts.IgnoreFields(apis.Condition{}, - "LastTransitionTime", "Severity") - if diff := cmp.Diff(test.want, got, ignoreTime); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_types.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_types.go deleted file mode 100644 index 9fc978f760..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_types.go +++ /dev/null @@ -1,168 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "time" - - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents" - kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "knative.dev/pkg/kmeta" - "knative.dev/pkg/webhook/resourcesemantics" - - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// CloudPubSubSource is a specification for a CloudPubSubSource resource. -// +k8s:openapi-gen=true -type CloudPubSubSource struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec CloudPubSubSourceSpec `json:"spec,omitempty"` - Status CloudPubSubSourceStatus `json:"status,omitempty"` -} - -// Verify that CloudPubSubSource matches various duck types. -var ( - _ apis.Convertible = (*CloudPubSubSource)(nil) - _ apis.Defaultable = (*CloudPubSubSource)(nil) - _ apis.Validatable = (*CloudPubSubSource)(nil) - _ runtime.Object = (*CloudPubSubSource)(nil) - _ kmeta.OwnerRefable = (*CloudPubSubSource)(nil) - _ resourcesemantics.GenericCRD = (*CloudPubSubSource)(nil) - _ kngcpduck.Identifiable = (*CloudPubSubSource)(nil) - _ kngcpduck.PubSubable = (*CloudPubSubSource)(nil) -) - -// CloudPubSubSourceSpec defines the desired state of the CloudPubSubSource. -type CloudPubSubSourceSpec struct { - // This brings in the PubSub based Source Specs. Includes: - // Sink, CloudEventOverrides, Secret and Project - duckv1alpha1.PubSubSpec `json:",inline"` - - // Topic is the ID of the PubSub Topic to Subscribe to. It must - // be in the form of the unique identifier within the project, not the - // entire name. E.g. it must be 'laconia', not - // 'projects/my-proj/topics/laconia'. - Topic string `json:"topic"` - - // AckDeadline is the default maximum time after a subscriber receives a - // message before the subscriber should acknowledge the message. Defaults - // to 30 seconds ('30s'). - // +optional - AckDeadline *string `json:"ackDeadline,omitempty"` - - // RetainAckedMessages defines whether to retain acknowledged messages. If - // true, acknowledged messages will not be expunged until they fall out of - // the RetentionDuration window. - RetainAckedMessages bool `json:"retainAckedMessages,omitempty"` - - // RetentionDuration defines how long to retain messages in backlog, from - // the time of publish. If RetainAckedMessages is true, this duration - // affects the retention of acknowledged messages, otherwise only - // unacknowledged messages are retained. Cannot be longer than 7 days or - // shorter than 10 minutes. Defaults to 7 days ('7d'). - // +optional - RetentionDuration *string `json:"retentionDuration,omitempty"` -} - -// GetAckDeadline parses AckDeadline and returns the default if an error occurs. -func (ps CloudPubSubSourceSpec) GetAckDeadline() time.Duration { - if ps.AckDeadline != nil { - if duration, err := time.ParseDuration(*ps.AckDeadline); err == nil { - return duration - } - } - return intevents.DefaultAckDeadline -} - -// GetRetentionDuration parses RetentionDuration and returns the default if an error occurs. -func (ps CloudPubSubSourceSpec) GetRetentionDuration() time.Duration { - if ps.RetentionDuration != nil { - if duration, err := time.ParseDuration(*ps.RetentionDuration); err == nil { - return duration - } - } - return intevents.DefaultRetentionDuration -} - -const ( - // CloudPubSubSourceConditionReady has status True when the CloudPubSubSource is - // ready to send events. - CloudPubSubSourceConditionReady = apis.ConditionReady -) - -var pubSubCondSet = apis.NewLivingConditionSet( - duckv1alpha1.PullSubscriptionReady, -) - -// CloudPubSubSourceStatus defines the observed state of CloudPubSubSource. -type CloudPubSubSourceStatus struct { - // This brings in duck/v1beta1 Status as well as SinkURI - duckv1alpha1.PubSubStatus `json:",inline"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// CloudPubSubSourceList contains a list of CloudPubSubSources. -type CloudPubSubSourceList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []CloudPubSubSource `json:"items"` -} - -// GetGroupVersionKind returns the GroupVersionKind. -func (s *CloudPubSubSource) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("CloudPubSubSource") -} - -// Methods for identifiable interface. -// IdentitySpec returns the IdentitySpec portion of the Spec. -func (s *CloudPubSubSource) IdentitySpec() *duckv1alpha1.IdentitySpec { - return &s.Spec.IdentitySpec -} - -// IdentityStatus returns the IdentityStatus portion of the Status. -func (s *CloudPubSubSource) IdentityStatus() *duckv1alpha1.IdentityStatus { - return &s.Status.IdentityStatus -} - -// ConditionSet returns the apis.ConditionSet of the embedding object. -func (ps *CloudPubSubSource) ConditionSet() *apis.ConditionSet { - return &pubSubCondSet -} - -// Methods for pubsubable interface. - -// CloudPubSubSourceSpec returns the CloudPubSubSourceSpec portion of the Spec. -func (ps *CloudPubSubSource) PubSubSpec() *duckv1alpha1.PubSubSpec { - return &ps.Spec.PubSubSpec -} - -// CloudPubSubSourceSpec returns the CloudPubSubSourceStatus portion of the Spec. -func (s *CloudPubSubSource) PubSubStatus() *duckv1alpha1.PubSubStatus { - return &s.Status.PubSubStatus -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_types_test.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_types_test.go deleted file mode 100644 index d0b225bfce..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_types_test.go +++ /dev/null @@ -1,139 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - "time" - - "github.com/google/go-cmp/cmp/cmpopts" - "knative.dev/pkg/apis" - - "knative.dev/pkg/ptr" - - "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -func TestCloudPubSubSourceGetGroupVersionKind(t *testing.T) { - want := schema.GroupVersionKind{ - Group: "events.cloud.google.com", - Version: "v1alpha1", - Kind: "CloudPubSubSource", - } - - c := &CloudPubSubSource{} - got := c.GetGroupVersionKind() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestGetAckDeadline(t *testing.T) { - want := 10 * time.Second - s := &CloudPubSubSourceSpec{AckDeadline: ptr.String("10s")} - got := s.GetAckDeadline() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestGetRetentionDuration(t *testing.T) { - want := 10 * time.Second - s := &CloudPubSubSourceSpec{RetentionDuration: ptr.String("10s")} - got := s.GetRetentionDuration() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestGetAckDeadline_default(t *testing.T) { - want := intevents.DefaultAckDeadline - s := &CloudPubSubSourceSpec{} - got := s.GetAckDeadline() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestGetRetentionDuration_default(t *testing.T) { - want := intevents.DefaultRetentionDuration - s := &CloudPubSubSourceSpec{} - got := s.GetRetentionDuration() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudPubSubSourceIdentitySpec(t *testing.T) { - s := &CloudPubSubSource{ - Spec: CloudPubSubSourceSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "test", - }, - }, - }, - } - want := "test" - got := s.IdentitySpec().ServiceAccountName - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudPubSubSourceIdentityStatus(t *testing.T) { - s := &CloudPubSubSource{ - Status: CloudPubSubSourceStatus{ - PubSubStatus: v1alpha1.PubSubStatus{}, - }, - } - want := &v1alpha1.IdentityStatus{} - got := s.IdentityStatus() - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudPubSubSourceConditionSet(t *testing.T) { - want := []apis.Condition{{ - Type: v1alpha1.PullSubscriptionReady, - }, { - Type: apis.ConditionReady, - }} - c := &CloudPubSubSource{} - - c.ConditionSet().Manage(&c.Status).InitializeConditions() - var got []apis.Condition = c.Status.GetConditions() - - compareConditionTypes := cmp.Transformer("ConditionType", func(c apis.Condition) apis.ConditionType { - return c.Type - }) - sortConditionTypes := cmpopts.SortSlices(func(a, b apis.Condition) bool { - return a.Type < b.Type - }) - if diff := cmp.Diff(want, got, sortConditionTypes, compareConditionTypes); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_validation.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_validation.go deleted file mode 100644 index 3204720620..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_validation.go +++ /dev/null @@ -1,105 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - "time" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck" - "github.com/google/knative-gcp/pkg/apis/intevents" - - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -func (current *CloudPubSubSource) Validate(ctx context.Context) *apis.FieldError { - errs := current.Spec.Validate(ctx).ViaField("spec") - - if apis.IsInUpdate(ctx) { - original := apis.GetBaseline(ctx).(*CloudPubSubSource) - errs = errs.Also(current.CheckImmutableFields(ctx, original)) - } - return duck.ValidateAutoscalingAnnotations(ctx, current.Annotations, errs) -} - -func (current *CloudPubSubSourceSpec) Validate(ctx context.Context) *apis.FieldError { - var errs *apis.FieldError - // Topic [required] - if current.Topic == "" { - errs = errs.Also(apis.ErrMissingField("topic")) - } - // Sink [required] - if equality.Semantic.DeepEqual(current.Sink, duckv1.Destination{}) { - errs = errs.Also(apis.ErrMissingField("sink")) - } else if err := current.Sink.Validate(ctx); err != nil { - errs = errs.Also(err.ViaField("sink")) - } - - if current.RetentionDuration != nil { - // If set, RetentionDuration Cannot be longer than 7 days or shorter than 10 minutes. - rd, err := time.ParseDuration(*current.RetentionDuration) - if err != nil { - errs = errs.Also(apis.ErrInvalidValue(*current.RetentionDuration, "retentionDuration")) - } else if rd < intevents.MinRetentionDuration || rd > intevents.MaxRetentionDuration { - errs = errs.Also(apis.ErrOutOfBoundsValue(*current.RetentionDuration, intevents.MinRetentionDuration.String(), intevents.MaxRetentionDuration.String(), "retentionDuration")) - } - } - - if current.AckDeadline != nil { - // If set, AckDeadline needs to parse to a valid duration. - ad, err := time.ParseDuration(*current.AckDeadline) - if err != nil { - errs = errs.Also(apis.ErrInvalidValue(*current.AckDeadline, "ackDeadline")) - } else if ad < intevents.MinAckDeadline || ad > intevents.MaxAckDeadline { - errs = errs.Also(apis.ErrOutOfBoundsValue(*current.AckDeadline, intevents.MinAckDeadline.String(), intevents.MaxAckDeadline.String(), "ackDeadline")) - } - } - - if err := duck.ValidateCredential(current.Secret, current.ServiceAccountName); err != nil { - errs = errs.Also(err) - } - - return errs -} - -func (current *CloudPubSubSource) CheckImmutableFields(ctx context.Context, original *CloudPubSubSource) *apis.FieldError { - if original == nil { - return nil - } - - var errs *apis.FieldError - // Modification of Topic, Secret, AckDeadline, RetainAckedMessages, RetentionDuration, ServiceAccountName and Project are not allowed. - // Everything else is mutable. - if diff := cmp.Diff(original.Spec, current.Spec, - cmpopts.IgnoreFields(CloudPubSubSourceSpec{}, - "Sink", "CloudEventOverrides")); diff != "" { - errs = errs.Also(&apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - }) - } - // Modification of AutoscalingClassAnnotations is not allowed. - errs = duck.CheckImmutableAutoscalingClassAnnotations(¤t.ObjectMeta, &original.ObjectMeta, errs) - - // Modification of non-empty cluster name annotation is not allowed. - return duck.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) -} diff --git a/pkg/apis/events/v1alpha1/cloudpubsubsource_validation_test.go b/pkg/apis/events/v1alpha1/cloudpubsubsource_validation_test.go deleted file mode 100644 index d0c480bf5f..0000000000 --- a/pkg/apis/events/v1alpha1/cloudpubsubsource_validation_test.go +++ /dev/null @@ -1,657 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - "testing" - - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/ptr" -) - -var ( - pubSubSourceSpec = CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key", - }, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Project: "my-eventing-project", - }, - Topic: "pubsub-topic", - AckDeadline: ptr.String("30s"), - RetainAckedMessages: true, - RetentionDuration: ptr.String("30s"), - } - - pubSubSourceSpecWithKSA = CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Project: "my-eventing-project", - }, - Topic: "pubsub-topic", - } -) - -func TestCloudPubSubSourceCheckValidationFields(t *testing.T) { - testCases := map[string]struct { - spec CloudPubSubSourceSpec - error bool - }{ - "ok": { - spec: pubSubSourceSpec, - error: false, - }, - "no topic": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.Topic = "" - return *obj - }(), - error: true, - }, - "bad RetentionDuration": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.RetentionDuration = ptr.String("wrong") - return *obj - }(), - error: true, - }, - "bad RetentionDuration, range": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.RetentionDuration = ptr.String("10000h") - return *obj - }(), - error: true, - }, - "bad AckDeadline": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.AckDeadline = ptr.String("wrong") - return *obj - }(), - error: true, - }, - "bad AckDeadline, range": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.AckDeadline = ptr.String("10000h") - return *obj - }(), - error: true, - }, - "bad sink, name": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.Sink.Ref.Name = "" - return *obj - }(), - error: true, - }, - "bad sink, apiVersion": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.Sink.Ref.APIVersion = "" - return *obj - }(), - error: true, - }, - "bad sink, kind": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.Sink.Ref.Kind = "" - return *obj - }(), - error: true, - }, - "bad sink, empty": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.Sink = duckv1.Destination{} - return *obj - }(), - error: true, - }, - "bad sink, uri scheme": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.Sink = duckv1.Destination{ - URI: &apis.URL{ - Host: "example.com", - }, - } - return *obj - }(), - error: true, - }, - "bad sink, uri host": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.Sink = duckv1.Destination{ - URI: &apis.URL{ - Scheme: "http", - }, - } - return *obj - }(), - error: true, - }, - "bad sink, uri and ref": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.Sink = duckv1.Destination{ - URI: &apis.URL{ - Scheme: "http", - Host: "example.com", - }, - Ref: &duckv1.KReference{ - Name: "foo", - }, - } - return *obj - }(), - error: true, - }, - "invalid secret, missing key": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.Secret = &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: gcpauthtesthelper.Secret.Name, - }, - } - return *obj - }(), - error: true, - }, - "nil service account": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - return *obj - }(), - error: false, - }, - "invalid k8s service account": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.ServiceAccountName = invalidServiceAccountName - return *obj - }(), - error: true, - }, - "have k8s service account and secret at the same time": { - spec: func() CloudPubSubSourceSpec { - obj := pubSubSourceSpec.DeepCopy() - obj.ServiceAccountName = validServiceAccountName - obj.Secret = &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "google-cloud-key", - }, - Key: "key.json", - } - return *obj - }(), - error: true, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - err := tc.spec.Validate(context.TODO()) - if tc.error != (err != nil) { - t.Fatalf("Unexpected validation failure. Got %v", err) - } - }) - } -} - -func TestCloudPubSubSourceCheckImmutableFields(t *testing.T) { - testCases := map[string]struct { - orig interface{} - updated CloudPubSubSourceSpec - origAnnotation map[string]string - updatedAnnotation map[string]string - allowed bool - }{ - "nil orig": { - updated: pubSubSourceSpec, - allowed: true, - }, - "ClusterName annotation changed": { - origAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", - }, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: false, - }, - "AnnotationClass annotation changed": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA + "new", - }, - allowed: false, - }, - "AnnotationClass annotation added": { - origAnnotation: map[string]string{}, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - allowed: false, - }, - "AnnotationClass annotation deleted": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{}, - allowed: false, - }, - "Secret.Name changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "some-other-name", - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpec.Sink, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: false, - }, - "Secret.Key changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: "some-other-key", - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpec.Sink, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: false, - }, - "Project changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: "some-other-project", - SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpec.Sink, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: false, - }, - "ServiceAccountName changed": { - orig: &pubSubSourceSpecWithKSA, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "new-service-account", - }, - SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpecWithKSA.Sink, - }, - Project: pubSubSourceSpecWithKSA.Project, - }, - Topic: pubSubSourceSpecWithKSA.Topic, - }, - allowed: false, - }, - "AckDeadline changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpec.Sink, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: ptr.String("50s"), - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: false, - }, - "RetainAckedMessages changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpec.Sink, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: false, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: false, - }, - "RetentionDuration changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpec.Sink, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: ptr.String("50s"), - }, - allowed: false, - }, - "Topic changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pubSubSourceSpec.Sink, - }, - }, - Topic: "some-other-topic", - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: false, - }, - "ServiceAccountName added": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: pubSubSourceSpec.SourceSpec, - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - }, - Topic: pubSubSourceSpecWithKSA.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: false, - }, - "ClusterName annotation added": { - origAnnotation: nil, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: true, - }, - "Sink.APIVersion changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: pubSubSourceSpec.Sink.Ref.Kind, - Namespace: pubSubSourceSpec.Sink.Ref.Namespace, - Name: pubSubSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: true, - }, - "Sink.Kind changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: pubSubSourceSpec.Sink.Ref.APIVersion, - Kind: "some-other-kind", - Namespace: pubSubSourceSpec.Sink.Ref.Namespace, - Name: pubSubSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: true, - }, - "Sink.Namespace changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: pubSubSourceSpec.Sink.Ref.APIVersion, - Kind: pubSubSourceSpec.Sink.Ref.Kind, - Namespace: "some-other-namespace", - Name: pubSubSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: true, - }, - "Sink.Name changed": { - orig: &pubSubSourceSpec, - updated: CloudPubSubSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pubSubSourceSpec.Secret.Name, - }, - Key: pubSubSourceSpec.Secret.Key, - }, - Project: pubSubSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: pubSubSourceSpec.Sink.Ref.APIVersion, - Kind: pubSubSourceSpec.Sink.Ref.Kind, - Namespace: pubSubSourceSpec.Sink.Ref.Namespace, - Name: "some-other-name", - }, - }, - }, - }, - Topic: pubSubSourceSpec.Topic, - AckDeadline: pubSubSourceSpec.AckDeadline, - RetainAckedMessages: pubSubSourceSpec.RetainAckedMessages, - RetentionDuration: pubSubSourceSpec.RetentionDuration, - }, - allowed: true, - }, - "no change": { - orig: &pubSubSourceSpec, - updated: pubSubSourceSpec, - allowed: true, - }, - "no spec": { - orig: []string{"wrong"}, - updated: pubSubSourceSpec, - allowed: true, - }, - } - - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - var orig *CloudPubSubSource - - if tc.origAnnotation != nil { - orig = &CloudPubSubSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.origAnnotation, - }, - } - } else if tc.orig != nil { - if spec, ok := tc.orig.(*CloudPubSubSourceSpec); ok { - orig = &CloudPubSubSource{ - Spec: *spec, - } - } - } - updated := &CloudPubSubSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.updatedAnnotation, - }, - Spec: tc.updated, - } - err := updated.CheckImmutableFields(context.TODO(), orig) - if tc.allowed != (err == nil) { - t.Fatalf("Unexpected immutable field check. Expected %v. Actual %v", tc.allowed, err) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_conversion.go b/pkg/apis/events/v1alpha1/cloudschedulersource_conversion.go deleted file mode 100644 index 1f5b4d6ab2..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_conversion.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - "github.com/google/knative-gcp/pkg/apis/convert" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - "knative.dev/pkg/apis" -) - -// ConvertTo implements apis.Convertible. -// Converts from a v1alpha1.CloudSchedulerSource to a higher version of CloudSchedulerSource. -func (source *CloudSchedulerSource) ConvertTo(ctx context.Context, to apis.Convertible) error { - switch sink := to.(type) { - case *v1beta1.CloudSchedulerSource: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.ToV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.Location = source.Spec.Location - sink.Spec.Schedule = source.Spec.Schedule - sink.Spec.Data = source.Spec.Data - sink.Status.PubSubStatus = convert.ToV1beta1PubSubStatus(source.Status.PubSubStatus) - sink.Status.JobName = source.Status.JobName - // Remove v1alpha1 as deprecated from the Status Condition when converting to a higher version. - convert.RemoveV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertToViaProxy(ctx, source, &v1beta1.CloudSchedulerSource{}, sink) - } -} - -// ConvertFrom implements apis.Convertible. -// Converts from a higher version of CloudSchedulerSource to a v1alpha1.CloudSchedulerSource. -func (sink *CloudSchedulerSource) ConvertFrom(ctx context.Context, from apis.Convertible) error { - switch source := from.(type) { - case *v1beta1.CloudSchedulerSource: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.FromV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.Location = source.Spec.Location - sink.Spec.Schedule = source.Spec.Schedule - sink.Spec.Data = source.Spec.Data - sink.Status.PubSubStatus = convert.FromV1beta1PubSubStatus(source.Status.PubSubStatus) - sink.Status.JobName = source.Status.JobName - // Mark v1alpha1 as deprecated as a Status Condition when converting to v1alpha1. - convert.MarkV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertFromViaProxy(ctx, source, &v1beta1.CloudSchedulerSource{}, sink) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_conversion_test.go b/pkg/apis/events/v1alpha1/cloudschedulersource_conversion_test.go deleted file mode 100644 index e807174512..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_conversion_test.go +++ /dev/null @@ -1,181 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "net/url" - "testing" - - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/convert" - - "github.com/google/go-cmp/cmp" - v1 "github.com/google/knative-gcp/pkg/apis/events/v1" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - gcptesting "github.com/google/knative-gcp/pkg/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -// These variables are used to create a 'complete' version of CloudSchedulerSource where every field is -// filled in. -var ( - // completeCloudSchedulerSource is a CloudSchedulerSource with every field filled in, except TypeMeta. - // TypeMeta is excluded because conversions do not convert it and this variable was created to - // test conversions. - completeCloudSchedulerSource = &CloudSchedulerSource{ - ObjectMeta: gcptesting.CompleteObjectMeta, - Spec: CloudSchedulerSourceSpec{ - PubSubSpec: gcptesting.CompleteV1alpha1PubSubSpec, - Location: "location", - Schedule: "schedule", - Data: "data", - }, - Status: CloudSchedulerSourceStatus{ - PubSubStatus: gcptesting.CompleteV1alpha1PubSubStatus, - JobName: "jobName", - }, - } -) - -func TestCloudSchedulerSourceConversionBadType(t *testing.T) { - good, bad := &CloudSchedulerSource{}, &CloudStorageSource{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestCloudSchedulerSourceConversionBetweenV1beta1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.CloudSchedulerSource{}} - - tests := []struct { - name string - in *CloudSchedulerSource - }{{ - name: "min configuration", - in: &CloudSchedulerSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: CloudSchedulerSourceSpec{}, - }, - }, { - name: "full configuration", - in: completeCloudSchedulerSource, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &CloudSchedulerSource{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - if diff := cmp.Diff(test.in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} - -func TestCloudSchedulerSourceConversionBetweenV1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1.CloudSchedulerSource{}} - - tests := []struct { - name string - in *CloudSchedulerSource - }{{ - name: "min configuration", - in: &CloudSchedulerSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: CloudSchedulerSourceSpec{}, - }, - }, { - name: "full configuration", - in: completeCloudSchedulerSource, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - // DeepCopy because we will edit it below. - in := test.in.DeepCopy() - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &CloudSchedulerSource{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - // IdentityStatus.ServiceAccountName in v1alpha1 and v1beta1, it doesn't exist in v1. - // So this is not a round trip, the field will be silently removed. - in.Status.ServiceAccountName = "" - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - if diff := cmp.Diff(in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_defaults.go b/pkg/apis/events/v1alpha1/cloudschedulersource_defaults.go deleted file mode 100644 index b0dfc380cb..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_defaults.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - - "knative.dev/pkg/apis" - - "github.com/google/knative-gcp/pkg/apis/duck" - metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" -) - -func (s *CloudSchedulerSource) SetDefaults(ctx context.Context) { - ctx = apis.WithinParent(ctx, s.ObjectMeta) - s.Spec.SetPubSubDefaults(ctx) - duck.SetClusterNameAnnotation(&s.ObjectMeta, metadataClient.NewDefaultMetadataClient()) - duck.SetAutoscalingAnnotationsDefaults(ctx, &s.ObjectMeta) -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_defaults_test.go b/pkg/apis/events/v1alpha1/cloudschedulersource_defaults_test.go deleted file mode 100644 index 22d123e508..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_defaults_test.go +++ /dev/null @@ -1,109 +0,0 @@ -/* -Copyright 2019 Google LLC - -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" - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestCloudSchedulerSource_SetDefaults(t *testing.T) { - testCases := map[string]struct { - orig *CloudSchedulerSource - expected *CloudSchedulerSource - }{ - // Due to the limitation mentioned in https://github.com/google/knative-gcp/issues/1037, specifying the cluster name annotation. - "missing defaults, except cluster name annotations": { - orig: &CloudSchedulerSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - }, - expected: &CloudSchedulerSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudSchedulerSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "google-cloud-key", - }, - Key: "key.json", - }, - }, - }, - }, - }, - "defaults present": { - orig: &CloudSchedulerSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudSchedulerSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key.json", - }, - }, - }, - }, - expected: &CloudSchedulerSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudSchedulerSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key.json", - }, - }, - }, - }, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - tc.orig.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - if diff := cmp.Diff(tc.expected, tc.orig); diff != "" { - t.Errorf("Unexpected differences (-want +got): %v", diff) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_lifecycle.go b/pkg/apis/events/v1alpha1/cloudschedulersource_lifecycle.go deleted file mode 100644 index ffc2a3c4b1..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_lifecycle.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "knative.dev/pkg/apis" -) - -// GetCondition returns the condition currently associated with the given type, or nil. -func (s *CloudSchedulerSourceStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return schedulerCondSet.Manage(s).GetCondition(t) -} - -// GetTopLevelCondition returns the top level condition. -func (s *CloudSchedulerSourceStatus) GetTopLevelCondition() *apis.Condition { - return schedulerCondSet.Manage(s).GetTopLevelCondition() -} - -// IsReady returns true if the resource is ready overall. -func (s *CloudSchedulerSourceStatus) IsReady() bool { - return schedulerCondSet.Manage(s).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (s *CloudSchedulerSourceStatus) InitializeConditions() { - schedulerCondSet.Manage(s).InitializeConditions() -} - -// MarkJobNotReady sets the condition that the CloudSchedulerSource Job has not been -// successfully created. -func (s *CloudSchedulerSourceStatus) MarkJobNotReady(reason, messageFormat string, messageA ...interface{}) { - schedulerCondSet.Manage(s).MarkFalse(JobReady, reason, messageFormat, messageA...) -} - -// MarkJobReady sets the condition for CloudSchedulerSource Job as Read and sets the -// Status.JobName to jobName. -func (s *CloudSchedulerSourceStatus) MarkJobReady(jobName string) { - schedulerCondSet.Manage(s).MarkTrue(JobReady) - s.JobName = jobName -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_lifecycle_test.go b/pkg/apis/events/v1alpha1/cloudschedulersource_lifecycle_test.go deleted file mode 100644 index 14412ded47..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_lifecycle_test.go +++ /dev/null @@ -1,201 +0,0 @@ -/* -Copyright 2019 Google LLC - -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" - - "knative.dev/pkg/apis" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - corev1 "k8s.io/api/core/v1" -) - -func TestCloudSchedulerSourceStatusIsReady(t *testing.T) { - tests := []struct { - name string - s *CloudSchedulerSourceStatus - wantConditionStatus corev1.ConditionStatus - want bool - }{{ - name: "uninitialized", - s: &CloudSchedulerSourceStatus{}, - want: false, - }, { - name: "initialized", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSource{} - s.Status.InitializeConditions() - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "the status of topic is false", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkJobReady("jobName") - s.Status.MarkTopicFailed(s.ConditionSet(), "TopicFailed", "the status of topic is false") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, { - name: "the status of topic is unknown", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkJobReady("jobName") - s.Status.MarkTopicUnknown(s.ConditionSet(), "TopicUnknown", "the status of topic is unknown") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "the status pullsubscription is false", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), "PullSubscriptionFailed", "the status of pullsubscription is false") - s.Status.MarkJobReady("jobName") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, { - name: "the status pullsubscription is unknown", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), "PullSubscriptionUnknown", "the status of pullsubscription is unknown") - s.Status.MarkJobReady("jobName") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "job not ready", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkJobNotReady("NotReady", "ps not ready") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, { - name: "ready", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkJobReady("jobName") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - if test.wantConditionStatus != "" { - gotConditionStatus := test.s.GetTopLevelCondition().Status - if gotConditionStatus != test.wantConditionStatus { - t.Errorf("unexpected condition status: want %v, got %v", test.wantConditionStatus, gotConditionStatus) - } - } - got := test.s.IsReady() - if got != test.want { - t.Errorf("unexpected readiness: want %v, got %v", test.want, got) - } - }) - } -} - -func TestCloudSchedulerSourceStatusGetCondition(t *testing.T) { - tests := []struct { - name string - s *CloudSchedulerSourceStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "uninitialized", - s: &CloudSchedulerSourceStatus{}, - condQuery: CloudSchedulerSourceConditionReady, - want: nil, - }, { - name: "initialized", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSourceStatus{} - s.InitializeConditions() - return s - }(), - condQuery: CloudSchedulerSourceConditionReady, - want: &apis.Condition{ - Type: CloudSchedulerSourceConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "not ready", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSourceStatus{} - s.InitializeConditions() - s.MarkJobNotReady("NotReady", "test message") - return s - }(), - condQuery: JobReady, - want: &apis.Condition{ - Type: JobReady, - Status: corev1.ConditionFalse, - Reason: "NotReady", - Message: "test message", - }, - }, { - name: "ready", - s: func() *CloudSchedulerSourceStatus { - s := &CloudSchedulerSourceStatus{} - s.InitializeConditions() - s.MarkJobReady("jobName") - return s - }(), - condQuery: JobReady, - want: &apis.Condition{ - Type: JobReady, - Status: corev1.ConditionTrue, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.s.GetCondition(test.condQuery) - ignoreTime := cmpopts.IgnoreFields(apis.Condition{}, - "LastTransitionTime", "Severity") - if diff := cmp.Diff(test.want, got, ignoreTime); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_types.go b/pkg/apis/events/v1alpha1/cloudschedulersource_types.go deleted file mode 100644 index 0f67d1e33b..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_types.go +++ /dev/null @@ -1,136 +0,0 @@ -/* -Copyright 2017 The Kubernetes 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 ( - "k8s.io/apimachinery/pkg/runtime" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" - "knative.dev/pkg/apis" - "knative.dev/pkg/kmeta" - "knative.dev/pkg/webhook/resourcesemantics" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// CloudSchedulerSource is a specification for a CloudSchedulerSource resource. -type CloudSchedulerSource struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec CloudSchedulerSourceSpec `json:"spec"` - Status CloudSchedulerSourceStatus `json:"status"` -} - -// Verify that CloudSchedulerSource matches various duck types. -var ( - _ apis.Convertible = (*CloudSchedulerSource)(nil) - _ apis.Defaultable = (*CloudSchedulerSource)(nil) - _ apis.Validatable = (*CloudSchedulerSource)(nil) - _ runtime.Object = (*CloudSchedulerSource)(nil) - _ kmeta.OwnerRefable = (*CloudSchedulerSource)(nil) - _ resourcesemantics.GenericCRD = (*CloudSchedulerSource)(nil) - _ kngcpduck.Identifiable = (*CloudSchedulerSource)(nil) - _ kngcpduck.PubSubable = (*CloudSchedulerSource)(nil) -) - -// CloudSchedulerSourceSpec is the spec for a CloudSchedulerSource resource. -type CloudSchedulerSourceSpec struct { - // This brings in the PubSub based Source Specs. Includes: - // Sink, CloudEventOverrides, Secret and Project - duckv1alpha1.PubSubSpec `json:",inline"` - - // Location where to create the Job in. - Location string `json:"location"` - - // Schedule in cron format, for example: "* * * * *" would be run - // every minute. - Schedule string `json:"schedule"` - - // What data to send - Data string `json:"data"` -} - -const ( - // CloudSchedulerSourceConditionReady has status True when CloudSchedulerSource is ready to send events. - CloudSchedulerSourceConditionReady = apis.ConditionReady - - // JobReady has status True when CloudSchedulerSource Job has been successfully created. - JobReady apis.ConditionType = "JobReady" -) - -var schedulerCondSet = apis.NewLivingConditionSet( - duckv1alpha1.PullSubscriptionReady, - duckv1alpha1.TopicReady, - JobReady) - -// CloudSchedulerSourceStatus is the status for a CloudSchedulerSource resource. -type CloudSchedulerSourceStatus struct { - // This brings in our GCP PubSub based events importers - // duck/v1beta1 Status, SinkURI, ProjectID, TopicID and SubscriptionID - duckv1alpha1.PubSubStatus `json:",inline"` - - // JobName is the name of the created scheduler Job on success. - // +optional - JobName string `json:"jobName,omitempty"` -} - -func (scheduler *CloudSchedulerSource) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("CloudSchedulerSource") -} - -// Methods for identifiable interface -// IdentitySpec returns the IdentitySpec portion of the Spec. -func (s *CloudSchedulerSource) IdentitySpec() *duckv1alpha1.IdentitySpec { - return &s.Spec.IdentitySpec -} - -// IdentityStatus returns the IdentityStatus portion of the Status. -func (s *CloudSchedulerSource) IdentityStatus() *duckv1alpha1.IdentityStatus { - return &s.Status.IdentityStatus -} - -// ConditionSet returns the apis.ConditionSet of the embedding object. -func (s *CloudSchedulerSource) ConditionSet() *apis.ConditionSet { - return &schedulerCondSet -} - -// Methods for pubsubable interface -// PubSubSpec returns the PubSubSpec portion of the Spec. -func (s *CloudSchedulerSource) PubSubSpec() *duckv1alpha1.PubSubSpec { - return &s.Spec.PubSubSpec -} - -// PubSubStatus returns the PubSubStatus portion of the Status. -func (s *CloudSchedulerSource) PubSubStatus() *duckv1alpha1.PubSubStatus { - return &s.Status.PubSubStatus -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// CloudSchedulerSourceList is a list of CloudSchedulerSource resources. -type CloudSchedulerSourceList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - - Items []CloudSchedulerSource `json:"items"` -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_types_test.go b/pkg/apis/events/v1alpha1/cloudschedulersource_types_test.go deleted file mode 100644 index c5f57d5de5..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_types_test.go +++ /dev/null @@ -1,99 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" -) - -func TestCloudSchedulerSourceGetGroupVersionKind(t *testing.T) { - want := schema.GroupVersionKind{ - Group: "events.cloud.google.com", - Version: "v1alpha1", - Kind: "CloudSchedulerSource", - } - - s := &CloudSchedulerSource{} - got := s.GetGroupVersionKind() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudSchedulerSourceConditionSet(t *testing.T) { - want := []apis.Condition{{ - Type: JobReady, - }, { - Type: v1alpha1.TopicReady, - }, { - Type: v1alpha1.PullSubscriptionReady, - }, { - Type: apis.ConditionReady, - }} - c := &CloudSchedulerSource{} - - c.ConditionSet().Manage(&c.Status).InitializeConditions() - var got []apis.Condition = c.Status.GetConditions() - - compareConditionTypes := cmp.Transformer("ConditionType", func(c apis.Condition) apis.ConditionType { - return c.Type - }) - sortConditionTypes := cmpopts.SortSlices(func(a, b apis.Condition) bool { - return a.Type < b.Type - }) - if diff := cmp.Diff(want, got, sortConditionTypes, compareConditionTypes); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudSchedulerSourceIdentitySpec(t *testing.T) { - s := &CloudSchedulerSource{ - Spec: CloudSchedulerSourceSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "test", - }, - }, - }, - } - want := "test" - got := s.IdentitySpec().ServiceAccountName - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudSchedulerSourceIdentityStatus(t *testing.T) { - s := &CloudSchedulerSource{ - Status: CloudSchedulerSourceStatus{ - PubSubStatus: v1alpha1.PubSubStatus{}, - }, - } - want := &v1alpha1.IdentityStatus{} - got := s.IdentityStatus() - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_validation.go b/pkg/apis/events/v1alpha1/cloudschedulersource_validation.go deleted file mode 100644 index d4cddb4ccc..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_validation.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck" - - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -func (current *CloudSchedulerSource) Validate(ctx context.Context) *apis.FieldError { - errs := current.Spec.Validate(ctx).ViaField("spec") - - if apis.IsInUpdate(ctx) { - original := apis.GetBaseline(ctx).(*CloudSchedulerSource) - errs = errs.Also(current.CheckImmutableFields(ctx, original)) - } - return duck.ValidateAutoscalingAnnotations(ctx, current.Annotations, errs) -} - -func (current *CloudSchedulerSourceSpec) Validate(ctx context.Context) *apis.FieldError { - var errs *apis.FieldError - - // Sink [required] - if equality.Semantic.DeepEqual(current.Sink, duckv1.Destination{}) { - errs = errs.Also(apis.ErrMissingField("sink")) - } else if err := current.Sink.Validate(ctx); err != nil { - errs = errs.Also(err.ViaField("sink")) - } - - // Location [required] - if current.Location == "" { - errs = errs.Also(apis.ErrMissingField("location")) - } - - // Schedule [required] - if current.Schedule == "" { - errs = errs.Also(apis.ErrMissingField("schedule")) - } - - // Data [required] - if current.Data == "" { - errs = errs.Also(apis.ErrMissingField("data")) - } - - if err := duck.ValidateCredential(current.Secret, current.ServiceAccountName); err != nil { - errs = errs.Also(err) - } - - return errs -} - -func (current *CloudSchedulerSource) CheckImmutableFields(ctx context.Context, original *CloudSchedulerSource) *apis.FieldError { - if original == nil { - return nil - } - - var errs *apis.FieldError - // Modification of Location, Schedule, Data, Secret, ServiceAccountName, Project are not allowed. Everything else is mutable. - if diff := cmp.Diff(original.Spec, current.Spec, - cmpopts.IgnoreFields(CloudSchedulerSourceSpec{}, - "Sink", "CloudEventOverrides")); diff != "" { - errs = errs.Also(&apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - }) - } - // Modification of AutoscalingClassAnnotations is not allowed. - errs = duck.CheckImmutableAutoscalingClassAnnotations(¤t.ObjectMeta, &original.ObjectMeta, errs) - - // Modification of non-empty cluster name annotation is not allowed. - return duck.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) -} diff --git a/pkg/apis/events/v1alpha1/cloudschedulersource_validation_test.go b/pkg/apis/events/v1alpha1/cloudschedulersource_validation_test.go deleted file mode 100644 index 59568bddad..0000000000 --- a/pkg/apis/events/v1alpha1/cloudschedulersource_validation_test.go +++ /dev/null @@ -1,679 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -var ( - // Bare minimum is Location, Schedule, Data and Sink - minimalCloudSchedulerSourceSpec = CloudSchedulerSourceSpec{ - Location: "mylocation", - Schedule: "* * * * *", - Data: "mydata", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - } - - // Location, Schedule, Data, Sink and Secret - schedulerWithSecret = CloudSchedulerSourceSpec{ - Location: "mylocation", - Schedule: "* * * * *", - Data: "mydata", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key", - }, - }, - } - - schedulerWithKSA = CloudSchedulerSourceSpec{ - Location: "mylocation", - Schedule: "* * * * *", - Data: "mydata", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - }, - } -) - -func TestCloudSchedulerSourceValidationFields(t *testing.T) { - testCases := []struct { - name string - s *CloudSchedulerSource - want *apis.FieldError - }{{ - name: "empty", - s: &CloudSchedulerSource{Spec: CloudSchedulerSourceSpec{}}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("spec.location", "spec.data", "spec.schedule", "spec.sink") - return fe - }(), - }, { - name: "missing data, schedule and sink", - s: &CloudSchedulerSource{Spec: CloudSchedulerSourceSpec{Location: "location"}}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("spec.data", "spec.schedule", "spec.sink") - return fe - }(), - }, { - name: "missing schedule and sink", - s: &CloudSchedulerSource{Spec: CloudSchedulerSourceSpec{Location: "location", Data: "data"}}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("spec.schedule", "spec.sink") - return fe - }(), - }, { - name: "missing sink", - s: &CloudSchedulerSource{Spec: CloudSchedulerSourceSpec{Location: "location", Data: "data", Schedule: "* * * * *"}}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("spec.sink") - return fe - }(), - }} - for _, test := range testCases { - t.Run(test.name, func(t *testing.T) { - got := test.s.Validate(context.TODO()) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("%s: Validate CloudSchedulerSourceSpec (-want, +got) = %v", test.name, diff) - } - }) - } -} - -func TestCloudSchedulerSourceSpecValidationFields(t *testing.T) { - testCases := []struct { - name string - spec *CloudSchedulerSourceSpec - want *apis.FieldError - }{{ - name: "empty", - spec: &CloudSchedulerSourceSpec{}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("data", "location", "schedule", "sink") - return fe - }(), - }, { - name: "missing data, schedule and sink", - spec: &CloudSchedulerSourceSpec{Location: "location"}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("data", "schedule", "sink") - return fe - }(), - }, { - name: "missing schedule and data", - spec: &CloudSchedulerSourceSpec{ - Location: "location", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("data", "schedule") - return fe - }(), - }, { - name: "invalid sink", - spec: &CloudSchedulerSourceSpec{ - Location: "location", - Schedule: "* * * * *", - Data: "data", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Name: "qux", - }, - }, - }, - }, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("sink.ref.kind") - return fe - }(), - }, { - name: "missing data", - spec: &CloudSchedulerSourceSpec{ - Location: "location", - Schedule: "* * * * *", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("data") - return fe - }(), - }, { - name: "invalid secret, missing name", - spec: &CloudSchedulerSourceSpec{ - Location: "my-test-location", - Schedule: "* * * * *", - Data: "data", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{}, - Key: "secret-test-key", - }, - }, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("secret.name") - return fe - }(), - }, { - name: "nil secret", - spec: &CloudSchedulerSourceSpec{ - Location: "my-test-location", - Schedule: "* * * * *", - Data: "data", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - }, - want: nil, - }, { - name: "invalid scheduler secret, missing key", - spec: &CloudSchedulerSourceSpec{ - Location: "my-test-location", - Schedule: "* * * * *", - Data: "data", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{Name: "gcs-test-secret"}, - }, - }, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("secret.key") - return fe - }(), - }, { - name: "invalid k8s service account", - spec: &CloudSchedulerSourceSpec{ - Location: "my-test-location", - Schedule: "* * * * *", - Data: "data", - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: invalidServiceAccountName, - }, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - }, - want: func() *apis.FieldError { - fe := &apis.FieldError{ - Message: `invalid value: @test, serviceAccountName should have format: ^[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?$`, - Paths: []string{"serviceAccountName"}, - } - return fe - }(), - }, { - name: "have k8s service account and secret at the same time", - spec: &CloudSchedulerSourceSpec{ - Location: "my-test-location", - Schedule: "* * * * *", - Data: "data", - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: validServiceAccountName, - }, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{}, - Key: "secret-test-key", - }, - }, - }, - want: func() *apis.FieldError { - fe := &apis.FieldError{ - Message: "Can't have spec.serviceAccountName and spec.secret at the same time", - Paths: []string{""}, - } - return fe - }(), - }} - for _, test := range testCases { - t.Run(test.name, func(t *testing.T) { - got := test.spec.Validate(context.TODO()) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("%s: Validate CloudSchedulerSourceSpec (-want, +got) = %v", test.name, diff) - } - }) - } - -} - -func TestCloudSchedulerSourceSpecCheckImmutableFields(t *testing.T) { - testCases := map[string]struct { - orig interface{} - updated CloudSchedulerSourceSpec - origAnnotation map[string]string - updatedAnnotation map[string]string - allowed bool - }{ - "nil orig": { - updated: schedulerWithSecret, - allowed: true, - }, - "ClusterName annotation changed": { - origAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", - }, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: false, - }, - "AnnotationClass annotation changed": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA + "new", - }, - allowed: false, - }, - "AnnotationClass annotation added": { - origAnnotation: map[string]string{}, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - allowed: false, - }, - "AnnotationClass annotation deleted": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{}, - allowed: false, - }, - "Location changed": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: "some-other-location", - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, - PubSubSpec: schedulerWithSecret.PubSubSpec, - }, - allowed: false, - }, - "Schedule changed": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: "* * * * 1", - Data: schedulerWithSecret.Data, - PubSubSpec: schedulerWithSecret.PubSubSpec, - }, - allowed: false, - }, - "Data changed": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: "some-other-data", - PubSubSpec: schedulerWithSecret.PubSubSpec, - }, - allowed: false, - }, - "Secret.Name changed": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: schedulerWithSecret.SourceSpec, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "some-other-name", - }, - Key: schedulerWithSecret.Secret.Key, - }, - Project: schedulerWithSecret.Project, - }, - }, - allowed: false, - }, - "Project changed": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: schedulerWithSecret.SourceSpec, - Secret: schedulerWithSecret.Secret, - Project: "some-other-project", - }, - }, - allowed: false, - }, - "ServiceAccountName changed": { - orig: &schedulerWithKSA, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithKSA.Location, - Schedule: schedulerWithKSA.Schedule, - Data: schedulerWithKSA.Data, - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "new-service-account", - }, - SourceSpec: schedulerWithKSA.SourceSpec, - }, - }, - allowed: false, - }, - "ServiceAccountName added": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: schedulerWithSecret.SourceSpec, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: schedulerWithSecret.Secret.Name, - }, - Key: schedulerWithSecret.Secret.Key, - }, - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "new-service-account", - }, - Project: schedulerWithSecret.Project, - }, - }, - allowed: false, - }, - "ClusterName annotation added": { - origAnnotation: nil, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: true, - }, - "Sink.APIVersion changed": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: schedulerWithSecret.Secret.Name, - }, - Key: schedulerWithSecret.Secret.Key, - }, - Project: schedulerWithSecret.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: schedulerWithSecret.Sink.Ref.Kind, - Namespace: schedulerWithSecret.Sink.Ref.Namespace, - Name: schedulerWithSecret.Sink.Ref.Name, - }, - }, - }, - }, - }, - allowed: true, - }, - "Sink.Kind changed": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: schedulerWithSecret.Secret.Name, - }, - Key: schedulerWithSecret.Secret.Key, - }, - Project: schedulerWithSecret.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: schedulerWithSecret.Sink.Ref.APIVersion, - Kind: "some-other-kind", - Namespace: schedulerWithSecret.Sink.Ref.Namespace, - Name: schedulerWithSecret.Sink.Ref.Name, - }, - }, - }, - }, - }, - allowed: true, - }, - "Sink.Namespace changed": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: schedulerWithSecret.Secret.Name, - }, - Key: schedulerWithSecret.Secret.Key, - }, - Project: schedulerWithSecret.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: schedulerWithSecret.Sink.Ref.APIVersion, - Kind: schedulerWithSecret.Sink.Ref.Kind, - Namespace: "some-other-namespace", - Name: schedulerWithSecret.Sink.Ref.Name, - }, - }, - }, - }, - }, - allowed: true, - }, - "Sink.Name changed": { - orig: &schedulerWithSecret, - updated: CloudSchedulerSourceSpec{ - Location: schedulerWithSecret.Location, - Schedule: schedulerWithSecret.Schedule, - Data: schedulerWithSecret.Data, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: schedulerWithSecret.Secret.Name, - }, - Key: schedulerWithSecret.Secret.Key, - }, - Project: schedulerWithSecret.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: schedulerWithSecret.Sink.Ref.APIVersion, - Kind: schedulerWithSecret.Sink.Ref.Kind, - Namespace: schedulerWithSecret.Sink.Ref.Namespace, - Name: "some-other-name", - }, - }, - }, - }, - }, - allowed: true, - }, - "no change": { - orig: &schedulerWithSecret, - updated: schedulerWithSecret, - allowed: true, - }, - "no spec": { - orig: []string{"wrong"}, - updated: schedulerWithSecret, - allowed: true, - }, - } - - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - var orig *CloudSchedulerSource - - if tc.origAnnotation != nil { - orig = &CloudSchedulerSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.origAnnotation, - }, - } - } else if tc.orig != nil { - if spec, ok := tc.orig.(*CloudSchedulerSourceSpec); ok { - orig = &CloudSchedulerSource{ - Spec: *spec, - } - } - } - updated := &CloudSchedulerSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.updatedAnnotation, - }, - Spec: tc.updated, - } - err := updated.CheckImmutableFields(context.TODO(), orig) - if tc.allowed != (err == nil) { - t.Fatalf("Unexpected immutable field check. Expected %v. Actual %v", tc.allowed, err) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_conversion.go b/pkg/apis/events/v1alpha1/cloudstoragesource_conversion.go deleted file mode 100644 index 2a4ec77154..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_conversion.go +++ /dev/null @@ -1,70 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - "github.com/google/knative-gcp/pkg/apis/convert" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - "knative.dev/pkg/apis" -) - -// ConvertTo implements apis.Convertible. -// Converts from v1alpha1.CloudStorageSource into a higher version. -func (source *CloudStorageSource) ConvertTo(ctx context.Context, to apis.Convertible) error { - switch sink := to.(type) { - case *v1beta1.CloudStorageSource: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.ToV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.ServiceAccountName = source.Spec.ServiceAccountName - sink.Spec.Bucket = source.Spec.Bucket - sink.Spec.EventTypes = source.Spec.EventTypes - sink.Spec.ObjectNamePrefix = source.Spec.ObjectNamePrefix - sink.Spec.PayloadFormat = source.Spec.PayloadFormat - sink.Status.PubSubStatus = convert.ToV1beta1PubSubStatus(source.Status.PubSubStatus) - sink.Status.NotificationID = source.Status.NotificationID - // Remove v1alpha1 as deprecated from the Status Condition when converting to a higher version. - convert.RemoveV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertToViaProxy(ctx, source, &v1beta1.CloudStorageSource{}, sink) - - } -} - -// ConvertFrom implements apis.Convertible. -// Converts from a higher version into v1alpha1.CloudStorageSource. -func (sink *CloudStorageSource) ConvertFrom(ctx context.Context, from apis.Convertible) error { - switch source := from.(type) { - case *v1beta1.CloudStorageSource: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.FromV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.ServiceAccountName = source.Spec.ServiceAccountName - sink.Spec.Bucket = source.Spec.Bucket - sink.Spec.EventTypes = source.Spec.EventTypes - sink.Spec.ObjectNamePrefix = source.Spec.ObjectNamePrefix - sink.Spec.PayloadFormat = source.Spec.PayloadFormat - sink.Status.PubSubStatus = convert.FromV1beta1PubSubStatus(source.Status.PubSubStatus) - sink.Status.NotificationID = source.Status.NotificationID - // Mark v1alpha1 as deprecated as a Status Condition when converting to v1alpha1. - convert.MarkV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertFromViaProxy(ctx, source, &v1beta1.CloudStorageSource{}, sink) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_conversion_test.go b/pkg/apis/events/v1alpha1/cloudstoragesource_conversion_test.go deleted file mode 100644 index 6abe884e78..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_conversion_test.go +++ /dev/null @@ -1,184 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "net/url" - "testing" - - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/convert" - - v1 "github.com/google/knative-gcp/pkg/apis/events/v1" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - - "github.com/google/go-cmp/cmp" - gcptesting "github.com/google/knative-gcp/pkg/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -// These variables are used to create a 'complete' version of CloudStorageSource where every field is -// filled in. -var ( - // completeCloudStorageSource is a CloudStorageSource with every field filled in, except TypeMeta. - // TypeMeta is excluded because conversions do not convert it and this variable was created to - // test conversions. - completeCloudStorageSource = &CloudStorageSource{ - ObjectMeta: gcptesting.CompleteObjectMeta, - Spec: CloudStorageSourceSpec{ - PubSubSpec: gcptesting.CompleteV1alpha1PubSubSpec, - Bucket: "bucket", - EventTypes: []string{"event", "types"}, - ObjectNamePrefix: "objectNamePrefix", - PayloadFormat: "payloadFormat", - }, - Status: CloudStorageSourceStatus{ - PubSubStatus: gcptesting.CompleteV1alpha1PubSubStatus, - NotificationID: "notificationId", - }, - } -) - -func TestCloudStorageSourceConversionBadType(t *testing.T) { - good, bad := &CloudStorageSource{}, &CloudPubSubSource{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestCloudStorageSourceConversionBetweenV1beta1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.CloudStorageSource{}} - - tests := []struct { - name string - in *CloudStorageSource - }{{ - name: "min configuration", - in: &CloudStorageSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: CloudStorageSourceSpec{}, - }, - }, { - name: "full configuration", - in: completeCloudStorageSource, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &CloudStorageSource{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - if diff := cmp.Diff(test.in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} - -func TestCloudStorageSourceConversionBetweenV1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1.CloudStorageSource{}} - - tests := []struct { - name string - in *CloudStorageSource - }{{ - name: "min configuration", - in: &CloudStorageSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: CloudStorageSourceSpec{}, - }, - }, { - name: "full configuration", - in: completeCloudStorageSource, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - // DeepCopy because we will edit it below. - in := test.in.DeepCopy() - if err := in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &CloudStorageSource{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - // ServiceAccountName and PayloadFormat only exists in v1alpha1 and v1beta1, they doesn't exist in v1. - // So it won't round trip, it will be silently removed. - in.Status.ServiceAccountName = "" - in.Spec.PayloadFormat = "" - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - if diff := cmp.Diff(in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_defaults.go b/pkg/apis/events/v1alpha1/cloudstoragesource_defaults.go deleted file mode 100644 index be59123e3b..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_defaults.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - - "knative.dev/pkg/apis" - - "github.com/google/knative-gcp/pkg/apis/duck" - metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" - schemasv1 "github.com/google/knative-gcp/pkg/schemas/v1" -) - -var allEventTypes = []string{ - schemasv1.CloudStorageObjectFinalizedEventType, - schemasv1.CloudStorageObjectDeletedEventType, - schemasv1.CloudStorageObjectArchivedEventType, - schemasv1.CloudStorageObjectMetadataUpdatedEventType, -} - -func (s *CloudStorageSource) SetDefaults(ctx context.Context) { - ctx = apis.WithinParent(ctx, s.ObjectMeta) - s.Spec.SetDefaults(ctx) - duck.SetClusterNameAnnotation(&s.ObjectMeta, metadataClient.NewDefaultMetadataClient()) - duck.SetAutoscalingAnnotationsDefaults(ctx, &s.ObjectMeta) -} - -func (ss *CloudStorageSourceSpec) SetDefaults(ctx context.Context) { - ss.SetPubSubDefaults(ctx) - if len(ss.EventTypes) == 0 { - ss.EventTypes = allEventTypes - } -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_defaults_test.go b/pkg/apis/events/v1alpha1/cloudstoragesource_defaults_test.go deleted file mode 100644 index c01e947c78..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_defaults_test.go +++ /dev/null @@ -1,176 +0,0 @@ -/* -Copyright 2019 Google LLC - -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" - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - schemasv1 "github.com/google/knative-gcp/pkg/schemas/v1" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestCloudStorageSourceSpec_SetDefaults(t *testing.T) { - testCases := map[string]struct { - orig *CloudStorageSourceSpec - expected *CloudStorageSourceSpec - }{ - "missing defaults": { - orig: &CloudStorageSourceSpec{}, - expected: &CloudStorageSourceSpec{ - EventTypes: allEventTypes, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "google-cloud-key", - }, - Key: "key.json", - }, - }, - }, - }, - "defaults present": { - orig: &CloudStorageSourceSpec{ - EventTypes: []string{schemasv1.CloudStorageObjectFinalizedEventType, schemasv1.CloudStorageObjectDeletedEventType}, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key.json", - }, - }, - }, - expected: &CloudStorageSourceSpec{ - EventTypes: []string{schemasv1.CloudStorageObjectFinalizedEventType, schemasv1.CloudStorageObjectDeletedEventType}, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key.json", - }, - }, - }, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - tc.orig.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - if diff := cmp.Diff(tc.expected, tc.orig); diff != "" { - t.Errorf("Unexpected differences (-want +got): %v", diff) - } - }) - } -} - -func TestCloudStorageSource_SetDefaults(t *testing.T) { - testCases := map[string]struct { - orig *CloudStorageSource - expected *CloudStorageSource - }{ - // Due to the limitation mentioned in https://github.com/google/knative-gcp/issues/1037, specifying the cluster name annotation. - "missing defaults, except cluster name annotations": { - orig: &CloudStorageSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - }, - expected: &CloudStorageSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudStorageSourceSpec{ - EventTypes: []string{ - schemasv1.CloudStorageObjectFinalizedEventType, - schemasv1.CloudStorageObjectDeletedEventType, - schemasv1.CloudStorageObjectArchivedEventType, - schemasv1.CloudStorageObjectMetadataUpdatedEventType, - }, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "google-cloud-key", - }, - Key: "key.json", - }, - }, - }, - }, - }, - "defaults present": { - orig: &CloudStorageSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudStorageSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key.json", - }, - }, - }, - }, - expected: &CloudStorageSource{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: CloudStorageSourceSpec{ - EventTypes: []string{ - schemasv1.CloudStorageObjectFinalizedEventType, - schemasv1.CloudStorageObjectDeletedEventType, - schemasv1.CloudStorageObjectArchivedEventType, - schemasv1.CloudStorageObjectMetadataUpdatedEventType, - }, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key.json", - }, - }, - }, - }, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - tc.orig.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - if diff := cmp.Diff(tc.expected, tc.orig); diff != "" { - t.Errorf("Unexpected differences (-want +got): %v", diff) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_lifecycle.go b/pkg/apis/events/v1alpha1/cloudstoragesource_lifecycle.go deleted file mode 100644 index d7112d2bbf..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_lifecycle.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "knative.dev/pkg/apis" -) - -// GetCondition returns the condition currently associated with the given type, or nil. -func (s *CloudStorageSourceStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return storageCondSet.Manage(s).GetCondition(t) -} - -// GetTopLevelCondition returns the top level condition. -func (s *CloudStorageSourceStatus) GetTopLevelCondition() *apis.Condition { - return storageCondSet.Manage(s).GetTopLevelCondition() -} - -// IsReady returns true if the resource is ready overall. -func (s *CloudStorageSourceStatus) IsReady() bool { - return storageCondSet.Manage(s).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (s *CloudStorageSourceStatus) InitializeConditions() { - storageCondSet.Manage(s).InitializeConditions() -} - -// MarkNotificationNotReady sets the condition that the GCS has not been configured -// to send Notifications and why. -func (s *CloudStorageSourceStatus) MarkNotificationNotReady(reason, messageFormat string, messageA ...interface{}) { - storageCondSet.Manage(s).MarkFalse(NotificationReady, reason, messageFormat, messageA...) -} - -func (s *CloudStorageSourceStatus) MarkNotificationReady(notificationID string) { - s.NotificationID = notificationID - storageCondSet.Manage(s).MarkTrue(NotificationReady) -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_lifecycle_test.go b/pkg/apis/events/v1alpha1/cloudstoragesource_lifecycle_test.go deleted file mode 100644 index 578a75d31e..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_lifecycle_test.go +++ /dev/null @@ -1,200 +0,0 @@ -/* -Copyright 2020 Google LLC - -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" - - "knative.dev/pkg/apis" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - corev1 "k8s.io/api/core/v1" -) - -func TestCloudStorageSourceStatusIsReady(t *testing.T) { - tests := []struct { - name string - s *CloudStorageSourceStatus - wantConditionStatus corev1.ConditionStatus - want bool - }{{ - name: "uninitialized", - s: &CloudStorageSourceStatus{}, - want: false, - }, { - name: "initialized", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSourceStatus{} - s.InitializeConditions() - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "the status of topic is false", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkNotificationReady("notificationID") - s.Status.MarkTopicFailed(s.ConditionSet(), "TopicFailed", "the status of topic is false") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, { - name: "the status of topic is unknown", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSource{} - s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkNotificationReady("notificationID") - s.Status.MarkTopicUnknown(s.ConditionSet(), "TopicUnknown", "the status of topic is unknown") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "the status of pullsubscription is false", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), "PullSubscriptionFailed", "the status of pullsubscription is false") - s.Status.MarkNotificationReady("notificationID") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, - { - name: "the status of pullsubscription is unknown", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), "PullSubscriptionUnknown", "the status of pullsubscription is unknown") - s.Status.MarkNotificationReady("notificationID") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "notification not ready", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkNotificationNotReady("NotReady", "notification not ready") - return &s.Status - }(), - }, { - name: "ready", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSource{} - s.Status.InitializeConditions() - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - s.Status.MarkNotificationReady("notificationID") - return &s.Status - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - if test.wantConditionStatus != "" { - gotConditionStatus := test.s.GetTopLevelCondition().Status - if gotConditionStatus != test.wantConditionStatus { - t.Errorf("unexpected condition status: want %v, got %v", test.wantConditionStatus, gotConditionStatus) - } - } - got := test.s.IsReady() - if got != test.want { - t.Errorf("unexpected readiness: want %v, got %v", test.want, got) - } - }) - } -} - -func TestCloudStorageSourceStatusGetCondition(t *testing.T) { - tests := []struct { - name string - s *CloudStorageSourceStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "uninitialized", - s: &CloudStorageSourceStatus{}, - condQuery: CloudStorageSourceConditionReady, - want: nil, - }, { - name: "initialized", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSourceStatus{} - s.InitializeConditions() - return s - }(), - condQuery: CloudStorageSourceConditionReady, - want: &apis.Condition{ - Type: CloudStorageSourceConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "not ready", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSourceStatus{} - s.InitializeConditions() - s.MarkNotificationNotReady("NotReady", "test message") - return s - }(), - condQuery: NotificationReady, - want: &apis.Condition{ - Type: NotificationReady, - Status: corev1.ConditionFalse, - Reason: "NotReady", - Message: "test message", - }, - }, { - name: "ready", - s: func() *CloudStorageSourceStatus { - s := &CloudStorageSourceStatus{} - s.InitializeConditions() - s.MarkNotificationReady("notificationID") - return s - }(), - condQuery: NotificationReady, - want: &apis.Condition{ - Type: NotificationReady, - Status: corev1.ConditionTrue, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.s.GetCondition(test.condQuery) - ignoreTime := cmpopts.IgnoreFields(apis.Condition{}, - "LastTransitionTime", "Severity") - if diff := cmp.Diff(test.want, got, ignoreTime); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_types.go b/pkg/apis/events/v1alpha1/cloudstoragesource_types.go deleted file mode 100644 index 1ecef5719d..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_types.go +++ /dev/null @@ -1,144 +0,0 @@ -/* -Copyright 2019 Google LLC. - -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 ( - "k8s.io/apimachinery/pkg/runtime" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" - "knative.dev/pkg/apis" - "knative.dev/pkg/kmeta" - "knative.dev/pkg/webhook/resourcesemantics" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// CloudStorageSource is a specification for a Google Cloud CloudStorageSource Source resource. -type CloudStorageSource struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec CloudStorageSourceSpec `json:"spec"` - Status CloudStorageSourceStatus `json:"status"` -} - -// Verify that CloudStorageSource matches various duck types. -var ( - _ apis.Convertible = (*CloudStorageSource)(nil) - _ apis.Defaultable = (*CloudStorageSource)(nil) - _ apis.Validatable = (*CloudStorageSource)(nil) - _ runtime.Object = (*CloudStorageSource)(nil) - _ kmeta.OwnerRefable = (*CloudStorageSource)(nil) - _ resourcesemantics.GenericCRD = (*CloudStorageSource)(nil) - _ kngcpduck.Identifiable = (*CloudStorageSource)(nil) - _ kngcpduck.PubSubable = (*CloudStorageSource)(nil) -) - -// CloudStorageSourceSpec is the spec for a CloudStorageSource resource. -type CloudStorageSourceSpec struct { - // This brings in the PubSub based Source Specs. Includes: - // Sink, CloudEventOverrides, Secret and Project - duckv1alpha1.PubSubSpec `json:",inline"` - - // Bucket to subscribe to. - Bucket string `json:"bucket"` - - // EventTypes to subscribe to. If unspecified, then subscribe to all events. - // +optional - EventTypes []string `json:"eventTypes,omitempty"` - - // ObjectNamePrefix limits the notifications to objects with this prefix - // +optional - ObjectNamePrefix string `json:"objectNamePrefix,omitempty"` - - // PayloadFormat specifies the contents of the message payload. - // See https://cloud.google.com/storage/docs/pubsub-notifications#payload. - // +optional - PayloadFormat string `json:"payloadFormat,omitempty"` -} - -const ( - // CloudStorageSourceConditionReady has status True when the CloudStorageSource is ready to send events. - CloudStorageSourceConditionReady = apis.ConditionReady - - // NotificationReady has status True when GCS has been configured properly to - // send Notification events. - NotificationReady apis.ConditionType = "NotificationReady" -) - -var storageCondSet = apis.NewLivingConditionSet( - duckv1alpha1.PullSubscriptionReady, - duckv1alpha1.TopicReady, - NotificationReady) - -// CloudStorageSourceStatus is the status for a GCS resource. -type CloudStorageSourceStatus struct { - // This brings in the Status for our GCP PubSub event sources. - // duck/v1beta1 Status, SinkURI, ProjectID, TopicID and SubscriptionID - duckv1alpha1.PubSubStatus `json:",inline"` - - // NotificationID is the ID that GCS identifies this notification as. - // +optional - NotificationID string `json:"notificationId,omitempty"` -} - -func (storage *CloudStorageSource) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("CloudStorageSource") -} - -// Methods for identifiable interface. -// IdentitySpec returns the IdentitySpec portion of the Spec. -func (s *CloudStorageSource) IdentitySpec() *duckv1alpha1.IdentitySpec { - return &s.Spec.IdentitySpec -} - -// IdentityStatus returns the IdentityStatus portion of the Status. -func (s *CloudStorageSource) IdentityStatus() *duckv1alpha1.IdentityStatus { - return &s.Status.IdentityStatus -} - -// ConditionSet returns the apis.ConditionSet of the embedding object. -func (s *CloudStorageSource) ConditionSet() *apis.ConditionSet { - return &storageCondSet -} - -// Methods for pubsubable interface. - -// PubSubSpec returns the PubSubSpec portion of the Spec. -func (s *CloudStorageSource) PubSubSpec() *duckv1alpha1.PubSubSpec { - return &s.Spec.PubSubSpec -} - -// PubSubStatus returns the PubSubStatus portion of the Status. -func (s *CloudStorageSource) PubSubStatus() *duckv1alpha1.PubSubStatus { - return &s.Status.PubSubStatus -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// CloudStorageSourceList is a list of CloudStorageSource resources. -type CloudStorageSourceList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - - Items []CloudStorageSource `json:"items"` -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_types_test.go b/pkg/apis/events/v1alpha1/cloudstoragesource_types_test.go deleted file mode 100644 index d92bb2584c..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_types_test.go +++ /dev/null @@ -1,98 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" -) - -func TestGetGroupVersionKind(t *testing.T) { - want := schema.GroupVersionKind{ - Group: "events.cloud.google.com", - Version: "v1alpha1", - Kind: "CloudStorageSource", - } - - c := &CloudStorageSource{} - got := c.GetGroupVersionKind() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudStorageSourceSourceConditionSet(t *testing.T) { - want := []apis.Condition{{ - Type: NotificationReady, - }, { - Type: v1alpha1.TopicReady, - }, { - Type: v1alpha1.PullSubscriptionReady, - }, { - Type: apis.ConditionReady, - }} - c := &CloudStorageSource{} - - c.ConditionSet().Manage(&c.Status).InitializeConditions() - var got []apis.Condition = c.Status.GetConditions() - - compareConditionTypes := cmp.Transformer("ConditionType", func(c apis.Condition) apis.ConditionType { - return c.Type - }) - sortConditionTypes := cmpopts.SortSlices(func(a, b apis.Condition) bool { - return a.Type < b.Type - }) - if diff := cmp.Diff(want, got, sortConditionTypes, compareConditionTypes); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudStorageSourceIdentitySpec(t *testing.T) { - s := &CloudStorageSource{ - Spec: CloudStorageSourceSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "test", - }, - }, - }, - } - want := "test" - got := s.IdentitySpec().ServiceAccountName - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestCloudStorageSourceIdentityStatus(t *testing.T) { - s := &CloudStorageSource{ - Status: CloudStorageSourceStatus{ - PubSubStatus: v1alpha1.PubSubStatus{}, - }, - } - want := &v1alpha1.IdentityStatus{} - got := s.IdentityStatus() - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_validation.go b/pkg/apis/events/v1alpha1/cloudstoragesource_validation.go deleted file mode 100644 index 4c90f3f857..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_validation.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck" -) - -func (current *CloudStorageSource) Validate(ctx context.Context) *apis.FieldError { - errs := current.Spec.Validate(ctx).ViaField("spec") - - if apis.IsInUpdate(ctx) { - original := apis.GetBaseline(ctx).(*CloudStorageSource) - errs = errs.Also(current.CheckImmutableFields(ctx, original)) - } - return duck.ValidateAutoscalingAnnotations(ctx, current.Annotations, errs) -} - -func (current *CloudStorageSourceSpec) Validate(ctx context.Context) *apis.FieldError { - var errs *apis.FieldError - - // Sink [required] - if equality.Semantic.DeepEqual(current.Sink, duckv1.Destination{}) { - errs = errs.Also(apis.ErrMissingField("sink")) - } else if err := current.Sink.Validate(ctx); err != nil { - errs = errs.Also(err.ViaField("sink")) - } - - // Bucket [required] - if current.Bucket == "" { - errs = errs.Also(apis.ErrMissingField("bucket")) - } - - if err := duck.ValidateCredential(current.Secret, current.ServiceAccountName); err != nil { - errs = errs.Also(err) - } - - return errs -} - -func (current *CloudStorageSource) CheckImmutableFields(ctx context.Context, original *CloudStorageSource) *apis.FieldError { - if original == nil { - return nil - } - - var errs *apis.FieldError - // Modification of EventType, Secret, ServiceAccountName, Project, Bucket, PayloadFormat, EventType, ObjectNamePrefix are not allowed. - // Everything else is mutable. - if diff := cmp.Diff(original.Spec, current.Spec, - cmpopts.IgnoreFields(CloudStorageSourceSpec{}, - "Sink", "CloudEventOverrides")); diff != "" { - errs = errs.Also(&apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - }) - } - // Modification of AutoscalingClassAnnotations is not allowed. - errs = duck.CheckImmutableAutoscalingClassAnnotations(¤t.ObjectMeta, &original.ObjectMeta, errs) - - // Modification of non-empty cluster name annotation is not allowed. - return duck.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) -} diff --git a/pkg/apis/events/v1alpha1/cloudstoragesource_validation_test.go b/pkg/apis/events/v1alpha1/cloudstoragesource_validation_test.go deleted file mode 100644 index 2d886c8824..0000000000 --- a/pkg/apis/events/v1alpha1/cloudstoragesource_validation_test.go +++ /dev/null @@ -1,689 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - "testing" - - cloudevents "github.com/cloudevents/sdk-go/v2" - "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - schemasv1 "github.com/google/knative-gcp/pkg/schemas/v1" - - corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -var ( - // Bare minimum is Bucket and Sink - minimalCloudStorageSourceSpec = CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - } - - // Bucket, Sink and Secret - withSecret = CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key", - }, - }, - } - - storageSourceSpecWithKSA = CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - }, - } - - // Bucket, Sink, Secret, Event Type and Project, ObjectNamePrefix and PayloadFormat - storageSourceSpec = CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - EventTypes: []string{schemasv1.CloudStorageObjectFinalizedEventType, schemasv1.CloudStorageObjectDeletedEventType}, - ObjectNamePrefix: "test-prefix", - PayloadFormat: cloudevents.ApplicationJSON, - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "gcs-secret-name", - }, - Key: "gcs-secret-key", - }, - Project: "my-eventing-project", - }, - } -) - -func TestValidationFields(t *testing.T) { - testCases := []struct { - name string - s *CloudStorageSource - want *apis.FieldError - }{{ - name: "empty", - s: &CloudStorageSource{Spec: CloudStorageSourceSpec{}}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("spec.bucket", "spec.sink") - return fe - }(), - }, { - name: "missing sink", - s: &CloudStorageSource{Spec: CloudStorageSourceSpec{Bucket: "foo"}}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("spec.sink") - return fe - }(), - }} - for _, test := range testCases { - t.Run(test.name, func(t *testing.T) { - got := test.s.Validate(context.TODO()) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("%s: Validate CloudStorageSourceSpec (-want, +got) = %v", test.name, diff) - } - }) - } -} - -func TestSpecValidationFields(t *testing.T) { - testCases := []struct { - name string - spec *CloudStorageSourceSpec - want *apis.FieldError - }{{ - name: "empty", - spec: &CloudStorageSourceSpec{}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("bucket", "sink") - return fe - }(), - }, { - name: "missing sink", - spec: &CloudStorageSourceSpec{Bucket: "foo"}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("sink") - return fe - }(), - }, { - name: "invalid sink", - spec: &CloudStorageSourceSpec{Bucket: "foo", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Namespace: "baz", - Name: "qux", - }, - }, - }}}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("sink.ref.kind") - return fe - }(), - }, { - name: "missing bucket", - spec: &CloudStorageSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("bucket") - return fe - }(), - }, { - name: "invalid secret, missing name", - spec: &CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{}, - Key: "secret-test-key", - }, - }, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("secret.name") - return fe - }(), - }, { - name: "nil secret", - spec: &CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - }, - want: nil, - }, { - name: "invalid gcs secret, missing key", - spec: &CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{Name: "gcs-test-secret"}, - }, - }, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("secret.key") - return fe - }(), - }, { - name: "invalid k8s service account", - spec: &CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: invalidServiceAccountName, - }, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - }, - want: func() *apis.FieldError { - fe := &apis.FieldError{ - Message: `invalid value: @test, serviceAccountName should have format: ^[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?$`, - Paths: []string{"serviceAccountName"}, - } - return fe - }(), - }, { - name: "valid k8s service account", - spec: &CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: validServiceAccountName, - }, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - }, - want: nil, - }, { - name: "have k8s service account and secret at the same time", - spec: &CloudStorageSourceSpec{ - Bucket: "my-test-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: validServiceAccountName, - }, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{}, - Key: "secret-test-key", - }, - }, - }, - want: func() *apis.FieldError { - fe := &apis.FieldError{ - Message: "Can't have spec.serviceAccountName and spec.secret at the same time", - Paths: []string{""}, - } - return fe - }(), - }} - for _, test := range testCases { - t.Run(test.name, func(t *testing.T) { - got := test.spec.Validate(context.TODO()) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("%s: Validate CloudStorageSourceSpec (-want, +got) = %v", test.name, diff) - } - }) - } -} - -func TestCheckImmutableFields(t *testing.T) { - testCases := map[string]struct { - orig interface{} - updated CloudStorageSourceSpec - origAnnotation map[string]string - updatedAnnotation map[string]string - allowed bool - }{ - "nil orig": { - updated: storageSourceSpec, - allowed: true, - }, - "ClusterName annotation changed": { - origAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", - }, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: false, - }, - "AnnotationClass annotation changed": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA + "new", - }, - allowed: false, - }, - "AnnotationClass annotation added": { - origAnnotation: map[string]string{}, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - allowed: false, - }, - "AnnotationClass annotation deleted": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{}, - allowed: false, - }, - "Bucket changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: "some-other-bucket", - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: storageSourceSpec.PayloadFormat, - PubSubSpec: storageSourceSpec.PubSubSpec, - }, - allowed: false, - }, - "EventType changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: []string{schemasv1.CloudStorageObjectMetadataUpdatedEventType}, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: storageSourceSpec.PayloadFormat, - PubSubSpec: storageSourceSpec.PubSubSpec, - }, - allowed: false, - }, - "ObjectNamePrefix changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: "some-other-prefix", - PayloadFormat: storageSourceSpec.PayloadFormat, - PubSubSpec: storageSourceSpec.PubSubSpec, - }, - allowed: false, - }, - "PayloadFormat changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: "some-other-format", - PubSubSpec: storageSourceSpec.PubSubSpec, - }, - allowed: false, - }, - "Secret.Name changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: storageSourceSpec.PayloadFormat, - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: storageSourceSpec.SourceSpec, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "some-other-name", - }, - Key: storageSourceSpec.Secret.Key, - }, - Project: storageSourceSpec.Project, - }, - }, - allowed: false, - }, - "Secret.Key changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: storageSourceSpec.SourceSpec, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: storageSourceSpec.Secret.Name, - }, - Key: "some-other-key", - }, - Project: storageSourceSpec.Project, - }, - }, - allowed: false, - }, - "Project changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: storageSourceSpec.PayloadFormat, - PubSubSpec: duckv1alpha1.PubSubSpec{ - SourceSpec: storageSourceSpec.SourceSpec, - Secret: storageSourceSpec.Secret, - Project: "some-other-project", - }, - }, - allowed: false, - }, - "ServiceAccountName changed": { - orig: &storageSourceSpecWithKSA, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpecWithKSA.Bucket, - EventTypes: storageSourceSpecWithKSA.EventTypes, - ObjectNamePrefix: storageSourceSpecWithKSA.ObjectNamePrefix, - PayloadFormat: storageSourceSpecWithKSA.PayloadFormat, - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ - ServiceAccountName: "new-service-account", - }, - SourceSpec: storageSourceSpecWithKSA.SourceSpec, - }, - }, - allowed: false, - }, - "ClusterName annotation added": { - origAnnotation: nil, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: true, - }, - "Sink.APIVersion changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: cloudevents.ApplicationJSON, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: storageSourceSpec.Secret.Name, - }, - Key: storageSourceSpec.Secret.Key, - }, - Project: storageSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: storageSourceSpec.Sink.Ref.Kind, - Namespace: storageSourceSpec.Sink.Ref.Namespace, - Name: storageSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - }, - allowed: true, - }, - "Sink.Kind changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: cloudevents.ApplicationJSON, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: storageSourceSpec.Secret.Name, - }, - Key: storageSourceSpec.Secret.Key, - }, - Project: storageSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: storageSourceSpec.Sink.Ref.APIVersion, - Kind: "some-other-kind", - Namespace: storageSourceSpec.Sink.Ref.Namespace, - Name: storageSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - }, - allowed: true, - }, - "Sink.Namespace changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: cloudevents.ApplicationJSON, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: storageSourceSpec.Secret.Name, - }, - Key: storageSourceSpec.Secret.Key, - }, - Project: storageSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: storageSourceSpec.Sink.Ref.APIVersion, - Kind: storageSourceSpec.Sink.Ref.Kind, - Namespace: "some-other-namespace", - Name: storageSourceSpec.Sink.Ref.Name, - }, - }, - }, - }, - }, - allowed: true, - }, - "Sink.Name changed": { - orig: &storageSourceSpec, - updated: CloudStorageSourceSpec{ - Bucket: storageSourceSpec.Bucket, - EventTypes: storageSourceSpec.EventTypes, - ObjectNamePrefix: storageSourceSpec.ObjectNamePrefix, - PayloadFormat: cloudevents.ApplicationJSON, - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: storageSourceSpec.Secret.Name, - }, - Key: storageSourceSpec.Secret.Key, - }, - Project: storageSourceSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: storageSourceSpec.Sink.Ref.APIVersion, - Kind: storageSourceSpec.Sink.Ref.Kind, - Namespace: storageSourceSpec.Sink.Ref.Namespace, - Name: "some-other-name", - }, - }, - }, - }, - }, - allowed: true, - }, - "no change": { - orig: &storageSourceSpec, - updated: storageSourceSpec, - allowed: true, - }, - "no spec": { - orig: []string{"wrong"}, - updated: storageSourceSpec, - allowed: true, - }, - } - - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - var orig *CloudStorageSource - - if tc.origAnnotation != nil { - orig = &CloudStorageSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.origAnnotation, - }, - } - } else if tc.orig != nil { - if spec, ok := tc.orig.(*CloudStorageSourceSpec); ok { - orig = &CloudStorageSource{ - Spec: *spec, - } - } - } - updated := &CloudStorageSource{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.updatedAnnotation, - }, - Spec: tc.updated, - } - err := updated.CheckImmutableFields(context.TODO(), orig) - if tc.allowed != (err == nil) { - t.Fatalf("Unexpected immutable field check. Expected %v. Actual %v", tc.allowed, err) - } - }) - } -} diff --git a/pkg/apis/events/v1alpha1/doc.go b/pkg/apis/events/v1alpha1/doc.go deleted file mode 100644 index 7d80491876..0000000000 --- a/pkg/apis/events/v1alpha1/doc.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 contains API Schema definitions for the events v1alpha1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=github.com/google/knative-gcp/pkg/apis/events -// +k8s:defaulter-gen=TypeMeta -// +groupName=events.cloud.google.com -package v1alpha1 diff --git a/pkg/apis/events/v1alpha1/implements_test.go b/pkg/apis/events/v1alpha1/implements_test.go deleted file mode 100644 index 1173f874a4..0000000000 --- a/pkg/apis/events/v1alpha1/implements_test.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2019 Google LLC -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" - - "knative.dev/pkg/apis/duck" - "knative.dev/pkg/apis/duck/v1beta1" -) - -func TestTypesImplements(t *testing.T) { - testCases := []struct { - instance interface{} - iface duck.Implementable - }{ - {instance: &CloudAuditLogsSource{}, iface: &v1beta1.Source{}}, - {instance: &CloudAuditLogsSource{}, iface: &v1beta1.Conditions{}}, - {instance: &CloudStorageSource{}, iface: &v1beta1.Source{}}, - {instance: &CloudStorageSource{}, iface: &v1beta1.Conditions{}}, - {instance: &CloudSchedulerSource{}, iface: &v1beta1.Source{}}, - {instance: &CloudSchedulerSource{}, iface: &v1beta1.Conditions{}}, - {instance: &CloudPubSubSource{}, iface: &v1beta1.Source{}}, - {instance: &CloudPubSubSource{}, iface: &v1beta1.Conditions{}}, - } - for _, tc := range testCases { - if err := duck.VerifyType(tc.instance, tc.iface); err != nil { - t.Error(err) - } - } -} diff --git a/pkg/apis/events/v1alpha1/register.go b/pkg/apis/events/v1alpha1/register.go deleted file mode 100644 index a1301e16ad..0000000000 --- a/pkg/apis/events/v1alpha1/register.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2019 Google LLC. - -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 ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - - "github.com/google/knative-gcp/pkg/apis/events" -) - -// SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: events.GroupName, Version: "v1alpha1"} - -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns a Group qualified GroupResource -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} - -var ( - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme -) - -// Adds the list of known types to Scheme. -func addKnownTypes(scheme *runtime.Scheme) error { - scheme.AddKnownTypes(SchemeGroupVersion, - &CloudAuditLogsSource{}, - &CloudAuditLogsSourceList{}, - &CloudStorageSource{}, - &CloudStorageSourceList{}, - &CloudSchedulerSource{}, - &CloudSchedulerSourceList{}, - &CloudPubSubSource{}, - &CloudPubSubSourceList{}, - &CloudBuildSource{}, - &CloudBuildSourceList{}, - ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) - return nil -} diff --git a/pkg/apis/events/v1alpha1/register_test.go b/pkg/apis/events/v1alpha1/register_test.go deleted file mode 100644 index c61a88a6c6..0000000000 --- a/pkg/apis/events/v1alpha1/register_test.go +++ /dev/null @@ -1,71 +0,0 @@ -/* -Copyright 2020 Google LLC - -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" - - "k8s.io/apimachinery/pkg/runtime" - - "github.com/google/go-cmp/cmp" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// Resource takes an unqualified resource and returns a Group qualified GroupResource -func TestResource(t *testing.T) { - want := schema.GroupResource{ - Group: "events.cloud.google.com", - Resource: "foo", - } - - got := Resource("foo") - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("unexpected resource (-want, +got) = %v", diff) - } -} - -func TestKind(t *testing.T) { - want := schema.GroupKind{ - Group: "events.cloud.google.com", - Kind: "foo", - } - - got := Kind("foo") - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("unexpected resource (-want, +got) = %v", diff) - } -} - -// TestKnownTypes makes sure that expected types get added. -func TestKnownTypes(t *testing.T) { - scheme := runtime.NewScheme() - addKnownTypes(scheme) - types := scheme.KnownTypes(SchemeGroupVersion) - - for _, name := range []string{ - "CloudPubSubSource", - "CloudAuditLogsSource", - "CloudStorageSource", - "CloudSchedulerSource", - } { - if _, ok := types[name]; !ok { - t.Errorf("Did not find %q as registered type", name) - } - } - -} diff --git a/pkg/apis/events/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/events/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index 16a4793749..0000000000 --- a/pkg/apis/events/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,520 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 Google LLC - -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 deepcopy-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - 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 *CloudAuditLogsSource) DeepCopyInto(out *CloudAuditLogsSource) { - *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 CloudAuditLogsSource. -func (in *CloudAuditLogsSource) DeepCopy() *CloudAuditLogsSource { - if in == nil { - return nil - } - out := new(CloudAuditLogsSource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudAuditLogsSource) 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 *CloudAuditLogsSourceList) DeepCopyInto(out *CloudAuditLogsSourceList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]CloudAuditLogsSource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudAuditLogsSourceList. -func (in *CloudAuditLogsSourceList) DeepCopy() *CloudAuditLogsSourceList { - if in == nil { - return nil - } - out := new(CloudAuditLogsSourceList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudAuditLogsSourceList) 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 *CloudAuditLogsSourceSpec) DeepCopyInto(out *CloudAuditLogsSourceSpec) { - *out = *in - in.PubSubSpec.DeepCopyInto(&out.PubSubSpec) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudAuditLogsSourceSpec. -func (in *CloudAuditLogsSourceSpec) DeepCopy() *CloudAuditLogsSourceSpec { - if in == nil { - return nil - } - out := new(CloudAuditLogsSourceSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CloudAuditLogsSourceStatus) DeepCopyInto(out *CloudAuditLogsSourceStatus) { - *out = *in - in.PubSubStatus.DeepCopyInto(&out.PubSubStatus) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudAuditLogsSourceStatus. -func (in *CloudAuditLogsSourceStatus) DeepCopy() *CloudAuditLogsSourceStatus { - if in == nil { - return nil - } - out := new(CloudAuditLogsSourceStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CloudBuildSource) DeepCopyInto(out *CloudBuildSource) { - *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 CloudBuildSource. -func (in *CloudBuildSource) DeepCopy() *CloudBuildSource { - if in == nil { - return nil - } - out := new(CloudBuildSource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudBuildSource) 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 *CloudBuildSourceList) DeepCopyInto(out *CloudBuildSourceList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]CloudBuildSource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudBuildSourceList. -func (in *CloudBuildSourceList) DeepCopy() *CloudBuildSourceList { - if in == nil { - return nil - } - out := new(CloudBuildSourceList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudBuildSourceList) 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 *CloudBuildSourceSpec) DeepCopyInto(out *CloudBuildSourceSpec) { - *out = *in - in.PubSubSpec.DeepCopyInto(&out.PubSubSpec) - if in.Topic != nil { - in, out := &in.Topic, &out.Topic - *out = new(string) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudBuildSourceSpec. -func (in *CloudBuildSourceSpec) DeepCopy() *CloudBuildSourceSpec { - if in == nil { - return nil - } - out := new(CloudBuildSourceSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CloudBuildSourceStatus) DeepCopyInto(out *CloudBuildSourceStatus) { - *out = *in - in.PubSubStatus.DeepCopyInto(&out.PubSubStatus) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudBuildSourceStatus. -func (in *CloudBuildSourceStatus) DeepCopy() *CloudBuildSourceStatus { - if in == nil { - return nil - } - out := new(CloudBuildSourceStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CloudPubSubSource) DeepCopyInto(out *CloudPubSubSource) { - *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 CloudPubSubSource. -func (in *CloudPubSubSource) DeepCopy() *CloudPubSubSource { - if in == nil { - return nil - } - out := new(CloudPubSubSource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudPubSubSource) 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 *CloudPubSubSourceList) DeepCopyInto(out *CloudPubSubSourceList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]CloudPubSubSource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudPubSubSourceList. -func (in *CloudPubSubSourceList) DeepCopy() *CloudPubSubSourceList { - if in == nil { - return nil - } - out := new(CloudPubSubSourceList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudPubSubSourceList) 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 *CloudPubSubSourceSpec) DeepCopyInto(out *CloudPubSubSourceSpec) { - *out = *in - in.PubSubSpec.DeepCopyInto(&out.PubSubSpec) - if in.AckDeadline != nil { - in, out := &in.AckDeadline, &out.AckDeadline - *out = new(string) - **out = **in - } - if in.RetentionDuration != nil { - in, out := &in.RetentionDuration, &out.RetentionDuration - *out = new(string) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudPubSubSourceSpec. -func (in *CloudPubSubSourceSpec) DeepCopy() *CloudPubSubSourceSpec { - if in == nil { - return nil - } - out := new(CloudPubSubSourceSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CloudPubSubSourceStatus) DeepCopyInto(out *CloudPubSubSourceStatus) { - *out = *in - in.PubSubStatus.DeepCopyInto(&out.PubSubStatus) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudPubSubSourceStatus. -func (in *CloudPubSubSourceStatus) DeepCopy() *CloudPubSubSourceStatus { - if in == nil { - return nil - } - out := new(CloudPubSubSourceStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CloudSchedulerSource) DeepCopyInto(out *CloudSchedulerSource) { - *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 CloudSchedulerSource. -func (in *CloudSchedulerSource) DeepCopy() *CloudSchedulerSource { - if in == nil { - return nil - } - out := new(CloudSchedulerSource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudSchedulerSource) 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 *CloudSchedulerSourceList) DeepCopyInto(out *CloudSchedulerSourceList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]CloudSchedulerSource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudSchedulerSourceList. -func (in *CloudSchedulerSourceList) DeepCopy() *CloudSchedulerSourceList { - if in == nil { - return nil - } - out := new(CloudSchedulerSourceList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudSchedulerSourceList) 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 *CloudSchedulerSourceSpec) DeepCopyInto(out *CloudSchedulerSourceSpec) { - *out = *in - in.PubSubSpec.DeepCopyInto(&out.PubSubSpec) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudSchedulerSourceSpec. -func (in *CloudSchedulerSourceSpec) DeepCopy() *CloudSchedulerSourceSpec { - if in == nil { - return nil - } - out := new(CloudSchedulerSourceSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CloudSchedulerSourceStatus) DeepCopyInto(out *CloudSchedulerSourceStatus) { - *out = *in - in.PubSubStatus.DeepCopyInto(&out.PubSubStatus) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudSchedulerSourceStatus. -func (in *CloudSchedulerSourceStatus) DeepCopy() *CloudSchedulerSourceStatus { - if in == nil { - return nil - } - out := new(CloudSchedulerSourceStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CloudStorageSource) DeepCopyInto(out *CloudStorageSource) { - *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 CloudStorageSource. -func (in *CloudStorageSource) DeepCopy() *CloudStorageSource { - if in == nil { - return nil - } - out := new(CloudStorageSource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudStorageSource) 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 *CloudStorageSourceList) DeepCopyInto(out *CloudStorageSourceList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]CloudStorageSource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudStorageSourceList. -func (in *CloudStorageSourceList) DeepCopy() *CloudStorageSourceList { - if in == nil { - return nil - } - out := new(CloudStorageSourceList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CloudStorageSourceList) 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 *CloudStorageSourceSpec) DeepCopyInto(out *CloudStorageSourceSpec) { - *out = *in - in.PubSubSpec.DeepCopyInto(&out.PubSubSpec) - if in.EventTypes != nil { - in, out := &in.EventTypes, &out.EventTypes - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudStorageSourceSpec. -func (in *CloudStorageSourceSpec) DeepCopy() *CloudStorageSourceSpec { - if in == nil { - return nil - } - out := new(CloudStorageSourceSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CloudStorageSourceStatus) DeepCopyInto(out *CloudStorageSourceStatus) { - *out = *in - in.PubSubStatus.DeepCopyInto(&out.PubSubStatus) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CloudStorageSourceStatus. -func (in *CloudStorageSourceStatus) DeepCopy() *CloudStorageSourceStatus { - if in == nil { - return nil - } - out := new(CloudStorageSourceStatus) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/apis/events/v1beta1/cloudpubsubsource_conversion.go b/pkg/apis/events/v1beta1/cloudpubsubsource_conversion.go index 3311d88334..d20e6e259f 100644 --- a/pkg/apis/events/v1beta1/cloudpubsubsource_conversion.go +++ b/pkg/apis/events/v1beta1/cloudpubsubsource_conversion.go @@ -26,7 +26,7 @@ import ( ) // ConvertTo implements apis.Convertible. -// Converts from a v1alpha1.CloudPubSubSource to a higher version of CloudPubSubSource. +// Converts from a v1beta1.CloudPubSubSource to a higher version of CloudPubSubSource. // Currently, we only support v1 as a higher version. func (source *CloudPubSubSource) ConvertTo(ctx context.Context, to apis.Convertible) error { switch sink := to.(type) { @@ -46,7 +46,7 @@ func (source *CloudPubSubSource) ConvertTo(ctx context.Context, to apis.Converti } // ConvertFrom implements apis.Convertible. -// Converts from a higher version of CloudPubSubSource to a v1alpha1.CloudPubSubSource. +// Converts from a higher version of CloudPubSubSource to a v1beta1.CloudPubSubSource. // Currently, we only support v1 as a higher version. func (sink *CloudPubSubSource) ConvertFrom(ctx context.Context, from apis.Convertible) error { switch source := from.(type) { diff --git a/pkg/apis/events/v1beta1/cloudschedulersource_conversion.go b/pkg/apis/events/v1beta1/cloudschedulersource_conversion.go index f1827d4e18..adcc69e1ad 100644 --- a/pkg/apis/events/v1beta1/cloudschedulersource_conversion.go +++ b/pkg/apis/events/v1beta1/cloudschedulersource_conversion.go @@ -26,7 +26,7 @@ import ( ) // ConvertTo implements apis.Convertible. -// Converts from a v1alpha1.CloudSchedulerSource to a higher version of CloudSchedulerSource. +// Converts from a v1beta1.CloudSchedulerSource to a higher version of CloudSchedulerSource. // Currently, we only support v1 as a higher version. func (source *CloudSchedulerSource) ConvertTo(ctx context.Context, to apis.Convertible) error { switch sink := to.(type) { @@ -45,7 +45,7 @@ func (source *CloudSchedulerSource) ConvertTo(ctx context.Context, to apis.Conve } // ConvertFrom implements apis.Convertible. -// Converts from a higher version of CloudSchedulerSource to a v1alpha1.CloudSchedulerSource. +// Converts from a higher version of CloudSchedulerSource to a v1beta1.CloudSchedulerSource. // Currently, we only support v1 as a higher version. func (sink *CloudSchedulerSource) ConvertFrom(ctx context.Context, from apis.Convertible) error { switch source := from.(type) { diff --git a/pkg/apis/intevents/v1alpha1/implements_test.go b/pkg/apis/intevents/v1alpha1/implements_test.go deleted file mode 100644 index 4836515ab3..0000000000 --- a/pkg/apis/intevents/v1alpha1/implements_test.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2019 Google LLC - -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" - - "knative.dev/pkg/apis/duck" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -func TestTypesImplements(t *testing.T) { - testCases := []struct { - instance interface{} - iface duck.Implementable - }{ - {instance: &PullSubscription{}, iface: &duckv1.Source{}}, - {instance: &PullSubscription{}, iface: &duckv1.Conditions{}}, - {instance: &Topic{}, iface: &duckv1.Conditions{}}, - {instance: &Topic{}, iface: &duckv1.Addressable{}}, - } - for _, tc := range testCases { - if err := duck.VerifyType(tc.instance, tc.iface); err != nil { - t.Error(err) - } - } -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_conversion.go b/pkg/apis/intevents/v1alpha1/pullsubscription_conversion.go deleted file mode 100644 index ad71c78f3a..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_conversion.go +++ /dev/null @@ -1,114 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "fmt" - - convert "github.com/google/knative-gcp/pkg/apis/convert" - "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" - "knative.dev/pkg/apis" -) - -// ConvertTo implements apis.Convertible. -// Converts a v1alpha1.PullSubscription to a higher version of PullSubscription. -func (source *PullSubscription) ConvertTo(ctx context.Context, to apis.Convertible) error { - switch sink := to.(type) { - case *v1beta1.PullSubscription: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.ToV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.Topic = source.Spec.Topic - sink.Spec.AckDeadline = source.Spec.AckDeadline - sink.Spec.RetainAckedMessages = source.Spec.RetainAckedMessages - sink.Spec.RetentionDuration = source.Spec.RetentionDuration - sink.Spec.Transformer = source.Spec.Transformer - if mode, err := convertToV1beta1ModeType(source.Spec.Mode); err != nil { - return err - } else { - sink.Spec.Mode = mode - } - sink.Spec.AdapterType = source.Spec.AdapterType - sink.Status.PubSubStatus = convert.ToV1beta1PubSubStatus(source.Status.PubSubStatus) - sink.Status.TransformerURI = source.Status.TransformerURI - sink.Status.SubscriptionID = source.Status.SubscriptionID - // Remove v1alpha1 as deprecated from the Status Condition when converting to a higher version. - convert.RemoveV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertToViaProxy(ctx, source, &v1beta1.PullSubscription{}, sink) - } -} - -// ConvertFrom implements apis.Convertible. -// Converts from a higher version of PullSubscription to a v1alpha1.PullSubscription. -func (sink *PullSubscription) ConvertFrom(ctx context.Context, from apis.Convertible) error { - switch source := from.(type) { - case *v1beta1.PullSubscription: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.PubSubSpec = convert.FromV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.Topic = source.Spec.Topic - sink.Spec.AckDeadline = source.Spec.AckDeadline - sink.Spec.RetainAckedMessages = source.Spec.RetainAckedMessages - sink.Spec.RetentionDuration = source.Spec.RetentionDuration - sink.Spec.Transformer = source.Spec.Transformer - if mode, err := convertFromV1beta1ModeType(source.Spec.Mode); err != nil { - return err - } else { - sink.Spec.Mode = mode - } - sink.Spec.AdapterType = source.Spec.AdapterType - sink.Status.PubSubStatus = convert.FromV1beta1PubSubStatus(source.Status.PubSubStatus) - sink.Status.TransformerURI = source.Status.TransformerURI - sink.Status.SubscriptionID = source.Status.SubscriptionID - // Mark v1alpha1 as deprecated as a Status Condition when converting to v1alpha1. - convert.MarkV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertFromViaProxy(ctx, source, &v1beta1.PullSubscription{}, sink) - } -} - -func convertToV1beta1ModeType(from ModeType) (v1beta1.ModeType, error) { - switch from { - case ModeCloudEventsBinary: - return v1beta1.ModeCloudEventsBinary, nil - case ModeCloudEventsStructured: - return v1beta1.ModeCloudEventsStructured, nil - case ModePushCompatible: - return v1beta1.ModePushCompatible, nil - case "": - return "", nil - default: - return "unknown", fmt.Errorf("unknown ModeType %v", from) - } -} - -func convertFromV1beta1ModeType(from v1beta1.ModeType) (ModeType, error) { - switch from { - case v1beta1.ModeCloudEventsBinary: - return ModeCloudEventsBinary, nil - case v1beta1.ModeCloudEventsStructured: - return ModeCloudEventsStructured, nil - case v1beta1.ModePushCompatible: - return ModePushCompatible, nil - case "": - return "", nil - default: - return "unknown", fmt.Errorf("unknown ModeType %v", from) - } -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_conversion_test.go b/pkg/apis/intevents/v1alpha1/pullsubscription_conversion_test.go deleted file mode 100644 index f25d2e71f5..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_conversion_test.go +++ /dev/null @@ -1,187 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "net/url" - "testing" - - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/convert" - - "github.com/google/go-cmp/cmp" - inteventsv1 "github.com/google/knative-gcp/pkg/apis/intevents/v1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" - gcptesting "github.com/google/knative-gcp/pkg/testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -// These variables are used to create a 'complete' version of PullSubscription where every field is -// filled in. -var ( - // completePullSubscription is a PullSubscription with every field filled in, except TypeMeta. - // TypeMeta is excluded because conversions do not convert it and this variable was created to - // test conversions. - completePullSubscription = &PullSubscription{ - ObjectMeta: gcptesting.CompleteObjectMeta, - Spec: PullSubscriptionSpec{ - PubSubSpec: gcptesting.CompleteV1alpha1PubSubSpec, - Topic: "topic", - AckDeadline: &gcptesting.RetentionDuration, - RetainAckedMessages: false, - RetentionDuration: &gcptesting.RetentionDuration, - Transformer: &gcptesting.CompleteDestination, - Mode: ModeCloudEventsBinary, - AdapterType: "adapterType", - }, - Status: PullSubscriptionStatus{ - PubSubStatus: gcptesting.CompleteV1alpha1PubSubStatus, - TransformerURI: &gcptesting.CompleteURL, - SubscriptionID: "subscriptionID", - }, - } -) - -func TestPullSubscriptionConversionBadType(t *testing.T) { - good, bad := &PullSubscription{}, &Topic{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestPullSubscriptionConversionBetweenV1Beta1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.PullSubscription{}} - - tests := []struct { - name string - in *PullSubscription - }{{ - name: "min configuration", - in: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: PullSubscriptionSpec{}, - }, - }, { - name: "full configuration", - in: completePullSubscription, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &PullSubscription{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - if diff := cmp.Diff(test.in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} - -func TestPullSubscriptionConversionBetweenV1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&inteventsv1.PullSubscription{}} - - tests := []struct { - name string - in *PullSubscription - }{{ - name: "min configuration", - in: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Name: "ps-name", - Namespace: "ps-ns", - Generation: 17, - }, - Spec: PullSubscriptionSpec{}, - }, - }, { - name: "full configuration", - in: completePullSubscription, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - // DeepCopy because we will edit it below. - in := test.in.DeepCopy() - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &PullSubscription{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - // IdentityStatus.ServiceAccountName and PullSubscriptionSpec.Mode only exists in v1alpha1 and v1beta1, they don't exist in v1. - // So this won't be a round trip, they will be silently removed. - in.Status.ServiceAccountName = "" - in.Spec.Mode = "" - if diff := cmp.Diff(in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_defaults.go b/pkg/apis/intevents/v1alpha1/pullsubscription_defaults.go deleted file mode 100644 index cf9ea77fdb..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_defaults.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - - "knative.dev/pkg/apis" - "knative.dev/pkg/ptr" - - "github.com/google/knative-gcp/pkg/apis/duck" - "github.com/google/knative-gcp/pkg/apis/intevents" - metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" -) - -func (s *PullSubscription) SetDefaults(ctx context.Context) { - ctx = apis.WithinParent(ctx, s.ObjectMeta) - s.Spec.SetDefaults(ctx) - duck.SetClusterNameAnnotation(&s.ObjectMeta, metadataClient.NewDefaultMetadataClient()) - duck.SetAutoscalingAnnotationsDefaults(ctx, &s.ObjectMeta) -} - -func (ss *PullSubscriptionSpec) SetDefaults(ctx context.Context) { - if ss.AckDeadline == nil { - ackDeadline := intevents.DefaultAckDeadline - ss.AckDeadline = ptr.String(ackDeadline.String()) - } - - if ss.RetentionDuration == nil { - retentionDuration := intevents.DefaultRetentionDuration - ss.RetentionDuration = ptr.String(retentionDuration.String()) - } - - ss.PubSubSpec.SetPubSubDefaults(ctx) - - switch ss.Mode { - case ModeCloudEventsBinary, ModeCloudEventsStructured, ModePushCompatible: - // Valid Mode. - default: - // Default is CloudEvents Binary Mode. - ss.Mode = ModeCloudEventsBinary - } -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_defaults_test.go b/pkg/apis/intevents/v1alpha1/pullsubscription_defaults_test.go deleted file mode 100644 index 8c322cdb1b..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_defaults_test.go +++ /dev/null @@ -1,233 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - "time" - - "github.com/google/go-cmp/cmp" - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "github.com/google/knative-gcp/pkg/apis/duck" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents" - testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/ptr" -) - -func TestPullSubscriptionDefaults(t *testing.T) { - - defaultRetentionDuration := intevents.DefaultRetentionDuration - defaultAckDeadline := intevents.DefaultAckDeadline - - tests := []struct { - name string - start *PullSubscription - want *PullSubscription - }{{ - name: "non-nil structured", - start: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{ - Mode: ModeCloudEventsStructured, - RetentionDuration: ptr.String(defaultRetentionDuration.String()), - AckDeadline: ptr.String(defaultAckDeadline.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "my-cloud-key", - }, - Key: "test.json", - }, - }, - }, - }, - want: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{ - Mode: ModeCloudEventsStructured, - RetentionDuration: ptr.String(defaultRetentionDuration.String()), - AckDeadline: ptr.String(defaultAckDeadline.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "my-cloud-key", - }, - Key: "test.json", - }, - }, - }, - }, - }, { - name: "non-nil push", - start: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{ - Mode: ModePushCompatible, - }, - }, - want: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{ - Mode: ModePushCompatible, - RetentionDuration: ptr.String(defaultRetentionDuration.String()), - AckDeadline: ptr.String(defaultAckDeadline.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &gcpauthtesthelper.Secret, - }, - }, - }, - }, { - name: "non-nil invalid", - start: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{ - Mode: "invalid", - }, - }, - want: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{ - Mode: ModeCloudEventsBinary, - RetentionDuration: ptr.String(defaultRetentionDuration.String()), - AckDeadline: ptr.String(defaultAckDeadline.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &gcpauthtesthelper.Secret, - }, - }, - }, - }, { - name: "nil", - start: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{}, - }, - want: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{ - Mode: ModeCloudEventsBinary, - RetentionDuration: ptr.String(defaultRetentionDuration.String()), - AckDeadline: ptr.String(defaultAckDeadline.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &gcpauthtesthelper.Secret, - }, - }, - }, - }, { - name: "nil secret", - start: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{}, - }, - want: &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{ - Mode: ModeCloudEventsBinary, - RetentionDuration: ptr.String(defaultRetentionDuration.String()), - AckDeadline: ptr.String(defaultAckDeadline.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &gcpauthtesthelper.Secret, - }, - }, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.start - got.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } - }) - } -} - -func TestPullSubscriptionDefaults_NoChange(t *testing.T) { - days2 := 2 * 24 * time.Hour - secs60 := 60 * time.Second - want := &PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: PullSubscriptionSpec{ - Mode: ModeCloudEventsBinary, - AckDeadline: ptr.String(secs60.String()), - RetentionDuration: ptr.String(days2.String()), - PubSubSpec: duckv1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "my-cloud-key", - }, - Key: "test.json", - }, - }, - }, - } - - got := want.DeepCopy() - got.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_lifecycle.go b/pkg/apis/intevents/v1alpha1/pullsubscription_lifecycle.go deleted file mode 100644 index e3881af9b3..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_lifecycle.go +++ /dev/null @@ -1,105 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" -) - -// GetCondition returns the condition currently associated with the given type, or nil. -func (s *PullSubscriptionStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return pullSubscriptionCondSet.Manage(s).GetCondition(t) -} - -// GetTopLevelCondition returns the top level Condition. -func (s *PullSubscriptionStatus) GetTopLevelCondition() *apis.Condition { - return pullSubscriptionCondSet.Manage(s).GetTopLevelCondition() -} - -// IsReady returns true if the resource is ready overall. -func (s *PullSubscriptionStatus) IsReady() bool { - return pullSubscriptionCondSet.Manage(s).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (s *PullSubscriptionStatus) InitializeConditions() { - pullSubscriptionCondSet.Manage(s).InitializeConditions() -} - -// MarkSink sets the condition that the source has a sink configured. -func (s *PullSubscriptionStatus) MarkSink(uri *apis.URL) { - s.SinkURI = uri - if !uri.IsEmpty() { - pullSubscriptionCondSet.Manage(s).MarkTrue(PullSubscriptionConditionSinkProvided) - } else { - pullSubscriptionCondSet.Manage(s).MarkUnknown(PullSubscriptionConditionSinkProvided, "SinkEmpty", "Sink has resolved to empty") - } -} - -// MarkNoSink sets the condition that the source does not have a sink configured. -func (s *PullSubscriptionStatus) MarkNoSink(reason, messageFormat string, messageA ...interface{}) { - pullSubscriptionCondSet.Manage(s).MarkFalse(PullSubscriptionConditionSinkProvided, reason, messageFormat, messageA...) -} - -// MarkTransformer sets the condition that the source has a transformer configured. -func (s *PullSubscriptionStatus) MarkTransformer(uri *apis.URL) { - s.TransformerURI = uri - if !uri.IsEmpty() { - pullSubscriptionCondSet.Manage(s).MarkTrue(PullSubscriptionConditionTransformerProvided) - } else { - pullSubscriptionCondSet.Manage(s).MarkUnknown(PullSubscriptionConditionTransformerProvided, "TransformerEmpty", "Transformer has resolved to empty.") - } -} - -// MarkNoTransformer sets the condition that the source does not have a transformer configured. -func (s *PullSubscriptionStatus) MarkNoTransformer(reason, messageFormat string, messageA ...interface{}) { - pullSubscriptionCondSet.Manage(s).MarkFalse(PullSubscriptionConditionTransformerProvided, reason, messageFormat, messageA...) -} - -// MarkSubscribed sets the condition that the subscription has been created. -func (s *PullSubscriptionStatus) MarkSubscribed(subscriptionID string) { - s.SubscriptionID = subscriptionID - pullSubscriptionCondSet.Manage(s).MarkTrue(PullSubscriptionConditionSubscribed) -} - -// MarkNoSubscription sets the condition that the subscription does not exist. -func (s *PullSubscriptionStatus) MarkNoSubscription(reason, messageFormat string, messageA ...interface{}) { - pullSubscriptionCondSet.Manage(s).MarkFalse(PullSubscriptionConditionSubscribed, reason, messageFormat, messageA...) -} - -// PropagateDeploymentAvailability uses the availability of the provided Deployment to determine if -// PullSubscriptionConditionDeployed should be marked as true or false. -func (s *PullSubscriptionStatus) PropagateDeploymentAvailability(d *appsv1.Deployment) { - deploymentAvailableFound := false - for _, cond := range d.Status.Conditions { - if cond.Type == appsv1.DeploymentAvailable { - deploymentAvailableFound = true - if cond.Status == corev1.ConditionTrue { - pullSubscriptionCondSet.Manage(s).MarkTrue(PullSubscriptionConditionDeployed) - } else if cond.Status == corev1.ConditionFalse { - pullSubscriptionCondSet.Manage(s).MarkFalse(PullSubscriptionConditionDeployed, cond.Reason, cond.Message) - } else if cond.Status == corev1.ConditionUnknown { - pullSubscriptionCondSet.Manage(s).MarkUnknown(PullSubscriptionConditionDeployed, cond.Reason, cond.Message) - } - } - } - if !deploymentAvailableFound { - pullSubscriptionCondSet.Manage(s).MarkUnknown(PullSubscriptionConditionDeployed, "DeploymentUnavailable", "Deployment %q is unavailable.", d.Name) - } -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_lifecycle_test.go b/pkg/apis/intevents/v1alpha1/pullsubscription_lifecycle_test.go deleted file mode 100644 index dad6b32aba..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_lifecycle_test.go +++ /dev/null @@ -1,457 +0,0 @@ -/* -Copyright 2019 Google LLC - -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" - - appsv1 "k8s.io/api/apps/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - corev1 "k8s.io/api/core/v1" -) - -var ( - availableDeployment = &appsv1.Deployment{ - Status: appsv1.DeploymentStatus{ - Conditions: []appsv1.DeploymentCondition{ - { - Type: appsv1.DeploymentAvailable, - Status: corev1.ConditionTrue, - }, - }, - }, - } - - unavailableDeployment = &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-deployment", - }, - Status: appsv1.DeploymentStatus{ - Conditions: []appsv1.DeploymentCondition{ - { - Type: appsv1.DeploymentAvailable, - Status: corev1.ConditionFalse, - Reason: "The status of Deployment is False", - Message: "False Status", - }, - }, - }, - } -) - -func TestPullSubscriptionStatusIsReady(t *testing.T) { - tests := []struct { - name string - s *PullSubscriptionStatus - wantConditionStatus corev1.ConditionStatus - want bool - }{{ - name: "uninitialized", - s: &PullSubscriptionStatus{}, - want: false, - }, { - name: "initialized", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "mark deployed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.PropagateDeploymentAvailability(availableDeployment) - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "mark sink", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "mark subscribed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSubscribed("subID") - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "mark sink and deployed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - s.PropagateDeploymentAvailability(availableDeployment) - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "mark sink and deployed and subscribed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - return s - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }, { - name: "mark sink and deployed and subscribed, then no sink", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - s.MarkNoSink("Testing", "") - return s - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, { - name: "mark sink and deployed and subscribed then not deployed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - s.PropagateDeploymentAvailability(unavailableDeployment) - return s - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, { - name: "mark sink and subscribed and not deployed then deployed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - s.MarkSubscribed("subID") - s.PropagateDeploymentAvailability(unavailableDeployment) - s.PropagateDeploymentAvailability(availableDeployment) - return s - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }, { - name: "mark sink nil and deployed and subscribed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(nil) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "mark sink nil and deployed and subscribed then sink", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(nil) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - s.MarkSink(apis.HTTP("example")) - return s - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }, { - name: "mark sink empty and deployed and subscribed then sink", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(&apis.URL{}) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - s.MarkSink(apis.HTTP("example")) - return s - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - if test.wantConditionStatus != "" { - gotConditionStatus := test.s.GetTopLevelCondition().Status - if gotConditionStatus != test.wantConditionStatus { - t.Errorf("unexpected condition status: want %v, got %v", test.wantConditionStatus, gotConditionStatus) - } - } - got := test.s.IsReady() - if got != test.want { - t.Errorf("unexpected readiness: want %v, got %v", test.want, got) - } - }) - } -} - -func TestPullSubscriptionStatusGetCondition(t *testing.T) { - tests := []struct { - name string - s *PullSubscriptionStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "uninitialized", - s: &PullSubscriptionStatus{}, - condQuery: PullSubscriptionConditionReady, - want: nil, - }, { - name: "initialized", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - return s - }(), - condQuery: PullSubscriptionConditionReady, - want: &apis.Condition{ - Type: PullSubscriptionConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark deployed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.PropagateDeploymentAvailability(availableDeployment) - return s - }(), - condQuery: PullSubscriptionConditionReady, - want: &apis.Condition{ - Type: PullSubscriptionConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark sink", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - return s - }(), - condQuery: PullSubscriptionConditionReady, - want: &apis.Condition{ - Type: PullSubscriptionConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark subscribed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSubscribed("subID") - return s - }(), - condQuery: PullSubscriptionConditionSubscribed, - want: &apis.Condition{ - Type: PullSubscriptionConditionSubscribed, - Status: corev1.ConditionTrue, - }, - }, { - name: "mark not subscribed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkNoSubscription("reason", "%s", "message") - return s - }(), - condQuery: PullSubscriptionConditionSubscribed, - want: &apis.Condition{ - Type: PullSubscriptionConditionSubscribed, - Status: corev1.ConditionFalse, - Reason: "reason", - Message: "message", - }, - }, { - name: "mark transformer", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkTransformer(apis.HTTP("url")) - return s - }(), - condQuery: PullSubscriptionConditionTransformerProvided, - want: &apis.Condition{ - Type: PullSubscriptionConditionTransformerProvided, - Status: corev1.ConditionTrue, - }, - }, { - name: "mark transformer unknown", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkTransformer(nil) - return s - }(), - condQuery: PullSubscriptionConditionTransformerProvided, - want: &apis.Condition{ - Type: PullSubscriptionConditionTransformerProvided, - Status: corev1.ConditionUnknown, - Reason: "TransformerEmpty", - Message: "Transformer has resolved to empty.", - }, - }, { - name: "mark no transformer", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkNoTransformer("reason", "%s", "message") - return s - }(), - condQuery: PullSubscriptionConditionTransformerProvided, - want: &apis.Condition{ - Type: PullSubscriptionConditionTransformerProvided, - Status: corev1.ConditionFalse, - Reason: "reason", - Message: "message", - }, - }, { - name: "mark sink and deployed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - s.PropagateDeploymentAvailability(availableDeployment) - return s - }(), - condQuery: PullSubscriptionConditionReady, - want: &apis.Condition{ - Type: PullSubscriptionConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark sink and deployed and subscribed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - return s - }(), - condQuery: PullSubscriptionConditionReady, - want: &apis.Condition{ - Type: PullSubscriptionConditionReady, - Status: corev1.ConditionTrue, - }, - }, { - name: "mark sink and deployed and subscribed then no sink", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - s.MarkNoSink("Testing", "hi") - return s - }(), - condQuery: PullSubscriptionConditionReady, - want: &apis.Condition{ - Type: PullSubscriptionConditionReady, - Status: corev1.ConditionFalse, - Reason: "Testing", - Message: "hi", - }, - }, { - name: "mark sink and deployed and subscribed then not deployed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(apis.HTTP("example")) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - s.PropagateDeploymentAvailability(unavailableDeployment) - return s - }(), - condQuery: PullSubscriptionConditionReady, - want: &apis.Condition{ - Type: PullSubscriptionConditionReady, - Status: corev1.ConditionFalse, - Reason: "The status of Deployment is False", - Message: "False Status", - }, - }, { - name: "mark sink nil and deployed and subscribed", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(nil) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - return s - }(), - condQuery: PullSubscriptionConditionReady, - want: &apis.Condition{ - Type: PullSubscriptionConditionReady, - Status: corev1.ConditionUnknown, - Reason: "SinkEmpty", - Message: "Sink has resolved to empty", - }, - }, { - name: "mark sink nil and deployed and subscribed then sink", - s: func() *PullSubscriptionStatus { - s := &PullSubscriptionStatus{} - s.InitializeConditions() - s.MarkSink(nil) - s.PropagateDeploymentAvailability(availableDeployment) - s.MarkSubscribed("subID") - s.MarkSink(apis.HTTP("example")) - return s - }(), - condQuery: PullSubscriptionConditionReady, - want: &apis.Condition{ - Type: PullSubscriptionConditionReady, - Status: corev1.ConditionTrue, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.s.GetCondition(test.condQuery) - ignoreTime := cmpopts.IgnoreFields(apis.Condition{}, - "LastTransitionTime", "Severity") - if diff := cmp.Diff(test.want, got, ignoreTime); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_types.go b/pkg/apis/intevents/v1alpha1/pullsubscription_types.go deleted file mode 100644 index 7dc4cc443e..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_types.go +++ /dev/null @@ -1,217 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "time" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck" - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// PullSubscription is the Schema for the gcppullSubscriptions API. -// +k8s:openapi-gen=true -type PullSubscription struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec PullSubscriptionSpec `json:"spec,omitempty"` - Status PullSubscriptionStatus `json:"status,omitempty"` -} - -// PubSubMode returns the mode currently set for PullSubscription. -func (p *PullSubscription) PubSubMode() ModeType { - return p.Spec.Mode -} - -// Check that PullSubscription can be converted to other versions. -var _ apis.Convertible = (*PullSubscription)(nil) - -// Check that PullSubscription can be validated and can be defaulted. -var _ runtime.Object = (*PullSubscription)(nil) - -// Check that PullSubscription implements the Conditions duck type. -var _ = duck.VerifyType(&PullSubscription{}, &duckv1.Conditions{}) - -// PullSubscriptionSpec defines the desired state of the PullSubscription. -type PullSubscriptionSpec struct { - v1alpha1.PubSubSpec `json:",inline"` - - // Topic is the ID of the PullSubscription Topic to Subscribe to. It must - // be in the form of the unique identifier within the project, not the - // entire name. E.g. it must be 'laconia', not - // 'projects/my-proj/topics/laconia'. - Topic string `json:"topic,omitempty"` - - // AckDeadline is the default maximum time after a subscriber receives a - // message before the subscriber should acknowledge the message. Defaults - // to 30 seconds ('30s'). - // +optional - AckDeadline *string `json:"ackDeadline,omitempty"` - - // RetainAckedMessages defines whether to retain acknowledged messages. If - // true, acknowledged messages will not be expunged until they fall out of - // the RetentionDuration window. - RetainAckedMessages bool `json:"retainAckedMessages,omitempty"` - - // RetentionDuration defines how long to retain messages in backlog, from - // the time of publish. If RetainAckedMessages is true, this duration - // affects the retention of acknowledged messages, otherwise only - // unacknowledged messages are retained. Cannot be longer than 7 days or - // shorter than 10 minutes. Defaults to 7 days ('7d'). - // +optional - RetentionDuration *string `json:"retentionDuration,omitempty"` - - // Transformer is a reference to an object that will resolve to a domain - // name or a URI directly to use as the transformer or a URI directly. - // +optional - Transformer *duckv1.Destination `json:"transformer,omitempty"` - - // Mode defines the encoding and structure of the payload of when the - // PullSubscription invokes the sink. - // +optional - Mode ModeType `json:"mode,omitempty"` - - // AdapterType determines the type of receive adapter that a - // PullSubscription uses. - // +optional - AdapterType string `json:"adapterType,omitempty"` -} - -// GetAckDeadline parses AckDeadline and returns the default if an error occurs. -func (ps PullSubscriptionSpec) GetAckDeadline() time.Duration { - if ps.AckDeadline != nil { - if duration, err := time.ParseDuration(*ps.AckDeadline); err == nil { - return duration - } - } - return intevents.DefaultAckDeadline -} - -// GetRetentionDuration parses RetentionDuration and returns the default if an error occurs. -func (ps PullSubscriptionSpec) GetRetentionDuration() time.Duration { - if ps.RetentionDuration != nil { - if duration, err := time.ParseDuration(*ps.RetentionDuration); err == nil { - return duration - } - } - return intevents.DefaultRetentionDuration -} - -type ModeType string - -const ( - // ModeCloudEventsBinary will use CloudEvents binary HTTP mode with - // flattened Pub/Sub payload. - ModeCloudEventsBinary ModeType = "CloudEventsBinary" - - // ModeCloudEventsStructured will use CloudEvents structured HTTP mode with - // flattened Pub/Sub payload. - ModeCloudEventsStructured ModeType = "CloudEventsStructured" - - // ModePushCompatible will use CloudEvents binary HTTP mode with expanded - // Pub/Sub payload that matches how Cloud Pub/Sub delivers a push message. - ModePushCompatible ModeType = "PushCompatible" -) - -const ( - // PullSubscriptionConditionReady has status True when the PullSubscription is - // ready to send events. - PullSubscriptionConditionReady = apis.ConditionReady - - // PullSubscriptionConditionSinkProvided has status True when the PullSubscription - // has been configured with a sink target. - PullSubscriptionConditionSinkProvided apis.ConditionType = "SinkProvided" - - // PullSubscriptionConditionDeployed has status True when the PullSubscription has - // had its data plane resource(s) created. - PullSubscriptionConditionDeployed apis.ConditionType = "Deployed" - - // PullSubscriptionConditionSubscribed has status True when a Google Cloud - // Pub/Sub Subscription has been created pointing at the created receive - // adapter deployment. - PullSubscriptionConditionSubscribed apis.ConditionType = "Subscribed" - - // PullSubscriptionConditionTransformerProvided has status True when the - // PullSubscription has been configured with a transformer target. - PullSubscriptionConditionTransformerProvided apis.ConditionType = "TransformerProvided" -) - -var pullSubscriptionCondSet = apis.NewLivingConditionSet( - PullSubscriptionConditionSinkProvided, - PullSubscriptionConditionDeployed, - PullSubscriptionConditionSubscribed, -) - -// PullSubscriptionStatus defines the observed state of PullSubscription. -type PullSubscriptionStatus struct { - v1alpha1.PubSubStatus `json:",inline"` - - // TransformerURI is the current active transformer URI that has been - // configured for the PullSubscription. - // +optional - TransformerURI *apis.URL `json:"transformerUri,omitempty"` - - // SubscriptionID is the created subscription ID used by the PullSubscription. - // +optional - SubscriptionID string `json:"subscriptionId,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// PullSubscriptionList contains a list of PubSubs. -type PullSubscriptionList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []PullSubscription `json:"items"` -} - -// GetGroupVersionKind returns the GroupVersionKind. -func (s *PullSubscription) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("PullSubscription") -} - -// GetGroupVersionKind returns the GroupVersion. -func (s *PullSubscription) GetGroupVersion() schema.GroupVersion { - return SchemeGroupVersion -} - -// Methods for identifiable interface. -// IdentitySpec returns the IdentitySpec portion of the Spec. -func (s *PullSubscription) IdentitySpec() *v1alpha1.IdentitySpec { - return &s.Spec.IdentitySpec -} - -// IdentityStatus returns the IdentityStatus portion of the Status. -func (s *PullSubscription) IdentityStatus() *v1alpha1.IdentityStatus { - return &s.Status.IdentityStatus -} - -// ConditionSet returns the apis.ConditionSet of the embedding object -func (*PullSubscription) ConditionSet() *apis.ConditionSet { - return &pullSubscriptionCondSet -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_types_test.go b/pkg/apis/intevents/v1alpha1/pullsubscription_types_test.go deleted file mode 100644 index 04fdb50336..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_types_test.go +++ /dev/null @@ -1,155 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - "time" - - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" - "knative.dev/pkg/ptr" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents" -) - -func TestPullSubscriptionGetGroupVersionKind(t *testing.T) { - want := schema.GroupVersionKind{ - Group: "internal.events.cloud.google.com", - Version: "v1alpha1", - Kind: "PullSubscription", - } - - c := &PullSubscription{} - got := c.GetGroupVersionKind() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestPullSubscriptionPubSubMode_nil(t *testing.T) { - want := ModeType("") - - c := &PullSubscription{} - got := c.PubSubMode() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestGetAckDeadline(t *testing.T) { - want := 10 * time.Second - s := &PullSubscriptionSpec{AckDeadline: ptr.String("10s")} - got := s.GetAckDeadline() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestGetRetentionDuration(t *testing.T) { - want := 10 * time.Second - s := &PullSubscriptionSpec{RetentionDuration: ptr.String("10s")} - got := s.GetRetentionDuration() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestGetAckDeadline_default(t *testing.T) { - want := intevents.DefaultAckDeadline - s := &PullSubscriptionSpec{} - got := s.GetAckDeadline() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestGetRetentionDuration_default(t *testing.T) { - want := intevents.DefaultRetentionDuration - s := &PullSubscriptionSpec{} - got := s.GetRetentionDuration() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestPullSubscriptionIdentitySpec(t *testing.T) { - s := &PullSubscription{ - Spec: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "test", - }, - }, - }, - } - want := "test" - got := s.IdentitySpec().ServiceAccountName - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestPullSubscriptionIdentityStatus(t *testing.T) { - s := &PullSubscription{ - Status: PullSubscriptionStatus{ - PubSubStatus: v1alpha1.PubSubStatus{ - IdentityStatus: v1alpha1.IdentityStatus{}, - }, - }, - } - want := &v1alpha1.IdentityStatus{} - got := s.IdentityStatus() - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestPullSubscriptionConditionSet(t *testing.T) { - want := []apis.Condition{{ - Type: PullSubscriptionConditionSinkProvided, - }, { - Type: PullSubscriptionConditionDeployed, - }, { - Type: PullSubscriptionConditionSubscribed, - }, { - Type: apis.ConditionReady, - }} - c := &PullSubscription{} - - c.ConditionSet().Manage(&c.Status).InitializeConditions() - var got []apis.Condition = c.Status.GetConditions() - - compareConditionTypes := cmp.Transformer("ConditionType", func(c apis.Condition) apis.ConditionType { - return c.Type - }) - sortConditionTypes := cmpopts.SortSlices(func(a, b apis.Condition) bool { - return a.Type < b.Type - }) - if diff := cmp.Diff(want, got, sortConditionTypes, compareConditionTypes); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_validation.go b/pkg/apis/intevents/v1alpha1/pullsubscription_validation.go deleted file mode 100644 index 385953144f..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_validation.go +++ /dev/null @@ -1,137 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - "time" - - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck" - "github.com/google/knative-gcp/pkg/apis/intevents" -) - -func (current *PullSubscription) Validate(ctx context.Context) *apis.FieldError { - errs := current.Spec.Validate(ctx).ViaField("spec") - - if apis.IsInUpdate(ctx) { - original := apis.GetBaseline(ctx).(*PullSubscription) - errs = errs.Also(current.CheckImmutableFields(ctx, original)) - } - return duck.ValidateAutoscalingAnnotations(ctx, current.Annotations, errs) -} - -func (current *PullSubscriptionSpec) Validate(ctx context.Context) *apis.FieldError { - var errs *apis.FieldError - // Topic [required] - if current.Topic == "" { - errs = errs.Also(apis.ErrMissingField("topic")) - } - // Sink [required] - if equality.Semantic.DeepEqual(current.Sink, duckv1.Destination{}) { - errs = errs.Also(apis.ErrMissingField("sink")) - } else if err := current.Sink.Validate(ctx); err != nil { - errs = errs.Also(err.ViaField("sink")) - } - // Transformer [optional] - if current.Transformer != nil && !equality.Semantic.DeepEqual(current.Transformer, &duckv1.Destination{}) { - if err := current.Transformer.Validate(ctx); err != nil { - errs = errs.Also(err.ViaField("transformer")) - } - } - - if current.RetentionDuration != nil { - // If set, RetentionDuration Cannot be longer than 7 days or shorter than 10 minutes. - rd, err := time.ParseDuration(*current.RetentionDuration) - if err != nil { - errs = errs.Also(apis.ErrInvalidValue(*current.RetentionDuration, "retentionDuration")) - } else if rd < intevents.MinRetentionDuration || rd > intevents.MaxRetentionDuration { - errs = errs.Also(apis.ErrOutOfBoundsValue(*current.RetentionDuration, intevents.MinRetentionDuration.String(), intevents.MaxRetentionDuration.String(), "retentionDuration")) - } - } - - if current.AckDeadline != nil { - // If set, AckDeadline needs to parse to a valid duration. - ad, err := time.ParseDuration(*current.AckDeadline) - if err != nil { - errs = errs.Also(apis.ErrInvalidValue(*current.AckDeadline, "ackDeadline")) - } else if ad < intevents.MinAckDeadline || ad > intevents.MaxAckDeadline { - errs = errs.Also(apis.ErrOutOfBoundsValue(*current.AckDeadline, intevents.MinAckDeadline.String(), intevents.MaxAckDeadline.String(), "ackDeadline")) - } - } - - // Mode [optional] - switch current.Mode { - case "", ModeCloudEventsBinary, ModeCloudEventsStructured, ModePushCompatible: - // valid - default: - errs = errs.Also(apis.ErrInvalidValue(current.Mode, "mode")) - } - - if current.Secret != nil { - if !equality.Semantic.DeepEqual(current.Secret, &corev1.SecretKeySelector{}) { - err := validateSecret(current.Secret) - if err != nil { - errs = errs.Also(err.ViaField("secret")) - } - } - } - - return errs -} - -// TODO move this to a common place. -func validateSecret(secret *corev1.SecretKeySelector) *apis.FieldError { - var errs *apis.FieldError - if secret.Name == "" { - errs = errs.Also(apis.ErrMissingField("name")) - } - if secret.Key == "" { - errs = errs.Also(apis.ErrMissingField("key")) - } - return errs -} - -func (current *PullSubscription) CheckImmutableFields(ctx context.Context, original *PullSubscription) *apis.FieldError { - if original == nil { - return nil - } - - var errs *apis.FieldError - // Modification of Topic, Secret, Mode, AckDeadline, RetainAckedMessages, RetentionDuration and Project are not allowed. - // Everything else is mutable. - if diff := cmp.Diff(original.Spec, current.Spec, - cmpopts.IgnoreFields(PullSubscriptionSpec{}, - "Sink", "Transformer", "CloudEventOverrides")); diff != "" { - errs = errs.Also(&apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - }) - } - // Modification of AutoscalingClassAnnotations is not allowed. - errs = duck.CheckImmutableAutoscalingClassAnnotations(¤t.ObjectMeta, &original.ObjectMeta, errs) - - // Modification of non-empty cluster name annotation is not allowed. - return duck.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) -} diff --git a/pkg/apis/intevents/v1alpha1/pullsubscription_validation_test.go b/pkg/apis/intevents/v1alpha1/pullsubscription_validation_test.go deleted file mode 100644 index b01a29a870..0000000000 --- a/pkg/apis/intevents/v1alpha1/pullsubscription_validation_test.go +++ /dev/null @@ -1,828 +0,0 @@ -/* -Copyright 2019 Google LLC - -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 ( - "context" - "testing" - - corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/ptr" - - "github.com/google/knative-gcp/pkg/apis/duck" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" -) - -var ( - pullSubscriptionSpec = PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key", - }, - Project: "my-eventing-project", - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - }, - Topic: "pubsub-topic", - Transformer: &duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - Mode: ModeCloudEventsStructured, - AckDeadline: ptr.String("30s"), - RetainAckedMessages: true, - RetentionDuration: ptr.String("30s"), - } - - pullSubscriptionSpecWithKSA = PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Project: "my-eventing-project", - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - }, - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - }, - Topic: "pubsub-topic", - Transformer: &duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - }, - Mode: ModeCloudEventsStructured, - } -) - -func TestPullSubscriptionCheckValidationFields(t *testing.T) { - testCases := map[string]struct { - spec PullSubscriptionSpec - error bool - }{ - "ok": { - spec: pullSubscriptionSpec, - error: false, - }, - "bad RetentionDuration": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.RetentionDuration = ptr.String("wrong") - return *obj - }(), - error: true, - }, - "bad RetentionDuration, range": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.RetentionDuration = ptr.String("10000h") - return *obj - }(), - error: true, - }, - "bad AckDeadline": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.AckDeadline = ptr.String("wrong") - return *obj - }(), - error: true, - }, - "bad AckDeadline, range": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.AckDeadline = ptr.String("10000h") - return *obj - }(), - error: true, - }, - "bad sink, name": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.Sink.Ref.Name = "" - return *obj - }(), - error: true, - }, - "bad sink, apiVersion": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.Sink.Ref.APIVersion = "" - return *obj - }(), - error: true, - }, - "bad sink, kind": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.Sink.Ref.Kind = "" - return *obj - }(), - error: true, - }, - "bad sink, empty": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.Sink = duckv1.Destination{} - return *obj - }(), - error: true, - }, - "bad sink, uri scheme": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.Sink = duckv1.Destination{ - URI: &apis.URL{ - Host: "example.com", - }, - } - return *obj - }(), - error: true, - }, - "bad sink, uri host": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.Sink = duckv1.Destination{ - URI: &apis.URL{ - Scheme: "http", - }, - } - return *obj - }(), - error: true, - }, - "bad sink, uri and ref": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.Sink = duckv1.Destination{ - URI: &apis.URL{ - Scheme: "http", - Host: "example.com", - }, - Ref: &duckv1.KReference{ - Name: "foo", - }, - } - return *obj - }(), - error: true, - }, - "bad transformer, name": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.Transformer = obj.Sink.DeepCopy() - obj.Transformer.Ref.Name = "" - return *obj - }(), - error: true, - }, - "bad secret, missing key": { - spec: func() PullSubscriptionSpec { - obj := pullSubscriptionSpec.DeepCopy() - obj.Secret = &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "some-other-name", - }, - } - return *obj - }(), - error: true, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - err := tc.spec.Validate(context.TODO()) - if tc.error != (err != nil) { - t.Fatalf("Unexpected validation failure. Got %v", err) - } - }) - } -} - -func TestPullSubscriptionCheckImmutableFields(t *testing.T) { - testCases := map[string]struct { - orig interface{} - updated PullSubscriptionSpec - origAnnotation map[string]string - updatedAnnotation map[string]string - allowed bool - }{ - "nil orig": { - updated: pullSubscriptionSpec, - allowed: true, - }, - "ClusterName annotation changed": { - origAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", - }, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: false, - }, - "AnnotationClass annotation changed": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA + "new", - }, - allowed: false, - }, - "AnnotationClass annotation added": { - origAnnotation: map[string]string{}, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - allowed: false, - }, - "AnnotationClass annotation deleted": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{}, - allowed: false, - }, - "Secret.Name changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "some-other-name", - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pullSubscriptionSpec.Sink, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: false, - }, - "Secret.Key changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: "some-other-key", - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pullSubscriptionSpec.Sink, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: false, - }, - "Project changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: "some-other-project", - SourceSpec: duckv1.SourceSpec{ - Sink: pullSubscriptionSpec.Sink, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: false, - }, - "Topic changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pullSubscriptionSpec.Sink, - }, - }, - Topic: "some-other-topic", - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: false, - }, - "ServiceAccountName changed": { - orig: &pullSubscriptionSpecWithKSA, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Project: pullSubscriptionSpecWithKSA.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pullSubscriptionSpecWithKSA.Sink, - }, - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "new-service-account", - }, - }, - Topic: pullSubscriptionSpecWithKSA.Topic, - Mode: pullSubscriptionSpecWithKSA.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: false, - }, - "Sink.APIVersion changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: pullSubscriptionSpec.Sink.Ref.Kind, - Namespace: pullSubscriptionSpec.Sink.Ref.Namespace, - Name: pullSubscriptionSpec.Sink.Ref.Name, - }, - }, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: true, - }, - "Sink.Kind changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: pullSubscriptionSpec.Sink.Ref.APIVersion, - Kind: "some-other-kind", - Namespace: pullSubscriptionSpec.Sink.Ref.Namespace, - Name: pullSubscriptionSpec.Sink.Ref.Name, - }, - }, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: true, - }, - "Sink.Namespace changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: pullSubscriptionSpec.Sink.Ref.APIVersion, - Kind: pullSubscriptionSpec.Sink.Ref.Kind, - Namespace: "some-other-namespace", - Name: pullSubscriptionSpec.Sink.Ref.Name, - }, - }, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: true, - }, - "Sink.Name changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: pullSubscriptionSpec.Sink.Ref.APIVersion, - Kind: pullSubscriptionSpec.Sink.Ref.Kind, - Namespace: pullSubscriptionSpec.Sink.Ref.Namespace, - Name: "some-other-name", - }, - }, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: true, - }, - "Transformer.APIVersion changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: pullSubscriptionSpec.Transformer.Ref.Kind, - Namespace: pullSubscriptionSpec.Transformer.Ref.Namespace, - Name: pullSubscriptionSpec.Transformer.Ref.Name, - }, - }, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: true, - }, - "Transformer.Kind changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: pullSubscriptionSpec.Transformer.Ref.Kind, - Namespace: pullSubscriptionSpec.Transformer.Ref.Namespace, - Name: pullSubscriptionSpec.Transformer.Ref.Name, - }, - }, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Transformer: &duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: pullSubscriptionSpec.Transformer.Ref.APIVersion, - Kind: "some-other-kind", - Namespace: pullSubscriptionSpec.Transformer.Ref.Namespace, - Name: pullSubscriptionSpec.Transformer.Ref.Name, - }, - }, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: true, - }, - "Transformer.Namespace changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: pullSubscriptionSpec.Transformer.Ref.Kind, - Namespace: pullSubscriptionSpec.Transformer.Ref.Namespace, - Name: pullSubscriptionSpec.Transformer.Ref.Name, - }, - }, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Transformer: &duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: pullSubscriptionSpec.Transformer.Ref.APIVersion, - Kind: pullSubscriptionSpec.Transformer.Ref.Kind, - Namespace: "some-other-namespace", - Name: pullSubscriptionSpec.Transformer.Ref.Name, - }, - }, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: true, - }, - "Transformer.Name changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: "some-other-api-version", - Kind: pullSubscriptionSpec.Transformer.Ref.Kind, - Namespace: pullSubscriptionSpec.Transformer.Ref.Namespace, - Name: pullSubscriptionSpec.Transformer.Ref.Name, - }, - }, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Transformer: &duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: pullSubscriptionSpec.Transformer.Ref.APIVersion, - Kind: pullSubscriptionSpec.Transformer.Ref.Kind, - Namespace: pullSubscriptionSpec.Transformer.Ref.Namespace, - Name: "some-other-name", - }, - }, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: true, - }, - "Mode changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pullSubscriptionSpec.Sink, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: ModePushCompatible, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: false, - }, - "AckDeadline changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pullSubscriptionSpec.Sink, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: ptr.String("50s"), - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: false, - }, - "RetainAckedMessages changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pullSubscriptionSpec.Sink, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: false, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: false, - }, - "RetentionDuration changed": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: duckv1.SourceSpec{ - Sink: pullSubscriptionSpec.Sink, - }, - }, - Topic: pullSubscriptionSpec.Topic, - Mode: pullSubscriptionSpec.Mode, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: ptr.String("50s"), - }, - allowed: false, - }, - "ServiceAccountName added": { - orig: &pullSubscriptionSpec, - updated: PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: pullSubscriptionSpec.Secret.Name, - }, - Key: pullSubscriptionSpec.Secret.Key, - }, - Project: pullSubscriptionSpec.Project, - SourceSpec: pullSubscriptionSpec.SourceSpec, - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - }, - Topic: pullSubscriptionSpecWithKSA.Topic, - AckDeadline: pullSubscriptionSpec.AckDeadline, - RetainAckedMessages: pullSubscriptionSpec.RetainAckedMessages, - RetentionDuration: pullSubscriptionSpec.RetentionDuration, - }, - allowed: false, - }, - "ClusterName annotation added": { - origAnnotation: nil, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: true, - }, - "no change": { - orig: &pullSubscriptionSpec, - updated: pullSubscriptionSpec, - allowed: true, - }, - "not spec": { - orig: []string{"wrong"}, - updated: pullSubscriptionSpec, - allowed: true, - }, - } - - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - var orig *PullSubscription - - if tc.origAnnotation != nil { - orig = &PullSubscription{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.origAnnotation, - }, - } - } else if tc.orig != nil { - if spec, ok := tc.orig.(*PullSubscriptionSpec); ok { - orig = &PullSubscription{ - Spec: *spec, - } - } - } - updated := &PullSubscription{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.updatedAnnotation, - }, - Spec: tc.updated, - } - err := updated.CheckImmutableFields(context.TODO(), orig) - if tc.allowed != (err == nil) { - t.Fatalf("Unexpected immutable field check. Expected %v. Actual %v", tc.allowed, err) - } - }) - } -} diff --git a/pkg/apis/intevents/v1alpha1/register.go b/pkg/apis/intevents/v1alpha1/register.go index e5941362cb..b2efee19fb 100644 --- a/pkg/apis/intevents/v1alpha1/register.go +++ b/pkg/apis/intevents/v1alpha1/register.go @@ -46,10 +46,6 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &BrokerCell{}, &BrokerCellList{}, - &PullSubscription{}, - &PullSubscriptionList{}, - &Topic{}, - &TopicList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/apis/intevents/v1alpha1/register_test.go b/pkg/apis/intevents/v1alpha1/register_test.go index 0a6b62888f..c71269b3de 100644 --- a/pkg/apis/intevents/v1alpha1/register_test.go +++ b/pkg/apis/intevents/v1alpha1/register_test.go @@ -31,12 +31,6 @@ func TestKind(t *testing.T) { "BrokerCell": { kind: "BrokerCell", }, - "PullSubscription": { - kind: "PullSubscription", - }, - "Topic": { - kind: "Topic", - }, } { t.Run(n, func(t *testing.T) { want := schema.GroupKind{ @@ -58,12 +52,6 @@ func TestResource(t *testing.T) { "BrokerCell": { resource: "BrokerCell", }, - "PullSubscription": { - resource: "PullSubscription", - }, - "Topic": { - resource: "Topic", - }, } { t.Run(n, func(t *testing.T) { want := schema.GroupResource{ @@ -87,10 +75,6 @@ func TestAddKnownTypes(t *testing.T) { want := []string{ "BrokerCell", "BrokerCellList", - "PullSubscription", - "PullSubscriptionList", - "Topic", - "TopicList", } got := scheme.KnownTypes(schema.GroupVersion{Group: "internal.events.cloud.google.com", Version: "v1alpha1"}) diff --git a/pkg/apis/intevents/v1alpha1/topic_conversion.go b/pkg/apis/intevents/v1alpha1/topic_conversion.go deleted file mode 100644 index 975ee3d3dc..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_conversion.go +++ /dev/null @@ -1,121 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "fmt" - - convert "github.com/google/knative-gcp/pkg/apis/convert" - "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" - "knative.dev/pkg/apis" -) - -// ConvertTo implements apis.Convertible. -// Converts a v1alpha1.Topic to a higher version of topic. -func (source *Topic) ConvertTo(ctx context.Context, to apis.Convertible) error { - switch sink := to.(type) { - case *v1beta1.Topic: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.IdentitySpec = convert.ToV1beta1IdentitySpec(source.Spec.IdentitySpec) - sink.Spec.Secret = source.Spec.Secret - sink.Spec.Project = source.Spec.Project - sink.Spec.Topic = source.Spec.Topic - if pp, err := convertToV1beta1PropagationPolicy(source.Spec.PropagationPolicy); err != nil { - return err - } else { - sink.Spec.PropagationPolicy = pp - } - sink.Spec.EnablePublisher = source.Spec.EnablePublisher - sink.Status.IdentityStatus = convert.ToV1beta1IdentityStatus(source.Status.IdentityStatus) - if as, err := convert.ToV1beta1AddressStatus(ctx, source.Status.AddressStatus); err != nil { - return err - } else { - sink.Status.AddressStatus = as - } - sink.Status.ProjectID = source.Status.ProjectID - sink.Status.TopicID = source.Status.TopicID - // Remove v1alpha1 as deprecated from the Status Condition when converting to a higher version. - convert.RemoveV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertToViaProxy(ctx, source, &v1beta1.Topic{}, sink) - - } -} - -// ConvertFrom implements apis.Convertible. -// Converts from a higher version of Topic to v1alpha1.Topic. -func (sink *Topic) ConvertFrom(ctx context.Context, from apis.Convertible) error { - switch source := from.(type) { - case *v1beta1.Topic: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.IdentitySpec = convert.FromV1beta1IdentitySpec(source.Spec.IdentitySpec) - sink.Spec.Secret = source.Spec.Secret - sink.Spec.Project = source.Spec.Project - sink.Spec.Topic = source.Spec.Topic - if pp, err := convertFromV1beta1PropagationPolicy(source.Spec.PropagationPolicy); err != nil { - return err - } else { - sink.Spec.PropagationPolicy = pp - } - sink.Spec.EnablePublisher = source.Spec.EnablePublisher - sink.Status.IdentityStatus = convert.FromV1beta1IdentityStatus(source.Status.IdentityStatus) - if as, err := convert.FromV1beta1AddressStatus(ctx, source.Status.AddressStatus); err != nil { - return err - } else { - sink.Status.AddressStatus = as - } - sink.Status.ProjectID = source.Status.ProjectID - sink.Status.TopicID = source.Status.TopicID - // Mark v1alpha1 as deprecated as a Status Condition when converting to v1alpha1. - convert.MarkV1alpha1Deprecated(sink.ConditionSet(), &sink.Status.Status) - return nil - default: - return apis.ConvertFromViaProxy(ctx, source, &v1beta1.Topic{}, sink) - } -} - -func convertToV1beta1PropagationPolicy(pp PropagationPolicyType) (v1beta1.PropagationPolicyType, error) { - switch pp { - case TopicPolicyCreateDelete: - return v1beta1.TopicPolicyCreateDelete, nil - case TopicPolicyCreateNoDelete: - return v1beta1.TopicPolicyCreateNoDelete, nil - case TopicPolicyNoCreateNoDelete: - return v1beta1.TopicPolicyNoCreateNoDelete, nil - case "": - return "", nil - default: - return "unknown", fmt.Errorf("unknown PropagationPolicyType %v", pp) - } -} - -func convertFromV1beta1PropagationPolicy(pp v1beta1.PropagationPolicyType) (PropagationPolicyType, error) { - switch pp { - case v1beta1.TopicPolicyCreateDelete: - return TopicPolicyCreateDelete, nil - case v1beta1.TopicPolicyCreateNoDelete: - return TopicPolicyCreateNoDelete, nil - case v1beta1.TopicPolicyNoCreateNoDelete: - return TopicPolicyNoCreateNoDelete, nil - case "": - return "", nil - default: - return "unknown", fmt.Errorf("unknown PropagationPolicyType %v", pp) - } -} diff --git a/pkg/apis/intevents/v1alpha1/topic_conversion_test.go b/pkg/apis/intevents/v1alpha1/topic_conversion_test.go deleted file mode 100644 index aa3625e0b8..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_conversion_test.go +++ /dev/null @@ -1,237 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "net/url" - "testing" - - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/convert" - - "knative.dev/pkg/apis/duck/v1alpha1" - - "github.com/google/go-cmp/cmp" - v1 "github.com/google/knative-gcp/pkg/apis/intevents/v1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" - gcptesting "github.com/google/knative-gcp/pkg/testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -// These variables are used to create a 'complete' version of Topic where every field is filled in. -var ( - // completeTopic is a Topic with every filled in, except TypeMeta. TypeMeta is excluded because - // conversions do not convert it and this variable was created to test conversions. - completeTopic = &Topic{ - ObjectMeta: gcptesting.CompleteObjectMeta, - Spec: TopicSpec{ - IdentitySpec: gcptesting.CompleteV1alpha1IdentitySpec, - Secret: gcptesting.CompleteSecret, - Project: "project", - Topic: "topic", - PropagationPolicy: TopicPolicyCreateDelete, - EnablePublisher: &trueVal, - }, - Status: TopicStatus{ - IdentityStatus: gcptesting.CompleteV1alpha1IdentityStatus, - AddressStatus: gcptesting.CompleteV1alpha1AddressStatus, - ProjectID: "projectID", - TopicID: "topicID", - }, - } -) - -func TestTopicConversionBadType(t *testing.T) { - good, bad := &Topic{}, &PullSubscription{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestTopicConversionBetweenV1beta1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.Topic{}} - - tests := []struct { - name string - in *Topic - }{{ - name: "min configuration", - in: &Topic{ - ObjectMeta: metav1.ObjectMeta{ - Name: "topic-name", - Namespace: "topic-ns", - Generation: 17, - }, - Spec: TopicSpec{}, - }, - }, { - name: "hostname, no URL", - in: &Topic{ - ObjectMeta: gcptesting.CompleteObjectMeta, - Status: TopicStatus{ - AddressStatus: v1alpha1.AddressStatus{ - Address: &v1alpha1.Addressable{ - Hostname: "not-in-uri", - }, - }, - }, - }, - }, { - name: "full configuration", - in: completeTopic, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &Topic{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Hostname exists in v1alpha1, but not in v1beta1, so it will not be present after - // the round-trip conversion. Compare it manually, then overwrite the output value - // so that the generic comparison later works. - if test.in.Status.Address != nil { - if wantHostname := test.in.Status.Address.Hostname; wantHostname != "" { - if gotHostname := got.Status.Address.URL.Host; wantHostname != gotHostname { - // Note that this assumes that if both a URL and a hostname are - // specified in the original, then they have the same value. - t.Errorf("Incorrect hostname, want %q, got %q", wantHostname, gotHostname) - } - got.Status.Address = test.in.Status.Address - } - } - - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - if diff := cmp.Diff(test.in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} - -func TestTopicConversionBetweenV1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1.Topic{}} - - tests := []struct { - name string - in *Topic - }{{ - name: "min configuration", - in: &Topic{ - ObjectMeta: metav1.ObjectMeta{ - Name: "topic-name", - Namespace: "topic-ns", - Generation: 17, - }, - Spec: TopicSpec{}, - }, - }, { - name: "hostname, no URL", - in: &Topic{ - ObjectMeta: gcptesting.CompleteObjectMeta, - Status: TopicStatus{ - AddressStatus: v1alpha1.AddressStatus{ - Address: &v1alpha1.Addressable{ - Hostname: "not-in-uri", - }, - }, - }, - }, - }, { - name: "full configuration", - in: completeTopic, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - // DeepCopy because we will edit it below. - in := test.in.DeepCopy() - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &Topic{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - - // Hostname exists in v1alpha1, but not in v1beta1, so it will not be present after - // the round-trip conversion. Compare it manually, then overwrite the output value - // so that the generic comparison later works. - if test.in.Status.Address != nil { - if wantHostname := test.in.Status.Address.Hostname; wantHostname != "" { - if gotHostname := got.Status.Address.URL.Host; wantHostname != gotHostname { - // Note that this assumes that if both a URL and a hostname are - // specified in the original, then they have the same value. - t.Errorf("Incorrect hostname, want %q, got %q", wantHostname, gotHostname) - } - got.Status.Address = test.in.Status.Address - } - } - // Make sure the Deprecated Condition is added to the Status after converted back to v1alpha1, - // We need to ignore the LastTransitionTime as it is set in real time when doing the comparison. - dc := got.Status.GetCondition(convert.DeprecatedType) - if dc == nil { - t.Errorf("ConvertFrom() should add a deprecated warning condition but it does not.") - } else if diff := cmp.Diff(*dc, convert.DeprecatedV1Alpha1Condition, - cmpopts.IgnoreFields(apis.Condition{}, "LastTransitionTime")); diff != "" { - t.Errorf("Failed to verify deprecated condition (-want, + got) = %v", diff) - } - // Remove the Deprecated Condition from Status to compare the remaining of fields. - cs := apis.NewLivingConditionSet() - cs.Manage(&got.Status).ClearCondition(convert.DeprecatedType) - - ignoreUsername := cmp.AllowUnexported(url.Userinfo{}) - // IdentityStatus.ServiceAccountName only exists in v1alpha1 and v1beta1, it doesn't exist in v1. - // So this won't be a round trip, it will be silently removed. - in.Status.ServiceAccountName = "" - if diff := cmp.Diff(in, got, ignoreUsername); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/intevents/v1alpha1/topic_defaults.go b/pkg/apis/intevents/v1alpha1/topic_defaults.go deleted file mode 100644 index 666b45a0d8..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_defaults.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - - "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - "github.com/google/knative-gcp/pkg/apis/duck" - metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" - - "github.com/google/knative-gcp/pkg/logging" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" -) - -var ( - trueVal = true -) - -func (t *Topic) SetDefaults(ctx context.Context) { - ctx = apis.WithinParent(ctx, t.ObjectMeta) - t.Spec.SetDefaults(ctx) - duck.SetClusterNameAnnotation(&t.ObjectMeta, metadataClient.NewDefaultMetadataClient()) -} - -func (ts *TopicSpec) SetDefaults(ctx context.Context) { - if ts.PropagationPolicy == "" { - ts.PropagationPolicy = TopicPolicyCreateNoDelete - } - - ad := gcpauth.FromContextOrDefaults(ctx).GCPAuthDefaults - if ad == nil { - // TODO This should probably error out, rather than silently allow in non-defaulted COs. - logging.FromContext(ctx).Error("Failed to get the GCPAuthDefaults") - return - } - if ts.ServiceAccountName == "" && - (ts.Secret == nil || equality.Semantic.DeepEqual(ts.Secret, &corev1.SecretKeySelector{})) { - ts.ServiceAccountName = ad.KSA(apis.ParentMeta(ctx).Namespace) - ts.Secret = ad.Secret(apis.ParentMeta(ctx).Namespace) - } - - if ts.EnablePublisher == nil { - ts.EnablePublisher = &trueVal - } -} diff --git a/pkg/apis/intevents/v1alpha1/topic_defaults_test.go b/pkg/apis/intevents/v1alpha1/topic_defaults_test.go deleted file mode 100644 index 39778d39d1..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_defaults_test.go +++ /dev/null @@ -1,92 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "github.com/google/knative-gcp/pkg/apis/duck" - testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestTopicDefaults(t *testing.T) { - testCases := map[string]struct { - want *Topic - got *Topic - ctx context.Context - }{ - "with GCP Auth": { - want: &Topic{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: TopicSpec{ - PropagationPolicy: TopicPolicyCreateNoDelete, - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "google-cloud-key", - }, - Key: "key.json", - }, - EnablePublisher: &trueVal, - }}, - got: &Topic{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: TopicSpec{}}, - ctx: gcpauthtesthelper.ContextWithDefaults(), - }, - "without GCP Auth": { - want: &Topic{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - Spec: TopicSpec{ - PropagationPolicy: TopicPolicyCreateNoDelete}, - }, - got: &Topic{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }, - }, - }, - ctx: context.Background(), - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - tc.got.SetDefaults(tc.ctx) - if diff := cmp.Diff(tc.want, tc.got); diff != "" { - t.Errorf("Unexpected differences (-want +got): %v", diff) - } - }) - } -} diff --git a/pkg/apis/intevents/v1alpha1/topic_lifecycle.go b/pkg/apis/intevents/v1alpha1/topic_lifecycle.go deleted file mode 100644 index 032b383e81..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_lifecycle.go +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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 v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck/v1alpha1" - v1 "knative.dev/serving/pkg/apis/serving/v1" -) - -// GetCondition returns the condition currently associated with the given type, -// or nil. -func (ts *TopicStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return topicCondSet.Manage(ts).GetCondition(t) -} - -// GetTopLevelCondition returns the top level condition -func (ts *TopicStatus) GetTopLevelCondition() *apis.Condition { - return topicCondSet.Manage(ts).GetTopLevelCondition() -} - -// IsReady returns true if the resource is ready overall. -func (ts *TopicStatus) IsReady() bool { - return topicCondSet.Manage(ts).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (ts *TopicStatus) InitializeConditions() { - topicCondSet.Manage(ts).InitializeConditions() -} - -// TODO: Use the new beta duck types. -func (ts *TopicStatus) SetAddress(url *apis.URL) { - if ts.Address == nil { - ts.Address = &v1alpha1.Addressable{} - } - if url != nil { - ts.Address.Hostname = url.Host - ts.Address.URL = url - topicCondSet.Manage(ts).MarkTrue(TopicConditionAddressable) - } else { - ts.Address.Hostname = "" - ts.Address.URL = nil - topicCondSet.Manage(ts).MarkFalse(TopicConditionAddressable, "emptyUrl", "url is the empty string") - // The TopicConditionAddressable is not included in the ready set as we don't want to create Publishers for Sources. - // We therefore need to set the ConditionReady to false here. - topicCondSet.Manage(ts).MarkFalse(apis.ConditionReady, "emptyUrl", "url is the empty string") - - } -} - -func (ts *TopicStatus) PropagatePublisherStatus(ss *v1.ServiceStatus) { - sc := ss.GetCondition(apis.ConditionReady) - if sc == nil { - ts.MarkPublisherNotConfigured() - return - } - - switch { - case sc.Status == corev1.ConditionUnknown: - ts.MarkPublisherUnknown(sc.Reason, sc.Message) - case sc.Status == corev1.ConditionTrue: - ts.SetAddress(ss.Address.URL) - ts.MarkPublisherDeployed() - case sc.Status == corev1.ConditionFalse: - ts.MarkPublisherNotDeployed(sc.Reason, sc.Message) - default: - ts.MarkPublisherUnknown("TopicUnknown", "The status of Topic is invalid: %v", sc.Status) - } -} - -// MarkPublisherDeployed sets the condition that the publisher has been deployed. -func (ts *TopicStatus) MarkPublisherDeployed() { - topicCondSet.Manage(ts).MarkTrue(TopicConditionPublisherReady) -} - -// MarkPublisherUnknown sets the condition that the status of publisher is Unknown. -func (ts *TopicStatus) MarkPublisherUnknown(reason, messageFormat string, messageA ...interface{}) { - topicCondSet.Manage(ts).MarkUnknown(TopicConditionPublisherReady, reason, messageFormat, messageA...) - // The TopicConditionPublisherReady is not included in the ready set as we don't want to create Publishers for Sources. - // We therefore need to set the ConditionReady to unknown here. - topicCondSet.Manage(ts).MarkUnknown(apis.ConditionReady, reason, messageFormat, messageA...) -} - -// MarkPublisherNotDeployed sets the condition that the publisher has not been deployed. -func (ts *TopicStatus) MarkPublisherNotDeployed(reason, messageFormat string, messageA ...interface{}) { - topicCondSet.Manage(ts).MarkFalse(TopicConditionPublisherReady, reason, messageFormat, messageA...) - // The TopicConditionPublisherReady is not included in the ready set as we don't want to create Publishers for Sources. - // We therefore need to set the ConditionReady to false here. - topicCondSet.Manage(ts).MarkFalse(apis.ConditionReady, reason, messageFormat, messageA...) -} - -// MarkPublisherNotConfigured changes the PublisherReady condition to be unknown to reflect -// that the Publisher does not yet have a Status. -func (ts *TopicStatus) MarkPublisherNotConfigured() { - topicCondSet.Manage(ts).MarkUnknown(TopicConditionPublisherReady, "PublisherNotConfigured", "Publisher has not yet been reconciled") - // The TopicConditionPublisherReady is not included in the ready set as we don't want to create Publishers for Sources. - // We therefore need to set the ConditionReady to unknown here. - topicCondSet.Manage(ts).MarkUnknown(apis.ConditionReady, "PublisherNotConfigured", "Publisher has not yet been reconciled") -} - -// MarkTopicReady sets the condition that the topic has been created. -func (ts *TopicStatus) MarkTopicReady() { - topicCondSet.Manage(ts).MarkTrue(TopicConditionTopicExists) -} - -// MarkNoTopic sets the condition that signals there is not a topic for this -// Topic. This could be because of an error or the Topic is being deleted. -func (ts *TopicStatus) MarkNoTopic(reason, messageFormat string, messageA ...interface{}) { - topicCondSet.Manage(ts).MarkFalse(TopicConditionTopicExists, reason, messageFormat, messageA...) -} diff --git a/pkg/apis/intevents/v1alpha1/topic_lifecycle_test.go b/pkg/apis/intevents/v1alpha1/topic_lifecycle_test.go deleted file mode 100644 index 0d6878b363..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_lifecycle_test.go +++ /dev/null @@ -1,211 +0,0 @@ -/* -Copyright 2019 Google LLC - -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/google/go-cmp/cmp/cmpopts" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" -) - -func TestTopicStatusIsReady(t *testing.T) { - tests := []struct { - name string - s *TopicStatus - wantConditionStatus corev1.ConditionStatus - want bool - }{{ - name: "uninitialized", - s: &TopicStatus{}, - want: false, - }, { - name: "initialized", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "mark deployed", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - s.MarkPublisherDeployed() - return s - }(), - wantConditionStatus: corev1.ConditionUnknown, - want: false, - }, { - name: "mark addressable", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - s.MarkTopicReady() - s.MarkPublisherDeployed() - s.SetAddress(&apis.URL{}) - return s - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }, { - name: "mark nil addressable", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - s.MarkTopicReady() - s.MarkPublisherDeployed() - s.SetAddress(nil) - return s - }(), - wantConditionStatus: corev1.ConditionFalse, - want: false, - }, { - name: "mark not deployed then deployed", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - s.MarkTopicReady() - s.SetAddress(&apis.URL{}) - s.MarkPublisherNotDeployed("MarkNotDeployed", "") - s.MarkPublisherDeployed() - return s - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }, { - name: "mark topic ready", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - s.MarkTopicReady() - return s - }(), - wantConditionStatus: corev1.ConditionTrue, - want: true, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - if test.wantConditionStatus != "" { - gotConditionStatus := test.s.GetTopLevelCondition().Status - if gotConditionStatus != test.wantConditionStatus { - t.Errorf("unexpected condition status: want %v, got %v", test.wantConditionStatus, gotConditionStatus) - } - } - got := test.s.IsReady() - if got != test.want { - t.Errorf("unexpected readiness: want %v, got %v", test.want, got) - } - }) - } -} - -func TestTopicStatusGetCondition(t *testing.T) { - tests := []struct { - name string - s *TopicStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "uninitialized", - s: &TopicStatus{}, - condQuery: TopicConditionReady, - want: nil, - }, { - name: "initialized", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - return s - }(), - condQuery: TopicConditionReady, - want: &apis.Condition{ - Type: TopicConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark deployed", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - s.MarkPublisherDeployed() - return s - }(), - condQuery: TopicConditionReady, - want: &apis.Condition{ - Type: TopicConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark topic ready", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - s.MarkTopicReady() - return s - }(), - condQuery: TopicConditionTopicExists, - want: &apis.Condition{ - Type: TopicConditionTopicExists, - Status: corev1.ConditionTrue, - }, - }, { - name: "mark topic ready condition ready", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - s.MarkTopicReady() - return s - }(), - condQuery: apis.ConditionReady, - want: &apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionTrue, - }, - }, { - name: "mark no topic", - s: func() *TopicStatus { - s := &TopicStatus{} - s.InitializeConditions() - s.MarkNoTopic("reason", "%s", "message") - return s - }(), - condQuery: TopicConditionTopicExists, - want: &apis.Condition{ - Type: TopicConditionTopicExists, - Status: corev1.ConditionFalse, - Reason: "reason", - Message: "message", - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.s.GetCondition(test.condQuery) - ignoreTime := cmpopts.IgnoreFields(apis.Condition{}, - "LastTransitionTime", "Severity") - if diff := cmp.Diff(test.want, got, ignoreTime); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/intevents/v1alpha1/topic_types.go b/pkg/apis/intevents/v1alpha1/topic_types.go deleted file mode 100644 index 030777b5a3..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_types.go +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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 v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck" - duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - "knative.dev/pkg/webhook/resourcesemantics" - - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// Topic is a resource representing a Topic backed by Google Cloud Pub/Sub. -type Topic struct { - metav1.TypeMeta `json:",inline"` - // +optional - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Spec defines the desired state of the Topic. - Spec TopicSpec `json:"spec,omitempty"` - - // Status represents the current state of the Topic. This data may be out of - // date. - // +optional - Status TopicStatus `json:"status,omitempty"` -} - -// Check that PullSubscription can be converted to other versions. -var _ apis.Convertible = (*Topic)(nil) - -// Check that Topic can be validated, can be defaulted, and has immutable fields. -var _ runtime.Object = (*Topic)(nil) -var _ resourcesemantics.GenericCRD = (*Topic)(nil) - -// Check that Topic implements the Conditions duck type. -var _ = duck.VerifyType(&Topic{}, &duckv1.Conditions{}) - -// TopicSpec defines parameters for creating or publishing to a Cloud Pub/Sub -// Topic depending on the PropagationPolicy. -type TopicSpec struct { - v1alpha1.IdentitySpec `json:",inline"` - - // Secret is the credential to be used to create and publish into the - // Cloud Pub/Sub Topic. The value of the secret entry must be a service - // account key in the JSON format - // (see https://cloud.google.com/iam/docs/creating-managing-service-account-keys). - Secret *corev1.SecretKeySelector `json:"secret,omitempty"` - - // Project is the ID of the Google Cloud Project that the Pub/Sub - // Topic will be created in or used from. - Project string `json:"project,omitempty"` - - // Topic is the ID of the Topic to create/use in Google Cloud Pub/Sub. - Topic string `json:"topic,omitempty"` - - //PropagationPolicy defines how Topic controls the Cloud Pub/Sub topic for - // lifecycle changes. Defaults to TopicPolicyCreateNoDelete if empty. - PropagationPolicy PropagationPolicyType `json:"propagationPolicy,omitempty"` - - // EnablePublisher controls the creation of an HTTP publisher endpoint. If set to true, then - // a publisher will be created and this Topic will be Addressable (have status.address). If set - // to false, then no publisher will be created and this custom object represents the creation - // and deletion of a GCP Pub/Sub Topic only. - // Defaults to true. - // +optional - EnablePublisher *bool `json:"publisher,omitempty"` -} - -// PropagationPolicyType defines enum type for TopicPolicy -type PropagationPolicyType string - -const ( - // TopicPolicyCreateDelete defines the Cloud Pub/Sub topic management - // policy for creating topic (if not present), and deleting topic when the - // Topic resource is deleted. - TopicPolicyCreateDelete PropagationPolicyType = "CreateDelete" - - // TopicPolicyCreateNoDelete defines the Cloud Pub/Sub topic management - // policy for creating topic (if not present), and not deleting topic when - // the Topic resource is deleted. - TopicPolicyCreateNoDelete PropagationPolicyType = "CreateNoDelete" - - // TopicPolicyNoCreateNoDelete defines the Cloud Pub/Sub topic - // management policy for only using existing topics, and not deleting - // topic when the Topic resource is deleted. - TopicPolicyNoCreateNoDelete PropagationPolicyType = "NoCreateNoDelete" -) - -var topicCondSet = apis.NewLivingConditionSet( - TopicConditionTopicExists, -) - -const ( - // TopicConditionReady has status True when all subconditions below have - // been set to True. - TopicConditionReady = apis.ConditionReady - - // TopicConditionAddressable has status true when this Topic meets the - // Addressable contract and has a non-empty hostname. - TopicConditionAddressable apis.ConditionType = "Addressable" - - // TopicConditionTopicExists has status True when the Topic has had a - // Pub/Sub topic created for it. - TopicConditionTopicExists apis.ConditionType = "TopicExists" - - // TopicConditionPublisherReady has status True when the Topic has had - // its publisher deployment created and ready. - TopicConditionPublisherReady apis.ConditionType = "PublisherReady" -) - -// TopicStatus represents the current state of a Topic. -type TopicStatus struct { - v1alpha1.IdentityStatus `json:",inline"` - - // Topic is Addressable. It currently exposes the endpoint as a - // fully-qualified DNS name which will distribute traffic over the - // provided targets from inside the cluster. - // - // It generally has the form {Topic}.{namespace}.svc.{cluster domain name} - duckv1alpha1.AddressStatus `json:",inline"` - - // ProjectID is the resolved project ID in use by the Topic. - // +optional - ProjectID string `json:"projectId,omitempty"` - - // TopicID is the created topic ID used by the Topic. - // +optional - TopicID string `json:"topicId,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// TopicList is a collection of Pub/Sub backed Topics. -type TopicList struct { - metav1.TypeMeta `json:",inline"` - // +optional - metav1.ListMeta `json:"metadata,omitempty"` - Items []Topic `json:"items"` -} - -// GetGroupVersionKind returns GroupVersionKind for Pub/Sub backed Topic. -func (t *Topic) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("Topic") -} - -// Methods for identifiable interface. -// IdentitySpec returns the IdentitySpec portion of the Spec. -func (s *Topic) IdentitySpec() *v1alpha1.IdentitySpec { - return &s.Spec.IdentitySpec -} - -// IdentityStatus returns the IdentityStatus portion of the Status. -func (s *Topic) IdentityStatus() *v1alpha1.IdentityStatus { - return &s.Status.IdentityStatus -} - -// ConditionSet returns the apis.ConditionSet of the embedding object -func (ps *Topic) ConditionSet() *apis.ConditionSet { - return &topicCondSet -} diff --git a/pkg/apis/intevents/v1alpha1/topic_types_test.go b/pkg/apis/intevents/v1alpha1/topic_types_test.go deleted file mode 100644 index 1c232106bc..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_types_test.go +++ /dev/null @@ -1,93 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" -) - -func TestTopicGetGroupVersionKind(t *testing.T) { - want := schema.GroupVersionKind{ - Group: "internal.events.cloud.google.com", - Version: "v1alpha1", - Kind: "Topic", - } - - p := &Topic{} - got := p.GetGroupVersionKind() - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestTopicIdentitySpec(t *testing.T) { - s := &Topic{ - Spec: TopicSpec{ - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "test", - }, - }, - } - want := "test" - got := s.IdentitySpec().ServiceAccountName - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestTopicIdentityStatus(t *testing.T) { - s := &Topic{ - Status: TopicStatus{ - IdentityStatus: v1alpha1.IdentityStatus{}, - }, - } - want := &v1alpha1.IdentityStatus{} - got := s.IdentityStatus() - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} - -func TestTopicConditionSet(t *testing.T) { - want := []apis.Condition{{ - Type: TopicConditionTopicExists, - }, { - Type: apis.ConditionReady, - }} - c := &Topic{} - - c.ConditionSet().Manage(&c.Status).InitializeConditions() - var got []apis.Condition = c.Status.GetConditions() - - compareConditionTypes := cmp.Transformer("ConditionType", func(c apis.Condition) apis.ConditionType { - return c.Type - }) - sortConditionTypes := cmpopts.SortSlices(func(a, b apis.Condition) bool { - return a.Type < b.Type - }) - if diff := cmp.Diff(want, got, sortConditionTypes, compareConditionTypes); diff != "" { - t.Errorf("failed to get expected (-want, +got) = %v", diff) - } -} diff --git a/pkg/apis/intevents/v1alpha1/topic_validation.go b/pkg/apis/intevents/v1alpha1/topic_validation.go deleted file mode 100644 index 197a9d94b7..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_validation.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/google/knative-gcp/pkg/apis/duck" - - "knative.dev/pkg/apis" -) - -func (t *Topic) Validate(ctx context.Context) *apis.FieldError { - err := t.Spec.Validate(ctx).ViaField("spec") - - if apis.IsInUpdate(ctx) { - original := apis.GetBaseline(ctx).(*Topic) - err = err.Also(t.CheckImmutableFields(ctx, original)) - } - return err -} - -func (ts *TopicSpec) Validate(ctx context.Context) *apis.FieldError { - var errs *apis.FieldError - - if ts.Topic == "" { - errs = errs.Also( - apis.ErrMissingField("topic"), - ) - } - - switch ts.PropagationPolicy { - case TopicPolicyCreateDelete, TopicPolicyCreateNoDelete, TopicPolicyNoCreateNoDelete: - // Valid value. - - default: - errs = errs.Also( - apis.ErrInvalidValue(ts.PropagationPolicy, "propagationPolicy"), - ) - } - - return errs -} - -func (current *Topic) CheckImmutableFields(ctx context.Context, original *Topic) *apis.FieldError { - if original == nil { - return nil - } - - var errs *apis.FieldError - // Modification of Topic, Secret, ServiceAccountName, PropagationPolicy, EnablePublisher and Project are not allowed. - if diff := cmp.Diff(original.Spec, current.Spec, - cmpopts.IgnoreFields(TopicSpec{})); diff != "" { - errs = errs.Also(&apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - }) - } - // Modification of AutoscalingClassAnnotations is not allowed. - errs = duck.CheckImmutableAutoscalingClassAnnotations(¤t.ObjectMeta, &original.ObjectMeta, errs) - - // Modification of non-empty cluster name annotation is not allowed. - return duck.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) -} diff --git a/pkg/apis/intevents/v1alpha1/topic_validation_test.go b/pkg/apis/intevents/v1alpha1/topic_validation_test.go deleted file mode 100644 index a861745276..0000000000 --- a/pkg/apis/intevents/v1alpha1/topic_validation_test.go +++ /dev/null @@ -1,294 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - "strings" - "testing" - - "knative.dev/pkg/ptr" - - corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/webhook/resourcesemantics" - - "github.com/google/knative-gcp/pkg/apis/duck" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" -) - -var ( - topicSpec = TopicSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key", - }, - Project: "my-eventing-project", - Topic: "pubsub-topic", - PropagationPolicy: TopicPolicyCreateDelete, - EnablePublisher: ptr.Bool(true), - } - - topicSpecWithKSA = TopicSpec{ - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "old-service-account", - }, - Project: "my-eventing-project", - Topic: "pubsub-topic", - } -) - -func TestTopicValidation(t *testing.T) { - tests := []struct { - name string - cr resourcesemantics.GenericCRD - want []string - }{{ - name: "empty", - cr: &Topic{ - Spec: TopicSpec{}, - }, - want: []string{ - "spec.propagationPolicy", - "spec.topic", - }, - }, { - name: "min", - cr: &Topic{ - Spec: TopicSpec{ - Topic: "topic", - PropagationPolicy: TopicPolicyCreateNoDelete, - }, - }, - want: nil, - }, { - name: "invalid propagation policy", - cr: &Topic{ - Spec: TopicSpec{ - Topic: "topic", - PropagationPolicy: "invalid-propagation-policy", - }, - }, - want: []string{ - "invalid value: invalid-propagation-policy: spec.propagationPolicy", - }, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.cr.Validate(context.TODO()) - - for _, v := range test.want { - if !strings.Contains(got.Error(), v) { - t.Errorf("%s: validate contains (want, got) = %v, %v", test.name, v, got.Error()) - } - } - }) - } -} - -func TestTopicCheckImmutableFields(t *testing.T) { - testCases := map[string]struct { - orig interface{} - updated TopicSpec - origAnnotation map[string]string - updatedAnnotation map[string]string - allowed bool - }{ - "nil orig": { - updated: topicSpec, - allowed: true, - }, - "ClusterName annotation changed": { - origAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", - }, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: false, - }, - "AnnotationClass annotation changed": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA + "new", - }, - allowed: false, - }, - "AnnotationClass annotation added": { - origAnnotation: map[string]string{}, - updatedAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - allowed: false, - }, - "AnnotationClass annotation deleted": { - origAnnotation: map[string]string{ - duck.AutoscalingClassAnnotation: duck.KEDA, - }, - updatedAnnotation: map[string]string{}, - allowed: false, - }, - "Topic changed": { - orig: &topicSpec, - updated: TopicSpec{ - Secret: topicSpec.Secret, - Project: topicSpec.Project, - Topic: "updated", - PropagationPolicy: topicSpec.PropagationPolicy, - EnablePublisher: topicSpec.EnablePublisher, - }, - allowed: false, - }, - "Project changed": { - orig: &topicSpec, - updated: TopicSpec{ - Secret: topicSpec.Secret, - Project: "new-project", - Topic: topicSpec.Topic, - PropagationPolicy: topicSpec.PropagationPolicy, - EnablePublisher: topicSpec.EnablePublisher, - }, - allowed: false, - }, - "PropagationPolicy changed": { - orig: &topicSpec, - updated: TopicSpec{ - Secret: topicSpec.Secret, - Project: "new-project", - Topic: topicSpec.Topic, - PropagationPolicy: TopicPolicyCreateNoDelete, - EnablePublisher: topicSpec.EnablePublisher, - }, - allowed: false, - }, - "EnablePublisher changed": { - orig: &topicSpec, - updated: TopicSpec{ - Secret: topicSpec.Secret, - Project: "new-project", - Topic: topicSpec.Topic, - PropagationPolicy: topicSpec.PropagationPolicy, - EnablePublisher: ptr.Bool(false), - }, - allowed: false, - }, - "Secret.Key changed": { - orig: &topicSpec, - updated: TopicSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: topicSpec.Secret.Name, - }, - Key: "some-other-key", - }, - Project: topicSpec.Project, - Topic: topicSpec.Topic, - PropagationPolicy: topicSpec.PropagationPolicy, - EnablePublisher: topicSpec.EnablePublisher, - }, - allowed: false, - }, - "Secret.Name changed": { - orig: &topicSpec, - updated: TopicSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "some-other-name", - }, - Key: topicSpec.Secret.Key, - }, - Project: topicSpec.Project, - Topic: topicSpec.Topic, - PropagationPolicy: topicSpec.PropagationPolicy, - EnablePublisher: topicSpec.EnablePublisher, - }, - allowed: false, - }, - "ServiceAccountName changed": { - orig: &topicSpecWithKSA, - updated: TopicSpec{ - Project: topicSpecWithKSA.Project, - Topic: topicSpecWithKSA.Topic, - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "new-service-account", - }, - }, - allowed: false, - }, - "ServiceAccountName added": { - orig: &topicSpec, - updated: TopicSpec{ - Secret: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: topicSpec.Secret.Name, - }, - Key: topicSpec.Secret.Key, - }, - Project: topicSpec.Project, - Topic: topicSpec.Topic, - PropagationPolicy: topicSpec.PropagationPolicy, - EnablePublisher: topicSpec.EnablePublisher, - IdentitySpec: v1alpha1.IdentitySpec{ - ServiceAccountName: "new-service-account", - }, - }, - allowed: false, - }, - "ClusterName annotation added": { - origAnnotation: nil, - updatedAnnotation: map[string]string{ - duck.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", - }, - allowed: true, - }, - } - - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - var orig *Topic - - if tc.origAnnotation != nil { - orig = &Topic{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.origAnnotation, - }, - } - } else if tc.orig != nil { - if spec, ok := tc.orig.(*TopicSpec); ok { - orig = &Topic{ - Spec: *spec, - } - } - } - updated := &Topic{ - ObjectMeta: v1.ObjectMeta{ - Annotations: tc.updatedAnnotation, - }, - Spec: tc.updated, - } - err := updated.CheckImmutableFields(context.TODO(), orig) - if tc.allowed != (err == nil) { - t.Fatalf("Unexpected immutable field check. Expected %v. Actual %v", tc.allowed, err) - } - }) - } -} diff --git a/pkg/apis/intevents/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/intevents/v1alpha1/zz_generated.deepcopy.go index 309728bf79..4a4f7dfec8 100644 --- a/pkg/apis/intevents/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/intevents/v1alpha1/zz_generated.deepcopy.go @@ -21,10 +21,7 @@ limitations under the License. package v1alpha1 import ( - corev1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" - apis "knative.dev/pkg/apis" - v1 "knative.dev/pkg/apis/duck/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -189,121 +186,6 @@ func (in *ComponentsParametersSpec) DeepCopy() *ComponentsParametersSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PullSubscription) DeepCopyInto(out *PullSubscription) { - *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 PullSubscription. -func (in *PullSubscription) DeepCopy() *PullSubscription { - if in == nil { - return nil - } - out := new(PullSubscription) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *PullSubscription) 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 *PullSubscriptionList) DeepCopyInto(out *PullSubscriptionList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]PullSubscription, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PullSubscriptionList. -func (in *PullSubscriptionList) DeepCopy() *PullSubscriptionList { - if in == nil { - return nil - } - out := new(PullSubscriptionList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *PullSubscriptionList) 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 *PullSubscriptionSpec) DeepCopyInto(out *PullSubscriptionSpec) { - *out = *in - in.PubSubSpec.DeepCopyInto(&out.PubSubSpec) - if in.AckDeadline != nil { - in, out := &in.AckDeadline, &out.AckDeadline - *out = new(string) - **out = **in - } - if in.RetentionDuration != nil { - in, out := &in.RetentionDuration, &out.RetentionDuration - *out = new(string) - **out = **in - } - if in.Transformer != nil { - in, out := &in.Transformer, &out.Transformer - *out = new(v1.Destination) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PullSubscriptionSpec. -func (in *PullSubscriptionSpec) DeepCopy() *PullSubscriptionSpec { - if in == nil { - return nil - } - out := new(PullSubscriptionSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PullSubscriptionStatus) DeepCopyInto(out *PullSubscriptionStatus) { - *out = *in - in.PubSubStatus.DeepCopyInto(&out.PubSubStatus) - if in.TransformerURI != nil { - in, out := &in.TransformerURI, &out.TransformerURI - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PullSubscriptionStatus. -func (in *PullSubscriptionStatus) DeepCopy() *PullSubscriptionStatus { - if in == nil { - return nil - } - out := new(PullSubscriptionStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResourceSpecification) DeepCopyInto(out *ResourceSpecification) { *out = *in @@ -337,109 +219,3 @@ func (in *SystemResource) DeepCopy() *SystemResource { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Topic) DeepCopyInto(out *Topic) { - *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 Topic. -func (in *Topic) DeepCopy() *Topic { - if in == nil { - return nil - } - out := new(Topic) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Topic) 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 *TopicList) DeepCopyInto(out *TopicList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Topic, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TopicList. -func (in *TopicList) DeepCopy() *TopicList { - if in == nil { - return nil - } - out := new(TopicList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TopicList) 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 *TopicSpec) DeepCopyInto(out *TopicSpec) { - *out = *in - out.IdentitySpec = in.IdentitySpec - if in.Secret != nil { - in, out := &in.Secret, &out.Secret - *out = new(corev1.SecretKeySelector) - (*in).DeepCopyInto(*out) - } - if in.EnablePublisher != nil { - in, out := &in.EnablePublisher, &out.EnablePublisher - *out = new(bool) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TopicSpec. -func (in *TopicSpec) DeepCopy() *TopicSpec { - if in == nil { - return nil - } - out := new(TopicSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TopicStatus) DeepCopyInto(out *TopicStatus) { - *out = *in - in.IdentityStatus.DeepCopyInto(&out.IdentityStatus) - in.AddressStatus.DeepCopyInto(&out.AddressStatus) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TopicStatus. -func (in *TopicStatus) DeepCopy() *TopicStatus { - if in == nil { - return nil - } - out := new(TopicStatus) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/apis/intevents/v1beta1/pullsubscription_conversion.go b/pkg/apis/intevents/v1beta1/pullsubscription_conversion.go index bb599cfc7d..0ccb9c7020 100644 --- a/pkg/apis/intevents/v1beta1/pullsubscription_conversion.go +++ b/pkg/apis/intevents/v1beta1/pullsubscription_conversion.go @@ -26,7 +26,7 @@ import ( ) // ConvertTo implements apis.Convertible. -// Converts v1alpha1.PullSubscription to a higher version of PullSubscription. +// Converts v1beta1.PullSubscription to a higher version of PullSubscription. // Currently, we only support v1 as a higher version. func (source *PullSubscription) ConvertTo(ctx context.Context, to apis.Convertible) error { switch sink := to.(type) { diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index b2d738d53f..7e95197a2f 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -23,7 +23,6 @@ import ( eventingv1beta1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/broker/v1beta1" eventsv1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1" - eventsv1alpha1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1alpha1" eventsv1beta1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1beta1" internalv1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1" internalv1alpha1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1alpha1" @@ -37,7 +36,6 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface EventingV1beta1() eventingv1beta1.EventingV1beta1Interface - EventsV1alpha1() eventsv1alpha1.EventsV1alpha1Interface EventsV1beta1() eventsv1beta1.EventsV1beta1Interface EventsV1() eventsv1.EventsV1Interface InternalV1alpha1() internalv1alpha1.InternalV1alpha1Interface @@ -51,7 +49,6 @@ type Interface interface { type Clientset struct { *discovery.DiscoveryClient eventingV1beta1 *eventingv1beta1.EventingV1beta1Client - eventsV1alpha1 *eventsv1alpha1.EventsV1alpha1Client eventsV1beta1 *eventsv1beta1.EventsV1beta1Client eventsV1 *eventsv1.EventsV1Client internalV1alpha1 *internalv1alpha1.InternalV1alpha1Client @@ -65,11 +62,6 @@ func (c *Clientset) EventingV1beta1() eventingv1beta1.EventingV1beta1Interface { return c.eventingV1beta1 } -// EventsV1alpha1 retrieves the EventsV1alpha1Client -func (c *Clientset) EventsV1alpha1() eventsv1alpha1.EventsV1alpha1Interface { - return c.eventsV1alpha1 -} - // EventsV1beta1 retrieves the EventsV1beta1Client func (c *Clientset) EventsV1beta1() eventsv1beta1.EventsV1beta1Interface { return c.eventsV1beta1 @@ -125,10 +117,6 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { if err != nil { return nil, err } - cs.eventsV1alpha1, err = eventsv1alpha1.NewForConfig(&configShallowCopy) - if err != nil { - return nil, err - } cs.eventsV1beta1, err = eventsv1beta1.NewForConfig(&configShallowCopy) if err != nil { return nil, err @@ -166,7 +154,6 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { func NewForConfigOrDie(c *rest.Config) *Clientset { var cs Clientset cs.eventingV1beta1 = eventingv1beta1.NewForConfigOrDie(c) - cs.eventsV1alpha1 = eventsv1alpha1.NewForConfigOrDie(c) cs.eventsV1beta1 = eventsv1beta1.NewForConfigOrDie(c) cs.eventsV1 = eventsv1.NewForConfigOrDie(c) cs.internalV1alpha1 = internalv1alpha1.NewForConfigOrDie(c) @@ -182,7 +169,6 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { func New(c rest.Interface) *Clientset { var cs Clientset cs.eventingV1beta1 = eventingv1beta1.New(c) - cs.eventsV1alpha1 = eventsv1alpha1.New(c) cs.eventsV1beta1 = eventsv1beta1.New(c) cs.eventsV1 = eventsv1.New(c) cs.internalV1alpha1 = internalv1alpha1.New(c) diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index a2a94753a1..69381d8f49 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -24,8 +24,6 @@ import ( fakeeventingv1beta1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/broker/v1beta1/fake" eventsv1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1" fakeeventsv1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1/fake" - eventsv1alpha1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1alpha1" - fakeeventsv1alpha1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1alpha1/fake" eventsv1beta1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1beta1" fakeeventsv1beta1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1beta1/fake" internalv1 "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1" @@ -95,11 +93,6 @@ func (c *Clientset) EventingV1beta1() eventingv1beta1.EventingV1beta1Interface { return &fakeeventingv1beta1.FakeEventingV1beta1{Fake: &c.Fake} } -// EventsV1alpha1 retrieves the EventsV1alpha1Client -func (c *Clientset) EventsV1alpha1() eventsv1alpha1.EventsV1alpha1Interface { - return &fakeeventsv1alpha1.FakeEventsV1alpha1{Fake: &c.Fake} -} - // EventsV1beta1 retrieves the EventsV1beta1Client func (c *Clientset) EventsV1beta1() eventsv1beta1.EventsV1beta1Interface { return &fakeeventsv1beta1.FakeEventsV1beta1{Fake: &c.Fake} diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index bb064b765e..d4f2d33934 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -21,7 +21,6 @@ package fake import ( eventingv1beta1 "github.com/google/knative-gcp/pkg/apis/broker/v1beta1" eventsv1 "github.com/google/knative-gcp/pkg/apis/events/v1" - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" eventsv1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" internalv1 "github.com/google/knative-gcp/pkg/apis/intevents/v1" internalv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" @@ -39,7 +38,6 @@ var codecs = serializer.NewCodecFactory(scheme) var parameterCodec = runtime.NewParameterCodec(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ eventingv1beta1.AddToScheme, - eventsv1alpha1.AddToScheme, eventsv1beta1.AddToScheme, eventsv1.AddToScheme, internalv1alpha1.AddToScheme, diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 83fc83bcab..ec2594c865 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -21,7 +21,6 @@ package scheme import ( eventingv1beta1 "github.com/google/knative-gcp/pkg/apis/broker/v1beta1" eventsv1 "github.com/google/knative-gcp/pkg/apis/events/v1" - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" eventsv1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" internalv1 "github.com/google/knative-gcp/pkg/apis/intevents/v1" internalv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" @@ -39,7 +38,6 @@ var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ eventingv1beta1.AddToScheme, - eventsv1alpha1.AddToScheme, eventsv1beta1.AddToScheme, eventsv1.AddToScheme, internalv1alpha1.AddToScheme, diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudauditlogssource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudauditlogssource.go deleted file mode 100644 index b60a4d78ff..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudauditlogssource.go +++ /dev/null @@ -1,195 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "time" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - scheme "github.com/google/knative-gcp/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" -) - -// CloudAuditLogsSourcesGetter has a method to return a CloudAuditLogsSourceInterface. -// A group's client should implement this interface. -type CloudAuditLogsSourcesGetter interface { - CloudAuditLogsSources(namespace string) CloudAuditLogsSourceInterface -} - -// CloudAuditLogsSourceInterface has methods to work with CloudAuditLogsSource resources. -type CloudAuditLogsSourceInterface interface { - Create(ctx context.Context, cloudAuditLogsSource *v1alpha1.CloudAuditLogsSource, opts v1.CreateOptions) (*v1alpha1.CloudAuditLogsSource, error) - Update(ctx context.Context, cloudAuditLogsSource *v1alpha1.CloudAuditLogsSource, opts v1.UpdateOptions) (*v1alpha1.CloudAuditLogsSource, error) - UpdateStatus(ctx context.Context, cloudAuditLogsSource *v1alpha1.CloudAuditLogsSource, opts v1.UpdateOptions) (*v1alpha1.CloudAuditLogsSource, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.CloudAuditLogsSource, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.CloudAuditLogsSourceList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudAuditLogsSource, err error) - CloudAuditLogsSourceExpansion -} - -// cloudAuditLogsSources implements CloudAuditLogsSourceInterface -type cloudAuditLogsSources struct { - client rest.Interface - ns string -} - -// newCloudAuditLogsSources returns a CloudAuditLogsSources -func newCloudAuditLogsSources(c *EventsV1alpha1Client, namespace string) *cloudAuditLogsSources { - return &cloudAuditLogsSources{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the cloudAuditLogsSource, and returns the corresponding cloudAuditLogsSource object, and an error if there is any. -func (c *cloudAuditLogsSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudAuditLogsSource, err error) { - result = &v1alpha1.CloudAuditLogsSource{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudauditlogssources"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of CloudAuditLogsSources that match those selectors. -func (c *cloudAuditLogsSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudAuditLogsSourceList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.CloudAuditLogsSourceList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudauditlogssources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested cloudAuditLogsSources. -func (c *cloudAuditLogsSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("cloudauditlogssources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a cloudAuditLogsSource and creates it. Returns the server's representation of the cloudAuditLogsSource, and an error, if there is any. -func (c *cloudAuditLogsSources) Create(ctx context.Context, cloudAuditLogsSource *v1alpha1.CloudAuditLogsSource, opts v1.CreateOptions) (result *v1alpha1.CloudAuditLogsSource, err error) { - result = &v1alpha1.CloudAuditLogsSource{} - err = c.client.Post(). - Namespace(c.ns). - Resource("cloudauditlogssources"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudAuditLogsSource). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a cloudAuditLogsSource and updates it. Returns the server's representation of the cloudAuditLogsSource, and an error, if there is any. -func (c *cloudAuditLogsSources) Update(ctx context.Context, cloudAuditLogsSource *v1alpha1.CloudAuditLogsSource, opts v1.UpdateOptions) (result *v1alpha1.CloudAuditLogsSource, err error) { - result = &v1alpha1.CloudAuditLogsSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudauditlogssources"). - Name(cloudAuditLogsSource.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudAuditLogsSource). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *cloudAuditLogsSources) UpdateStatus(ctx context.Context, cloudAuditLogsSource *v1alpha1.CloudAuditLogsSource, opts v1.UpdateOptions) (result *v1alpha1.CloudAuditLogsSource, err error) { - result = &v1alpha1.CloudAuditLogsSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudauditlogssources"). - Name(cloudAuditLogsSource.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudAuditLogsSource). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the cloudAuditLogsSource and deletes it. Returns an error if one occurs. -func (c *cloudAuditLogsSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudauditlogssources"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *cloudAuditLogsSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudauditlogssources"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched cloudAuditLogsSource. -func (c *cloudAuditLogsSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudAuditLogsSource, err error) { - result = &v1alpha1.CloudAuditLogsSource{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("cloudauditlogssources"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudbuildsource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudbuildsource.go deleted file mode 100644 index 356b65617d..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudbuildsource.go +++ /dev/null @@ -1,195 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "time" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - scheme "github.com/google/knative-gcp/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" -) - -// CloudBuildSourcesGetter has a method to return a CloudBuildSourceInterface. -// A group's client should implement this interface. -type CloudBuildSourcesGetter interface { - CloudBuildSources(namespace string) CloudBuildSourceInterface -} - -// CloudBuildSourceInterface has methods to work with CloudBuildSource resources. -type CloudBuildSourceInterface interface { - Create(ctx context.Context, cloudBuildSource *v1alpha1.CloudBuildSource, opts v1.CreateOptions) (*v1alpha1.CloudBuildSource, error) - Update(ctx context.Context, cloudBuildSource *v1alpha1.CloudBuildSource, opts v1.UpdateOptions) (*v1alpha1.CloudBuildSource, error) - UpdateStatus(ctx context.Context, cloudBuildSource *v1alpha1.CloudBuildSource, opts v1.UpdateOptions) (*v1alpha1.CloudBuildSource, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.CloudBuildSource, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.CloudBuildSourceList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudBuildSource, err error) - CloudBuildSourceExpansion -} - -// cloudBuildSources implements CloudBuildSourceInterface -type cloudBuildSources struct { - client rest.Interface - ns string -} - -// newCloudBuildSources returns a CloudBuildSources -func newCloudBuildSources(c *EventsV1alpha1Client, namespace string) *cloudBuildSources { - return &cloudBuildSources{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the cloudBuildSource, and returns the corresponding cloudBuildSource object, and an error if there is any. -func (c *cloudBuildSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudBuildSource, err error) { - result = &v1alpha1.CloudBuildSource{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudbuildsources"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of CloudBuildSources that match those selectors. -func (c *cloudBuildSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudBuildSourceList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.CloudBuildSourceList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudbuildsources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested cloudBuildSources. -func (c *cloudBuildSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("cloudbuildsources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a cloudBuildSource and creates it. Returns the server's representation of the cloudBuildSource, and an error, if there is any. -func (c *cloudBuildSources) Create(ctx context.Context, cloudBuildSource *v1alpha1.CloudBuildSource, opts v1.CreateOptions) (result *v1alpha1.CloudBuildSource, err error) { - result = &v1alpha1.CloudBuildSource{} - err = c.client.Post(). - Namespace(c.ns). - Resource("cloudbuildsources"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudBuildSource). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a cloudBuildSource and updates it. Returns the server's representation of the cloudBuildSource, and an error, if there is any. -func (c *cloudBuildSources) Update(ctx context.Context, cloudBuildSource *v1alpha1.CloudBuildSource, opts v1.UpdateOptions) (result *v1alpha1.CloudBuildSource, err error) { - result = &v1alpha1.CloudBuildSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudbuildsources"). - Name(cloudBuildSource.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudBuildSource). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *cloudBuildSources) UpdateStatus(ctx context.Context, cloudBuildSource *v1alpha1.CloudBuildSource, opts v1.UpdateOptions) (result *v1alpha1.CloudBuildSource, err error) { - result = &v1alpha1.CloudBuildSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudbuildsources"). - Name(cloudBuildSource.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudBuildSource). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the cloudBuildSource and deletes it. Returns an error if one occurs. -func (c *cloudBuildSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudbuildsources"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *cloudBuildSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudbuildsources"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched cloudBuildSource. -func (c *cloudBuildSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudBuildSource, err error) { - result = &v1alpha1.CloudBuildSource{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("cloudbuildsources"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudpubsubsource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudpubsubsource.go deleted file mode 100644 index e4f9a02785..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudpubsubsource.go +++ /dev/null @@ -1,195 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "time" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - scheme "github.com/google/knative-gcp/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" -) - -// CloudPubSubSourcesGetter has a method to return a CloudPubSubSourceInterface. -// A group's client should implement this interface. -type CloudPubSubSourcesGetter interface { - CloudPubSubSources(namespace string) CloudPubSubSourceInterface -} - -// CloudPubSubSourceInterface has methods to work with CloudPubSubSource resources. -type CloudPubSubSourceInterface interface { - Create(ctx context.Context, cloudPubSubSource *v1alpha1.CloudPubSubSource, opts v1.CreateOptions) (*v1alpha1.CloudPubSubSource, error) - Update(ctx context.Context, cloudPubSubSource *v1alpha1.CloudPubSubSource, opts v1.UpdateOptions) (*v1alpha1.CloudPubSubSource, error) - UpdateStatus(ctx context.Context, cloudPubSubSource *v1alpha1.CloudPubSubSource, opts v1.UpdateOptions) (*v1alpha1.CloudPubSubSource, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.CloudPubSubSource, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.CloudPubSubSourceList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudPubSubSource, err error) - CloudPubSubSourceExpansion -} - -// cloudPubSubSources implements CloudPubSubSourceInterface -type cloudPubSubSources struct { - client rest.Interface - ns string -} - -// newCloudPubSubSources returns a CloudPubSubSources -func newCloudPubSubSources(c *EventsV1alpha1Client, namespace string) *cloudPubSubSources { - return &cloudPubSubSources{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the cloudPubSubSource, and returns the corresponding cloudPubSubSource object, and an error if there is any. -func (c *cloudPubSubSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudPubSubSource, err error) { - result = &v1alpha1.CloudPubSubSource{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudpubsubsources"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of CloudPubSubSources that match those selectors. -func (c *cloudPubSubSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudPubSubSourceList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.CloudPubSubSourceList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudpubsubsources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested cloudPubSubSources. -func (c *cloudPubSubSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("cloudpubsubsources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a cloudPubSubSource and creates it. Returns the server's representation of the cloudPubSubSource, and an error, if there is any. -func (c *cloudPubSubSources) Create(ctx context.Context, cloudPubSubSource *v1alpha1.CloudPubSubSource, opts v1.CreateOptions) (result *v1alpha1.CloudPubSubSource, err error) { - result = &v1alpha1.CloudPubSubSource{} - err = c.client.Post(). - Namespace(c.ns). - Resource("cloudpubsubsources"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudPubSubSource). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a cloudPubSubSource and updates it. Returns the server's representation of the cloudPubSubSource, and an error, if there is any. -func (c *cloudPubSubSources) Update(ctx context.Context, cloudPubSubSource *v1alpha1.CloudPubSubSource, opts v1.UpdateOptions) (result *v1alpha1.CloudPubSubSource, err error) { - result = &v1alpha1.CloudPubSubSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudpubsubsources"). - Name(cloudPubSubSource.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudPubSubSource). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *cloudPubSubSources) UpdateStatus(ctx context.Context, cloudPubSubSource *v1alpha1.CloudPubSubSource, opts v1.UpdateOptions) (result *v1alpha1.CloudPubSubSource, err error) { - result = &v1alpha1.CloudPubSubSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudpubsubsources"). - Name(cloudPubSubSource.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudPubSubSource). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the cloudPubSubSource and deletes it. Returns an error if one occurs. -func (c *cloudPubSubSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudpubsubsources"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *cloudPubSubSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudpubsubsources"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched cloudPubSubSource. -func (c *cloudPubSubSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudPubSubSource, err error) { - result = &v1alpha1.CloudPubSubSource{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("cloudpubsubsources"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudschedulersource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudschedulersource.go deleted file mode 100644 index 7f7aa061c0..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudschedulersource.go +++ /dev/null @@ -1,195 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "time" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - scheme "github.com/google/knative-gcp/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" -) - -// CloudSchedulerSourcesGetter has a method to return a CloudSchedulerSourceInterface. -// A group's client should implement this interface. -type CloudSchedulerSourcesGetter interface { - CloudSchedulerSources(namespace string) CloudSchedulerSourceInterface -} - -// CloudSchedulerSourceInterface has methods to work with CloudSchedulerSource resources. -type CloudSchedulerSourceInterface interface { - Create(ctx context.Context, cloudSchedulerSource *v1alpha1.CloudSchedulerSource, opts v1.CreateOptions) (*v1alpha1.CloudSchedulerSource, error) - Update(ctx context.Context, cloudSchedulerSource *v1alpha1.CloudSchedulerSource, opts v1.UpdateOptions) (*v1alpha1.CloudSchedulerSource, error) - UpdateStatus(ctx context.Context, cloudSchedulerSource *v1alpha1.CloudSchedulerSource, opts v1.UpdateOptions) (*v1alpha1.CloudSchedulerSource, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.CloudSchedulerSource, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.CloudSchedulerSourceList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudSchedulerSource, err error) - CloudSchedulerSourceExpansion -} - -// cloudSchedulerSources implements CloudSchedulerSourceInterface -type cloudSchedulerSources struct { - client rest.Interface - ns string -} - -// newCloudSchedulerSources returns a CloudSchedulerSources -func newCloudSchedulerSources(c *EventsV1alpha1Client, namespace string) *cloudSchedulerSources { - return &cloudSchedulerSources{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the cloudSchedulerSource, and returns the corresponding cloudSchedulerSource object, and an error if there is any. -func (c *cloudSchedulerSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudSchedulerSource, err error) { - result = &v1alpha1.CloudSchedulerSource{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudschedulersources"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of CloudSchedulerSources that match those selectors. -func (c *cloudSchedulerSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudSchedulerSourceList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.CloudSchedulerSourceList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudschedulersources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested cloudSchedulerSources. -func (c *cloudSchedulerSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("cloudschedulersources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a cloudSchedulerSource and creates it. Returns the server's representation of the cloudSchedulerSource, and an error, if there is any. -func (c *cloudSchedulerSources) Create(ctx context.Context, cloudSchedulerSource *v1alpha1.CloudSchedulerSource, opts v1.CreateOptions) (result *v1alpha1.CloudSchedulerSource, err error) { - result = &v1alpha1.CloudSchedulerSource{} - err = c.client.Post(). - Namespace(c.ns). - Resource("cloudschedulersources"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudSchedulerSource). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a cloudSchedulerSource and updates it. Returns the server's representation of the cloudSchedulerSource, and an error, if there is any. -func (c *cloudSchedulerSources) Update(ctx context.Context, cloudSchedulerSource *v1alpha1.CloudSchedulerSource, opts v1.UpdateOptions) (result *v1alpha1.CloudSchedulerSource, err error) { - result = &v1alpha1.CloudSchedulerSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudschedulersources"). - Name(cloudSchedulerSource.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudSchedulerSource). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *cloudSchedulerSources) UpdateStatus(ctx context.Context, cloudSchedulerSource *v1alpha1.CloudSchedulerSource, opts v1.UpdateOptions) (result *v1alpha1.CloudSchedulerSource, err error) { - result = &v1alpha1.CloudSchedulerSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudschedulersources"). - Name(cloudSchedulerSource.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudSchedulerSource). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the cloudSchedulerSource and deletes it. Returns an error if one occurs. -func (c *cloudSchedulerSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudschedulersources"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *cloudSchedulerSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudschedulersources"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched cloudSchedulerSource. -func (c *cloudSchedulerSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudSchedulerSource, err error) { - result = &v1alpha1.CloudSchedulerSource{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("cloudschedulersources"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudstoragesource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudstoragesource.go deleted file mode 100644 index 71e3a2cbdd..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/cloudstoragesource.go +++ /dev/null @@ -1,195 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "time" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - scheme "github.com/google/knative-gcp/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" -) - -// CloudStorageSourcesGetter has a method to return a CloudStorageSourceInterface. -// A group's client should implement this interface. -type CloudStorageSourcesGetter interface { - CloudStorageSources(namespace string) CloudStorageSourceInterface -} - -// CloudStorageSourceInterface has methods to work with CloudStorageSource resources. -type CloudStorageSourceInterface interface { - Create(ctx context.Context, cloudStorageSource *v1alpha1.CloudStorageSource, opts v1.CreateOptions) (*v1alpha1.CloudStorageSource, error) - Update(ctx context.Context, cloudStorageSource *v1alpha1.CloudStorageSource, opts v1.UpdateOptions) (*v1alpha1.CloudStorageSource, error) - UpdateStatus(ctx context.Context, cloudStorageSource *v1alpha1.CloudStorageSource, opts v1.UpdateOptions) (*v1alpha1.CloudStorageSource, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.CloudStorageSource, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.CloudStorageSourceList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudStorageSource, err error) - CloudStorageSourceExpansion -} - -// cloudStorageSources implements CloudStorageSourceInterface -type cloudStorageSources struct { - client rest.Interface - ns string -} - -// newCloudStorageSources returns a CloudStorageSources -func newCloudStorageSources(c *EventsV1alpha1Client, namespace string) *cloudStorageSources { - return &cloudStorageSources{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the cloudStorageSource, and returns the corresponding cloudStorageSource object, and an error if there is any. -func (c *cloudStorageSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudStorageSource, err error) { - result = &v1alpha1.CloudStorageSource{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudstoragesources"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of CloudStorageSources that match those selectors. -func (c *cloudStorageSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudStorageSourceList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.CloudStorageSourceList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cloudstoragesources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested cloudStorageSources. -func (c *cloudStorageSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("cloudstoragesources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a cloudStorageSource and creates it. Returns the server's representation of the cloudStorageSource, and an error, if there is any. -func (c *cloudStorageSources) Create(ctx context.Context, cloudStorageSource *v1alpha1.CloudStorageSource, opts v1.CreateOptions) (result *v1alpha1.CloudStorageSource, err error) { - result = &v1alpha1.CloudStorageSource{} - err = c.client.Post(). - Namespace(c.ns). - Resource("cloudstoragesources"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudStorageSource). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a cloudStorageSource and updates it. Returns the server's representation of the cloudStorageSource, and an error, if there is any. -func (c *cloudStorageSources) Update(ctx context.Context, cloudStorageSource *v1alpha1.CloudStorageSource, opts v1.UpdateOptions) (result *v1alpha1.CloudStorageSource, err error) { - result = &v1alpha1.CloudStorageSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudstoragesources"). - Name(cloudStorageSource.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudStorageSource). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *cloudStorageSources) UpdateStatus(ctx context.Context, cloudStorageSource *v1alpha1.CloudStorageSource, opts v1.UpdateOptions) (result *v1alpha1.CloudStorageSource, err error) { - result = &v1alpha1.CloudStorageSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cloudstoragesources"). - Name(cloudStorageSource.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cloudStorageSource). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the cloudStorageSource and deletes it. Returns an error if one occurs. -func (c *cloudStorageSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudstoragesources"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *cloudStorageSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("cloudstoragesources"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched cloudStorageSource. -func (c *cloudStorageSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudStorageSource, err error) { - result = &v1alpha1.CloudStorageSource{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("cloudstoragesources"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/doc.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/doc.go deleted file mode 100644 index 97ff870da8..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2020 Google LLC - -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. - -// This package has the automatically generated typed clients. -package v1alpha1 diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/events_client.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/events_client.go deleted file mode 100644 index 17185b7302..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/events_client.go +++ /dev/null @@ -1,109 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/knative-gcp/pkg/apis/events/v1alpha1" - "github.com/google/knative-gcp/pkg/client/clientset/versioned/scheme" - rest "k8s.io/client-go/rest" -) - -type EventsV1alpha1Interface interface { - RESTClient() rest.Interface - CloudAuditLogsSourcesGetter - CloudBuildSourcesGetter - CloudPubSubSourcesGetter - CloudSchedulerSourcesGetter - CloudStorageSourcesGetter -} - -// EventsV1alpha1Client is used to interact with features provided by the events.cloud.google.com group. -type EventsV1alpha1Client struct { - restClient rest.Interface -} - -func (c *EventsV1alpha1Client) CloudAuditLogsSources(namespace string) CloudAuditLogsSourceInterface { - return newCloudAuditLogsSources(c, namespace) -} - -func (c *EventsV1alpha1Client) CloudBuildSources(namespace string) CloudBuildSourceInterface { - return newCloudBuildSources(c, namespace) -} - -func (c *EventsV1alpha1Client) CloudPubSubSources(namespace string) CloudPubSubSourceInterface { - return newCloudPubSubSources(c, namespace) -} - -func (c *EventsV1alpha1Client) CloudSchedulerSources(namespace string) CloudSchedulerSourceInterface { - return newCloudSchedulerSources(c, namespace) -} - -func (c *EventsV1alpha1Client) CloudStorageSources(namespace string) CloudStorageSourceInterface { - return newCloudStorageSources(c, namespace) -} - -// NewForConfig creates a new EventsV1alpha1Client for the given config. -func NewForConfig(c *rest.Config) (*EventsV1alpha1Client, error) { - config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } - client, err := rest.RESTClientFor(&config) - if err != nil { - return nil, err - } - return &EventsV1alpha1Client{client}, nil -} - -// NewForConfigOrDie creates a new EventsV1alpha1Client for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *EventsV1alpha1Client { - client, err := NewForConfig(c) - if err != nil { - panic(err) - } - return client -} - -// New creates a new EventsV1alpha1Client for the given RESTClient. -func New(c rest.Interface) *EventsV1alpha1Client { - return &EventsV1alpha1Client{c} -} - -func setConfigDefaults(config *rest.Config) error { - gv := v1alpha1.SchemeGroupVersion - config.GroupVersion = &gv - config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() - - if config.UserAgent == "" { - config.UserAgent = rest.DefaultKubernetesUserAgent() - } - - return nil -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *EventsV1alpha1Client) RESTClient() rest.Interface { - if c == nil { - return nil - } - return c.restClient -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/doc.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/doc.go deleted file mode 100644 index cc740d3ffd..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 has the automatically generated clients. -package fake diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudauditlogssource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudauditlogssource.go deleted file mode 100644 index 65d8d89cea..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudauditlogssource.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/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" -) - -// FakeCloudAuditLogsSources implements CloudAuditLogsSourceInterface -type FakeCloudAuditLogsSources struct { - Fake *FakeEventsV1alpha1 - ns string -} - -var cloudauditlogssourcesResource = schema.GroupVersionResource{Group: "events.cloud.google.com", Version: "v1alpha1", Resource: "cloudauditlogssources"} - -var cloudauditlogssourcesKind = schema.GroupVersionKind{Group: "events.cloud.google.com", Version: "v1alpha1", Kind: "CloudAuditLogsSource"} - -// Get takes name of the cloudAuditLogsSource, and returns the corresponding cloudAuditLogsSource object, and an error if there is any. -func (c *FakeCloudAuditLogsSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudAuditLogsSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(cloudauditlogssourcesResource, c.ns, name), &v1alpha1.CloudAuditLogsSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudAuditLogsSource), err -} - -// List takes label and field selectors, and returns the list of CloudAuditLogsSources that match those selectors. -func (c *FakeCloudAuditLogsSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudAuditLogsSourceList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(cloudauditlogssourcesResource, cloudauditlogssourcesKind, c.ns, opts), &v1alpha1.CloudAuditLogsSourceList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.CloudAuditLogsSourceList{ListMeta: obj.(*v1alpha1.CloudAuditLogsSourceList).ListMeta} - for _, item := range obj.(*v1alpha1.CloudAuditLogsSourceList).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 cloudAuditLogsSources. -func (c *FakeCloudAuditLogsSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(cloudauditlogssourcesResource, c.ns, opts)) - -} - -// Create takes the representation of a cloudAuditLogsSource and creates it. Returns the server's representation of the cloudAuditLogsSource, and an error, if there is any. -func (c *FakeCloudAuditLogsSources) Create(ctx context.Context, cloudAuditLogsSource *v1alpha1.CloudAuditLogsSource, opts v1.CreateOptions) (result *v1alpha1.CloudAuditLogsSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(cloudauditlogssourcesResource, c.ns, cloudAuditLogsSource), &v1alpha1.CloudAuditLogsSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudAuditLogsSource), err -} - -// Update takes the representation of a cloudAuditLogsSource and updates it. Returns the server's representation of the cloudAuditLogsSource, and an error, if there is any. -func (c *FakeCloudAuditLogsSources) Update(ctx context.Context, cloudAuditLogsSource *v1alpha1.CloudAuditLogsSource, opts v1.UpdateOptions) (result *v1alpha1.CloudAuditLogsSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(cloudauditlogssourcesResource, c.ns, cloudAuditLogsSource), &v1alpha1.CloudAuditLogsSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudAuditLogsSource), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeCloudAuditLogsSources) UpdateStatus(ctx context.Context, cloudAuditLogsSource *v1alpha1.CloudAuditLogsSource, opts v1.UpdateOptions) (*v1alpha1.CloudAuditLogsSource, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(cloudauditlogssourcesResource, "status", c.ns, cloudAuditLogsSource), &v1alpha1.CloudAuditLogsSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudAuditLogsSource), err -} - -// Delete takes name of the cloudAuditLogsSource and deletes it. Returns an error if one occurs. -func (c *FakeCloudAuditLogsSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(cloudauditlogssourcesResource, c.ns, name), &v1alpha1.CloudAuditLogsSource{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeCloudAuditLogsSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(cloudauditlogssourcesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.CloudAuditLogsSourceList{}) - return err -} - -// Patch applies the patch and returns the patched cloudAuditLogsSource. -func (c *FakeCloudAuditLogsSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudAuditLogsSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(cloudauditlogssourcesResource, c.ns, name, pt, data, subresources...), &v1alpha1.CloudAuditLogsSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudAuditLogsSource), err -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudbuildsource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudbuildsource.go deleted file mode 100644 index b10cab50ff..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudbuildsource.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/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" -) - -// FakeCloudBuildSources implements CloudBuildSourceInterface -type FakeCloudBuildSources struct { - Fake *FakeEventsV1alpha1 - ns string -} - -var cloudbuildsourcesResource = schema.GroupVersionResource{Group: "events.cloud.google.com", Version: "v1alpha1", Resource: "cloudbuildsources"} - -var cloudbuildsourcesKind = schema.GroupVersionKind{Group: "events.cloud.google.com", Version: "v1alpha1", Kind: "CloudBuildSource"} - -// Get takes name of the cloudBuildSource, and returns the corresponding cloudBuildSource object, and an error if there is any. -func (c *FakeCloudBuildSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudBuildSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(cloudbuildsourcesResource, c.ns, name), &v1alpha1.CloudBuildSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudBuildSource), err -} - -// List takes label and field selectors, and returns the list of CloudBuildSources that match those selectors. -func (c *FakeCloudBuildSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudBuildSourceList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(cloudbuildsourcesResource, cloudbuildsourcesKind, c.ns, opts), &v1alpha1.CloudBuildSourceList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.CloudBuildSourceList{ListMeta: obj.(*v1alpha1.CloudBuildSourceList).ListMeta} - for _, item := range obj.(*v1alpha1.CloudBuildSourceList).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 cloudBuildSources. -func (c *FakeCloudBuildSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(cloudbuildsourcesResource, c.ns, opts)) - -} - -// Create takes the representation of a cloudBuildSource and creates it. Returns the server's representation of the cloudBuildSource, and an error, if there is any. -func (c *FakeCloudBuildSources) Create(ctx context.Context, cloudBuildSource *v1alpha1.CloudBuildSource, opts v1.CreateOptions) (result *v1alpha1.CloudBuildSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(cloudbuildsourcesResource, c.ns, cloudBuildSource), &v1alpha1.CloudBuildSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudBuildSource), err -} - -// Update takes the representation of a cloudBuildSource and updates it. Returns the server's representation of the cloudBuildSource, and an error, if there is any. -func (c *FakeCloudBuildSources) Update(ctx context.Context, cloudBuildSource *v1alpha1.CloudBuildSource, opts v1.UpdateOptions) (result *v1alpha1.CloudBuildSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(cloudbuildsourcesResource, c.ns, cloudBuildSource), &v1alpha1.CloudBuildSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudBuildSource), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeCloudBuildSources) UpdateStatus(ctx context.Context, cloudBuildSource *v1alpha1.CloudBuildSource, opts v1.UpdateOptions) (*v1alpha1.CloudBuildSource, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(cloudbuildsourcesResource, "status", c.ns, cloudBuildSource), &v1alpha1.CloudBuildSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudBuildSource), err -} - -// Delete takes name of the cloudBuildSource and deletes it. Returns an error if one occurs. -func (c *FakeCloudBuildSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(cloudbuildsourcesResource, c.ns, name), &v1alpha1.CloudBuildSource{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeCloudBuildSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(cloudbuildsourcesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.CloudBuildSourceList{}) - return err -} - -// Patch applies the patch and returns the patched cloudBuildSource. -func (c *FakeCloudBuildSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudBuildSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(cloudbuildsourcesResource, c.ns, name, pt, data, subresources...), &v1alpha1.CloudBuildSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudBuildSource), err -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudpubsubsource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudpubsubsource.go deleted file mode 100644 index 0157f03905..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudpubsubsource.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/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" -) - -// FakeCloudPubSubSources implements CloudPubSubSourceInterface -type FakeCloudPubSubSources struct { - Fake *FakeEventsV1alpha1 - ns string -} - -var cloudpubsubsourcesResource = schema.GroupVersionResource{Group: "events.cloud.google.com", Version: "v1alpha1", Resource: "cloudpubsubsources"} - -var cloudpubsubsourcesKind = schema.GroupVersionKind{Group: "events.cloud.google.com", Version: "v1alpha1", Kind: "CloudPubSubSource"} - -// Get takes name of the cloudPubSubSource, and returns the corresponding cloudPubSubSource object, and an error if there is any. -func (c *FakeCloudPubSubSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudPubSubSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(cloudpubsubsourcesResource, c.ns, name), &v1alpha1.CloudPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudPubSubSource), err -} - -// List takes label and field selectors, and returns the list of CloudPubSubSources that match those selectors. -func (c *FakeCloudPubSubSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudPubSubSourceList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(cloudpubsubsourcesResource, cloudpubsubsourcesKind, c.ns, opts), &v1alpha1.CloudPubSubSourceList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.CloudPubSubSourceList{ListMeta: obj.(*v1alpha1.CloudPubSubSourceList).ListMeta} - for _, item := range obj.(*v1alpha1.CloudPubSubSourceList).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 cloudPubSubSources. -func (c *FakeCloudPubSubSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(cloudpubsubsourcesResource, c.ns, opts)) - -} - -// Create takes the representation of a cloudPubSubSource and creates it. Returns the server's representation of the cloudPubSubSource, and an error, if there is any. -func (c *FakeCloudPubSubSources) Create(ctx context.Context, cloudPubSubSource *v1alpha1.CloudPubSubSource, opts v1.CreateOptions) (result *v1alpha1.CloudPubSubSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(cloudpubsubsourcesResource, c.ns, cloudPubSubSource), &v1alpha1.CloudPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudPubSubSource), err -} - -// Update takes the representation of a cloudPubSubSource and updates it. Returns the server's representation of the cloudPubSubSource, and an error, if there is any. -func (c *FakeCloudPubSubSources) Update(ctx context.Context, cloudPubSubSource *v1alpha1.CloudPubSubSource, opts v1.UpdateOptions) (result *v1alpha1.CloudPubSubSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(cloudpubsubsourcesResource, c.ns, cloudPubSubSource), &v1alpha1.CloudPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudPubSubSource), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeCloudPubSubSources) UpdateStatus(ctx context.Context, cloudPubSubSource *v1alpha1.CloudPubSubSource, opts v1.UpdateOptions) (*v1alpha1.CloudPubSubSource, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(cloudpubsubsourcesResource, "status", c.ns, cloudPubSubSource), &v1alpha1.CloudPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudPubSubSource), err -} - -// Delete takes name of the cloudPubSubSource and deletes it. Returns an error if one occurs. -func (c *FakeCloudPubSubSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(cloudpubsubsourcesResource, c.ns, name), &v1alpha1.CloudPubSubSource{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeCloudPubSubSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(cloudpubsubsourcesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.CloudPubSubSourceList{}) - return err -} - -// Patch applies the patch and returns the patched cloudPubSubSource. -func (c *FakeCloudPubSubSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudPubSubSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(cloudpubsubsourcesResource, c.ns, name, pt, data, subresources...), &v1alpha1.CloudPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudPubSubSource), err -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudschedulersource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudschedulersource.go deleted file mode 100644 index c3e64606cb..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudschedulersource.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/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" -) - -// FakeCloudSchedulerSources implements CloudSchedulerSourceInterface -type FakeCloudSchedulerSources struct { - Fake *FakeEventsV1alpha1 - ns string -} - -var cloudschedulersourcesResource = schema.GroupVersionResource{Group: "events.cloud.google.com", Version: "v1alpha1", Resource: "cloudschedulersources"} - -var cloudschedulersourcesKind = schema.GroupVersionKind{Group: "events.cloud.google.com", Version: "v1alpha1", Kind: "CloudSchedulerSource"} - -// Get takes name of the cloudSchedulerSource, and returns the corresponding cloudSchedulerSource object, and an error if there is any. -func (c *FakeCloudSchedulerSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudSchedulerSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(cloudschedulersourcesResource, c.ns, name), &v1alpha1.CloudSchedulerSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudSchedulerSource), err -} - -// List takes label and field selectors, and returns the list of CloudSchedulerSources that match those selectors. -func (c *FakeCloudSchedulerSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudSchedulerSourceList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(cloudschedulersourcesResource, cloudschedulersourcesKind, c.ns, opts), &v1alpha1.CloudSchedulerSourceList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.CloudSchedulerSourceList{ListMeta: obj.(*v1alpha1.CloudSchedulerSourceList).ListMeta} - for _, item := range obj.(*v1alpha1.CloudSchedulerSourceList).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 cloudSchedulerSources. -func (c *FakeCloudSchedulerSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(cloudschedulersourcesResource, c.ns, opts)) - -} - -// Create takes the representation of a cloudSchedulerSource and creates it. Returns the server's representation of the cloudSchedulerSource, and an error, if there is any. -func (c *FakeCloudSchedulerSources) Create(ctx context.Context, cloudSchedulerSource *v1alpha1.CloudSchedulerSource, opts v1.CreateOptions) (result *v1alpha1.CloudSchedulerSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(cloudschedulersourcesResource, c.ns, cloudSchedulerSource), &v1alpha1.CloudSchedulerSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudSchedulerSource), err -} - -// Update takes the representation of a cloudSchedulerSource and updates it. Returns the server's representation of the cloudSchedulerSource, and an error, if there is any. -func (c *FakeCloudSchedulerSources) Update(ctx context.Context, cloudSchedulerSource *v1alpha1.CloudSchedulerSource, opts v1.UpdateOptions) (result *v1alpha1.CloudSchedulerSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(cloudschedulersourcesResource, c.ns, cloudSchedulerSource), &v1alpha1.CloudSchedulerSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudSchedulerSource), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeCloudSchedulerSources) UpdateStatus(ctx context.Context, cloudSchedulerSource *v1alpha1.CloudSchedulerSource, opts v1.UpdateOptions) (*v1alpha1.CloudSchedulerSource, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(cloudschedulersourcesResource, "status", c.ns, cloudSchedulerSource), &v1alpha1.CloudSchedulerSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudSchedulerSource), err -} - -// Delete takes name of the cloudSchedulerSource and deletes it. Returns an error if one occurs. -func (c *FakeCloudSchedulerSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(cloudschedulersourcesResource, c.ns, name), &v1alpha1.CloudSchedulerSource{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeCloudSchedulerSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(cloudschedulersourcesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.CloudSchedulerSourceList{}) - return err -} - -// Patch applies the patch and returns the patched cloudSchedulerSource. -func (c *FakeCloudSchedulerSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudSchedulerSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(cloudschedulersourcesResource, c.ns, name, pt, data, subresources...), &v1alpha1.CloudSchedulerSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudSchedulerSource), err -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudstoragesource.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudstoragesource.go deleted file mode 100644 index 7f4824d96c..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_cloudstoragesource.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/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" -) - -// FakeCloudStorageSources implements CloudStorageSourceInterface -type FakeCloudStorageSources struct { - Fake *FakeEventsV1alpha1 - ns string -} - -var cloudstoragesourcesResource = schema.GroupVersionResource{Group: "events.cloud.google.com", Version: "v1alpha1", Resource: "cloudstoragesources"} - -var cloudstoragesourcesKind = schema.GroupVersionKind{Group: "events.cloud.google.com", Version: "v1alpha1", Kind: "CloudStorageSource"} - -// Get takes name of the cloudStorageSource, and returns the corresponding cloudStorageSource object, and an error if there is any. -func (c *FakeCloudStorageSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CloudStorageSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(cloudstoragesourcesResource, c.ns, name), &v1alpha1.CloudStorageSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudStorageSource), err -} - -// List takes label and field selectors, and returns the list of CloudStorageSources that match those selectors. -func (c *FakeCloudStorageSources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CloudStorageSourceList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(cloudstoragesourcesResource, cloudstoragesourcesKind, c.ns, opts), &v1alpha1.CloudStorageSourceList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.CloudStorageSourceList{ListMeta: obj.(*v1alpha1.CloudStorageSourceList).ListMeta} - for _, item := range obj.(*v1alpha1.CloudStorageSourceList).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 cloudStorageSources. -func (c *FakeCloudStorageSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(cloudstoragesourcesResource, c.ns, opts)) - -} - -// Create takes the representation of a cloudStorageSource and creates it. Returns the server's representation of the cloudStorageSource, and an error, if there is any. -func (c *FakeCloudStorageSources) Create(ctx context.Context, cloudStorageSource *v1alpha1.CloudStorageSource, opts v1.CreateOptions) (result *v1alpha1.CloudStorageSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(cloudstoragesourcesResource, c.ns, cloudStorageSource), &v1alpha1.CloudStorageSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudStorageSource), err -} - -// Update takes the representation of a cloudStorageSource and updates it. Returns the server's representation of the cloudStorageSource, and an error, if there is any. -func (c *FakeCloudStorageSources) Update(ctx context.Context, cloudStorageSource *v1alpha1.CloudStorageSource, opts v1.UpdateOptions) (result *v1alpha1.CloudStorageSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(cloudstoragesourcesResource, c.ns, cloudStorageSource), &v1alpha1.CloudStorageSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudStorageSource), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeCloudStorageSources) UpdateStatus(ctx context.Context, cloudStorageSource *v1alpha1.CloudStorageSource, opts v1.UpdateOptions) (*v1alpha1.CloudStorageSource, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(cloudstoragesourcesResource, "status", c.ns, cloudStorageSource), &v1alpha1.CloudStorageSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudStorageSource), err -} - -// Delete takes name of the cloudStorageSource and deletes it. Returns an error if one occurs. -func (c *FakeCloudStorageSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(cloudstoragesourcesResource, c.ns, name), &v1alpha1.CloudStorageSource{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeCloudStorageSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(cloudstoragesourcesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.CloudStorageSourceList{}) - return err -} - -// Patch applies the patch and returns the patched cloudStorageSource. -func (c *FakeCloudStorageSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CloudStorageSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(cloudstoragesourcesResource, c.ns, name, pt, data, subresources...), &v1alpha1.CloudStorageSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.CloudStorageSource), err -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_events_client.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_events_client.go deleted file mode 100644 index 11b1c3ee9d..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/fake/fake_events_client.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/knative-gcp/pkg/client/clientset/versioned/typed/events/v1alpha1" - rest "k8s.io/client-go/rest" - testing "k8s.io/client-go/testing" -) - -type FakeEventsV1alpha1 struct { - *testing.Fake -} - -func (c *FakeEventsV1alpha1) CloudAuditLogsSources(namespace string) v1alpha1.CloudAuditLogsSourceInterface { - return &FakeCloudAuditLogsSources{c, namespace} -} - -func (c *FakeEventsV1alpha1) CloudBuildSources(namespace string) v1alpha1.CloudBuildSourceInterface { - return &FakeCloudBuildSources{c, namespace} -} - -func (c *FakeEventsV1alpha1) CloudPubSubSources(namespace string) v1alpha1.CloudPubSubSourceInterface { - return &FakeCloudPubSubSources{c, namespace} -} - -func (c *FakeEventsV1alpha1) CloudSchedulerSources(namespace string) v1alpha1.CloudSchedulerSourceInterface { - return &FakeCloudSchedulerSources{c, namespace} -} - -func (c *FakeEventsV1alpha1) CloudStorageSources(namespace string) v1alpha1.CloudStorageSourceInterface { - return &FakeCloudStorageSources{c, namespace} -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *FakeEventsV1alpha1) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret -} diff --git a/pkg/client/clientset/versioned/typed/events/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/events/v1alpha1/generated_expansion.go deleted file mode 100644 index 8025a7e4ae..0000000000 --- a/pkg/client/clientset/versioned/typed/events/v1alpha1/generated_expansion.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 - -type CloudAuditLogsSourceExpansion interface{} - -type CloudBuildSourceExpansion interface{} - -type CloudPubSubSourceExpansion interface{} - -type CloudSchedulerSourceExpansion interface{} - -type CloudStorageSourceExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_intevents_client.go b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_intevents_client.go index 60bd3ae289..6b9926f7b3 100644 --- a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_intevents_client.go +++ b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_intevents_client.go @@ -32,14 +32,6 @@ func (c *FakeInternalV1alpha1) BrokerCells(namespace string) v1alpha1.BrokerCell return &FakeBrokerCells{c, namespace} } -func (c *FakeInternalV1alpha1) PullSubscriptions(namespace string) v1alpha1.PullSubscriptionInterface { - return &FakePullSubscriptions{c, namespace} -} - -func (c *FakeInternalV1alpha1) Topics(namespace string) v1alpha1.TopicInterface { - return &FakeTopics{c, namespace} -} - // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeInternalV1alpha1) RESTClient() rest.Interface { diff --git a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_pullsubscription.go b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_pullsubscription.go deleted file mode 100644 index 4a3442bf47..0000000000 --- a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_pullsubscription.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/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" -) - -// FakePullSubscriptions implements PullSubscriptionInterface -type FakePullSubscriptions struct { - Fake *FakeInternalV1alpha1 - ns string -} - -var pullsubscriptionsResource = schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "pullsubscriptions"} - -var pullsubscriptionsKind = schema.GroupVersionKind{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Kind: "PullSubscription"} - -// Get takes name of the pullSubscription, and returns the corresponding pullSubscription object, and an error if there is any. -func (c *FakePullSubscriptions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PullSubscription, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(pullsubscriptionsResource, c.ns, name), &v1alpha1.PullSubscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.PullSubscription), err -} - -// List takes label and field selectors, and returns the list of PullSubscriptions that match those selectors. -func (c *FakePullSubscriptions) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PullSubscriptionList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(pullsubscriptionsResource, pullsubscriptionsKind, c.ns, opts), &v1alpha1.PullSubscriptionList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.PullSubscriptionList{ListMeta: obj.(*v1alpha1.PullSubscriptionList).ListMeta} - for _, item := range obj.(*v1alpha1.PullSubscriptionList).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 pullSubscriptions. -func (c *FakePullSubscriptions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(pullsubscriptionsResource, c.ns, opts)) - -} - -// Create takes the representation of a pullSubscription and creates it. Returns the server's representation of the pullSubscription, and an error, if there is any. -func (c *FakePullSubscriptions) Create(ctx context.Context, pullSubscription *v1alpha1.PullSubscription, opts v1.CreateOptions) (result *v1alpha1.PullSubscription, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(pullsubscriptionsResource, c.ns, pullSubscription), &v1alpha1.PullSubscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.PullSubscription), err -} - -// Update takes the representation of a pullSubscription and updates it. Returns the server's representation of the pullSubscription, and an error, if there is any. -func (c *FakePullSubscriptions) Update(ctx context.Context, pullSubscription *v1alpha1.PullSubscription, opts v1.UpdateOptions) (result *v1alpha1.PullSubscription, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(pullsubscriptionsResource, c.ns, pullSubscription), &v1alpha1.PullSubscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.PullSubscription), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakePullSubscriptions) UpdateStatus(ctx context.Context, pullSubscription *v1alpha1.PullSubscription, opts v1.UpdateOptions) (*v1alpha1.PullSubscription, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(pullsubscriptionsResource, "status", c.ns, pullSubscription), &v1alpha1.PullSubscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.PullSubscription), err -} - -// Delete takes name of the pullSubscription and deletes it. Returns an error if one occurs. -func (c *FakePullSubscriptions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(pullsubscriptionsResource, c.ns, name), &v1alpha1.PullSubscription{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakePullSubscriptions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(pullsubscriptionsResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.PullSubscriptionList{}) - return err -} - -// Patch applies the patch and returns the patched pullSubscription. -func (c *FakePullSubscriptions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PullSubscription, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(pullsubscriptionsResource, c.ns, name, pt, data, subresources...), &v1alpha1.PullSubscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.PullSubscription), err -} diff --git a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_topic.go b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_topic.go deleted file mode 100644 index 1fdec81236..0000000000 --- a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake/fake_topic.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/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" -) - -// FakeTopics implements TopicInterface -type FakeTopics struct { - Fake *FakeInternalV1alpha1 - ns string -} - -var topicsResource = schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "topics"} - -var topicsKind = schema.GroupVersionKind{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Kind: "Topic"} - -// Get takes name of the topic, and returns the corresponding topic object, and an error if there is any. -func (c *FakeTopics) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Topic, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(topicsResource, c.ns, name), &v1alpha1.Topic{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Topic), err -} - -// List takes label and field selectors, and returns the list of Topics that match those selectors. -func (c *FakeTopics) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.TopicList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(topicsResource, topicsKind, c.ns, opts), &v1alpha1.TopicList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.TopicList{ListMeta: obj.(*v1alpha1.TopicList).ListMeta} - for _, item := range obj.(*v1alpha1.TopicList).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 topics. -func (c *FakeTopics) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(topicsResource, c.ns, opts)) - -} - -// Create takes the representation of a topic and creates it. Returns the server's representation of the topic, and an error, if there is any. -func (c *FakeTopics) Create(ctx context.Context, topic *v1alpha1.Topic, opts v1.CreateOptions) (result *v1alpha1.Topic, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(topicsResource, c.ns, topic), &v1alpha1.Topic{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Topic), err -} - -// Update takes the representation of a topic and updates it. Returns the server's representation of the topic, and an error, if there is any. -func (c *FakeTopics) Update(ctx context.Context, topic *v1alpha1.Topic, opts v1.UpdateOptions) (result *v1alpha1.Topic, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(topicsResource, c.ns, topic), &v1alpha1.Topic{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Topic), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTopics) UpdateStatus(ctx context.Context, topic *v1alpha1.Topic, opts v1.UpdateOptions) (*v1alpha1.Topic, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(topicsResource, "status", c.ns, topic), &v1alpha1.Topic{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Topic), err -} - -// Delete takes name of the topic and deletes it. Returns an error if one occurs. -func (c *FakeTopics) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(topicsResource, c.ns, name), &v1alpha1.Topic{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTopics) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(topicsResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.TopicList{}) - return err -} - -// Patch applies the patch and returns the patched topic. -func (c *FakeTopics) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Topic, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(topicsResource, c.ns, name, pt, data, subresources...), &v1alpha1.Topic{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Topic), err -} diff --git a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/generated_expansion.go index 351e5bd906..441e30b94d 100644 --- a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/generated_expansion.go @@ -19,7 +19,3 @@ limitations under the License. package v1alpha1 type BrokerCellExpansion interface{} - -type PullSubscriptionExpansion interface{} - -type TopicExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/intevents_client.go b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/intevents_client.go index f42d0a148b..06779c8ba6 100644 --- a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/intevents_client.go +++ b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/intevents_client.go @@ -27,8 +27,6 @@ import ( type InternalV1alpha1Interface interface { RESTClient() rest.Interface BrokerCellsGetter - PullSubscriptionsGetter - TopicsGetter } // InternalV1alpha1Client is used to interact with features provided by the internal.events.cloud.google.com group. @@ -40,14 +38,6 @@ func (c *InternalV1alpha1Client) BrokerCells(namespace string) BrokerCellInterfa return newBrokerCells(c, namespace) } -func (c *InternalV1alpha1Client) PullSubscriptions(namespace string) PullSubscriptionInterface { - return newPullSubscriptions(c, namespace) -} - -func (c *InternalV1alpha1Client) Topics(namespace string) TopicInterface { - return newTopics(c, namespace) -} - // NewForConfig creates a new InternalV1alpha1Client for the given config. func NewForConfig(c *rest.Config) (*InternalV1alpha1Client, error) { config := *c diff --git a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/pullsubscription.go b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/pullsubscription.go deleted file mode 100644 index c37512801b..0000000000 --- a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/pullsubscription.go +++ /dev/null @@ -1,195 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "time" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - scheme "github.com/google/knative-gcp/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" -) - -// PullSubscriptionsGetter has a method to return a PullSubscriptionInterface. -// A group's client should implement this interface. -type PullSubscriptionsGetter interface { - PullSubscriptions(namespace string) PullSubscriptionInterface -} - -// PullSubscriptionInterface has methods to work with PullSubscription resources. -type PullSubscriptionInterface interface { - Create(ctx context.Context, pullSubscription *v1alpha1.PullSubscription, opts v1.CreateOptions) (*v1alpha1.PullSubscription, error) - Update(ctx context.Context, pullSubscription *v1alpha1.PullSubscription, opts v1.UpdateOptions) (*v1alpha1.PullSubscription, error) - UpdateStatus(ctx context.Context, pullSubscription *v1alpha1.PullSubscription, opts v1.UpdateOptions) (*v1alpha1.PullSubscription, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.PullSubscription, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.PullSubscriptionList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PullSubscription, err error) - PullSubscriptionExpansion -} - -// pullSubscriptions implements PullSubscriptionInterface -type pullSubscriptions struct { - client rest.Interface - ns string -} - -// newPullSubscriptions returns a PullSubscriptions -func newPullSubscriptions(c *InternalV1alpha1Client, namespace string) *pullSubscriptions { - return &pullSubscriptions{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the pullSubscription, and returns the corresponding pullSubscription object, and an error if there is any. -func (c *pullSubscriptions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PullSubscription, err error) { - result = &v1alpha1.PullSubscription{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pullsubscriptions"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of PullSubscriptions that match those selectors. -func (c *pullSubscriptions) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PullSubscriptionList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.PullSubscriptionList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pullsubscriptions"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested pullSubscriptions. -func (c *pullSubscriptions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("pullsubscriptions"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a pullSubscription and creates it. Returns the server's representation of the pullSubscription, and an error, if there is any. -func (c *pullSubscriptions) Create(ctx context.Context, pullSubscription *v1alpha1.PullSubscription, opts v1.CreateOptions) (result *v1alpha1.PullSubscription, err error) { - result = &v1alpha1.PullSubscription{} - err = c.client.Post(). - Namespace(c.ns). - Resource("pullsubscriptions"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pullSubscription). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a pullSubscription and updates it. Returns the server's representation of the pullSubscription, and an error, if there is any. -func (c *pullSubscriptions) Update(ctx context.Context, pullSubscription *v1alpha1.PullSubscription, opts v1.UpdateOptions) (result *v1alpha1.PullSubscription, err error) { - result = &v1alpha1.PullSubscription{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pullsubscriptions"). - Name(pullSubscription.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pullSubscription). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *pullSubscriptions) UpdateStatus(ctx context.Context, pullSubscription *v1alpha1.PullSubscription, opts v1.UpdateOptions) (result *v1alpha1.PullSubscription, err error) { - result = &v1alpha1.PullSubscription{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pullsubscriptions"). - Name(pullSubscription.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pullSubscription). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the pullSubscription and deletes it. Returns an error if one occurs. -func (c *pullSubscriptions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("pullsubscriptions"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *pullSubscriptions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("pullsubscriptions"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched pullSubscription. -func (c *pullSubscriptions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PullSubscription, err error) { - result = &v1alpha1.PullSubscription{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("pullsubscriptions"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/topic.go b/pkg/client/clientset/versioned/typed/intevents/v1alpha1/topic.go deleted file mode 100644 index 5e24c9e319..0000000000 --- a/pkg/client/clientset/versioned/typed/intevents/v1alpha1/topic.go +++ /dev/null @@ -1,195 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - "time" - - v1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - scheme "github.com/google/knative-gcp/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" -) - -// TopicsGetter has a method to return a TopicInterface. -// A group's client should implement this interface. -type TopicsGetter interface { - Topics(namespace string) TopicInterface -} - -// TopicInterface has methods to work with Topic resources. -type TopicInterface interface { - Create(ctx context.Context, topic *v1alpha1.Topic, opts v1.CreateOptions) (*v1alpha1.Topic, error) - Update(ctx context.Context, topic *v1alpha1.Topic, opts v1.UpdateOptions) (*v1alpha1.Topic, error) - UpdateStatus(ctx context.Context, topic *v1alpha1.Topic, opts v1.UpdateOptions) (*v1alpha1.Topic, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.Topic, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.TopicList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Topic, err error) - TopicExpansion -} - -// topics implements TopicInterface -type topics struct { - client rest.Interface - ns string -} - -// newTopics returns a Topics -func newTopics(c *InternalV1alpha1Client, namespace string) *topics { - return &topics{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the topic, and returns the corresponding topic object, and an error if there is any. -func (c *topics) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Topic, err error) { - result = &v1alpha1.Topic{} - err = c.client.Get(). - Namespace(c.ns). - Resource("topics"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Topics that match those selectors. -func (c *topics) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.TopicList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.TopicList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("topics"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested topics. -func (c *topics) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("topics"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a topic and creates it. Returns the server's representation of the topic, and an error, if there is any. -func (c *topics) Create(ctx context.Context, topic *v1alpha1.Topic, opts v1.CreateOptions) (result *v1alpha1.Topic, err error) { - result = &v1alpha1.Topic{} - err = c.client.Post(). - Namespace(c.ns). - Resource("topics"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(topic). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a topic and updates it. Returns the server's representation of the topic, and an error, if there is any. -func (c *topics) Update(ctx context.Context, topic *v1alpha1.Topic, opts v1.UpdateOptions) (result *v1alpha1.Topic, err error) { - result = &v1alpha1.Topic{} - err = c.client.Put(). - Namespace(c.ns). - Resource("topics"). - Name(topic.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(topic). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *topics) UpdateStatus(ctx context.Context, topic *v1alpha1.Topic, opts v1.UpdateOptions) (result *v1alpha1.Topic, err error) { - result = &v1alpha1.Topic{} - err = c.client.Put(). - Namespace(c.ns). - Resource("topics"). - Name(topic.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(topic). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the topic and deletes it. Returns an error if one occurs. -func (c *topics) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("topics"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *topics) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("topics"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched topic. -func (c *topics) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Topic, err error) { - result = &v1alpha1.Topic{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("topics"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/informers/externalversions/events/interface.go b/pkg/client/informers/externalversions/events/interface.go index 94be884b63..76c4d9fe8c 100644 --- a/pkg/client/informers/externalversions/events/interface.go +++ b/pkg/client/informers/externalversions/events/interface.go @@ -20,15 +20,12 @@ package events import ( v1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1" - v1alpha1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1" v1beta1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1beta1" internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" ) // Interface provides access to each of this group's versions. type Interface interface { - // V1alpha1 provides access to shared informers for resources in V1alpha1. - V1alpha1() v1alpha1.Interface // V1beta1 provides access to shared informers for resources in V1beta1. V1beta1() v1beta1.Interface // V1 provides access to shared informers for resources in V1. @@ -46,11 +43,6 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// V1alpha1 returns a new v1alpha1.Interface. -func (g *group) V1alpha1() v1alpha1.Interface { - return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) -} - // V1beta1 returns a new v1beta1.Interface. func (g *group) V1beta1() v1beta1.Interface { return v1beta1.New(g.factory, g.namespace, g.tweakListOptions) diff --git a/pkg/client/informers/externalversions/events/v1alpha1/cloudauditlogssource.go b/pkg/client/informers/externalversions/events/v1alpha1/cloudauditlogssource.go deleted file mode 100644 index fb01df4903..0000000000 --- a/pkg/client/informers/externalversions/events/v1alpha1/cloudauditlogssource.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - time "time" - - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - versioned "github.com/google/knative-gcp/pkg/client/clientset/versioned" - internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/google/knative-gcp/pkg/client/listers/events/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" -) - -// CloudAuditLogsSourceInformer provides access to a shared informer and lister for -// CloudAuditLogsSources. -type CloudAuditLogsSourceInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.CloudAuditLogsSourceLister -} - -type cloudAuditLogsSourceInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewCloudAuditLogsSourceInformer constructs a new informer for CloudAuditLogsSource 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 NewCloudAuditLogsSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredCloudAuditLogsSourceInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredCloudAuditLogsSourceInformer constructs a new informer for CloudAuditLogsSource 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 NewFilteredCloudAuditLogsSourceInformer(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.EventsV1alpha1().CloudAuditLogsSources(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.EventsV1alpha1().CloudAuditLogsSources(namespace).Watch(context.TODO(), options) - }, - }, - &eventsv1alpha1.CloudAuditLogsSource{}, - resyncPeriod, - indexers, - ) -} - -func (f *cloudAuditLogsSourceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredCloudAuditLogsSourceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *cloudAuditLogsSourceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventsv1alpha1.CloudAuditLogsSource{}, f.defaultInformer) -} - -func (f *cloudAuditLogsSourceInformer) Lister() v1alpha1.CloudAuditLogsSourceLister { - return v1alpha1.NewCloudAuditLogsSourceLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/informers/externalversions/events/v1alpha1/cloudbuildsource.go b/pkg/client/informers/externalversions/events/v1alpha1/cloudbuildsource.go deleted file mode 100644 index 8fb42dbc42..0000000000 --- a/pkg/client/informers/externalversions/events/v1alpha1/cloudbuildsource.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - time "time" - - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - versioned "github.com/google/knative-gcp/pkg/client/clientset/versioned" - internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/google/knative-gcp/pkg/client/listers/events/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" -) - -// CloudBuildSourceInformer provides access to a shared informer and lister for -// CloudBuildSources. -type CloudBuildSourceInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.CloudBuildSourceLister -} - -type cloudBuildSourceInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewCloudBuildSourceInformer constructs a new informer for CloudBuildSource 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 NewCloudBuildSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredCloudBuildSourceInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredCloudBuildSourceInformer constructs a new informer for CloudBuildSource 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 NewFilteredCloudBuildSourceInformer(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.EventsV1alpha1().CloudBuildSources(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.EventsV1alpha1().CloudBuildSources(namespace).Watch(context.TODO(), options) - }, - }, - &eventsv1alpha1.CloudBuildSource{}, - resyncPeriod, - indexers, - ) -} - -func (f *cloudBuildSourceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredCloudBuildSourceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *cloudBuildSourceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventsv1alpha1.CloudBuildSource{}, f.defaultInformer) -} - -func (f *cloudBuildSourceInformer) Lister() v1alpha1.CloudBuildSourceLister { - return v1alpha1.NewCloudBuildSourceLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/informers/externalversions/events/v1alpha1/cloudpubsubsource.go b/pkg/client/informers/externalversions/events/v1alpha1/cloudpubsubsource.go deleted file mode 100644 index 67744f8d7c..0000000000 --- a/pkg/client/informers/externalversions/events/v1alpha1/cloudpubsubsource.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - time "time" - - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - versioned "github.com/google/knative-gcp/pkg/client/clientset/versioned" - internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/google/knative-gcp/pkg/client/listers/events/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" -) - -// CloudPubSubSourceInformer provides access to a shared informer and lister for -// CloudPubSubSources. -type CloudPubSubSourceInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.CloudPubSubSourceLister -} - -type cloudPubSubSourceInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewCloudPubSubSourceInformer constructs a new informer for CloudPubSubSource 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 NewCloudPubSubSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredCloudPubSubSourceInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredCloudPubSubSourceInformer constructs a new informer for CloudPubSubSource 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 NewFilteredCloudPubSubSourceInformer(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.EventsV1alpha1().CloudPubSubSources(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.EventsV1alpha1().CloudPubSubSources(namespace).Watch(context.TODO(), options) - }, - }, - &eventsv1alpha1.CloudPubSubSource{}, - resyncPeriod, - indexers, - ) -} - -func (f *cloudPubSubSourceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredCloudPubSubSourceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *cloudPubSubSourceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventsv1alpha1.CloudPubSubSource{}, f.defaultInformer) -} - -func (f *cloudPubSubSourceInformer) Lister() v1alpha1.CloudPubSubSourceLister { - return v1alpha1.NewCloudPubSubSourceLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/informers/externalversions/events/v1alpha1/cloudschedulersource.go b/pkg/client/informers/externalversions/events/v1alpha1/cloudschedulersource.go deleted file mode 100644 index c63104d66e..0000000000 --- a/pkg/client/informers/externalversions/events/v1alpha1/cloudschedulersource.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - time "time" - - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - versioned "github.com/google/knative-gcp/pkg/client/clientset/versioned" - internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/google/knative-gcp/pkg/client/listers/events/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" -) - -// CloudSchedulerSourceInformer provides access to a shared informer and lister for -// CloudSchedulerSources. -type CloudSchedulerSourceInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.CloudSchedulerSourceLister -} - -type cloudSchedulerSourceInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewCloudSchedulerSourceInformer constructs a new informer for CloudSchedulerSource 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 NewCloudSchedulerSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredCloudSchedulerSourceInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredCloudSchedulerSourceInformer constructs a new informer for CloudSchedulerSource 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 NewFilteredCloudSchedulerSourceInformer(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.EventsV1alpha1().CloudSchedulerSources(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.EventsV1alpha1().CloudSchedulerSources(namespace).Watch(context.TODO(), options) - }, - }, - &eventsv1alpha1.CloudSchedulerSource{}, - resyncPeriod, - indexers, - ) -} - -func (f *cloudSchedulerSourceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredCloudSchedulerSourceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *cloudSchedulerSourceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventsv1alpha1.CloudSchedulerSource{}, f.defaultInformer) -} - -func (f *cloudSchedulerSourceInformer) Lister() v1alpha1.CloudSchedulerSourceLister { - return v1alpha1.NewCloudSchedulerSourceLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/informers/externalversions/events/v1alpha1/cloudstoragesource.go b/pkg/client/informers/externalversions/events/v1alpha1/cloudstoragesource.go deleted file mode 100644 index 7eb77a55f4..0000000000 --- a/pkg/client/informers/externalversions/events/v1alpha1/cloudstoragesource.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - time "time" - - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - versioned "github.com/google/knative-gcp/pkg/client/clientset/versioned" - internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/google/knative-gcp/pkg/client/listers/events/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" -) - -// CloudStorageSourceInformer provides access to a shared informer and lister for -// CloudStorageSources. -type CloudStorageSourceInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.CloudStorageSourceLister -} - -type cloudStorageSourceInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewCloudStorageSourceInformer constructs a new informer for CloudStorageSource 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 NewCloudStorageSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredCloudStorageSourceInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredCloudStorageSourceInformer constructs a new informer for CloudStorageSource 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 NewFilteredCloudStorageSourceInformer(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.EventsV1alpha1().CloudStorageSources(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.EventsV1alpha1().CloudStorageSources(namespace).Watch(context.TODO(), options) - }, - }, - &eventsv1alpha1.CloudStorageSource{}, - resyncPeriod, - indexers, - ) -} - -func (f *cloudStorageSourceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredCloudStorageSourceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *cloudStorageSourceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&eventsv1alpha1.CloudStorageSource{}, f.defaultInformer) -} - -func (f *cloudStorageSourceInformer) Lister() v1alpha1.CloudStorageSourceLister { - return v1alpha1.NewCloudStorageSourceLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/informers/externalversions/events/v1alpha1/interface.go b/pkg/client/informers/externalversions/events/v1alpha1/interface.go deleted file mode 100644 index 48ee2406cc..0000000000 --- a/pkg/client/informers/externalversions/events/v1alpha1/interface.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" -) - -// Interface provides access to all the informers in this group version. -type Interface interface { - // CloudAuditLogsSources returns a CloudAuditLogsSourceInformer. - CloudAuditLogsSources() CloudAuditLogsSourceInformer - // CloudBuildSources returns a CloudBuildSourceInformer. - CloudBuildSources() CloudBuildSourceInformer - // CloudPubSubSources returns a CloudPubSubSourceInformer. - CloudPubSubSources() CloudPubSubSourceInformer - // CloudSchedulerSources returns a CloudSchedulerSourceInformer. - CloudSchedulerSources() CloudSchedulerSourceInformer - // CloudStorageSources returns a CloudStorageSourceInformer. - CloudStorageSources() CloudStorageSourceInformer -} - -type version struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// CloudAuditLogsSources returns a CloudAuditLogsSourceInformer. -func (v *version) CloudAuditLogsSources() CloudAuditLogsSourceInformer { - return &cloudAuditLogsSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// CloudBuildSources returns a CloudBuildSourceInformer. -func (v *version) CloudBuildSources() CloudBuildSourceInformer { - return &cloudBuildSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// CloudPubSubSources returns a CloudPubSubSourceInformer. -func (v *version) CloudPubSubSources() CloudPubSubSourceInformer { - return &cloudPubSubSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// CloudSchedulerSources returns a CloudSchedulerSourceInformer. -func (v *version) CloudSchedulerSources() CloudSchedulerSourceInformer { - return &cloudSchedulerSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// CloudStorageSources returns a CloudStorageSourceInformer. -func (v *version) CloudStorageSources() CloudStorageSourceInformer { - return &cloudStorageSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 408182b564..ed17454fae 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -23,10 +23,9 @@ import ( v1beta1 "github.com/google/knative-gcp/pkg/apis/broker/v1beta1" v1 "github.com/google/knative-gcp/pkg/apis/events/v1" - v1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" eventsv1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" inteventsv1 "github.com/google/knative-gcp/pkg/apis/intevents/v1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + v1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" messagingv1beta1 "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -77,18 +76,6 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case v1.SchemeGroupVersion.WithResource("cloudstoragesources"): return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1().CloudStorageSources().Informer()}, nil - // Group=events.cloud.google.com, Version=v1alpha1 - case v1alpha1.SchemeGroupVersion.WithResource("cloudauditlogssources"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1alpha1().CloudAuditLogsSources().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("cloudbuildsources"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1alpha1().CloudBuildSources().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("cloudpubsubsources"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1alpha1().CloudPubSubSources().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("cloudschedulersources"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1alpha1().CloudSchedulerSources().Informer()}, nil - case v1alpha1.SchemeGroupVersion.WithResource("cloudstoragesources"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1alpha1().CloudStorageSources().Informer()}, nil - // Group=events.cloud.google.com, Version=v1beta1 case eventsv1beta1.SchemeGroupVersion.WithResource("cloudauditlogssources"): return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1beta1().CloudAuditLogsSources().Informer()}, nil @@ -108,12 +95,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Internal().V1().Topics().Informer()}, nil // Group=internal.events.cloud.google.com, Version=v1alpha1 - case inteventsv1alpha1.SchemeGroupVersion.WithResource("brokercells"): + case v1alpha1.SchemeGroupVersion.WithResource("brokercells"): return &genericInformer{resource: resource.GroupResource(), informer: f.Internal().V1alpha1().BrokerCells().Informer()}, nil - case inteventsv1alpha1.SchemeGroupVersion.WithResource("pullsubscriptions"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Internal().V1alpha1().PullSubscriptions().Informer()}, nil - case inteventsv1alpha1.SchemeGroupVersion.WithResource("topics"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Internal().V1alpha1().Topics().Informer()}, nil // Group=internal.events.cloud.google.com, Version=v1beta1 case inteventsv1beta1.SchemeGroupVersion.WithResource("pullsubscriptions"): diff --git a/pkg/client/informers/externalversions/intevents/v1alpha1/interface.go b/pkg/client/informers/externalversions/intevents/v1alpha1/interface.go index d163f2bc76..773635b154 100644 --- a/pkg/client/informers/externalversions/intevents/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/intevents/v1alpha1/interface.go @@ -26,10 +26,6 @@ import ( type Interface interface { // BrokerCells returns a BrokerCellInformer. BrokerCells() BrokerCellInformer - // PullSubscriptions returns a PullSubscriptionInformer. - PullSubscriptions() PullSubscriptionInformer - // Topics returns a TopicInformer. - Topics() TopicInformer } type version struct { @@ -47,13 +43,3 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList func (v *version) BrokerCells() BrokerCellInformer { return &brokerCellInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } - -// PullSubscriptions returns a PullSubscriptionInformer. -func (v *version) PullSubscriptions() PullSubscriptionInformer { - return &pullSubscriptionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// Topics returns a TopicInformer. -func (v *version) Topics() TopicInformer { - return &topicInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/client/informers/externalversions/intevents/v1alpha1/pullsubscription.go b/pkg/client/informers/externalversions/intevents/v1alpha1/pullsubscription.go deleted file mode 100644 index dd513d32ac..0000000000 --- a/pkg/client/informers/externalversions/intevents/v1alpha1/pullsubscription.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - time "time" - - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - versioned "github.com/google/knative-gcp/pkg/client/clientset/versioned" - internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/google/knative-gcp/pkg/client/listers/intevents/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" -) - -// PullSubscriptionInformer provides access to a shared informer and lister for -// PullSubscriptions. -type PullSubscriptionInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.PullSubscriptionLister -} - -type pullSubscriptionInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewPullSubscriptionInformer constructs a new informer for PullSubscription 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 NewPullSubscriptionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredPullSubscriptionInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredPullSubscriptionInformer constructs a new informer for PullSubscription 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 NewFilteredPullSubscriptionInformer(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.InternalV1alpha1().PullSubscriptions(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.InternalV1alpha1().PullSubscriptions(namespace).Watch(context.TODO(), options) - }, - }, - &inteventsv1alpha1.PullSubscription{}, - resyncPeriod, - indexers, - ) -} - -func (f *pullSubscriptionInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredPullSubscriptionInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *pullSubscriptionInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&inteventsv1alpha1.PullSubscription{}, f.defaultInformer) -} - -func (f *pullSubscriptionInformer) Lister() v1alpha1.PullSubscriptionLister { - return v1alpha1.NewPullSubscriptionLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/informers/externalversions/intevents/v1alpha1/topic.go b/pkg/client/informers/externalversions/intevents/v1alpha1/topic.go deleted file mode 100644 index 071491e9b5..0000000000 --- a/pkg/client/informers/externalversions/intevents/v1alpha1/topic.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2020 Google LLC - -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 ( - "context" - time "time" - - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - versioned "github.com/google/knative-gcp/pkg/client/clientset/versioned" - internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/google/knative-gcp/pkg/client/listers/intevents/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" -) - -// TopicInformer provides access to a shared informer and lister for -// Topics. -type TopicInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.TopicLister -} - -type topicInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewTopicInformer constructs a new informer for Topic 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 NewTopicInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredTopicInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredTopicInformer constructs a new informer for Topic 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 NewFilteredTopicInformer(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.InternalV1alpha1().Topics(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.InternalV1alpha1().Topics(namespace).Watch(context.TODO(), options) - }, - }, - &inteventsv1alpha1.Topic{}, - resyncPeriod, - indexers, - ) -} - -func (f *topicInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredTopicInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *topicInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&inteventsv1alpha1.Topic{}, f.defaultInformer) -} - -func (f *topicInformer) Lister() v1alpha1.TopicLister { - return v1alpha1.NewTopicLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource/cloudauditlogssource.go b/pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource/cloudauditlogssource.go deleted file mode 100644 index d6a3680343..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource/cloudauditlogssource.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package cloudauditlogssource - -import ( - context "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1" - factory "github.com/google/knative-gcp/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Events().V1alpha1().CloudAuditLogsSources() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.CloudAuditLogsSourceInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1.CloudAuditLogsSourceInformer from context.") - } - return untyped.(v1alpha1.CloudAuditLogsSourceInformer) -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource/fake/fake.go b/pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource/fake/fake.go deleted file mode 100644 index 3f14627b90..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - cloudauditlogssource "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource" - fake "github.com/google/knative-gcp/pkg/client/injection/informers/factory/fake" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = cloudauditlogssource.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Events().V1alpha1().CloudAuditLogsSources() - return context.WithValue(ctx, cloudauditlogssource.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudbuildsource/cloudbuildsource.go b/pkg/client/injection/informers/events/v1alpha1/cloudbuildsource/cloudbuildsource.go deleted file mode 100644 index ab40108bda..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudbuildsource/cloudbuildsource.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package cloudbuildsource - -import ( - context "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1" - factory "github.com/google/knative-gcp/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Events().V1alpha1().CloudBuildSources() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.CloudBuildSourceInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1.CloudBuildSourceInformer from context.") - } - return untyped.(v1alpha1.CloudBuildSourceInformer) -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudbuildsource/fake/fake.go b/pkg/client/injection/informers/events/v1alpha1/cloudbuildsource/fake/fake.go deleted file mode 100644 index a2002e1ddc..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudbuildsource/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - cloudbuildsource "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudbuildsource" - fake "github.com/google/knative-gcp/pkg/client/injection/informers/factory/fake" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = cloudbuildsource.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Events().V1alpha1().CloudBuildSources() - return context.WithValue(ctx, cloudbuildsource.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource/cloudpubsubsource.go b/pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource/cloudpubsubsource.go deleted file mode 100644 index 1c0d963cfc..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource/cloudpubsubsource.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package cloudpubsubsource - -import ( - context "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1" - factory "github.com/google/knative-gcp/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Events().V1alpha1().CloudPubSubSources() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.CloudPubSubSourceInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1.CloudPubSubSourceInformer from context.") - } - return untyped.(v1alpha1.CloudPubSubSourceInformer) -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource/fake/fake.go b/pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource/fake/fake.go deleted file mode 100644 index 584b215002..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - cloudpubsubsource "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource" - fake "github.com/google/knative-gcp/pkg/client/injection/informers/factory/fake" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = cloudpubsubsource.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Events().V1alpha1().CloudPubSubSources() - return context.WithValue(ctx, cloudpubsubsource.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudschedulersource/cloudschedulersource.go b/pkg/client/injection/informers/events/v1alpha1/cloudschedulersource/cloudschedulersource.go deleted file mode 100644 index 8852882d49..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudschedulersource/cloudschedulersource.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package cloudschedulersource - -import ( - context "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1" - factory "github.com/google/knative-gcp/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Events().V1alpha1().CloudSchedulerSources() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.CloudSchedulerSourceInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1.CloudSchedulerSourceInformer from context.") - } - return untyped.(v1alpha1.CloudSchedulerSourceInformer) -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudschedulersource/fake/fake.go b/pkg/client/injection/informers/events/v1alpha1/cloudschedulersource/fake/fake.go deleted file mode 100644 index b00fc842f3..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudschedulersource/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - cloudschedulersource "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudschedulersource" - fake "github.com/google/knative-gcp/pkg/client/injection/informers/factory/fake" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = cloudschedulersource.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Events().V1alpha1().CloudSchedulerSources() - return context.WithValue(ctx, cloudschedulersource.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudstoragesource/cloudstoragesource.go b/pkg/client/injection/informers/events/v1alpha1/cloudstoragesource/cloudstoragesource.go deleted file mode 100644 index a635aa97a1..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudstoragesource/cloudstoragesource.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package cloudstoragesource - -import ( - context "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1" - factory "github.com/google/knative-gcp/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Events().V1alpha1().CloudStorageSources() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.CloudStorageSourceInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1alpha1.CloudStorageSourceInformer from context.") - } - return untyped.(v1alpha1.CloudStorageSourceInformer) -} diff --git a/pkg/client/injection/informers/events/v1alpha1/cloudstoragesource/fake/fake.go b/pkg/client/injection/informers/events/v1alpha1/cloudstoragesource/fake/fake.go deleted file mode 100644 index ea63cb712a..0000000000 --- a/pkg/client/injection/informers/events/v1alpha1/cloudstoragesource/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - cloudstoragesource "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudstoragesource" - fake "github.com/google/knative-gcp/pkg/client/injection/informers/factory/fake" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = cloudstoragesource.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Events().V1alpha1().CloudStorageSources() - return context.WithValue(ctx, cloudstoragesource.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake/fake.go b/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake/fake.go deleted file mode 100644 index e673468f07..0000000000 --- a/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - fake "github.com/google/knative-gcp/pkg/client/injection/informers/factory/fake" - pullsubscription "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = pullsubscription.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Internal().V1alpha1().PullSubscriptions() - return context.WithValue(ctx, pullsubscription.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/pullsubscription.go b/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/pullsubscription.go deleted file mode 100644 index e779ea805d..0000000000 --- a/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/pullsubscription.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package pullsubscription - -import ( - context "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/intevents/v1alpha1" - factory "github.com/google/knative-gcp/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Internal().V1alpha1().PullSubscriptions() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.PullSubscriptionInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/google/knative-gcp/pkg/client/informers/externalversions/intevents/v1alpha1.PullSubscriptionInformer from context.") - } - return untyped.(v1alpha1.PullSubscriptionInformer) -} diff --git a/pkg/client/injection/informers/intevents/v1alpha1/topic/fake/fake.go b/pkg/client/injection/informers/intevents/v1alpha1/topic/fake/fake.go deleted file mode 100644 index 61d71f0297..0000000000 --- a/pkg/client/injection/informers/intevents/v1alpha1/topic/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - fake "github.com/google/knative-gcp/pkg/client/injection/informers/factory/fake" - topic "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = topic.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Internal().V1alpha1().Topics() - return context.WithValue(ctx, topic.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/intevents/v1alpha1/topic/topic.go b/pkg/client/injection/informers/intevents/v1alpha1/topic/topic.go deleted file mode 100644 index 8c836f230d..0000000000 --- a/pkg/client/injection/informers/intevents/v1alpha1/topic/topic.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package topic - -import ( - context "context" - - v1alpha1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/intevents/v1alpha1" - factory "github.com/google/knative-gcp/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Internal().V1alpha1().Topics() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.TopicInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch github.com/google/knative-gcp/pkg/client/informers/externalversions/intevents/v1alpha1.TopicInformer from context.") - } - return untyped.(v1alpha1.TopicInformer) -} diff --git a/pkg/client/listers/events/v1alpha1/cloudauditlogssource.go b/pkg/client/listers/events/v1alpha1/cloudauditlogssource.go deleted file mode 100644 index b8825e67c9..0000000000 --- a/pkg/client/listers/events/v1alpha1/cloudauditlogssource.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/knative-gcp/pkg/apis/events/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// CloudAuditLogsSourceLister helps list CloudAuditLogsSources. -type CloudAuditLogsSourceLister interface { - // List lists all CloudAuditLogsSources in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.CloudAuditLogsSource, err error) - // CloudAuditLogsSources returns an object that can list and get CloudAuditLogsSources. - CloudAuditLogsSources(namespace string) CloudAuditLogsSourceNamespaceLister - CloudAuditLogsSourceListerExpansion -} - -// cloudAuditLogsSourceLister implements the CloudAuditLogsSourceLister interface. -type cloudAuditLogsSourceLister struct { - indexer cache.Indexer -} - -// NewCloudAuditLogsSourceLister returns a new CloudAuditLogsSourceLister. -func NewCloudAuditLogsSourceLister(indexer cache.Indexer) CloudAuditLogsSourceLister { - return &cloudAuditLogsSourceLister{indexer: indexer} -} - -// List lists all CloudAuditLogsSources in the indexer. -func (s *cloudAuditLogsSourceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudAuditLogsSource, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudAuditLogsSource)) - }) - return ret, err -} - -// CloudAuditLogsSources returns an object that can list and get CloudAuditLogsSources. -func (s *cloudAuditLogsSourceLister) CloudAuditLogsSources(namespace string) CloudAuditLogsSourceNamespaceLister { - return cloudAuditLogsSourceNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// CloudAuditLogsSourceNamespaceLister helps list and get CloudAuditLogsSources. -type CloudAuditLogsSourceNamespaceLister interface { - // List lists all CloudAuditLogsSources in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.CloudAuditLogsSource, err error) - // Get retrieves the CloudAuditLogsSource from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.CloudAuditLogsSource, error) - CloudAuditLogsSourceNamespaceListerExpansion -} - -// cloudAuditLogsSourceNamespaceLister implements the CloudAuditLogsSourceNamespaceLister -// interface. -type cloudAuditLogsSourceNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all CloudAuditLogsSources in the indexer for a given namespace. -func (s cloudAuditLogsSourceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudAuditLogsSource, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudAuditLogsSource)) - }) - return ret, err -} - -// Get retrieves the CloudAuditLogsSource from the indexer for a given namespace and name. -func (s cloudAuditLogsSourceNamespaceLister) Get(name string) (*v1alpha1.CloudAuditLogsSource, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("cloudauditlogssource"), name) - } - return obj.(*v1alpha1.CloudAuditLogsSource), nil -} diff --git a/pkg/client/listers/events/v1alpha1/cloudbuildsource.go b/pkg/client/listers/events/v1alpha1/cloudbuildsource.go deleted file mode 100644 index 4554d4b643..0000000000 --- a/pkg/client/listers/events/v1alpha1/cloudbuildsource.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/knative-gcp/pkg/apis/events/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// CloudBuildSourceLister helps list CloudBuildSources. -type CloudBuildSourceLister interface { - // List lists all CloudBuildSources in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.CloudBuildSource, err error) - // CloudBuildSources returns an object that can list and get CloudBuildSources. - CloudBuildSources(namespace string) CloudBuildSourceNamespaceLister - CloudBuildSourceListerExpansion -} - -// cloudBuildSourceLister implements the CloudBuildSourceLister interface. -type cloudBuildSourceLister struct { - indexer cache.Indexer -} - -// NewCloudBuildSourceLister returns a new CloudBuildSourceLister. -func NewCloudBuildSourceLister(indexer cache.Indexer) CloudBuildSourceLister { - return &cloudBuildSourceLister{indexer: indexer} -} - -// List lists all CloudBuildSources in the indexer. -func (s *cloudBuildSourceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudBuildSource, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudBuildSource)) - }) - return ret, err -} - -// CloudBuildSources returns an object that can list and get CloudBuildSources. -func (s *cloudBuildSourceLister) CloudBuildSources(namespace string) CloudBuildSourceNamespaceLister { - return cloudBuildSourceNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// CloudBuildSourceNamespaceLister helps list and get CloudBuildSources. -type CloudBuildSourceNamespaceLister interface { - // List lists all CloudBuildSources in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.CloudBuildSource, err error) - // Get retrieves the CloudBuildSource from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.CloudBuildSource, error) - CloudBuildSourceNamespaceListerExpansion -} - -// cloudBuildSourceNamespaceLister implements the CloudBuildSourceNamespaceLister -// interface. -type cloudBuildSourceNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all CloudBuildSources in the indexer for a given namespace. -func (s cloudBuildSourceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudBuildSource, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudBuildSource)) - }) - return ret, err -} - -// Get retrieves the CloudBuildSource from the indexer for a given namespace and name. -func (s cloudBuildSourceNamespaceLister) Get(name string) (*v1alpha1.CloudBuildSource, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("cloudbuildsource"), name) - } - return obj.(*v1alpha1.CloudBuildSource), nil -} diff --git a/pkg/client/listers/events/v1alpha1/cloudpubsubsource.go b/pkg/client/listers/events/v1alpha1/cloudpubsubsource.go deleted file mode 100644 index d1b2071555..0000000000 --- a/pkg/client/listers/events/v1alpha1/cloudpubsubsource.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/knative-gcp/pkg/apis/events/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// CloudPubSubSourceLister helps list CloudPubSubSources. -type CloudPubSubSourceLister interface { - // List lists all CloudPubSubSources in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.CloudPubSubSource, err error) - // CloudPubSubSources returns an object that can list and get CloudPubSubSources. - CloudPubSubSources(namespace string) CloudPubSubSourceNamespaceLister - CloudPubSubSourceListerExpansion -} - -// cloudPubSubSourceLister implements the CloudPubSubSourceLister interface. -type cloudPubSubSourceLister struct { - indexer cache.Indexer -} - -// NewCloudPubSubSourceLister returns a new CloudPubSubSourceLister. -func NewCloudPubSubSourceLister(indexer cache.Indexer) CloudPubSubSourceLister { - return &cloudPubSubSourceLister{indexer: indexer} -} - -// List lists all CloudPubSubSources in the indexer. -func (s *cloudPubSubSourceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudPubSubSource, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudPubSubSource)) - }) - return ret, err -} - -// CloudPubSubSources returns an object that can list and get CloudPubSubSources. -func (s *cloudPubSubSourceLister) CloudPubSubSources(namespace string) CloudPubSubSourceNamespaceLister { - return cloudPubSubSourceNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// CloudPubSubSourceNamespaceLister helps list and get CloudPubSubSources. -type CloudPubSubSourceNamespaceLister interface { - // List lists all CloudPubSubSources in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.CloudPubSubSource, err error) - // Get retrieves the CloudPubSubSource from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.CloudPubSubSource, error) - CloudPubSubSourceNamespaceListerExpansion -} - -// cloudPubSubSourceNamespaceLister implements the CloudPubSubSourceNamespaceLister -// interface. -type cloudPubSubSourceNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all CloudPubSubSources in the indexer for a given namespace. -func (s cloudPubSubSourceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudPubSubSource, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudPubSubSource)) - }) - return ret, err -} - -// Get retrieves the CloudPubSubSource from the indexer for a given namespace and name. -func (s cloudPubSubSourceNamespaceLister) Get(name string) (*v1alpha1.CloudPubSubSource, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("cloudpubsubsource"), name) - } - return obj.(*v1alpha1.CloudPubSubSource), nil -} diff --git a/pkg/client/listers/events/v1alpha1/cloudschedulersource.go b/pkg/client/listers/events/v1alpha1/cloudschedulersource.go deleted file mode 100644 index c6d16eb7d7..0000000000 --- a/pkg/client/listers/events/v1alpha1/cloudschedulersource.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/knative-gcp/pkg/apis/events/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// CloudSchedulerSourceLister helps list CloudSchedulerSources. -type CloudSchedulerSourceLister interface { - // List lists all CloudSchedulerSources in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.CloudSchedulerSource, err error) - // CloudSchedulerSources returns an object that can list and get CloudSchedulerSources. - CloudSchedulerSources(namespace string) CloudSchedulerSourceNamespaceLister - CloudSchedulerSourceListerExpansion -} - -// cloudSchedulerSourceLister implements the CloudSchedulerSourceLister interface. -type cloudSchedulerSourceLister struct { - indexer cache.Indexer -} - -// NewCloudSchedulerSourceLister returns a new CloudSchedulerSourceLister. -func NewCloudSchedulerSourceLister(indexer cache.Indexer) CloudSchedulerSourceLister { - return &cloudSchedulerSourceLister{indexer: indexer} -} - -// List lists all CloudSchedulerSources in the indexer. -func (s *cloudSchedulerSourceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudSchedulerSource, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudSchedulerSource)) - }) - return ret, err -} - -// CloudSchedulerSources returns an object that can list and get CloudSchedulerSources. -func (s *cloudSchedulerSourceLister) CloudSchedulerSources(namespace string) CloudSchedulerSourceNamespaceLister { - return cloudSchedulerSourceNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// CloudSchedulerSourceNamespaceLister helps list and get CloudSchedulerSources. -type CloudSchedulerSourceNamespaceLister interface { - // List lists all CloudSchedulerSources in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.CloudSchedulerSource, err error) - // Get retrieves the CloudSchedulerSource from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.CloudSchedulerSource, error) - CloudSchedulerSourceNamespaceListerExpansion -} - -// cloudSchedulerSourceNamespaceLister implements the CloudSchedulerSourceNamespaceLister -// interface. -type cloudSchedulerSourceNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all CloudSchedulerSources in the indexer for a given namespace. -func (s cloudSchedulerSourceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudSchedulerSource, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudSchedulerSource)) - }) - return ret, err -} - -// Get retrieves the CloudSchedulerSource from the indexer for a given namespace and name. -func (s cloudSchedulerSourceNamespaceLister) Get(name string) (*v1alpha1.CloudSchedulerSource, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("cloudschedulersource"), name) - } - return obj.(*v1alpha1.CloudSchedulerSource), nil -} diff --git a/pkg/client/listers/events/v1alpha1/cloudstoragesource.go b/pkg/client/listers/events/v1alpha1/cloudstoragesource.go deleted file mode 100644 index 377e964e19..0000000000 --- a/pkg/client/listers/events/v1alpha1/cloudstoragesource.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/knative-gcp/pkg/apis/events/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// CloudStorageSourceLister helps list CloudStorageSources. -type CloudStorageSourceLister interface { - // List lists all CloudStorageSources in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.CloudStorageSource, err error) - // CloudStorageSources returns an object that can list and get CloudStorageSources. - CloudStorageSources(namespace string) CloudStorageSourceNamespaceLister - CloudStorageSourceListerExpansion -} - -// cloudStorageSourceLister implements the CloudStorageSourceLister interface. -type cloudStorageSourceLister struct { - indexer cache.Indexer -} - -// NewCloudStorageSourceLister returns a new CloudStorageSourceLister. -func NewCloudStorageSourceLister(indexer cache.Indexer) CloudStorageSourceLister { - return &cloudStorageSourceLister{indexer: indexer} -} - -// List lists all CloudStorageSources in the indexer. -func (s *cloudStorageSourceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudStorageSource, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudStorageSource)) - }) - return ret, err -} - -// CloudStorageSources returns an object that can list and get CloudStorageSources. -func (s *cloudStorageSourceLister) CloudStorageSources(namespace string) CloudStorageSourceNamespaceLister { - return cloudStorageSourceNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// CloudStorageSourceNamespaceLister helps list and get CloudStorageSources. -type CloudStorageSourceNamespaceLister interface { - // List lists all CloudStorageSources in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.CloudStorageSource, err error) - // Get retrieves the CloudStorageSource from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.CloudStorageSource, error) - CloudStorageSourceNamespaceListerExpansion -} - -// cloudStorageSourceNamespaceLister implements the CloudStorageSourceNamespaceLister -// interface. -type cloudStorageSourceNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all CloudStorageSources in the indexer for a given namespace. -func (s cloudStorageSourceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.CloudStorageSource, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.CloudStorageSource)) - }) - return ret, err -} - -// Get retrieves the CloudStorageSource from the indexer for a given namespace and name. -func (s cloudStorageSourceNamespaceLister) Get(name string) (*v1alpha1.CloudStorageSource, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("cloudstoragesource"), name) - } - return obj.(*v1alpha1.CloudStorageSource), nil -} diff --git a/pkg/client/listers/intevents/v1alpha1/expansion_generated.go b/pkg/client/listers/intevents/v1alpha1/expansion_generated.go index 5d47893750..00670ea4fb 100644 --- a/pkg/client/listers/intevents/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/intevents/v1alpha1/expansion_generated.go @@ -25,19 +25,3 @@ type BrokerCellListerExpansion interface{} // BrokerCellNamespaceListerExpansion allows custom methods to be added to // BrokerCellNamespaceLister. type BrokerCellNamespaceListerExpansion interface{} - -// PullSubscriptionListerExpansion allows custom methods to be added to -// PullSubscriptionLister. -type PullSubscriptionListerExpansion interface{} - -// PullSubscriptionNamespaceListerExpansion allows custom methods to be added to -// PullSubscriptionNamespaceLister. -type PullSubscriptionNamespaceListerExpansion interface{} - -// TopicListerExpansion allows custom methods to be added to -// TopicLister. -type TopicListerExpansion interface{} - -// TopicNamespaceListerExpansion allows custom methods to be added to -// TopicNamespaceLister. -type TopicNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/intevents/v1alpha1/pullsubscription.go b/pkg/client/listers/intevents/v1alpha1/pullsubscription.go deleted file mode 100644 index fefe31a2ec..0000000000 --- a/pkg/client/listers/intevents/v1alpha1/pullsubscription.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// PullSubscriptionLister helps list PullSubscriptions. -type PullSubscriptionLister interface { - // List lists all PullSubscriptions in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.PullSubscription, err error) - // PullSubscriptions returns an object that can list and get PullSubscriptions. - PullSubscriptions(namespace string) PullSubscriptionNamespaceLister - PullSubscriptionListerExpansion -} - -// pullSubscriptionLister implements the PullSubscriptionLister interface. -type pullSubscriptionLister struct { - indexer cache.Indexer -} - -// NewPullSubscriptionLister returns a new PullSubscriptionLister. -func NewPullSubscriptionLister(indexer cache.Indexer) PullSubscriptionLister { - return &pullSubscriptionLister{indexer: indexer} -} - -// List lists all PullSubscriptions in the indexer. -func (s *pullSubscriptionLister) List(selector labels.Selector) (ret []*v1alpha1.PullSubscription, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.PullSubscription)) - }) - return ret, err -} - -// PullSubscriptions returns an object that can list and get PullSubscriptions. -func (s *pullSubscriptionLister) PullSubscriptions(namespace string) PullSubscriptionNamespaceLister { - return pullSubscriptionNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// PullSubscriptionNamespaceLister helps list and get PullSubscriptions. -type PullSubscriptionNamespaceLister interface { - // List lists all PullSubscriptions in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.PullSubscription, err error) - // Get retrieves the PullSubscription from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.PullSubscription, error) - PullSubscriptionNamespaceListerExpansion -} - -// pullSubscriptionNamespaceLister implements the PullSubscriptionNamespaceLister -// interface. -type pullSubscriptionNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all PullSubscriptions in the indexer for a given namespace. -func (s pullSubscriptionNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.PullSubscription, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.PullSubscription)) - }) - return ret, err -} - -// Get retrieves the PullSubscription from the indexer for a given namespace and name. -func (s pullSubscriptionNamespaceLister) Get(name string) (*v1alpha1.PullSubscription, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("pullsubscription"), name) - } - return obj.(*v1alpha1.PullSubscription), nil -} diff --git a/pkg/client/listers/intevents/v1alpha1/topic.go b/pkg/client/listers/intevents/v1alpha1/topic.go deleted file mode 100644 index b49a0d6e8f..0000000000 --- a/pkg/client/listers/intevents/v1alpha1/topic.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 Google LLC - -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/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// TopicLister helps list Topics. -type TopicLister interface { - // List lists all Topics in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.Topic, err error) - // Topics returns an object that can list and get Topics. - Topics(namespace string) TopicNamespaceLister - TopicListerExpansion -} - -// topicLister implements the TopicLister interface. -type topicLister struct { - indexer cache.Indexer -} - -// NewTopicLister returns a new TopicLister. -func NewTopicLister(indexer cache.Indexer) TopicLister { - return &topicLister{indexer: indexer} -} - -// List lists all Topics in the indexer. -func (s *topicLister) List(selector labels.Selector) (ret []*v1alpha1.Topic, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Topic)) - }) - return ret, err -} - -// Topics returns an object that can list and get Topics. -func (s *topicLister) Topics(namespace string) TopicNamespaceLister { - return topicNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// TopicNamespaceLister helps list and get Topics. -type TopicNamespaceLister interface { - // List lists all Topics in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.Topic, err error) - // Get retrieves the Topic from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.Topic, error) - TopicNamespaceListerExpansion -} - -// topicNamespaceLister implements the TopicNamespaceLister -// interface. -type topicNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Topics in the indexer for a given namespace. -func (s topicNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Topic, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Topic)) - }) - return ret, err -} - -// Get retrieves the Topic from the indexer for a given namespace and name. -func (s topicNamespaceLister) Get(name string) (*v1alpha1.Topic, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("topic"), name) - } - return obj.(*v1alpha1.Topic), nil -} diff --git a/pkg/reconciler/deployment/deployment_test.go b/pkg/reconciler/deployment/deployment_test.go index 08309bc7fb..72bece8f62 100644 --- a/pkg/reconciler/deployment/deployment_test.go +++ b/pkg/reconciler/deployment/deployment_test.go @@ -26,7 +26,7 @@ import ( "k8s.io/client-go/kubernetes/scheme" clientgotesting "k8s.io/client-go/testing" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" "github.com/google/knative-gcp/pkg/reconciler" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" @@ -42,7 +42,7 @@ const ( func init() { // Add types to scheme - _ = v1alpha1.AddToScheme(scheme.Scheme) + _ = v1beta1.AddToScheme(scheme.Scheme) } func TestAllCases(t *testing.T) { diff --git a/pkg/reconciler/testing/v1alpha1/auditlogs.go b/pkg/reconciler/testing/v1alpha1/auditlogs.go deleted file mode 100644 index 5b91b008ec..0000000000 --- a/pkg/reconciler/testing/v1alpha1/auditlogs.go +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright 2020 Google LLC. - -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/knative-gcp/pkg/reconciler/testing" - - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -type CloudAuditLogsSourceOption func(*v1alpha1.CloudAuditLogsSource) - -func NewCloudAuditLogsSource(name, namespace string, opts ...CloudAuditLogsSourceOption) *v1alpha1.CloudAuditLogsSource { - cal := &v1alpha1.CloudAuditLogsSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - } - for _, opt := range opts { - opt(cal) - } - return cal -} - -func WithCloudAuditLogsSourceSink(gvk metav1.GroupVersionKind, name string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { - s.Spec.Sink = duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: testing.ApiVersion(gvk), - Kind: gvk.Kind, - Name: name, - }, - } - } -} - -func WithCloudAuditLogsSourceProject(project string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { - s.Spec.Project = project - } -} - -func WithCloudAuditLogsSourceResourceName(resourceName string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { - s.Spec.ResourceName = resourceName - } -} - -func WithCloudAuditLogsSourceServiceName(serviceName string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { - s.Spec.ServiceName = serviceName - } -} - -func WithCloudAuditLogsSourceServiceAccount(kServiceAccount string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { - s.Spec.ServiceAccountName = kServiceAccount - } -} - -func WithCloudAuditLogsSourceMethodName(methodName string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { - s.Spec.MethodName = methodName - } -} diff --git a/pkg/reconciler/testing/v1alpha1/build.go b/pkg/reconciler/testing/v1alpha1/build.go deleted file mode 100644 index 1dc9cddab8..0000000000 --- a/pkg/reconciler/testing/v1alpha1/build.go +++ /dev/null @@ -1,63 +0,0 @@ -/* -Copyright 2019 Google LLC - -Licensed under the Apache License, Veroute.on 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/knative-gcp/pkg/reconciler/testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" -) - -// CloudBuildSourceOption enables further configuration of a CloudBuildSource. -type CloudBuildSourceOption func(*v1alpha1.CloudBuildSource) - -// NewCloudBuildSource creates a CloudBuildSource with CloudBuildSourceOptions -func NewCloudBuildSource(name, namespace string, so ...CloudBuildSourceOption) *v1alpha1.CloudBuildSource { - bs := &v1alpha1.CloudBuildSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - UID: "test-build-uid", - }, - } - for _, opt := range so { - opt(bs) - } - return bs -} - -func WithCloudBuildSourceSink(gvk metav1.GroupVersionKind, name string) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { - bs.Spec.Sink = duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: testing.ApiVersion(gvk), - Kind: gvk.Kind, - Name: name, - }, - } - } -} - -func WithCloudBuildSourceServiceAccount(kServiceAccount string) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { - bs.Spec.ServiceAccountName = kServiceAccount - } -} diff --git a/pkg/reconciler/testing/v1alpha1/pubsub.go b/pkg/reconciler/testing/v1alpha1/pubsub.go deleted file mode 100644 index 57dc3f6381..0000000000 --- a/pkg/reconciler/testing/v1alpha1/pubsub.go +++ /dev/null @@ -1,68 +0,0 @@ -/* -Copyright 2020 Google LLC. - -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/knative-gcp/pkg/reconciler/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" -) - -// CloudPubSubSourceOption enables further configuration of a CloudPubSubSource. -type CloudPubSubSourceOption func(*v1alpha1.CloudPubSubSource) - -// NewCloudPubSubSource creates a CloudPubSubSource with CloudPubSubSourceOptions -func NewCloudPubSubSource(name, namespace string, so ...CloudPubSubSourceOption) *v1alpha1.CloudPubSubSource { - ps := &v1alpha1.CloudPubSubSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - UID: "test-pubsub-uid", - }, - } - for _, opt := range so { - opt(ps) - } - return ps -} - -func WithCloudPubSubSourceSink(gvk metav1.GroupVersionKind, name string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { - ps.Spec.Sink = duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: testing.ApiVersion(gvk), - Kind: gvk.Kind, - Name: name, - }, - } - } -} - -func WithCloudPubSubSourceServiceAccount(kServiceAccount string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { - ps.Spec.ServiceAccountName = kServiceAccount - } -} - -func WithCloudPubSubSourceTopic(topicID string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { - ps.Spec.Topic = topicID - } -} diff --git a/pkg/reconciler/testing/v1alpha1/pullsubscription.go b/pkg/reconciler/testing/v1alpha1/pullsubscription.go deleted file mode 100644 index 5fe40275dd..0000000000 --- a/pkg/reconciler/testing/v1alpha1/pullsubscription.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2020 Google LLC. - -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/knative-gcp/pkg/reconciler/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" -) - -// PullSubscriptionOption enables further configuration of a PullSubscription. -type PullSubscriptionOption func(*v1alpha1.PullSubscription) - -const ( - SubscriptionID = "subID" -) - -// NewPullSubscription creates a PullSubscription with PullSubscriptionOptions -func NewPullSubscription(name, namespace string, so ...PullSubscriptionOption) *v1alpha1.PullSubscription { - s := &v1alpha1.PullSubscription{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - } - for _, opt := range so { - opt(s) - } - return s -} - -func WithPullSubscriptionSink(gvk metav1.GroupVersionKind, name string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { - s.Spec.Sink = duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: testing.ApiVersion(gvk), - Kind: gvk.Kind, - Name: name, - }, - } - } -} - -func WithPullSubscriptionSpec(spec v1alpha1.PullSubscriptionSpec) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { - s.Spec = spec - } -} - -func WithPullSubscriptionTopic(topicID string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { - s.Spec.Topic = topicID - } -} - -func WithPullSubscriptionServiceAccount(kServiceAccount string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { - s.Spec.ServiceAccountName = kServiceAccount - } -} diff --git a/pkg/reconciler/testing/v1alpha1/scheduler.go b/pkg/reconciler/testing/v1alpha1/scheduler.go deleted file mode 100644 index a860a0288d..0000000000 --- a/pkg/reconciler/testing/v1alpha1/scheduler.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright 2020 Google LLC. - -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/knative-gcp/pkg/reconciler/testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" -) - -// CloudSchedulerSourceOption enables further configuration of a CloudSchedulerSource. -type CloudSchedulerSourceOption func(*v1alpha1.CloudSchedulerSource) - -// NewCloudSchedulerSource creates a CloudSchedulerSource with CloudSchedulerSourceOptions -func NewCloudSchedulerSource(name, namespace string, so ...CloudSchedulerSourceOption) *v1alpha1.CloudSchedulerSource { - s := &v1alpha1.CloudSchedulerSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - UID: "test-scheduler-uid", - }, - } - for _, opt := range so { - opt(s) - } - return s -} - -func WithCloudSchedulerSourceSink(gvk metav1.GroupVersionKind, name string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { - s.Spec.Sink = duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: testing.ApiVersion(gvk), - Kind: gvk.Kind, - Name: name, - }, - } - } -} - -func WithCloudSchedulerSourceLocation(location string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { - s.Spec.Location = location - } -} - -func WithCloudSchedulerSourceSchedule(schedule string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { - s.Spec.Schedule = schedule - } -} - -func WithCloudSchedulerSourceServiceAccount(kServiceAccount string) CloudSchedulerSourceOption { - return func(ps *v1alpha1.CloudSchedulerSource) { - ps.Spec.ServiceAccountName = kServiceAccount - } -} - -func WithCloudSchedulerSourceData(data string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { - s.Spec.Data = data - } -} diff --git a/pkg/reconciler/testing/v1alpha1/storage.go b/pkg/reconciler/testing/v1alpha1/storage.go deleted file mode 100644 index 9bf8d5096d..0000000000 --- a/pkg/reconciler/testing/v1alpha1/storage.go +++ /dev/null @@ -1,238 +0,0 @@ -/* -Copyright 2020 Google LLC. - -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 ( - "time" - - gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - reconcilertesting "github.com/google/knative-gcp/pkg/reconciler/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - - "github.com/google/knative-gcp/pkg/apis/duck" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - "github.com/google/knative-gcp/pkg/gclient/metadata/testing" -) - -// CloudStorageSourceOption enables further configuration of a CloudStorageSource. -type CloudStorageSourceOption func(*v1alpha1.CloudStorageSource) - -// NewCloudStorageSource creates a CloudStorageSource with CloudStorageSourceOptions -func NewCloudStorageSource(name, namespace string, so ...CloudStorageSourceOption) *v1alpha1.CloudStorageSource { - s := &v1alpha1.CloudStorageSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - UID: "test-storage-uid", - Annotations: map[string]string{ - duck.ClusterNameAnnotation: testing.FakeClusterName, - }, - }, - } - for _, opt := range so { - opt(s) - } - return s -} - -func WithCloudStorageSourceBucket(bucket string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Spec.Bucket = bucket - } -} - -func WithCloudStorageSourceProject(project string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Spec.Project = project - } -} - -func WithCloudStorageSourceEventTypes(eventTypes []string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Spec.EventTypes = eventTypes - } -} - -func WithCloudStorageSourceSink(gvk metav1.GroupVersionKind, name string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Spec.Sink = duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: reconcilertesting.ApiVersion(gvk), - Kind: gvk.Kind, - Name: name, - }, - } - } -} - -func WithCloudStorageSourceSinkDestination(sink duckv1.Destination) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Spec.Sink = sink - } -} - -// WithInitCloudStorageSourceConditions initializes the CloudStorageSources's conditions. -func WithInitCloudStorageSourceConditions(s *v1alpha1.CloudStorageSource) { - s.Status.InitializeConditions() -} - -// WithCloudStorageSourceServiceAccountName will give status.ServiceAccountName a k8s service account name, which is related on Workload Identity's Google service account. -func WithCloudStorageSourceServiceAccountName(name string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.ServiceAccountName = name - } -} - -func WithCloudStorageSourceWorkloadIdentityFailed(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.MarkWorkloadIdentityFailed(s.ConditionSet(), reason, message) - } -} - -func WithCloudStorageSourceServiceAccount(kServiceAccount string) CloudStorageSourceOption { - return func(ps *v1alpha1.CloudStorageSource) { - ps.Spec.ServiceAccountName = kServiceAccount - } -} - -// WithCloudStorageSourceTopicFailed marks the condition that the -// topic is False -func WithCloudStorageSourceTopicFailed(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.MarkTopicFailed(s.ConditionSet(), reason, message) - } -} - -// WithCloudStorageSourceTopicUnknown marks the condition that the -// topic is False -func WithCloudStorageSourceTopicUnknown(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.MarkTopicUnknown(s.ConditionSet(), reason, message) - } -} - -// WithCloudStorageSourceTopicNotReady marks the condition that the -// topic is not ready -func WithCloudStorageSourceTopicReady(topicID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.MarkTopicReady(s.ConditionSet()) - s.Status.TopicID = topicID - } -} - -func WithCloudStorageSourceTopicID(topicID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.TopicID = topicID - } -} - -// WithCloudStorageSourcePullSubscriptionFailed marks the condition that the -// status of topic is False -func WithCloudStorageSourcePullSubscriptionFailed(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), reason, message) - } -} - -// WithCloudStorageSourcePullSubscriptionUnknown marks the condition that the -// status of topic is Unknown. -func WithCloudStorageSourcePullSubscriptionUnknown(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), reason, message) - } -} - -// WithCloudStorageSourcePullSubscriptionReady marks the condition that the -// topic is ready. -func WithCloudStorageSourcePullSubscriptionReady() CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.MarkPullSubscriptionReady(s.ConditionSet()) - } -} - -// WithCloudStorageSourceNotificationNotReady marks the condition that the -// GCS Notification is not ready. -func WithCloudStorageSourceNotificationNotReady(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.MarkNotificationNotReady(reason, message) - } -} - -// WithCloudStorageSourceNotificationReady marks the condition that the GCS -// Notification is ready. -func WithCloudStorageSourceNotificationReady(notificationID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.MarkNotificationReady(notificationID) - } -} - -// WithCloudStorageSourceSinkURI sets the status for sink URI -func WithCloudStorageSourceSinkURI(url *apis.URL) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.SinkURI = url - } -} - -// WithCloudStorageSourceNotificationId sets the status for Notification ID -func WithCloudStorageSourceNotificationID(notificationID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.NotificationID = notificationID - } -} - -// WithCloudStorageSourceProjectId sets the status for Project ID -func WithCloudStorageSourceProjectID(projectID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.ProjectID = projectID - } -} - -func WithCloudStorageSourceSubscriptionID(subscriptionID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.SubscriptionID = subscriptionID - } -} - -func WithCloudStorageSourceStatusObservedGeneration(generation int64) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.Status.Status.ObservedGeneration = generation - } -} - -func WithCloudStorageSourceObjectMetaGeneration(generation int64) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.ObjectMeta.Generation = generation - } -} - -func WithDeletionTimestamp(s *v1alpha1.CloudStorageSource) { - ts := metav1.NewTime(time.Unix(1e9, 0)) - s.DeletionTimestamp = &ts -} - -func WithCloudStorageSourceAnnotations(Annotations map[string]string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { - s.ObjectMeta.Annotations = Annotations - } -} - -func WithCloudStorageSourceSetDefaults(s *v1alpha1.CloudStorageSource) { - s.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) -} diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index aeb8306789..b529f72510 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -244,14 +244,6 @@ func TestSmokePullSubscriptionV1beta1(t *testing.T) { SmokePullSubscriptionTestHelper(t, authConfig, "v1beta1") } -// TestSmokePullSubscriptionV1alpha1 test we can create a v1alpha1 PullSubscription to ready state -// We keep a set of smoke tests for each supported version of PullSubscription to make sure the webhook works. -func TestSmokePullSubscriptionV1alpha1(t *testing.T) { - cancel := logstream.Start(t) - defer cancel() - SmokePullSubscriptionTestHelper(t, authConfig, "v1alpha1") -} - // TestPullSubscriptionWithTarget tests we can knock down a target. func TestPullSubscriptionWithTarget(t *testing.T) { cancel := logstream.Start(t) @@ -266,14 +258,6 @@ func TestSmokeCloudPubSubSourceWithDeletion(t *testing.T) { SmokeCloudPubSubSourceWithDeletionTestImpl(t, authConfig) } -// TestSmokeCloudPubSubSourceV1alpha1 we can create a v1alpha1 CloudPubSubSource to ready state. -// We keep a set of smoke tests for each supported version of CloudPubSubSource to make sure the webhook works. -func TestSmokeCloudPubSubSourceV1alpha1(t *testing.T) { - cancel := logstream.Start(t) - defer cancel() - SmokeCloudPubSubSourceTestHelper(t, authConfig, "v1alpha1") -} - // TestSmokeCloudPubSubSourceV1beta1 we can create a v1beta1 CloudPubSubSource to ready state. // We keep a set of smoke tests for each supported version of CloudPubSubSource to make sure the webhook works. func TestSmokeCloudPubSubSourceV1beta1(t *testing.T) { @@ -297,15 +281,7 @@ func TestCloudPubSubSourceStackDriverMetrics(t *testing.T) { CloudPubSubSourceWithTargetTestImpl(t, true /*assertMetrics */, authConfig) } -// TestSmokeCloudBuildSourceV1alpha1 we can create a v1alpha1 CloudBuildSource to ready state. -// We keep a set of smoke tests for each supported version of CloudBuildSource to make sure the webhook works. -func TestSmokeCloudBuildSourceV1alpha1(t *testing.T) { - cancel := logstream.Start(t) - defer cancel() - SmokeCloudBuildSourceTestHelper(t, authConfig, "v1alpha1") -} - -// TestSmokeCloudBuildSourceV1beta1 we can create a v1alpha1 CloudBuildSource to ready state. +// TestSmokeCloudBuildSourceV1beta1 we can create a v1beta1 CloudBuildSource to ready state. // We keep a set of smoke tests for each supported version of CloudBuildSource to make sure the webhook works. func TestSmokeCloudBuildSourceV1beta1(t *testing.T) { cancel := logstream.Start(t) @@ -349,14 +325,6 @@ func TestCloudStorageSourceStackDriverMetrics(t *testing.T) { CloudStorageSourceWithTargetTestImpl(t, true /*assertMetrics */, authConfig) } -// TestSmokeCloudAuditLogsSourceV1alpha1 we can create a v1alpha1 CloudAuditLogsSource to ready state. -// We keep a set of smoke tests for each supported version of CloudAuditLogsSource to make sure the webhook works. -func TestSmokeCloudAuditLogsSourceV1alpha1(t *testing.T) { - cancel := logstream.Start(t) - defer cancel() - SmokeCloudAuditLogsSourceTestHelper(t, authConfig, "v1alpha1") -} - // TestSmokeCloudPubSubSourceV1beta1 we can create a v1beta1 CloudAuditLogsSource to ready state. // We keep a set of smoke tests for each supported version of CloudAuditLogsSource to make sure the webhook works. func TestSmokeCloudAuditLogsSourceV1beta1(t *testing.T) { @@ -379,14 +347,6 @@ func TestCloudAuditLogsSourceWithTarget(t *testing.T) { CloudAuditLogsSourceWithTargetTestImpl(t, authConfig) } -// TestSmokeCloudSchedulerSourceV1alpha1 we can create a v1alpha1 CloudSchedulerSource to ready state. -// We keep a set of smoke tests for each supported version of CloudSchedulerSource to make sure the webhook works. -func TestSmokeCloudSchedulerSourceV1alpha1(t *testing.T) { - cancel := logstream.Start(t) - defer cancel() - SmokeCloudSchedulerSourceTestHelper(t, authConfig, "v1alpha1") -} - // TestSmokeCloudSchedulerSourceV1beta1 we can create a v1beta1 CloudSchedulerSource to ready state. // We keep a set of smoke tests for each supported version of CloudSchedulerSource to make sure the webhook works. func TestSmokeCloudSchedulerSourceV1beta1(t *testing.T) { @@ -395,14 +355,6 @@ func TestSmokeCloudSchedulerSourceV1beta1(t *testing.T) { SmokeCloudSchedulerSourceTestHelper(t, authConfig, "v1beta1") } -// TestSmokeCloudStorageSourceV1alpha1 we can create a v1alpha1 CloudStorageSource to ready state. -// We keep a set of smoke tests for each supported version of CloudStorageSource to make sure the webhook works. -func TestSmokeCloudStorageSourceV1alpha1(t *testing.T) { - cancel := logstream.Start(t) - defer cancel() - SmokeCloudStorageSourceTestHelper(t, authConfig, "v1alpha1") -} - // TestSmokeCloudStorageSourceV1beta1 we can create a v1beta1 CloudStorageSource to ready state. // We keep a set of smoke tests for each supported version of CloudStorageSource to make sure the webhook works. func TestSmokeCloudStorageSourceV1beta1(t *testing.T) { diff --git a/test/e2e/test_auditlogs.go b/test/e2e/test_auditlogs.go index da95ee06bb..b13d621fa6 100644 --- a/test/e2e/test_auditlogs.go +++ b/test/e2e/test_auditlogs.go @@ -58,9 +58,7 @@ func SmokeCloudAuditLogsSourceTestHelper(t *testing.T, authConfig lib.AuthConfig ServiceAccountName: authConfig.ServiceAccountName, } - if cloudAuditLogsSourceVersion == "v1alpha1" { - lib.MakeAuditLogsV1alpha1OrDie(client, auditLogsConfig) - } else if cloudAuditLogsSourceVersion == "v1beta1" { + if cloudAuditLogsSourceVersion == "v1beta1" { lib.MakeAuditLogsV1beta1OrDie(client, auditLogsConfig) } else if cloudAuditLogsSourceVersion == "v1" { lib.MakeAuditLogsOrDie(client, auditLogsConfig) diff --git a/test/e2e/test_build.go b/test/e2e/test_build.go index 7c3d340d3b..1d7269888c 100644 --- a/test/e2e/test_build.go +++ b/test/e2e/test_build.go @@ -54,9 +54,7 @@ func SmokeCloudBuildSourceTestHelper(t *testing.T, authConfig lib.AuthConfig, cl ServiceAccountName: authConfig.ServiceAccountName, } - if cloudBuildSourceVersion == "v1alpha1" { - lib.MakeBuildV1alpha1OrDie(client, buildConfig) - } else if cloudBuildSourceVersion == "v1beta1" { + if cloudBuildSourceVersion == "v1beta1" { lib.MakeBuildV1beta1OrDie(client, buildConfig) } else if cloudBuildSourceVersion == "v1" { lib.MakeBuildOrDie(client, buildConfig) diff --git a/test/e2e/test_pubsub.go b/test/e2e/test_pubsub.go index e1a092784a..b7fa56f24f 100644 --- a/test/e2e/test_pubsub.go +++ b/test/e2e/test_pubsub.go @@ -56,9 +56,7 @@ func SmokeCloudPubSubSourceTestHelper(t *testing.T, authConfig lib.AuthConfig, c ServiceAccountName: authConfig.ServiceAccountName, } - if cloudPubSubSourceVersion == "v1alpha1" { - lib.MakePubSubV1alpha1OrDie(client, pubSubConfig) - } else if cloudPubSubSourceVersion == "v1beta1" { + if cloudPubSubSourceVersion == "v1beta1" { lib.MakePubSubV1beta1OrDie(client, pubSubConfig) } else if cloudPubSubSourceVersion == "v1" { lib.MakePubSubOrDie(client, pubSubConfig) diff --git a/test/e2e/test_pullsubscription.go b/test/e2e/test_pullsubscription.go index 2ad1e4ff8d..c3e2372fba 100644 --- a/test/e2e/test_pullsubscription.go +++ b/test/e2e/test_pullsubscription.go @@ -51,9 +51,7 @@ func SmokePullSubscriptionTestHelper(t *testing.T, authConfig lib.AuthConfig, pu ServiceAccountName: authConfig.ServiceAccountName, } - if pullsubscriptionVersion == "v1alpha1" { - lib.MakePullSubscriptionV1alpha1OrDie(client, pullSubscriptionConfig) - } else if pullsubscriptionVersion == "v1beta1" { + if pullsubscriptionVersion == "v1beta1" { lib.MakePullSubscriptionV1beta1OrDie(client, pullSubscriptionConfig) } else if pullsubscriptionVersion == "v1" { lib.MakePullSubscriptionOrDie(client, pullSubscriptionConfig) diff --git a/test/e2e/test_scheduler.go b/test/e2e/test_scheduler.go index bdfd01e73b..09482a60c0 100644 --- a/test/e2e/test_scheduler.go +++ b/test/e2e/test_scheduler.go @@ -50,9 +50,7 @@ func SmokeCloudSchedulerSourceTestHelper(t *testing.T, authConfig lib.AuthConfig ServiceAccountName: authConfig.ServiceAccountName, } - if cloudSchedulerSourceVersion == "v1alpha1" { - lib.MakeSchedulerOrDie(client, schedulerConfig) - } else if cloudSchedulerSourceVersion == "v1beta1" { + if cloudSchedulerSourceVersion == "v1beta1" { lib.MakeSchedulerOrDie(client, schedulerConfig) } else if cloudSchedulerSourceVersion == "v1" { lib.MakeSchedulerOrDie(client, schedulerConfig) diff --git a/test/e2e/test_storage.go b/test/e2e/test_storage.go index 82be7b9286..4453ca4d6f 100644 --- a/test/e2e/test_storage.go +++ b/test/e2e/test_storage.go @@ -57,9 +57,7 @@ func SmokeCloudStorageSourceTestHelper(t *testing.T, authConfig lib.AuthConfig, ServiceAccountName: authConfig.ServiceAccountName, } - if cloudStorageSourceVersion == "v1alpha1" { - lib.MakeStorageV1alpha1OrDie(client, storageConfig) - } else if cloudStorageSourceVersion == "v1beta1" { + if cloudStorageSourceVersion == "v1beta1" { lib.MakeStorageV1beta1OrDie(client, storageConfig) } else if cloudStorageSourceVersion == "v1" { lib.MakeStorageOrDie(client, storageConfig) diff --git a/test/lib/auditlogs.go b/test/lib/auditlogs.go index 753f8f78ff..14b87bf178 100644 --- a/test/lib/auditlogs.go +++ b/test/lib/auditlogs.go @@ -23,7 +23,6 @@ import ( "time" reconcilertestingv1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1" - reconcilertestingv1alpha1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1alpha1" reconcilertestingv1beta1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1beta1" "google.golang.org/api/option" @@ -86,22 +85,6 @@ func MakeAuditLogsV1beta1OrDie(client *Client, config AuditLogsConfig) { client.Core.WaitForResourceReadyOrFail(config.AuditlogsName, CloudAuditLogsSourceV1beta1TypeMeta) } -func MakeAuditLogsV1alpha1OrDie(client *Client, config AuditLogsConfig) { - client.T.Helper() - so := make([]reconcilertestingv1alpha1.CloudAuditLogsSourceOption, 0) - so = append(so, reconcilertestingv1alpha1.WithCloudAuditLogsSourceServiceName(config.ServiceName)) - so = append(so, reconcilertestingv1alpha1.WithCloudAuditLogsSourceMethodName(config.MethodName)) - so = append(so, reconcilertestingv1alpha1.WithCloudAuditLogsSourceProject(config.Project)) - so = append(so, reconcilertestingv1alpha1.WithCloudAuditLogsSourceResourceName(config.ResourceName)) - so = append(so, reconcilertestingv1alpha1.WithCloudAuditLogsSourceSink(config.SinkGVK, config.SinkName)) - so = append(so, reconcilertestingv1alpha1.WithCloudAuditLogsSourceServiceAccount(config.ServiceAccountName)) - eventsAuditLogs := reconcilertestingv1alpha1.NewCloudAuditLogsSource(config.AuditlogsName, client.Namespace, so...) - client.CreateAuditLogsV1alpha1OrFail(eventsAuditLogs) - // AuditLog source may not be ready within the 2 min timeout in WaitForResourceReadyOrFail function. - time.Sleep(resources.WaitExtraSourceReadyTime) - client.Core.WaitForResourceReadyOrFail(config.AuditlogsName, CloudAuditLogsSourceV1alpha1TypeMeta) -} - func MakeAuditLogsJobOrDie(client *Client, methodName, project, resourceName, serviceName, targetName, eventType string) { client.T.Helper() job := resources.AuditLogsTargetJob(targetName, []v1.EnvVar{{ diff --git a/test/lib/build.go b/test/lib/build.go index 6019e631e0..6a2fe3deea 100644 --- a/test/lib/build.go +++ b/test/lib/build.go @@ -25,8 +25,6 @@ import ( reconcilertestingv1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1" reconcilertestingv1beta1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1beta1" - reconcilertestingv1alpha1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1alpha1" - v1 "k8s.io/api/core/v1" "google.golang.org/api/option" @@ -68,18 +66,6 @@ func MakeBuildV1beta1OrDie(client *Client, config BuildConfig) { client.Core.WaitForResourceReadyOrFail(config.BuildName, CloudBuildSourceV1beta1TypeMeta) } -func MakeBuildV1alpha1OrDie(client *Client, config BuildConfig) { - client.T.Helper() - so := make([]reconcilertestingv1alpha1.CloudBuildSourceOption, 0) - so = append(so, reconcilertestingv1alpha1.WithCloudBuildSourceSink(config.SinkGVK, config.SinkName)) - so = append(so, reconcilertestingv1alpha1.WithCloudBuildSourceServiceAccount(config.ServiceAccountName)) - build := reconcilertestingv1alpha1.NewCloudBuildSource(config.BuildName, client.Namespace, so...) - client.CreateBuildV1alpha1OrFail(build) - // CloudBuildSource source may not be ready within the 2 min timeout in WaitForResourceReadyOrFail function. - time.Sleep(resources.WaitExtraSourceReadyTime) - client.Core.WaitForResourceReadyOrFail(config.BuildName, CloudBuildSourceV1alpha1TypeMeta) -} - func MakeBuildTargetJobOrDie(client *Client, images, targetName, eventType string) { client.T.Helper() job := resources.BuildTargetJob(targetName, []v1.EnvVar{ diff --git a/test/lib/creation.go b/test/lib/creation.go index 186149e3ee..3eba5a7cd3 100644 --- a/test/lib/creation.go +++ b/test/lib/creation.go @@ -20,8 +20,6 @@ import ( "context" "github.com/google/knative-gcp/pkg/apis/broker/v1beta1" - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" knativegcptestresources "github.com/google/knative-gcp/test/lib/resources" batchv1 "k8s.io/api/batch/v1" @@ -84,18 +82,6 @@ func (c *Client) CreateAuditLogsV1beta1OrFail(auditlogs *eventsv1beta1.CloudAudi c.Tracker.AddObj(auditlogs) } -func (c *Client) CreateAuditLogsV1alpha1OrFail(auditlogs *eventsv1alpha1.CloudAuditLogsSource) { - ctx := context.Background() - c.T.Helper() - auditlogses := c.KnativeGCP.EventsV1alpha1().CloudAuditLogsSources(c.Namespace) - _, err := auditlogses.Create(ctx, auditlogs, v1.CreateOptions{}) - if err != nil { - c.T.Fatalf("Failed to create auditlogs %s/%s: %v", c.Namespace, auditlogs.Name, err) - } - c.T.Logf("Created auditlogs: %s/%s", c.Namespace, auditlogs.Name) - c.Tracker.AddObj(auditlogs) -} - func (c *Client) CreatePubSubOrFail(pubsub *eventsv1.CloudPubSubSource) { ctx := context.Background() c.T.Helper() @@ -120,18 +106,6 @@ func (c *Client) CreatePubSubV1beta1OrFail(pubsub *eventsv1beta1.CloudPubSubSour c.Tracker.AddObj(pubsub) } -func (c *Client) CreatePubSubV1alpha1OrFail(pubsub *eventsv1alpha1.CloudPubSubSource) { - ctx := context.Background() - c.T.Helper() - pubsubs := c.KnativeGCP.EventsV1alpha1().CloudPubSubSources(c.Namespace) - _, err := pubsubs.Create(ctx, pubsub, v1.CreateOptions{}) - if err != nil { - c.T.Fatalf("Failed to create pubsub %s/%s: %v", c.Namespace, pubsub.Name, err) - } - c.T.Logf("Created pubsub: %s/%s", c.Namespace, pubsub.Name) - c.Tracker.AddObj(pubsub) -} - func (c *Client) CreateBuildOrFail(build *eventsv1.CloudBuildSource) { ctx := context.Background() c.T.Helper() @@ -156,18 +130,6 @@ func (c *Client) CreateBuildV1beta1OrFail(build *eventsv1beta1.CloudBuildSource) c.Tracker.AddObj(build) } -func (c *Client) CreateBuildV1alpha1OrFail(build *eventsv1alpha1.CloudBuildSource) { - ctx := context.Background() - c.T.Helper() - builds := c.KnativeGCP.EventsV1alpha1().CloudBuildSources(c.Namespace) - _, err := builds.Create(ctx, build, v1.CreateOptions{}) - if err != nil { - c.T.Fatalf("Failed to create build %s/%s: %v", c.Namespace, build.Name, err) - } - c.T.Logf("Created build: %s/%s", c.Namespace, build.Name) - c.Tracker.AddObj(build) -} - func (c *Client) CreateStorageOrFail(storage *eventsv1.CloudStorageSource) { ctx := context.Background() c.T.Helper() @@ -192,18 +154,6 @@ func (c *Client) CreateStorageV1beta1OrFail(storage *eventsv1beta1.CloudStorageS c.Tracker.AddObj(storage) } -func (c *Client) CreateStorageV1alpha1OrFail(storage *eventsv1alpha1.CloudStorageSource) { - ctx := context.Background() - c.T.Helper() - storages := c.KnativeGCP.EventsV1alpha1().CloudStorageSources(c.Namespace) - _, err := storages.Create(ctx, storage, v1.CreateOptions{}) - if err != nil { - c.T.Fatalf("Failed to create storage %s/%s: %v", c.Namespace, storage.Name, err) - } - c.T.Logf("Created storage: %s/%s", c.Namespace, storage.Name) - c.Tracker.AddObj(storage) -} - func (c *Client) CreatePullSubscriptionOrFail(pullsubscription *inteventsv1.PullSubscription) { ctx := context.Background() c.T.Helper() @@ -228,18 +178,6 @@ func (c *Client) CreatePullSubscriptionV1beta1OrFail(pullsubscription *intevents c.Tracker.AddObj(pullsubscription) } -func (c *Client) CreatePullSubscriptionV1alpha1OrFail(pullsubscription *inteventsv1alpha1.PullSubscription) { - ctx := context.Background() - c.T.Helper() - pullsubscriptions := c.KnativeGCP.InternalV1alpha1().PullSubscriptions(c.Namespace) - _, err := pullsubscriptions.Create(ctx, pullsubscription, v1.CreateOptions{}) - if err != nil { - c.T.Fatalf("Failed to create pullsubscription %s/%s: %v", c.Namespace, pullsubscription.Name, err) - } - c.T.Logf("Created pullsubscription: %s/%s", c.Namespace, pullsubscription.Name) - c.Tracker.AddObj(pullsubscription) -} - func (c *Client) CreateSchedulerOrFail(scheduler *eventsv1.CloudSchedulerSource) { ctx := context.Background() c.T.Helper() @@ -264,18 +202,6 @@ func (c *Client) CreateSchedulerV1beta1OrFail(scheduler *eventsv1beta1.CloudSche c.Tracker.AddObj(scheduler) } -func (c *Client) CreateSchedulerV1alpha1OrFail(scheduler *eventsv1alpha1.CloudSchedulerSource) { - ctx := context.Background() - c.T.Helper() - schedulers := c.KnativeGCP.EventsV1alpha1().CloudSchedulerSources(c.Namespace) - _, err := schedulers.Create(ctx, scheduler, v1.CreateOptions{}) - if err != nil { - c.T.Fatalf("Failed to create scheduler %s/%s: %v", c.Namespace, scheduler.Name, err) - } - c.T.Logf("Created scheduler: %s/%s", c.Namespace, scheduler.Name) - c.Tracker.AddObj(scheduler) -} - // CreateGCPBrokerV1Beta1OrFail will create a GCP Broker or fail the test if there is an error. func (c *Client) CreateGCPBrokerV1Beta1OrFail(name string, options ...knativegcptestresources.BrokerV1Beta1Option) *v1beta1.Broker { ctx := context.Background() diff --git a/test/lib/pubsub.go b/test/lib/pubsub.go index 34aa575c62..c2124ece1f 100644 --- a/test/lib/pubsub.go +++ b/test/lib/pubsub.go @@ -22,7 +22,6 @@ import ( "time" reconcilertestingv1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1" - reconcilertestingv1alpha1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1alpha1" reconcilertestingv1beta1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1beta1" v1 "k8s.io/api/core/v1" @@ -66,18 +65,6 @@ func MakePubSubV1beta1OrDie(client *Client, config PubSubConfig) { client.Core.WaitForResourceReadyOrFail(config.PubSubName, CloudPubSubSourceV1beta1TypeMeta) } -func MakePubSubV1alpha1OrDie(client *Client, config PubSubConfig) { - client.T.Helper() - so := make([]reconcilertestingv1alpha1.CloudPubSubSourceOption, 0) - so = append(so, reconcilertestingv1alpha1.WithCloudPubSubSourceSink(config.SinkGVK, config.SinkName)) - so = append(so, reconcilertestingv1alpha1.WithCloudPubSubSourceTopic(config.TopicName)) - so = append(so, reconcilertestingv1alpha1.WithCloudPubSubSourceServiceAccount(config.ServiceAccountName)) - eventsPubSub := reconcilertestingv1alpha1.NewCloudPubSubSource(config.PubSubName, client.Namespace, so...) - client.CreatePubSubV1alpha1OrFail(eventsPubSub) - - client.Core.WaitForResourceReadyOrFail(config.PubSubName, CloudPubSubSourceV1alpha1TypeMeta) -} - func MakePubSubTargetJobOrDie(client *Client, source, targetName, eventType string, schema string) { client.T.Helper() job := resources.PubSubTargetJob(targetName, []v1.EnvVar{ diff --git a/test/lib/pullsubscription.go b/test/lib/pullsubscription.go index 5043f6bf6d..ad4722993d 100644 --- a/test/lib/pullsubscription.go +++ b/test/lib/pullsubscription.go @@ -2,7 +2,6 @@ package lib import ( reconcilertestingv1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1" - reconcilertestingv1alpha1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1alpha1" reconcilertestingv1beta1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -40,16 +39,3 @@ func MakePullSubscriptionV1beta1OrDie(client *Client, config PullSubscriptionCon client.Core.WaitForResourceReadyOrFail(config.PullSubscriptionName, PullSubscriptionV1beta1TypeMeta) } - -func MakePullSubscriptionV1alpha1OrDie(client *Client, config PullSubscriptionConfig) { - client.T.Helper() - so := make([]reconcilertestingv1alpha1.PullSubscriptionOption, 0) - so = append(so, reconcilertestingv1alpha1.WithPullSubscriptionSink(config.SinkGVK, config.SinkName)) - so = append(so, reconcilertestingv1alpha1.WithPullSubscriptionTopic(config.TopicName)) - so = append(so, reconcilertestingv1alpha1.WithPullSubscriptionServiceAccount(config.ServiceAccountName)) - pullsubscription := reconcilertestingv1alpha1.NewPullSubscription(config.PullSubscriptionName, client.Namespace, so...) - - client.CreatePullSubscriptionV1alpha1OrFail(pullsubscription) - - client.Core.WaitForResourceReadyOrFail(config.PullSubscriptionName, PullSubscriptionV1alpha1TypeMeta) -} diff --git a/test/lib/scheduler.go b/test/lib/scheduler.go index 4454dd1410..77932d481c 100644 --- a/test/lib/scheduler.go +++ b/test/lib/scheduler.go @@ -23,7 +23,6 @@ import ( "time" reconcilertestingv1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1" - reconcilertestingv1alpha1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1alpha1" reconcilertestingv1beta1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1beta1" "google.golang.org/api/option" @@ -78,22 +77,6 @@ func MakeSchedulerV1beta1OrDie(client *Client, config SchedulerConfig) { client.Core.WaitForResourceReadyOrFail(config.SchedulerName, CloudSchedulerSourceV1beta1TypeMeta) } -func MakeSchedulerV1alpha1OrDie(client *Client, config SchedulerConfig) { - client.T.Helper() - so := make([]reconcilertestingv1alpha1.CloudSchedulerSourceOption, 0) - so = append(so, reconcilertestingv1alpha1.WithCloudSchedulerSourceLocation("us-central1")) - so = append(so, reconcilertestingv1alpha1.WithCloudSchedulerSourceData(config.Data)) - so = append(so, reconcilertestingv1alpha1.WithCloudSchedulerSourceSchedule("* * * * *")) - so = append(so, reconcilertestingv1alpha1.WithCloudSchedulerSourceSink(config.SinkGVK, config.SinkName)) - so = append(so, reconcilertestingv1alpha1.WithCloudSchedulerSourceServiceAccount(config.ServiceAccountName)) - scheduler := reconcilertestingv1alpha1.NewCloudSchedulerSource(config.SchedulerName, client.Namespace, so...) - - client.CreateSchedulerV1alpha1OrFail(scheduler) - // Scheduler source may not be ready within the 2 min timeout in WaitForResourceReadyOrFail function. - time.Sleep(resources.WaitExtraSourceReadyTime) - client.Core.WaitForResourceReadyOrFail(config.SchedulerName, CloudSchedulerSourceV1alpha1TypeMeta) -} - func MakeSchedulerJobOrDie(client *Client, data, targetName, eventType string) { client.T.Helper() job := resources.SchedulerTargetJob(targetName, []v1.EnvVar{ diff --git a/test/lib/storage.go b/test/lib/storage.go index 432a1f4e59..bd405b3af5 100644 --- a/test/lib/storage.go +++ b/test/lib/storage.go @@ -23,7 +23,6 @@ import ( "time" reconcilertestingv1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1" - reconcilertestingv1alpha1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1alpha1" reconcilertestingv1beta1 "github.com/google/knative-gcp/pkg/reconciler/testing/v1beta1" "cloud.google.com/go/storage" @@ -71,19 +70,6 @@ func MakeStorageV1beta1OrDie(client *Client, config StorageConfig) { client.Core.WaitForResourceReadyOrFail(config.StorageName, CloudStorageSourceV1beta1TypeMeta) } -func MakeStorageV1alpha1OrDie(client *Client, config StorageConfig) { - client.T.Helper() - so := make([]reconcilertestingv1alpha1.CloudStorageSourceOption, 0) - so = append(so, reconcilertestingv1alpha1.WithCloudStorageSourceBucket(config.BucketName)) - so = append(so, reconcilertestingv1alpha1.WithCloudStorageSourceSink(config.SinkGVK, config.SinkName)) - so = append(so, reconcilertestingv1alpha1.WithCloudStorageSourceServiceAccount(config.ServiceAccountName)) - eventsStorage := reconcilertestingv1alpha1.NewCloudStorageSource(config.StorageName, client.Namespace, so...) - client.CreateStorageV1alpha1OrFail(eventsStorage) - // Storage source may not be ready within the 2 min timeout in WaitForResourceReadyOrFail function. - time.Sleep(resources.WaitExtraSourceReadyTime) - client.Core.WaitForResourceReadyOrFail(config.StorageName, CloudStorageSourceV1alpha1TypeMeta) -} - func MakeStorageJobOrDie(client *Client, source, subject, targetName, eventType string) { client.T.Helper() job := resources.StorageTargetJob(targetName, []v1.EnvVar{