From fc8686c88ab17a224008caf5e1d2c79fccbd674e Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Wed, 10 Jun 2020 16:12:03 -0700 Subject: [PATCH 01/14] changed channel to v1beta1 and added cloudbuildsource in v1beta1 --- pkg/apis/duck/v1beta1/annotations.go | 2 + pkg/apis/events/register.go | 4 + .../v1beta1/cloudbuildsource_defaults.go | 48 ++ .../v1beta1/cloudbuildsource_defaults_test.go | 141 ++++++ .../v1beta1/cloudbuildsource_lifecycle.go | 41 ++ .../cloudbuildsource_lifecycle_test.go | 158 ++++++ .../events/v1beta1/cloudbuildsource_types.go | 133 +++++ .../v1beta1/cloudbuildsource_types_test.go | 102 ++++ .../v1beta1/cloudbuildsource_validation.go | 74 +++ .../cloudbuildsource_validation_test.go | 469 ++++++++++++++++++ pkg/apis/events/v1beta1/register.go | 2 + pkg/reconciler/identity/reconciler.go | 2 +- .../intevents/topic/resources/names.go | 4 +- .../intevents/topic/resources/publisher.go | 4 +- pkg/reconciler/intevents/topic/topic.go | 20 +- pkg/reconciler/messaging/channel/channel.go | 69 ++- .../messaging/channel/channel_test.go | 272 ++++++---- .../messaging/channel/controller.go | 8 +- .../messaging/channel/resources/names.go | 6 +- .../channel/resources/pullsubscription.go | 18 +- .../messaging/channel/resources/topic.go | 12 +- pkg/reconciler/testing/channel.go | 64 +-- pkg/reconciler/testing/listers.go | 14 +- 23 files changed, 1455 insertions(+), 212 deletions(-) create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_defaults.go create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_lifecycle.go create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_types.go create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_types_test.go create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_validation.go create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go diff --git a/pkg/apis/duck/v1beta1/annotations.go b/pkg/apis/duck/v1beta1/annotations.go index 50640303cc..7067ad7f34 100644 --- a/pkg/apis/duck/v1beta1/annotations.go +++ b/pkg/apis/duck/v1beta1/annotations.go @@ -33,6 +33,8 @@ const ( // AutoscalingClassAnnotation is the annotation for the explicit class of // scaler that a particular resource has opted into. AutoscalingClassAnnotation = Autoscaling + "/class" + // ClusterNameAnnotation is the annotation for the cluster Name. + ClusterNameAnnotation = "cluster-name" // AutoscalingMinScaleAnnotation is the annotation to specify the minimum number of pods to scale to. AutoscalingMinScaleAnnotation = Autoscaling + "/minScale" diff --git a/pkg/apis/events/register.go b/pkg/apis/events/register.go index 14ab420eb9..f4e55fdd8f 100644 --- a/pkg/apis/events/register.go +++ b/pkg/apis/events/register.go @@ -44,4 +44,8 @@ var ( Group: GroupName, Resource: "cloudstoragesources", } + CloudBuildSourcesResource = schema.GroupResource{ + Group: GroupName, + Resource: "cloudbuildsources", + } ) diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go b/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go new file mode 100644 index 0000000000..4b31fa73c0 --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go @@ -0,0 +1,48 @@ +/* +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 v1beta1 + +import ( + "context" + + "knative.dev/pkg/apis" + + duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" + + "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) + duckv1alpha1.SetClusterNameAnnotation(&bs.ObjectMeta, metadataClient.NewDefaultMetadataClient()) + duckv1alpha1.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/v1beta1/cloudbuildsource_defaults_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go new file mode 100644 index 0000000000..d1f4db69b5 --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go @@ -0,0 +1,141 @@ +/* +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 v1beta1 + +import ( + "testing" + + gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" + + "knative.dev/pkg/ptr" + + "github.com/google/go-cmp/cmp" + 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{ + duckv1alpha1.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{ + duckv1alpha1.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{ + duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + }, + }, + Spec: CloudBuildSourceSpec{}, + }, + want: &CloudBuildSource{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + duckv1alpha1.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{ + duckv1alpha1.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/v1beta1/cloudbuildsource_lifecycle.go b/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle.go new file mode 100644 index 0000000000..6fd44a01d8 --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle.go @@ -0,0 +1,41 @@ +/* +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 v1beta1 + +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/v1beta1/cloudbuildsource_lifecycle_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go new file mode 100644 index 0000000000..aceabc8278 --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go @@ -0,0 +1,158 @@ +/* +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 v1beta1 + +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/v1beta1/cloudbuildsource_types.go b/pkg/apis/events/v1beta1/cloudbuildsource_types.go new file mode 100644 index 0000000000..5cc5aac623 --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_types.go @@ -0,0 +1,133 @@ +/* +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 v1beta1 + +import ( + "fmt" + + 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/apis/duck" + "knative.dev/pkg/kmeta" + "knative.dev/pkg/webhook/resourcesemantics" + + "k8s.io/apimachinery/pkg/runtime/schema" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +// CloudBuildSource is a specification for a CloudBuildSource resource +// +genclient +// +genreconciler +// +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"` +} + +var ( + _ kmeta.OwnerRefable = (*CloudBuildSource)(nil) + _ resourcesemantics.GenericCRD = (*CloudBuildSource)(nil) + _ kngcpduck.PubSubable = (*CloudBuildSource)(nil) + _ kngcpduck.Identifiable = (*CloudBuildSource)(nil) + _ = duck.VerifyType(&CloudBuildSource{}, &duckv1.Conditions{}) +) + +// 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"` +} + +const ( + // CloudBuildSource CloudEvent type + CloudBuildSourceEvent = "com.google.cloud.build.event" + // CloudBuildSourceBuildId is the Pub/Sub message attribute key with the CloudBuildSource's buildId. + CloudBuildSourceBuildId = "buildId" + // CloudBuildSourceBuildStatus is the Pub/Sub message attribute key with the CloudBuildSource's build status. + CloudBuildSourceBuildStatus = "status" +) + +// 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/v1beta1/cloudbuildsource_types_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_types_test.go new file mode 100644 index 0000000000..3fe9a9f23e --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_types_test.go @@ -0,0 +1,102 @@ +/* +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 v1beta1 + +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/v1beta1/cloudbuildsource_validation.go b/pkg/apis/events/v1beta1/cloudbuildsource_validation.go new file mode 100644 index 0000000000..e4cf832212 --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_validation.go @@ -0,0 +1,74 @@ +/* +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 v1beta1 + +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" + + duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" +) + +func (current *CloudBuildSource) Validate(ctx context.Context) *apis.FieldError { + errs := current.Spec.Validate(ctx).ViaField("spec") + return duckv1alpha1.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 := duckv1alpha1.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 non-empty cluster name annotation is not allowed. + return duckv1alpha1.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) +} diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go new file mode 100644 index 0000000000..5a517fffd3 --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go @@ -0,0 +1,469 @@ +/* +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 v1beta1 + +import ( + "context" + "testing" + + gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + 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), + } +) + +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{ + duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", + }, + updatedAnnotation: map[string]string{ + duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", + }, + 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, + }, + "ServiceAccount changed": { + orig: &buildSourceSpec, + updated: CloudBuildSourceSpec{ + PubSubSpec: duckv1alpha1.PubSubSpec{ + IdentitySpec: duckv1alpha1.IdentitySpec{ + ServiceAccountName: "new-service-account", + }, + Secret: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: buildSourceSpec.Secret.Name, + }, + Key: buildSourceSpec.Secret.Key, + }, + SourceSpec: duckv1.SourceSpec{ + Sink: buildSourceSpec.Sink, + }, + }, + Topic: buildSourceSpec.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, + }, + "not 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/v1beta1/register.go b/pkg/apis/events/v1beta1/register.go index 0216f2d523..bbf98f8fdc 100644 --- a/pkg/apis/events/v1beta1/register.go +++ b/pkg/apis/events/v1beta1/register.go @@ -53,6 +53,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &CloudSchedulerSourceList{}, &CloudPubSubSource{}, &CloudPubSubSourceList{}, + &CloudBuildSource{}, + &CloudBuildSourceList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/reconciler/identity/reconciler.go b/pkg/reconciler/identity/reconciler.go index 61222c3e9d..45dfa34fc8 100644 --- a/pkg/reconciler/identity/reconciler.go +++ b/pkg/reconciler/identity/reconciler.go @@ -33,7 +33,7 @@ import ( "knative.dev/pkg/ptr" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - duck "github.com/google/knative-gcp/pkg/duck/v1alpha1" + duck "github.com/google/knative-gcp/pkg/duck/v1beta1" metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" "github.com/google/knative-gcp/pkg/reconciler/identity/iam" "github.com/google/knative-gcp/pkg/reconciler/identity/resources" diff --git a/pkg/reconciler/intevents/topic/resources/names.go b/pkg/reconciler/intevents/topic/resources/names.go index bfff8b6760..13edbd4a2b 100644 --- a/pkg/reconciler/intevents/topic/resources/names.go +++ b/pkg/reconciler/intevents/topic/resources/names.go @@ -22,10 +22,10 @@ import ( "knative.dev/pkg/kmeta" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" ) -func GeneratePublisherName(topic *v1alpha1.Topic) string { +func GeneratePublisherName(topic *v1beta1.Topic) string { if HasPrefix(topic.Name, "cre-") { return kmeta.ChildName(topic.Name, "-publish") } diff --git a/pkg/reconciler/intevents/topic/resources/publisher.go b/pkg/reconciler/intevents/topic/resources/publisher.go index a133628cf0..9da5ce914d 100644 --- a/pkg/reconciler/intevents/topic/resources/publisher.go +++ b/pkg/reconciler/intevents/topic/resources/publisher.go @@ -24,14 +24,14 @@ import ( "knative.dev/pkg/kmeta" servingv1 "knative.dev/serving/pkg/apis/serving/v1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" ) // PublisherArgs are the arguments needed to create a Topic publisher. // Every field is required. type PublisherArgs struct { Image string - Topic *v1alpha1.Topic + Topic *v1beta1.Topic Labels map[string]string TracingConfig string diff --git a/pkg/reconciler/intevents/topic/topic.go b/pkg/reconciler/intevents/topic/topic.go index f9a5ae9dc5..93ef47e9c6 100644 --- a/pkg/reconciler/intevents/topic/topic.go +++ b/pkg/reconciler/intevents/topic/topic.go @@ -42,9 +42,9 @@ import ( gstatus "google.golang.org/grpc/status" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - topicreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1alpha1/topic" - listers "github.com/google/knative-gcp/pkg/client/listers/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + topicreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1beta1/topic" + listers "github.com/google/knative-gcp/pkg/client/listers/intevents/v1beta1" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/intevents" @@ -85,7 +85,7 @@ type Reconciler struct { // Check that our Reconciler implements Interface. var _ topicreconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, topic *v1alpha1.Topic) reconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, topic *v1beta1.Topic) reconciler.Event { ctx = logging.WithLogger(ctx, r.Logger.With(zap.Any("topic", topic))) topic.Status.InitializeConditions() @@ -128,7 +128,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, topic *v1alpha1.Topic) r return reconciler.NewEvent(corev1.EventTypeNormal, reconciledSuccessReason, `Topic reconciled: "%s/%s"`, topic.Namespace, topic.Name) } -func (r *Reconciler) reconcileTopic(ctx context.Context, topic *v1alpha1.Topic) error { +func (r *Reconciler) reconcileTopic(ctx context.Context, topic *v1beta1.Topic) error { if topic.Status.ProjectID == "" { projectID, err := utils.ProjectID(topic.Spec.Project, metadataClient.NewDefaultMetadataClient()) if err != nil { @@ -156,7 +156,7 @@ func (r *Reconciler) reconcileTopic(ctx context.Context, topic *v1alpha1.Topic) } if !exists { - if topic.Spec.PropagationPolicy == v1alpha1.TopicPolicyNoCreateNoDelete { + if topic.Spec.PropagationPolicy == v1beta1.TopicPolicyNoCreateNoDelete { logging.FromContext(ctx).Desugar().Error("Topic does not exist and the topic policy doesn't allow creation") return fmt.Errorf("Topic %q does not exist and the topic policy doesn't allow creation", topic.Spec.Topic) } else { @@ -183,7 +183,7 @@ func (r *Reconciler) reconcileTopic(ctx context.Context, topic *v1alpha1.Topic) // deleteTopic looks at the status.TopicID and if non-empty, // hence indicating that we have created a topic successfully, // remove it. -func (r *Reconciler) deleteTopic(ctx context.Context, topic *v1alpha1.Topic) error { +func (r *Reconciler) deleteTopic(ctx context.Context, topic *v1beta1.Topic) error { if topic.Status.TopicID == "" { return nil } @@ -213,7 +213,7 @@ func (r *Reconciler) deleteTopic(ctx context.Context, topic *v1alpha1.Topic) err return nil } -func (r *Reconciler) reconcilePublisher(ctx context.Context, topic *v1alpha1.Topic) (error, *servingv1.Service) { +func (r *Reconciler) reconcilePublisher(ctx context.Context, topic *v1beta1.Topic) (error, *servingv1.Service) { name := resources.GeneratePublisherName(topic) existing, err := r.serviceLister.Services(topic.Namespace).Get(name) if err != nil { @@ -275,7 +275,7 @@ func (r *Reconciler) UpdateFromTracingConfigMap(cfg *corev1.ConfigMap) { // TODO: requeue all Topics. See https://github.com/google/knative-gcp/issues/457. } -func (r *Reconciler) FinalizeKind(ctx context.Context, topic *v1alpha1.Topic) reconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, topic *v1beta1.Topic) reconciler.Event { // If topic doesn't have ownerReference, and // k8s ServiceAccount exists, binds to the default GCP ServiceAccount, and it only has one ownerReference, // remove the corresponding GCP ServiceAccount iam policy binding. @@ -285,7 +285,7 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, topic *v1alpha1.Topic) re return reconciler.NewEvent(corev1.EventTypeWarning, deleteWorkloadIdentityFailed, "Failed to delete delete Pub/Sub topic workload identity: %s", err.Error()) } } - if topic.Spec.PropagationPolicy == v1alpha1.TopicPolicyCreateDelete { + if topic.Spec.PropagationPolicy == v1beta1.TopicPolicyCreateDelete { logging.FromContext(ctx).Desugar().Debug("Deleting Pub/Sub topic") if err := r.deleteTopic(ctx, topic); err != nil { return reconciler.NewEvent(corev1.EventTypeWarning, deleteTopicFailed, "Failed to delete Pub/Sub topic: %s", err.Error()) diff --git a/pkg/reconciler/messaging/channel/channel.go b/pkg/reconciler/messaging/channel/channel.go index 55f88fb1bd..e91a049890 100644 --- a/pkg/reconciler/messaging/channel/channel.go +++ b/pkg/reconciler/messaging/channel/channel.go @@ -27,17 +27,16 @@ import ( apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" "knative.dev/pkg/logging" pkgreconciler "knative.dev/pkg/reconciler" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" - channelreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/messaging/v1alpha1/channel" - inteventslisters "github.com/google/knative-gcp/pkg/client/listers/intevents/v1alpha1" - listers "github.com/google/knative-gcp/pkg/client/listers/messaging/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" + channelreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/messaging/v1beta1/channel" + inteventslisters "github.com/google/knative-gcp/pkg/client/listers/intevents/v1beta1" + listers "github.com/google/knative-gcp/pkg/client/listers/messaging/v1beta1" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/messaging/channel/resources" @@ -67,7 +66,7 @@ type Reconciler struct { // Check that our Reconciler implements Interface. var _ channelreconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, channel *v1alpha1.Channel) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, channel *v1beta1.Channel) pkgreconciler.Event { ctx = logging.WithLogger(ctx, r.Logger.With(zap.Any("channel", channel))) channel.Status.InitializeConditions() @@ -104,21 +103,21 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, channel *v1alpha1.Channe return pkgreconciler.NewEvent(corev1.EventTypeNormal, reconciledSuccessReason, `Channel reconciled: "%s/%s"`, channel.Namespace, channel.Name) } -func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Channel) error { - if channel.Status.SubscribableStatus == nil { - channel.Status.SubscribableStatus = &eventingduck.SubscribableStatus{ +func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1beta1.Channel) error { + if equality.Semantic.DeepEqual(channel.Status.SubscribableStatus, eventingduckv1beta1.SubscribableStatus{}) { + channel.Status.SubscribableStatus = eventingduckv1beta1.SubscribableStatus{ Subscribers: make([]eventingduckv1beta1.SubscriberStatus, 0), } } else if channel.Status.SubscribableStatus.Subscribers == nil { channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0) } - subCreates := []eventingduck.SubscriberSpec(nil) - subUpdates := []eventingduck.SubscriberSpec(nil) + subCreates := []eventingduckv1beta1.SubscriberSpec(nil) + subUpdates := []eventingduckv1beta1.SubscriberSpec(nil) subDeletes := []eventingduckv1beta1.SubscriberStatus(nil) // Make a map of name to PullSubscription for lookup. - pullsubs := make(map[string]inteventsv1alpha1.PullSubscription) + pullsubs := make(map[string]inteventsv1beta1.PullSubscription) if subs, err := r.getPullSubscriptions(ctx, channel); err != nil { logging.FromContext(ctx).Desugar().Error("Failed to list PullSubscriptions", zap.Error(err)) } else { @@ -132,8 +131,8 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Chan exists[s.UID] = s } - if channel.Spec.Subscribable != nil { - for _, want := range channel.Spec.Subscribable.Subscribers { + if channel.Spec.SubscribableSpec != nil { + for _, want := range channel.Spec.SubscribableSpec.Subscribers { if got, ok := exists[want.UID]; !ok { // If it does not exist, then create it. subCreates = append(subCreates, want) @@ -154,7 +153,7 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Chan subDeletes = append(subDeletes, e) } - clusterName := channel.GetAnnotations()[duckv1alpha1.ClusterNameAnnotation] + clusterName := channel.GetAnnotations()[duckv1beta1.ClusterNameAnnotation] for _, s := range subCreates { genName := resources.GeneratePullSubscriptionName(s.UID) @@ -169,7 +168,7 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Chan Annotations: resources.GetPullSubscriptionAnnotations(channel.Name, clusterName), Subscriber: s, }) - ps, err := r.RunClientSet.InternalV1alpha1().PullSubscriptions(channel.Namespace).Create(ps) + ps, err := r.RunClientSet.InternalV1beta1().PullSubscriptions(channel.Namespace).Create(ps) if apierrs.IsAlreadyExists(err) { // If the pullsub already exists and is owned by the current channel, mark it for update. if _, found := pullsubs[genName]; found { @@ -208,7 +207,7 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Chan existingPs, found := pullsubs[genName] if !found { // PullSubscription does not exist, that's ok, create it now. - ps, err := r.RunClientSet.InternalV1alpha1().PullSubscriptions(channel.Namespace).Create(ps) + ps, err := r.RunClientSet.InternalV1beta1().PullSubscriptions(channel.Namespace).Create(ps) if apierrs.IsAlreadyExists(err) { // If the pullsub is not owned by the current channel, this is an error. r.Recorder.Eventf(channel, corev1.EventTypeWarning, "SubscriberNotOwned", "Subscriber %q is not owned by this channel", genName) @@ -222,7 +221,7 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Chan // Don't modify the informers copy. desired := existingPs.DeepCopy() desired.Spec = ps.Spec - ps, err := r.RunClientSet.InternalV1alpha1().PullSubscriptions(channel.Namespace).Update(desired) + ps, err := r.RunClientSet.InternalV1beta1().PullSubscriptions(channel.Namespace).Update(desired) if err != nil { r.Recorder.Eventf(channel, corev1.EventTypeWarning, "SubscriberUpdateFailed", "Updating Subscriber %q failed", genName) return err @@ -240,7 +239,7 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Chan for _, s := range subDeletes { genName := resources.GeneratePullSubscriptionName(s.UID) // TODO: we need to handle the case of a already deleted pull subscription. Perhaps move to ensure deleted method. - if err := r.RunClientSet.InternalV1alpha1().PullSubscriptions(channel.Namespace).Delete(genName, &metav1.DeleteOptions{}); err != nil { + if err := r.RunClientSet.InternalV1beta1().PullSubscriptions(channel.Namespace).Delete(genName, &metav1.DeleteOptions{}); err != nil { logging.FromContext(ctx).Desugar().Error("unable to delete PullSubscription for Channel", zap.String("ps", genName), zap.String("channel", channel.Name), zap.Error(err)) r.Recorder.Eventf(channel, corev1.EventTypeWarning, "SubscriberDeleteFailed", "Deleting Subscriber %q failed", genName) return err @@ -261,9 +260,9 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Chan return nil } -func (r *Reconciler) syncSubscribersStatus(ctx context.Context, channel *v1alpha1.Channel) error { - if channel.Status.SubscribableStatus == nil { - channel.Status.SubscribableStatus = &eventingduck.SubscribableStatus{ +func (r *Reconciler) syncSubscribersStatus(ctx context.Context, channel *v1beta1.Channel) error { + if equality.Semantic.DeepEqual(channel.Status.SubscribableStatus, eventingduckv1beta1.SubscribableStatus{}){ + channel.Status.SubscribableStatus = eventingduckv1beta1.SubscribableStatus{ Subscribers: make([]eventingduckv1beta1.SubscriberStatus, 0), } } else if channel.Status.SubscribableStatus.Subscribers == nil { @@ -271,7 +270,7 @@ func (r *Reconciler) syncSubscribersStatus(ctx context.Context, channel *v1alpha } // Make a map of subscriber name to PullSubscription for lookup. - pullsubs := make(map[string]inteventsv1alpha1.PullSubscription) + pullsubs := make(map[string]inteventsv1beta1.PullSubscription) if subs, err := r.getPullSubscriptions(ctx, channel); err != nil { logging.FromContext(ctx).Desugar().Error("Failed to list PullSubscriptions", zap.Error(err)) } else { @@ -293,7 +292,7 @@ func (r *Reconciler) syncSubscribersStatus(ctx context.Context, channel *v1alpha return nil } -func (r *Reconciler) reconcileTopic(ctx context.Context, channel *v1alpha1.Channel) (*inteventsv1alpha1.Topic, error) { +func (r *Reconciler) reconcileTopic(ctx context.Context, channel *v1beta1.Channel) (*inteventsv1beta1.Topic, error) { topic, err := r.getTopic(ctx, channel) if err != nil && !apierrors.IsNotFound(err) { logging.FromContext(ctx).Desugar().Error("Unable to get a Topic", zap.Error(err)) @@ -307,7 +306,7 @@ func (r *Reconciler) reconcileTopic(ctx context.Context, channel *v1alpha1.Chann } return topic, nil } - clusterName := channel.GetAnnotations()[duckv1alpha1.ClusterNameAnnotation] + clusterName := channel.GetAnnotations()[duckv1beta1.ClusterNameAnnotation] t := resources.MakeTopic(&resources.TopicArgs{ Owner: channel, Name: resources.GeneratePublisherName(channel), @@ -319,7 +318,7 @@ func (r *Reconciler) reconcileTopic(ctx context.Context, channel *v1alpha1.Chann Annotations: resources.GetTopicAnnotations(clusterName), }) - topic, err = r.RunClientSet.InternalV1alpha1().Topics(channel.Namespace).Create(t) + topic, err = r.RunClientSet.InternalV1beta1().Topics(channel.Namespace).Create(t) if err != nil { logging.FromContext(ctx).Desugar().Error("Failed to create Topic", zap.Error(err)) r.Recorder.Eventf(channel, corev1.EventTypeWarning, "TopicCreateFailed", "Failed to created Topic %q: %s", topic.Name, err.Error()) @@ -329,7 +328,7 @@ func (r *Reconciler) reconcileTopic(ctx context.Context, channel *v1alpha1.Chann return topic, err } -func (r *Reconciler) getTopic(_ context.Context, channel *v1alpha1.Channel) (*inteventsv1alpha1.Topic, error) { +func (r *Reconciler) getTopic(_ context.Context, channel *v1beta1.Channel) (*inteventsv1beta1.Topic, error) { name := resources.GeneratePublisherName(channel) topic, err := r.topicLister.Topics(channel.Namespace).Get(name) if err != nil { @@ -342,12 +341,12 @@ func (r *Reconciler) getTopic(_ context.Context, channel *v1alpha1.Channel) (*in return topic, nil } -func (r *Reconciler) getPullSubscriptions(ctx context.Context, channel *v1alpha1.Channel) ([]inteventsv1alpha1.PullSubscription, error) { - sl, err := r.RunClientSet.InternalV1alpha1().PullSubscriptions(channel.Namespace).List(metav1.ListOptions{ +func (r *Reconciler) getPullSubscriptions(ctx context.Context, channel *v1beta1.Channel) ([]inteventsv1beta1.PullSubscription, error) { + sl, err := r.RunClientSet.InternalV1beta1().PullSubscriptions(channel.Namespace).List(metav1.ListOptions{ // Use GetLabelSelector to select all PullSubscriptions related to this channel. LabelSelector: resources.GetLabelSelector(controllerAgentName, channel.Name, string(channel.UID)).String(), TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.SchemeGroupVersion.String(), + APIVersion: v1beta1.SchemeGroupVersion.String(), Kind: "Channel", }, }) @@ -356,7 +355,7 @@ func (r *Reconciler) getPullSubscriptions(ctx context.Context, channel *v1alpha1 logging.FromContext(ctx).Desugar().Error("Failed to list PullSubscriptions", zap.Error(err)) return nil, err } - subs := []inteventsv1alpha1.PullSubscription(nil) + subs := []inteventsv1beta1.PullSubscription(nil) for _, subscription := range sl.Items { if metav1.IsControlledBy(&subscription, channel) { subs = append(subs, subscription) @@ -365,7 +364,7 @@ func (r *Reconciler) getPullSubscriptions(ctx context.Context, channel *v1alpha1 return subs, nil } -func (r *Reconciler) getPullSubscriptionStatus(ps *inteventsv1alpha1.PullSubscription) (corev1.ConditionStatus, string) { +func (r *Reconciler) getPullSubscriptionStatus(ps *inteventsv1beta1.PullSubscription) (corev1.ConditionStatus, string) { ready := corev1.ConditionTrue message := "" if !ps.Status.IsReady() { @@ -375,7 +374,7 @@ func (r *Reconciler) getPullSubscriptionStatus(ps *inteventsv1alpha1.PullSubscri return ready, message } -func (r *Reconciler) FinalizeKind(ctx context.Context, channel *v1alpha1.Channel) pkgreconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, channel *v1beta1.Channel) pkgreconciler.Event { // If k8s ServiceAccount exists, binds to the default GCP ServiceAccount, and it only has one ownerReference, // remove the corresponding GCP ServiceAccount iam policy binding. // No need to delete k8s ServiceAccount, it will be automatically handled by k8s Garbage Collection. diff --git a/pkg/reconciler/messaging/channel/channel_test.go b/pkg/reconciler/messaging/channel/channel_test.go index 35f2c29b1b..7c4ce9cf26 100644 --- a/pkg/reconciler/messaging/channel/channel_test.go +++ b/pkg/reconciler/messaging/channel/channel_test.go @@ -32,16 +32,15 @@ import ( "knative.dev/pkg/configmap" "knative.dev/pkg/controller" logtesting "knative.dev/pkg/logging/testing" - - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" + eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" . "knative.dev/pkg/reconciler/testing" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/reconciler/messaging/v1alpha1/channel" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/reconciler/messaging/v1beta1/channel" testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" @@ -75,7 +74,7 @@ var ( sinkGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Sink", } @@ -90,7 +89,7 @@ var ( func init() { // Add types to scheme - _ = inteventsv1alpha1.AddToScheme(scheme.Scheme) + _ = inteventsv1beta1.AddToScheme(scheme.Scheme) } func patchFinalizers(namespace, name string, add bool) clientgotesting.PatchActionImpl { @@ -121,12 +120,12 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithChannelDefaults, WithChannelAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), ), }, @@ -139,7 +138,7 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithChannelDefaults, @@ -148,7 +147,7 @@ func TestAllCases(t *testing.T) { WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus(nil)), WithChannelTopicID(testTopicID), WithChannelAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithChannelTopicUnknown("TopicNotConfigured", "Topic has not yet been reconciled"), ), @@ -164,7 +163,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, @@ -180,7 +179,7 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, @@ -199,7 +198,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, @@ -215,7 +214,7 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, @@ -236,14 +235,14 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, WithChannelDefaults, WithChannelTopic(testTopicID), WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{ + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, }), ), @@ -258,14 +257,14 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, WithChannelDefaults, WithChannelTopic(testTopicID), WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{ + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, }), // Updates @@ -275,7 +274,7 @@ func TestAllCases(t *testing.T) { ), }}, WantCreates: []runtime.Object{ - newPullSubscription(eventingduck.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), + newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), }, WantPatches: []clientgotesting.PatchActionImpl{ patchFinalizers(testNS, channelName, true), @@ -285,14 +284,14 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, WithChannelDefaults, WithChannelTopic(testTopicID), WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{ + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ {UID: subscriptionUID, Generation: 2, SubscriberURI: subscriberURI, ReplyURI: replyURI}, }), WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{ @@ -300,7 +299,7 @@ func TestAllCases(t *testing.T) { }), ), newReadyTopic(), - newPullSubscription(eventingduck.SubscriberSpec{UID: subscriptionUID, SubscriberURI: apis.HTTP("wrong"), ReplyURI: apis.HTTP("wrong")}), + newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: apis.HTTP("wrong"), ReplyURI: apis.HTTP("wrong")}), }, Key: testNS + "/" + channelName, WantEvents: []string{ @@ -311,14 +310,14 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, WithChannelDefaults, WithChannelTopic(testTopicID), WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{ + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ {UID: subscriptionUID, Generation: 2, SubscriberURI: subscriberURI, ReplyURI: replyURI}, }), // Updates @@ -328,75 +327,77 @@ func TestAllCases(t *testing.T) { ), }}, WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: newPullSubscription(eventingduck.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), - }}, - WantPatches: []clientgotesting.PatchActionImpl{ - patchFinalizers(testNS, channelName, true), - }, - }, { - Name: "subscriber already exists owned by other channel", - Objects: []runtime.Object{ - NewChannel(channelName, testNS, - WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ - Project: testProject, - }), - WithInitChannelConditions, - WithChannelDefaults, - WithChannelTopic(testTopicID), - WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{ - {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, - }), - ), - newReadyTopic(), - newPullSubscriptionWithOwner( - eventingduck.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, - NewChannel("other-channel", testNS, WithChannelUID("other-id"), WithInitChannelConditions), - ), - }, - Key: testNS + "/" + channelName, - WantEvents: []string{ - Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", channelName), - Eventf(corev1.EventTypeWarning, "SubscriberNotOwned", "Subscriber %q is not owned by this channel", "cre-sub-testsubscription-abc-123"), - Eventf(corev1.EventTypeWarning, reconciledSubscribersFailedReason, "Reconcile Subscribers failed with: channel %q does not own subscriber %q", channelName, "cre-sub-testsubscription-abc-123"), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewChannel(channelName, testNS, - WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ - Project: testProject, - }), - WithInitChannelConditions, - WithChannelDefaults, - WithChannelTopic(testTopicID), - WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{ - {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, - }), - // Updates - WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{}), - ), + Object: newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), }}, - WantCreates: []runtime.Object{ - newPullSubscription(eventingduck.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), - }, WantPatches: []clientgotesting.PatchActionImpl{ patchFinalizers(testNS, channelName, true), }, - }, { + }, + //{ + // Name: "subscriber already exists owned by other channel", + // Objects: []runtime.Object{ + // NewChannel(channelName, testNS, + // WithChannelUID(channelUID), + // WithChannelSpec(v1beta1.ChannelSpec{ + // Project: testProject, + // }), + // WithInitChannelConditions, + // WithChannelDefaults, + // WithChannelTopic(testTopicID), + // WithChannelAddress(topicURI), + // WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ + // {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, + // }), + // ), + // newReadyTopic(), + // newPullSubscriptionWithOwner( + // eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, + // NewChannel("other-channel", testNS, WithChannelUID("other-id"), WithInitChannelConditions), + // ), + // }, + // Key: testNS + "/" + channelName, + // WantEvents: []string{ + // Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", channelName), + // Eventf(corev1.EventTypeWarning, "SubscriberNotOwned", "Subscriber %q is not owned by this channel", "cre-sub-testsubscription-abc-123"), + // Eventf(corev1.EventTypeWarning, reconciledSubscribersFailedReason, "Reconcile Subscribers failed with: channel %q does not own subscriber %q", channelName, "cre-sub-testsubscription-abc-123"), + // }, + // WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + // Object: NewChannel(channelName, testNS, + // WithChannelUID(channelUID), + // WithChannelSpec(v1beta1.ChannelSpec{ + // Project: testProject, + // }), + // WithInitChannelConditions, + // WithChannelDefaults, + // WithChannelTopic(testTopicID), + // WithChannelAddress(topicURI), + // WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ + // {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, + // }), + // // Updates + // WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{}), + // ), + // }}, + // WantCreates: []runtime.Object{ + // newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), + // }, + // WantPatches: []clientgotesting.PatchActionImpl{ + // patchFinalizers(testNS, channelName, true), + // }, + //}, + { Name: "subscriber already exists in status owned by other channel", Objects: []runtime.Object{ NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, WithChannelDefaults, WithChannelTopic(testTopicID), WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{ + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, }), WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{ @@ -405,7 +406,7 @@ func TestAllCases(t *testing.T) { ), newReadyTopic(), newPullSubscriptionWithOwner( - eventingduck.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, + eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, NewChannel("other-channel", testNS, WithChannelUID("other-id"), WithInitChannelConditions), ), }, @@ -416,7 +417,7 @@ func TestAllCases(t *testing.T) { Eventf(corev1.EventTypeWarning, reconciledSubscribersFailedReason, "Reconcile Subscribers failed with: channel %q does not own subscriber %q", channelName, "cre-sub-testsubscription-abc-123"), }, WantCreates: []runtime.Object{ - newPullSubscription(eventingduck.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), + newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), }, WantPatches: []clientgotesting.PatchActionImpl{ patchFinalizers(testNS, channelName, true), @@ -426,14 +427,14 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, WithChannelDefaults, WithChannelTopic(testTopicID), WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{ + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ {UID: subscriptionUID, Generation: 1, SubscriberURI: subscriberURI, ReplyURI: replyURI}, }), WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{ @@ -449,7 +450,7 @@ func TestAllCases(t *testing.T) { Eventf(corev1.EventTypeNormal, reconciledSuccessReason, `Channel reconciled: "%s/%s"`, testNS, channelName), }, WantCreates: []runtime.Object{ - newPullSubscription(eventingduck.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), + newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), }, WantPatches: []clientgotesting.PatchActionImpl{ patchFinalizers(testNS, channelName, true), @@ -459,20 +460,20 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, WithChannelDefaults, WithChannelTopic(testTopicID), WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{}), + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{}), WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{ {UID: subscriptionUID}, }), ), newReadyTopic(), - newPullSubscription(eventingduck.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), + newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), }, Key: testNS + "/" + channelName, WantEvents: []string{ @@ -483,21 +484,21 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, WithChannelDefaults, WithChannelTopic(testTopicID), WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduck.SubscriberSpec{}), + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{}), // Updates WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{}), ), }}, WantDeletes: []clientgotesting.DeleteActionImpl{ {ActionImpl: clientgotesting.ActionImpl{ - Namespace: "testnamespace", Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "pullsubscriptions"}}, + Namespace: "testnamespace", Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "pullsubscriptions"}}, Name: "cre-sub-testsubscription-abc-123", }, }, @@ -519,10 +520,10 @@ func TestAllCases(t *testing.T) { } -func newTopic() *inteventsv1alpha1.Topic { +func newTopic() *inteventsv1beta1.Topic { channel := NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, @@ -537,12 +538,12 @@ func newTopic() *inteventsv1alpha1.Topic { Secret: channel.Spec.Secret, Labels: resources.GetLabels(controllerAgentName, channel.Name, string(channel.UID)), Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }, }) } -func newReadyTopic() *inteventsv1alpha1.Topic { +func newReadyTopic() *inteventsv1beta1.Topic { topic := newTopic() url, _ := apis.ParseURL(topicURI) topic.Status.SetAddress(url) @@ -551,7 +552,7 @@ func newReadyTopic() *inteventsv1alpha1.Topic { return topic } -func newFalseTopic() *inteventsv1alpha1.Topic { +func newFalseTopic() *inteventsv1beta1.Topic { topic := newTopic() url, _ := apis.ParseURL(topicURI) topic.Status.SetAddress(url) @@ -559,10 +560,10 @@ func newFalseTopic() *inteventsv1alpha1.Topic { return topic } -func newPullSubscription(subscriber eventingduck.SubscriberSpec) *inteventsv1alpha1.PullSubscription { +func newPullSubscription(subscriber eventingduckv1beta1.SubscriberSpec) *inteventsv1beta1.PullSubscription { channel := NewChannel(channelName, testNS, WithChannelUID(channelUID), - WithChannelSpec(v1alpha1.ChannelSpec{ + WithChannelSpec(v1beta1.ChannelSpec{ Project: testProject, }), WithInitChannelConditions, @@ -572,7 +573,7 @@ func newPullSubscription(subscriber eventingduck.SubscriberSpec) *inteventsv1alp return newPullSubscriptionWithOwner(subscriber, channel) } -func newPullSubscriptionWithOwner(subscriber eventingduck.SubscriberSpec, channel *v1alpha1.Channel) *inteventsv1alpha1.PullSubscription { +func newPullSubscriptionWithOwner(subscriber eventingduckv1beta1.SubscriberSpec, channel *v1beta1.Channel) *inteventsv1beta1.PullSubscription { return resources.MakePullSubscription(&resources.PullSubscriptionArgs{ Owner: channel, Name: resources.GeneratePullSubscriptionName(subscriber.UID), @@ -580,7 +581,76 @@ func newPullSubscriptionWithOwner(subscriber eventingduck.SubscriberSpec, channe Topic: channel.Status.TopicID, Secret: channel.Spec.Secret, Labels: resources.GetPullSubscriptionLabels(controllerAgentName, channel.Name, resources.GeneratePullSubscriptionName(subscriber.UID), string(channel.UID)), - Annotations: resources.GetPullSubscriptionAnnotations(channel.Name, channel.GetAnnotations()[duckv1alpha1.ClusterNameAnnotation]), + Annotations: resources.GetPullSubscriptionAnnotations(channel.Name, channel.GetAnnotations()[duckv1beta1.ClusterNameAnnotation]), Subscriber: subscriber, }) } + + +//// TODO add a unit test for successfully creating a k8s service account, after issue https://github.com/google/knative-gcp/issues/657 gets solved. +//func TestDEBUG(t *testing.T) { +// table := TableTest{ { +// Name: "subscriber already exists owned by other channel", +// Objects: []runtime.Object{ +// NewChannel(channelName, testNS, +// WithChannelUID(channelUID), +// WithChannelSpec(v1beta1.ChannelSpec{ +// Project: testProject, +// }), +// WithInitChannelConditions, +// WithChannelDefaults, +// WithChannelTopic(testTopicID), +// WithChannelAddress(topicURI), +// WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ +// {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, +// }), +// ), +// newReadyTopic(), +// newPullSubscriptionWithOwner( +// eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, +// NewChannel("other-channel", testNS, WithChannelUID("other-id"), WithInitChannelConditions), +// ), +// }, +// Key: testNS + "/" + channelName, +// WantEvents: []string{ +// Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", channelName), +// Eventf(corev1.EventTypeWarning, "SubscriberNotOwned", "Subscriber %q is not owned by this channel", "cre-sub-testsubscription-abc-123"), +// Eventf(corev1.EventTypeWarning, reconciledSubscribersFailedReason, "Reconcile Subscribers failed with: channel %q does not own subscriber %q", channelName, "cre-sub-testsubscription-abc-123"), +// }, +// WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ +// Object: NewChannel(channelName, testNS, +// WithChannelUID(channelUID), +// WithChannelSpec(v1beta1.ChannelSpec{ +// Project: testProject, +// }), +// WithInitChannelConditions, +// WithChannelDefaults, +// WithChannelTopic(testTopicID), +// WithChannelAddress(topicURI), +// WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ +// {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, +// }), +// // Updates +// WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{}), +// ), +// }}, +// WantCreates: []runtime.Object{ +// newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), +// }, +// WantPatches: []clientgotesting.PatchActionImpl{ +// patchFinalizers(testNS, channelName, true), +// }, +// }} +// +// defer logtesting.ClearAll() +// table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher, _ map[string]interface{}) controller.Reconciler { +// r := &Reconciler{ +// Base: reconciler.NewBase(ctx, controllerAgentName, cmw), +// Identity: identity.NewIdentity(ctx, NoopIAMPolicyManager, NewGCPAuthTestStore(t, nil)), +// channelLister: listers.GetChannelLister(), +// topicLister: listers.GetTopicLister(), +// } +// return channel.NewReconciler(ctx, r.Logger, r.RunClientSet, listers.GetChannelLister(), r.Recorder, r) +// })) +// +//} \ No newline at end of file diff --git a/pkg/reconciler/messaging/channel/controller.go b/pkg/reconciler/messaging/channel/controller.go index 358b24e4e5..e9ef7ea6c2 100644 --- a/pkg/reconciler/messaging/channel/controller.go +++ b/pkg/reconciler/messaging/channel/controller.go @@ -27,10 +27,10 @@ import ( "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" - pullsubscriptioninformer "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription" - topicinformer "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic" - channelinformer "github.com/google/knative-gcp/pkg/client/injection/informers/messaging/v1alpha1/channel" - channelreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/messaging/v1alpha1/channel" + pullsubscriptioninformer "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription" + topicinformer "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic" + channelinformer "github.com/google/knative-gcp/pkg/client/injection/informers/messaging/v1beta1/channel" + channelreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/messaging/v1beta1/channel" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/identity/iam" diff --git a/pkg/reconciler/messaging/channel/resources/names.go b/pkg/reconciler/messaging/channel/resources/names.go index 21427c707d..564aa8d7ff 100644 --- a/pkg/reconciler/messaging/channel/resources/names.go +++ b/pkg/reconciler/messaging/channel/resources/names.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/types" "knative.dev/pkg/kmeta" - "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" "github.com/google/knative-gcp/pkg/utils/naming" ) @@ -32,11 +32,11 @@ const ( ) // GenerateTopicID generates the name of the Pub/Sub topic, not our Topic resource. -func GenerateTopicID(channel *v1alpha1.Channel) string { +func GenerateTopicID(channel *v1beta1.Channel) string { return naming.TruncatedPubsubResourceName("cre-chan", channel.Namespace, channel.Name, channel.UID) } -func GeneratePublisherName(channel *v1alpha1.Channel) string { +func GeneratePublisherName(channel *v1beta1.Channel) string { if strings.HasPrefix(channel.Name, "cre-") { return kmeta.ChildName(channel.Name, "-chan") } diff --git a/pkg/reconciler/messaging/channel/resources/pullsubscription.go b/pkg/reconciler/messaging/channel/resources/pullsubscription.go index 3aedb770cb..619e46be10 100644 --- a/pkg/reconciler/messaging/channel/resources/pullsubscription.go +++ b/pkg/reconciler/messaging/channel/resources/pullsubscription.go @@ -19,12 +19,12 @@ package resources import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" + duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/kmeta" - gcpduckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + gcpduckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" ) // PullSubscriptionArgs are the arguments needed to create a Channel Subscriber. @@ -39,17 +39,17 @@ type PullSubscriptionArgs struct { Secret *corev1.SecretKeySelector Labels map[string]string Annotations map[string]string - Subscriber duckv1alpha1.SubscriberSpec + Subscriber duckv1beta1.SubscriberSpec } // MakePullSubscription generates (but does not insert into K8s) the // PullSubscription for Channels. -func MakePullSubscription(args *PullSubscriptionArgs) *v1alpha1.PullSubscription { +func MakePullSubscription(args *PullSubscriptionArgs) *v1beta1.PullSubscription { - spec := v1alpha1.PullSubscriptionSpec{ - PubSubSpec: gcpduckv1alpha1.PubSubSpec{ + spec := v1beta1.PullSubscriptionSpec{ + PubSubSpec: gcpduckv1beta1.PubSubSpec{ SourceSpec: duckv1.SourceSpec{}, - IdentitySpec: gcpduckv1alpha1.IdentitySpec{ + IdentitySpec: gcpduckv1beta1.IdentitySpec{ ServiceAccountName: args.ServiceAccountName, }, Secret: args.Secret, @@ -83,7 +83,7 @@ func MakePullSubscription(args *PullSubscriptionArgs) *v1alpha1.PullSubscription } } - return &v1alpha1.PullSubscription{ + return &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Namespace: args.Owner.GetObjectMeta().GetNamespace(), Name: args.Name, diff --git a/pkg/reconciler/messaging/channel/resources/topic.go b/pkg/reconciler/messaging/channel/resources/topic.go index 372e522c02..02aa404a31 100644 --- a/pkg/reconciler/messaging/channel/resources/topic.go +++ b/pkg/reconciler/messaging/channel/resources/topic.go @@ -22,8 +22,8 @@ import ( "knative.dev/pkg/kmeta" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" ) // TopicArgs are the arguments needed to create a Channel Topic. @@ -41,8 +41,8 @@ type TopicArgs struct { } // MakeInvoker generates (but does not insert into K8s) the Topic for Channels. -func MakeTopic(args *TopicArgs) *v1alpha1.Topic { - return &v1alpha1.Topic{ +func MakeTopic(args *TopicArgs) *v1beta1.Topic { + return &v1beta1.Topic{ ObjectMeta: metav1.ObjectMeta{ Namespace: args.Owner.GetObjectMeta().GetNamespace(), Name: args.Name, @@ -50,14 +50,14 @@ func MakeTopic(args *TopicArgs) *v1alpha1.Topic { Annotations: args.Annotations, OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(args.Owner)}, }, - Spec: v1alpha1.TopicSpec{ + Spec: v1beta1.TopicSpec{ IdentitySpec: duckv1alpha1.IdentitySpec{ ServiceAccountName: args.ServiceAccountName, }, Secret: args.Secret, Project: args.Project, Topic: args.Topic, - PropagationPolicy: v1alpha1.TopicPolicyCreateDelete, + PropagationPolicy: v1beta1.TopicPolicyCreateDelete, }, } } diff --git a/pkg/reconciler/testing/channel.go b/pkg/reconciler/testing/channel.go index ddf215f91b..e5e9ff19f9 100644 --- a/pkg/reconciler/testing/channel.go +++ b/pkg/reconciler/testing/channel.go @@ -26,18 +26,18 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" + duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" ) // ChannelOption enables further configuration of a Channel. -type ChannelOption func(*v1alpha1.Channel) +type ChannelOption func(*v1beta1.Channel) // NewChannel creates a Channel with ChannelOptions -func NewChannel(name, namespace string, so ...ChannelOption) *v1alpha1.Channel { - s := &v1alpha1.Channel{ +func NewChannel(name, namespace string, so ...ChannelOption) *v1beta1.Channel { + s := &v1beta1.Channel{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, @@ -51,8 +51,8 @@ func NewChannel(name, namespace string, so ...ChannelOption) *v1alpha1.Channel { } // NewChannelWithoutNamespace creates a Channel with ChannelOptions but without a specific namespace -func NewChannelWithoutNamespace(name string, so ...ChannelOption) *v1alpha1.Channel { - s := &v1alpha1.Channel{ +func NewChannelWithoutNamespace(name string, so ...ChannelOption) *v1beta1.Channel { + s := &v1beta1.Channel{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -65,83 +65,83 @@ func NewChannelWithoutNamespace(name string, so ...ChannelOption) *v1alpha1.Chan } func WithChannelUID(uid types.UID) ChannelOption { - return func(s *v1alpha1.Channel) { + return func(s *v1beta1.Channel) { s.UID = uid } } func WithChannelGenerateName(generateName string) ChannelOption { - return func(c *v1alpha1.Channel) { + return func(c *v1beta1.Channel) { c.ObjectMeta.GenerateName = generateName } } // WithInitChannelConditions initializes the Channels's conditions. -func WithInitChannelConditions(s *v1alpha1.Channel) { +func WithInitChannelConditions(s *v1beta1.Channel) { s.Status.InitializeConditions() } // WithChannelServiceAccountName will give status.ServiceAccountName a k8s service account name, which is related on Workload Identity's Google service account. func WithChannelServiceAccountName(name string) ChannelOption { - return func(s *v1alpha1.Channel) { + return func(s *v1beta1.Channel) { s.Status.ServiceAccountName = name } } func WithChannelWorkloadIdentityFailed(reason, message string) ChannelOption { - return func(s *v1alpha1.Channel) { + return func(s *v1beta1.Channel) { s.Status.MarkWorkloadIdentityFailed(s.ConditionSet(), reason, message) } } func WithChannelTopic(topicID string) ChannelOption { - return func(s *v1alpha1.Channel) { + return func(s *v1beta1.Channel) { s.Status.MarkTopicReady() s.Status.TopicID = topicID } } func WithChannelTopicID(topicID string) ChannelOption { - return func(s *v1alpha1.Channel) { + return func(s *v1beta1.Channel) { s.Status.TopicID = topicID } } func WithChannelTopicFailed(reason, message string) ChannelOption { - return func(c *v1alpha1.Channel) { + return func(c *v1beta1.Channel) { c.Status.MarkTopicFailed(reason, message) } } func WithChannelTopicUnknown(reason, message string) ChannelOption { - return func(c *v1alpha1.Channel) { + return func(c *v1beta1.Channel) { c.Status.MarkTopicUnknown(reason, message) } } -func WithChannelSpec(spec v1alpha1.ChannelSpec) ChannelOption { - return func(s *v1alpha1.Channel) { +func WithChannelSpec(spec v1beta1.ChannelSpec) ChannelOption { + return func(s *v1beta1.Channel) { s.Spec = spec } } -func WithChannelDefaults(s *v1alpha1.Channel) { +func WithChannelDefaults(s *v1beta1.Channel) { s.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) } func WithChannelServiceAccount(kServiceAccount string) ChannelOption { - return func(ps *v1alpha1.Channel) { + return func(ps *v1beta1.Channel) { ps.Spec.ServiceAccountName = kServiceAccount } } -func WithChannelDeletionTimestamp(s *v1alpha1.Channel) { +func WithChannelDeletionTimestamp(s *v1beta1.Channel) { t := metav1.NewTime(time.Unix(1e9, 0)) s.ObjectMeta.SetDeletionTimestamp(&t) } func WithChannelReady(topicID string) ChannelOption { - return func(s *v1alpha1.Channel) { + return func(s *v1beta1.Channel) { s.Status.InitializeConditions() s.Status.MarkTopicReady() s.Status.TopicID = topicID @@ -149,47 +149,47 @@ func WithChannelReady(topicID string) ChannelOption { } func WithChannelAddress(url string) ChannelOption { - return func(s *v1alpha1.Channel) { + return func(s *v1beta1.Channel) { u, _ := apis.ParseURL(url) s.Status.SetAddress(u) } } -func WithChannelSubscribers(subscribers []duckv1alpha1.SubscriberSpec) ChannelOption { - return func(c *v1alpha1.Channel) { - c.Spec.Subscribable = &duckv1alpha1.Subscribable{ +func WithChannelSubscribers(subscribers []duckv1beta1.SubscriberSpec) ChannelOption { + return func(c *v1beta1.Channel) { + c.Spec.SubscribableSpec = &duckv1beta1.SubscribableSpec{ Subscribers: subscribers, } } } func WithChannelSubscribersStatus(subscribers []eventingduckv1beta1.SubscriberStatus) ChannelOption { - return func(c *v1alpha1.Channel) { - c.Status.SubscribableStatus = &duckv1alpha1.SubscribableStatus{ + return func(c *v1beta1.Channel) { + c.Status.SubscribableStatus = duckv1beta1.SubscribableStatus{ Subscribers: subscribers, } } } -func WithChannelDeleted(s *v1alpha1.Channel) { +func WithChannelDeleted(s *v1beta1.Channel) { t := metav1.NewTime(time.Unix(1e9, 0)) s.ObjectMeta.SetDeletionTimestamp(&t) } func WithChannelOwnerReferences(ownerReferences []metav1.OwnerReference) ChannelOption { - return func(c *v1alpha1.Channel) { + return func(c *v1beta1.Channel) { c.ObjectMeta.OwnerReferences = ownerReferences } } func WithChannelLabels(labels map[string]string) ChannelOption { - return func(c *v1alpha1.Channel) { + return func(c *v1beta1.Channel) { c.ObjectMeta.Labels = labels } } func WithChannelAnnotations(Annotations map[string]string) ChannelOption { - return func(c *v1alpha1.Channel) { + return func(c *v1beta1.Channel) { c.ObjectMeta.Annotations = Annotations } } diff --git a/pkg/reconciler/testing/listers.go b/pkg/reconciler/testing/listers.go index ef3c8d1f61..08cf67605a 100644 --- a/pkg/reconciler/testing/listers.go +++ b/pkg/reconciler/testing/listers.go @@ -45,15 +45,15 @@ import ( brokerv1beta1 "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" intv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - MessagingV1alpha1 "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + Messagingv1beta1 "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" fakeeventsclientset "github.com/google/knative-gcp/pkg/client/clientset/versioned/fake" brokerlisters "github.com/google/knative-gcp/pkg/client/listers/broker/v1beta1" eventslisters "github.com/google/knative-gcp/pkg/client/listers/events/v1alpha1" - inteventslisters "github.com/google/knative-gcp/pkg/client/listers/intevents/v1alpha1" intlisters "github.com/google/knative-gcp/pkg/client/listers/intevents/v1alpha1" - messaginglisters "github.com/google/knative-gcp/pkg/client/listers/messaging/v1alpha1" + inteventslisters "github.com/google/knative-gcp/pkg/client/listers/intevents/v1beta1" + messaginglisters "github.com/google/knative-gcp/pkg/client/listers/messaging/v1beta1" ) var sinkAddToScheme = func(scheme *runtime.Scheme) error { @@ -117,15 +117,15 @@ func (l *Listers) GetServingObjects() []runtime.Object { } func (l *Listers) GetPullSubscriptionLister() inteventslisters.PullSubscriptionLister { - return inteventslisters.NewPullSubscriptionLister(l.indexerFor(&inteventsv1alpha1.PullSubscription{})) + return inteventslisters.NewPullSubscriptionLister(l.indexerFor(&inteventsv1beta1.PullSubscription{})) } func (l *Listers) GetTopicLister() inteventslisters.TopicLister { - return inteventslisters.NewTopicLister(l.indexerFor(&inteventsv1alpha1.Topic{})) + return inteventslisters.NewTopicLister(l.indexerFor(&inteventsv1beta1.Topic{})) } func (l *Listers) GetChannelLister() messaginglisters.ChannelLister { - return messaginglisters.NewChannelLister(l.indexerFor(&MessagingV1alpha1.Channel{})) + return messaginglisters.NewChannelLister(l.indexerFor(&Messagingv1beta1.Channel{})) } func (l *Listers) GetJobLister() batchv1listers.JobLister { From 95c99cca4e186435d1342ecdf0ecf8b2507d7348 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Wed, 10 Jun 2020 23:57:06 +0000 Subject: [PATCH 02/14] updated cloudbuildsource to v1beta1 --- pkg/apis/duck/v1beta1/annotations.go | 28 ++ .../v1beta1/cloudbuildsource_defaults.go | 6 +- .../v1beta1/cloudbuildsource_defaults_test.go | 20 +- .../cloudbuildsource_lifecycle_test.go | 10 +- .../events/v1beta1/cloudbuildsource_types.go | 18 +- .../v1beta1/cloudbuildsource_types_test.go | 14 +- .../v1beta1/cloudbuildsource_validation.go | 8 +- .../cloudbuildsource_validation_test.go | 28 +- .../events/v1beta1/zz_generated.deepcopy.go | 100 +++++ .../typed/events/v1beta1/cloudbuildsource.go | 191 ++++++++++ .../typed/events/v1beta1/events_client.go | 5 + .../v1beta1/fake/fake_cloudbuildsource.go | 140 +++++++ .../events/v1beta1/fake/fake_events_client.go | 4 + .../events/v1beta1/generated_expansion.go | 2 + .../events/v1beta1/cloudbuildsource.go | 89 +++++ .../events/v1beta1/interface.go | 7 + .../informers/externalversions/generic.go | 2 + .../cloudbuildsource/cloudbuildsource.go | 52 +++ .../v1beta1/cloudbuildsource/fake/fake.go | 40 ++ .../v1beta1/cloudbuildsource/controller.go | 118 ++++++ .../v1beta1/cloudbuildsource/reconciler.go | 353 ++++++++++++++++++ .../cloudbuildsource/stub/controller.go | 54 +++ .../cloudbuildsource/stub/reconciler.go | 66 ++++ .../events/v1beta1/cloudbuildsource.go | 94 +++++ .../events/v1beta1/expansion_generated.go | 8 + pkg/reconciler/events/auditlogs/auditlogs.go | 18 +- pkg/reconciler/events/auditlogs/controller.go | 16 +- .../events/auditlogs/resources/names.go | 8 +- pkg/reconciler/events/build/build.go | 10 +- pkg/reconciler/events/build/controller.go | 10 +- pkg/reconciler/events/pubsub/controller.go | 12 +- pkg/reconciler/events/pubsub/pubsub.go | 10 +- pkg/reconciler/events/scheduler/controller.go | 16 +- .../events/scheduler/resources/names.go | 8 +- pkg/reconciler/events/scheduler/scheduler.go | 18 +- pkg/reconciler/events/storage/controller.go | 16 +- .../events/storage/resources/names.go | 4 +- .../events/storage/resources/names_test.go | 4 +- pkg/reconciler/events/storage/storage.go | 22 +- pkg/reconciler/events/storage/storage_test.go | 140 +++---- .../pullsubscription/keda/resources/names.go | 4 +- .../keda/resources/scaled_object.go | 22 +- .../intevents/pullsubscription/reconciler.go | 22 +- .../pullsubscription/resources/names.go | 10 +- .../resources/receive_adapter.go | 10 +- .../pullsubscription/static/controller.go | 12 +- .../static/pullsubscription.go | 10 +- pkg/reconciler/intevents/reconciler.go | 26 +- .../intevents/resources/pullsubscription.go | 18 +- pkg/reconciler/intevents/resources/topic.go | 16 +- pkg/reconciler/intevents/topic/controller.go | 10 +- pkg/reconciler/testing/listers.go | 2 +- pkg/reconciler/testing/pullsubscription.go | 88 ++--- pkg/reconciler/testing/topic.go | 60 +-- 54 files changed, 1716 insertions(+), 363 deletions(-) create mode 100644 pkg/client/clientset/versioned/typed/events/v1beta1/cloudbuildsource.go create mode 100644 pkg/client/clientset/versioned/typed/events/v1beta1/fake/fake_cloudbuildsource.go create mode 100644 pkg/client/informers/externalversions/events/v1beta1/cloudbuildsource.go create mode 100644 pkg/client/injection/informers/events/v1beta1/cloudbuildsource/cloudbuildsource.go create mode 100644 pkg/client/injection/informers/events/v1beta1/cloudbuildsource/fake/fake.go create mode 100644 pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/controller.go create mode 100644 pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/reconciler.go create mode 100644 pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/stub/controller.go create mode 100644 pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/stub/reconciler.go create mode 100644 pkg/client/listers/events/v1beta1/cloudbuildsource.go diff --git a/pkg/apis/duck/v1beta1/annotations.go b/pkg/apis/duck/v1beta1/annotations.go index 7067ad7f34..977fa99f19 100644 --- a/pkg/apis/duck/v1beta1/annotations.go +++ b/pkg/apis/duck/v1beta1/annotations.go @@ -19,6 +19,9 @@ package v1beta1 import ( "context" "fmt" + "github.com/google/go-cmp/cmp" + metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" + "github.com/google/knative-gcp/pkg/utils" "math" "strconv" @@ -163,3 +166,28 @@ func validateAnnotationNotExists(annotations map[string]string, annotation strin } return errs } + +// SetClusterNameAnnotation sets the cluster-name annotation when running on GKE or GCE. +func SetClusterNameAnnotation(obj *metav1.ObjectMeta, client metadataClient.Client) { + if _, ok := obj.Annotations[ClusterNameAnnotation]; !ok && client.OnGCE() { + clusterName, err := utils.ClusterName(obj.Annotations[ClusterNameAnnotation], client) + // If metadata access is disabled for some reason, leave the annotation to be empty. + if err == nil { + setDefaultAnnotationIfNotPresent(obj, ClusterNameAnnotation, clusterName) + } + } +} + +// CheckImmutableClusterNameAnnotation checks non-empty cluster-name annotation is immutable. +func CheckImmutableClusterNameAnnotation(current *metav1.ObjectMeta, original *metav1.ObjectMeta, errs *apis.FieldError) *apis.FieldError { + if _, ok := original.Annotations[ClusterNameAnnotation]; ok { + if diff := cmp.Diff(original.Annotations[ClusterNameAnnotation], current.Annotations[ClusterNameAnnotation]); diff != "" { + return errs.Also(&apis.FieldError{ + Message: "Immutable fields changed (-old +new)", + Paths: []string{fmt.Sprintf("metadata.annotations[%s]", ClusterNameAnnotation)}, + Details: diff, + }) + } + } + return errs +} diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go b/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go index 4b31fa73c0..bf09793656 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go @@ -21,7 +21,7 @@ import ( "knative.dev/pkg/apis" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" "knative.dev/pkg/ptr" @@ -34,8 +34,8 @@ const ( func (bs *CloudBuildSource) SetDefaults(ctx context.Context) { ctx = apis.WithinParent(ctx, bs.ObjectMeta) bs.Spec.SetDefaults(ctx) - duckv1alpha1.SetClusterNameAnnotation(&bs.ObjectMeta, metadataClient.NewDefaultMetadataClient()) - duckv1alpha1.SetAutoscalingAnnotationsDefaults(ctx, &bs.ObjectMeta) + duckv1beta1.SetClusterNameAnnotation(&bs.ObjectMeta, metadataClient.NewDefaultMetadataClient()) + duckv1beta1.SetAutoscalingAnnotationsDefaults(ctx, &bs.ObjectMeta) } func (bss *CloudBuildSourceSpec) SetDefaults(ctx context.Context) { diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go index d1f4db69b5..a238751bcc 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go @@ -24,7 +24,7 @@ import ( "knative.dev/pkg/ptr" "github.com/google/go-cmp/cmp" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" corev1 "k8s.io/api/core/v1" @@ -42,11 +42,11 @@ func TestBuildSourceDefaults(t *testing.T) { start: &CloudBuildSource{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }, }, Spec: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "my-cloud-key", @@ -60,11 +60,11 @@ func TestBuildSourceDefaults(t *testing.T) { want: &CloudBuildSource{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }, }, Spec: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "my-cloud-key", @@ -81,7 +81,7 @@ func TestBuildSourceDefaults(t *testing.T) { start: &CloudBuildSource{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }, }, Spec: CloudBuildSourceSpec{}, @@ -89,11 +89,11 @@ func TestBuildSourceDefaults(t *testing.T) { want: &CloudBuildSource{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }, }, Spec: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &gcpauthtesthelper.Secret, }, Topic: ptr.String(defaultTopic), @@ -117,11 +117,11 @@ func TestCloudBuildSourceDefaults_NoChange(t *testing.T) { want := &CloudBuildSource{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }, }, Spec: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "my-cloud-key", diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go index aceabc8278..84f042b89a 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go @@ -21,7 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" ) @@ -124,9 +124,9 @@ func TestCloudBuildSourceStatusGetCondition(t *testing.T) { s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), "NotReady", "test message") return &s.Status }(), - condQuery: duckv1alpha1.PullSubscriptionReady, + condQuery: duckv1beta1.PullSubscriptionReady, want: &apis.Condition{ - Type: duckv1alpha1.PullSubscriptionReady, + Type: duckv1beta1.PullSubscriptionReady, Status: corev1.ConditionFalse, Reason: "NotReady", Message: "test message", @@ -139,9 +139,9 @@ func TestCloudBuildSourceStatusGetCondition(t *testing.T) { s.Status.MarkPullSubscriptionReady(s.ConditionSet()) return &s.Status }(), - condQuery: duckv1alpha1.PullSubscriptionReady, + condQuery: duckv1beta1.PullSubscriptionReady, want: &apis.Condition{ - Type: duckv1alpha1.PullSubscriptionReady, + Type: duckv1beta1.PullSubscriptionReady, Status: corev1.ConditionTrue, }, }} diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_types.go b/pkg/apis/events/v1beta1/cloudbuildsource_types.go index 5cc5aac623..4c45dc6354 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_types.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_types.go @@ -16,8 +16,8 @@ package v1beta1 import ( "fmt" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - kngcpduck "github.com/google/knative-gcp/pkg/duck/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + kngcpduck "github.com/google/knative-gcp/pkg/duck/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis/duck" "knative.dev/pkg/kmeta" @@ -52,7 +52,7 @@ var ( type CloudBuildSourceSpec struct { // This brings in the PubSub based Source Specs. Includes: // Sink, CloudEventOverrides, Secret, and Project - duckv1alpha1.PubSubSpec `json:",inline"` + duckv1beta1.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 @@ -84,12 +84,12 @@ const ( ) var buildCondSet = apis.NewLivingConditionSet( - duckv1alpha1.PullSubscriptionReady, + duckv1beta1.PullSubscriptionReady, ) // CloudBuildSourceStatus defines the observed state of CloudBuildSource. type CloudBuildSourceStatus struct { - duckv1alpha1.PubSubStatus `json:",inline"` + duckv1beta1.PubSubStatus `json:",inline"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -108,22 +108,22 @@ func (*CloudBuildSource) GetGroupVersionKind() schema.GroupVersionKind { // Methods for identifiable interface. // IdentitySpec returns the IdentitySpec portion of the Spec. -func (s *CloudBuildSource) IdentitySpec() *duckv1alpha1.IdentitySpec { +func (s *CloudBuildSource) IdentitySpec() *duckv1beta1.IdentitySpec { return &s.Spec.IdentitySpec } // IdentityStatus returns the IdentityStatus portion of the Status. -func (s *CloudBuildSource) IdentityStatus() *duckv1alpha1.IdentityStatus { +func (s *CloudBuildSource) IdentityStatus() *duckv1beta1.IdentityStatus { return &s.Status.IdentityStatus } // CloudBuildSourceSpec returns the CloudBuildSourceSpec portion of the Spec. -func (bs *CloudBuildSource) PubSubSpec() *duckv1alpha1.PubSubSpec { +func (bs *CloudBuildSource) PubSubSpec() *duckv1beta1.PubSubSpec { return &bs.Spec.PubSubSpec } // PubSubStatus returns the PubSubStatus portion of the Status. -func (bs *CloudBuildSource) PubSubStatus() *duckv1alpha1.PubSubStatus { +func (bs *CloudBuildSource) PubSubStatus() *duckv1beta1.PubSubStatus { return &bs.Status.PubSubStatus } diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_types_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_types_test.go index 3fe9a9f23e..170d0f7385 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_types_test.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_types_test.go @@ -20,7 +20,7 @@ import ( "knative.dev/pkg/apis" "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -37,7 +37,7 @@ func TestCloudBuildSourceEventSource(t *testing.T) { func TestCloudBuildSourceGetGroupVersionKind(t *testing.T) { want := schema.GroupVersionKind{ Group: "events.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "CloudBuildSource", } @@ -52,8 +52,8 @@ func TestCloudBuildSourceGetGroupVersionKind(t *testing.T) { func TestCloudBuildSourceIdentitySpec(t *testing.T) { s := &CloudBuildSource{ Spec: CloudBuildSourceSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ - IdentitySpec: v1alpha1.IdentitySpec{ + PubSubSpec: v1beta1.PubSubSpec{ + IdentitySpec: v1beta1.IdentitySpec{ ServiceAccountName: "test", }, }, @@ -69,10 +69,10 @@ func TestCloudBuildSourceIdentitySpec(t *testing.T) { func TestCloudBuildSourceIdentityStatus(t *testing.T) { s := &CloudBuildSource{ Status: CloudBuildSourceStatus{ - PubSubStatus: v1alpha1.PubSubStatus{}, + PubSubStatus: v1beta1.PubSubStatus{}, }, } - want := &v1alpha1.IdentityStatus{} + want := &v1beta1.IdentityStatus{} got := s.IdentityStatus() if diff := cmp.Diff(want, got); diff != "" { t.Errorf("failed to get expected (-want, +got) = %v", diff) @@ -81,7 +81,7 @@ func TestCloudBuildSourceIdentityStatus(t *testing.T) { func TestCloudBuildSourceConditionSet(t *testing.T) { want := []apis.Condition{{ - Type: v1alpha1.PullSubscriptionReady, + Type: v1beta1.PullSubscriptionReady, }, { Type: apis.ConditionReady, }} diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_validation.go b/pkg/apis/events/v1beta1/cloudbuildsource_validation.go index e4cf832212..7880e8b352 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_validation.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_validation.go @@ -24,12 +24,12 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" ) func (current *CloudBuildSource) Validate(ctx context.Context) *apis.FieldError { errs := current.Spec.Validate(ctx).ViaField("spec") - return duckv1alpha1.ValidateAutoscalingAnnotations(ctx, current.Annotations, errs) + return duckv1beta1.ValidateAutoscalingAnnotations(ctx, current.Annotations, errs) } func (current *CloudBuildSourceSpec) Validate(ctx context.Context) *apis.FieldError { @@ -46,7 +46,7 @@ func (current *CloudBuildSourceSpec) Validate(ctx context.Context) *apis.FieldEr errs = errs.Also(err.ViaField("sink")) } - if err := duckv1alpha1.ValidateCredential(current.Secret, current.ServiceAccountName); err != nil { + if err := duckv1beta1.ValidateCredential(current.Secret, current.ServiceAccountName); err != nil { errs = errs.Also(err) } @@ -70,5 +70,5 @@ func (current *CloudBuildSource) CheckImmutableFields(ctx context.Context, origi }) } // Modification of non-empty cluster name annotation is not allowed. - return duckv1alpha1.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) + return duckv1beta1.CheckImmutableClusterNameAnnotation(¤t.ObjectMeta, &original.ObjectMeta, errs) } diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go index 5a517fffd3..76f08bf5df 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go @@ -24,7 +24,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" corev1 "k8s.io/api/core/v1" @@ -36,7 +36,7 @@ import ( var ( topic = DefaultTopic buildSourceSpec = CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "secret-name", @@ -217,17 +217,17 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { }, "ClusterName annotation changed": { origAnnotation: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", + duckv1beta1.ClusterNameAnnotation: metadatatesting.FakeClusterName + "old", }, updatedAnnotation: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", + duckv1beta1.ClusterNameAnnotation: metadatatesting.FakeClusterName + "new", }, allowed: false, }, "Secret.Name changed": { orig: &buildSourceSpec, updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "some-other-name", @@ -246,7 +246,7 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { "Secret.Key changed": { orig: &buildSourceSpec, updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: buildSourceSpec.Secret.Name, @@ -265,7 +265,7 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { "Project changed": { orig: &buildSourceSpec, updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: buildSourceSpec.Secret.Name, @@ -284,8 +284,8 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { "ServiceAccount changed": { orig: &buildSourceSpec, updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ + IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: "new-service-account", }, Secret: &corev1.SecretKeySelector{ @@ -305,7 +305,7 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { "Topic changed": { orig: &buildSourceSpec, updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: buildSourceSpec.Secret.Name, @@ -324,7 +324,7 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { "Sink.APIVersion changed": { orig: &buildSourceSpec, updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: buildSourceSpec.Secret.Name, @@ -350,7 +350,7 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { "Sink.Kind changed": { orig: &buildSourceSpec, updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: buildSourceSpec.Secret.Name, @@ -376,7 +376,7 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { "Sink.Namespace changed": { orig: &buildSourceSpec, updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: buildSourceSpec.Secret.Name, @@ -402,7 +402,7 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { "Sink.Name changed": { orig: &buildSourceSpec, updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: buildSourceSpec.Secret.Name, diff --git a/pkg/apis/events/v1beta1/zz_generated.deepcopy.go b/pkg/apis/events/v1beta1/zz_generated.deepcopy.go index 3637022cb0..6a075fd9a6 100644 --- a/pkg/apis/events/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/events/v1beta1/zz_generated.deepcopy.go @@ -119,6 +119,106 @@ func (in *CloudAuditLogsSourceStatus) DeepCopy() *CloudAuditLogsSourceStatus { 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 diff --git a/pkg/client/clientset/versioned/typed/events/v1beta1/cloudbuildsource.go b/pkg/client/clientset/versioned/typed/events/v1beta1/cloudbuildsource.go new file mode 100644 index 0000000000..e0a8815067 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/events/v1beta1/cloudbuildsource.go @@ -0,0 +1,191 @@ +/* +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 v1beta1 + +import ( + "time" + + v1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + 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(*v1beta1.CloudBuildSource) (*v1beta1.CloudBuildSource, error) + Update(*v1beta1.CloudBuildSource) (*v1beta1.CloudBuildSource, error) + UpdateStatus(*v1beta1.CloudBuildSource) (*v1beta1.CloudBuildSource, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1beta1.CloudBuildSource, error) + List(opts v1.ListOptions) (*v1beta1.CloudBuildSourceList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1beta1.CloudBuildSource, err error) + CloudBuildSourceExpansion +} + +// cloudBuildSources implements CloudBuildSourceInterface +type cloudBuildSources struct { + client rest.Interface + ns string +} + +// newCloudBuildSources returns a CloudBuildSources +func newCloudBuildSources(c *EventsV1beta1Client, 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(name string, options v1.GetOptions) (result *v1beta1.CloudBuildSource, err error) { + result = &v1beta1.CloudBuildSource{} + err = c.client.Get(). + Namespace(c.ns). + Resource("cloudbuildsources"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of CloudBuildSources that match those selectors. +func (c *cloudBuildSources) List(opts v1.ListOptions) (result *v1beta1.CloudBuildSourceList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.CloudBuildSourceList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("cloudbuildsources"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested cloudBuildSources. +func (c *cloudBuildSources) Watch(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() +} + +// 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(cloudBuildSource *v1beta1.CloudBuildSource) (result *v1beta1.CloudBuildSource, err error) { + result = &v1beta1.CloudBuildSource{} + err = c.client.Post(). + Namespace(c.ns). + Resource("cloudbuildsources"). + Body(cloudBuildSource). + Do(). + 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(cloudBuildSource *v1beta1.CloudBuildSource) (result *v1beta1.CloudBuildSource, err error) { + result = &v1beta1.CloudBuildSource{} + err = c.client.Put(). + Namespace(c.ns). + Resource("cloudbuildsources"). + Name(cloudBuildSource.Name). + Body(cloudBuildSource). + Do(). + 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(cloudBuildSource *v1beta1.CloudBuildSource) (result *v1beta1.CloudBuildSource, err error) { + result = &v1beta1.CloudBuildSource{} + err = c.client.Put(). + Namespace(c.ns). + Resource("cloudbuildsources"). + Name(cloudBuildSource.Name). + SubResource("status"). + Body(cloudBuildSource). + Do(). + Into(result) + return +} + +// Delete takes name of the cloudBuildSource and deletes it. Returns an error if one occurs. +func (c *cloudBuildSources) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("cloudbuildsources"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *cloudBuildSources) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + var timeout time.Duration + if listOptions.TimeoutSeconds != nil { + timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("cloudbuildsources"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Timeout(timeout). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched cloudBuildSource. +func (c *cloudBuildSources) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1beta1.CloudBuildSource, err error) { + result = &v1beta1.CloudBuildSource{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("cloudbuildsources"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/events/v1beta1/events_client.go b/pkg/client/clientset/versioned/typed/events/v1beta1/events_client.go index 0068f6cb62..b5b301942e 100644 --- a/pkg/client/clientset/versioned/typed/events/v1beta1/events_client.go +++ b/pkg/client/clientset/versioned/typed/events/v1beta1/events_client.go @@ -27,6 +27,7 @@ import ( type EventsV1beta1Interface interface { RESTClient() rest.Interface CloudAuditLogsSourcesGetter + CloudBuildSourcesGetter CloudPubSubSourcesGetter CloudSchedulerSourcesGetter CloudStorageSourcesGetter @@ -41,6 +42,10 @@ func (c *EventsV1beta1Client) CloudAuditLogsSources(namespace string) CloudAudit return newCloudAuditLogsSources(c, namespace) } +func (c *EventsV1beta1Client) CloudBuildSources(namespace string) CloudBuildSourceInterface { + return newCloudBuildSources(c, namespace) +} + func (c *EventsV1beta1Client) CloudPubSubSources(namespace string) CloudPubSubSourceInterface { return newCloudPubSubSources(c, namespace) } diff --git a/pkg/client/clientset/versioned/typed/events/v1beta1/fake/fake_cloudbuildsource.go b/pkg/client/clientset/versioned/typed/events/v1beta1/fake/fake_cloudbuildsource.go new file mode 100644 index 0000000000..72858b1fb4 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/events/v1beta1/fake/fake_cloudbuildsource.go @@ -0,0 +1,140 @@ +/* +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 ( + v1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + 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 *FakeEventsV1beta1 + ns string +} + +var cloudbuildsourcesResource = schema.GroupVersionResource{Group: "events.cloud.google.com", Version: "v1beta1", Resource: "cloudbuildsources"} + +var cloudbuildsourcesKind = schema.GroupVersionKind{Group: "events.cloud.google.com", Version: "v1beta1", 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(name string, options v1.GetOptions) (result *v1beta1.CloudBuildSource, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(cloudbuildsourcesResource, c.ns, name), &v1beta1.CloudBuildSource{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.CloudBuildSource), err +} + +// List takes label and field selectors, and returns the list of CloudBuildSources that match those selectors. +func (c *FakeCloudBuildSources) List(opts v1.ListOptions) (result *v1beta1.CloudBuildSourceList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(cloudbuildsourcesResource, cloudbuildsourcesKind, c.ns, opts), &v1beta1.CloudBuildSourceList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.CloudBuildSourceList{ListMeta: obj.(*v1beta1.CloudBuildSourceList).ListMeta} + for _, item := range obj.(*v1beta1.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(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(cloudBuildSource *v1beta1.CloudBuildSource) (result *v1beta1.CloudBuildSource, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(cloudbuildsourcesResource, c.ns, cloudBuildSource), &v1beta1.CloudBuildSource{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.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(cloudBuildSource *v1beta1.CloudBuildSource) (result *v1beta1.CloudBuildSource, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(cloudbuildsourcesResource, c.ns, cloudBuildSource), &v1beta1.CloudBuildSource{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.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(cloudBuildSource *v1beta1.CloudBuildSource) (*v1beta1.CloudBuildSource, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(cloudbuildsourcesResource, "status", c.ns, cloudBuildSource), &v1beta1.CloudBuildSource{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.CloudBuildSource), err +} + +// Delete takes name of the cloudBuildSource and deletes it. Returns an error if one occurs. +func (c *FakeCloudBuildSources) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(cloudbuildsourcesResource, c.ns, name), &v1beta1.CloudBuildSource{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeCloudBuildSources) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(cloudbuildsourcesResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1beta1.CloudBuildSourceList{}) + return err +} + +// Patch applies the patch and returns the patched cloudBuildSource. +func (c *FakeCloudBuildSources) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1beta1.CloudBuildSource, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(cloudbuildsourcesResource, c.ns, name, pt, data, subresources...), &v1beta1.CloudBuildSource{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.CloudBuildSource), err +} diff --git a/pkg/client/clientset/versioned/typed/events/v1beta1/fake/fake_events_client.go b/pkg/client/clientset/versioned/typed/events/v1beta1/fake/fake_events_client.go index ab08880ae0..4f434410fc 100644 --- a/pkg/client/clientset/versioned/typed/events/v1beta1/fake/fake_events_client.go +++ b/pkg/client/clientset/versioned/typed/events/v1beta1/fake/fake_events_client.go @@ -32,6 +32,10 @@ func (c *FakeEventsV1beta1) CloudAuditLogsSources(namespace string) v1beta1.Clou return &FakeCloudAuditLogsSources{c, namespace} } +func (c *FakeEventsV1beta1) CloudBuildSources(namespace string) v1beta1.CloudBuildSourceInterface { + return &FakeCloudBuildSources{c, namespace} +} + func (c *FakeEventsV1beta1) CloudPubSubSources(namespace string) v1beta1.CloudPubSubSourceInterface { return &FakeCloudPubSubSources{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/events/v1beta1/generated_expansion.go b/pkg/client/clientset/versioned/typed/events/v1beta1/generated_expansion.go index f17b0cd180..0dffc2d15d 100644 --- a/pkg/client/clientset/versioned/typed/events/v1beta1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/events/v1beta1/generated_expansion.go @@ -20,6 +20,8 @@ package v1beta1 type CloudAuditLogsSourceExpansion interface{} +type CloudBuildSourceExpansion interface{} + type CloudPubSubSourceExpansion interface{} type CloudSchedulerSourceExpansion interface{} diff --git a/pkg/client/informers/externalversions/events/v1beta1/cloudbuildsource.go b/pkg/client/informers/externalversions/events/v1beta1/cloudbuildsource.go new file mode 100644 index 0000000000..2611c2e9f2 --- /dev/null +++ b/pkg/client/informers/externalversions/events/v1beta1/cloudbuildsource.go @@ -0,0 +1,89 @@ +/* +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 v1beta1 + +import ( + time "time" + + eventsv1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + versioned "github.com/google/knative-gcp/pkg/client/clientset/versioned" + internalinterfaces "github.com/google/knative-gcp/pkg/client/informers/externalversions/internalinterfaces" + v1beta1 "github.com/google/knative-gcp/pkg/client/listers/events/v1beta1" + 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() v1beta1.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.EventsV1beta1().CloudBuildSources(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.EventsV1beta1().CloudBuildSources(namespace).Watch(options) + }, + }, + &eventsv1beta1.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(&eventsv1beta1.CloudBuildSource{}, f.defaultInformer) +} + +func (f *cloudBuildSourceInformer) Lister() v1beta1.CloudBuildSourceLister { + return v1beta1.NewCloudBuildSourceLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/events/v1beta1/interface.go b/pkg/client/informers/externalversions/events/v1beta1/interface.go index 0f86a25b02..bdbe295573 100644 --- a/pkg/client/informers/externalversions/events/v1beta1/interface.go +++ b/pkg/client/informers/externalversions/events/v1beta1/interface.go @@ -26,6 +26,8 @@ import ( 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. @@ -50,6 +52,11 @@ 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} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index a553954fe6..72925a3c9b 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -79,6 +79,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource // Group=events.cloud.google.com, Version=v1beta1 case eventsv1beta1.SchemeGroupVersion.WithResource("cloudauditlogssources"): return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1beta1().CloudAuditLogsSources().Informer()}, nil + case eventsv1beta1.SchemeGroupVersion.WithResource("cloudbuildsources"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1beta1().CloudBuildSources().Informer()}, nil case eventsv1beta1.SchemeGroupVersion.WithResource("cloudpubsubsources"): return &genericInformer{resource: resource.GroupResource(), informer: f.Events().V1beta1().CloudPubSubSources().Informer()}, nil case eventsv1beta1.SchemeGroupVersion.WithResource("cloudschedulersources"): diff --git a/pkg/client/injection/informers/events/v1beta1/cloudbuildsource/cloudbuildsource.go b/pkg/client/injection/informers/events/v1beta1/cloudbuildsource/cloudbuildsource.go new file mode 100644 index 0000000000..b68a6278ef --- /dev/null +++ b/pkg/client/injection/informers/events/v1beta1/cloudbuildsource/cloudbuildsource.go @@ -0,0 +1,52 @@ +/* +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" + + v1beta1 "github.com/google/knative-gcp/pkg/client/informers/externalversions/events/v1beta1" + 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().V1beta1().CloudBuildSources() + return context.WithValue(ctx, Key{}, inf), inf.Informer() +} + +// Get extracts the typed informer from the context. +func Get(ctx context.Context) v1beta1.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/v1beta1.CloudBuildSourceInformer from context.") + } + return untyped.(v1beta1.CloudBuildSourceInformer) +} diff --git a/pkg/client/injection/informers/events/v1beta1/cloudbuildsource/fake/fake.go b/pkg/client/injection/informers/events/v1beta1/cloudbuildsource/fake/fake.go new file mode 100644 index 0000000000..615bce6fb3 --- /dev/null +++ b/pkg/client/injection/informers/events/v1beta1/cloudbuildsource/fake/fake.go @@ -0,0 +1,40 @@ +/* +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/v1beta1/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().V1beta1().CloudBuildSources() + return context.WithValue(ctx, cloudbuildsource.Key{}, inf), inf.Informer() +} diff --git a/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/controller.go b/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/controller.go new file mode 100644 index 0000000000..c80a9eeecf --- /dev/null +++ b/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/controller.go @@ -0,0 +1,118 @@ +/* +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" + fmt "fmt" + reflect "reflect" + strings "strings" + + versionedscheme "github.com/google/knative-gcp/pkg/client/clientset/versioned/scheme" + client "github.com/google/knative-gcp/pkg/client/injection/client" + cloudbuildsource "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudbuildsource" + corev1 "k8s.io/api/core/v1" + watch "k8s.io/apimachinery/pkg/watch" + scheme "k8s.io/client-go/kubernetes/scheme" + v1 "k8s.io/client-go/kubernetes/typed/core/v1" + record "k8s.io/client-go/tools/record" + kubeclient "knative.dev/pkg/client/injection/kube/client" + controller "knative.dev/pkg/controller" + logging "knative.dev/pkg/logging" +) + +const ( + defaultControllerAgentName = "cloudbuildsource-controller" + defaultFinalizerName = "cloudbuildsources.events.cloud.google.com" +) + +// NewImpl returns a controller.Impl that handles queuing and feeding work from +// the queue through an implementation of controller.Reconciler, delegating to +// the provided Interface and optional Finalizer methods. OptionsFn is used to return +// controller.Options to be used but the internal reconciler. +func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsFn) *controller.Impl { + logger := logging.FromContext(ctx) + + // Check the options function input. It should be 0 or 1. + if len(optionsFns) > 1 { + logger.Fatalf("up to one options function is supported, found %d", len(optionsFns)) + } + + cloudbuildsourceInformer := cloudbuildsource.Get(ctx) + + rec := &reconcilerImpl{ + Client: client.Get(ctx), + Lister: cloudbuildsourceInformer.Lister(), + reconciler: r, + finalizerName: defaultFinalizerName, + } + + t := reflect.TypeOf(r).Elem() + queueName := fmt.Sprintf("%s.%s", strings.ReplaceAll(t.PkgPath(), "/", "-"), t.Name()) + + impl := controller.NewImpl(rec, logger, queueName) + agentName := defaultControllerAgentName + + // Pass impl to the options. Save any optional results. + for _, fn := range optionsFns { + opts := fn(impl) + if opts.ConfigStore != nil { + rec.configStore = opts.ConfigStore + } + if opts.FinalizerName != "" { + rec.finalizerName = opts.FinalizerName + } + if opts.AgentName != "" { + agentName = opts.AgentName + } + } + + rec.Recorder = createRecorder(ctx, agentName) + + return impl +} + +func createRecorder(ctx context.Context, agentName string) record.EventRecorder { + logger := logging.FromContext(ctx) + + recorder := controller.GetEventRecorder(ctx) + if recorder == nil { + // Create event broadcaster + logger.Debug("Creating event broadcaster") + eventBroadcaster := record.NewBroadcaster() + watches := []watch.Interface{ + eventBroadcaster.StartLogging(logger.Named("event-broadcaster").Infof), + eventBroadcaster.StartRecordingToSink( + &v1.EventSinkImpl{Interface: kubeclient.Get(ctx).CoreV1().Events("")}), + } + recorder = eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: agentName}) + go func() { + <-ctx.Done() + for _, w := range watches { + w.Stop() + } + }() + } + + return recorder +} + +func init() { + versionedscheme.AddToScheme(scheme.Scheme) +} diff --git a/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/reconciler.go b/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/reconciler.go new file mode 100644 index 0000000000..27ac1aacf1 --- /dev/null +++ b/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/reconciler.go @@ -0,0 +1,353 @@ +/* +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" + json "encoding/json" + reflect "reflect" + + v1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + versioned "github.com/google/knative-gcp/pkg/client/clientset/versioned" + eventsv1beta1 "github.com/google/knative-gcp/pkg/client/listers/events/v1beta1" + zap "go.uber.org/zap" + v1 "k8s.io/api/core/v1" + equality "k8s.io/apimachinery/pkg/api/equality" + errors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + sets "k8s.io/apimachinery/pkg/util/sets" + cache "k8s.io/client-go/tools/cache" + record "k8s.io/client-go/tools/record" + controller "knative.dev/pkg/controller" + logging "knative.dev/pkg/logging" + reconciler "knative.dev/pkg/reconciler" +) + +// Interface defines the strongly typed interfaces to be implemented by a +// controller reconciling v1beta1.CloudBuildSource. +type Interface interface { + // ReconcileKind implements custom logic to reconcile v1beta1.CloudBuildSource. Any changes + // to the objects .Status or .Finalizers will be propagated to the stored + // object. It is recommended that implementors do not call any update calls + // for the Kind inside of ReconcileKind, it is the responsibility of the calling + // controller to propagate those properties. The resource passed to ReconcileKind + // will always have an empty deletion timestamp. + ReconcileKind(ctx context.Context, o *v1beta1.CloudBuildSource) reconciler.Event +} + +// Finalizer defines the strongly typed interfaces to be implemented by a +// controller finalizing v1beta1.CloudBuildSource. +type Finalizer interface { + // FinalizeKind implements custom logic to finalize v1beta1.CloudBuildSource. Any changes + // to the objects .Status or .Finalizers will be ignored. Returning a nil or + // Normal type reconciler.Event will allow the finalizer to be deleted on + // the resource. The resource passed to FinalizeKind will always have a set + // deletion timestamp. + FinalizeKind(ctx context.Context, o *v1beta1.CloudBuildSource) reconciler.Event +} + +// reconcilerImpl implements controller.Reconciler for v1beta1.CloudBuildSource resources. +type reconcilerImpl struct { + // Client is used to write back status updates. + Client versioned.Interface + + // Listers index properties about resources + Lister eventsv1beta1.CloudBuildSourceLister + + // Recorder is an event recorder for recording Event resources to the + // Kubernetes API. + Recorder record.EventRecorder + + // configStore allows for decorating a context with config maps. + // +optional + configStore reconciler.ConfigStore + + // reconciler is the implementation of the business logic of the resource. + reconciler Interface + + // finalizerName is the name of the finalizer to reconcile. + finalizerName string +} + +// Check that our Reconciler implements controller.Reconciler +var _ controller.Reconciler = (*reconcilerImpl)(nil) + +func NewReconciler(ctx context.Context, logger *zap.SugaredLogger, client versioned.Interface, lister eventsv1beta1.CloudBuildSourceLister, recorder record.EventRecorder, r Interface, options ...controller.Options) controller.Reconciler { + // Check the options function input. It should be 0 or 1. + if len(options) > 1 { + logger.Fatalf("up to one options struct is supported, found %d", len(options)) + } + + rec := &reconcilerImpl{ + Client: client, + Lister: lister, + Recorder: recorder, + reconciler: r, + finalizerName: defaultFinalizerName, + } + + for _, opts := range options { + if opts.ConfigStore != nil { + rec.configStore = opts.ConfigStore + } + if opts.FinalizerName != "" { + rec.finalizerName = opts.FinalizerName + } + } + + return rec +} + +// Reconcile implements controller.Reconciler +func (r *reconcilerImpl) Reconcile(ctx context.Context, key string) error { + logger := logging.FromContext(ctx) + + // If configStore is set, attach the frozen configuration to the context. + if r.configStore != nil { + ctx = r.configStore.ToContext(ctx) + } + + // Add the recorder to context. + ctx = controller.WithEventRecorder(ctx, r.Recorder) + + // Convert the namespace/name string into a distinct namespace and name + + namespace, name, err := cache.SplitMetaNamespaceKey(key) + + if err != nil { + logger.Errorf("invalid resource key: %s", key) + return nil + } + + // Get the resource with this namespace/name. + + getter := r.Lister.CloudBuildSources(namespace) + + original, err := getter.Get(name) + + if errors.IsNotFound(err) { + // The resource may no longer exist, in which case we stop processing. + logger.Debugf("resource %q no longer exists", key) + return nil + } else if err != nil { + return err + } + + // Don't modify the informers copy. + resource := original.DeepCopy() + + var reconcileEvent reconciler.Event + if resource.GetDeletionTimestamp().IsZero() { + // Append the target method to the logger. + logger = logger.With(zap.String("targetMethod", "ReconcileKind")) + + // Set and update the finalizer on resource if r.reconciler + // implements Finalizer. + if resource, err = r.setFinalizerIfFinalizer(ctx, resource); err != nil { + logger.Warnw("Failed to set finalizers", zap.Error(err)) + } + + // Reconcile this copy of the resource and then write back any status + // updates regardless of whether the reconciliation errored out. + reconcileEvent = r.reconciler.ReconcileKind(ctx, resource) + + } else if fin, ok := r.reconciler.(Finalizer); ok { + // Append the target method to the logger. + logger = logger.With(zap.String("targetMethod", "FinalizeKind")) + + // For finalizing reconcilers, if this resource being marked for deletion + // and reconciled cleanly (nil or normal event), remove the finalizer. + reconcileEvent = fin.FinalizeKind(ctx, resource) + if resource, err = r.clearFinalizer(ctx, resource, reconcileEvent); err != nil { + logger.Warnw("Failed to clear finalizers", zap.Error(err)) + } + } + + // Synchronize the status. + if equality.Semantic.DeepEqual(original.Status, resource.Status) { + // If we didn't change anything then don't call updateStatus. + // This is important because the copy we loaded from the injectionInformer's + // cache may be stale and we don't want to overwrite a prior update + // to status with this stale state. + } else if err = r.updateStatus(original, resource); err != nil { + logger.Warnw("Failed to update resource status", zap.Error(err)) + r.Recorder.Eventf(resource, v1.EventTypeWarning, "UpdateFailed", + "Failed to update status for %q: %v", resource.Name, err) + return err + } + + // Report the reconciler event, if any. + if reconcileEvent != nil { + var event *reconciler.ReconcilerEvent + if reconciler.EventAs(reconcileEvent, &event) { + logger.Infow("Returned an event", zap.Any("event", reconcileEvent)) + r.Recorder.Eventf(resource, event.EventType, event.Reason, event.Format, event.Args...) + + // the event was wrapped inside an error, consider the reconciliation as failed + if _, isEvent := reconcileEvent.(*reconciler.ReconcilerEvent); !isEvent { + return reconcileEvent + } + return nil + } + + logger.Errorw("Returned an error", zap.Error(reconcileEvent)) + r.Recorder.Event(resource, v1.EventTypeWarning, "InternalError", reconcileEvent.Error()) + return reconcileEvent + } + + return nil +} + +func (r *reconcilerImpl) updateStatus(existing *v1beta1.CloudBuildSource, desired *v1beta1.CloudBuildSource) error { + existing = existing.DeepCopy() + return reconciler.RetryUpdateConflicts(func(attempts int) (err error) { + // The first iteration tries to use the injectionInformer's state, subsequent attempts fetch the latest state via API. + if attempts > 0 { + + getter := r.Client.EventsV1beta1().CloudBuildSources(desired.Namespace) + + existing, err = getter.Get(desired.Name, metav1.GetOptions{}) + if err != nil { + return err + } + } + + // If there's nothing to update, just return. + if reflect.DeepEqual(existing.Status, desired.Status) { + return nil + } + + existing.Status = desired.Status + + updater := r.Client.EventsV1beta1().CloudBuildSources(existing.Namespace) + + _, err = updater.UpdateStatus(existing) + return err + }) +} + +// updateFinalizersFiltered will update the Finalizers of the resource. +// TODO: this method could be generic and sync all finalizers. For now it only +// updates defaultFinalizerName or its override. +func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource *v1beta1.CloudBuildSource) (*v1beta1.CloudBuildSource, error) { + + getter := r.Lister.CloudBuildSources(resource.Namespace) + + actual, err := getter.Get(resource.Name) + if err != nil { + return resource, err + } + + // Don't modify the informers copy. + existing := actual.DeepCopy() + + var finalizers []string + + // If there's nothing to update, just return. + existingFinalizers := sets.NewString(existing.Finalizers...) + desiredFinalizers := sets.NewString(resource.Finalizers...) + + if desiredFinalizers.Has(r.finalizerName) { + if existingFinalizers.Has(r.finalizerName) { + // Nothing to do. + return resource, nil + } + // Add the finalizer. + finalizers = append(existing.Finalizers, r.finalizerName) + } else { + if !existingFinalizers.Has(r.finalizerName) { + // Nothing to do. + return resource, nil + } + // Remove the finalizer. + existingFinalizers.Delete(r.finalizerName) + finalizers = existingFinalizers.List() + } + + mergePatch := map[string]interface{}{ + "metadata": map[string]interface{}{ + "finalizers": finalizers, + "resourceVersion": existing.ResourceVersion, + }, + } + + patch, err := json.Marshal(mergePatch) + if err != nil { + return resource, err + } + + patcher := r.Client.EventsV1beta1().CloudBuildSources(resource.Namespace) + + resourceName := resource.Name + resource, err = patcher.Patch(resourceName, types.MergePatchType, patch) + if err != nil { + r.Recorder.Eventf(resource, v1.EventTypeWarning, "FinalizerUpdateFailed", + "Failed to update finalizers for %q: %v", resourceName, err) + } else { + r.Recorder.Eventf(resource, v1.EventTypeNormal, "FinalizerUpdate", + "Updated %q finalizers", resource.GetName()) + } + return resource, err +} + +func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource *v1beta1.CloudBuildSource) (*v1beta1.CloudBuildSource, error) { + if _, ok := r.reconciler.(Finalizer); !ok { + return resource, nil + } + + finalizers := sets.NewString(resource.Finalizers...) + + // If this resource is not being deleted, mark the finalizer. + if resource.GetDeletionTimestamp().IsZero() { + finalizers.Insert(r.finalizerName) + } + + resource.Finalizers = finalizers.List() + + // Synchronize the finalizers filtered by r.finalizerName. + return r.updateFinalizersFiltered(ctx, resource) +} + +func (r *reconcilerImpl) clearFinalizer(ctx context.Context, resource *v1beta1.CloudBuildSource, reconcileEvent reconciler.Event) (*v1beta1.CloudBuildSource, error) { + if _, ok := r.reconciler.(Finalizer); !ok { + return resource, nil + } + if resource.GetDeletionTimestamp().IsZero() { + return resource, nil + } + + finalizers := sets.NewString(resource.Finalizers...) + + if reconcileEvent != nil { + var event *reconciler.ReconcilerEvent + if reconciler.EventAs(reconcileEvent, &event) { + if event.EventType == v1.EventTypeNormal { + finalizers.Delete(r.finalizerName) + } + } + } else { + finalizers.Delete(r.finalizerName) + } + + resource.Finalizers = finalizers.List() + + // Synchronize the finalizers filtered by r.finalizerName. + return r.updateFinalizersFiltered(ctx, resource) +} diff --git a/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/stub/controller.go b/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/stub/controller.go new file mode 100644 index 0000000000..a181cbaf4a --- /dev/null +++ b/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/stub/controller.go @@ -0,0 +1,54 @@ +/* +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" + + cloudbuildsource "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudbuildsource" + v1beta1cloudbuildsource "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource" + configmap "knative.dev/pkg/configmap" + controller "knative.dev/pkg/controller" + logging "knative.dev/pkg/logging" +) + +// TODO: PLEASE COPY AND MODIFY THIS FILE AS A STARTING POINT + +// NewController creates a Reconciler for CloudBuildSource and returns the result of NewImpl. +func NewController( + ctx context.Context, + cmw configmap.Watcher, +) *controller.Impl { + logger := logging.FromContext(ctx) + + cloudbuildsourceInformer := cloudbuildsource.Get(ctx) + + // TODO: setup additional informers here. + + r := &Reconciler{} + impl := v1beta1cloudbuildsource.NewImpl(ctx, r) + + logger.Info("Setting up event handlers.") + + cloudbuildsourceInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) + + // TODO: add additional informer event handlers here. + + return impl +} diff --git a/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/stub/reconciler.go b/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/stub/reconciler.go new file mode 100644 index 0000000000..a946e8ae7e --- /dev/null +++ b/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource/stub/reconciler.go @@ -0,0 +1,66 @@ +/* +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" + + v1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + cloudbuildsource "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource" + v1 "k8s.io/api/core/v1" + reconciler "knative.dev/pkg/reconciler" +) + +// TODO: PLEASE COPY AND MODIFY THIS FILE AS A STARTING POINT + +// newReconciledNormal makes a new reconciler event with event type Normal, and +// reason CloudBuildSourceReconciled. +func newReconciledNormal(namespace, name string) reconciler.Event { + return reconciler.NewEvent(v1.EventTypeNormal, "CloudBuildSourceReconciled", "CloudBuildSource reconciled: \"%s/%s\"", namespace, name) +} + +// Reconciler implements controller.Reconciler for CloudBuildSource resources. +type Reconciler struct { + // TODO: add additional requirements here. +} + +// Check that our Reconciler implements Interface +var _ cloudbuildsource.Interface = (*Reconciler)(nil) + +// Optionally check that our Reconciler implements Finalizer +//var _ cloudbuildsource.Finalizer = (*Reconciler)(nil) + +// ReconcileKind implements Interface.ReconcileKind. +func (r *Reconciler) ReconcileKind(ctx context.Context, o *v1beta1.CloudBuildSource) reconciler.Event { + // TODO: use this if the resource implements InitializeConditions. + // o.Status.InitializeConditions() + + // TODO: add custom reconciliation logic here. + + // TODO: use this if the object has .status.ObservedGeneration. + // o.Status.ObservedGeneration = o.Generation + return newReconciledNormal(o.Namespace, o.Name) +} + +// Optionally, use FinalizeKind to add finalizers. FinalizeKind will be called +// when the resource is deleted. +//func (r *Reconciler) FinalizeKind(ctx context.Context, o *v1beta1.CloudBuildSource) reconciler.Event { +// // TODO: add custom finalization logic here. +// return nil +//} diff --git a/pkg/client/listers/events/v1beta1/cloudbuildsource.go b/pkg/client/listers/events/v1beta1/cloudbuildsource.go new file mode 100644 index 0000000000..06c31a55e5 --- /dev/null +++ b/pkg/client/listers/events/v1beta1/cloudbuildsource.go @@ -0,0 +1,94 @@ +/* +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 v1beta1 + +import ( + v1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + "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 []*v1beta1.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 []*v1beta1.CloudBuildSource, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.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 []*v1beta1.CloudBuildSource, err error) + // Get retrieves the CloudBuildSource from the indexer for a given namespace and name. + Get(name string) (*v1beta1.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 []*v1beta1.CloudBuildSource, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.CloudBuildSource)) + }) + return ret, err +} + +// Get retrieves the CloudBuildSource from the indexer for a given namespace and name. +func (s cloudBuildSourceNamespaceLister) Get(name string) (*v1beta1.CloudBuildSource, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("cloudbuildsource"), name) + } + return obj.(*v1beta1.CloudBuildSource), nil +} diff --git a/pkg/client/listers/events/v1beta1/expansion_generated.go b/pkg/client/listers/events/v1beta1/expansion_generated.go index c158719437..626ced1b9f 100644 --- a/pkg/client/listers/events/v1beta1/expansion_generated.go +++ b/pkg/client/listers/events/v1beta1/expansion_generated.go @@ -26,6 +26,14 @@ type CloudAuditLogsSourceListerExpansion interface{} // CloudAuditLogsSourceNamespaceLister. type CloudAuditLogsSourceNamespaceListerExpansion interface{} +// CloudBuildSourceListerExpansion allows custom methods to be added to +// CloudBuildSourceLister. +type CloudBuildSourceListerExpansion interface{} + +// CloudBuildSourceNamespaceListerExpansion allows custom methods to be added to +// CloudBuildSourceNamespaceLister. +type CloudBuildSourceNamespaceListerExpansion interface{} + // CloudPubSubSourceListerExpansion allows custom methods to be added to // CloudPubSubSourceLister. type CloudPubSubSourceListerExpansion interface{} diff --git a/pkg/reconciler/events/auditlogs/auditlogs.go b/pkg/reconciler/events/auditlogs/auditlogs.go index 2a5c4a0368..31564252f4 100644 --- a/pkg/reconciler/events/auditlogs/auditlogs.go +++ b/pkg/reconciler/events/auditlogs/auditlogs.go @@ -29,9 +29,9 @@ import ( "knative.dev/pkg/logging" "knative.dev/pkg/reconciler" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - cloudauditlogssourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudauditlogssource" - listers "github.com/google/knative-gcp/pkg/client/listers/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + cloudauditlogssourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudauditlogssource" + listers "github.com/google/knative-gcp/pkg/client/listers/events/v1beta1" glogadmin "github.com/google/knative-gcp/pkg/gclient/logging/logadmin" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub" "github.com/google/knative-gcp/pkg/reconciler/events/auditlogs/resources" @@ -66,7 +66,7 @@ type Reconciler struct { // Check that our Reconciler implements Interface. var _ cloudauditlogssourcereconciler.Interface = (*Reconciler)(nil) -func (c *Reconciler) ReconcileKind(ctx context.Context, s *v1alpha1.CloudAuditLogsSource) reconciler.Event { +func (c *Reconciler) ReconcileKind(ctx context.Context, s *v1beta1.CloudAuditLogsSource) reconciler.Event { ctx = logging.WithLogger(ctx, c.Logger.With(zap.Any("auditlogsource", s))) s.Status.InitializeConditions() @@ -97,7 +97,7 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, s *v1alpha1.CloudAuditLo return reconciler.NewEvent(corev1.EventTypeNormal, reconciledSuccessReason, `CloudAuditLogsSource reconciled: "%s/%s"`, s.Namespace, s.Name) } -func (c *Reconciler) reconcileSink(ctx context.Context, s *v1alpha1.CloudAuditLogsSource) (string, error) { +func (c *Reconciler) reconcileSink(ctx context.Context, s *v1beta1.CloudAuditLogsSource) (string, error) { sink, err := c.ensureSinkCreated(ctx, s) if err != nil { s.Status.MarkSinkNotReady("SinkCreateFailed", "failed to ensure creation of logging sink: %s", err.Error()) @@ -111,7 +111,7 @@ func (c *Reconciler) reconcileSink(ctx context.Context, s *v1alpha1.CloudAuditLo return sink.ID, nil } -func (c *Reconciler) ensureSinkCreated(ctx context.Context, s *v1alpha1.CloudAuditLogsSource) (*logadmin.Sink, error) { +func (c *Reconciler) ensureSinkCreated(ctx context.Context, s *v1beta1.CloudAuditLogsSource) (*logadmin.Sink, error) { sinkID := s.Status.StackdriverSink if sinkID == "" { sinkID = resources.GenerateSinkName(s) @@ -143,7 +143,7 @@ func (c *Reconciler) ensureSinkCreated(ctx context.Context, s *v1alpha1.CloudAud } // Ensures that the sink has been granted the pubsub.publisher role on the source topic. -func (c *Reconciler) ensureSinkIsPublisher(ctx context.Context, s *v1alpha1.CloudAuditLogsSource, sink *logadmin.Sink) error { +func (c *Reconciler) ensureSinkIsPublisher(ctx context.Context, s *v1beta1.CloudAuditLogsSource, sink *logadmin.Sink) error { pubsubClient, err := c.pubsubClientProvider(ctx, s.Status.ProjectID) if err != nil { logging.FromContext(ctx).Desugar().Error("Failed to create PubSub client", zap.Error(err)) @@ -169,7 +169,7 @@ func (c *Reconciler) ensureSinkIsPublisher(ctx context.Context, s *v1alpha1.Clou // deleteSink looks at status.SinkID and if non-empty will delete the // previously created stackdriver sink. -func (c *Reconciler) deleteSink(ctx context.Context, s *v1alpha1.CloudAuditLogsSource) error { +func (c *Reconciler) deleteSink(ctx context.Context, s *v1beta1.CloudAuditLogsSource) error { if s.Status.StackdriverSink == "" { return nil } @@ -184,7 +184,7 @@ func (c *Reconciler) deleteSink(ctx context.Context, s *v1alpha1.CloudAuditLogsS return nil } -func (c *Reconciler) FinalizeKind(ctx context.Context, s *v1alpha1.CloudAuditLogsSource) reconciler.Event { +func (c *Reconciler) FinalizeKind(ctx context.Context, s *v1beta1.CloudAuditLogsSource) reconciler.Event { // If k8s ServiceAccount exists, binds to the default GCP ServiceAccount, and it only has one ownerReference, // remove the corresponding GCP ServiceAccount iam policy binding. // No need to delete k8s ServiceAccount, it will be automatically handled by k8s Garbage Collection. diff --git a/pkg/reconciler/events/auditlogs/controller.go b/pkg/reconciler/events/auditlogs/controller.go index aa0bd91d86..be33e1140a 100644 --- a/pkg/reconciler/events/auditlogs/controller.go +++ b/pkg/reconciler/events/auditlogs/controller.go @@ -28,17 +28,17 @@ import ( "knative.dev/pkg/controller" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" "github.com/google/knative-gcp/pkg/pubsub/adapter/converters" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/identity/iam" "github.com/google/knative-gcp/pkg/reconciler/intevents" - cloudauditlogssourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource" - pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription" - topicinformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic" - cloudauditlogssourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudauditlogssource" + cloudauditlogssourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudauditlogssource" + pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription" + topicinformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic" + cloudauditlogssourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudauditlogssource" glogadmin "github.com/google/knative-gcp/pkg/gclient/logging/logadmin" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub" ) @@ -90,17 +90,17 @@ func newController( controller.HandleAll(impl.Enqueue), reconciler.DefaultResyncPeriod) topicInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("CloudAuditLogsSource")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("CloudAuditLogsSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) pullsubscriptionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("CloudAuditLogsSource")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("CloudAuditLogsSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) serviceAccountInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind("CloudAuditLogsSource")), + FilterFunc: controller.FilterGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("CloudAuditLogsSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/events/auditlogs/resources/names.go b/pkg/reconciler/events/auditlogs/resources/names.go index ff1f4f6667..ac08fadacf 100644 --- a/pkg/reconciler/events/auditlogs/resources/names.go +++ b/pkg/reconciler/events/auditlogs/resources/names.go @@ -20,24 +20,24 @@ package resources import ( "fmt" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" "github.com/google/knative-gcp/pkg/utils/naming" ) // GenerateTopicName generates a topic name for the audit log // source. This refers to the underlying Pub/Sub topic, and not our // Topic resource. -func GenerateTopicName(s *v1alpha1.CloudAuditLogsSource) string { +func GenerateTopicName(s *v1beta1.CloudAuditLogsSource) string { return naming.TruncatedPubsubResourceName("cre-src", s.Namespace, s.Name, s.UID) } // Generates the resource name for the topic used by an CloudAuditLogsSource. -func GenerateTopicResourceName(s *v1alpha1.CloudAuditLogsSource) string { +func GenerateTopicResourceName(s *v1beta1.CloudAuditLogsSource) string { return fmt.Sprintf("pubsub.googleapis.com/projects/%s/topics/%s", s.Status.ProjectID, s.Status.TopicID) } // GenerateSinkName generates a Stackdriver sink resource name for an // CloudAuditLogsSource. -func GenerateSinkName(s *v1alpha1.CloudAuditLogsSource) string { +func GenerateSinkName(s *v1beta1.CloudAuditLogsSource) string { return naming.TruncatedLoggingSinkResourceName("cre-src", s.Namespace, s.Name, s.UID) } diff --git a/pkg/reconciler/events/build/build.go b/pkg/reconciler/events/build/build.go index 484dba3c58..b747144c87 100644 --- a/pkg/reconciler/events/build/build.go +++ b/pkg/reconciler/events/build/build.go @@ -27,9 +27,9 @@ import ( "knative.dev/pkg/logging" pkgreconciler "knative.dev/pkg/reconciler" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - cloudbuildsourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudbuildsource" - listers "github.com/google/knative-gcp/pkg/client/listers/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + cloudbuildsourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource" + listers "github.com/google/knative-gcp/pkg/client/listers/events/v1beta1" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/intevents" ) @@ -60,7 +60,7 @@ type Reconciler struct { // Check that our Reconciler implements Interface. var _ cloudbuildsourcereconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, build *v1alpha1.CloudBuildSource) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, build *v1beta1.CloudBuildSource) pkgreconciler.Event { ctx = logging.WithLogger(ctx, r.Logger.With(zap.Any("build", build))) build.Status.InitializeConditions() @@ -79,7 +79,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, build *v1alpha1.CloudBui return pkgreconciler.NewEvent(corev1.EventTypeNormal, reconciledSuccessReason, `CloudBuildSource reconciled: "%s/%s"`, build.Namespace, build.Name) } -func (r *Reconciler) FinalizeKind(ctx context.Context, build *v1alpha1.CloudBuildSource) pkgreconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, build *v1beta1.CloudBuildSource) pkgreconciler.Event { // If k8s ServiceAccount exists, binds to the default GCP ServiceAccount, and it only has one ownerReference, // remove the corresponding GCP ServiceAccount iam policy binding. // No need to delete k8s ServiceAccount, it will be automatically handled by k8s Garbage Collection. diff --git a/pkg/reconciler/events/build/controller.go b/pkg/reconciler/events/build/controller.go index b3149cd1e2..51dc846ebe 100644 --- a/pkg/reconciler/events/build/controller.go +++ b/pkg/reconciler/events/build/controller.go @@ -24,10 +24,10 @@ import ( "knative.dev/pkg/controller" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - cloudbuildsourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudbuildsource" - pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription" - cloudbuildsourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudbuildsource" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + cloudbuildsourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudbuildsource" + pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription" + cloudbuildsourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource" "github.com/google/knative-gcp/pkg/pubsub/adapter/converters" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" @@ -79,7 +79,7 @@ func newController( controller.HandleAll(impl.Enqueue), reconciler.DefaultResyncPeriod) pullsubscriptionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind("CloudBuildSource")), + FilterFunc: controller.FilterGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("CloudBuildSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/events/pubsub/controller.go b/pkg/reconciler/events/pubsub/controller.go index 76db9b178e..81c90ad9f9 100644 --- a/pkg/reconciler/events/pubsub/controller.go +++ b/pkg/reconciler/events/pubsub/controller.go @@ -27,10 +27,10 @@ import ( "knative.dev/pkg/controller" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - cloudpubsubsourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource" - pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription" - cloudpubsubsourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudpubsubsource" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + cloudpubsubsourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudpubsubsource" + pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription" + cloudpubsubsourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudpubsubsource" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/identity/iam" @@ -80,12 +80,12 @@ func newController( controller.HandleAll(impl.Enqueue), reconciler.DefaultResyncPeriod) pullsubscriptionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("CloudPubSubSource")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("CloudPubSubSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) serviceAccountInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind("CloudPubSubSource")), + FilterFunc: controller.FilterGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("CloudPubSubSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/events/pubsub/pubsub.go b/pkg/reconciler/events/pubsub/pubsub.go index 4539d688ab..56216cb636 100644 --- a/pkg/reconciler/events/pubsub/pubsub.go +++ b/pkg/reconciler/events/pubsub/pubsub.go @@ -24,9 +24,9 @@ import ( "knative.dev/pkg/logging" pkgreconciler "knative.dev/pkg/reconciler" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - cloudpubsubsourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudpubsubsource" - listers "github.com/google/knative-gcp/pkg/client/listers/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + cloudpubsubsourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudpubsubsource" + listers "github.com/google/knative-gcp/pkg/client/listers/events/v1beta1" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/intevents" ) @@ -51,7 +51,7 @@ type Reconciler struct { // Check that our Reconciler implements Interface. var _ cloudpubsubsourcereconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, pubsub *v1alpha1.CloudPubSubSource) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, pubsub *v1beta1.CloudPubSubSource) pkgreconciler.Event { ctx = logging.WithLogger(ctx, r.Logger.With(zap.Any("pubsub", pubsub))) pubsub.Status.InitializeConditions() @@ -71,7 +71,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, pubsub *v1alpha1.CloudPu return pkgreconciler.NewEvent(corev1.EventTypeNormal, reconciledSuccessReason, `CloudPubSubSource reconciled: "%s/%s"`, pubsub.Namespace, pubsub.Name) } -func (r *Reconciler) FinalizeKind(ctx context.Context, pubsub *v1alpha1.CloudPubSubSource) pkgreconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, pubsub *v1beta1.CloudPubSubSource) pkgreconciler.Event { // If k8s ServiceAccount exists, binds to the default GCP ServiceAccount, and it only has one ownerReference, // remove the corresponding GCP ServiceAccount iam policy binding. // No need to delete k8s ServiceAccount, it will be automatically handled by k8s Garbage Collection. diff --git a/pkg/reconciler/events/scheduler/controller.go b/pkg/reconciler/events/scheduler/controller.go index d8a2bf2359..b938195f4e 100644 --- a/pkg/reconciler/events/scheduler/controller.go +++ b/pkg/reconciler/events/scheduler/controller.go @@ -22,7 +22,7 @@ import ( "knative.dev/pkg/injection" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - "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" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/identity/iam" @@ -32,10 +32,10 @@ import ( "knative.dev/pkg/configmap" "knative.dev/pkg/controller" - cloudschedulersourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudschedulersource" - pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription" - topicinformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic" - cloudschedulersourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudschedulersource" + cloudschedulersourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudschedulersource" + pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription" + topicinformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic" + cloudschedulersourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudschedulersource" gscheduler "github.com/google/knative-gcp/pkg/gclient/scheduler" ) @@ -83,17 +83,17 @@ func newController( cloudschedulersourceInformer.Informer().AddEventHandlerWithResyncPeriod(controller.HandleAll(impl.Enqueue), reconciler.DefaultResyncPeriod) topicInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("CloudSchedulerSource")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("CloudSchedulerSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) pullsubscriptionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("CloudSchedulerSource")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("CloudSchedulerSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) serviceAccountInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind("CloudSchedulerSource")), + FilterFunc: controller.FilterGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("CloudSchedulerSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/events/scheduler/resources/names.go b/pkg/reconciler/events/scheduler/resources/names.go index a715754b49..6ed66721cc 100644 --- a/pkg/reconciler/events/scheduler/resources/names.go +++ b/pkg/reconciler/events/scheduler/resources/names.go @@ -20,7 +20,7 @@ import ( "fmt" "strings" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" "github.com/google/knative-gcp/pkg/utils/naming" ) @@ -29,7 +29,7 @@ const ( ) // GenerateJobName generates a job name like this: projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID. -func GenerateJobName(scheduler *v1alpha1.CloudSchedulerSource) string { +func GenerateJobName(scheduler *v1beta1.CloudSchedulerSource) string { return fmt.Sprintf("projects/%s/locations/%s/%s-%s", scheduler.Status.ProjectID, scheduler.Spec.Location, JobPrefix, string(scheduler.UID)) } @@ -47,11 +47,11 @@ func ExtractJobID(jobName string) string { // GenerateTopicName generates a topic name for the scheduler. This refers to the underlying Pub/Sub topic, and not our // Topic resource. -func GenerateTopicName(scheduler *v1alpha1.CloudSchedulerSource) string { +func GenerateTopicName(scheduler *v1beta1.CloudSchedulerSource) string { return naming.TruncatedPubsubResourceName("cre-src", scheduler.Namespace, scheduler.Name, scheduler.UID) } // GeneratePubSubTarget generates a topic name for the PubsubTarget used to create the CloudSchedulerSource job. -func GeneratePubSubTargetTopic(scheduler *v1alpha1.CloudSchedulerSource, topic string) string { +func GeneratePubSubTargetTopic(scheduler *v1beta1.CloudSchedulerSource, topic string) string { return fmt.Sprintf("projects/%s/topics/%s", scheduler.Status.ProjectID, topic) } diff --git a/pkg/reconciler/events/scheduler/scheduler.go b/pkg/reconciler/events/scheduler/scheduler.go index aeff2eda90..fa6b77ba30 100644 --- a/pkg/reconciler/events/scheduler/scheduler.go +++ b/pkg/reconciler/events/scheduler/scheduler.go @@ -28,9 +28,9 @@ import ( "google.golang.org/grpc/codes" gstatus "google.golang.org/grpc/status" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - cloudschedulersourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudschedulersource" - listers "github.com/google/knative-gcp/pkg/client/listers/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + cloudschedulersourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudschedulersource" + listers "github.com/google/knative-gcp/pkg/client/listers/events/v1beta1" metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" gscheduler "github.com/google/knative-gcp/pkg/gclient/scheduler" "github.com/google/knative-gcp/pkg/pubsub/adapter/converters" @@ -66,7 +66,7 @@ type Reconciler struct { // Check that our Reconciler implements Interface. var _ cloudschedulersourcereconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, scheduler *v1alpha1.CloudSchedulerSource) reconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, scheduler *v1beta1.CloudSchedulerSource) reconciler.Event { ctx = logging.WithLogger(ctx, r.Logger.With(zap.Any("scheduler", scheduler))) scheduler.Status.InitializeConditions() @@ -95,7 +95,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, scheduler *v1alpha1.Clou return reconciler.NewEvent(corev1.EventTypeNormal, reconciledSuccessReason, `CloudSchedulerSource reconciled: "%s/%s"`, scheduler.Namespace, scheduler.Name) } -func (r *Reconciler) reconcileJob(ctx context.Context, scheduler *v1alpha1.CloudSchedulerSource, topic, jobName string) error { +func (r *Reconciler) reconcileJob(ctx context.Context, scheduler *v1beta1.CloudSchedulerSource, topic, jobName string) error { if scheduler.Status.ProjectID == "" { projectID, err := utils.ProjectID(scheduler.Spec.Project, metadataClient.NewDefaultMetadataClient()) if err != nil { @@ -125,8 +125,8 @@ func (r *Reconciler) reconcileJob(ctx context.Context, scheduler *v1alpha1.Cloud // Add our own converter type, jobName, and schedulerName as customAttributes. customAttributes := map[string]string{ converters.KnativeGCPConverter: converters.CloudSchedulerConverter, - v1alpha1.CloudSchedulerSourceJobName: jobName, - v1alpha1.CloudSchedulerSourceName: scheduler.GetName(), + v1beta1.CloudSchedulerSourceJobName: jobName, + v1beta1.CloudSchedulerSourceName: scheduler.GetName(), } _, err = client.CreateJob(ctx, &schedulerpb.CreateJobRequest{ Parent: parent, @@ -157,7 +157,7 @@ func (r *Reconciler) reconcileJob(ctx context.Context, scheduler *v1alpha1.Cloud // deleteJob looks at the status.JobName and if non-empty, // hence indicating that we have created a job successfully // in the Scheduler, remove it. -func (r *Reconciler) deleteJob(ctx context.Context, scheduler *v1alpha1.CloudSchedulerSource) error { +func (r *Reconciler) deleteJob(ctx context.Context, scheduler *v1beta1.CloudSchedulerSource) error { if scheduler.Status.JobName == "" { return nil } @@ -184,7 +184,7 @@ func (r *Reconciler) deleteJob(ctx context.Context, scheduler *v1alpha1.CloudSch return nil } -func (r *Reconciler) FinalizeKind(ctx context.Context, scheduler *v1alpha1.CloudSchedulerSource) reconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, scheduler *v1beta1.CloudSchedulerSource) reconciler.Event { // If k8s ServiceAccount exists, binds to the default GCP ServiceAccount, and it only has one ownerReference, // remove the corresponding GCP ServiceAccount iam policy binding. // No need to delete k8s ServiceAccount, it will be automatically handled by k8s Garbage Collection. diff --git a/pkg/reconciler/events/storage/controller.go b/pkg/reconciler/events/storage/controller.go index 3f0cac74af..4f3b173913 100644 --- a/pkg/reconciler/events/storage/controller.go +++ b/pkg/reconciler/events/storage/controller.go @@ -27,11 +27,11 @@ import ( "knative.dev/pkg/controller" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - cloudstoragesourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudstoragesource" - pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription" - topicinformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic" - cloudstoragesourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudstoragesource" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + cloudstoragesourceinformers "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudstoragesource" + pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription" + topicinformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic" + cloudstoragesourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudstoragesource" gstorage "github.com/google/knative-gcp/pkg/gclient/storage" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" @@ -83,17 +83,17 @@ func newController( cloudstoragesourceInformer.Informer().AddEventHandlerWithResyncPeriod(controller.HandleAll(impl.Enqueue), reconciler.DefaultResyncPeriod) topicInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("CloudStorageSource")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("CloudStorageSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) pullsubscriptionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("CloudStorageSource")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("CloudStorageSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) serviceAccountInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind("CloudStorageSource")), + FilterFunc: controller.FilterGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("CloudStorageSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/events/storage/resources/names.go b/pkg/reconciler/events/storage/resources/names.go index bda7f27367..868c989a0b 100644 --- a/pkg/reconciler/events/storage/resources/names.go +++ b/pkg/reconciler/events/storage/resources/names.go @@ -19,11 +19,11 @@ package resources import ( "github.com/google/knative-gcp/pkg/utils/naming" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" ) // GenerateTopicName generates a topic name for the storage. This refers to the underlying Pub/Sub topic, and not our // Topic resource. -func GenerateTopicName(storage *v1alpha1.CloudStorageSource) string { +func GenerateTopicName(storage *v1beta1.CloudStorageSource) string { return naming.TruncatedPubsubResourceName("cre-src", storage.Namespace, storage.Name, storage.UID) } diff --git a/pkg/reconciler/events/storage/resources/names_test.go b/pkg/reconciler/events/storage/resources/names_test.go index 61aebda300..02941a21b7 100644 --- a/pkg/reconciler/events/storage/resources/names_test.go +++ b/pkg/reconciler/events/storage/resources/names_test.go @@ -20,13 +20,13 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestGenerateTopicName(t *testing.T) { want := "cre-src_mynamespace_myname_uid" - got := GenerateTopicName(&v1alpha1.CloudStorageSource{ + got := GenerateTopicName(&v1beta1.CloudStorageSource{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", diff --git a/pkg/reconciler/events/storage/storage.go b/pkg/reconciler/events/storage/storage.go index 59d0853623..9a627785fd 100644 --- a/pkg/reconciler/events/storage/storage.go +++ b/pkg/reconciler/events/storage/storage.go @@ -29,9 +29,9 @@ import ( . "cloud.google.com/go/storage" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - cloudstoragesourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudstoragesource" - listers "github.com/google/knative-gcp/pkg/client/listers/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + cloudstoragesourcereconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudstoragesource" + listers "github.com/google/knative-gcp/pkg/client/listers/events/v1beta1" metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" gstorage "github.com/google/knative-gcp/pkg/gclient/storage" "github.com/google/knative-gcp/pkg/pubsub/adapter/converters" @@ -56,10 +56,10 @@ const ( var ( // Mapping of the storage source CloudEvent types to google storage types. storageEventTypes = map[string]string{ - v1alpha1.CloudStorageSourceFinalize: "OBJECT_FINALIZE", - v1alpha1.CloudStorageSourceArchive: "OBJECT_ARCHIVE", - v1alpha1.CloudStorageSourceDelete: "OBJECT_DELETE", - v1alpha1.CloudStorageSourceMetadataUpdate: "OBJECT_METADATA_UPDATE", + v1beta1.CloudStorageSourceFinalize: "OBJECT_FINALIZE", + v1beta1.CloudStorageSourceArchive: "OBJECT_ARCHIVE", + v1beta1.CloudStorageSourceDelete: "OBJECT_DELETE", + v1beta1.CloudStorageSourceMetadataUpdate: "OBJECT_METADATA_UPDATE", } ) @@ -80,7 +80,7 @@ type Reconciler struct { // Check that our Reconciler implements Interface. var _ cloudstoragesourcereconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, storage *v1alpha1.CloudStorageSource) reconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, storage *v1beta1.CloudStorageSource) reconciler.Event { ctx = logging.WithLogger(ctx, r.Logger.With(zap.Any("storage", storage))) storage.Status.InitializeConditions() @@ -109,7 +109,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, storage *v1alpha1.CloudS return reconciler.NewEvent(corev1.EventTypeNormal, reconciledSuccessReason, `CloudStorageSource reconciled: "%s/%s"`, storage.Namespace, storage.Name) } -func (r *Reconciler) reconcileNotification(ctx context.Context, storage *v1alpha1.CloudStorageSource) (string, error) { +func (r *Reconciler) reconcileNotification(ctx context.Context, storage *v1beta1.CloudStorageSource) (string, error) { if storage.Status.ProjectID == "" { projectID, err := utils.ProjectID(storage.Spec.Project, metadataClient.NewDefaultMetadataClient()) if err != nil { @@ -185,7 +185,7 @@ func (r *Reconciler) toCloudStorageSourceEventTypes(eventTypes []string) []strin // deleteNotification looks at the status.NotificationID and if non-empty, // hence indicating that we have created a notification successfully // in the CloudStorageSource, remove it. -func (r *Reconciler) deleteNotification(ctx context.Context, storage *v1alpha1.CloudStorageSource) error { +func (r *Reconciler) deleteNotification(ctx context.Context, storage *v1beta1.CloudStorageSource) error { if storage.Status.NotificationID == "" { return nil } @@ -240,7 +240,7 @@ func (r *Reconciler) deleteNotification(ctx context.Context, storage *v1alpha1.C return nil } -func (r *Reconciler) FinalizeKind(ctx context.Context, storage *v1alpha1.CloudStorageSource) reconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, storage *v1beta1.CloudStorageSource) reconciler.Event { // If k8s ServiceAccount exists, binds to the default GCP ServiceAccount, and it only has one ownerReference, // remove the corresponding GCP ServiceAccount iam policy binding. // No need to delete k8s ServiceAccount, it will be automatically handled by k8s Garbage Collection. diff --git a/pkg/reconciler/events/storage/storage_test.go b/pkg/reconciler/events/storage/storage_test.go index 00f5d0fd33..ebc748d59f 100644 --- a/pkg/reconciler/events/storage/storage_test.go +++ b/pkg/reconciler/events/storage/storage_test.go @@ -41,11 +41,11 @@ import ( . "knative.dev/pkg/reconciler/testing" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - storagev1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + storagev1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" . "github.com/google/knative-gcp/pkg/apis/intevents" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudstoragesource" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudstoragesource" testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" gstorage "github.com/google/knative-gcp/pkg/gclient/storage/testing" "github.com/google/knative-gcp/pkg/reconciler/identity" @@ -85,7 +85,7 @@ var ( sinkGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Sink", } @@ -101,13 +101,13 @@ var ( func init() { // Add types to scheme - _ = storagev1alpha1.AddToScheme(scheme.Scheme) + _ = storagev1beta1.AddToScheme(scheme.Scheme) } // Returns an ownerref for the test CloudStorageSource object func ownerRef() metav1.OwnerReference { return metav1.OwnerReference{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudStorageSource", Name: "my-test-storage", UID: storageUID, @@ -132,7 +132,7 @@ func patchFinalizers(namespace, name string, add bool) clientgotesting.PatchActi func newSink() *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "testing.cloud.google.com/v1alpha1", + "apiVersion": "testing.cloud.google.com/v1beta1", "kind": "Sink", "metadata": map[string]interface{}{ "namespace": testNS, @@ -150,7 +150,7 @@ func newSink() *unstructured.Unstructured { func newSinkDestination() duckv1.Destination { return duckv1.Destination{ Ref: &duckv1.KReference{ - APIVersion: "testing.cloud.google.com/v1alpha1", + APIVersion: "testing.cloud.google.com/v1beta1", Kind: "Sink", Name: sinkName, Namespace: testNS, @@ -178,7 +178,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), WithCloudStorageSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), ), newSink(), @@ -192,14 +192,14 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), WithInitCloudStorageSourceConditions, WithCloudStorageSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudStorageSourceTopicUnknown("TopicNotConfigured", failedToReconcileTopicMsg), ), }}, WantCreates: []runtime.Object{ NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -209,7 +209,7 @@ func TestAllCases(t *testing.T) { SourceLabelKey: storageName, }), WithTopicAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -230,7 +230,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -265,7 +265,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -302,7 +302,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -340,7 +340,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -378,7 +378,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -415,7 +415,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -451,12 +451,12 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), WithCloudStorageSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudStorageSourceDefaultGCPAuth(), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -479,7 +479,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceTopicReady(testTopicID), WithCloudStorageSourceProjectID(testProject), WithCloudStorageSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudStorageSourceDefaultGCPAuth(), WithCloudStorageSourcePullSubscriptionUnknown("PullSubscriptionNotConfigured", failedToReconcilepullSubscriptionMsg), @@ -487,9 +487,9 @@ func TestAllCases(t *testing.T) { }}, WantCreates: []runtime.Object{ NewPullSubscriptionWithNoDefaults(storageName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, }, }), @@ -500,7 +500,7 @@ func TestAllCases(t *testing.T) { }), WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithPullSubscriptionOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -521,7 +521,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -531,9 +531,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(storageName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -571,7 +571,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -581,9 +581,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(storageName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -601,7 +601,7 @@ func TestAllCases(t *testing.T) { WithInitCloudStorageSourceConditions, WithCloudStorageSourceTopicReady(testTopicID), WithCloudStorageSourceProjectID(testProject), - WithCloudStorageSourcePullSubscriptionFailed("InvalidSink", `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1alpha1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), + WithCloudStorageSourcePullSubscriptionFailed("InvalidSink", `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1beta1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), ), }}, WantPatches: []clientgotesting.PatchActionImpl{ @@ -620,7 +620,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceSink(sinkGVK, sinkName), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -630,9 +630,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(storageName, testNS, WithPullSubscriptionUnknown(), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -668,10 +668,10 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -682,9 +682,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(storageName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Project: testProject, Secret: &secret, SourceSpec: duckv1.SourceSpec{ @@ -716,7 +716,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceStatusObservedGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithInitCloudStorageSourceConditions, WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceTopicReady(testTopicID), @@ -736,10 +736,10 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -750,9 +750,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(storageName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Project: testProject, Secret: &secret, SourceSpec: duckv1.SourceSpec{ @@ -786,7 +786,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceStatusObservedGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithInitCloudStorageSourceConditions, WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceTopicReady(testTopicID), @@ -805,10 +805,10 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -819,9 +819,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(storageName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Project: testProject, Secret: &secret, SourceSpec: duckv1.SourceSpec{ @@ -855,7 +855,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceStatusObservedGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithInitCloudStorageSourceConditions, WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceTopicReady(testTopicID), @@ -874,10 +874,10 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -888,9 +888,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(storageName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Project: testProject, Secret: &secret, SourceSpec: duckv1.SourceSpec{ @@ -924,7 +924,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceStatusObservedGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithInitCloudStorageSourceConditions, WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceTopicReady(testTopicID), @@ -943,10 +943,10 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), ), NewTopic(storageName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -957,9 +957,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(storageName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Project: testProject, Secret: &secret, SourceSpec: duckv1.SourceSpec{ @@ -993,7 +993,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceStatusObservedGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithInitCloudStorageSourceConditions, WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceTopicReady(testTopicID), @@ -1012,7 +1012,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithCloudStorageSourceSinkURI(storageSinkURL), WithCloudStorageSourceNotificationReady(notificationId), WithCloudStorageSourceTopicReady(testTopicID), @@ -1053,7 +1053,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithCloudStorageSourceSinkURI(storageSinkURL), WithCloudStorageSourceNotificationReady(notificationId), WithCloudStorageSourceTopicReady(testTopicID), @@ -1094,7 +1094,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithCloudStorageSourceSinkURI(storageSinkURL), WithCloudStorageSourceTopicReady(testTopicID), WithDeletionTimestamp(), @@ -1119,11 +1119,11 @@ func TestAllCases(t *testing.T) { }, WantDeletes: []clientgotesting.DeleteActionImpl{ {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "topics"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "topics"}}, Name: storageName, }, {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "pullsubscriptions"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "pullsubscriptions"}}, Name: storageName, }, }, @@ -1133,7 +1133,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceTopicFailed("TopicDeleted", fmt.Sprintf("Successfully deleted Topic: %s", storageName)), WithCloudStorageSourcePullSubscriptionFailed("PullSubscriptionDeleted", fmt.Sprintf("Successfully deleted PullSubscription: %s", storageName)), @@ -1148,7 +1148,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithCloudStorageSourceSinkURI(storageSinkURL), WithCloudStorageSourceTopicReady(testTopicID), WithDeletionTimestamp(), @@ -1177,11 +1177,11 @@ func TestAllCases(t *testing.T) { }, WantDeletes: []clientgotesting.DeleteActionImpl{ {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "topics"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "topics"}}, Name: storageName, }, {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "pullsubscriptions"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "pullsubscriptions"}}, Name: storageName, }, }, @@ -1191,7 +1191,7 @@ func TestAllCases(t *testing.T) { WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceBucket(bucket), WithCloudStorageSourceSink(sinkGVK, sinkName), - WithCloudStorageSourceEventTypes([]string{storagev1alpha1.CloudStorageSourceFinalize}), + WithCloudStorageSourceEventTypes([]string{storagev1beta1.CloudStorageSourceFinalize}), WithCloudStorageSourceObjectMetaGeneration(generation), WithCloudStorageSourceTopicFailed("TopicDeleted", fmt.Sprintf("Successfully deleted Topic: %s", storageName)), WithCloudStorageSourcePullSubscriptionFailed("PullSubscriptionDeleted", fmt.Sprintf("Successfully deleted PullSubscription: %s", storageName)), diff --git a/pkg/reconciler/intevents/pullsubscription/keda/resources/names.go b/pkg/reconciler/intevents/pullsubscription/keda/resources/names.go index aa5f5a1648..01fba5de39 100644 --- a/pkg/reconciler/intevents/pullsubscription/keda/resources/names.go +++ b/pkg/reconciler/intevents/pullsubscription/keda/resources/names.go @@ -1,11 +1,11 @@ package resources import ( - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" "github.com/google/knative-gcp/pkg/reconciler/intevents/pullsubscription/resources" ) // GenerateScaledObjectName generates the name for the ScaledObject based on the PullSubscription information. -func GenerateScaledObjectName(ps *v1alpha1.PullSubscription) string { +func GenerateScaledObjectName(ps *v1beta1.PullSubscription) string { return resources.GenerateK8sName(ps) } diff --git a/pkg/reconciler/intevents/pullsubscription/keda/resources/scaled_object.go b/pkg/reconciler/intevents/pullsubscription/keda/resources/scaled_object.go index c6fde340a6..8f2cb193da 100644 --- a/pkg/reconciler/intevents/pullsubscription/keda/resources/scaled_object.go +++ b/pkg/reconciler/intevents/pullsubscription/keda/resources/scaled_object.go @@ -23,34 +23,34 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" v1 "k8s.io/api/apps/v1" ) var ( ScaledObjectGVK = schema.GroupVersionKind{ Group: "keda.k8s.io", - Version: "v1alpha1", + Version: "v1beta1", Kind: "ScaledObject", } - KedaSchemeGroupVersion = schema.GroupVersion{Group: "keda.k8s.io", Version: "v1alpha1"} + KedaSchemeGroupVersion = schema.GroupVersion{Group: "keda.k8s.io", Version: "v1beta1"} ) -func MakeScaledObject(ctx context.Context, ra *v1.Deployment, ps *v1alpha1.PullSubscription) *unstructured.Unstructured { +func MakeScaledObject(ctx context.Context, ra *v1.Deployment, ps *v1beta1.PullSubscription) *unstructured.Unstructured { // These values should have already been validated in the webhook, and be valid ints. Not checking for errors. - minReplicaCount, _ := strconv.ParseInt(ps.Annotations[duckv1alpha1.AutoscalingMinScaleAnnotation], 10, 64) - maxReplicateCount, _ := strconv.ParseInt(ps.Annotations[duckv1alpha1.AutoscalingMaxScaleAnnotation], 10, 64) - cooldownPeriod, _ := strconv.ParseInt(ps.Annotations[duckv1alpha1.KedaAutoscalingCooldownPeriodAnnotation], 10, 64) - pollingInterval, _ := strconv.ParseInt(ps.Annotations[duckv1alpha1.KedaAutoscalingPollingIntervalAnnotation], 10, 64) + minReplicaCount, _ := strconv.ParseInt(ps.Annotations[duckv1beta1.AutoscalingMinScaleAnnotation], 10, 64) + maxReplicateCount, _ := strconv.ParseInt(ps.Annotations[duckv1beta1.AutoscalingMaxScaleAnnotation], 10, 64) + cooldownPeriod, _ := strconv.ParseInt(ps.Annotations[duckv1beta1.KedaAutoscalingCooldownPeriodAnnotation], 10, 64) + pollingInterval, _ := strconv.ParseInt(ps.Annotations[duckv1beta1.KedaAutoscalingPollingIntervalAnnotation], 10, 64) // Using Unstructured instead of adding the Keda dependency. Given that the only way to interact with the scaledObject // is using the dynamicClient (see https://keda.sh/faq/), it does not make much sense for now to add an extra dependency, // which BTW brings things like controller-runtime, etc. so := &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "keda.k8s.io/v1alpha1", + "apiVersion": "keda.k8s.io/v1beta1", "kind": "ScaledObject", "metadata": map[string]interface{}{ "namespace": ra.Namespace, @@ -81,7 +81,7 @@ func MakeScaledObject(ctx context.Context, ra *v1.Deployment, ps *v1alpha1.PullS map[string]interface{}{ "type": "gcp-pubsub", "metadata": map[string]interface{}{ - "subscriptionSize": ps.Annotations[duckv1alpha1.KedaAutoscalingSubscriptionSizeAnnotation], + "subscriptionSize": ps.Annotations[duckv1beta1.KedaAutoscalingSubscriptionSizeAnnotation], "subscriptionName": ps.Status.SubscriptionID, "credentials": "GOOGLE_APPLICATION_CREDENTIALS_JSON", }, diff --git a/pkg/reconciler/intevents/pullsubscription/reconciler.go b/pkg/reconciler/intevents/pullsubscription/reconciler.go index 49450dabe2..4ff5f80eb7 100644 --- a/pkg/reconciler/intevents/pullsubscription/reconciler.go +++ b/pkg/reconciler/intevents/pullsubscription/reconciler.go @@ -42,8 +42,8 @@ import ( "knative.dev/pkg/resolver" tracingconfig "knative.dev/pkg/tracing/config" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - listers "github.com/google/knative-gcp/pkg/client/listers/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + listers "github.com/google/knative-gcp/pkg/client/listers/intevents/v1beta1" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/intevents" @@ -95,9 +95,9 @@ type Base struct { } // ReconcileDataPlaneFunc is used to reconcile the data plane component(s). -type ReconcileDataPlaneFunc func(ctx context.Context, d *appsv1.Deployment, ps *v1alpha1.PullSubscription) error +type ReconcileDataPlaneFunc func(ctx context.Context, d *appsv1.Deployment, ps *v1beta1.PullSubscription) error -func (r *Base) ReconcileKind(ctx context.Context, ps *v1alpha1.PullSubscription) reconciler.Event { +func (r *Base) ReconcileKind(ctx context.Context, ps *v1beta1.PullSubscription) reconciler.Event { ctx = logging.WithLogger(ctx, r.Logger.With(zap.Any("pullsubscription", ps))) ps.Status.InitializeConditions() @@ -151,7 +151,7 @@ func (r *Base) ReconcileKind(ctx context.Context, ps *v1alpha1.PullSubscription) return reconciler.NewEvent(corev1.EventTypeNormal, reconciledSuccessReason, `PullSubscription reconciled: "%s/%s"`, ps.Namespace, ps.Name) } -func (r *Base) reconcileSubscription(ctx context.Context, ps *v1alpha1.PullSubscription) (string, error) { +func (r *Base) reconcileSubscription(ctx context.Context, ps *v1beta1.PullSubscription) (string, error) { if ps.Status.ProjectID == "" { projectID, err := utils.ProjectID(ps.Spec.Project, metadataClient.NewDefaultMetadataClient()) if err != nil { @@ -233,7 +233,7 @@ func (r *Base) reconcileSubscription(ctx context.Context, ps *v1alpha1.PullSubsc // deleteSubscription looks at the status.SubscriptionID and if non-empty, // hence indicating that we have created a subscription successfully // in the PullSubscription, remove it. -func (r *Base) deleteSubscription(ctx context.Context, ps *v1alpha1.PullSubscription) error { +func (r *Base) deleteSubscription(ctx context.Context, ps *v1beta1.PullSubscription) error { if ps.Status.SubscriptionID == "" { return nil } @@ -263,7 +263,7 @@ func (r *Base) deleteSubscription(ctx context.Context, ps *v1alpha1.PullSubscrip return nil } -func (r *Base) reconcileDataPlaneResources(ctx context.Context, ps *v1alpha1.PullSubscription, f ReconcileDataPlaneFunc) error { +func (r *Base) reconcileDataPlaneResources(ctx context.Context, ps *v1beta1.PullSubscription, f ReconcileDataPlaneFunc) error { loggingConfig, err := logging.LoggingConfigToJson(r.LoggingConfig) if err != nil { logging.FromContext(ctx).Desugar().Error("Error serializing existing logging config", zap.Error(err)) @@ -303,7 +303,7 @@ func (r *Base) reconcileDataPlaneResources(ctx context.Context, ps *v1alpha1.Pul return f(ctx, desired, ps) } -func (r *Base) GetOrCreateReceiveAdapter(ctx context.Context, desired *appsv1.Deployment, ps *v1alpha1.PullSubscription) (*appsv1.Deployment, error) { +func (r *Base) GetOrCreateReceiveAdapter(ctx context.Context, desired *appsv1.Deployment, ps *v1beta1.PullSubscription) (*appsv1.Deployment, error) { existing, err := r.getReceiveAdapter(ctx, ps) if err != nil && !apierrors.IsNotFound(err) { logging.FromContext(ctx).Desugar().Error("Unable to get an existing Receive Adapter", zap.Error(err)) @@ -319,7 +319,7 @@ func (r *Base) GetOrCreateReceiveAdapter(ctx context.Context, desired *appsv1.De return existing, nil } -func (r *Base) getReceiveAdapter(ctx context.Context, ps *v1alpha1.PullSubscription) (*appsv1.Deployment, error) { +func (r *Base) getReceiveAdapter(ctx context.Context, ps *v1beta1.PullSubscription) (*appsv1.Deployment, error) { dl, err := r.KubeClientSet.AppsV1().Deployments(ps.Namespace).List(metav1.ListOptions{ LabelSelector: resources.GetLabelSelector(r.ControllerAgentName, ps.Name).String(), TypeMeta: metav1.TypeMeta{ @@ -387,7 +387,7 @@ func (r *Base) UpdateFromTracingConfigMap(cfg *corev1.ConfigMap) { // TODO: requeue all PullSubscriptions. See https://github.com/google/knative-gcp/issues/457. } -func (r *Base) resolveDestination(ctx context.Context, destination duckv1.Destination, ps *v1alpha1.PullSubscription) (*apis.URL, error) { +func (r *Base) resolveDestination(ctx context.Context, destination duckv1.Destination, ps *v1beta1.PullSubscription) (*apis.URL, error) { // To call URIFromDestinationV1(), dest.Ref must have a Namespace. If there is // no Namespace defined in dest.Ref, we will use the Namespace of the PS // as the Namespace of dest.Ref. @@ -401,7 +401,7 @@ func (r *Base) resolveDestination(ctx context.Context, destination duckv1.Destin return url, nil } -func (r *Base) FinalizeKind(ctx context.Context, ps *v1alpha1.PullSubscription) reconciler.Event { +func (r *Base) FinalizeKind(ctx context.Context, ps *v1beta1.PullSubscription) reconciler.Event { // If pullsubscription doesn't have ownerReference, and // k8s ServiceAccount exists, binds to the default GCP ServiceAccount, and it only has one ownerReference, // remove the corresponding GCP ServiceAccount iam policy binding. diff --git a/pkg/reconciler/intevents/pullsubscription/resources/names.go b/pkg/reconciler/intevents/pullsubscription/resources/names.go index ca367e2810..d0e462b9fa 100644 --- a/pkg/reconciler/intevents/pullsubscription/resources/names.go +++ b/pkg/reconciler/intevents/pullsubscription/resources/names.go @@ -19,31 +19,31 @@ package resources import ( "fmt" "github.com/google/knative-gcp/pkg/apis/intevents" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" "github.com/google/knative-gcp/pkg/utils/naming" "knative.dev/pkg/kmeta" ) // GenerateSubscriptionName generates the name for the Pub/Sub subscription to be used for this PullSubscription. // It uses the object labels to see whether it's from a source, channel, or ps to construct the name. -func GenerateSubscriptionName(ps *v1alpha1.PullSubscription) string { +func GenerateSubscriptionName(ps *v1beta1.PullSubscription) string { prefix := getPrefix(ps) return naming.TruncatedPubsubResourceName(prefix, ps.Namespace, ps.Name, ps.UID) } // GenerateReceiveAdapterName generates the name of the receive adapter to be used for this PullSubscription. -func GenerateReceiveAdapterName(ps *v1alpha1.PullSubscription) string { +func GenerateReceiveAdapterName(ps *v1beta1.PullSubscription) string { return GenerateK8sName(ps) } // GenerateK8sName generates a k8s name based on PullSubscription information. // It uses the object labels to see whether it's from a source, channel, or ps to constructs a k8s compliant name. -func GenerateK8sName(ps *v1alpha1.PullSubscription) string { +func GenerateK8sName(ps *v1beta1.PullSubscription) string { prefix := getPrefix(ps) return kmeta.ChildName(fmt.Sprintf("%s-%s", prefix, ps.Name), "-"+string(ps.UID)) } -func getPrefix(ps *v1alpha1.PullSubscription) string { +func getPrefix(ps *v1beta1.PullSubscription) string { prefix := "cre-ps" if _, ok := ps.Labels[intevents.SourceLabelKey]; ok { prefix = "cre-src" diff --git a/pkg/reconciler/intevents/pullsubscription/resources/receive_adapter.go b/pkg/reconciler/intevents/pullsubscription/resources/receive_adapter.go index 7fdff21943..6cf144d3e5 100644 --- a/pkg/reconciler/intevents/pullsubscription/resources/receive_adapter.go +++ b/pkg/reconciler/intevents/pullsubscription/resources/receive_adapter.go @@ -26,7 +26,7 @@ import ( "knative.dev/pkg/kmeta" "knative.dev/pkg/logging" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" "github.com/google/knative-gcp/pkg/pubsub/adapter/converters" "github.com/google/knative-gcp/pkg/utils" @@ -39,7 +39,7 @@ import ( // Adapter. Every field is required. type ReceiveAdapterArgs struct { Image string - PullSubscription *v1alpha1.PullSubscription + PullSubscription *v1beta1.PullSubscription Labels map[string]string SubscriptionID string SinkURI *apis.URL @@ -71,11 +71,11 @@ func makeReceiveAdapterPodSpec(ctx context.Context, args *ReceiveAdapterArgs) *c var mode converters.ModeType switch args.PullSubscription.PubSubMode() { - case "", v1alpha1.ModeCloudEventsBinary: + case "", v1beta1.ModeCloudEventsBinary: mode = converters.Binary - case v1alpha1.ModeCloudEventsStructured: + case v1beta1.ModeCloudEventsStructured: mode = converters.Structured - case v1alpha1.ModePushCompatible: + case v1beta1.ModePushCompatible: mode = converters.Push } diff --git a/pkg/reconciler/intevents/pullsubscription/static/controller.go b/pkg/reconciler/intevents/pullsubscription/static/controller.go index b967f29764..91617329f9 100644 --- a/pkg/reconciler/intevents/pullsubscription/static/controller.go +++ b/pkg/reconciler/intevents/pullsubscription/static/controller.go @@ -22,9 +22,9 @@ import ( "knative.dev/pkg/injection" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" @@ -35,7 +35,7 @@ import ( "go.uber.org/zap" "k8s.io/client-go/tools/cache" - pullsubscriptionreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1alpha1/pullsubscription" + pullsubscriptionreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1beta1/pullsubscription" deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment" serviceaccountinformers "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount" "knative.dev/pkg/configmap" @@ -113,7 +113,7 @@ func newController( // Whenever we introduce a new way of scaling, this code will have to be updated to not just exclude Keda, but the others. // Might be useful to use pkgreconciler.ChainFilterFuncs and move them somewhere else. // TODO revisit once we introduce new scaling strategies. - onlyKedaScaler := pkgreconciler.AnnotationFilterFunc(duckv1alpha1.AutoscalingClassAnnotation, duckv1alpha1.KEDA, false) + onlyKedaScaler := pkgreconciler.AnnotationFilterFunc(duckv1beta1.AutoscalingClassAnnotation, duckv1beta1.KEDA, false) notKedaScaler := pkgreconciler.Not(onlyKedaScaler) pullSubscriptionHandler := cache.FilteringResourceEventHandler{ @@ -128,7 +128,7 @@ func newController( }) serviceAccountInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind("Pullsubscription")), + FilterFunc: controller.FilterGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("Pullsubscription")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/intevents/pullsubscription/static/pullsubscription.go b/pkg/reconciler/intevents/pullsubscription/static/pullsubscription.go index f48b2db30e..0d21394ef4 100644 --- a/pkg/reconciler/intevents/pullsubscription/static/pullsubscription.go +++ b/pkg/reconciler/intevents/pullsubscription/static/pullsubscription.go @@ -21,8 +21,8 @@ import ( "go.uber.org/zap" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - pullsubscriptionreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1alpha1/pullsubscription" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + pullsubscriptionreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1beta1/pullsubscription" psreconciler "github.com/google/knative-gcp/pkg/reconciler/intevents/pullsubscription" appsv1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/api/equality" @@ -38,11 +38,11 @@ type Reconciler struct { // Check that our Reconciler implements Interface. var _ pullsubscriptionreconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, ps *v1alpha1.PullSubscription) reconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, ps *v1beta1.PullSubscription) reconciler.Event { return r.Base.ReconcileKind(ctx, ps) } -func (r *Reconciler) ReconcileDeployment(ctx context.Context, ra *appsv1.Deployment, src *v1alpha1.PullSubscription) error { +func (r *Reconciler) ReconcileDeployment(ctx context.Context, ra *appsv1.Deployment, src *v1beta1.PullSubscription) error { existing, err := r.Base.GetOrCreateReceiveAdapter(ctx, ra, src) if err != nil { return err @@ -58,6 +58,6 @@ func (r *Reconciler) ReconcileDeployment(ctx context.Context, ra *appsv1.Deploym return nil } -func (r *Reconciler) FinalizeKind(ctx context.Context, ps *v1alpha1.PullSubscription) reconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, ps *v1beta1.PullSubscription) reconciler.Event { return r.Base.FinalizeKind(ctx, ps) } diff --git a/pkg/reconciler/intevents/reconciler.go b/pkg/reconciler/intevents/reconciler.go index 2ae3d0037f..8dc0eb68c4 100644 --- a/pkg/reconciler/intevents/reconciler.go +++ b/pkg/reconciler/intevents/reconciler.go @@ -20,10 +20,10 @@ import ( "context" "fmt" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" clientset "github.com/google/knative-gcp/pkg/client/clientset/versioned" - duck "github.com/google/knative-gcp/pkg/duck/v1alpha1" + duck "github.com/google/knative-gcp/pkg/duck/v1beta1" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/intevents/resources" "go.uber.org/zap" @@ -63,7 +63,7 @@ type PubSubBase struct { // "TopicReady", and "PullSubscriptionReady" // Also sets the following fields in the pubsubable.Status upon success // TopicID, ProjectID, and SinkURI -func (psb *PubSubBase) ReconcilePubSub(ctx context.Context, pubsubable duck.PubSubable, topic, resourceGroup string) (*inteventsv1alpha1.Topic, *inteventsv1alpha1.PullSubscription, error) { +func (psb *PubSubBase) ReconcilePubSub(ctx context.Context, pubsubable duck.PubSubable, topic, resourceGroup string) (*inteventsv1beta1.Topic, *inteventsv1beta1.PullSubscription, error) { t, err := psb.reconcileTopic(ctx, pubsubable, topic) if err != nil { return t, nil, err @@ -76,7 +76,7 @@ func (psb *PubSubBase) ReconcilePubSub(ctx context.Context, pubsubable duck.PubS return t, ps, nil } -func (psb *PubSubBase) reconcileTopic(ctx context.Context, pubsubable duck.PubSubable, topic string) (*inteventsv1alpha1.Topic, pkgreconciler.Event) { +func (psb *PubSubBase) reconcileTopic(ctx context.Context, pubsubable duck.PubSubable, topic string) (*inteventsv1beta1.Topic, pkgreconciler.Event) { if pubsubable == nil { return nil, fmt.Errorf("nil pubsubable passed in") } @@ -94,7 +94,7 @@ func (psb *PubSubBase) reconcileTopic(ctx context.Context, pubsubable duck.PubSu } newTopic := resources.MakeTopic(args) - topics := psb.pubsubClient.InternalV1alpha1().Topics(newTopic.Namespace) + topics := psb.pubsubClient.InternalV1beta1().Topics(newTopic.Namespace) t, err := topics.Get(newTopic.Name, v1.GetOptions{}) if apierrs.IsNotFound(err) { logging.FromContext(ctx).Desugar().Debug("Creating Topic", zap.Any("topic", newTopic)) @@ -128,7 +128,7 @@ func (psb *PubSubBase) reconcileTopic(ctx context.Context, pubsubable duck.PubSu return t, nil } -func (psb *PubSubBase) ReconcilePullSubscription(ctx context.Context, pubsubable duck.PubSubable, topic, resourceGroup string, isPushCompatible bool) (*inteventsv1alpha1.PullSubscription, pkgreconciler.Event) { +func (psb *PubSubBase) ReconcilePullSubscription(ctx context.Context, pubsubable duck.PubSubable, topic, resourceGroup string, isPushCompatible bool) (*inteventsv1beta1.PullSubscription, pkgreconciler.Event) { if pubsubable == nil { logging.FromContext(ctx).Desugar().Error("Nil pubsubable passed in") return nil, pkgreconciler.NewEvent(corev1.EventTypeWarning, nilPubsubableReason, "nil pubsubable passed in") @@ -152,11 +152,11 @@ func (psb *PubSubBase) ReconcilePullSubscription(ctx context.Context, pubsubable Annotations: resources.GetAnnotations(annotations, resourceGroup), } if isPushCompatible { - args.Mode = inteventsv1alpha1.ModePushCompatible + args.Mode = inteventsv1beta1.ModePushCompatible } newPS := resources.MakePullSubscription(args) - pullSubscriptions := psb.pubsubClient.InternalV1alpha1().PullSubscriptions(namespace) + pullSubscriptions := psb.pubsubClient.InternalV1beta1().PullSubscriptions(namespace) ps, err := pullSubscriptions.Get(name, v1.GetOptions{}) if err != nil { if !apierrs.IsNotFound(err) { @@ -192,7 +192,7 @@ func (psb *PubSubBase) ReconcilePullSubscription(ctx context.Context, pubsubable return ps, nil } -func propagatePullSubscriptionStatus(ps *inteventsv1alpha1.PullSubscription, status *duckv1alpha1.PubSubStatus, cs *apis.ConditionSet) error { +func propagatePullSubscriptionStatus(ps *inteventsv1beta1.PullSubscription, status *duckv1beta1.PubSubStatus, cs *apis.ConditionSet) error { pc := ps.Status.GetTopLevelCondition() if pc == nil { status.MarkPullSubscriptionNotConfigured(cs) @@ -214,7 +214,7 @@ func propagatePullSubscriptionStatus(ps *inteventsv1alpha1.PullSubscription, sta return nil } -func propagateTopicStatus(t *inteventsv1alpha1.Topic, status *duckv1alpha1.PubSubStatus, cs *apis.ConditionSet, topic string) error { +func propagateTopicStatus(t *inteventsv1beta1.Topic, status *duckv1beta1.PubSubStatus, cs *apis.ConditionSet, topic string) error { tc := t.Status.GetTopLevelCondition() if tc == nil { status.MarkTopicNotConfigured(cs) @@ -263,7 +263,7 @@ func (psb *PubSubBase) DeletePubSub(ctx context.Context, pubsubable duck.PubSuba cs := pubsubable.ConditionSet() // Delete the topic - err := psb.pubsubClient.InternalV1alpha1().Topics(namespace).Delete(name, nil) + err := psb.pubsubClient.InternalV1beta1().Topics(namespace).Delete(name, nil) if err != nil && !apierrs.IsNotFound(err) { logging.FromContext(ctx).Desugar().Error("Failed to delete Topic", zap.String("name", name), zap.Error(err)) status.MarkTopicFailed(cs, "TopicDeleteFailed", "Failed to delete Topic: %s", err.Error()) @@ -274,7 +274,7 @@ func (psb *PubSubBase) DeletePubSub(ctx context.Context, pubsubable duck.PubSuba status.ProjectID = "" // Delete the pullsubscription - err = psb.pubsubClient.InternalV1alpha1().PullSubscriptions(namespace).Delete(name, nil) + err = psb.pubsubClient.InternalV1beta1().PullSubscriptions(namespace).Delete(name, nil) if err != nil && !apierrs.IsNotFound(err) { logging.FromContext(ctx).Desugar().Error("Failed to delete PullSubscription", zap.String("name", name), zap.Error(err)) status.MarkPullSubscriptionFailed(cs, "PullSubscriptionDeleteFailed", "Failed to delete PullSubscription: %s", err.Error()) diff --git a/pkg/reconciler/intevents/resources/pullsubscription.go b/pkg/reconciler/intevents/resources/pullsubscription.go index 17d557fb0b..25750e5e69 100644 --- a/pkg/reconciler/intevents/resources/pullsubscription.go +++ b/pkg/reconciler/intevents/resources/pullsubscription.go @@ -21,26 +21,26 @@ import ( duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/kmeta" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" ) type PullSubscriptionArgs struct { Namespace string Name string - Spec *duckv1alpha1.PubSubSpec + Spec *duckv1beta1.PubSubSpec Owner kmeta.OwnerRefable Topic string AdapterType string - Mode inteventsv1alpha1.ModeType + Mode inteventsv1beta1.ModeType Labels map[string]string Annotations map[string]string } // MakePullSubscription creates the spec for, but does not create, a GCP PullSubscription // for a given GCS. -func MakePullSubscription(args *PullSubscriptionArgs) *inteventsv1alpha1.PullSubscription { - ps := &inteventsv1alpha1.PullSubscription{ +func MakePullSubscription(args *PullSubscriptionArgs) *inteventsv1beta1.PullSubscription { + ps := &inteventsv1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: args.Name, Namespace: args.Namespace, @@ -48,9 +48,9 @@ func MakePullSubscription(args *PullSubscriptionArgs) *inteventsv1alpha1.PullSub Annotations: args.Annotations, OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(args.Owner)}, }, - Spec: inteventsv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ + Spec: inteventsv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ + IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: args.Spec.IdentitySpec.ServiceAccountName, }, Secret: args.Spec.Secret, diff --git a/pkg/reconciler/intevents/resources/topic.go b/pkg/reconciler/intevents/resources/topic.go index 4232322e12..3765ae8e78 100644 --- a/pkg/reconciler/intevents/resources/topic.go +++ b/pkg/reconciler/intevents/resources/topic.go @@ -20,14 +20,14 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/kmeta" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" ) type TopicArgs struct { Namespace string Name string - Spec *duckv1alpha1.PubSubSpec + Spec *duckv1beta1.PubSubSpec EnablePublisher *bool Owner kmeta.OwnerRefable Topic string @@ -37,8 +37,8 @@ type TopicArgs struct { // MakeTopic creates the spec for, but does not create, a GCP Topic // for a given GCS. -func MakeTopic(args *TopicArgs) *inteventsv1alpha1.Topic { - return &inteventsv1alpha1.Topic{ +func MakeTopic(args *TopicArgs) *inteventsv1beta1.Topic { + return &inteventsv1beta1.Topic{ ObjectMeta: metav1.ObjectMeta{ Name: args.Name, Namespace: args.Namespace, @@ -46,14 +46,14 @@ func MakeTopic(args *TopicArgs) *inteventsv1alpha1.Topic { Annotations: args.Annotations, OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(args.Owner)}, }, - Spec: inteventsv1alpha1.TopicSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ + Spec: inteventsv1beta1.TopicSpec{ + IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: args.Spec.IdentitySpec.ServiceAccountName, }, Secret: args.Spec.Secret, Project: args.Spec.Project, Topic: args.Topic, - PropagationPolicy: inteventsv1alpha1.TopicPolicyCreateDelete, + PropagationPolicy: inteventsv1beta1.TopicPolicyCreateDelete, EnablePublisher: args.EnablePublisher, }, } diff --git a/pkg/reconciler/intevents/topic/controller.go b/pkg/reconciler/intevents/topic/controller.go index b0c0d512ce..531f7ed88f 100644 --- a/pkg/reconciler/intevents/topic/controller.go +++ b/pkg/reconciler/intevents/topic/controller.go @@ -30,15 +30,15 @@ import ( tracingconfig "knative.dev/pkg/tracing/config" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/identity/iam" "github.com/google/knative-gcp/pkg/reconciler/intevents" - topicinformer "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic" - topicreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1alpha1/topic" + topicinformer "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic" + topicreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1beta1/topic" serviceaccountinformers "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount" serviceinformer "knative.dev/serving/pkg/client/injection/informers/serving/v1/service" ) @@ -102,12 +102,12 @@ func newController( topicInformer.Informer().AddEventHandlerWithResyncPeriod(controller.HandleAll(impl.Enqueue), reconciler.DefaultResyncPeriod) serviceInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("Topic")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("Topic")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) serviceAccountInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind("Topic")), + FilterFunc: controller.FilterGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("Topic")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/testing/listers.go b/pkg/reconciler/testing/listers.go index 08cf67605a..1726753136 100644 --- a/pkg/reconciler/testing/listers.go +++ b/pkg/reconciler/testing/listers.go @@ -50,7 +50,7 @@ import ( Messagingv1beta1 "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" fakeeventsclientset "github.com/google/knative-gcp/pkg/client/clientset/versioned/fake" brokerlisters "github.com/google/knative-gcp/pkg/client/listers/broker/v1beta1" - eventslisters "github.com/google/knative-gcp/pkg/client/listers/events/v1alpha1" + eventslisters "github.com/google/knative-gcp/pkg/client/listers/events/v1beta1" intlisters "github.com/google/knative-gcp/pkg/client/listers/intevents/v1alpha1" inteventslisters "github.com/google/knative-gcp/pkg/client/listers/intevents/v1beta1" messaginglisters "github.com/google/knative-gcp/pkg/client/listers/messaging/v1beta1" diff --git a/pkg/reconciler/testing/pullsubscription.go b/pkg/reconciler/testing/pullsubscription.go index 3169c89751..a12d43fefe 100644 --- a/pkg/reconciler/testing/pullsubscription.go +++ b/pkg/reconciler/testing/pullsubscription.go @@ -28,19 +28,19 @@ import ( "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" ) // PullSubscriptionOption enables further configuration of a PullSubscription. -type PullSubscriptionOption func(*v1alpha1.PullSubscription) +type PullSubscriptionOption func(*v1beta1.PullSubscription) const ( SubscriptionID = "subID" ) // NewPullSubscription creates a PullSubscription with PullSubscriptionOptions -func NewPullSubscription(name, namespace string, so ...PullSubscriptionOption) *v1alpha1.PullSubscription { - s := &v1alpha1.PullSubscription{ +func NewPullSubscription(name, namespace string, so ...PullSubscriptionOption) *v1beta1.PullSubscription { + s := &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, @@ -55,8 +55,8 @@ func NewPullSubscription(name, namespace string, so ...PullSubscriptionOption) * // NewPullSubscriptionWithNoDefaults creates a PullSubscription with // PullSubscriptionOptions but does not set defaults. -func NewPullSubscriptionWithNoDefaults(name, namespace string, so ...PullSubscriptionOption) *v1alpha1.PullSubscription { - s := &v1alpha1.PullSubscription{ +func NewPullSubscriptionWithNoDefaults(name, namespace string, so ...PullSubscriptionOption) *v1beta1.PullSubscription { + s := &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, @@ -69,8 +69,8 @@ func NewPullSubscriptionWithNoDefaults(name, namespace string, so ...PullSubscri } // NewPullSubscriptionWithoutNamespace creates a PullSubscription with PullSubscriptionOptions but without a specific namespace -func NewPullSubscriptionWithoutNamespace(name string, so ...PullSubscriptionOption) *v1alpha1.PullSubscription { - s := &v1alpha1.PullSubscription{ +func NewPullSubscriptionWithoutNamespace(name string, so ...PullSubscriptionOption) *v1beta1.PullSubscription { + s := &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -83,24 +83,24 @@ func NewPullSubscriptionWithoutNamespace(name string, so ...PullSubscriptionOpti } func WithPullSubscriptionUID(uid types.UID) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.UID = uid } } func WithPullSubscriptionGenerateName(generateName string) PullSubscriptionOption { - return func(c *v1alpha1.PullSubscription) { + return func(c *v1beta1.PullSubscription) { c.ObjectMeta.GenerateName = generateName } } // WithInitPullSubscriptionConditions initializes the PullSubscriptions's conditions. -func WithInitPullSubscriptionConditions(s *v1alpha1.PullSubscription) { +func WithInitPullSubscriptionConditions(s *v1beta1.PullSubscription) { s.Status.InitializeConditions() } func WithPullSubscriptionSink(gvk metav1.GroupVersionKind, name string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Spec.Sink = duckv1.Destination{ Ref: &duckv1.KReference{ APIVersion: apiVersion(gvk), @@ -112,7 +112,7 @@ func WithPullSubscriptionSink(gvk metav1.GroupVersionKind, name string) PullSubs } func WithPullSubscriptionTransformer(gvk metav1.GroupVersionKind, name string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Spec.Transformer = &duckv1.Destination{ Ref: &duckv1.KReference{ APIVersion: apiVersion(gvk), @@ -124,73 +124,73 @@ func WithPullSubscriptionTransformer(gvk metav1.GroupVersionKind, name string) P } func WithPullSubscriptionMarkSink(uri *apis.URL) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.MarkSink(uri) } } func WithPullSubscriptionMarkTransformer(uri *apis.URL) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.MarkTransformer(uri) } } func WithPullSubscriptionMarkNoTransformer(reason, message string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.MarkNoTransformer(reason, message) } } func WithPullSubscriptionMarkSubscribed(subscriptionID string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.MarkSubscribed(subscriptionID) } } func WithPullSubscriptionSubscriptionID(subscriptionID string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.SubscriptionID = subscriptionID } } func WithPullSubscriptionProjectID(projectID string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.ProjectID = projectID } } func WithPullSubscriptionTransformerURI(uri *apis.URL) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.TransformerURI = uri } } func WithPullSubscriptionMarkNoSubscription(reason, message string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.MarkNoSubscription(reason, message) } } -func WithPullSubscriptionMarkDeployed(ps *v1alpha1.PullSubscription) { +func WithPullSubscriptionMarkDeployed(ps *v1beta1.PullSubscription) { ps.Status.MarkDeployed() } -func WithPullSubscriptionSpec(spec v1alpha1.PullSubscriptionSpec) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { +func WithPullSubscriptionSpec(spec v1beta1.PullSubscriptionSpec) PullSubscriptionOption { + return func(s *v1beta1.PullSubscription) { s.Spec = spec s.Spec.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) } } // Same as withPullSubscriptionSpec but does not set defaults -func WithPullSubscriptionSpecWithNoDefaults(spec v1alpha1.PullSubscriptionSpec) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { +func WithPullSubscriptionSpecWithNoDefaults(spec v1beta1.PullSubscriptionSpec) PullSubscriptionOption { + return func(s *v1beta1.PullSubscription) { s.Spec = spec } } func WithPullSubscriptionReady(sink *apis.URL) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.InitializeConditions() s.Status.MarkSink(sink) s.Status.MarkDeployed() @@ -199,77 +199,77 @@ func WithPullSubscriptionReady(sink *apis.URL) PullSubscriptionOption { } func WithPullSubscriptionFailed() PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.InitializeConditions() s.Status.MarkNoSink("InvalidSink", - `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1alpha1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`) + `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1beta1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`) } } func WithPullSubscriptionUnknown() PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.InitializeConditions() } } func WithPullSubscriptionJobFailure(subscriptionID, reason, message string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.SubscriptionID = subscriptionID s.Status.MarkNoSubscription(reason, message) } } func WithPullSubscriptionSinkNotFound() PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.MarkNoSink("InvalidSink", - `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1alpha1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`) + `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1beta1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`) } } -func WithPullSubscriptionDeleted(s *v1alpha1.PullSubscription) { +func WithPullSubscriptionDeleted(s *v1beta1.PullSubscription) { t := metav1.NewTime(time.Unix(1e9, 0)) s.ObjectMeta.SetDeletionTimestamp(&t) } func WithPullSubscriptionOwnerReferences(ownerReferences []metav1.OwnerReference) PullSubscriptionOption { - return func(c *v1alpha1.PullSubscription) { + return func(c *v1beta1.PullSubscription) { c.ObjectMeta.OwnerReferences = ownerReferences } } func WithPullSubscriptionLabels(labels map[string]string) PullSubscriptionOption { - return func(c *v1alpha1.PullSubscription) { + return func(c *v1beta1.PullSubscription) { c.ObjectMeta.Labels = labels } } func WithPullSubscriptionAnnotations(annotations map[string]string) PullSubscriptionOption { - return func(c *v1alpha1.PullSubscription) { + return func(c *v1beta1.PullSubscription) { c.ObjectMeta.Annotations = annotations } } func WithPullSubscriptionFinalizers(finalizers ...string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Finalizers = finalizers } } func WithPullSubscriptionStatusObservedGeneration(generation int64) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.Status.ObservedGeneration = generation } } func WithPullSubscriptionObjectMetaGeneration(generation int64) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.ObjectMeta.Generation = generation } } func WithPullSubscriptionReadyStatus(status corev1.ConditionStatus, reason, message string) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Status.Conditions = []apis.Condition{{ Type: apis.ConditionReady, Status: status, @@ -279,14 +279,14 @@ func WithPullSubscriptionReadyStatus(status corev1.ConditionStatus, reason, mess } } -func WithPullSubscriptionMode(mode v1alpha1.ModeType) PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { +func WithPullSubscriptionMode(mode v1beta1.ModeType) PullSubscriptionOption { + return func(s *v1beta1.PullSubscription) { s.Spec.Mode = mode } } func WithPullSubscriptionDefaultGCPAuth() PullSubscriptionOption { - return func(s *v1alpha1.PullSubscription) { + return func(s *v1beta1.PullSubscription) { s.Spec.PubSubSpec.SetPubSubDefaults(gcpauthtesthelper.ContextWithDefaults()) } } diff --git a/pkg/reconciler/testing/topic.go b/pkg/reconciler/testing/topic.go index 9818bda8fa..98147e03bf 100644 --- a/pkg/reconciler/testing/topic.go +++ b/pkg/reconciler/testing/topic.go @@ -26,15 +26,15 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" ) // TopicOption enables further configuration of a Topic. -type TopicOption func(*v1alpha1.Topic) +type TopicOption func(*v1beta1.Topic) // NewTopic creates a Topic with TopicOptions -func NewTopic(name, namespace string, so ...TopicOption) *v1alpha1.Topic { - s := &v1alpha1.Topic{ +func NewTopic(name, namespace string, so ...TopicOption) *v1beta1.Topic { + s := &v1beta1.Topic{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, @@ -48,45 +48,45 @@ func NewTopic(name, namespace string, so ...TopicOption) *v1alpha1.Topic { } func WithTopicUID(uid types.UID) TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.UID = uid } } // WithInitTopicConditions initializes the Topics's conditions. -func WithInitTopicConditions(s *v1alpha1.Topic) { +func WithInitTopicConditions(s *v1beta1.Topic) { s.Status.InitializeConditions() } func WithTopicTopicID(topicID string) TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.Status.MarkTopicReady() s.Status.TopicID = topicID } } func WithTopicPropagationPolicy(policy string) TopicOption { - return func(s *v1alpha1.Topic) { - s.Spec.PropagationPolicy = v1alpha1.PropagationPolicyType(policy) + return func(s *v1beta1.Topic) { + s.Spec.PropagationPolicy = v1beta1.PropagationPolicyType(policy) } } func WithTopicTopicDeleted(topicID string) TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.Status.MarkNoTopic("Deleted", "Successfully deleted topic %q.", topicID) s.Status.TopicID = "" } } func WithTopicJobFailure(topicID, reason, message string) TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.Status.TopicID = topicID s.Status.MarkNoTopic(reason, message) } } func WithTopicAddress(uri string) TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { if uri != "" { u, _ := apis.ParseURL(uri) s.Status.SetAddress(u) @@ -96,42 +96,42 @@ func WithTopicAddress(uri string) TopicOption { } } -func WithTopicSpec(spec v1alpha1.TopicSpec) TopicOption { - return func(s *v1alpha1.Topic) { +func WithTopicSpec(spec v1beta1.TopicSpec) TopicOption { + return func(s *v1beta1.Topic) { s.Spec = spec } } -func WithTopicPublisherDeployed(s *v1alpha1.Topic) { +func WithTopicPublisherDeployed(s *v1beta1.Topic) { s.Status.MarkPublisherDeployed() } func WithTopicPublisherNotDeployed(reason, message string) TopicOption { - return func(t *v1alpha1.Topic) { + return func(t *v1beta1.Topic) { t.Status.MarkPublisherNotDeployed(reason, message) } } func WithTopicPublisherUnknown(reason, message string) TopicOption { - return func(t *v1alpha1.Topic) { + return func(t *v1beta1.Topic) { t.Status.MarkPublisherUnknown(reason, message) } } func WithTopicPublisherNotConfigured() TopicOption { - return func(t *v1alpha1.Topic) { + return func(t *v1beta1.Topic) { t.Status.MarkPublisherNotConfigured() } } func WithTopicProjectID(projectID string) TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.Status.ProjectID = projectID } } func WithTopicReady(topicID string) TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.Status.InitializeConditions() s.Status.MarkTopicReady() s.Status.TopicID = topicID @@ -139,7 +139,7 @@ func WithTopicReady(topicID string) TopicOption { } func WithTopicReadyAndPublisherDeployed(topicID string) TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.Status.InitializeConditions() s.Status.MarkPublisherDeployed() s.Status.MarkTopicReady() @@ -148,55 +148,55 @@ func WithTopicReadyAndPublisherDeployed(topicID string) TopicOption { } func WithTopicFailed() TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.Status.InitializeConditions() s.Status.MarkNoTopic("TopicFailed", "test message") } } func WithTopicUnknown() TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.Status.InitializeConditions() } } -func WithTopicDeleted(t *v1alpha1.Topic) { +func WithTopicDeleted(t *v1beta1.Topic) { tt := metav1.NewTime(time.Unix(1e9, 0)) t.ObjectMeta.SetDeletionTimestamp(&tt) } func WithTopicOwnerReferences(ownerReferences []metav1.OwnerReference) TopicOption { - return func(c *v1alpha1.Topic) { + return func(c *v1beta1.Topic) { c.ObjectMeta.OwnerReferences = ownerReferences } } func WithTopicLabels(labels map[string]string) TopicOption { - return func(c *v1alpha1.Topic) { + return func(c *v1beta1.Topic) { c.ObjectMeta.Labels = labels } } func WithTopicNoTopic(reason, message string) TopicOption { - return func(t *v1alpha1.Topic) { + return func(t *v1beta1.Topic) { t.Status.MarkNoTopic(reason, message) } } func WithTopicFinalizers(finalizers ...string) TopicOption { - return func(s *v1alpha1.Topic) { + return func(s *v1beta1.Topic) { s.Finalizers = finalizers } } func WithTopicAnnotations(annotations map[string]string) TopicOption { - return func(c *v1alpha1.Topic) { + return func(c *v1beta1.Topic) { c.ObjectMeta.Annotations = annotations } } func WithTopicDefaultGCPAuth() TopicOption { - return func(t *v1alpha1.Topic) { + return func(t *v1beta1.Topic) { t.Spec.SetDefaults(gcpauthtesthelper.ContextWithDefaults()) } } From de78da9a85e57c2bc063eb518eba21a9f7ff48d0 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Wed, 10 Jun 2020 17:41:58 -0700 Subject: [PATCH 03/14] changed all sources to v1beta1 --- .../events/auditlogs/auditlogs_test.go | 204 ++++++++++++------ .../events/auditlogs/controller_test.go | 8 +- .../events/auditlogs/resources/names_test.go | 14 +- pkg/reconciler/events/build/build_test.go | 44 ++-- .../events/pubsub/controller_test.go | 6 +- pkg/reconciler/events/pubsub/pubsub_test.go | 50 ++--- .../events/scheduler/controller_test.go | 8 +- .../events/scheduler/resources/names_test.go | 20 +- .../events/scheduler/scheduler_test.go | 112 +++++----- .../events/storage/controller_test.go | 8 +- pkg/reconciler/identity/reconciler_test.go | 24 +-- .../pullsubscription/keda/controller.go | 14 +- .../pullsubscription/keda/controller_test.go | 4 +- .../pullsubscription/keda/pullsubscription.go | 10 +- .../keda/pullsubscription_test.go | 132 ++++++------ .../keda/resources/names_test.go | 12 +- .../keda/resources/scaled_object_test.go | 24 +-- .../pullsubscription/resources/names_test.go | 20 +- .../resources/receive_adapter_test.go | 32 +-- .../static/controller_test.go | 2 +- .../static/pullsubscription_test.go | 120 +++++------ pkg/reconciler/intevents/reconciler_test.go | 138 ++++++------ .../resources/pullsubscription_test.go | 20 +- .../intevents/resources/topic_test.go | 46 ++-- .../topic/resources/publisher_test.go | 20 +- pkg/reconciler/intevents/topic/topic_test.go | 60 +++--- .../messaging/channel/controller_test.go | 6 +- .../messaging/channel/resources/names_test.go | 8 +- .../resources/pullsubscription_test.go | 56 ++--- .../messaging/channel/resources/topic_test.go | 18 +- pkg/reconciler/testing/auditlogs.go | 60 +++--- pkg/reconciler/testing/listers.go | 12 +- pkg/reconciler/testing/pubsub.go | 44 ++-- pkg/reconciler/testing/scheduler.go | 56 ++--- pkg/reconciler/testing/storage.go | 66 +++--- test/e2e/lib/creation.go | 30 +-- test/e2e/test_pullsubscription.go | 16 +- 37 files changed, 802 insertions(+), 722 deletions(-) diff --git a/pkg/reconciler/events/auditlogs/auditlogs_test.go b/pkg/reconciler/events/auditlogs/auditlogs_test.go index 1d1ad5217b..7562118070 100644 --- a/pkg/reconciler/events/auditlogs/auditlogs_test.go +++ b/pkg/reconciler/events/auditlogs/auditlogs_test.go @@ -41,9 +41,9 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudauditlogssource" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudauditlogssource" testiam "github.com/google/knative-gcp/pkg/gclient/iam/testing" glogadmin "github.com/google/knative-gcp/pkg/gclient/logging/logadmin" glogadmintesting "github.com/google/knative-gcp/pkg/gclient/logging/logadmin/testing" @@ -85,7 +85,7 @@ var ( sinkGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Sink", } @@ -107,7 +107,7 @@ var ( func sourceOwnerRef(name string, uid types.UID) metav1.OwnerReference { return metav1.OwnerReference{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudAuditLogsSource", Name: name, UID: uid, @@ -132,7 +132,7 @@ func patchFinalizers(namespace, name string, add bool) clientgotesting.PatchActi func newSinkDestination() duckv1.Destination { return duckv1.Destination{ Ref: &duckv1.KReference{ - APIVersion: "testing.cloud.google.com/v1alpha1", + APIVersion: "testing.cloud.google.com/v1beta1", Kind: "Sink", Name: sinkName, }, @@ -159,7 +159,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceMethodName(testMethodName), WithCloudAuditLogsSourceServiceName(testServiceName), WithCloudAuditLogsSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, })), }, Key: testNS + "/" + sourceName, @@ -172,12 +172,12 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), WithCloudAuditLogsSourceTopicUnknown("TopicNotConfigured", failedToReconcileTopicMsg), WithCloudAuditLogsSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, })), }}, WantCreates: []runtime.Object{ NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -188,7 +188,7 @@ func TestAllCases(t *testing.T) { }), WithTopicOwnerReferences([]metav1.OwnerReference{sourceOwnerRef(sourceName, sourceUID)}), WithTopicAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), ), }, @@ -208,11 +208,11 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceMethodName(testMethodName), WithCloudAuditLogsSourceServiceName(testServiceName), WithCloudAuditLogsSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -229,7 +229,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceMethodName(testMethodName), WithCloudAuditLogsSourceServiceName(testServiceName), WithCloudAuditLogsSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, })), }}, WantPatches: []clientgotesting.PatchActionImpl{ @@ -249,7 +249,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -286,7 +286,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -324,7 +324,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -362,7 +362,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -397,7 +397,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -431,12 +431,12 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), WithCloudAuditLogsSourceSink(sinkGVK, sinkName), WithCloudAuditLogsSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudAuditLogsSourceDefaultGCPAuth(), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -458,7 +458,7 @@ func TestAllCases(t *testing.T) { WithInitCloudAuditLogsSourceConditions, WithCloudAuditLogsSourceTopicReady(testTopicID), WithCloudAuditLogsSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudAuditLogsSourceDefaultGCPAuth(), WithCloudAuditLogsSourcePullSubscriptionUnknown("PullSubscriptionNotConfigured", failedToReconcilePullSubscriptionMsg), @@ -466,9 +466,9 @@ func TestAllCases(t *testing.T) { }}, WantCreates: []runtime.Object{ NewPullSubscriptionWithNoDefaults(sourceName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, }, AdapterType: converters.CloudAuditLogsConverter, @@ -480,7 +480,7 @@ func TestAllCases(t *testing.T) { }), WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithPullSubscriptionOwnerReferences([]metav1.OwnerReference{sourceOwnerRef(sourceName, sourceUID)}), WithPullSubscriptionDefaultGCPAuth(), @@ -503,7 +503,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceSink(sinkGVK, sinkName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -513,9 +513,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -554,7 +554,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceSink(sinkGVK, sinkName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -564,9 +564,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionFailed(), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -585,7 +585,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceProjectID(testProject), WithInitCloudAuditLogsSourceConditions, WithCloudAuditLogsSourceTopicReady(testTopicID), - WithCloudAuditLogsSourcePullSubscriptionFailed("InvalidSink", `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1alpha1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), + WithCloudAuditLogsSourcePullSubscriptionFailed("InvalidSink", `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1beta1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), ), }}, WantPatches: []clientgotesting.PatchActionImpl{ @@ -605,7 +605,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceSink(sinkGVK, sinkName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -615,9 +615,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionUnknown(), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -656,7 +656,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceSink(sinkGVK, sinkName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -667,9 +667,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -716,7 +716,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceSink(sinkGVK, sinkName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -727,9 +727,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -776,7 +776,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceSink(sinkGVK, sinkName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -787,9 +787,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -836,7 +836,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceSink(sinkGVK, sinkName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -847,9 +847,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -897,7 +897,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), WithCloudAuditLogsSourceMethodName(testMethodName)), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -908,9 +908,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -968,7 +968,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), WithCloudAuditLogsSourceMethodName(testMethodName)), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -979,9 +979,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -1039,7 +1039,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceServiceName(testServiceName), WithCloudAuditLogsSourceMethodName(testMethodName)), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -1050,9 +1050,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -1105,7 +1105,7 @@ func TestAllCases(t *testing.T) { WithCloudAuditLogsSourceSink(sinkGVK, sinkName), ), NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -1116,9 +1116,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(sourceName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -1263,11 +1263,11 @@ func TestAllCases(t *testing.T) { }}, WantDeletes: []clientgotesting.DeleteActionImpl{ {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "topics"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "topics"}}, Name: sourceName, }, {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "pullsubscriptions"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "pullsubscriptions"}}, Name: sourceName, }, }, @@ -1318,11 +1318,11 @@ func TestAllCases(t *testing.T) { }}, WantDeletes: []clientgotesting.DeleteActionImpl{ {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "topics"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "topics"}}, Name: sourceName, }, {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "pullsubscriptions"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "pullsubscriptions"}}, Name: sourceName, }, }, @@ -1381,3 +1381,83 @@ func expectSinks(t *testing.T, clientProvider glogadmin.CreateFn, sinks map[stri } } } + + +// TODO add a unit test for successfully creating a k8s service account, after issue https://github.com/google/knative-gcp/issues/657 gets solved. +func TestDebug(t *testing.T) { + table := TableTest{ { + Name: "topic created, not yet been reconciled", + Objects: []runtime.Object{ + NewCloudAuditLogsSource(sourceName, testNS, + WithCloudAuditLogsSourceUID(sourceUID), + WithCloudAuditLogsSourceSink(sinkGVK, sinkName), + WithCloudAuditLogsSourceMethodName(testMethodName), + WithCloudAuditLogsSourceServiceName(testServiceName), + WithCloudAuditLogsSourceAnnotations(map[string]string{ + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + })), + }, + Key: testNS + "/" + sourceName, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewCloudAuditLogsSource(sourceName, testNS, + WithCloudAuditLogsSourceUID(sourceUID), + WithInitCloudAuditLogsSourceConditions, + WithCloudAuditLogsSourceSink(sinkGVK, sinkName), + WithCloudAuditLogsSourceMethodName(testMethodName), + WithCloudAuditLogsSourceServiceName(testServiceName), + WithCloudAuditLogsSourceTopicUnknown("TopicNotConfigured", failedToReconcileTopicMsg), + WithCloudAuditLogsSourceAnnotations(map[string]string{ + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + })), + }}, + WantCreates: []runtime.Object{ + NewTopic(sourceName, testNS, + WithTopicSpec(inteventsv1beta1.TopicSpec{ + Topic: testTopicID, + PropagationPolicy: "CreateDelete", + EnablePublisher: &falseVal, + }), + WithTopicLabels(map[string]string{ + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": sourceName, + }), + WithTopicOwnerReferences([]metav1.OwnerReference{sourceOwnerRef(sourceName, sourceUID)}), + WithTopicAnnotations(map[string]string{ + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + }), + ), + }, + WantPatches: []clientgotesting.PatchActionImpl{ + patchFinalizers(testNS, sourceName, true), + }, + WantEvents: []string{ + Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", sourceName), + Eventf(corev1.EventTypeWarning, reconciledPubSubFailedReason, "Reconcile PubSub failed with: Topic %q has not yet been reconciled", sourceName), + }, + }} + + defer logtesting.ClearAll() + for _, tt := range table { + t.Run(tt.Name, func(t *testing.T) { + logadminClientProvider := glogadmintesting.TestClientCreator(tt.OtherTestData["logadmin"]) + if existingSinks := tt.OtherTestData["existingSinks"]; existingSinks != nil { + createSinks(t, logadminClientProvider, existingSinks.([]logadmin.Sink)) + } + tt.Test(t, MakeFactory( + func(ctx context.Context, listers *Listers, cmw configmap.Watcher, testData map[string]interface{}) controller.Reconciler { + r := &Reconciler{ + PubSubBase: intevents.NewPubSubBaseWithAdapter(ctx, controllerAgentName, receiveAdapterName, converters.CloudAuditLogsConverter, cmw), + Identity: identity.NewIdentity(ctx, NoopIAMPolicyManager, NewGCPAuthTestStore(t, nil)), + auditLogsSourceLister: listers.GetCloudAuditLogsSourceLister(), + logadminClientProvider: logadminClientProvider, + pubsubClientProvider: gpubsub.TestClientCreator(testData["pubsub"]), + serviceAccountLister: listers.GetServiceAccountLister(), + } + return cloudauditlogssource.NewReconciler(ctx, r.Logger, r.RunClientSet, listers.GetCloudAuditLogsSourceLister(), r.Recorder, r) + })) + if expectedSinks := tt.OtherTestData["expectedSinks"]; expectedSinks != nil { + expectSinks(t, logadminClientProvider, expectedSinks.(map[string]*logadmin.Sink)) + } + }) + } +} \ No newline at end of file diff --git a/pkg/reconciler/events/auditlogs/controller_test.go b/pkg/reconciler/events/auditlogs/controller_test.go index 984da3fcc1..86a5f2f072 100644 --- a/pkg/reconciler/events/auditlogs/controller_test.go +++ b/pkg/reconciler/events/auditlogs/controller_test.go @@ -25,11 +25,11 @@ import ( . "knative.dev/pkg/reconciler/testing" // Fake injection informers - _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake" + _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1beta1/fake" _ "github.com/google/knative-gcp/pkg/client/injection/client/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudauditlogssource/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudauditlogssource/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic/fake" _ "github.com/google/knative-gcp/pkg/reconciler/testing" _ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/fake" ) diff --git a/pkg/reconciler/events/auditlogs/resources/names_test.go b/pkg/reconciler/events/auditlogs/resources/names_test.go index cb6b416eb8..2688bd9b52 100644 --- a/pkg/reconciler/events/auditlogs/resources/names_test.go +++ b/pkg/reconciler/events/auditlogs/resources/names_test.go @@ -20,14 +20,14 @@ import ( "testing" "github.com/google/go-cmp/cmp" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestGenerateTopicName(t *testing.T) { want := "cre-src_mynamespace_myname_uid" - got := GenerateTopicName(&v1alpha1.CloudAuditLogsSource{ + got := GenerateTopicName(&v1beta1.CloudAuditLogsSource{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -42,9 +42,9 @@ func TestGenerateTopicName(t *testing.T) { func TestGenerateTopicResourceName(t *testing.T) { want := "pubsub.googleapis.com/projects/project/topics/topic" - got := GenerateTopicResourceName(&v1alpha1.CloudAuditLogsSource{ - Status: v1alpha1.CloudAuditLogsSourceStatus{ - PubSubStatus: duckv1alpha1.PubSubStatus{ + got := GenerateTopicResourceName(&v1beta1.CloudAuditLogsSource{ + Status: v1beta1.CloudAuditLogsSourceStatus{ + PubSubStatus: duckv1beta1.PubSubStatus{ ProjectID: "project", TopicID: "topic", }, @@ -58,7 +58,7 @@ func TestGenerateTopicResourceName(t *testing.T) { func TestGenerateSinkName(t *testing.T) { want := "cre-src_mynamespace_myname_uid" - got := GenerateSinkName(&v1alpha1.CloudAuditLogsSource{ + got := GenerateSinkName(&v1beta1.CloudAuditLogsSource{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", diff --git a/pkg/reconciler/events/build/build_test.go b/pkg/reconciler/events/build/build_test.go index 3ea359ed1b..84487bcc59 100644 --- a/pkg/reconciler/events/build/build_test.go +++ b/pkg/reconciler/events/build/build_test.go @@ -38,10 +38,10 @@ import ( . "knative.dev/pkg/reconciler/testing" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudbuildsource" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudbuildsource" testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/intevents" @@ -54,7 +54,7 @@ const ( sinkName = "sink" testNS = "testnamespace" - testTopicID = v1alpha1.DefaultTopic + testTopicID = v1beta1.DefaultTopic generation = 1 failedToPropagatePullSubscriptionStatusMsg = `Failed to propagate PullSubscription status` ) @@ -68,7 +68,7 @@ var ( sinkGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Sink", } @@ -84,13 +84,13 @@ var ( func init() { // Add types to scheme - _ = v1alpha1.AddToScheme(scheme.Scheme) + _ = v1beta1.AddToScheme(scheme.Scheme) } // Returns an ownerref for the test CloudBuildSource object func ownerRef() metav1.OwnerReference { return metav1.OwnerReference{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudBuildSource", Name: buildName, UID: buildUID, @@ -115,7 +115,7 @@ func patchFinalizers(namespace, name string, add bool) clientgotesting.PatchActi func newSink() *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "testing.cloud.google.com/v1alpha1", + "apiVersion": "testing.cloud.google.com/v1beta1", "kind": "Sink", "metadata": map[string]interface{}{ "namespace": testNS, @@ -133,7 +133,7 @@ func newSink() *unstructured.Unstructured { func newSinkDestination() duckv1.Destination { return duckv1.Destination{ Ref: &duckv1.KReference{ - APIVersion: "testing.cloud.google.com/v1alpha1", + APIVersion: "testing.cloud.google.com/v1beta1", Kind: "Sink", Namespace: testNS, Name: sinkName, @@ -164,7 +164,7 @@ func TestAllCases(t *testing.T) { WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), WithCloudBuildSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudBuildSourceDefaultGCPAuth(), ), @@ -180,7 +180,7 @@ func TestAllCases(t *testing.T) { WithInitCloudBuildSourceConditions, WithCloudBuildSourceObjectMetaGeneration(generation), WithCloudBuildSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudBuildSourceDefaultGCPAuth(), WithCloudBuildSourcePullSubscriptionUnknown("PullSubscriptionNotConfigured", "PullSubscription has not yet been reconciled"), @@ -188,9 +188,9 @@ func TestAllCases(t *testing.T) { }}, WantCreates: []runtime.Object{ NewPullSubscriptionWithNoDefaults(buildName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -204,7 +204,7 @@ func TestAllCases(t *testing.T) { }), WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithPullSubscriptionOwnerReferences([]metav1.OwnerReference{ownerRef()}), WithPullSubscriptionDefaultGCPAuth(), @@ -226,9 +226,9 @@ func TestAllCases(t *testing.T) { WithCloudBuildSourceSink(sinkGVK, sinkName), ), NewPullSubscriptionWithNoDefaults(buildName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -266,9 +266,9 @@ func TestAllCases(t *testing.T) { WithCloudBuildSourceSink(sinkGVK, sinkName), ), NewPullSubscriptionWithNoDefaults(buildName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -306,9 +306,9 @@ func TestAllCases(t *testing.T) { WithCloudBuildSourceSink(sinkGVK, sinkName), ), NewPullSubscriptionWithNoDefaults(buildName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -327,7 +327,7 @@ func TestAllCases(t *testing.T) { return false, nil, nil } attempts++ - return true, nil, apierrs.NewConflict(v1alpha1.Resource("foo"), "bar", errors.New("foo")) + return true, nil, apierrs.NewConflict(v1beta1.Resource("foo"), "bar", errors.New("foo")) }, }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ diff --git a/pkg/reconciler/events/pubsub/controller_test.go b/pkg/reconciler/events/pubsub/controller_test.go index e0e8d71f3c..55de53662c 100644 --- a/pkg/reconciler/events/pubsub/controller_test.go +++ b/pkg/reconciler/events/pubsub/controller_test.go @@ -25,10 +25,10 @@ import ( . "knative.dev/pkg/reconciler/testing" // Fake injection informers - _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake" + _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1beta1/fake" _ "github.com/google/knative-gcp/pkg/client/injection/client/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudpubsubsource/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudpubsubsource/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription/fake" _ "github.com/google/knative-gcp/pkg/reconciler/testing" _ "knative.dev/pkg/client/injection/kube/informers/batch/v1/job/fake" _ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/fake" diff --git a/pkg/reconciler/events/pubsub/pubsub_test.go b/pkg/reconciler/events/pubsub/pubsub_test.go index da95138bab..b21929cef6 100644 --- a/pkg/reconciler/events/pubsub/pubsub_test.go +++ b/pkg/reconciler/events/pubsub/pubsub_test.go @@ -38,10 +38,10 @@ import ( . "knative.dev/pkg/reconciler/testing" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudpubsubsource" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudpubsubsource" testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" "github.com/google/knative-gcp/pkg/reconciler/identity" "github.com/google/knative-gcp/pkg/reconciler/intevents" @@ -68,7 +68,7 @@ var ( sinkGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Sink", } @@ -84,13 +84,13 @@ var ( func init() { // Add types to scheme - _ = v1alpha1.AddToScheme(scheme.Scheme) + _ = v1beta1.AddToScheme(scheme.Scheme) } // Returns an ownerref for the test CloudPubSubSource object func ownerRef() metav1.OwnerReference { return metav1.OwnerReference{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudPubSubSource", Name: pubsubName, UID: pubsubUID, @@ -115,7 +115,7 @@ func patchFinalizers(namespace, name string, add bool) clientgotesting.PatchActi func newSink() *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "testing.cloud.google.com/v1alpha1", + "apiVersion": "testing.cloud.google.com/v1beta1", "kind": "Sink", "metadata": map[string]interface{}{ "namespace": testNS, @@ -133,7 +133,7 @@ func newSink() *unstructured.Unstructured { func newSinkDestination() duckv1.Destination { return duckv1.Destination{ Ref: &duckv1.KReference{ - APIVersion: "testing.cloud.google.com/v1alpha1", + APIVersion: "testing.cloud.google.com/v1beta1", Kind: "Sink", Namespace: testNS, Name: sinkName, @@ -162,7 +162,7 @@ func TestAllCases(t *testing.T) { WithCloudPubSubSourceTopic(testTopicID), WithCloudPubSubSourceSink(sinkGVK, sinkName), WithCloudPubSubSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudPubSubSourceDefaultGCPAuth(), ), @@ -178,7 +178,7 @@ func TestAllCases(t *testing.T) { WithInitCloudPubSubSourceConditions, WithCloudPubSubSourceObjectMetaGeneration(generation), WithCloudPubSubSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudPubSubSourceDefaultGCPAuth(), WithCloudPubSubSourcePullSubscriptionUnknown("PullSubscriptionNotConfigured", "PullSubscription has not yet been reconciled"), @@ -186,21 +186,21 @@ func TestAllCases(t *testing.T) { }}, WantCreates: []runtime.Object{ NewPullSubscriptionWithNoDefaults(pubsubName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, }, }), WithPullSubscriptionSink(sinkGVK, sinkName), - WithPullSubscriptionMode(inteventsv1alpha1.ModePushCompatible), + WithPullSubscriptionMode(inteventsv1beta1.ModePushCompatible), WithPullSubscriptionLabels(map[string]string{ "receive-adapter": receiveAdapterName, "events.cloud.google.com/source-name": pubsubName, }), WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithPullSubscriptionOwnerReferences([]metav1.OwnerReference{ownerRef()}), WithPullSubscriptionDefaultGCPAuth(), @@ -222,15 +222,15 @@ func TestAllCases(t *testing.T) { WithCloudPubSubSourceSink(sinkGVK, sinkName), ), NewPullSubscriptionWithNoDefaults(pubsubName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), }, }, - Mode: inteventsv1alpha1.ModePushCompatible, + Mode: inteventsv1beta1.ModePushCompatible, }), WithPullSubscriptionReadyStatus(corev1.ConditionFalse, "PullSubscriptionFalse", "status false test message")), newSink(), @@ -263,15 +263,15 @@ func TestAllCases(t *testing.T) { WithCloudPubSubSourceSink(sinkGVK, sinkName), ), NewPullSubscriptionWithNoDefaults(pubsubName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), }, }, - Mode: inteventsv1alpha1.ModePushCompatible, + Mode: inteventsv1beta1.ModePushCompatible, }), WithPullSubscriptionReadyStatus(corev1.ConditionUnknown, "PullSubscriptionUnknown", "status unknown test message")), newSink(), @@ -304,15 +304,15 @@ func TestAllCases(t *testing.T) { WithCloudPubSubSourceSink(sinkGVK, sinkName), ), NewPullSubscriptionWithNoDefaults(pubsubName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), }, }, - Mode: inteventsv1alpha1.ModePushCompatible, + Mode: inteventsv1beta1.ModePushCompatible, }), WithPullSubscriptionReady(sinkURI), WithPullSubscriptionReadyStatus(corev1.ConditionTrue, "PullSubscriptionNoReady", ""), @@ -326,7 +326,7 @@ func TestAllCases(t *testing.T) { return false, nil, nil } attempts++ - return true, nil, apierrs.NewConflict(v1alpha1.Resource("foo"), "bar", errors.New("foo")) + return true, nil, apierrs.NewConflict(v1beta1.Resource("foo"), "bar", errors.New("foo")) }, }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ diff --git a/pkg/reconciler/events/scheduler/controller_test.go b/pkg/reconciler/events/scheduler/controller_test.go index 4141209dbe..a9f7dc9361 100644 --- a/pkg/reconciler/events/scheduler/controller_test.go +++ b/pkg/reconciler/events/scheduler/controller_test.go @@ -29,11 +29,11 @@ import ( _ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/fake" // Fake injection informers - _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake" + _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1beta1/fake" _ "github.com/google/knative-gcp/pkg/client/injection/client/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudschedulersource/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudschedulersource/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic/fake" _ "github.com/google/knative-gcp/pkg/reconciler/testing" ) diff --git a/pkg/reconciler/events/scheduler/resources/names_test.go b/pkg/reconciler/events/scheduler/resources/names_test.go index 9bfdac7ff8..ebd8521415 100644 --- a/pkg/reconciler/events/scheduler/resources/names_test.go +++ b/pkg/reconciler/events/scheduler/resources/names_test.go @@ -20,22 +20,22 @@ import ( "testing" "github.com/google/go-cmp/cmp" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestGenerateJobName(t *testing.T) { want := "projects/project/locations/location/" + JobPrefix + "-uid" - got := GenerateJobName(&v1alpha1.CloudSchedulerSource{ + got := GenerateJobName(&v1beta1.CloudSchedulerSource{ ObjectMeta: metav1.ObjectMeta{ UID: "uid", }, - Spec: v1alpha1.CloudSchedulerSourceSpec{ + Spec: v1beta1.CloudSchedulerSourceSpec{ Location: "location", }, - Status: v1alpha1.CloudSchedulerSourceStatus{ - PubSubStatus: duckv1alpha1.PubSubStatus{ + Status: v1beta1.CloudSchedulerSourceStatus{ + PubSubStatus: duckv1beta1.PubSubStatus{ ProjectID: "project", }, }, @@ -64,7 +64,7 @@ func TestExtractJobId(t *testing.T) { func TestGenerateTopicName(t *testing.T) { want := "cre-src_mynamespace_myname_uid" - got := GenerateTopicName(&v1alpha1.CloudSchedulerSource{ + got := GenerateTopicName(&v1beta1.CloudSchedulerSource{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -79,9 +79,9 @@ func TestGenerateTopicName(t *testing.T) { func TestGeneratePubSubTargetTopic(t *testing.T) { want := "projects/project/topics/topic" - got := GeneratePubSubTargetTopic(&v1alpha1.CloudSchedulerSource{ - Status: v1alpha1.CloudSchedulerSourceStatus{ - PubSubStatus: duckv1alpha1.PubSubStatus{ + got := GeneratePubSubTargetTopic(&v1beta1.CloudSchedulerSource{ + Status: v1beta1.CloudSchedulerSourceStatus{ + PubSubStatus: duckv1beta1.PubSubStatus{ ProjectID: "project", }, }, diff --git a/pkg/reconciler/events/scheduler/scheduler_test.go b/pkg/reconciler/events/scheduler/scheduler_test.go index 992533744a..6569f50b66 100644 --- a/pkg/reconciler/events/scheduler/scheduler_test.go +++ b/pkg/reconciler/events/scheduler/scheduler_test.go @@ -39,11 +39,11 @@ import ( gstatus "google.golang.org/grpc/status" . "knative.dev/pkg/reconciler/testing" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - schedulerv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + schedulerv1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" . "github.com/google/knative-gcp/pkg/apis/intevents" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1alpha1/cloudschedulersource" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/reconciler/events/v1beta1/cloudschedulersource" testingMetadataClient "github.com/google/knative-gcp/pkg/gclient/metadata/testing" gscheduler "github.com/google/knative-gcp/pkg/gclient/scheduler/testing" "github.com/google/knative-gcp/pkg/reconciler/identity" @@ -86,7 +86,7 @@ var ( sinkGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Sink", } @@ -102,13 +102,13 @@ var ( func init() { // Add types to scheme - _ = schedulerv1alpha1.AddToScheme(scheme.Scheme) + _ = schedulerv1beta1.AddToScheme(scheme.Scheme) } // Returns an ownerref for the test CloudSchedulerSource object func ownerRef() metav1.OwnerReference { return metav1.OwnerReference{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudSchedulerSource", Name: "my-test-scheduler", UID: schedulerUID, @@ -133,7 +133,7 @@ func patchFinalizers(namespace, name string, add bool) clientgotesting.PatchActi func newSink() *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "testing.cloud.google.com/v1alpha1", + "apiVersion": "testing.cloud.google.com/v1beta1", "kind": "Sink", "metadata": map[string]interface{}{ "namespace": testNS, @@ -151,7 +151,7 @@ func newSink() *unstructured.Unstructured { func newSinkDestination() duckv1.Destination { return duckv1.Destination{ Ref: &duckv1.KReference{ - APIVersion: "testing.cloud.google.com/v1alpha1", + APIVersion: "testing.cloud.google.com/v1beta1", Kind: "Sink", Name: sinkName, }, @@ -179,7 +179,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceData(testData), WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), WithCloudSchedulerSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), ), newSink(), @@ -193,14 +193,14 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), WithInitCloudSchedulerSourceConditions, WithCloudSchedulerSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudSchedulerSourceTopicUnknown("TopicNotConfigured", failedToReconcileTopicMsg), ), }}, WantCreates: []runtime.Object{ NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -210,7 +210,7 @@ func TestAllCases(t *testing.T) { SourceLabelKey: schedulerName, }), WithTopicAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -232,7 +232,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -268,7 +268,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -306,7 +306,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -345,7 +345,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -384,7 +384,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -422,7 +422,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -460,12 +460,12 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceData(testData), WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), WithCloudSchedulerSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudSchedulerSourceDefaultGCPAuth(), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -487,7 +487,7 @@ func TestAllCases(t *testing.T) { WithInitCloudSchedulerSourceConditions, WithCloudSchedulerSourceTopicReady(testTopicID, testProject), WithCloudSchedulerSourceAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithCloudSchedulerSourceDefaultGCPAuth(), WithCloudSchedulerSourcePullSubscriptionUnknown("PullSubscriptionNotConfigured", failedToReconcilePullSubscriptionMsg), @@ -495,9 +495,9 @@ func TestAllCases(t *testing.T) { }}, WantCreates: []runtime.Object{ NewPullSubscriptionWithNoDefaults(schedulerName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, }, }), @@ -507,7 +507,7 @@ func TestAllCases(t *testing.T) { SourceLabelKey: schedulerName}), WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }), WithPullSubscriptionOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -529,7 +529,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -539,9 +539,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(schedulerName, testNS, - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -579,7 +579,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -589,9 +589,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(schedulerName, testNS, WithPullSubscriptionFailed(), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -609,7 +609,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), WithInitCloudSchedulerSourceConditions, WithCloudSchedulerSourceTopicReady(testTopicID, testProject), - WithCloudSchedulerSourcePullSubscriptionFailed("InvalidSink", `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1alpha1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), + WithCloudSchedulerSourcePullSubscriptionFailed("InvalidSink", `failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1beta1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), ), }}, WantPatches: []clientgotesting.PatchActionImpl{ @@ -629,7 +629,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -639,9 +639,9 @@ func TestAllCases(t *testing.T) { WithTopicProjectID(testProject), ), NewPullSubscriptionWithNoDefaults(schedulerName, testNS, WithPullSubscriptionUnknown(), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -680,7 +680,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -692,9 +692,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(schedulerName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -743,7 +743,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -755,9 +755,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(schedulerName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -806,7 +806,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -818,9 +818,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(schedulerName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -869,7 +869,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -881,9 +881,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(schedulerName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -933,7 +933,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -945,9 +945,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(schedulerName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -996,7 +996,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceSchedule(onceAMinuteSchedule), ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", Project: testProject, @@ -1008,9 +1008,9 @@ func TestAllCases(t *testing.T) { ), NewPullSubscriptionWithNoDefaults(schedulerName, testNS, WithPullSubscriptionReady(sinkURI), - WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: newSinkDestination(), @@ -1061,7 +1061,7 @@ func TestAllCases(t *testing.T) { WithCloudSchedulerSourceDeletionTimestamp, ), NewTopic(schedulerName, testNS, - WithTopicSpec(inteventsv1alpha1.TopicSpec{ + WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -1164,11 +1164,11 @@ func TestAllCases(t *testing.T) { }}, WantDeletes: []clientgotesting.DeleteActionImpl{ {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "topics"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "topics"}}, Name: schedulerName, }, {ActionImpl: clientgotesting.ActionImpl{ - Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "pullsubscriptions"}}, + Namespace: testNS, Verb: "delete", Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "pullsubscriptions"}}, Name: schedulerName, }, }, diff --git a/pkg/reconciler/events/storage/controller_test.go b/pkg/reconciler/events/storage/controller_test.go index 607ccd4074..aac5c6c3b6 100644 --- a/pkg/reconciler/events/storage/controller_test.go +++ b/pkg/reconciler/events/storage/controller_test.go @@ -29,11 +29,11 @@ import ( _ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/fake" // Fake injection informers - _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake" + _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1beta1/fake" _ "github.com/google/knative-gcp/pkg/client/injection/client/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudstoragesource/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudstoragesource/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic/fake" _ "github.com/google/knative-gcp/pkg/reconciler/testing" ) diff --git a/pkg/reconciler/identity/reconciler_test.go b/pkg/reconciler/identity/reconciler_test.go index bd81cbe0b9..f6501c799d 100644 --- a/pkg/reconciler/identity/reconciler_test.go +++ b/pkg/reconciler/identity/reconciler_test.go @@ -43,8 +43,8 @@ import ( "github.com/google/go-cmp/cmp" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" "github.com/google/knative-gcp/pkg/reconciler/identity/iam" . "github.com/google/knative-gcp/pkg/reconciler/testing" ) @@ -91,7 +91,7 @@ func TestKSACreates(t *testing.T) { }, expectedServiceAccount: NewServiceAccount(kServiceAccountName, testNS, gServiceAccountName, WithServiceAccountOwnerReferences([]metav1.OwnerReference{{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudPubSubSource", UID: "test-pubsub-uid", Name: identifiableName, @@ -108,7 +108,7 @@ func TestKSACreates(t *testing.T) { config: ConfigMapFromTestFile(t, "config-gcp-auth", "default-auth-config"), expectedServiceAccount: NewServiceAccount(kServiceAccountName, testNS, gServiceAccountName, WithServiceAccountOwnerReferences([]metav1.OwnerReference{{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudPubSubSource", UID: "test-pubsub-uid", Name: identifiableName, @@ -141,7 +141,7 @@ func TestKSACreates(t *testing.T) { identifiable := NewCloudPubSubSource(identifiableName, testNS) identifiable.Spec.ServiceAccountName = kServiceAccountName identifiable.SetAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }) arl := pkgtesting.ActionRecorderList{cs} @@ -200,7 +200,7 @@ func TestKSADeletes(t *testing.T) { objects: []runtime.Object{ NewServiceAccount(kServiceAccountName, testNS, gServiceAccountName, WithServiceAccountOwnerReferences([]metav1.OwnerReference{{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudPubSubSource", UID: "test-pubsub-uid", Name: identifiableName, @@ -216,14 +216,14 @@ func TestKSADeletes(t *testing.T) { objects: []runtime.Object{ NewServiceAccount(kServiceAccountName, testNS, gServiceAccountName, WithServiceAccountOwnerReferences([]metav1.OwnerReference{{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudPubSubSource", UID: "test-pubsub-uid1", Name: identifiableName, Controller: &falseVal, BlockOwnerDeletion: &trueVal, }, { - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudPubSubSource", UID: "test-pubsub-uid2", Name: identifiableName + "new", @@ -257,7 +257,7 @@ func TestKSADeletes(t *testing.T) { WithCloudPubSubSourceServiceAccountName(kServiceAccountName)) identifiable.Spec.ServiceAccountName = kServiceAccountName identifiable.SetAnnotations(map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, }) arl := pkgtesting.ActionRecorderList{cs} @@ -303,14 +303,14 @@ func TestKSADeletes(t *testing.T) { func TestOwnerReferenceExists(t *testing.T) { t.Parallel() - source := &v1alpha1.CloudSchedulerSource{ + source := &v1beta1.CloudSchedulerSource{ ObjectMeta: metav1.ObjectMeta{ Name: "scheduler-name", Namespace: "scheduler-namespace", UID: "scheduler-uid", }, - Spec: v1alpha1.CloudSchedulerSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + Spec: v1beta1.CloudSchedulerSourceSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Project: "project-123", Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ diff --git a/pkg/reconciler/intevents/pullsubscription/keda/controller.go b/pkg/reconciler/intevents/pullsubscription/keda/controller.go index 6cfc118605..76644b1f37 100644 --- a/pkg/reconciler/intevents/pullsubscription/keda/controller.go +++ b/pkg/reconciler/intevents/pullsubscription/keda/controller.go @@ -26,11 +26,11 @@ import ( "k8s.io/client-go/tools/cache" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/ducks/duck/v1alpha1/resource" - pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription" - pullsubscriptionreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1alpha1/pullsubscription" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/ducks/duck/v1beta1/resource" + pullsubscriptioninformers "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription" + pullsubscriptionreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1beta1/pullsubscription" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/identity" @@ -113,7 +113,7 @@ func newController( impl := pullsubscriptionreconciler.NewImpl(ctx, r) pubsubBase.Logger.Info("Setting up event handlers") - onlyKedaScaler := pkgreconciler.AnnotationFilterFunc(duckv1alpha1.AutoscalingClassAnnotation, duckv1alpha1.KEDA, false) + onlyKedaScaler := pkgreconciler.AnnotationFilterFunc(duckv1beta1.AutoscalingClassAnnotation, duckv1beta1.KEDA, false) pullSubscriptionHandler := cache.FilteringResourceEventHandler{ FilterFunc: onlyKedaScaler, @@ -127,7 +127,7 @@ func newController( }) serviceAccountInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind("Pullsubscription")), + FilterFunc: controller.FilterGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("Pullsubscription")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/intevents/pullsubscription/keda/controller_test.go b/pkg/reconciler/intevents/pullsubscription/keda/controller_test.go index f7a8e2ed67..d04dd6fab5 100644 --- a/pkg/reconciler/intevents/pullsubscription/keda/controller_test.go +++ b/pkg/reconciler/intevents/pullsubscription/keda/controller_test.go @@ -35,8 +35,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // Fake injection informers and clients - _ "github.com/google/knative-gcp/pkg/client/injection/ducks/duck/v1alpha1/resource/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/ducks/duck/v1beta1/resource/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription/fake" _ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake" _ "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment/fake" _ "knative.dev/pkg/client/injection/kube/informers/batch/v1/job/fake" diff --git a/pkg/reconciler/intevents/pullsubscription/keda/pullsubscription.go b/pkg/reconciler/intevents/pullsubscription/keda/pullsubscription.go index 4ec9a81906..013c792db1 100644 --- a/pkg/reconciler/intevents/pullsubscription/keda/pullsubscription.go +++ b/pkg/reconciler/intevents/pullsubscription/keda/pullsubscription.go @@ -21,8 +21,8 @@ import ( "fmt" "strings" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - pullsubscriptionreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1alpha1/pullsubscription" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + pullsubscriptionreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1beta1/pullsubscription" psreconciler "github.com/google/knative-gcp/pkg/reconciler/intevents/pullsubscription" "github.com/google/knative-gcp/pkg/reconciler/intevents/pullsubscription/keda/resources" "go.uber.org/zap" @@ -56,12 +56,12 @@ type Reconciler struct { // Check that our Reconciler implements Interface. var _ pullsubscriptionreconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, ps *v1alpha1.PullSubscription) reconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, ps *v1beta1.PullSubscription) reconciler.Event { return r.Base.ReconcileKind(ctx, ps) } // TODO upstream to pkg -func (r *Reconciler) ReconcileScaledObject(ctx context.Context, ra *appsv1.Deployment, src *v1alpha1.PullSubscription) error { +func (r *Reconciler) ReconcileScaledObject(ctx context.Context, ra *appsv1.Deployment, src *v1beta1.PullSubscription) error { // Check whether KEDA is installed, if not, error out. // Ideally this should be done in the webhook, thus not even allowing the creation of the object. if err := r.discoveryFn(r.KubeClientSet.Discovery(), resources.KedaSchemeGroupVersion); err != nil { @@ -133,6 +133,6 @@ func (r *Reconciler) ReconcileScaledObject(ctx context.Context, ra *appsv1.Deplo return nil } -func (r *Reconciler) FinalizeKind(ctx context.Context, ps *v1alpha1.PullSubscription) reconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, ps *v1beta1.PullSubscription) reconciler.Event { return r.Base.FinalizeKind(ctx, ps) } diff --git a/pkg/reconciler/intevents/pullsubscription/keda/pullsubscription_test.go b/pkg/reconciler/intevents/pullsubscription/keda/pullsubscription_test.go index 6d1bd28b80..0a79b428f0 100644 --- a/pkg/reconciler/intevents/pullsubscription/keda/pullsubscription_test.go +++ b/pkg/reconciler/intevents/pullsubscription/keda/pullsubscription_test.go @@ -23,7 +23,7 @@ import ( "strings" "testing" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" "k8s.io/api/apps/v1" "knative.dev/pkg/apis" @@ -46,9 +46,9 @@ import ( . "knative.dev/pkg/reconciler/testing" "knative.dev/pkg/resolver" - pubsubv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/ducks/duck/v1alpha1/resource" - "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1alpha1/pullsubscription" + pubsubv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/ducks/duck/v1beta1/resource" + "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1beta1/pullsubscription" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub/testing" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/intevents" @@ -91,13 +91,13 @@ var ( sinkGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Sink", } transformerGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Transformer", } @@ -111,7 +111,7 @@ var ( func init() { // Add types to scheme - _ = pubsubv1alpha1.AddToScheme(scheme.Scheme) + _ = pubsubv1beta1.AddToScheme(scheme.Scheme) } func newSecret() *corev1.Secret { @@ -126,14 +126,14 @@ func newSecret() *corev1.Secret { } } -func newPullSubscription(subscriptionId string) *pubsubv1alpha1.PullSubscription { +func newPullSubscription(subscriptionId string) *pubsubv1beta1.PullSubscription { return NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -148,7 +148,7 @@ func newPullSubscription(subscriptionId string) *pubsubv1alpha1.PullSubscription func newSink() *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "testing.cloud.google.com/v1alpha1", + "apiVersion": "testing.cloud.google.com/v1beta1", "kind": "Sink", "metadata": map[string]interface{}{ "namespace": testNS, @@ -165,19 +165,19 @@ func newSink() *unstructured.Unstructured { func newAnnotations() map[string]string { return map[string]string{ - v1alpha1.AutoscalingClassAnnotation: v1alpha1.KEDA, - v1alpha1.AutoscalingMinScaleAnnotation: "0", - v1alpha1.AutoscalingMaxScaleAnnotation: "3", - v1alpha1.KedaAutoscalingSubscriptionSizeAnnotation: "5", - v1alpha1.KedaAutoscalingCooldownPeriodAnnotation: "60", - v1alpha1.KedaAutoscalingPollingIntervalAnnotation: "30", + v1beta1.AutoscalingClassAnnotation: v1beta1.KEDA, + v1beta1.AutoscalingMinScaleAnnotation: "0", + v1beta1.AutoscalingMaxScaleAnnotation: "3", + v1beta1.KedaAutoscalingSubscriptionSizeAnnotation: "5", + v1beta1.KedaAutoscalingCooldownPeriodAnnotation: "60", + v1beta1.KedaAutoscalingPollingIntervalAnnotation: "30", } } func newTransformer() *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "testing.cloud.google.com/v1alpha1", + "apiVersion": "testing.cloud.google.com/v1beta1", "kind": "Transformer", "metadata": map[string]interface{}{ "namespace": testNS, @@ -207,8 +207,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -222,7 +222,7 @@ func TestAllCases(t *testing.T) { WantEvents: []string{ Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", sourceName), Eventf(corev1.EventTypeWarning, "InvalidSink", - `InvalidSink: failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1alpha1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), + `InvalidSink: failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1beta1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), }, WantPatches: []clientgotesting.PatchActionImpl{ patchFinalizers(testNS, sourceName, resourceGroup), @@ -231,8 +231,8 @@ func TestAllCases(t *testing.T) { Object: NewPullSubscription(sourceName, testNS, WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -252,8 +252,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -282,8 +282,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -307,8 +307,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -339,8 +339,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -364,8 +364,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -396,8 +396,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -421,8 +421,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -453,8 +453,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -478,8 +478,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -511,8 +511,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -557,8 +557,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -586,8 +586,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -619,8 +619,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -647,8 +647,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -690,8 +690,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -718,8 +718,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -756,8 +756,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(newAnnotations()), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -821,15 +821,15 @@ func newReceiveAdapter(ctx context.Context, image string, transformer *apis.URL) ps := NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionAnnotations(map[string]string{ - v1alpha1.AutoscalingClassAnnotation: v1alpha1.KEDA, - v1alpha1.AutoscalingMinScaleAnnotation: "0", - v1alpha1.AutoscalingMaxScaleAnnotation: "3", - v1alpha1.KedaAutoscalingSubscriptionSizeAnnotation: "5", - v1alpha1.KedaAutoscalingCooldownPeriodAnnotation: "60", - v1alpha1.KedaAutoscalingPollingIntervalAnnotation: "30", + v1beta1.AutoscalingClassAnnotation: v1beta1.KEDA, + v1beta1.AutoscalingMinScaleAnnotation: "0", + v1beta1.AutoscalingMaxScaleAnnotation: "3", + v1beta1.KedaAutoscalingSubscriptionSizeAnnotation: "5", + v1beta1.KedaAutoscalingCooldownPeriodAnnotation: "60", + v1beta1.KedaAutoscalingPollingIntervalAnnotation: "30", }), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: v1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -846,7 +846,7 @@ func newReceiveAdapter(ctx context.Context, image string, transformer *apis.URL) return resources.MakeReceiveAdapter(ctx, args) } -func newScaledObject(ps *pubsubv1alpha1.PullSubscription) runtime.Object { +func newScaledObject(ps *pubsubv1beta1.PullSubscription) runtime.Object { ctx := context.Background() ra := newReceiveAdapter(ctx, testImage, nil) d, _ := ra.(*v1.Deployment) diff --git a/pkg/reconciler/intevents/pullsubscription/keda/resources/names_test.go b/pkg/reconciler/intevents/pullsubscription/keda/resources/names_test.go index 70ab5e433e..2ef14a7a62 100644 --- a/pkg/reconciler/intevents/pullsubscription/keda/resources/names_test.go +++ b/pkg/reconciler/intevents/pullsubscription/keda/resources/names_test.go @@ -21,18 +21,18 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/knative-gcp/pkg/apis/intevents" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestGenerateScaledObjectName(t *testing.T) { tests := []struct { name string - ps *v1alpha1.PullSubscription + ps *v1beta1.PullSubscription want string }{{ name: "ps-based name", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -42,7 +42,7 @@ func TestGenerateScaledObjectName(t *testing.T) { want: "cre-ps-myname-uid", }, { name: "source-based name", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -55,7 +55,7 @@ func TestGenerateScaledObjectName(t *testing.T) { want: "cre-src-myname-uid", }, { name: "channel-based name", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -68,7 +68,7 @@ func TestGenerateScaledObjectName(t *testing.T) { want: "cre-chan-myname-uid", }, { name: "name too long, hashed and shortened", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "mynameistoooooolongggggggggggggggggggggggggggggggggg", Namespace: "mynamespace", diff --git a/pkg/reconciler/intevents/pullsubscription/keda/resources/scaled_object_test.go b/pkg/reconciler/intevents/pullsubscription/keda/resources/scaled_object_test.go index 927cb92d22..25c3af9064 100644 --- a/pkg/reconciler/intevents/pullsubscription/keda/resources/scaled_object_test.go +++ b/pkg/reconciler/intevents/pullsubscription/keda/resources/scaled_object_test.go @@ -20,7 +20,7 @@ import ( "context" "testing" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" "github.com/google/knative-gcp/pkg/reconciler/intevents/pullsubscription/resources" . "github.com/google/knative-gcp/pkg/reconciler/testing" "k8s.io/api/apps/v1" @@ -28,21 +28,21 @@ import ( "knative.dev/pkg/apis" "github.com/google/go-cmp/cmp" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" ) func newAnnotations() map[string]string { return map[string]string{ - duckv1alpha1.AutoscalingClassAnnotation: duckv1alpha1.KEDA, - duckv1alpha1.AutoscalingMinScaleAnnotation: "0", - duckv1alpha1.AutoscalingMaxScaleAnnotation: "3", - duckv1alpha1.KedaAutoscalingSubscriptionSizeAnnotation: "5", - duckv1alpha1.KedaAutoscalingCooldownPeriodAnnotation: "60", - duckv1alpha1.KedaAutoscalingPollingIntervalAnnotation: "30", + duckv1beta1.AutoscalingClassAnnotation: duckv1beta1.KEDA, + duckv1beta1.AutoscalingMinScaleAnnotation: "0", + duckv1beta1.AutoscalingMaxScaleAnnotation: "3", + duckv1beta1.KedaAutoscalingSubscriptionSizeAnnotation: "5", + duckv1beta1.KedaAutoscalingCooldownPeriodAnnotation: "60", + duckv1beta1.KedaAutoscalingPollingIntervalAnnotation: "30", } } -func newPullSubscription() *v1alpha1.PullSubscription { +func newPullSubscription() *v1beta1.PullSubscription { return NewPullSubscription("psname", "psnamespace", WithPullSubscriptionUID("psuid"), WithPullSubscriptionAnnotations(newAnnotations()), @@ -50,7 +50,7 @@ func newPullSubscription() *v1alpha1.PullSubscription { ) } -func newReceiveAdapter(ps *v1alpha1.PullSubscription) *v1.Deployment { +func newReceiveAdapter(ps *v1beta1.PullSubscription) *v1.Deployment { raArgs := &resources.ReceiveAdapterArgs{ Image: "image", PullSubscription: ps, @@ -68,7 +68,7 @@ func TestMakeScaledObject(t *testing.T) { want := &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "keda.k8s.io/v1alpha1", + "apiVersion": "keda.k8s.io/v1beta1", "kind": "ScaledObject", "metadata": map[string]interface{}{ "namespace": "psnamespace", @@ -79,7 +79,7 @@ func TestMakeScaledObject(t *testing.T) { }, "ownerReferences": []interface{}{ map[string]interface{}{ - "apiVersion": "internal.events.cloud.google.com/v1alpha1", + "apiVersion": "internal.events.cloud.google.com/v1beta1", "kind": "PullSubscription", "blockOwnerDeletion": true, "controller": true, diff --git a/pkg/reconciler/intevents/pullsubscription/resources/names_test.go b/pkg/reconciler/intevents/pullsubscription/resources/names_test.go index 7ed33df70b..523d8609c0 100644 --- a/pkg/reconciler/intevents/pullsubscription/resources/names_test.go +++ b/pkg/reconciler/intevents/pullsubscription/resources/names_test.go @@ -21,18 +21,18 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/knative-gcp/pkg/apis/intevents" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestGenerateSubscriptionName(t *testing.T) { tests := []struct { name string - ps *v1alpha1.PullSubscription + ps *v1beta1.PullSubscription want string }{{ name: "ps-based name", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -42,7 +42,7 @@ func TestGenerateSubscriptionName(t *testing.T) { want: "cre-ps_mynamespace_myname_uid", }, { name: "source-based name", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -55,7 +55,7 @@ func TestGenerateSubscriptionName(t *testing.T) { want: "cre-src_mynamespace_myname_uid", }, { name: "channel-based name", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -80,11 +80,11 @@ func TestGenerateSubscriptionName(t *testing.T) { func TestGenerateReceiveAdapterName(t *testing.T) { tests := []struct { name string - ps *v1alpha1.PullSubscription + ps *v1beta1.PullSubscription want string }{{ name: "ps-based name", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -94,7 +94,7 @@ func TestGenerateReceiveAdapterName(t *testing.T) { want: "cre-ps-myname-uid", }, { name: "source-based name", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -107,7 +107,7 @@ func TestGenerateReceiveAdapterName(t *testing.T) { want: "cre-src-myname-uid", }, { name: "channel-based name", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "myname", Namespace: "mynamespace", @@ -120,7 +120,7 @@ func TestGenerateReceiveAdapterName(t *testing.T) { want: "cre-chan-myname-uid", }, { name: "name too long, hashed and shortened", - ps: &v1alpha1.PullSubscription{ + ps: &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "mynameistoooooolongggggggggggggggggggggggggggggggggg", Namespace: "mynamespace", diff --git a/pkg/reconciler/intevents/pullsubscription/resources/receive_adapter_test.go b/pkg/reconciler/intevents/pullsubscription/resources/receive_adapter_test.go index 26cca038de..14b9a03546 100644 --- a/pkg/reconciler/intevents/pullsubscription/resources/receive_adapter_test.go +++ b/pkg/reconciler/intevents/pullsubscription/resources/receive_adapter_test.go @@ -22,8 +22,8 @@ import ( "github.com/google/go-cmp/cmp" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" testingmetadata "github.com/google/knative-gcp/pkg/gclient/metadata/testing" v1 "k8s.io/api/apps/v1" @@ -34,13 +34,13 @@ import ( ) func TestMakeMinimumReceiveAdapter(t *testing.T) { - ps := &v1alpha1.PullSubscription{ + ps := &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "testname", Namespace: "testnamespace", }, - Spec: v1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + Spec: v1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "eventing-secret-name", @@ -79,7 +79,7 @@ func TestMakeMinimumReceiveAdapter(t *testing.T) { "test-key2": "test-value2", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "internal.events.cloud.google.com/v1alpha1", + APIVersion: "internal.events.cloud.google.com/v1beta1", Kind: "PullSubscription", Name: "testname", Controller: &yes, @@ -179,7 +179,7 @@ func TestMakeMinimumReceiveAdapter(t *testing.T) { } func TestMakeFullReceiveAdapter(t *testing.T) { - ps := &v1alpha1.PullSubscription{ + ps := &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "testname", Namespace: "testnamespace", @@ -187,8 +187,8 @@ func TestMakeFullReceiveAdapter(t *testing.T) { "metrics-resource-group": "test-resource-group", }, }, - Spec: v1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + Spec: v1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "eventing-secret-name", @@ -236,7 +236,7 @@ func TestMakeFullReceiveAdapter(t *testing.T) { "test-key2": "test-value2", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "internal.events.cloud.google.com/v1alpha1", + APIVersion: "internal.events.cloud.google.com/v1beta1", Kind: "PullSubscription", Name: "testname", Controller: &yes, @@ -343,18 +343,18 @@ func TestMakeFullReceiveAdapter(t *testing.T) { func TestMakeReceiveAdapterWithServiceAccount(t *testing.T) { serviceAccountName := "test" - ps := &v1alpha1.PullSubscription{ + ps := &v1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Name: "testname", Namespace: "testnamespace", Annotations: map[string]string{ "metrics-resource-group": "test-resource-group", - duckv1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }, }, - Spec: v1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ + Spec: v1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ + IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: serviceAccountName, }, Project: "eventing-name", @@ -398,7 +398,7 @@ func TestMakeReceiveAdapterWithServiceAccount(t *testing.T) { "test-key2": "test-value2", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "internal.events.cloud.google.com/v1alpha1", + APIVersion: "internal.events.cloud.google.com/v1beta1", Kind: "PullSubscription", Name: "testname", Controller: &yes, diff --git a/pkg/reconciler/intevents/pullsubscription/static/controller_test.go b/pkg/reconciler/intevents/pullsubscription/static/controller_test.go index 3e1a12e8d1..7690024be7 100644 --- a/pkg/reconciler/intevents/pullsubscription/static/controller_test.go +++ b/pkg/reconciler/intevents/pullsubscription/static/controller_test.go @@ -38,7 +38,7 @@ import ( iamtesting "github.com/google/knative-gcp/pkg/reconciler/testing" // Fake injection informers - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription/fake" ) func TestNew(t *testing.T) { diff --git a/pkg/reconciler/intevents/pullsubscription/static/pullsubscription_test.go b/pkg/reconciler/intevents/pullsubscription/static/pullsubscription_test.go index 937d170dea..babb36327c 100644 --- a/pkg/reconciler/intevents/pullsubscription/static/pullsubscription_test.go +++ b/pkg/reconciler/intevents/pullsubscription/static/pullsubscription_test.go @@ -43,9 +43,9 @@ import ( . "knative.dev/pkg/reconciler/testing" "knative.dev/pkg/resolver" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - pubsubv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1alpha1/pullsubscription" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + pubsubv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1beta1/pullsubscription" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub/testing" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/intevents" @@ -84,7 +84,7 @@ var ( sinkGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Sink", } @@ -92,7 +92,7 @@ var ( transformerGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Transformer", } @@ -106,7 +106,7 @@ var ( func init() { // Add types to scheme - _ = pubsubv1alpha1.AddToScheme(scheme.Scheme) + _ = pubsubv1beta1.AddToScheme(scheme.Scheme) } func newSecret() *corev1.Secret { @@ -124,7 +124,7 @@ func newSecret() *corev1.Secret { func newSink() *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "testing.cloud.google.com/v1alpha1", + "apiVersion": "testing.cloud.google.com/v1beta1", "kind": "Sink", "metadata": map[string]interface{}{ "namespace": testNS, @@ -142,7 +142,7 @@ func newSink() *unstructured.Unstructured { func newSinkDestination(namespace string) duckv1.Destination { return duckv1.Destination{ Ref: &duckv1.KReference{ - APIVersion: "testing.cloud.google.com/v1alpha1", + APIVersion: "testing.cloud.google.com/v1beta1", Kind: "Sink", Name: sinkName, Namespace: namespace, @@ -153,7 +153,7 @@ func newSinkDestination(namespace string) duckv1.Destination { func newTransformer() *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "testing.cloud.google.com/v1alpha1", + "apiVersion": "testing.cloud.google.com/v1beta1", "kind": "Transformer", "metadata": map[string]interface{}{ "namespace": testNS, @@ -182,8 +182,8 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewPullSubscription(sourceName, testNS, WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -197,7 +197,7 @@ func TestAllCases(t *testing.T) { WantEvents: []string{ Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", sourceName), Eventf(corev1.EventTypeWarning, "InvalidSink", - `InvalidSink: failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1alpha1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), + `InvalidSink: failed to get ref &ObjectReference{Kind:Sink,Namespace:testnamespace,Name:sink,UID:,APIVersion:testing.cloud.google.com/v1beta1,ResourceVersion:,FieldPath:,}: sinks.testing.cloud.google.com "sink" not found`), }, WantPatches: []clientgotesting.PatchActionImpl{ patchFinalizers(testNS, sourceName, resourceGroup), @@ -206,8 +206,8 @@ func TestAllCases(t *testing.T) { Object: NewPullSubscription(sourceName, testNS, WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -225,8 +225,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -254,8 +254,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -278,8 +278,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -312,8 +312,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -333,8 +333,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -367,8 +367,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -388,8 +388,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -422,8 +422,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -443,8 +443,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -478,8 +478,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -499,8 +499,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -532,8 +532,8 @@ func TestAllCases(t *testing.T) { Object: NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -560,8 +560,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, SourceSpec: duckv1.SourceSpec{ @@ -596,8 +596,8 @@ func TestAllCases(t *testing.T) { Object: NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -624,8 +624,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, SourceSpec: duckv1.SourceSpec{ @@ -662,8 +662,8 @@ func TestAllCases(t *testing.T) { Object: NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -690,8 +690,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -722,8 +722,8 @@ func TestAllCases(t *testing.T) { Object: NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -746,8 +746,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -789,8 +789,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), //WithPullSubscriptionFinalizers(resourceGroup), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -813,8 +813,8 @@ func TestAllCases(t *testing.T) { NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -851,8 +851,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionUID(sourceUID), WithPullSubscriptionObjectMetaGeneration(generation), WithPullSubscriptionStatusObservedGeneration(generation), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, @@ -906,8 +906,8 @@ func TestAllCases(t *testing.T) { func newReceiveAdapter(ctx context.Context, image string, transformer *apis.URL) runtime.Object { ps := NewPullSubscription(sourceName, testNS, WithPullSubscriptionUID(sourceUID), - WithPullSubscriptionSpec(pubsubv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + WithPullSubscriptionSpec(pubsubv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &secret, Project: testProject, }, diff --git a/pkg/reconciler/intevents/reconciler_test.go b/pkg/reconciler/intevents/reconciler_test.go index 7c6277a17a..82fb070ff3 100644 --- a/pkg/reconciler/intevents/reconciler_test.go +++ b/pkg/reconciler/intevents/reconciler_test.go @@ -40,8 +40,8 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" fakePubsubClient "github.com/google/knative-gcp/pkg/client/clientset/versioned/fake" testingmetadata "github.com/google/knative-gcp/pkg/gclient/metadata/testing" "github.com/google/knative-gcp/pkg/reconciler" @@ -99,7 +99,7 @@ var ( // Returns an ownerref for the test object func ownerRef() metav1.OwnerReference { return metav1.OwnerReference{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudStorageSource", Name: name, UID: "test-storage-uid", @@ -112,15 +112,15 @@ func TestCreates(t *testing.T) { testCases := []struct { name string objects []runtime.Object - expectedTopic *inteventsv1alpha1.Topic - expectedPS *inteventsv1alpha1.PullSubscription + expectedTopic *inteventsv1beta1.Topic + expectedPS *inteventsv1beta1.PullSubscription expectedErr string wantCreates []runtime.Object wantUpdates []clientgotesting.UpdateActionImpl }{{ name: "topic does not exist, created, not yet been reconciled", expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -131,7 +131,7 @@ func TestCreates(t *testing.T) { "events.cloud.google.com/source-name": name, }), rectesting.WithTopicAnnotations(map[string]string{ - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -139,7 +139,7 @@ func TestCreates(t *testing.T) { expectedErr: fmt.Sprintf("Topic %q has not yet been reconciled", name), wantCreates: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -150,7 +150,7 @@ func TestCreates(t *testing.T) { "events.cloud.google.com/source-name": name, }), rectesting.WithTopicAnnotations(map[string]string{ - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -159,7 +159,7 @@ func TestCreates(t *testing.T) { name: "topic exists but is not yet been reconciled", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -172,7 +172,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -190,7 +190,7 @@ func TestCreates(t *testing.T) { name: "topic exists and is ready but no projectid", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -205,7 +205,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -226,7 +226,7 @@ func TestCreates(t *testing.T) { name: "topic exists and the status of topic is false", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -241,7 +241,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -262,7 +262,7 @@ func TestCreates(t *testing.T) { name: "topic exists and the status of topic is unknown", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -277,7 +277,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -298,7 +298,7 @@ func TestCreates(t *testing.T) { name: "topic exists and is ready but no topicid", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -314,7 +314,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -336,7 +336,7 @@ func TestCreates(t *testing.T) { name: "topic updated due to different secret, pullsubscription created, not yet been reconciled", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &oldSecret, Topic: testTopicID, PropagationPolicy: "CreatDelete", @@ -347,7 +347,7 @@ func TestCreates(t *testing.T) { "events.cloud.google.com/source-name": name, }), rectesting.WithTopicAnnotations(map[string]string{ - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicProjectID(testProjectID), @@ -356,7 +356,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -367,7 +367,7 @@ func TestCreates(t *testing.T) { "events.cloud.google.com/source-name": name, }), rectesting.WithTopicAnnotations(map[string]string{ - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReadyAndPublisherDeployed(testTopicID), @@ -376,9 +376,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), expectedPS: rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -391,16 +391,16 @@ func TestCreates(t *testing.T) { }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithPullSubscriptionOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), expectedErr: fmt.Sprintf("%s: PullSubscription %q has not yet been reconciled", failedToPropagatePullSubscriptionStatusMsg, name), wantCreates: []runtime.Object{ rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -413,14 +413,14 @@ func TestCreates(t *testing.T) { }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithPullSubscriptionOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), }, wantUpdates: []clientgotesting.UpdateActionImpl{{ Object: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -431,7 +431,7 @@ func TestCreates(t *testing.T) { "events.cloud.google.com/source-name": name, }), rectesting.WithTopicAnnotations(map[string]string{ - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReadyAndPublisherDeployed(testTopicID), @@ -444,7 +444,7 @@ func TestCreates(t *testing.T) { name: "topic exists and is ready, pullsubscription created, not yet been reconciled", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -454,7 +454,7 @@ func TestCreates(t *testing.T) { "events.cloud.google.com/source-name": name, }), rectesting.WithTopicAnnotations(map[string]string{ - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicProjectID(testProjectID), @@ -463,7 +463,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -474,7 +474,7 @@ func TestCreates(t *testing.T) { "events.cloud.google.com/source-name": name, }), rectesting.WithTopicAnnotations(map[string]string{ - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReadyAndPublisherDeployed(testTopicID), @@ -483,9 +483,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), expectedPS: rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -498,16 +498,16 @@ func TestCreates(t *testing.T) { }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithPullSubscriptionOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), expectedErr: fmt.Sprintf("%s: PullSubscription %q has not yet been reconciled", failedToPropagatePullSubscriptionStatusMsg, name), wantCreates: []runtime.Object{ rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -520,7 +520,7 @@ func TestCreates(t *testing.T) { }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, - v1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + v1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }), rectesting.WithPullSubscriptionOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -529,7 +529,7 @@ func TestCreates(t *testing.T) { name: "topic exists and is ready, pullsubscription exists, not yet been reconciled", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -544,9 +544,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicAddress(testTopicURI), ), rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -564,7 +564,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -581,9 +581,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), expectedPS: rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -604,7 +604,7 @@ func TestCreates(t *testing.T) { name: "topic exists and is ready, pullsubscription exists and the status is false", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -619,9 +619,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicAddress(testTopicURI), ), rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -640,7 +640,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -657,9 +657,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), expectedPS: rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -681,7 +681,7 @@ func TestCreates(t *testing.T) { name: "topic exists and is ready, pullsubscription exists and the status is unknown", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -696,9 +696,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicAddress(testTopicURI), ), rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -717,7 +717,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -734,9 +734,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), expectedPS: rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -758,7 +758,7 @@ func TestCreates(t *testing.T) { name: "topic exists and is ready, pullsubscription is updated due to different sink", objects: []runtime.Object{ rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Topic: testTopicID, PropagationPolicy: "CreateDelete", EnablePublisher: &falseVal, @@ -773,9 +773,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicAddress(testTopicURI), ), rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: oldSink, @@ -794,7 +794,7 @@ func TestCreates(t *testing.T) { ), }, expectedTopic: rectesting.NewTopic(name, testNS, - rectesting.WithTopicSpec(inteventsv1alpha1.TopicSpec{ + rectesting.WithTopicSpec(inteventsv1beta1.TopicSpec{ Secret: &secret, Topic: testTopicID, PropagationPolicy: "CreateDelete", @@ -811,9 +811,9 @@ func TestCreates(t *testing.T) { rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), expectedPS: rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -833,9 +833,9 @@ func TestCreates(t *testing.T) { ), wantUpdates: []clientgotesting.UpdateActionImpl{{ Object: rectesting.NewPullSubscriptionWithNoDefaults(name, testNS, - rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1alpha1.PullSubscriptionSpec{ + rectesting.WithPullSubscriptionSpecWithNoDefaults(inteventsv1beta1.PullSubscriptionSpec{ Topic: testTopicID, - PubSubSpec: v1alpha1.PubSubSpec{ + PubSubSpec: v1beta1.PubSubSpec{ Secret: &secret, SourceSpec: duckv1.SourceSpec{ Sink: sink, @@ -1028,14 +1028,14 @@ func TestDeletes(t *testing.T) { ActionImpl: clientgotesting.ActionImpl{ Namespace: testNS, Verb: "delete", - Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "topics"}, + Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "topics"}, }, Name: name, }, { ActionImpl: clientgotesting.ActionImpl{ Namespace: testNS, Verb: "delete", - Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1alpha1", Resource: "pullsubscriptions"}, + Resource: schema.GroupVersionResource{Group: "internal.events.cloud.google.com", Version: "v1beta1", Resource: "pullsubscriptions"}, }, Name: name, }, diff --git a/pkg/reconciler/intevents/resources/pullsubscription_test.go b/pkg/reconciler/intevents/resources/pullsubscription_test.go index 3eeab796df..238ec57d45 100644 --- a/pkg/reconciler/intevents/resources/pullsubscription_test.go +++ b/pkg/reconciler/intevents/resources/pullsubscription_test.go @@ -20,24 +20,24 @@ import ( "testing" "github.com/google/go-cmp/cmp" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" duckv1 "knative.dev/pkg/apis/duck/v1" ) func TestMakePullSubscription(t *testing.T) { - source := &v1alpha1.CloudStorageSource{ + source := &v1beta1.CloudStorageSource{ ObjectMeta: metav1.ObjectMeta{ Name: "bucket-name", Namespace: "bucket-namespace", UID: "bucket-uid", }, - Spec: v1alpha1.CloudStorageSourceSpec{ + Spec: v1beta1.CloudStorageSourceSpec{ Bucket: "this-bucket", - PubSubSpec: duckv1alpha1.PubSubSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Project: "project-123", Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ @@ -78,7 +78,7 @@ func TestMakePullSubscription(t *testing.T) { got := MakePullSubscription(args) yes := true - want := &inteventsv1alpha1.PullSubscription{ + want := &inteventsv1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Namespace: "bucket-namespace", Name: "bucket-name", @@ -90,7 +90,7 @@ func TestMakePullSubscription(t *testing.T) { "metrics-resource-group": "storages.events.cloud.google.com", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudStorageSource", Name: "bucket-name", UID: "bucket-uid", @@ -98,8 +98,8 @@ func TestMakePullSubscription(t *testing.T) { BlockOwnerDeletion: &yes, }}, }, - Spec: inteventsv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + Spec: inteventsv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "eventing-secret-name", diff --git a/pkg/reconciler/intevents/resources/topic_test.go b/pkg/reconciler/intevents/resources/topic_test.go index 64fe20d628..ea18a5ad32 100644 --- a/pkg/reconciler/intevents/resources/topic_test.go +++ b/pkg/reconciler/intevents/resources/topic_test.go @@ -23,26 +23,26 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" metadatatesting "github.com/google/knative-gcp/pkg/gclient/metadata/testing" duckv1 "knative.dev/pkg/apis/duck/v1" ) func TestMakeTopicWithCloudStorageSource(t *testing.T) { - source := &v1alpha1.CloudStorageSource{ + source := &v1beta1.CloudStorageSource{ ObjectMeta: metav1.ObjectMeta{ Name: "storage-name", Namespace: "storage-namespace", UID: "storage-uid", Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: metadatatesting.FakeClusterName, }, }, - Spec: v1alpha1.CloudStorageSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + Spec: v1beta1.CloudStorageSourceSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Project: "project-123", Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ @@ -74,13 +74,13 @@ func TestMakeTopicWithCloudStorageSource(t *testing.T) { "source": source.Name, }, Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: metadatatesting.FakeClusterName, }, } got := MakeTopic(args) yes := true - want := &inteventsv1alpha1.Topic{ + want := &inteventsv1beta1.Topic{ ObjectMeta: metav1.ObjectMeta{ Namespace: "storage-namespace", Name: "storage-name", @@ -89,7 +89,7 @@ func TestMakeTopicWithCloudStorageSource(t *testing.T) { "source": "storage-name", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudStorageSource", Name: "storage-name", UID: "storage-uid", @@ -97,10 +97,10 @@ func TestMakeTopicWithCloudStorageSource(t *testing.T) { BlockOwnerDeletion: &yes, }}, Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: metadatatesting.FakeClusterName, }, }, - Spec: inteventsv1alpha1.TopicSpec{ + Spec: inteventsv1beta1.TopicSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "eventing-secret-name", @@ -109,7 +109,7 @@ func TestMakeTopicWithCloudStorageSource(t *testing.T) { }, Project: "project-123", Topic: "topic-abc", - PropagationPolicy: inteventsv1alpha1.TopicPolicyCreateDelete, + PropagationPolicy: inteventsv1beta1.TopicPolicyCreateDelete, }, } @@ -119,17 +119,17 @@ func TestMakeTopicWithCloudStorageSource(t *testing.T) { } func TestMakeTopicWithCloudSchedulerSource(t *testing.T) { - source := &v1alpha1.CloudSchedulerSource{ + source := &v1beta1.CloudSchedulerSource{ ObjectMeta: metav1.ObjectMeta{ Name: "scheduler-name", Namespace: "scheduler-namespace", UID: "scheduler-uid", Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: metadatatesting.FakeClusterName, }, }, - Spec: v1alpha1.CloudSchedulerSourceSpec{ - PubSubSpec: duckv1alpha1.PubSubSpec{ + Spec: v1beta1.CloudSchedulerSourceSpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ Project: "project-123", Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ @@ -160,13 +160,13 @@ func TestMakeTopicWithCloudSchedulerSource(t *testing.T) { "source": source.Name, }, Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: metadatatesting.FakeClusterName, }, } got := MakeTopic(args) yes := true - want := &inteventsv1alpha1.Topic{ + want := &inteventsv1beta1.Topic{ ObjectMeta: metav1.ObjectMeta{ Namespace: "scheduler-namespace", Name: "scheduler-name", @@ -175,7 +175,7 @@ func TestMakeTopicWithCloudSchedulerSource(t *testing.T) { "source": "scheduler-name", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "events.cloud.google.com/v1alpha1", + APIVersion: "events.cloud.google.com/v1beta1", Kind: "CloudSchedulerSource", Name: "scheduler-name", UID: "scheduler-uid", @@ -183,10 +183,10 @@ func TestMakeTopicWithCloudSchedulerSource(t *testing.T) { BlockOwnerDeletion: &yes, }}, Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: metadatatesting.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: metadatatesting.FakeClusterName, }, }, - Spec: inteventsv1alpha1.TopicSpec{ + Spec: inteventsv1beta1.TopicSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "eventing-secret-name", @@ -195,7 +195,7 @@ func TestMakeTopicWithCloudSchedulerSource(t *testing.T) { }, Project: "project-123", Topic: "topic-abc", - PropagationPolicy: inteventsv1alpha1.TopicPolicyCreateDelete, + PropagationPolicy: inteventsv1beta1.TopicPolicyCreateDelete, }, } diff --git a/pkg/reconciler/intevents/topic/resources/publisher_test.go b/pkg/reconciler/intevents/topic/resources/publisher_test.go index d68699889f..29e6c3f0b8 100644 --- a/pkg/reconciler/intevents/topic/resources/publisher_test.go +++ b/pkg/reconciler/intevents/topic/resources/publisher_test.go @@ -25,18 +25,18 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" servingv1 "knative.dev/serving/pkg/apis/serving/v1" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" testingmetadata "github.com/google/knative-gcp/pkg/gclient/metadata/testing" ) func TestMakePublisher(t *testing.T) { - topic := &v1alpha1.Topic{ + topic := &v1beta1.Topic{ ObjectMeta: metav1.ObjectMeta{ Name: "topic-name", Namespace: "topic-namespace", }, - Spec: v1alpha1.TopicSpec{ + Spec: v1beta1.TopicSpec{ Project: "eventing-name", Topic: "topic-name", Secret: &corev1.SecretKeySelector{ @@ -69,7 +69,7 @@ func TestMakePublisher(t *testing.T) { }, "ownerReferences": [ { - "apiVersion": "internal.events.cloud.google.com/v1alpha1", + "apiVersion": "internal.events.cloud.google.com/v1beta1", "kind": "Topic", "name": "topic-name", "uid": "", @@ -140,18 +140,18 @@ func TestMakePublisher(t *testing.T) { func TestMakePublisherWithServiceAccount(t *testing.T) { serviceAccountName := "test" - topic := &v1alpha1.Topic{ + topic := &v1beta1.Topic{ ObjectMeta: metav1.ObjectMeta{ Name: "topic-name", Namespace: "topic-namespace", Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testingmetadata.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testingmetadata.FakeClusterName, }, }, - Spec: v1alpha1.TopicSpec{ + Spec: v1beta1.TopicSpec{ Project: "eventing-name", Topic: "topic-name", - IdentitySpec: duckv1alpha1.IdentitySpec{ + IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: serviceAccountName, }, }, @@ -175,7 +175,7 @@ func TestMakePublisherWithServiceAccount(t *testing.T) { "internal.events.cloud.google.com/topic": "topic-name", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "internal.events.cloud.google.com/v1alpha1", + APIVersion: "internal.events.cloud.google.com/v1beta1", Kind: "Topic", Name: "topic-name", Controller: &yes, diff --git a/pkg/reconciler/intevents/topic/topic_test.go b/pkg/reconciler/intevents/topic/topic_test.go index 830181c5c3..0bfee2476e 100644 --- a/pkg/reconciler/intevents/topic/topic_test.go +++ b/pkg/reconciler/intevents/topic/topic_test.go @@ -39,8 +39,8 @@ import ( . "knative.dev/pkg/reconciler/testing" servingv1 "knative.dev/serving/pkg/apis/serving/v1" - pubsubv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1alpha1/topic" + pubsubv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/client/injection/reconciler/intevents/v1beta1/topic" gpubsub "github.com/google/knative-gcp/pkg/gclient/pubsub/testing" "github.com/google/knative-gcp/pkg/reconciler" "github.com/google/knative-gcp/pkg/reconciler/intevents" @@ -74,7 +74,7 @@ var ( sinkGVK = metav1.GroupVersionKind{ Group: "testing.cloud.google.com", - Version: "v1alpha1", + Version: "v1beta1", Kind: "Sink", } @@ -88,13 +88,13 @@ var ( func init() { // Add types to scheme - _ = pubsubv1alpha1.AddToScheme(scheme.Scheme) + _ = pubsubv1beta1.AddToScheme(scheme.Scheme) } func newSink() *unstructured.Unstructured { return &unstructured.Unstructured{ Object: map[string]interface{}{ - "apiVersion": "testing.cloud.google.com/v1alpha1", + "apiVersion": "testing.cloud.google.com/v1beta1", "kind": "Sink", "metadata": map[string]interface{}{ "namespace": testNS, @@ -135,7 +135,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -162,7 +162,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -177,7 +177,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -206,7 +206,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -221,7 +221,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -243,7 +243,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -258,7 +258,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -285,7 +285,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -300,7 +300,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -323,7 +323,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -339,7 +339,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -364,7 +364,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -381,7 +381,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -409,7 +409,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -425,7 +425,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -453,7 +453,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -469,7 +469,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -497,7 +497,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -514,7 +514,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -542,7 +542,7 @@ func TestAllCases(t *testing.T) { Object: NewTopic(topicName, testNS, WithTopicUID(topicUID), WithTopicProjectID(testProject), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -559,7 +559,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -578,7 +578,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -598,7 +598,7 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, @@ -670,7 +670,7 @@ func patchFinalizers(namespace, name, finalizer string, existingFinalizers ...st func ownerReferences() []metav1.OwnerReference { return []metav1.OwnerReference{{ - APIVersion: "internal.events.cloud.google.com/v1alpha1", + APIVersion: "internal.events.cloud.google.com/v1beta1", Kind: "Topic", Name: topicName, UID: topicUID, @@ -731,7 +731,7 @@ func makeFalseStatusPublisher(reason, message string) *servingv1.Service { func newPublisher() *servingv1.Service { t := NewTopic(topicName, testNS, WithTopicUID(topicUID), - WithTopicSpec(pubsubv1alpha1.TopicSpec{ + WithTopicSpec(pubsubv1beta1.TopicSpec{ Project: testProject, Topic: testTopicID, Secret: &secret, diff --git a/pkg/reconciler/messaging/channel/controller_test.go b/pkg/reconciler/messaging/channel/controller_test.go index eb64798284..a10c6d7376 100644 --- a/pkg/reconciler/messaging/channel/controller_test.go +++ b/pkg/reconciler/messaging/channel/controller_test.go @@ -26,9 +26,9 @@ import ( // Fake injection informers - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/messaging/v1alpha1/channel/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/messaging/v1beta1/channel/fake" _ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/fake" ) diff --git a/pkg/reconciler/messaging/channel/resources/names_test.go b/pkg/reconciler/messaging/channel/resources/names_test.go index 931efd87f6..6ed69a415d 100644 --- a/pkg/reconciler/messaging/channel/resources/names_test.go +++ b/pkg/reconciler/messaging/channel/resources/names_test.go @@ -23,12 +23,12 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" ) func TestGenerateTopicID(t *testing.T) { want := "cre-chan_default_foo_a-uid" - got := GenerateTopicID(&v1alpha1.Channel{ + got := GenerateTopicID(&v1beta1.Channel{ ObjectMeta: v1.ObjectMeta{ Name: "foo", Namespace: "default", @@ -43,7 +43,7 @@ func TestGenerateTopicID(t *testing.T) { func TestGeneratePublisherName(t *testing.T) { want := "cre-foo-chan" - got := GeneratePublisherName(&v1alpha1.Channel{ + got := GeneratePublisherName(&v1beta1.Channel{ ObjectMeta: v1.ObjectMeta{ Name: "foo", }, @@ -56,7 +56,7 @@ func TestGeneratePublisherName(t *testing.T) { func TestGeneratePublisherNameFromChannel(t *testing.T) { want := "cre-foo-chan" - got := GeneratePublisherName(&v1alpha1.Channel{ + got := GeneratePublisherName(&v1beta1.Channel{ ObjectMeta: v1.ObjectMeta{ Name: "cre-foo", }, diff --git a/pkg/reconciler/messaging/channel/resources/pullsubscription_test.go b/pkg/reconciler/messaging/channel/resources/pullsubscription_test.go index 78511b8361..7b6f0b2fa4 100644 --- a/pkg/reconciler/messaging/channel/resources/pullsubscription_test.go +++ b/pkg/reconciler/messaging/channel/resources/pullsubscription_test.go @@ -20,24 +20,24 @@ import ( "testing" "github.com/google/go-cmp/cmp" - duckinteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" + duckinteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" + duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" ) func TestMakePullSubscription(t *testing.T) { - channel := &v1alpha1.Channel{ + channel := &v1beta1.Channel{ ObjectMeta: metav1.ObjectMeta{ Name: "channel-name", Namespace: "channel-namespace", UID: "channel-uid", }, - Spec: v1alpha1.ChannelSpec{ + Spec: v1beta1.ChannelSpec{ Project: "eventing-name", Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ @@ -46,7 +46,7 @@ func TestMakePullSubscription(t *testing.T) { Key: "eventing-secret-key", }, }, - Status: v1alpha1.ChannelStatus{ + Status: v1beta1.ChannelStatus{ ProjectID: "project-123", TopicID: "topic-abc", }, @@ -62,7 +62,7 @@ func TestMakePullSubscription(t *testing.T) { "test-key1": "test-value1", "test-key2": "test-value2", }, - Subscriber: duckv1alpha1.SubscriberSpec{ + Subscriber: duckv1beta1.SubscriberSpec{ SubscriberURI: &apis.URL{ Scheme: "http", Path: "/", @@ -77,7 +77,7 @@ func TestMakePullSubscription(t *testing.T) { }) yes := true - want := &inteventsv1alpha1.PullSubscription{ + want := &inteventsv1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Namespace: "channel-namespace", Name: "cre-sub-subscriber-uid", @@ -86,7 +86,7 @@ func TestMakePullSubscription(t *testing.T) { "test-key2": "test-value2", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "messaging.cloud.google.com/v1alpha1", + APIVersion: "messaging.cloud.google.com/v1beta1", Kind: "Channel", Name: "channel-name", UID: "channel-uid", @@ -94,8 +94,8 @@ func TestMakePullSubscription(t *testing.T) { BlockOwnerDeletion: &yes, }}, }, - Spec: inteventsv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckinteventsv1alpha1.PubSubSpec{ + Spec: inteventsv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckinteventsv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "eventing-secret-name", @@ -122,13 +122,13 @@ func TestMakePullSubscription(t *testing.T) { } func TestMakePullSubscription_JustSubscriber(t *testing.T) { - channel := &v1alpha1.Channel{ + channel := &v1beta1.Channel{ ObjectMeta: metav1.ObjectMeta{ Name: "channel-name", Namespace: "channel-namespace", UID: "channel-uid", }, - Spec: v1alpha1.ChannelSpec{ + Spec: v1beta1.ChannelSpec{ Project: "eventing-name", Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ @@ -137,7 +137,7 @@ func TestMakePullSubscription_JustSubscriber(t *testing.T) { Key: "eventing-secret-key", }, }, - Status: v1alpha1.ChannelStatus{ + Status: v1beta1.ChannelStatus{ ProjectID: "project-123", TopicID: "topic-abc", }, @@ -153,7 +153,7 @@ func TestMakePullSubscription_JustSubscriber(t *testing.T) { "test-key1": "test-value1", "test-key2": "test-value2", }, - Subscriber: duckv1alpha1.SubscriberSpec{ + Subscriber: duckv1beta1.SubscriberSpec{ SubscriberURI: &apis.URL{ Scheme: "http", Path: "/", @@ -163,7 +163,7 @@ func TestMakePullSubscription_JustSubscriber(t *testing.T) { }) yes := true - want := &inteventsv1alpha1.PullSubscription{ + want := &inteventsv1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Namespace: "channel-namespace", Name: "cre-sub-subscriber-uid", @@ -172,7 +172,7 @@ func TestMakePullSubscription_JustSubscriber(t *testing.T) { "test-key2": "test-value2", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "messaging.cloud.google.com/v1alpha1", + APIVersion: "messaging.cloud.google.com/v1beta1", Kind: "Channel", Name: "channel-name", UID: "channel-uid", @@ -180,8 +180,8 @@ func TestMakePullSubscription_JustSubscriber(t *testing.T) { BlockOwnerDeletion: &yes, }}, }, - Spec: inteventsv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckinteventsv1alpha1.PubSubSpec{ + Spec: inteventsv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckinteventsv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "eventing-secret-name", @@ -205,13 +205,13 @@ func TestMakePullSubscription_JustSubscriber(t *testing.T) { } func TestMakePullSubscription_JustReply(t *testing.T) { - channel := &v1alpha1.Channel{ + channel := &v1beta1.Channel{ ObjectMeta: metav1.ObjectMeta{ Name: "channel-name", Namespace: "channel-namespace", UID: "channel-uid", }, - Spec: v1alpha1.ChannelSpec{ + Spec: v1beta1.ChannelSpec{ Project: "eventing-name", Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ @@ -220,7 +220,7 @@ func TestMakePullSubscription_JustReply(t *testing.T) { Key: "eventing-secret-key", }, }, - Status: v1alpha1.ChannelStatus{ + Status: v1beta1.ChannelStatus{ ProjectID: "project-123", TopicID: "topic-abc", }, @@ -236,7 +236,7 @@ func TestMakePullSubscription_JustReply(t *testing.T) { "test-key1": "test-value1", "test-key2": "test-value2", }, - Subscriber: duckv1alpha1.SubscriberSpec{ + Subscriber: duckv1beta1.SubscriberSpec{ ReplyURI: &apis.URL{ Scheme: "http", Path: "/", @@ -246,7 +246,7 @@ func TestMakePullSubscription_JustReply(t *testing.T) { }) yes := true - want := &inteventsv1alpha1.PullSubscription{ + want := &inteventsv1beta1.PullSubscription{ ObjectMeta: metav1.ObjectMeta{ Namespace: "channel-namespace", Name: "cre-sub-subscriber-uid", @@ -255,7 +255,7 @@ func TestMakePullSubscription_JustReply(t *testing.T) { "test-key2": "test-value2", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "messaging.cloud.google.com/v1alpha1", + APIVersion: "messaging.cloud.google.com/v1beta1", Kind: "Channel", Name: "channel-name", UID: "channel-uid", @@ -263,8 +263,8 @@ func TestMakePullSubscription_JustReply(t *testing.T) { BlockOwnerDeletion: &yes, }}, }, - Spec: inteventsv1alpha1.PullSubscriptionSpec{ - PubSubSpec: duckinteventsv1alpha1.PubSubSpec{ + Spec: inteventsv1beta1.PullSubscriptionSpec{ + PubSubSpec: duckinteventsv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "eventing-secret-name", diff --git a/pkg/reconciler/messaging/channel/resources/topic_test.go b/pkg/reconciler/messaging/channel/resources/topic_test.go index 209a33b189..cc110fa873 100644 --- a/pkg/reconciler/messaging/channel/resources/topic_test.go +++ b/pkg/reconciler/messaging/channel/resources/topic_test.go @@ -23,17 +23,17 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" ) func TestMakeTopic(t *testing.T) { - channel := &v1alpha1.Channel{ + channel := &v1beta1.Channel{ ObjectMeta: metav1.ObjectMeta{ Name: "channel-name", Namespace: "channel-namespace", }, - Spec: v1alpha1.ChannelSpec{ + Spec: v1beta1.ChannelSpec{ Project: "eventing-name", Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ @@ -42,7 +42,7 @@ func TestMakeTopic(t *testing.T) { Key: "eventing-secret-key", }, }, - Status: v1alpha1.ChannelStatus{ + Status: v1beta1.ChannelStatus{ ProjectID: "project-123", TopicID: "topic-abc", }, @@ -61,7 +61,7 @@ func TestMakeTopic(t *testing.T) { }) yes := true - want := &inteventsv1alpha1.Topic{ + want := &inteventsv1beta1.Topic{ ObjectMeta: metav1.ObjectMeta{ Namespace: "channel-namespace", Name: "cre-channel-name-chan", @@ -70,14 +70,14 @@ func TestMakeTopic(t *testing.T) { "test-key2": "test-value2", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "messaging.cloud.google.com/v1alpha1", + APIVersion: "messaging.cloud.google.com/v1beta1", Kind: "Channel", Name: "channel-name", Controller: &yes, BlockOwnerDeletion: &yes, }}, }, - Spec: inteventsv1alpha1.TopicSpec{ + Spec: inteventsv1beta1.TopicSpec{ Secret: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: "eventing-secret-name", @@ -86,7 +86,7 @@ func TestMakeTopic(t *testing.T) { }, Project: "project-123", Topic: "topic-abc", - PropagationPolicy: inteventsv1alpha1.TopicPolicyCreateDelete, + PropagationPolicy: inteventsv1beta1.TopicPolicyCreateDelete, }, } diff --git a/pkg/reconciler/testing/auditlogs.go b/pkg/reconciler/testing/auditlogs.go index 1ae47aedb4..4181dc8eaa 100644 --- a/pkg/reconciler/testing/auditlogs.go +++ b/pkg/reconciler/testing/auditlogs.go @@ -23,16 +23,16 @@ import ( gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" ) -type CloudAuditLogsSourceOption func(*v1alpha1.CloudAuditLogsSource) +type CloudAuditLogsSourceOption func(*v1beta1.CloudAuditLogsSource) -func NewCloudAuditLogsSource(name, namespace string, opts ...CloudAuditLogsSourceOption) *v1alpha1.CloudAuditLogsSource { - cal := &v1alpha1.CloudAuditLogsSource{ +func NewCloudAuditLogsSource(name, namespace string, opts ...CloudAuditLogsSourceOption) *v1beta1.CloudAuditLogsSource { + cal := &v1beta1.CloudAuditLogsSource{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, @@ -45,80 +45,80 @@ func NewCloudAuditLogsSource(name, namespace string, opts ...CloudAuditLogsSourc return cal } -func WithInitCloudAuditLogsSourceConditions(s *v1alpha1.CloudAuditLogsSource) { +func WithInitCloudAuditLogsSourceConditions(s *v1beta1.CloudAuditLogsSource) { s.Status.InitializeConditions() } func WithCloudAuditLogsSourceUID(uid string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.ObjectMeta.UID = types.UID(uid) } } // WithCloudAuditLogsSourceServiceAccountName will give status.ServiceAccountName a k8s service account name, which is related on Workload Identity's Google service account. func WithCloudAuditLogsSourceServiceAccountName(name string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.ServiceAccountName = name } } func WithCloudAuditLogsSourceTopicFailed(reason, message string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.MarkTopicFailed(s.ConditionSet(), reason, message) } } func WithCloudAuditLogsSourceWorkloadIdentityFailed(reason, message string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.MarkWorkloadIdentityFailed(s.ConditionSet(), reason, message) } } func WithCloudAuditLogsSourceTopicUnknown(reason, message string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.MarkTopicUnknown(s.ConditionSet(), reason, message) } } func WithCloudAuditLogsSourceTopicReady(topicID string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.MarkTopicReady(s.ConditionSet()) s.Status.TopicID = topicID } } func WithCloudAuditLogsSourcePullSubscriptionFailed(reason, message string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), reason, message) } } func WithCloudAuditLogsSourcePullSubscriptionUnknown(reason, message string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), reason, message) } } func WithCloudAuditLogsSourcePullSubscriptionReady() CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.MarkPullSubscriptionReady(s.ConditionSet()) } } func WithCloudAuditLogsSourceSinkNotReady(reason, messageFmt string, messageA ...interface{}) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.MarkSinkNotReady(reason, messageFmt, messageA...) } } func WithCloudAuditLogsSourceSinkReady() CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.MarkSinkReady() } } func WithCloudAuditLogsSourceSink(gvk metav1.GroupVersionKind, name string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Spec.Sink = duckv1.Destination{ Ref: &duckv1.KReference{ APIVersion: apiVersion(gvk), @@ -130,78 +130,78 @@ func WithCloudAuditLogsSourceSink(gvk metav1.GroupVersionKind, name string) Clou } func WithCloudAuditLogsSourceSinkURI(url *apis.URL) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.SinkURI = url } } func WithCloudAuditLogsSourceProjectID(projectID string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.ProjectID = projectID } } func WithCloudAuditLogsSourceSubscriptionID(subscriptionID string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.SubscriptionID = subscriptionID } } func WithCloudAuditLogsSourceSinkID(sinkID string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Status.StackdriverSink = sinkID } } func WithCloudAuditLogsSourceProject(project string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Spec.Project = project } } func WithCloudAuditLogsSourceResourceName(resourceName string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Spec.ResourceName = resourceName } } func WithCloudAuditLogsSourceServiceName(serviceName string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Spec.ServiceName = serviceName } } func WithCloudAuditLogsSourceServiceAccount(kServiceAccount string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Spec.ServiceAccountName = kServiceAccount } } func WithCloudAuditLogsSourceMethodName(methodName string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Spec.MethodName = methodName } } func WithCloudAuditLogsSourceFinalizers(finalizers ...string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Finalizers = finalizers } } -func WithCloudAuditLogsSourceDeletionTimestamp(s *v1alpha1.CloudAuditLogsSource) { +func WithCloudAuditLogsSourceDeletionTimestamp(s *v1beta1.CloudAuditLogsSource) { t := metav1.NewTime(time.Unix(1e9, 0)) s.ObjectMeta.SetDeletionTimestamp(&t) } func WithCloudAuditLogsSourceAnnotations(Annotations map[string]string) CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.ObjectMeta.Annotations = Annotations } } func WithCloudAuditLogsSourceDefaultGCPAuth() CloudAuditLogsSourceOption { - return func(s *v1alpha1.CloudAuditLogsSource) { + return func(s *v1beta1.CloudAuditLogsSource) { s.Spec.PubSubSpec.SetPubSubDefaults(gcpauthtesthelper.ContextWithDefaults()) } } diff --git a/pkg/reconciler/testing/listers.go b/pkg/reconciler/testing/listers.go index 1726753136..5e3f43a37a 100644 --- a/pkg/reconciler/testing/listers.go +++ b/pkg/reconciler/testing/listers.go @@ -44,7 +44,7 @@ import ( fakeservingclientset "knative.dev/serving/pkg/client/clientset/versioned/fake" brokerv1beta1 "github.com/google/knative-gcp/pkg/apis/broker/v1beta1" - EventsV1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + EventsV1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" intv1alpha1 "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" @@ -133,23 +133,23 @@ func (l *Listers) GetJobLister() batchv1listers.JobLister { } func (l *Listers) GetCloudAuditLogsSourceLister() eventslisters.CloudAuditLogsSourceLister { - return eventslisters.NewCloudAuditLogsSourceLister(l.indexerFor(&EventsV1alpha1.CloudAuditLogsSource{})) + return eventslisters.NewCloudAuditLogsSourceLister(l.indexerFor(&EventsV1beta1.CloudAuditLogsSource{})) } func (l *Listers) GetCloudStorageSourceLister() eventslisters.CloudStorageSourceLister { - return eventslisters.NewCloudStorageSourceLister(l.indexerFor(&EventsV1alpha1.CloudStorageSource{})) + return eventslisters.NewCloudStorageSourceLister(l.indexerFor(&EventsV1beta1.CloudStorageSource{})) } func (l *Listers) GetCloudSchedulerSourceLister() eventslisters.CloudSchedulerSourceLister { - return eventslisters.NewCloudSchedulerSourceLister(l.indexerFor(&EventsV1alpha1.CloudSchedulerSource{})) + return eventslisters.NewCloudSchedulerSourceLister(l.indexerFor(&EventsV1beta1.CloudSchedulerSource{})) } func (l *Listers) GetCloudPubSubSourceLister() eventslisters.CloudPubSubSourceLister { - return eventslisters.NewCloudPubSubSourceLister(l.indexerFor(&EventsV1alpha1.CloudPubSubSource{})) + return eventslisters.NewCloudPubSubSourceLister(l.indexerFor(&EventsV1beta1.CloudPubSubSource{})) } func (l *Listers) GetCloudBuildSourceLister() eventslisters.CloudBuildSourceLister { - return eventslisters.NewCloudBuildSourceLister(l.indexerFor(&EventsV1alpha1.CloudBuildSource{})) + return eventslisters.NewCloudBuildSourceLister(l.indexerFor(&EventsV1beta1.CloudBuildSource{})) } func (l *Listers) GetDeploymentLister() appsv1listers.DeploymentLister { diff --git a/pkg/reconciler/testing/pubsub.go b/pkg/reconciler/testing/pubsub.go index 62b63900b0..5d016bdae2 100644 --- a/pkg/reconciler/testing/pubsub.go +++ b/pkg/reconciler/testing/pubsub.go @@ -26,15 +26,15 @@ import ( "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" ) // CloudPubSubSourceOption enables further configuration of a CloudPubSubSource. -type CloudPubSubSourceOption func(*v1alpha1.CloudPubSubSource) +type CloudPubSubSourceOption func(*v1beta1.CloudPubSubSource) // NewCloudPubSubSource creates a CloudPubSubSource with CloudPubSubSourceOptions -func NewCloudPubSubSource(name, namespace string, so ...CloudPubSubSourceOption) *v1alpha1.CloudPubSubSource { - ps := &v1alpha1.CloudPubSubSource{ +func NewCloudPubSubSource(name, namespace string, so ...CloudPubSubSourceOption) *v1beta1.CloudPubSubSource { + ps := &v1beta1.CloudPubSubSource{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, @@ -49,7 +49,7 @@ func NewCloudPubSubSource(name, namespace string, so ...CloudPubSubSourceOption) } func WithCloudPubSubSourceSink(gvk metav1.GroupVersionKind, name string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Spec.Sink = duckv1.Destination{ Ref: &duckv1.KReference{ APIVersion: apiVersion(gvk), @@ -61,42 +61,42 @@ func WithCloudPubSubSourceSink(gvk metav1.GroupVersionKind, name string) CloudPu } func WithCloudPubSubSourceServiceAccount(kServiceAccount string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Spec.ServiceAccountName = kServiceAccount } } -func WithCloudPubSubSourceDeletionTimestamp(s *v1alpha1.CloudPubSubSource) { +func WithCloudPubSubSourceDeletionTimestamp(s *v1beta1.CloudPubSubSource) { t := metav1.NewTime(time.Unix(1e9, 0)) s.ObjectMeta.SetDeletionTimestamp(&t) } func WithCloudPubSubSourceProject(project string) CloudPubSubSourceOption { - return func(s *v1alpha1.CloudPubSubSource) { + return func(s *v1beta1.CloudPubSubSource) { s.Spec.Project = project } } func WithCloudPubSubSourceTopic(topicID string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Spec.Topic = topicID } } // WithInitCloudPubSubSourceConditions initializes the CloudPubSubSource's conditions. -func WithInitCloudPubSubSourceConditions(ps *v1alpha1.CloudPubSubSource) { +func WithInitCloudPubSubSourceConditions(ps *v1beta1.CloudPubSubSource) { ps.Status.InitializeConditions() } // WithCloudPubSubSourceServiceAccountName will give status.ServiceAccountName a k8s service account name, which is related on Workload Identity's Google service account. func WithCloudPubSubSourceServiceAccountName(name string) CloudPubSubSourceOption { - return func(s *v1alpha1.CloudPubSubSource) { + return func(s *v1beta1.CloudPubSubSource) { s.Status.ServiceAccountName = name } } func WithCloudPubSubSourceWorkloadIdentityFailed(reason, message string) CloudPubSubSourceOption { - return func(s *v1alpha1.CloudPubSubSource) { + return func(s *v1beta1.CloudPubSubSource) { s.Status.MarkWorkloadIdentityFailed(s.ConditionSet(), reason, message) } } @@ -104,7 +104,7 @@ func WithCloudPubSubSourceWorkloadIdentityFailed(reason, message string) CloudPu // WithCloudPubSubSourcePullSubscriptionFailed marks the condition that the // status of PullSubscription is False func WithCloudPubSubSourcePullSubscriptionFailed(reason, message string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Status.MarkPullSubscriptionFailed(ps.ConditionSet(), reason, message) } } @@ -112,7 +112,7 @@ func WithCloudPubSubSourcePullSubscriptionFailed(reason, message string) CloudPu // WithCloudPubSubSourcePullSubscriptionUnknown marks the condition that the // topic is Unknown func WithCloudPubSubSourcePullSubscriptionUnknown(reason, message string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Status.MarkPullSubscriptionUnknown(ps.ConditionSet(), reason, message) } } @@ -120,50 +120,50 @@ func WithCloudPubSubSourcePullSubscriptionUnknown(reason, message string) CloudP // WithCloudPubSubSourcePullSubscriptionReady marks the condition that the // topic is not ready func WithCloudPubSubSourcePullSubscriptionReady() CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Status.MarkPullSubscriptionReady(ps.ConditionSet()) } } // WithCloudPubSubSourceSinkURI sets the status for sink URI func WithCloudPubSubSourceSinkURI(url *apis.URL) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Status.SinkURI = url } } func WithCloudPubSubSourceSubscriptionID(subscriptionID string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Status.SubscriptionID = subscriptionID } } func WithCloudPubSubSourceFinalizers(finalizers ...string) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Finalizers = finalizers } } func WithCloudPubSubSourceStatusObservedGeneration(generation int64) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.Status.Status.ObservedGeneration = generation } } func WithCloudPubSubSourceObjectMetaGeneration(generation int64) CloudPubSubSourceOption { - return func(ps *v1alpha1.CloudPubSubSource) { + return func(ps *v1beta1.CloudPubSubSource) { ps.ObjectMeta.Generation = generation } } func WithCloudPubSubSourceAnnotations(Annotations map[string]string) CloudPubSubSourceOption { - return func(s *v1alpha1.CloudPubSubSource) { + return func(s *v1beta1.CloudPubSubSource) { s.ObjectMeta.Annotations = Annotations } } func WithCloudPubSubSourceDefaultGCPAuth() CloudPubSubSourceOption { - return func(s *v1alpha1.CloudPubSubSource) { + return func(s *v1beta1.CloudPubSubSource) { s.Spec.PubSubSpec.SetPubSubDefaults(gcpauthtesthelper.ContextWithDefaults()) } } diff --git a/pkg/reconciler/testing/scheduler.go b/pkg/reconciler/testing/scheduler.go index 0336963509..8f378adf62 100644 --- a/pkg/reconciler/testing/scheduler.go +++ b/pkg/reconciler/testing/scheduler.go @@ -26,15 +26,15 @@ import ( "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" ) // CloudSchedulerSourceOption enables further configuration of a CloudSchedulerSource. -type CloudSchedulerSourceOption func(*v1alpha1.CloudSchedulerSource) +type CloudSchedulerSourceOption func(*v1beta1.CloudSchedulerSource) // NewCloudSchedulerSource creates a CloudSchedulerSource with CloudSchedulerSourceOptions -func NewCloudSchedulerSource(name, namespace string, so ...CloudSchedulerSourceOption) *v1alpha1.CloudSchedulerSource { - s := &v1alpha1.CloudSchedulerSource{ +func NewCloudSchedulerSource(name, namespace string, so ...CloudSchedulerSourceOption) *v1beta1.CloudSchedulerSource { + s := &v1beta1.CloudSchedulerSource{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, @@ -49,7 +49,7 @@ func NewCloudSchedulerSource(name, namespace string, so ...CloudSchedulerSourceO } func WithCloudSchedulerSourceSink(gvk metav1.GroupVersionKind, name string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Spec.Sink = duckv1.Destination{ Ref: &duckv1.KReference{ APIVersion: apiVersion(gvk), @@ -61,54 +61,54 @@ func WithCloudSchedulerSourceSink(gvk metav1.GroupVersionKind, name string) Clou } func WithCloudSchedulerSourceLocation(location string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Spec.Location = location } } func WithCloudSchedulerSourceProject(project string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Spec.Project = project } } func WithCloudSchedulerSourceSchedule(schedule string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Spec.Schedule = schedule } } func WithCloudSchedulerSourceServiceAccount(kServiceAccount string) CloudSchedulerSourceOption { - return func(ps *v1alpha1.CloudSchedulerSource) { + return func(ps *v1beta1.CloudSchedulerSource) { ps.Spec.ServiceAccountName = kServiceAccount } } func WithCloudSchedulerSourceData(data string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Spec.Data = data } } -func WithCloudSchedulerSourceDeletionTimestamp(s *v1alpha1.CloudSchedulerSource) { +func WithCloudSchedulerSourceDeletionTimestamp(s *v1beta1.CloudSchedulerSource) { t := metav1.NewTime(time.Unix(1e9, 0)) s.ObjectMeta.SetDeletionTimestamp(&t) } // WithInitCloudSchedulerSourceConditions initializes the CloudSchedulerSources's conditions. -func WithInitCloudSchedulerSourceConditions(s *v1alpha1.CloudSchedulerSource) { +func WithInitCloudSchedulerSourceConditions(s *v1beta1.CloudSchedulerSource) { s.Status.InitializeConditions() } // WithCloudSchedulerSourceServiceAccountName will give status.ServiceAccountName a k8s service account name, which is related on Workload Identity's Google service account. func WithCloudSchedulerSourceServiceAccountName(name string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.ServiceAccountName = name } } func WithCloudSchedulerSourceWorkloadIdentityFailed(reason, message string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.MarkWorkloadIdentityFailed(s.ConditionSet(), reason, message) } } @@ -116,7 +116,7 @@ func WithCloudSchedulerSourceWorkloadIdentityFailed(reason, message string) Clou // WithCloudSchedulerSourceTopicFailed marks the condition that the // status of topic is False. func WithCloudSchedulerSourceTopicFailed(reason, message string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.MarkTopicFailed(s.ConditionSet(), reason, message) } } @@ -124,7 +124,7 @@ func WithCloudSchedulerSourceTopicFailed(reason, message string) CloudSchedulerS // WithCloudSchedulerSourceTopicUnknown marks the condition that the // status of topic is Unknown. func WithCloudSchedulerSourceTopicUnknown(reason, message string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.MarkTopicUnknown(s.ConditionSet(), reason, message) } } @@ -132,7 +132,7 @@ func WithCloudSchedulerSourceTopicUnknown(reason, message string) CloudScheduler // WithCloudSchedulerSourceTopicNotReady marks the condition that the // topic is not ready. func WithCloudSchedulerSourceTopicReady(topicID, projectID string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.MarkTopicReady(s.ConditionSet()) s.Status.TopicID = topicID s.Status.ProjectID = projectID @@ -142,7 +142,7 @@ func WithCloudSchedulerSourceTopicReady(topicID, projectID string) CloudSchedule // WithCloudSchedulerSourcePullSubscriptionFailed marks the condition that the // topic is False. func WithCloudSchedulerSourcePullSubscriptionFailed(reason, message string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), reason, message) } } @@ -150,7 +150,7 @@ func WithCloudSchedulerSourcePullSubscriptionFailed(reason, message string) Clou // WithCloudSchedulerSourcePullSubscriptionUnknown marks the condition that the // topic is Unknown. func WithCloudSchedulerSourcePullSubscriptionUnknown(reason, message string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), reason, message) } } @@ -158,7 +158,7 @@ func WithCloudSchedulerSourcePullSubscriptionUnknown(reason, message string) Clo // WithCloudSchedulerSourcePullSubscriptionReady marks the condition that the // topic is ready. func WithCloudSchedulerSourcePullSubscriptionReady() CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.MarkPullSubscriptionReady(s.ConditionSet()) } } @@ -166,7 +166,7 @@ func WithCloudSchedulerSourcePullSubscriptionReady() CloudSchedulerSourceOption // WithCloudSchedulerSourceJobNotReady marks the condition that the // CloudSchedulerSource Job is not ready. func WithCloudSchedulerSourceJobNotReady(reason, message string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.MarkJobNotReady(reason, message) } } @@ -174,45 +174,45 @@ func WithCloudSchedulerSourceJobNotReady(reason, message string) CloudSchedulerS // WithCloudSchedulerSourceJobReady marks the condition that the // CloudSchedulerSource Job is ready and sets Status.JobName to jobName. func WithCloudSchedulerSourceJobReady(jobName string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.MarkJobReady(jobName) } } // WithCloudSchedulerSourceSinkURI sets the status for sink URI func WithCloudSchedulerSourceSinkURI(url *apis.URL) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.SinkURI = url } } func WithCloudSchedulerSourceSubscriptionID(subscriptionID string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.SubscriptionID = subscriptionID } } // WithCloudSchedulerSourceJobName sets the status for job Name func WithCloudSchedulerSourceJobName(jobName string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Status.JobName = jobName } } func WithCloudSchedulerSourceFinalizers(finalizers ...string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Finalizers = finalizers } } func WithCloudSchedulerSourceAnnotations(Annotations map[string]string) CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.ObjectMeta.Annotations = Annotations } } func WithCloudSchedulerSourceDefaultGCPAuth() CloudSchedulerSourceOption { - return func(s *v1alpha1.CloudSchedulerSource) { + return func(s *v1beta1.CloudSchedulerSource) { s.Spec.PubSubSpec.SetPubSubDefaults(gcpauthtesthelper.ContextWithDefaults()) } } diff --git a/pkg/reconciler/testing/storage.go b/pkg/reconciler/testing/storage.go index 4c3b70b1d6..16de28027b 100644 --- a/pkg/reconciler/testing/storage.go +++ b/pkg/reconciler/testing/storage.go @@ -26,23 +26,23 @@ import ( "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" "github.com/google/knative-gcp/pkg/gclient/metadata/testing" ) // CloudStorageSourceOption enables further configuration of a CloudStorageSource. -type CloudStorageSourceOption func(*v1alpha1.CloudStorageSource) +type CloudStorageSourceOption func(*v1beta1.CloudStorageSource) // NewCloudStorageSource creates a CloudStorageSource with CloudStorageSourceOptions -func NewCloudStorageSource(name, namespace string, so ...CloudStorageSourceOption) *v1alpha1.CloudStorageSource { - s := &v1alpha1.CloudStorageSource{ +func NewCloudStorageSource(name, namespace string, so ...CloudStorageSourceOption) *v1beta1.CloudStorageSource { + s := &v1beta1.CloudStorageSource{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, UID: "test-storage-uid", Annotations: map[string]string{ - duckv1alpha1.ClusterNameAnnotation: testing.FakeClusterName, + duckv1beta1.ClusterNameAnnotation: testing.FakeClusterName, }, }, } @@ -54,25 +54,25 @@ func NewCloudStorageSource(name, namespace string, so ...CloudStorageSourceOptio } func WithCloudStorageSourceBucket(bucket string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Spec.Bucket = bucket } } func WithCloudStorageSourceProject(project string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Spec.Project = project } } func WithCloudStorageSourceEventTypes(eventTypes []string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Spec.EventTypes = eventTypes } } func WithCloudStorageSourceSink(gvk metav1.GroupVersionKind, name string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Spec.Sink = duckv1.Destination{ Ref: &duckv1.KReference{ APIVersion: apiVersion(gvk), @@ -84,31 +84,31 @@ func WithCloudStorageSourceSink(gvk metav1.GroupVersionKind, name string) CloudS } func WithCloudStorageSourceSinkDestination(sink duckv1.Destination) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Spec.Sink = sink } } // WithInitCloudStorageSourceConditions initializes the CloudStorageSources's conditions. -func WithInitCloudStorageSourceConditions(s *v1alpha1.CloudStorageSource) { +func WithInitCloudStorageSourceConditions(s *v1beta1.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) { + return func(s *v1beta1.CloudStorageSource) { s.Status.ServiceAccountName = name } } func WithCloudStorageSourceWorkloadIdentityFailed(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.MarkWorkloadIdentityFailed(s.ConditionSet(), reason, message) } } func WithCloudStorageSourceServiceAccount(kServiceAccount string) CloudStorageSourceOption { - return func(ps *v1alpha1.CloudStorageSource) { + return func(ps *v1beta1.CloudStorageSource) { ps.Spec.ServiceAccountName = kServiceAccount } } @@ -116,7 +116,7 @@ func WithCloudStorageSourceServiceAccount(kServiceAccount string) CloudStorageSo // WithCloudStorageSourceTopicFailed marks the condition that the // topic is False func WithCloudStorageSourceTopicFailed(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.MarkTopicFailed(s.ConditionSet(), reason, message) } } @@ -124,7 +124,7 @@ func WithCloudStorageSourceTopicFailed(reason, message string) CloudStorageSourc // WithCloudStorageSourceTopicUnknown marks the condition that the // topic is False func WithCloudStorageSourceTopicUnknown(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.MarkTopicUnknown(s.ConditionSet(), reason, message) } } @@ -132,14 +132,14 @@ func WithCloudStorageSourceTopicUnknown(reason, message string) CloudStorageSour // WithCloudStorageSourceTopicNotReady marks the condition that the // topic is not ready func WithCloudStorageSourceTopicReady(topicID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.MarkTopicReady(s.ConditionSet()) s.Status.TopicID = topicID } } func WithCloudStorageSourceTopicID(topicID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.TopicID = topicID } } @@ -147,7 +147,7 @@ func WithCloudStorageSourceTopicID(topicID string) CloudStorageSourceOption { // WithCloudStorageSourcePullSubscriptionFailed marks the condition that the // status of topic is False func WithCloudStorageSourcePullSubscriptionFailed(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.MarkPullSubscriptionFailed(s.ConditionSet(), reason, message) } } @@ -155,7 +155,7 @@ func WithCloudStorageSourcePullSubscriptionFailed(reason, message string) CloudS // WithCloudStorageSourcePullSubscriptionUnknown marks the condition that the // status of topic is Unknown. func WithCloudStorageSourcePullSubscriptionUnknown(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), reason, message) } } @@ -163,7 +163,7 @@ func WithCloudStorageSourcePullSubscriptionUnknown(reason, message string) Cloud // WithCloudStorageSourcePullSubscriptionReady marks the condition that the // topic is ready. func WithCloudStorageSourcePullSubscriptionReady() CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.MarkPullSubscriptionReady(s.ConditionSet()) } } @@ -171,7 +171,7 @@ func WithCloudStorageSourcePullSubscriptionReady() CloudStorageSourceOption { // WithCloudStorageSourceNotificationNotReady marks the condition that the // GCS Notification is not ready. func WithCloudStorageSourceNotificationNotReady(reason, message string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.MarkNotificationNotReady(reason, message) } } @@ -179,65 +179,65 @@ func WithCloudStorageSourceNotificationNotReady(reason, message string) CloudSto // WithCloudStorageSourceNotificationReady marks the condition that the GCS // Notification is ready. func WithCloudStorageSourceNotificationReady(notificationID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.MarkNotificationReady(notificationID) } } // WithCloudStorageSourceSinkURI sets the status for sink URI func WithCloudStorageSourceSinkURI(url *apis.URL) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.SinkURI = url } } // WithCloudStorageSourceNotificationId sets the status for Notification ID func WithCloudStorageSourceNotificationID(notificationID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.NotificationID = notificationID } } // WithCloudStorageSourceProjectId sets the status for Project ID func WithCloudStorageSourceProjectID(projectID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.ProjectID = projectID } } func WithCloudStorageSourceSubscriptionID(subscriptionID string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.SubscriptionID = subscriptionID } } func WithCloudStorageSourceStatusObservedGeneration(generation int64) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Status.Status.ObservedGeneration = generation } } func WithCloudStorageSourceObjectMetaGeneration(generation int64) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.ObjectMeta.Generation = generation } } func WithDeletionTimestamp() CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { ts := metav1.NewTime(time.Unix(1e9, 0)) s.DeletionTimestamp = &ts } } func WithCloudStorageSourceAnnotations(Annotations map[string]string) CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.ObjectMeta.Annotations = Annotations } } func WithCloudStorageSourceDefaultGCPAuth() CloudStorageSourceOption { - return func(s *v1alpha1.CloudStorageSource) { + return func(s *v1beta1.CloudStorageSource) { s.Spec.PubSubSpec.SetPubSubDefaults(gcpauthtesthelper.ContextWithDefaults()) } } diff --git a/test/e2e/lib/creation.go b/test/e2e/lib/creation.go index bcb6976512..f6aaacd956 100644 --- a/test/e2e/lib/creation.go +++ b/test/e2e/lib/creation.go @@ -25,9 +25,9 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "knative.dev/eventing/test/lib/resources" - eventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" - inteventsv1alpha1 "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" - messagingv1alpha1 "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" + eventsv1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + messagingv1beta1 "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" ) func (c *Client) CreateUnstructuredObjOrFail(spec *unstructured.Unstructured) { @@ -41,9 +41,9 @@ func (c *Client) CreateUnstructuredObjOrFail(spec *unstructured.Unstructured) { c.Tracker.Add(gvr.Group, gvr.Version, gvr.Resource, c.Namespace, spec.GetName()) } -func (c *Client) CreateChannelOrFail(channel *messagingv1alpha1.Channel) { +func (c *Client) CreateChannelOrFail(channel *messagingv1beta1.Channel) { c.T.Helper() - channels := c.KnativeGCP.MessagingV1alpha1().Channels(c.Namespace) + channels := c.KnativeGCP.MessagingV1beta1().Channels(c.Namespace) _, err := channels.Create(channel) if err != nil { c.T.Fatalf("Failed to create channel %s/%s: %v", c.Namespace, channel.Name, err) @@ -52,9 +52,9 @@ func (c *Client) CreateChannelOrFail(channel *messagingv1alpha1.Channel) { c.Tracker.AddObj(channel) } -func (c *Client) CreateAuditLogsOrFail(auditlogs *eventsv1alpha1.CloudAuditLogsSource) { +func (c *Client) CreateAuditLogsOrFail(auditlogs *eventsv1beta1.CloudAuditLogsSource) { c.T.Helper() - auditlogses := c.KnativeGCP.EventsV1alpha1().CloudAuditLogsSources(c.Namespace) + auditlogses := c.KnativeGCP.EventsV1beta1().CloudAuditLogsSources(c.Namespace) _, err := auditlogses.Create(auditlogs) if err != nil { c.T.Fatalf("Failed to create auditlogs %s/%s: %v", c.Namespace, auditlogs.Name, err) @@ -63,9 +63,9 @@ func (c *Client) CreateAuditLogsOrFail(auditlogs *eventsv1alpha1.CloudAuditLogsS c.Tracker.AddObj(auditlogs) } -func (c *Client) CreatePubSubOrFail(pubsub *eventsv1alpha1.CloudPubSubSource) { +func (c *Client) CreatePubSubOrFail(pubsub *eventsv1beta1.CloudPubSubSource) { c.T.Helper() - pubsubs := c.KnativeGCP.EventsV1alpha1().CloudPubSubSources(c.Namespace) + pubsubs := c.KnativeGCP.EventsV1beta1().CloudPubSubSources(c.Namespace) _, err := pubsubs.Create(pubsub) if err != nil { c.T.Fatalf("Failed to create pubsub %s/%s: %v", c.Namespace, pubsub.Name, err) @@ -74,9 +74,9 @@ func (c *Client) CreatePubSubOrFail(pubsub *eventsv1alpha1.CloudPubSubSource) { c.Tracker.AddObj(pubsub) } -func (c *Client) CreateStorageOrFail(storage *eventsv1alpha1.CloudStorageSource) { +func (c *Client) CreateStorageOrFail(storage *eventsv1beta1.CloudStorageSource) { c.T.Helper() - storages := c.KnativeGCP.EventsV1alpha1().CloudStorageSources(c.Namespace) + storages := c.KnativeGCP.EventsV1beta1().CloudStorageSources(c.Namespace) _, err := storages.Create(storage) if err != nil { c.T.Fatalf("Failed to create storage %s/%s: %v", c.Namespace, storage.Name, err) @@ -85,9 +85,9 @@ func (c *Client) CreateStorageOrFail(storage *eventsv1alpha1.CloudStorageSource) c.Tracker.AddObj(storage) } -func (c *Client) CreatePullSubscriptionOrFail(pullsubscription *inteventsv1alpha1.PullSubscription) { +func (c *Client) CreatePullSubscriptionOrFail(pullsubscription *inteventsv1beta1.PullSubscription) { c.T.Helper() - pullsubscriptions := c.KnativeGCP.InternalV1alpha1().PullSubscriptions(c.Namespace) + pullsubscriptions := c.KnativeGCP.InternalV1beta1().PullSubscriptions(c.Namespace) _, err := pullsubscriptions.Create(pullsubscription) if err != nil { c.T.Fatalf("Failed to create pullsubscription %s/%s: %v", c.Namespace, pullsubscription.Name, err) @@ -96,9 +96,9 @@ func (c *Client) CreatePullSubscriptionOrFail(pullsubscription *inteventsv1alpha c.Tracker.AddObj(pullsubscription) } -func (c *Client) CreateSchedulerOrFail(scheduler *eventsv1alpha1.CloudSchedulerSource) { +func (c *Client) CreateSchedulerOrFail(scheduler *eventsv1beta1.CloudSchedulerSource) { c.T.Helper() - schedulers := c.KnativeGCP.EventsV1alpha1().CloudSchedulerSources(c.Namespace) + schedulers := c.KnativeGCP.EventsV1beta1().CloudSchedulerSources(c.Namespace) _, err := schedulers.Create(scheduler) if err != nil { c.T.Fatalf("Failed to create scheduler %s/%s: %v", c.Namespace, scheduler.Name, err) diff --git a/test/e2e/test_pullsubscription.go b/test/e2e/test_pullsubscription.go index 1af65a84ad..91bbe3ca1f 100644 --- a/test/e2e/test_pullsubscription.go +++ b/test/e2e/test_pullsubscription.go @@ -27,9 +27,9 @@ import ( // The following line to load the gcp plugin (only required to authenticate against GKE clusters). _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1" + duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" kngcptesting "github.com/google/knative-gcp/pkg/reconciler/testing" "github.com/google/knative-gcp/test/e2e/lib" ) @@ -48,10 +48,10 @@ func SmokePullSubscriptionTestImpl(t *testing.T, authConfig lib.AuthConfig) { // Create PullSubscription. pullsubscription := kngcptesting.NewPullSubscription(psName, client.Namespace, - kngcptesting.WithPullSubscriptionSpec(v1alpha1.PullSubscriptionSpec{ + kngcptesting.WithPullSubscriptionSpec(v1beta1.PullSubscriptionSpec{ Topic: topic, - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ + IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: authConfig.ServiceAccountName, }, }, @@ -82,10 +82,10 @@ func PullSubscriptionWithTargetTestImpl(t *testing.T, authConfig lib.AuthConfig) // Create PullSubscription. pullsubscription := kngcptesting.NewPullSubscription(psName, client.Namespace, - kngcptesting.WithPullSubscriptionSpec(v1alpha1.PullSubscriptionSpec{ + kngcptesting.WithPullSubscriptionSpec(v1beta1.PullSubscriptionSpec{ Topic: topicName, - PubSubSpec: duckv1alpha1.PubSubSpec{ - IdentitySpec: duckv1alpha1.IdentitySpec{ + PubSubSpec: duckv1beta1.PubSubSpec{ + IdentitySpec: duckv1beta1.IdentitySpec{ ServiceAccountName: authConfig.ServiceAccountName, }, }, From 8c7b9c37d67f87b4455e8ced625fa69738cd1df1 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Wed, 10 Jun 2020 18:44:49 -0700 Subject: [PATCH 04/14] fixed most ut tests --- .../events/build/controller_test.go | 6 +- pkg/reconciler/messaging/channel/channel.go | 29 ++-- .../messaging/channel/channel_test.go | 135 +++++++++--------- pkg/reconciler/testing/build.go | 42 +++--- pkg/reconciler/testing/listers.go | 2 +- test/e2e/test_pullsubscription.go | 12 +- 6 files changed, 116 insertions(+), 110 deletions(-) diff --git a/pkg/reconciler/events/build/controller_test.go b/pkg/reconciler/events/build/controller_test.go index ca778133b6..9e9866b392 100644 --- a/pkg/reconciler/events/build/controller_test.go +++ b/pkg/reconciler/events/build/controller_test.go @@ -25,10 +25,10 @@ import ( . "knative.dev/pkg/reconciler/testing" // Fake injection informers - _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1alpha1/fake" + _ "github.com/google/knative-gcp/pkg/client/clientset/versioned/typed/intevents/v1beta1/fake" _ "github.com/google/knative-gcp/pkg/client/injection/client/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1alpha1/cloudbuildsource/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/pullsubscription/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/events/v1beta1/cloudbuildsource/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription/fake" _ "github.com/google/knative-gcp/pkg/reconciler/testing" _ "knative.dev/pkg/client/injection/kube/informers/batch/v1/job/fake" _ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/fake" diff --git a/pkg/reconciler/messaging/channel/channel.go b/pkg/reconciler/messaging/channel/channel.go index e91a049890..5f20b08bfa 100644 --- a/pkg/reconciler/messaging/channel/channel.go +++ b/pkg/reconciler/messaging/channel/channel.go @@ -104,11 +104,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, channel *v1beta1.Channel } func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1beta1.Channel) error { - if equality.Semantic.DeepEqual(channel.Status.SubscribableStatus, eventingduckv1beta1.SubscribableStatus{}) { - channel.Status.SubscribableStatus = eventingduckv1beta1.SubscribableStatus{ - Subscribers: make([]eventingduckv1beta1.SubscriberStatus, 0), - } - } else if channel.Status.SubscribableStatus.Subscribers == nil { + //if equality.Semantic.DeepEqual(channel.Status.SubscribableStatus, eventingduckv1beta1.SubscribableStatus{}) { + // channel.Status.SubscribableStatus = eventingduckv1beta1.SubscribableStatus{ + // Subscribers: make([]eventingduckv1beta1.SubscriberStatus, 0), + // } + //} else if channel.Status.SubscribableStatus.Subscribers == nil { + // channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0) + //} + if channel.Status.SubscribableStatus.Subscribers == nil { channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0) } @@ -261,13 +264,15 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1beta1.Chann } func (r *Reconciler) syncSubscribersStatus(ctx context.Context, channel *v1beta1.Channel) error { - if equality.Semantic.DeepEqual(channel.Status.SubscribableStatus, eventingduckv1beta1.SubscribableStatus{}){ - channel.Status.SubscribableStatus = eventingduckv1beta1.SubscribableStatus{ - Subscribers: make([]eventingduckv1beta1.SubscriberStatus, 0), - } - } else if channel.Status.SubscribableStatus.Subscribers == nil { - channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0) - } + //if equality.Semantic.DeepEqual(channel.Status.SubscribableStatus, eventingduckv1beta1.SubscribableStatus{}){ + // channel.Status.SubscribableStatus = eventingduckv1beta1.SubscribableStatus{ + // Subscribers: make([]eventingduckv1beta1.SubscriberStatus, 0), + // } + //} else if channel.Status.SubscribableStatus.Subscribers == nil { + // channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0) + //} + if channel.Status.SubscribableStatus.Subscribers == nil { + channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0)} // Make a map of subscriber name to PullSubscription for lookup. pullsubs := make(map[string]inteventsv1beta1.PullSubscription) diff --git a/pkg/reconciler/messaging/channel/channel_test.go b/pkg/reconciler/messaging/channel/channel_test.go index 7c4ce9cf26..84b7b94b30 100644 --- a/pkg/reconciler/messaging/channel/channel_test.go +++ b/pkg/reconciler/messaging/channel/channel_test.go @@ -587,70 +587,71 @@ func newPullSubscriptionWithOwner(subscriber eventingduckv1beta1.SubscriberSpec, } -//// TODO add a unit test for successfully creating a k8s service account, after issue https://github.com/google/knative-gcp/issues/657 gets solved. -//func TestDEBUG(t *testing.T) { -// table := TableTest{ { -// Name: "subscriber already exists owned by other channel", -// Objects: []runtime.Object{ -// NewChannel(channelName, testNS, -// WithChannelUID(channelUID), -// WithChannelSpec(v1beta1.ChannelSpec{ -// Project: testProject, -// }), -// WithInitChannelConditions, -// WithChannelDefaults, -// WithChannelTopic(testTopicID), -// WithChannelAddress(topicURI), -// WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ -// {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, -// }), -// ), -// newReadyTopic(), -// newPullSubscriptionWithOwner( -// eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, -// NewChannel("other-channel", testNS, WithChannelUID("other-id"), WithInitChannelConditions), -// ), -// }, -// Key: testNS + "/" + channelName, -// WantEvents: []string{ -// Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", channelName), -// Eventf(corev1.EventTypeWarning, "SubscriberNotOwned", "Subscriber %q is not owned by this channel", "cre-sub-testsubscription-abc-123"), -// Eventf(corev1.EventTypeWarning, reconciledSubscribersFailedReason, "Reconcile Subscribers failed with: channel %q does not own subscriber %q", channelName, "cre-sub-testsubscription-abc-123"), -// }, -// WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ -// Object: NewChannel(channelName, testNS, -// WithChannelUID(channelUID), -// WithChannelSpec(v1beta1.ChannelSpec{ -// Project: testProject, -// }), -// WithInitChannelConditions, -// WithChannelDefaults, -// WithChannelTopic(testTopicID), -// WithChannelAddress(topicURI), -// WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ -// {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, -// }), -// // Updates -// WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{}), -// ), -// }}, -// WantCreates: []runtime.Object{ -// newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), -// }, -// WantPatches: []clientgotesting.PatchActionImpl{ -// patchFinalizers(testNS, channelName, true), -// }, -// }} -// -// defer logtesting.ClearAll() -// table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher, _ map[string]interface{}) controller.Reconciler { -// r := &Reconciler{ -// Base: reconciler.NewBase(ctx, controllerAgentName, cmw), -// Identity: identity.NewIdentity(ctx, NoopIAMPolicyManager, NewGCPAuthTestStore(t, nil)), -// channelLister: listers.GetChannelLister(), -// topicLister: listers.GetTopicLister(), -// } -// return channel.NewReconciler(ctx, r.Logger, r.RunClientSet, listers.GetChannelLister(), r.Recorder, r) -// })) -// -//} \ No newline at end of file +// TODO add a unit test for successfully creating a k8s service account, after issue https://github.com/google/knative-gcp/issues/657 gets solved. +func TestDEBUG(t *testing.T) { + table := TableTest{ { + Name: "subscriber already exists owned by other channel", + Objects: []runtime.Object{ + NewChannel(channelName, testNS, + WithChannelUID(channelUID), + WithChannelSpec(v1beta1.ChannelSpec{ + Project: testProject, + }), + WithInitChannelConditions, + WithChannelDefaults, + WithChannelTopic(testTopicID), + WithChannelAddress(topicURI), + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ + {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, + }), + ), + newReadyTopic(), + newPullSubscriptionWithOwner( + eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, + NewChannel("other-channel", testNS, WithChannelUID("other-id"), WithInitChannelConditions), + ), + }, + Key: testNS + "/" + channelName, + WantEvents: []string{ + Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", channelName), + Eventf(corev1.EventTypeWarning, "SubscriberNotOwned", "Subscriber %q is not owned by this channel", "cre-sub-testsubscription-abc-123"), + Eventf(corev1.EventTypeWarning, reconciledSubscribersFailedReason, "Reconcile Subscribers failed with: channel %q does not own subscriber %q", channelName, "cre-sub-testsubscription-abc-123"), + }, + WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ + Object: NewChannel(channelName, testNS, + WithChannelUID(channelUID), + WithChannelSpec(v1beta1.ChannelSpec{ + Project: testProject, + }), + WithInitChannelConditions, + WithChannelDefaults, + WithChannelTopic(testTopicID), + WithChannelAddress(topicURI), + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ + {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, + }), + // Updates + WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus(nil)), + + ), + }}, + WantCreates: []runtime.Object{ + newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), + }, + WantPatches: []clientgotesting.PatchActionImpl{ + patchFinalizers(testNS, channelName, true), + }, + }} + + defer logtesting.ClearAll() + table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher, _ map[string]interface{}) controller.Reconciler { + r := &Reconciler{ + Base: reconciler.NewBase(ctx, controllerAgentName, cmw), + Identity: identity.NewIdentity(ctx, NoopIAMPolicyManager, NewGCPAuthTestStore(t, nil)), + channelLister: listers.GetChannelLister(), + topicLister: listers.GetTopicLister(), + } + return channel.NewReconciler(ctx, r.Logger, r.RunClientSet, listers.GetChannelLister(), r.Recorder, r) + })) + +} \ No newline at end of file diff --git a/pkg/reconciler/testing/build.go b/pkg/reconciler/testing/build.go index eee3a6cb4b..70a8f3cc5c 100644 --- a/pkg/reconciler/testing/build.go +++ b/pkg/reconciler/testing/build.go @@ -28,15 +28,15 @@ import ( "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" - "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" ) // CloudBuildSourceOption enables further configuration of a CloudBuildSource. -type CloudBuildSourceOption func(*v1alpha1.CloudBuildSource) +type CloudBuildSourceOption func(*v1beta1.CloudBuildSource) // NewCloudBuildSource creates a CloudBuildSource with CloudBuildSourceOptions -func NewCloudBuildSource(name, namespace string, so ...CloudBuildSourceOption) *v1alpha1.CloudBuildSource { - bs := &v1alpha1.CloudBuildSource{ +func NewCloudBuildSource(name, namespace string, so ...CloudBuildSourceOption) *v1beta1.CloudBuildSource { + bs := &v1beta1.CloudBuildSource{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, @@ -51,7 +51,7 @@ func NewCloudBuildSource(name, namespace string, so ...CloudBuildSourceOption) * } func WithCloudBuildSourceSink(gvk metav1.GroupVersionKind, name string) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.Spec.Sink = duckv1.Destination{ Ref: &duckv1.KReference{ APIVersion: apiVersion(gvk), @@ -62,37 +62,37 @@ func WithCloudBuildSourceSink(gvk metav1.GroupVersionKind, name string) CloudBui } } -func WithCloudBuildSourceDeletionTimestamp(s *v1alpha1.CloudBuildSource) { +func WithCloudBuildSourceDeletionTimestamp(s *v1beta1.CloudBuildSource) { t := metav1.NewTime(time.Unix(1e9, 0)) s.ObjectMeta.SetDeletionTimestamp(&t) } func WithCloudBuildSourceProject(project string) CloudBuildSourceOption { - return func(s *v1alpha1.CloudBuildSource) { + return func(s *v1beta1.CloudBuildSource) { s.Spec.Project = project } } func WithCloudBuildSourceTopic(topicID string) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.Spec.Topic = ptr.String(topicID) } } // WithInitCloudBuildSourceConditions initializes the CloudBuildSource's conditions. -func WithInitCloudBuildSourceConditions(bs *v1alpha1.CloudBuildSource) { +func WithInitCloudBuildSourceConditions(bs *v1beta1.CloudBuildSource) { bs.Status.InitializeConditions() } // WithCloudBuildSourceServiceAccountName will give status.ServiceAccountName a k8s service account name, which is related on Workload Identity's Google service account. func WithCloudBuildSourceServiceAccountName(name string) CloudBuildSourceOption { - return func(s *v1alpha1.CloudBuildSource) { + return func(s *v1beta1.CloudBuildSource) { s.Status.ServiceAccountName = name } } func WithCloudBuildSourceWorkloadIdentityFailed(reason, message string) CloudBuildSourceOption { - return func(s *v1alpha1.CloudBuildSource) { + return func(s *v1beta1.CloudBuildSource) { s.Status.MarkWorkloadIdentityFailed(s.ConditionSet(), reason, message) } } @@ -100,7 +100,7 @@ func WithCloudBuildSourceWorkloadIdentityFailed(reason, message string) CloudBui // WithCloudBuildSourcePullSubscriptionFailed marks the condition that the // status of PullSubscription is False func WithCloudBuildSourcePullSubscriptionFailed(reason, message string) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.Status.MarkPullSubscriptionFailed(bs.ConditionSet(), reason, message) } } @@ -108,7 +108,7 @@ func WithCloudBuildSourcePullSubscriptionFailed(reason, message string) CloudBui // WithCloudBuildSourcePullSubscriptionUnknown marks the condition that the // topic is Unknown func WithCloudBuildSourcePullSubscriptionUnknown(reason, message string) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.Status.MarkPullSubscriptionUnknown(bs.ConditionSet(), reason, message) } } @@ -116,50 +116,50 @@ func WithCloudBuildSourcePullSubscriptionUnknown(reason, message string) CloudBu // WithCloudBuildSourcePullSubscriptionReady marks the condition that the // topic is not ready func WithCloudBuildSourcePullSubscriptionReady() CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.Status.MarkPullSubscriptionReady(bs.ConditionSet()) } } // WithCloudBuildSourceSinkURI sets the status for sink URI func WithCloudBuildSourceSinkURI(url *apis.URL) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.Status.SinkURI = url } } func WithCloudBuildSourceSubscriptionID(subscriptionID string) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.Status.SubscriptionID = subscriptionID } } func WithCloudBuildSourceFinalizers(finalizers ...string) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.Finalizers = finalizers } } func WithCloudBuildSourceStatusObservedGeneration(generation int64) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.Status.Status.ObservedGeneration = generation } } func WithCloudBuildSourceObjectMetaGeneration(generation int64) CloudBuildSourceOption { - return func(bs *v1alpha1.CloudBuildSource) { + return func(bs *v1beta1.CloudBuildSource) { bs.ObjectMeta.Generation = generation } } func WithCloudBuildSourceAnnotations(Annotations map[string]string) CloudBuildSourceOption { - return func(s *v1alpha1.CloudBuildSource) { + return func(s *v1beta1.CloudBuildSource) { s.ObjectMeta.Annotations = Annotations } } func WithCloudBuildSourceDefaultGCPAuth() CloudBuildSourceOption { - return func(s *v1alpha1.CloudBuildSource) { + return func(s *v1beta1.CloudBuildSource) { s.Spec.PubSubSpec.SetPubSubDefaults(gcpauthtesthelper.ContextWithDefaults()) } } diff --git a/pkg/reconciler/testing/listers.go b/pkg/reconciler/testing/listers.go index 5e3f43a37a..dae31cb9e2 100644 --- a/pkg/reconciler/testing/listers.go +++ b/pkg/reconciler/testing/listers.go @@ -44,7 +44,7 @@ import ( fakeservingclientset "knative.dev/serving/pkg/client/clientset/versioned/fake" brokerv1beta1 "github.com/google/knative-gcp/pkg/apis/broker/v1beta1" - EventsV1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1alpha1" + EventsV1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" intv1alpha1 "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" diff --git a/test/e2e/test_pullsubscription.go b/test/e2e/test_pullsubscription.go index 91bbe3ca1f..46b90ccab5 100644 --- a/test/e2e/test_pullsubscription.go +++ b/test/e2e/test_pullsubscription.go @@ -28,8 +28,8 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" - "github.com/google/knative-gcp/pkg/apis/events/v1beta1" - "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" + eventsv1beta1 "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + inteventsv1beta1 "github.com/google/knative-gcp/pkg/apis/intevents/v1beta1" kngcptesting "github.com/google/knative-gcp/pkg/reconciler/testing" "github.com/google/knative-gcp/test/e2e/lib" ) @@ -48,7 +48,7 @@ func SmokePullSubscriptionTestImpl(t *testing.T, authConfig lib.AuthConfig) { // Create PullSubscription. pullsubscription := kngcptesting.NewPullSubscription(psName, client.Namespace, - kngcptesting.WithPullSubscriptionSpec(v1beta1.PullSubscriptionSpec{ + kngcptesting.WithPullSubscriptionSpec(inteventsv1beta1.PullSubscriptionSpec{ Topic: topic, PubSubSpec: duckv1beta1.PubSubSpec{ IdentitySpec: duckv1beta1.IdentitySpec{ @@ -71,18 +71,18 @@ func PullSubscriptionWithTargetTestImpl(t *testing.T, authConfig lib.AuthConfig) psName := topicName + "-sub" targetName := topicName + "-target" - source := v1beta1.CloudPubSubSourceEventSource(project, topicName) + source := eventsv1beta1.CloudPubSubSourceEventSource(project, topicName) data := fmt.Sprintf(`{"topic":%s}`, topicName) client := lib.Setup(t, true, authConfig.WorkloadIdentity) defer lib.TearDown(client) // Create a target Job to receive the events. - lib.MakePubSubTargetJobOrDie(client, source, targetName, v1beta1.CloudPubSubSourcePublish) + lib.MakePubSubTargetJobOrDie(client, source, targetName, eventsv1beta1.CloudPubSubSourcePublish) // Create PullSubscription. pullsubscription := kngcptesting.NewPullSubscription(psName, client.Namespace, - kngcptesting.WithPullSubscriptionSpec(v1beta1.PullSubscriptionSpec{ + kngcptesting.WithPullSubscriptionSpec(inteventsv1beta1.PullSubscriptionSpec{ Topic: topicName, PubSubSpec: duckv1beta1.PubSubSpec{ IdentitySpec: duckv1beta1.IdentitySpec{ From a5182c684a7569f71eca9ec1d7b275f9c8540491 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Wed, 10 Jun 2020 20:13:02 -0700 Subject: [PATCH 05/14] fixed channel unit tests --- .../messaging/channel/channel_test.go | 157 ++++-------------- 1 file changed, 35 insertions(+), 122 deletions(-) diff --git a/pkg/reconciler/messaging/channel/channel_test.go b/pkg/reconciler/messaging/channel/channel_test.go index 84b7b94b30..e62f2c188b 100644 --- a/pkg/reconciler/messaging/channel/channel_test.go +++ b/pkg/reconciler/messaging/channel/channel_test.go @@ -333,58 +333,41 @@ func TestAllCases(t *testing.T) { patchFinalizers(testNS, channelName, true), }, }, - //{ - // Name: "subscriber already exists owned by other channel", - // Objects: []runtime.Object{ - // NewChannel(channelName, testNS, - // WithChannelUID(channelUID), - // WithChannelSpec(v1beta1.ChannelSpec{ - // Project: testProject, - // }), - // WithInitChannelConditions, - // WithChannelDefaults, - // WithChannelTopic(testTopicID), - // WithChannelAddress(topicURI), - // WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ - // {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, - // }), - // ), - // newReadyTopic(), - // newPullSubscriptionWithOwner( - // eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, - // NewChannel("other-channel", testNS, WithChannelUID("other-id"), WithInitChannelConditions), - // ), - // }, - // Key: testNS + "/" + channelName, - // WantEvents: []string{ - // Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", channelName), - // Eventf(corev1.EventTypeWarning, "SubscriberNotOwned", "Subscriber %q is not owned by this channel", "cre-sub-testsubscription-abc-123"), - // Eventf(corev1.EventTypeWarning, reconciledSubscribersFailedReason, "Reconcile Subscribers failed with: channel %q does not own subscriber %q", channelName, "cre-sub-testsubscription-abc-123"), - // }, - // WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - // Object: NewChannel(channelName, testNS, - // WithChannelUID(channelUID), - // WithChannelSpec(v1beta1.ChannelSpec{ - // Project: testProject, - // }), - // WithInitChannelConditions, - // WithChannelDefaults, - // WithChannelTopic(testTopicID), - // WithChannelAddress(topicURI), - // WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ - // {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, - // }), - // // Updates - // WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus{}), - // ), - // }}, - // WantCreates: []runtime.Object{ - // newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), - // }, - // WantPatches: []clientgotesting.PatchActionImpl{ - // patchFinalizers(testNS, channelName, true), - // }, - //}, + { + Name: "subscriber already exists owned by other channel", + Objects: []runtime.Object{ + NewChannel(channelName, testNS, + WithChannelUID(channelUID), + WithChannelSpec(v1beta1.ChannelSpec{ + Project: testProject, + }), + WithInitChannelConditions, + WithChannelDefaults, + WithChannelTopic(testTopicID), + WithChannelAddress(topicURI), + WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ + {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, + }), + ), + newReadyTopic(), + newPullSubscriptionWithOwner( + eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, + NewChannel("other-channel", testNS, WithChannelUID("other-id"), WithInitChannelConditions), + ), + }, + Key: testNS + "/" + channelName, + WantEvents: []string{ + Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", channelName), + Eventf(corev1.EventTypeWarning, "SubscriberNotOwned", "Subscriber %q is not owned by this channel", "cre-sub-testsubscription-abc-123"), + Eventf(corev1.EventTypeWarning, reconciledSubscribersFailedReason, "Reconcile Subscribers failed with: channel %q does not own subscriber %q", channelName, "cre-sub-testsubscription-abc-123"), + }, + WantCreates: []runtime.Object{ + newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), + }, + WantPatches: []clientgotesting.PatchActionImpl{ + patchFinalizers(testNS, channelName, true), + }, + }, { Name: "subscriber already exists in status owned by other channel", Objects: []runtime.Object{ @@ -584,74 +567,4 @@ func newPullSubscriptionWithOwner(subscriber eventingduckv1beta1.SubscriberSpec, Annotations: resources.GetPullSubscriptionAnnotations(channel.Name, channel.GetAnnotations()[duckv1beta1.ClusterNameAnnotation]), Subscriber: subscriber, }) -} - - -// TODO add a unit test for successfully creating a k8s service account, after issue https://github.com/google/knative-gcp/issues/657 gets solved. -func TestDEBUG(t *testing.T) { - table := TableTest{ { - Name: "subscriber already exists owned by other channel", - Objects: []runtime.Object{ - NewChannel(channelName, testNS, - WithChannelUID(channelUID), - WithChannelSpec(v1beta1.ChannelSpec{ - Project: testProject, - }), - WithInitChannelConditions, - WithChannelDefaults, - WithChannelTopic(testTopicID), - WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ - {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, - }), - ), - newReadyTopic(), - newPullSubscriptionWithOwner( - eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, - NewChannel("other-channel", testNS, WithChannelUID("other-id"), WithInitChannelConditions), - ), - }, - Key: testNS + "/" + channelName, - WantEvents: []string{ - Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", channelName), - Eventf(corev1.EventTypeWarning, "SubscriberNotOwned", "Subscriber %q is not owned by this channel", "cre-sub-testsubscription-abc-123"), - Eventf(corev1.EventTypeWarning, reconciledSubscribersFailedReason, "Reconcile Subscribers failed with: channel %q does not own subscriber %q", channelName, "cre-sub-testsubscription-abc-123"), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewChannel(channelName, testNS, - WithChannelUID(channelUID), - WithChannelSpec(v1beta1.ChannelSpec{ - Project: testProject, - }), - WithInitChannelConditions, - WithChannelDefaults, - WithChannelTopic(testTopicID), - WithChannelAddress(topicURI), - WithChannelSubscribers([]eventingduckv1beta1.SubscriberSpec{ - {UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}, - }), - // Updates - WithChannelSubscribersStatus([]eventingduckv1beta1.SubscriberStatus(nil)), - - ), - }}, - WantCreates: []runtime.Object{ - newPullSubscription(eventingduckv1beta1.SubscriberSpec{UID: subscriptionUID, SubscriberURI: subscriberURI, ReplyURI: replyURI}), - }, - WantPatches: []clientgotesting.PatchActionImpl{ - patchFinalizers(testNS, channelName, true), - }, - }} - - defer logtesting.ClearAll() - table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher, _ map[string]interface{}) controller.Reconciler { - r := &Reconciler{ - Base: reconciler.NewBase(ctx, controllerAgentName, cmw), - Identity: identity.NewIdentity(ctx, NoopIAMPolicyManager, NewGCPAuthTestStore(t, nil)), - channelLister: listers.GetChannelLister(), - topicLister: listers.GetTopicLister(), - } - return channel.NewReconciler(ctx, r.Logger, r.RunClientSet, listers.GetChannelLister(), r.Recorder, r) - })) - } \ No newline at end of file From ada8d2bcce606efc5ce4a649f470f55f9182c220 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Wed, 10 Jun 2020 20:41:47 -0700 Subject: [PATCH 06/14] fixed topic tests --- pkg/reconciler/intevents/topic/controller_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/reconciler/intevents/topic/controller_test.go b/pkg/reconciler/intevents/topic/controller_test.go index 696d260d78..0470a09698 100644 --- a/pkg/reconciler/intevents/topic/controller_test.go +++ b/pkg/reconciler/intevents/topic/controller_test.go @@ -36,7 +36,7 @@ import ( _ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/fake" _ "knative.dev/serving/pkg/client/injection/informers/serving/v1/service/fake" - _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1alpha1/topic/fake" + _ "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic/fake" ) func TestNew(t *testing.T) { From 7efccb1086b074c8d1f400eca90a313adb31f73a Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Thu, 11 Jun 2020 09:40:00 -0700 Subject: [PATCH 07/14] added build conversion --- cmd/webhook/main.go | 8 ++ config/core/resources/cloudbuildsource.yaml | 9 ++ .../cloudschedulersource.yaml | 2 +- .../v1alpha1/cloudbuildsource_conversion.go | 58 ++++++++++ .../cloudbuildsource_conversion_test.go | 102 ++++++++++++++++++ .../events/v1alpha1/cloudbuildsource_types.go | 11 +- .../v1beta1/cloudbuildsource_conversion.go | 35 ++++++ .../cloudbuildsource_conversion_test.go | 34 ++++++ pkg/apis/events/v1beta1/implements_test.go | 2 + pkg/apis/events/v1beta1/register_test.go | 1 + 10 files changed, 257 insertions(+), 5 deletions(-) create mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go create mode 100644 pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_conversion.go create mode 100644 pkg/apis/events/v1beta1/cloudbuildsource_conversion_test.go diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 29f9efc929..4b1536f58e 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -213,6 +213,14 @@ func newConversionController(ctx context.Context, _ configmap.Watcher, gcpas *gc eventsv1beta1_: &eventsv1beta1.CloudStorageSource{}, }, }, + eventsv1alpha1.Kind("CloudBuildSource"): { + DefinitionName: events.CloudBuildSourcesResource.String(), + HubVersion: eventsv1alpha1_, + Zygotes: map[string]conversion.ConvertibleObject{ + eventsv1alpha1_: &eventsv1alpha1.CloudBuildSource{}, + eventsv1beta1_: &eventsv1beta1.CloudBuildSource{}, + }, + }, // intevents inteventsv1alpha1.Kind("PullSubscription"): { DefinitionName: intevents.PullSubscriptionsResource.String(), diff --git a/config/core/resources/cloudbuildsource.yaml b/config/core/resources/cloudbuildsource.yaml index ea96e692b1..32c4e66eed 100644 --- a/config/core/resources/cloudbuildsource.yaml +++ b/config/core/resources/cloudbuildsource.yaml @@ -40,6 +40,12 @@ spec: subresources: status: {} preserveUnknownFields: false + conversion: + strategy: Webhook + webhookClientConfig: + service: + name: webhook + namespace: cloud-run-events additionalPrinterColumns: - name: Ready type: string @@ -54,6 +60,9 @@ spec: - name: v1alpha1 served: true storage: true + - name: v1beta1 + served: true + storage: false validation: openAPIV3Schema: type: object diff --git a/docs/examples/cloudschedulersource/cloudschedulersource.yaml b/docs/examples/cloudschedulersource/cloudschedulersource.yaml index 69d10578c7..61e03cd34b 100644 --- a/docs/examples/cloudschedulersource/cloudschedulersource.yaml +++ b/docs/examples/cloudschedulersource/cloudschedulersource.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: events.cloud.google.com/v1alpha1 +apiVersion: events.cloud.google.com/v1beta1 kind: CloudSchedulerSource metadata: name: scheduler-test diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go new file mode 100644 index 0000000000..0676705337 --- /dev/null +++ b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go @@ -0,0 +1,58 @@ +/* +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" + + "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(_ context.Context, to apis.Convertible) error { + switch sink := to.(type) { + case *v1beta1.CloudBuildSource: + sink.ObjectMeta = source.ObjectMeta + sink.Spec.PubSubSpec = convert.ToV1beta1PubSubSpec(source.Spec.PubSubSpec) + sink.Spec.Topic = source.Spec.Topic + sink.Status.PubSubStatus = convert.ToV1beta1PubSubStatus(source.Status.PubSubStatus) + return nil + default: + return fmt.Errorf("unknown conversion, got: %T", sink) + + } +} + +// ConvertFrom implements apis.Convertible. +// Converts obj from v1alpha1.CloudBuildSource into v1beta1.CloudBuildSource. +func (sink *CloudBuildSource) ConvertFrom(_ context.Context, from apis.Convertible) error { + switch source := from.(type) { + case *v1beta1.CloudBuildSource: + sink.ObjectMeta = source.ObjectMeta + sink.Spec.PubSubSpec = convert.FromV1beta1PubSubSpec(source.Spec.PubSubSpec) + sink.Spec.Topic = source.Spec.Topic + sink.Status.PubSubStatus = convert.FromV1beta1PubSubStatus(source.Status.PubSubStatus) + return nil + default: + return fmt.Errorf("unknown conversion, got: %T", source) + } +} + diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go new file mode 100644 index 0000000000..89ff316ba7 --- /dev/null +++ b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go @@ -0,0 +1,102 @@ +/* +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" + "knative.dev/pkg/ptr" + "net/url" + "testing" + + "github.com/google/knative-gcp/pkg/apis/events/v1beta1" + + "github.com/google/go-cmp/cmp" + 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: completeObjectMeta, + Spec: CloudBuildSourceSpec{ + PubSubSpec: completePubSubSpec, + Topic: ptr.String(DefaultTopic), + }, + Status: CloudBuildSourceStatus{ + PubSubStatus: completePubSubStatus, + }, + } +) + +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{}} + + 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) + } + 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_types.go b/pkg/apis/events/v1alpha1/cloudbuildsource_types.go index 9fa479ca77..8fa856ea7f 100644 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_types.go +++ b/pkg/apis/events/v1alpha1/cloudbuildsource_types.go @@ -15,17 +15,16 @@ 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/apis/duck" "knative.dev/pkg/kmeta" "knative.dev/pkg/webhook/resourcesemantics" "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" ) // CloudBuildSource is a specification for a CloudBuildSource resource @@ -40,12 +39,16 @@ type CloudBuildSource struct { 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.PubSubable = (*CloudBuildSource)(nil) _ kngcpduck.Identifiable = (*CloudBuildSource)(nil) - _ = duck.VerifyType(&CloudBuildSource{}, &duckv1.Conditions{}) + _ kngcpduck.PubSubable = (*CloudBuildSource)(nil) ) // CloudBuildSourceSpec defines the desired state of the CloudBuildSource. diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_conversion.go b/pkg/apis/events/v1beta1/cloudbuildsource_conversion.go new file mode 100644 index 0000000000..d7dffb1ada --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_conversion.go @@ -0,0 +1,35 @@ +/* +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 v1beta1 + +import ( + "context" + "fmt" + + "knative.dev/pkg/apis" +) + +// ConvertTo implements apis.Convertible. +func (*CloudBuildSource) ConvertTo(_ context.Context, to apis.Convertible) error { + return fmt.Errorf("v1beta1 is the highest known version, got: %T", to) +} + +// ConvertFrom implements apis.Convertible. +func (*CloudBuildSource) ConvertFrom(_ context.Context, from apis.Convertible) error { + return fmt.Errorf("v1beta1 is the highest known version, got: %T", from) +} + diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_conversion_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_conversion_test.go new file mode 100644 index 0000000000..0b504e393f --- /dev/null +++ b/pkg/apis/events/v1beta1/cloudbuildsource_conversion_test.go @@ -0,0 +1,34 @@ +/* +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 v1beta1 + +import ( + "context" + "testing" +) + +func TestCloudBuildSourceConversionBadType(t *testing.T) { + good, bad := &CloudBuildSource{}, &CloudBuildSource{} + + 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) + } +} diff --git a/pkg/apis/events/v1beta1/implements_test.go b/pkg/apis/events/v1beta1/implements_test.go index 82696cebc9..c1e69d2541 100644 --- a/pkg/apis/events/v1beta1/implements_test.go +++ b/pkg/apis/events/v1beta1/implements_test.go @@ -33,6 +33,8 @@ func TestTypesImplements(t *testing.T) { {instance: &CloudSchedulerSource{}, iface: &v1beta1.Conditions{}}, {instance: &CloudPubSubSource{}, iface: &v1beta1.Source{}}, {instance: &CloudPubSubSource{}, iface: &v1beta1.Conditions{}}, + {instance: &CloudBuildSource{}, iface: &v1beta1.Source{}}, + {instance: &CloudBuildSource{}, iface: &v1beta1.Conditions{}}, } for _, tc := range testCases { if err := duck.VerifyType(tc.instance, tc.iface); err != nil { diff --git a/pkg/apis/events/v1beta1/register_test.go b/pkg/apis/events/v1beta1/register_test.go index 80c4056985..ceb251c5c1 100644 --- a/pkg/apis/events/v1beta1/register_test.go +++ b/pkg/apis/events/v1beta1/register_test.go @@ -62,6 +62,7 @@ func TestKnownTypes(t *testing.T) { "CloudAuditLogsSource", "CloudStorageSource", "CloudSchedulerSource", + "CloudBuildSource", } { if _, ok := types[name]; !ok { t.Errorf("Did not find %q as registered type", name) From e502a7b3d19ea853cc9bb0b00e82af01d97c9eb4 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Thu, 11 Jun 2020 10:36:59 -0700 Subject: [PATCH 08/14] changed channel e2e to v1beta1 --- test/e2e/e2e_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 1a2db853ff..a671b1d030 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -28,7 +28,7 @@ import ( eventingtestlib "knative.dev/eventing/test/lib" "knative.dev/pkg/test/logstream" - messagingv1alpha1 "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" + messagingv1beta1 "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" "github.com/google/knative-gcp/test/e2e/lib" ) @@ -48,7 +48,7 @@ func TestSingleBinaryEventForChannel(t *testing.T) { t.Skip("Skipping until https://github.com/google/knative-gcp/issues/486 is fixed.") cancel := logstream.Start(t) defer cancel() - e2ehelpers.SingleEventForChannelTestHelper(t, binding.EncodingBinary, "v1alpha1", "", channelTestRunner, lib.DuplicatePubSubSecret) + e2ehelpers.SingleEventForChannelTestHelper(t, binding.EncodingBinary, "v1beta1", "", channelTestRunner, lib.DuplicatePubSubSecret) } func TestSingleStructuredEventForChannel(t *testing.T) { @@ -58,7 +58,7 @@ func TestSingleStructuredEventForChannel(t *testing.T) { t.Skip("Skipping until https://github.com/google/knative-gcp/issues/486 is fixed.") cancel := logstream.Start(t) defer cancel() - e2ehelpers.SingleEventForChannelTestHelper(t, binding.EncodingStructured, "v1alpha1", "", channelTestRunner, lib.DuplicatePubSubSecret) + e2ehelpers.SingleEventForChannelTestHelper(t, binding.EncodingStructured, "v1beta1", "", channelTestRunner, lib.DuplicatePubSubSecret) } func TestChannelClusterDefaulter(t *testing.T) { @@ -146,7 +146,7 @@ func TestChannelTracing(t *testing.T) { cancel := logstream.Start(t) defer cancel() conformancehelpers.ChannelTracingTestHelper(t, metav1.TypeMeta{ - APIVersion: messagingv1alpha1.SchemeGroupVersion.String(), + APIVersion: messagingv1beta1.SchemeGroupVersion.String(), Kind: "Channel", }, func(client *eventingtestlib.Client) { // This test is running based on code in knative/eventing, so it does not use the same From 69e31d88e0029110cdbb718dbfb887bcd85c48fb Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Thu, 11 Jun 2020 11:00:39 -0700 Subject: [PATCH 09/14] fixed set default annotation --- pkg/apis/duck/v1beta1/annotations.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/apis/duck/v1beta1/annotations.go b/pkg/apis/duck/v1beta1/annotations.go index 977fa99f19..8dc4392ab9 100644 --- a/pkg/apis/duck/v1beta1/annotations.go +++ b/pkg/apis/duck/v1beta1/annotations.go @@ -149,6 +149,9 @@ func validateAnnotation(annotations map[string]string, annotation string, minimu } func setDefaultAnnotationIfNotPresent(obj *metav1.ObjectMeta, annotation string, defaultValue string) { + if obj.Annotations == nil { + obj.Annotations = map[string]string{} + } if _, ok := obj.Annotations[annotation]; !ok { obj.Annotations[annotation] = defaultValue } From ae6f00cc2394f784716205047c0ea62baa876ad5 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Thu, 11 Jun 2020 11:36:53 -0700 Subject: [PATCH 10/14] merged with master and fixed ut failure --- pkg/apis/intevents/v1beta1/topic_lifecycle.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/apis/intevents/v1beta1/topic_lifecycle.go b/pkg/apis/intevents/v1beta1/topic_lifecycle.go index 911a1de047..19c9f9da01 100644 --- a/pkg/apis/intevents/v1beta1/topic_lifecycle.go +++ b/pkg/apis/intevents/v1beta1/topic_lifecycle.go @@ -72,6 +72,7 @@ func (ts *TopicStatus) PropagatePublisherStatus(ss *v1.ServiceStatus) { 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) From 81e4bd40780e2db34bd1afe227f4d1d84c74040b Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Thu, 11 Jun 2020 15:26:06 -0700 Subject: [PATCH 11/14] fixed channel bug --- pkg/reconciler/messaging/channel/controller.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/reconciler/messaging/channel/controller.go b/pkg/reconciler/messaging/channel/controller.go index e9ef7ea6c2..d12ad01511 100644 --- a/pkg/reconciler/messaging/channel/controller.go +++ b/pkg/reconciler/messaging/channel/controller.go @@ -26,7 +26,7 @@ import ( "knative.dev/pkg/controller" "github.com/google/knative-gcp/pkg/apis/configs/gcpauth" - "github.com/google/knative-gcp/pkg/apis/messaging/v1alpha1" + "github.com/google/knative-gcp/pkg/apis/messaging/v1beta1" pullsubscriptioninformer "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/pullsubscription" topicinformer "github.com/google/knative-gcp/pkg/client/injection/informers/intevents/v1beta1/topic" channelinformer "github.com/google/knative-gcp/pkg/client/injection/informers/messaging/v1beta1/channel" @@ -79,17 +79,17 @@ func newController( channelInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) topicInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("Channel")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("Channel")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) pullSubscriptionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("Channel")), + FilterFunc: controller.Filter(v1beta1.SchemeGroupVersion.WithKind("Channel")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) serviceAccountInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind("Channel")), + FilterFunc: controller.FilterGroupVersionKind(v1beta1.SchemeGroupVersion.WithKind("Channel")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) From b6a64ba1a777aa40e1bd7fdeccb0260da6290536 Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Thu, 11 Jun 2020 17:27:11 -0700 Subject: [PATCH 12/14] fixed comments,waiting codegen --- pkg/apis/events/register.go | 2 + .../v1alpha1/cloudbuildsource_conversion.go | 2 - .../v1beta1/cloudbuildsource_defaults.go | 11 --- .../v1beta1/cloudbuildsource_defaults_test.go | 6 -- .../cloudbuildsource_lifecycle_test.go | 2 +- .../events/v1beta1/cloudbuildsource_types.go | 7 -- .../v1beta1/cloudbuildsource_validation.go | 6 -- .../cloudbuildsource_validation_test.go | 46 ----------- .../events/auditlogs/auditlogs_test.go | 80 ------------------- pkg/reconciler/events/build/build.go | 3 +- pkg/reconciler/events/build/build_test.go | 12 +-- pkg/reconciler/messaging/channel/channel.go | 14 ---- .../messaging/channel/channel_test.go | 2 +- pkg/reconciler/testing/build.go | 8 -- 14 files changed, 8 insertions(+), 193 deletions(-) diff --git a/pkg/apis/events/register.go b/pkg/apis/events/register.go index f4e55fdd8f..d8935c092e 100644 --- a/pkg/apis/events/register.go +++ b/pkg/apis/events/register.go @@ -21,6 +21,7 @@ import "k8s.io/apimachinery/pkg/runtime/schema" const ( GroupName = "events.cloud.google.com" + CloudBuildTopic = "cloud-builds" ) var ( @@ -44,6 +45,7 @@ var ( Group: GroupName, Resource: "cloudstoragesources", } + // CloudBuildSourcesResource represents a CloudBuildSource. CloudBuildSourcesResource = schema.GroupResource{ Group: GroupName, Resource: "cloudbuildsources", diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go index 0676705337..f3df06a97c 100644 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go +++ b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go @@ -32,7 +32,6 @@ func (source *CloudBuildSource) ConvertTo(_ context.Context, to apis.Convertible case *v1beta1.CloudBuildSource: sink.ObjectMeta = source.ObjectMeta sink.Spec.PubSubSpec = convert.ToV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.Topic = source.Spec.Topic sink.Status.PubSubStatus = convert.ToV1beta1PubSubStatus(source.Status.PubSubStatus) return nil default: @@ -48,7 +47,6 @@ func (sink *CloudBuildSource) ConvertFrom(_ context.Context, from apis.Convertib case *v1beta1.CloudBuildSource: sink.ObjectMeta = source.ObjectMeta sink.Spec.PubSubSpec = convert.FromV1beta1PubSubSpec(source.Spec.PubSubSpec) - sink.Spec.Topic = source.Spec.Topic sink.Status.PubSubStatus = convert.FromV1beta1PubSubStatus(source.Status.PubSubStatus) return nil default: diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go b/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go index bf09793656..98ad213961 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_defaults.go @@ -23,12 +23,6 @@ import ( duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" metadataClient "github.com/google/knative-gcp/pkg/gclient/metadata" - - "knative.dev/pkg/ptr" -) - -const ( - DefaultTopic = "cloud-builds" ) func (bs *CloudBuildSource) SetDefaults(ctx context.Context) { @@ -40,9 +34,4 @@ func (bs *CloudBuildSource) SetDefaults(ctx context.Context) { 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/v1beta1/cloudbuildsource_defaults_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go index a238751bcc..472b106fda 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_defaults_test.go @@ -21,7 +21,6 @@ import ( gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "knative.dev/pkg/ptr" "github.com/google/go-cmp/cmp" duckv1beta1 "github.com/google/knative-gcp/pkg/apis/duck/v1beta1" @@ -32,7 +31,6 @@ import ( ) func TestBuildSourceDefaults(t *testing.T) { - defaultTopic := DefaultTopic tests := []struct { name string start *CloudBuildSource @@ -54,7 +52,6 @@ func TestBuildSourceDefaults(t *testing.T) { Key: "test.json", }, }, - Topic: ptr.String(defaultTopic), }, }, want: &CloudBuildSource{ @@ -72,7 +69,6 @@ func TestBuildSourceDefaults(t *testing.T) { Key: "test.json", }, }, - Topic: ptr.String(defaultTopic), }, }, }, { @@ -96,7 +92,6 @@ func TestBuildSourceDefaults(t *testing.T) { PubSubSpec: duckv1beta1.PubSubSpec{ Secret: &gcpauthtesthelper.Secret, }, - Topic: ptr.String(defaultTopic), }, }, }} @@ -129,7 +124,6 @@ func TestCloudBuildSourceDefaults_NoChange(t *testing.T) { Key: "test.json", }, }, - Topic: ptr.String(DefaultTopic), }, } diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go index 84f042b89a..5da16434bd 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_lifecycle_test.go @@ -61,7 +61,7 @@ func TestCloudBuildSourceStatusIsReady(t *testing.T) { s: func() *CloudBuildSourceStatus { s := &CloudBuildSource{} s.Status.InitializeConditions() - s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), "PullSubscriptionUnknonw", "status unknown test message") + s.Status.MarkPullSubscriptionUnknown(s.ConditionSet(), "PullSubscriptionUnknown", "status unknown test message") return &s.Status }(), wantConditionStatus: corev1.ConditionUnknown, diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_types.go b/pkg/apis/events/v1beta1/cloudbuildsource_types.go index 4c45dc6354..ff4dfcb2bb 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_types.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_types.go @@ -54,13 +54,6 @@ type CloudBuildSourceSpec struct { // Sink, CloudEventOverrides, Secret, and Project duckv1beta1.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"` } const ( diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_validation.go b/pkg/apis/events/v1beta1/cloudbuildsource_validation.go index 7880e8b352..09dc2f753d 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_validation.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_validation.go @@ -15,8 +15,6 @@ package v1beta1 import ( "context" - "fmt" - "k8s.io/apimachinery/pkg/api/equality" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" @@ -35,10 +33,6 @@ func (current *CloudBuildSource) Validate(ctx context.Context) *apis.FieldError 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")) diff --git a/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go b/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go index 76f08bf5df..4875628a97 100644 --- a/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go +++ b/pkg/apis/events/v1beta1/cloudbuildsource_validation_test.go @@ -30,11 +30,9 @@ import ( 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: duckv1beta1.PubSubSpec{ Secret: &corev1.SecretKeySelector{ @@ -55,7 +53,6 @@ var ( }, Project: "my-eventing-project", }, - Topic: ptr.String(topic), } ) @@ -68,22 +65,6 @@ func TestCloudBuildSourceCheckValidationFields(t *testing.T) { 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() @@ -239,7 +220,6 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { Sink: buildSourceSpec.Sink, }, }, - Topic: buildSourceSpec.Topic, }, allowed: false, }, @@ -258,7 +238,6 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { Sink: buildSourceSpec.Sink, }, }, - Topic: buildSourceSpec.Topic, }, allowed: false, }, @@ -277,7 +256,6 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { Sink: buildSourceSpec.Sink, }, }, - Topic: buildSourceSpec.Topic, }, allowed: false, }, @@ -298,26 +276,6 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { Sink: buildSourceSpec.Sink, }, }, - Topic: buildSourceSpec.Topic, - }, - allowed: false, - }, - "Topic changed": { - orig: &buildSourceSpec, - updated: CloudBuildSourceSpec{ - PubSubSpec: duckv1beta1.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, }, @@ -343,7 +301,6 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { }, }, }, - Topic: buildSourceSpec.Topic, }, allowed: true, }, @@ -369,7 +326,6 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { }, }, }, - Topic: buildSourceSpec.Topic, }, allowed: true, }, @@ -395,7 +351,6 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { }, }, }, - Topic: buildSourceSpec.Topic, }, allowed: true, }, @@ -421,7 +376,6 @@ func TestCloudBuildSourceCheckImmutableFields(t *testing.T) { }, }, }, - Topic: buildSourceSpec.Topic, }, allowed: true, }, diff --git a/pkg/reconciler/events/auditlogs/auditlogs_test.go b/pkg/reconciler/events/auditlogs/auditlogs_test.go index 7562118070..76f98cbd74 100644 --- a/pkg/reconciler/events/auditlogs/auditlogs_test.go +++ b/pkg/reconciler/events/auditlogs/auditlogs_test.go @@ -1381,83 +1381,3 @@ func expectSinks(t *testing.T, clientProvider glogadmin.CreateFn, sinks map[stri } } } - - -// TODO add a unit test for successfully creating a k8s service account, after issue https://github.com/google/knative-gcp/issues/657 gets solved. -func TestDebug(t *testing.T) { - table := TableTest{ { - Name: "topic created, not yet been reconciled", - Objects: []runtime.Object{ - NewCloudAuditLogsSource(sourceName, testNS, - WithCloudAuditLogsSourceUID(sourceUID), - WithCloudAuditLogsSourceSink(sinkGVK, sinkName), - WithCloudAuditLogsSourceMethodName(testMethodName), - WithCloudAuditLogsSourceServiceName(testServiceName), - WithCloudAuditLogsSourceAnnotations(map[string]string{ - duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - })), - }, - Key: testNS + "/" + sourceName, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewCloudAuditLogsSource(sourceName, testNS, - WithCloudAuditLogsSourceUID(sourceUID), - WithInitCloudAuditLogsSourceConditions, - WithCloudAuditLogsSourceSink(sinkGVK, sinkName), - WithCloudAuditLogsSourceMethodName(testMethodName), - WithCloudAuditLogsSourceServiceName(testServiceName), - WithCloudAuditLogsSourceTopicUnknown("TopicNotConfigured", failedToReconcileTopicMsg), - WithCloudAuditLogsSourceAnnotations(map[string]string{ - duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - })), - }}, - WantCreates: []runtime.Object{ - NewTopic(sourceName, testNS, - WithTopicSpec(inteventsv1beta1.TopicSpec{ - Topic: testTopicID, - PropagationPolicy: "CreateDelete", - EnablePublisher: &falseVal, - }), - WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "events.cloud.google.com/source-name": sourceName, - }), - WithTopicOwnerReferences([]metav1.OwnerReference{sourceOwnerRef(sourceName, sourceUID)}), - WithTopicAnnotations(map[string]string{ - duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, - }), - ), - }, - WantPatches: []clientgotesting.PatchActionImpl{ - patchFinalizers(testNS, sourceName, true), - }, - WantEvents: []string{ - Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", sourceName), - Eventf(corev1.EventTypeWarning, reconciledPubSubFailedReason, "Reconcile PubSub failed with: Topic %q has not yet been reconciled", sourceName), - }, - }} - - defer logtesting.ClearAll() - for _, tt := range table { - t.Run(tt.Name, func(t *testing.T) { - logadminClientProvider := glogadmintesting.TestClientCreator(tt.OtherTestData["logadmin"]) - if existingSinks := tt.OtherTestData["existingSinks"]; existingSinks != nil { - createSinks(t, logadminClientProvider, existingSinks.([]logadmin.Sink)) - } - tt.Test(t, MakeFactory( - func(ctx context.Context, listers *Listers, cmw configmap.Watcher, testData map[string]interface{}) controller.Reconciler { - r := &Reconciler{ - PubSubBase: intevents.NewPubSubBaseWithAdapter(ctx, controllerAgentName, receiveAdapterName, converters.CloudAuditLogsConverter, cmw), - Identity: identity.NewIdentity(ctx, NoopIAMPolicyManager, NewGCPAuthTestStore(t, nil)), - auditLogsSourceLister: listers.GetCloudAuditLogsSourceLister(), - logadminClientProvider: logadminClientProvider, - pubsubClientProvider: gpubsub.TestClientCreator(testData["pubsub"]), - serviceAccountLister: listers.GetServiceAccountLister(), - } - return cloudauditlogssource.NewReconciler(ctx, r.Logger, r.RunClientSet, listers.GetCloudAuditLogsSourceLister(), r.Recorder, r) - })) - if expectedSinks := tt.OtherTestData["expectedSinks"]; expectedSinks != nil { - expectSinks(t, logadminClientProvider, expectedSinks.(map[string]*logadmin.Sink)) - } - }) - } -} \ No newline at end of file diff --git a/pkg/reconciler/events/build/build.go b/pkg/reconciler/events/build/build.go index b747144c87..25a3495a65 100644 --- a/pkg/reconciler/events/build/build.go +++ b/pkg/reconciler/events/build/build.go @@ -18,6 +18,7 @@ package build import ( "context" + "github.com/google/knative-gcp/pkg/apis/events" "go.uber.org/zap" @@ -71,7 +72,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, build *v1beta1.CloudBuil return pkgreconciler.NewEvent(corev1.EventTypeWarning, workloadIdentityFailed, "Failed to reconcile CloudBuildSource workload identity: %s", err.Error()) } } - _, event := r.PubSubBase.ReconcilePullSubscription(ctx, build, *build.Spec.Topic, resourceGroup, false) + _, event := r.PubSubBase.ReconcilePullSubscription(ctx, build, events.CloudBuildTopic, resourceGroup, false) if event != nil { return event } diff --git a/pkg/reconciler/events/build/build_test.go b/pkg/reconciler/events/build/build_test.go index 84487bcc59..b704849a7b 100644 --- a/pkg/reconciler/events/build/build_test.go +++ b/pkg/reconciler/events/build/build_test.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "github.com/google/knative-gcp/pkg/apis/events" "testing" corev1 "k8s.io/api/core/v1" @@ -54,7 +55,7 @@ const ( sinkName = "sink" testNS = "testnamespace" - testTopicID = v1beta1.DefaultTopic + testTopicID = events.CloudBuildTopic generation = 1 failedToPropagatePullSubscriptionStatusMsg = `Failed to propagate PullSubscription status` ) @@ -161,7 +162,6 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewCloudBuildSource(buildName, testNS, WithCloudBuildSourceObjectMetaGeneration(generation), - WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), WithCloudBuildSourceAnnotations(map[string]string{ duckv1beta1.ClusterNameAnnotation: testingMetadataClient.FakeClusterName, @@ -175,7 +175,6 @@ func TestAllCases(t *testing.T) { Object: NewCloudBuildSource(buildName, testNS, WithCloudBuildSourceObjectMetaGeneration(generation), WithCloudBuildSourceStatusObservedGeneration(generation), - WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), WithInitCloudBuildSourceConditions, WithCloudBuildSourceObjectMetaGeneration(generation), @@ -222,7 +221,6 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewCloudBuildSource(buildName, testNS, WithCloudBuildSourceObjectMetaGeneration(generation), - WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), ), NewPullSubscriptionWithNoDefaults(buildName, testNS, @@ -243,7 +241,6 @@ func TestAllCases(t *testing.T) { Object: NewCloudBuildSource(buildName, testNS, WithCloudBuildSourceObjectMetaGeneration(generation), WithCloudBuildSourceStatusObservedGeneration(generation), - WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), WithInitCloudBuildSourceConditions, WithCloudBuildSourceObjectMetaGeneration(generation), @@ -262,7 +259,6 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewCloudBuildSource(buildName, testNS, WithCloudBuildSourceObjectMetaGeneration(generation), - WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), ), NewPullSubscriptionWithNoDefaults(buildName, testNS, @@ -283,7 +279,6 @@ func TestAllCases(t *testing.T) { Object: NewCloudBuildSource(buildName, testNS, WithCloudBuildSourceObjectMetaGeneration(generation), WithCloudBuildSourceStatusObservedGeneration(generation), - WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), WithInitCloudBuildSourceConditions, WithCloudBuildSourceObjectMetaGeneration(generation), @@ -302,7 +297,6 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ NewCloudBuildSource(buildName, testNS, WithCloudBuildSourceObjectMetaGeneration(generation), - WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), ), NewPullSubscriptionWithNoDefaults(buildName, testNS, @@ -334,7 +328,6 @@ func TestAllCases(t *testing.T) { Object: NewCloudBuildSource(buildName, testNS, WithCloudBuildSourceObjectMetaGeneration(generation), WithCloudBuildSourceStatusObservedGeneration(generation), - WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), WithInitCloudBuildSourceConditions, WithCloudBuildSourcePullSubscriptionReady(), @@ -345,7 +338,6 @@ func TestAllCases(t *testing.T) { Object: NewCloudBuildSource(buildName, testNS, WithCloudBuildSourceObjectMetaGeneration(generation), WithCloudBuildSourceStatusObservedGeneration(generation), - WithCloudBuildSourceTopic(testTopicID), WithCloudBuildSourceSink(sinkGVK, sinkName), WithInitCloudBuildSourceConditions, WithCloudBuildSourcePullSubscriptionReady(), diff --git a/pkg/reconciler/messaging/channel/channel.go b/pkg/reconciler/messaging/channel/channel.go index 5f20b08bfa..85db3bce3b 100644 --- a/pkg/reconciler/messaging/channel/channel.go +++ b/pkg/reconciler/messaging/channel/channel.go @@ -104,13 +104,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, channel *v1beta1.Channel } func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1beta1.Channel) error { - //if equality.Semantic.DeepEqual(channel.Status.SubscribableStatus, eventingduckv1beta1.SubscribableStatus{}) { - // channel.Status.SubscribableStatus = eventingduckv1beta1.SubscribableStatus{ - // Subscribers: make([]eventingduckv1beta1.SubscriberStatus, 0), - // } - //} else if channel.Status.SubscribableStatus.Subscribers == nil { - // channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0) - //} if channel.Status.SubscribableStatus.Subscribers == nil { channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0) } @@ -264,13 +257,6 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1beta1.Chann } func (r *Reconciler) syncSubscribersStatus(ctx context.Context, channel *v1beta1.Channel) error { - //if equality.Semantic.DeepEqual(channel.Status.SubscribableStatus, eventingduckv1beta1.SubscribableStatus{}){ - // channel.Status.SubscribableStatus = eventingduckv1beta1.SubscribableStatus{ - // Subscribers: make([]eventingduckv1beta1.SubscriberStatus, 0), - // } - //} else if channel.Status.SubscribableStatus.Subscribers == nil { - // channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0) - //} if channel.Status.SubscribableStatus.Subscribers == nil { channel.Status.SubscribableStatus.Subscribers = make([]eventingduckv1beta1.SubscriberStatus, 0)} diff --git a/pkg/reconciler/messaging/channel/channel_test.go b/pkg/reconciler/messaging/channel/channel_test.go index e62f2c188b..c947abac0f 100644 --- a/pkg/reconciler/messaging/channel/channel_test.go +++ b/pkg/reconciler/messaging/channel/channel_test.go @@ -567,4 +567,4 @@ func newPullSubscriptionWithOwner(subscriber eventingduckv1beta1.SubscriberSpec, Annotations: resources.GetPullSubscriptionAnnotations(channel.Name, channel.GetAnnotations()[duckv1beta1.ClusterNameAnnotation]), Subscriber: subscriber, }) -} \ No newline at end of file +} diff --git a/pkg/reconciler/testing/build.go b/pkg/reconciler/testing/build.go index 70a8f3cc5c..04d26453ac 100644 --- a/pkg/reconciler/testing/build.go +++ b/pkg/reconciler/testing/build.go @@ -21,8 +21,6 @@ import ( gcpauthtesthelper "github.com/google/knative-gcp/pkg/apis/configs/gcpauth/testhelper" - "knative.dev/pkg/ptr" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -73,12 +71,6 @@ func WithCloudBuildSourceProject(project string) CloudBuildSourceOption { } } -func WithCloudBuildSourceTopic(topicID string) CloudBuildSourceOption { - return func(bs *v1beta1.CloudBuildSource) { - bs.Spec.Topic = ptr.String(topicID) - } -} - // WithInitCloudBuildSourceConditions initializes the CloudBuildSource's conditions. func WithInitCloudBuildSourceConditions(bs *v1beta1.CloudBuildSource) { bs.Status.InitializeConditions() From 6e7bd975542c491d8061afffebba2387ab67c690 Mon Sep 17 00:00:00 2001 From: Nacho Cano Date: Thu, 11 Jun 2020 18:09:06 -0700 Subject: [PATCH 13/14] update codegen --- pkg/apis/events/v1beta1/zz_generated.deepcopy.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkg/apis/events/v1beta1/zz_generated.deepcopy.go b/pkg/apis/events/v1beta1/zz_generated.deepcopy.go index 6a075fd9a6..cb22ae136a 100644 --- a/pkg/apis/events/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/events/v1beta1/zz_generated.deepcopy.go @@ -184,11 +184,6 @@ func (in *CloudBuildSourceList) DeepCopyObject() runtime.Object { 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 } From 1cbecadf18e652a329b44ba0c9d82dd1dcce61cf Mon Sep 17 00:00:00 2001 From: XiyueYu Date: Thu, 11 Jun 2020 18:48:50 -0700 Subject: [PATCH 14/14] fixed ut and changed yaml --- config/core/resources/cloudauditlogssource.yaml | 4 ++-- config/core/resources/cloudbuildsource.yaml | 9 ++------- config/core/resources/cloudpubsubsource.yaml | 4 ++-- config/core/resources/cloudschedulersource.yaml | 4 ++-- config/core/resources/cloudstoragesource.yaml | 4 ++-- config/core/resources/pullsubscription.yaml | 4 ++-- config/core/resources/topic.yaml | 4 ++-- docs/examples/cloudbuildsource/cloudbuildsource.yaml | 2 +- pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go | 1 - .../events/v1alpha1/cloudbuildsource_conversion_test.go | 2 -- 10 files changed, 15 insertions(+), 23 deletions(-) diff --git a/config/core/resources/cloudauditlogssource.yaml b/config/core/resources/cloudauditlogssource.yaml index 2ae2e58fe2..a31a5447fa 100644 --- a/config/core/resources/cloudauditlogssource.yaml +++ b/config/core/resources/cloudauditlogssource.yaml @@ -58,10 +58,10 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false - name: v1beta1 served: true - storage: false + storage: true validation: openAPIV3Schema: type: object diff --git a/config/core/resources/cloudbuildsource.yaml b/config/core/resources/cloudbuildsource.yaml index 32c4e66eed..0e64e297c0 100644 --- a/config/core/resources/cloudbuildsource.yaml +++ b/config/core/resources/cloudbuildsource.yaml @@ -59,10 +59,10 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false - name: v1beta1 served: true - storage: false + storage: true validation: openAPIV3Schema: type: object @@ -134,11 +134,6 @@ spec: description: > Google Cloud Project ID of the project into which the topic should be created. If omitted uses the Project ID from the GKE cluster metadata service. - topic: - type: string - description: > - ID of the Cloud Pub/Sub Topic to Subscribe to. It must be `cloud-builds` if - specified. Defaults to `cloud-builds`. status: type: object properties: diff --git a/config/core/resources/cloudpubsubsource.yaml b/config/core/resources/cloudpubsubsource.yaml index fadb57c14b..94d22ec8fb 100644 --- a/config/core/resources/cloudpubsubsource.yaml +++ b/config/core/resources/cloudpubsubsource.yaml @@ -58,10 +58,10 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false - name: v1beta1 served: true - storage: false + storage: true validation: openAPIV3Schema: type: object diff --git a/config/core/resources/cloudschedulersource.yaml b/config/core/resources/cloudschedulersource.yaml index e958c2aeea..994b337013 100644 --- a/config/core/resources/cloudschedulersource.yaml +++ b/config/core/resources/cloudschedulersource.yaml @@ -58,10 +58,10 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false - name: v1beta1 served: true - storage: false + storage: true validation: openAPIV3Schema: type: object diff --git a/config/core/resources/cloudstoragesource.yaml b/config/core/resources/cloudstoragesource.yaml index 73185b8118..a9031d274e 100644 --- a/config/core/resources/cloudstoragesource.yaml +++ b/config/core/resources/cloudstoragesource.yaml @@ -61,10 +61,10 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false - name: v1beta1 served: true - storage: false + storage: true validation: openAPIV3Schema: type: object diff --git a/config/core/resources/pullsubscription.yaml b/config/core/resources/pullsubscription.yaml index 57bbd497b4..6446cdbe16 100644 --- a/config/core/resources/pullsubscription.yaml +++ b/config/core/resources/pullsubscription.yaml @@ -51,10 +51,10 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false - name: v1beta1 served: true - storage: false + storage: true # All versions happen to have the same schema today. They will likely diverge in the future. validation: openAPIV3Schema: diff --git a/config/core/resources/topic.yaml b/config/core/resources/topic.yaml index 19ae9eeca0..278b49c233 100644 --- a/config/core/resources/topic.yaml +++ b/config/core/resources/topic.yaml @@ -55,10 +55,10 @@ spec: versions: - name: v1alpha1 served: true - storage: true + storage: false - name: v1beta1 served: true - storage: false + storage: true # All versions happen to have the same schema today. They will likely diverge in the future. validation: openAPIV3Schema: diff --git a/docs/examples/cloudbuildsource/cloudbuildsource.yaml b/docs/examples/cloudbuildsource/cloudbuildsource.yaml index f4e26c6c94..00798a8993 100644 --- a/docs/examples/cloudbuildsource/cloudbuildsource.yaml +++ b/docs/examples/cloudbuildsource/cloudbuildsource.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: events.cloud.google.com/v1alpha1 +apiVersion: events.cloud.google.com/v1beta1 kind: CloudBuildSource metadata: name: cloudbuildsource-test diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go index f3df06a97c..9f43252b73 100644 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go +++ b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion.go @@ -19,7 +19,6 @@ package v1alpha1 import ( "context" "fmt" - "github.com/google/knative-gcp/pkg/apis/convert" "github.com/google/knative-gcp/pkg/apis/events/v1beta1" "knative.dev/pkg/apis" diff --git a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go index 89ff316ba7..c672256abc 100644 --- a/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go +++ b/pkg/apis/events/v1alpha1/cloudbuildsource_conversion_test.go @@ -18,7 +18,6 @@ package v1alpha1 import ( "context" - "knative.dev/pkg/ptr" "net/url" "testing" @@ -39,7 +38,6 @@ var ( ObjectMeta: completeObjectMeta, Spec: CloudBuildSourceSpec{ PubSubSpec: completePubSubSpec, - Topic: ptr.String(DefaultTopic), }, Status: CloudBuildSourceStatus{ PubSubStatus: completePubSubStatus,