diff --git a/pkg/reconciler/events/auditlogs/auditlogs_test.go b/pkg/reconciler/events/auditlogs/auditlogs_test.go index eff34a4948..3e56a656a8 100644 --- a/pkg/reconciler/events/auditlogs/auditlogs_test.go +++ b/pkg/reconciler/events/auditlogs/auditlogs_test.go @@ -161,7 +161,8 @@ func TestAllCases(t *testing.T) { PropagationPolicy: "CreateDelete", }), WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": sourceName, }), WithTopicOwnerReferences([]metav1.OwnerReference{sourceOwnerRef(sourceName, sourceUID)}), ), @@ -371,7 +372,8 @@ func TestAllCases(t *testing.T) { }), WithPullSubscriptionSink(sinkGVK, sinkName), WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": sourceName, }), WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, diff --git a/pkg/reconciler/events/pubsub/pubsub.go b/pkg/reconciler/events/pubsub/pubsub.go index b3f5d7b2c3..13fe38176a 100644 --- a/pkg/reconciler/events/pubsub/pubsub.go +++ b/pkg/reconciler/events/pubsub/pubsub.go @@ -157,10 +157,7 @@ func (r *Reconciler) reconcilePullSubscription(ctx context.Context, source *v1al Topic: source.Spec.Topic, ResourceGroup: resourceGroup, Mode: pubsubv1alpha1.ModePushCompatible, - Labels: map[string]string{ - "receive-adapter": r.receiveAdapterName, - "source": source.Name, - }, + Labels: resources.GetLabels(r.receiveAdapterName, source.Name), } newPS := resources.MakePullSubscription(args) logging.FromContext(ctx).Desugar().Debug("Creating PullSubscription", zap.Any("ps", newPS)) diff --git a/pkg/reconciler/events/pubsub/pubsub_test.go b/pkg/reconciler/events/pubsub/pubsub_test.go index 8319048c1f..690a1f9ff8 100644 --- a/pkg/reconciler/events/pubsub/pubsub_test.go +++ b/pkg/reconciler/events/pubsub/pubsub_test.go @@ -161,8 +161,8 @@ func TestAllCases(t *testing.T) { WithPullSubscriptionSink(sinkGVK, sinkName), WithPullSubscriptionMode(pubsubv1alpha1.ModePushCompatible), WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": pubsubName, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": pubsubName, }), WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, diff --git a/pkg/reconciler/events/scheduler/scheduler_test.go b/pkg/reconciler/events/scheduler/scheduler_test.go index ac8db24da0..a1c09a712b 100644 --- a/pkg/reconciler/events/scheduler/scheduler_test.go +++ b/pkg/reconciler/events/scheduler/scheduler_test.go @@ -189,7 +189,8 @@ func TestAllCases(t *testing.T) { PropagationPolicy: "CreateDelete", }), WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": schedulerName, }), WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -434,8 +435,8 @@ func TestAllCases(t *testing.T) { }), WithPullSubscriptionSink(sinkGVK, sinkName), WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - }), + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": schedulerName}), WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, }), diff --git a/pkg/reconciler/pubsub/reconciler.go b/pkg/reconciler/pubsub/reconciler.go index 33e2faeecb..3b18ef629a 100644 --- a/pkg/reconciler/pubsub/reconciler.go +++ b/pkg/reconciler/pubsub/reconciler.go @@ -75,10 +75,7 @@ func (psb *PubSubBase) ReconcilePubSub(ctx context.Context, pubsubable duck.PubS Spec: spec, Owner: pubsubable, Topic: topic, - Labels: map[string]string{ - "receive-adapter": psb.receiveAdapterName, - "source": name, - }, + Labels: resources.GetLabels(psb.receiveAdapterName, name), } newTopic := resources.MakeTopic(args) t, err = topics.Create(newTopic) @@ -110,10 +107,7 @@ func (psb *PubSubBase) ReconcilePubSub(ctx context.Context, pubsubable duck.PubS Topic: topic, AdapterType: psb.adapterType, ResourceGroup: resourceGroup, - Labels: map[string]string{ - "receive-adapter": psb.receiveAdapterName, - "source": name, - }, + Labels: resources.GetLabels(psb.receiveAdapterName, name), } newPS := resources.MakePullSubscription(args) ps, err = pullSubscriptions.Create(newPS) diff --git a/pkg/reconciler/pubsub/reconciler_test.go b/pkg/reconciler/pubsub/reconciler_test.go index 33bc2ab689..e9373efc55 100644 --- a/pkg/reconciler/pubsub/reconciler_test.go +++ b/pkg/reconciler/pubsub/reconciler_test.go @@ -95,8 +95,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -109,8 +109,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -124,8 +124,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -137,8 +137,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), ), @@ -153,8 +153,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReady(testTopicID), @@ -168,8 +168,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReady(testTopicID), @@ -187,8 +187,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicProjectID(testProjectID), @@ -202,8 +202,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicFailed(), @@ -221,8 +221,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicProjectID(testProjectID), @@ -236,8 +236,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicUnknown(), @@ -255,8 +255,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicProjectID(testProjectID), @@ -271,8 +271,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReady(""), @@ -291,8 +291,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicProjectID(testProjectID), @@ -307,8 +307,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReady(testTopicID), @@ -322,8 +322,8 @@ func TestCreates(t *testing.T) { Secret: &secret, }), rectesting.WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, @@ -338,8 +338,8 @@ func TestCreates(t *testing.T) { Secret: &secret, }), rectesting.WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, @@ -356,8 +356,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicProjectID(testProjectID), @@ -370,8 +370,8 @@ func TestCreates(t *testing.T) { Secret: &secret, }), rectesting.WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, @@ -386,8 +386,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReady(testTopicID), @@ -401,8 +401,8 @@ func TestCreates(t *testing.T) { Secret: &secret, }), rectesting.WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, @@ -419,8 +419,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicProjectID(testProjectID), @@ -433,8 +433,8 @@ func TestCreates(t *testing.T) { Secret: &secret, }), rectesting.WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, @@ -450,8 +450,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReady(testTopicID), @@ -465,8 +465,8 @@ func TestCreates(t *testing.T) { Secret: &secret, }), rectesting.WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, @@ -484,8 +484,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicProjectID(testProjectID), @@ -498,8 +498,8 @@ func TestCreates(t *testing.T) { Secret: &secret, }), rectesting.WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, @@ -515,8 +515,8 @@ func TestCreates(t *testing.T) { PropagationPolicy: "CreateDelete", }), rectesting.WithTopicLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}), rectesting.WithTopicReady(testTopicID), @@ -530,8 +530,8 @@ func TestCreates(t *testing.T) { Secret: &secret, }), rectesting.WithPullSubscriptionLabels(map[string]string{ - "receive-adapter": receiveAdapterName, - "source": name, + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": name, }), rectesting.WithPullSubscriptionAnnotations(map[string]string{ "metrics-resource-group": resourceGroup, diff --git a/pkg/reconciler/pubsub/resources/labels.go b/pkg/reconciler/pubsub/resources/labels.go new file mode 100644 index 0000000000..b7e45b219c --- /dev/null +++ b/pkg/reconciler/pubsub/resources/labels.go @@ -0,0 +1,24 @@ +/* +Copyright 2019 Google LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package resources + +func GetLabels(receiveAdapterName, source string) map[string]string { + return map[string]string{ + "receive-adapter": receiveAdapterName, + "events.cloud.google.com/source-name": source, + } +} diff --git a/pkg/reconciler/pubsub/resources/labesl_test.go b/pkg/reconciler/pubsub/resources/labesl_test.go new file mode 100644 index 0000000000..be2cca0433 --- /dev/null +++ b/pkg/reconciler/pubsub/resources/labesl_test.go @@ -0,0 +1,35 @@ +/* +Copyright 2019 Google LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package resources + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestGetLabels(t *testing.T) { + want := map[string]string{ + "receive-adapter": "receive-adapter-name", + "events.cloud.google.com/source-name": "source", + } + got := GetLabels("receive-adapter-name", "source") + + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("unexpected (-want, +got) = %v", diff) + } +} diff --git a/pkg/reconciler/pubsub/resources/pullsubscription.go b/pkg/reconciler/pubsub/resources/pullsubscription.go index 17fc9bca64..1c60aac4b1 100644 --- a/pkg/reconciler/pubsub/resources/pullsubscription.go +++ b/pkg/reconciler/pubsub/resources/pullsubscription.go @@ -68,9 +68,9 @@ func MakePullSubscription(args *PullSubscriptionArgs) *pubsubv1alpha1.PullSubscr }, }, } - if args.Spec.SourceSpec.CloudEventOverrides != nil && args.Spec.SourceSpec.CloudEventOverrides.Extensions != nil { + if args.Spec.CloudEventOverrides != nil && args.Spec.CloudEventOverrides.Extensions != nil { ps.Spec.SourceSpec.CloudEventOverrides = &duckv1.CloudEventOverrides{ - Extensions: args.Spec.SourceSpec.CloudEventOverrides.Extensions, + Extensions: args.Spec.CloudEventOverrides.Extensions, } } return ps diff --git a/pkg/reconciler/pubsub/resources/pullsubscription_test.go b/pkg/reconciler/pubsub/resources/pullsubscription_test.go index 85fce0d11f..0a677ba530 100644 --- a/pkg/reconciler/pubsub/resources/pullsubscription_test.go +++ b/pkg/reconciler/pubsub/resources/pullsubscription_test.go @@ -72,7 +72,7 @@ func TestMakePullSubscription(t *testing.T) { ResourceGroup: "storages.events.cloud.google.com", Labels: map[string]string{ "receive-adapter": "storage.events.cloud.google.com", - "source": source.Name, + "events.cloud.google.com/source-name": source.Name, }, } got := MakePullSubscription(args) @@ -84,7 +84,7 @@ func TestMakePullSubscription(t *testing.T) { Name: "bucket-name", Labels: map[string]string{ "receive-adapter": "storage.events.cloud.google.com", - "source": "bucket-name", + "events.cloud.google.com/source-name": "bucket-name", }, Annotations: map[string]string{ "metrics-resource-group": "storages.events.cloud.google.com",