From d897af3d6fdac95407e371b1cc64fae901d82061 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Thu, 27 Aug 2020 17:05:24 -0400 Subject: [PATCH 01/20] Make PingSource v1beta1 the stored version and add a migration tool Signed-off-by: Ansu Varghese --- config/core/resources/pingsource.yaml | 6 +- config/pre-install/v0.18.0/clusterrole.yaml | 1 + config/pre-install/v0.18.0/pingsource.yaml | 208 ++++++++++++ .../v0.18.0/storage-version-migration.yaml | 3 +- pkg/adapter/mtping/config.go | 4 +- pkg/adapter/mtping/config_test.go | 16 +- pkg/adapter/mtping/runner.go | 8 +- pkg/adapter/ping/adapter.go | 6 +- pkg/reconciler/mtbroker/broker_test.go | 30 +- .../mtbroker/trigger/trigger_test.go | 28 +- pkg/reconciler/pingsource/controller.go | 8 +- pkg/reconciler/pingsource/controller_test.go | 2 +- pkg/reconciler/pingsource/pingsource.go | 24 +- pkg/reconciler/pingsource/pingsource_test.go | 315 +++++++++--------- .../pingsource/resources/receive_adapter.go | 4 +- .../resources/receive_adapter_test.go | 8 +- .../pingsource/resources/role_binding.go | 4 +- .../pingsource/resources/role_binding_test.go | 6 +- .../resources/service_account_test.go | 4 +- pkg/reconciler/testing/listers.go | 4 +- pkg/reconciler/testing/pingsource.go | 86 ++++- pkg/reconciler/testing/v1beta1/listers.go | 4 +- test/conformance/main_test.go | 2 +- .../e2e/trigger_dependency_annotation_test.go | 12 +- test/lib/setupclientoptions/sources.go | 11 +- 25 files changed, 534 insertions(+), 270 deletions(-) create mode 100644 config/pre-install/v0.18.0/pingsource.yaml diff --git a/config/core/resources/pingsource.yaml b/config/core/resources/pingsource.yaml index 0b7fdf326dd..fd13efd7b03 100644 --- a/config/core/resources/pingsource.yaml +++ b/config/core/resources/pingsource.yaml @@ -32,8 +32,8 @@ spec: versions: - &version name: v1alpha2 - served: true - storage: true + served: false + storage: false subresources: status: {} schema: @@ -182,7 +182,7 @@ spec: - <<: *version name: v1beta1 served: true - storage: false + storage: true schema: openAPIV3Schema: type: object diff --git a/config/pre-install/v0.18.0/clusterrole.yaml b/config/pre-install/v0.18.0/clusterrole.yaml index b80fa65e81e..976da49c1e2 100644 --- a/config/pre-install/v0.18.0/clusterrole.yaml +++ b/config/pre-install/v0.18.0/clusterrole.yaml @@ -37,6 +37,7 @@ rules: resources: - "containersources" - "sinkbindings" + - "pingsources" verbs: - "get" - "list" diff --git a/config/pre-install/v0.18.0/pingsource.yaml b/config/pre-install/v0.18.0/pingsource.yaml new file mode 100644 index 00000000000..5222eb55c1d --- /dev/null +++ b/config/pre-install/v0.18.0/pingsource.yaml @@ -0,0 +1,208 @@ +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + labels: + eventing.knative.dev/release: devel + eventing.knative.dev/source: "true" + duck.knative.dev/source: "true" + knative.dev/crd-install: "true" + annotations: + # TODO add schemas and descriptions + registry.knative.dev/eventTypes: | + [ + { "type": "dev.knative.sources.ping" } + ] + name: pingsources.sources.knative.dev +spec: + group: sources.knative.dev + versions: + - &version + name: v1beta1 + served: true + storage: true + subresources: + status: {} + schema: + openAPIV3Schema: + type: object + description: 'PingSource describes an event source with a fixed payload produced on a specified cron schedule.' + properties: + spec: + type: object + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + properties: + ceOverrides: + description: 'CloudEventOverrides defines overrides to control the + output format and modifications of the event sent to the sink.' + type: object + properties: + extensions: + description: 'Extensions specify what attribute are added or + overridden on the outbound event. Each `Extensions` key-value + pair are set on the event as an attribute extension independently.' + type: object + additionalProperties: + type: string + x-kubernetes-preserve-unknown-fields: true + jsonData: + description: 'JsonData is json encoded data used as the body of the + event posted to the sink. Default is empty. If set, datacontenttype + will also be set to "application/json".' + type: string + schedule: + description: 'Schedule is the cronjob schedule. Defaults to `* * * + * *`.' + type: string + sink: + description: 'Sink is a reference to an object that will resolve to + a uri to use as the sink.' + type: object + properties: + ref: + description: 'Ref points to an Addressable.' + type: object + properties: + apiVersion: + description: 'API version of the referent.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: + https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + This is optional field, it gets defaulted to the + object holding it if left out.' + type: string + uri: + description: 'URI can be an absolute URL(non-empty scheme and + non-empty host) pointing to the target or a relative URI. + Relative URIs will be resolved using the base URI retrieved + from Ref.' + type: string + timezone: + description: 'Timezone modifies the actual time relative to the specified + timezone. Defaults to the system time zone. More general information + about time zones: https://www.iana.org/time-zones List of valid + timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' + type: string + status: + type: object + description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' + properties: + annotations: + description: 'Annotations is additional Status fields for the Resource + to save some additional State as well as convey more information + to the user. This is roughly akin to Annotations on any k8s resource, + just the reconciler conveying richer information outwards.' + type: object + x-kubernetes-preserve-unknown-fields: true + ceAttributes: + description: 'CloudEventAttributes are the specific attributes that + the Source uses as part of its CloudEvents.' + type: array + items: + type: object + properties: + source: + description: 'Source is the CloudEvents source attribute.' + type: string + type: + description: 'Type refers to the CloudEvent type attribute.' + type: string + conditions: + description: 'Conditions the latest available observations of a resource''s + current state.' + type: array + items: + type: object + required: + - type + - status + properties: + lastTransitionTime: + description: 'LastTransitionTime is the last time the condition + transitioned from one status to another. We use VolatileTime + in place of metav1.Time to exclude this from creating + equality.Semantic differences (all other things held + constant).' + type: string + message: + description: 'A human readable message indicating details + about the transition.' + type: string + reason: + description: 'The reason for the condition''s last transition.' + type: string + severity: + description: 'Severity with which to treat failures of + this type of condition. When this is not specified, + it defaults to Error.' + type: string + status: + description: 'Status of the condition, one of True, False, + Unknown.' + type: string + type: + description: 'Type of condition.' + type: string + observedGeneration: + description: 'ObservedGeneration is the "Generation" of the Service + that was last processed by the controller.' + type: integer + format: int64 + sinkUri: + description: 'SinkURI is the current active sink URI that has been + configured for the Source.' + type: string + additionalPrinterColumns: + - name: Ready + type: string + jsonPath: ".status.conditions[?(@.type=='Ready')].status" + - name: Reason + type: string + jsonPath: ".status.conditions[?(@.type=='Ready')].reason" + - name: Sink + type: string + jsonPath: .status.sinkUri + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + - << : *version + name: v1alpha2 + served: false + storage: false + names: + categories: + - all + - knative + - eventing + - sources + kind: PingSource + plural: pingsources + scope: Namespaced + conversion: + strategy: Webhook + webhook: + conversionReviewVersions: ["v1", "v1beta1"] + clientConfig: + service: + name: eventing-webhook + namespace: knative-eventing diff --git a/config/pre-install/v0.18.0/storage-version-migration.yaml b/config/pre-install/v0.18.0/storage-version-migration.yaml index 29eed16f74c..57d939dd27d 100644 --- a/config/pre-install/v0.18.0/storage-version-migration.yaml +++ b/config/pre-install/v0.18.0/storage-version-migration.yaml @@ -1,4 +1,4 @@ -# Copyright 2020 The Knative Authors +.# Copyright 2020 The Knative Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -44,3 +44,4 @@ spec: - "triggers.sources.knative.dev" - "channels.messaging.knative.dev" - "inmemorychannels.messaging.knative.dev" + - "pingsources.sources.knative.dev" diff --git a/pkg/adapter/mtping/config.go b/pkg/adapter/mtping/config.go index 2c14aa4a5ae..d24f9fc38ef 100644 --- a/pkg/adapter/mtping/config.go +++ b/pkg/adapter/mtping/config.go @@ -20,7 +20,7 @@ import ( corev1 "k8s.io/api/core/v1" "knative.dev/eventing/pkg/apis/eventing" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" ) type PingConfig struct { @@ -50,7 +50,7 @@ type PingConfigs map[string]PingConfig // Project creates a PingConfig for the given source func Project(i interface{}) interface{} { - obj := i.(*v1alpha2.PingSource) + obj := i.(*v1beta1.PingSource) if scope, ok := obj.Annotations[eventing.ScopeAnnotationKey]; ok && scope != eventing.ScopeCluster { return nil diff --git a/pkg/adapter/mtping/config_test.go b/pkg/adapter/mtping/config_test.go index 61d57dff932..a176697d7c8 100644 --- a/pkg/adapter/mtping/config_test.go +++ b/pkg/adapter/mtping/config_test.go @@ -26,28 +26,28 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" duckv1 "knative.dev/pkg/apis/duck/v1" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func TestProject(t *testing.T) { testCases := map[string]struct { - source sourcesv1alpha2.PingSource + source sourcesv1beta1.PingSource expected PingConfig }{ "TestAddRunRemoveSchedule": { - source: sourcesv1alpha2.PingSource{ + source: sourcesv1beta1.PingSource{ ObjectMeta: metav1.ObjectMeta{ Name: "test-name", Namespace: "test-ns"}, - Spec: sourcesv1alpha2.PingSourceSpec{ + Spec: sourcesv1beta1.PingSourceSpec{ SourceSpec: duckv1.SourceSpec{ CloudEventOverrides: nil, }, Schedule: "* * * * ?", JsonData: "some data", }, - Status: sourcesv1alpha2.PingSourceStatus{ + Status: sourcesv1beta1.PingSourceStatus{ SourceStatus: duckv1.SourceStatus{ SinkURI: &apis.URL{ Host: "asink", @@ -65,11 +65,11 @@ func TestProject(t *testing.T) { SinkURI: "//asink", }}, "TestAddRunRemoveScheduleWithExtensionOverride": { - source: sourcesv1alpha2.PingSource{ + source: sourcesv1beta1.PingSource{ ObjectMeta: metav1.ObjectMeta{ Name: "test-name", Namespace: "test-ns"}, - Spec: sourcesv1alpha2.PingSourceSpec{ + Spec: sourcesv1beta1.PingSourceSpec{ SourceSpec: duckv1.SourceSpec{ Sink: duckv1.Destination{}, CloudEventOverrides: &duckv1.CloudEventOverrides{ @@ -79,7 +79,7 @@ func TestProject(t *testing.T) { Schedule: "* * * * ?", JsonData: "some data", }, - Status: sourcesv1alpha2.PingSourceStatus{ + Status: sourcesv1beta1.PingSourceStatus{ SourceStatus: duckv1.SourceStatus{ SinkURI: &apis.URL{Host: "anothersink"}, }, diff --git a/pkg/adapter/mtping/runner.go b/pkg/adapter/mtping/runner.go index 5439deceb3a..41743ff525a 100644 --- a/pkg/adapter/mtping/runner.go +++ b/pkg/adapter/mtping/runner.go @@ -35,7 +35,7 @@ import ( kncloudevents "knative.dev/eventing/pkg/adapter/v2" "knative.dev/eventing/pkg/adapter/v2/util/crstatusevent" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" "knative.dev/eventing/pkg/utils/cache" ) @@ -77,8 +77,8 @@ func NewCronJobsRunner(ceClient cloudevents.Client, kubeClient kubernetes.Interf func (a *cronJobsRunner) AddSchedule(cfg PingConfig) cron.EntryID { event := cloudevents.NewEvent() - event.SetType(sourcesv1alpha2.PingSourceEventType) - event.SetSource(sourcesv1alpha2.PingSourceSource(cfg.Namespace, cfg.Name)) + event.SetType(sourcesv1beta1.PingSourceEventType) + event.SetSource(sourcesv1beta1.PingSourceSource(cfg.Namespace, cfg.Name)) event.SetData(cloudevents.ApplicationJSON, message(cfg.JsonData)) if cfg.Extensions != nil { for key, override := range cfg.Extensions { @@ -179,7 +179,7 @@ func (a *cronJobsRunner) updateFromConfigMap(cm *corev1.ConfigMap) { } for key, cfg := range cfgs { - cfg.APIVersion = sourcesv1alpha2.SchemeGroupVersion.String() + cfg.APIVersion = sourcesv1beta1.SchemeGroupVersion.String() cfg.Kind = "PingSource" // Is the schedule already cached? diff --git a/pkg/adapter/ping/adapter.go b/pkg/adapter/ping/adapter.go index c076504c2af..04b30b2e77b 100644 --- a/pkg/adapter/ping/adapter.go +++ b/pkg/adapter/ping/adapter.go @@ -29,7 +29,7 @@ import ( "knative.dev/pkg/logging" "knative.dev/eventing/pkg/adapter/v2" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" ) type envConfig struct { @@ -106,8 +106,8 @@ func (a *pingAdapter) cronTick() { ctx = cloudevents.ContextWithRetriesExponentialBackoff(ctx, 50*time.Millisecond, 5) event := cloudevents.NewEvent(cloudevents.VersionV1) - event.SetType(sourcesv1alpha2.PingSourceEventType) - event.SetSource(sourcesv1alpha2.PingSourceSource(a.Namespace, a.Name)) + event.SetType(sourcesv1beta1.PingSourceEventType) + event.SetSource(sourcesv1beta1.PingSourceSource(a.Namespace, a.Name)) if err := event.SetData(cloudevents.ApplicationJSON, message(a.Data)); err != nil { logging.FromContext(ctx).Errorw("ping failed to set event data", zap.Error(err)) } diff --git a/pkg/reconciler/mtbroker/broker_test.go b/pkg/reconciler/mtbroker/broker_test.go index cc81b5a6790..75e320953ad 100644 --- a/pkg/reconciler/mtbroker/broker_test.go +++ b/pkg/reconciler/mtbroker/broker_test.go @@ -33,7 +33,7 @@ import ( "knative.dev/eventing/pkg/apis/eventing" eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" "knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable" "knative.dev/eventing/pkg/client/injection/reconciler/eventing/v1/broker" @@ -85,7 +85,7 @@ const ( testSchedule = "*/2 * * * *" testData = "data" sinkName = "testsink" - dependencyAnnotation = "{\"kind\":\"PingSource\",\"name\":\"test-ping-source\",\"apiVersion\":\"sources.knative.dev/v1alpha2\"}" + dependencyAnnotation = "{\"kind\":\"PingSource\",\"name\":\"test-ping-source\",\"apiVersion\":\"sources.knative.dev/v1beta1\"}" subscriberURIReference = "foo" subscriberResolvedTargetURI = "http://example.com/subscriber/foo" @@ -724,39 +724,37 @@ func makeFalseStatusSubscription() *messagingv1.Subscription { return s } -func makeFalseStatusPingSource() *sourcesv1alpha2.PingSource { - return rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS, rtv1alpha1.WithPingSourceV1A2SinkNotFound) +func makeFalseStatusPingSource() *sourcesv1beta1.PingSource { + return rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS, rtv1alpha1.WithPingSourceV1B1SinkNotFound) } -func makeUnknownStatusCronJobSource() *sourcesv1alpha2.PingSource { - cjs := rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS) +func makeUnknownStatusCronJobSource() *sourcesv1beta1.PingSource { + cjs := rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS) cjs.Status.InitializeConditions() return cjs } -func makeGenerationNotEqualPingSource() *sourcesv1alpha2.PingSource { +func makeGenerationNotEqualPingSource() *sourcesv1beta1.PingSource { c := makeFalseStatusPingSource() c.Generation = currentGeneration c.Status.ObservedGeneration = outdatedGeneration return c } -func makeReadyPingSource() *sourcesv1alpha2.PingSource { +func makeReadyPingSource() *sourcesv1beta1.PingSource { u, _ := apis.ParseURL(sinkURI) - return rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS, - rtv1alpha1.WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + return rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS, + rtv1alpha1.WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: brokerDestv1, }, }), - rtv1alpha1.WithInitPingSourceV1A2Conditions, - rtv1alpha1.WithValidPingSourceV1A2Schedule, - rtv1alpha1.WithValidPingSourceV1A2Resources, - rtv1alpha1.WithPingSourceV1A2Deployed, - rtv1alpha1.WithPingSourceV1A2CloudEventAttributes, - rtv1alpha1.WithPingSourceV1A2Sink(u), + rtv1alpha1.WithInitPingSourceV1B1Conditions, + rtv1alpha1.WithPingSourceV1B1Deployed, + rtv1alpha1.WithPingSourceV1B1CloudEventAttributes, + rtv1alpha1.WithPingSourceV1B1Sink(u), ) } func makeSubscriberKubernetesServiceAsUnstructured() *unstructured.Unstructured { diff --git a/pkg/reconciler/mtbroker/trigger/trigger_test.go b/pkg/reconciler/mtbroker/trigger/trigger_test.go index b319ba51fd2..19e2adabdf8 100644 --- a/pkg/reconciler/mtbroker/trigger/trigger_test.go +++ b/pkg/reconciler/mtbroker/trigger/trigger_test.go @@ -33,7 +33,7 @@ import ( "knative.dev/eventing/pkg/apis/eventing" eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" "knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable" "knative.dev/eventing/pkg/client/injection/reconciler/eventing/v1/trigger" @@ -946,39 +946,37 @@ func makeFalseStatusSubscription() *messagingv1.Subscription { return s } -func makeFalseStatusPingSource() *sourcesv1alpha2.PingSource { - return rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS, rtv1alpha1.WithPingSourceV1A2SinkNotFound) +func makeFalseStatusPingSource() *sourcesv1beta1.PingSource { + return rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS, rtv1alpha1.WithPingSourceV1B1SinkNotFound) } -func makeUnknownStatusCronJobSource() *sourcesv1alpha2.PingSource { - cjs := rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS) +func makeUnknownStatusCronJobSource() *sourcesv1beta1.PingSource { + cjs := rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS) cjs.Status.InitializeConditions() return cjs } -func makeGenerationNotEqualPingSource() *sourcesv1alpha2.PingSource { +func makeGenerationNotEqualPingSource() *sourcesv1beta1.PingSource { c := makeFalseStatusPingSource() c.Generation = currentGeneration c.Status.ObservedGeneration = outdatedGeneration return c } -func makeReadyPingSource() *sourcesv1alpha2.PingSource { +func makeReadyPingSource() *sourcesv1beta1.PingSource { u, _ := apis.ParseURL(sinkURI) - return rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS, - rtv1alpha1.WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + return rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS, + rtv1alpha1.WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: brokerDestv1, }, }), - rtv1alpha1.WithInitPingSourceV1A2Conditions, - rtv1alpha1.WithValidPingSourceV1A2Schedule, - rtv1alpha1.WithValidPingSourceV1A2Resources, - rtv1alpha1.WithPingSourceV1A2Deployed, - rtv1alpha1.WithPingSourceV1A2CloudEventAttributes, - rtv1alpha1.WithPingSourceV1A2Sink(u), + rtv1alpha1.WithInitPingSourceV1B1Conditions, + rtv1alpha1.WithPingSourceV1B1Deployed, + rtv1alpha1.WithPingSourceV1B1CloudEventAttributes, + rtv1alpha1.WithPingSourceV1B1Sink(u), ) } func makeSubscriberKubernetesServiceAsUnstructured() *unstructured.Unstructured { diff --git a/pkg/reconciler/pingsource/controller.go b/pkg/reconciler/pingsource/controller.go index 8b1959d7aa8..98d14bc11c6 100644 --- a/pkg/reconciler/pingsource/controller.go +++ b/pkg/reconciler/pingsource/controller.go @@ -38,9 +38,9 @@ import ( "knative.dev/eventing/pkg/adapter/mtping" "knative.dev/eventing/pkg/adapter/v2" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" - pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource" - pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" + "knative.dev/eventing/pkg/apis/sources/v1beta1" + pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/pingsource" + pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" reconcilersource "knative.dev/eventing/pkg/reconciler/source" eventingcache "knative.dev/eventing/pkg/utils/cache" ) @@ -107,7 +107,7 @@ func NewController( // Watch for deployments owned by the source (single-tenant) deploymentInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterControllerGK(v1alpha2.Kind("PingSource")), + FilterFunc: controller.FilterControllerGK(v1beta1.Kind("PingSource")), Handler: controller.HandleAll(impl.EnqueueControllerOf), }) diff --git a/pkg/reconciler/pingsource/controller_test.go b/pkg/reconciler/pingsource/controller_test.go index 68691a713a8..6b30971477a 100644 --- a/pkg/reconciler/pingsource/controller_test.go +++ b/pkg/reconciler/pingsource/controller_test.go @@ -27,7 +27,7 @@ import ( // Fake injection informers _ "knative.dev/eventing/pkg/client/injection/informers/eventing/v1beta1/eventtype/fake" - _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/pingsource/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/core/v1/serviceaccount/fake" diff --git a/pkg/reconciler/pingsource/pingsource.go b/pkg/reconciler/pingsource/pingsource.go index fd48198b1ab..4ff64affba9 100644 --- a/pkg/reconciler/pingsource/pingsource.go +++ b/pkg/reconciler/pingsource/pingsource.go @@ -46,9 +46,9 @@ import ( "knative.dev/pkg/tracker" "knative.dev/eventing/pkg/apis/eventing" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" - pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" - listers "knative.dev/eventing/pkg/client/listers/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" + pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" + listers "knative.dev/eventing/pkg/client/listers/sources/v1beta1" "knative.dev/eventing/pkg/logging" "knative.dev/eventing/pkg/reconciler/pingsource/resources" recresources "knative.dev/eventing/pkg/reconciler/resources" @@ -109,7 +109,7 @@ type Reconciler struct { // Check that our Reconciler implements ReconcileKind var _ pingsourcereconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSource) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1beta1.PingSource) pkgreconciler.Event { // This Source attempts to reconcile three things. // 1. Determine the sink's URI. // - Nothing to delete. @@ -136,10 +136,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSou } source.Status.MarkSink(sinkURI) - // The webhook does not allow for invalid schedules to be posted. - // TODO: remove MarkSchedule - source.Status.MarkSchedule() - scope, ok := source.Annotations[eventing.ScopeAnnotationKey] if !ok { scope = eventing.ScopeCluster @@ -187,14 +183,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSou } source.Status.CloudEventAttributes = []duckv1.CloudEventAttributes{{ - Type: v1alpha2.PingSourceEventType, - Source: v1alpha2.PingSourceSource(source.Namespace, source.Name), + Type: v1beta1.PingSourceEventType, + Source: v1beta1.PingSourceSource(source.Namespace, source.Name), }} return nil } -func (r *Reconciler) reconcileServiceAccount(ctx context.Context, source *v1alpha2.PingSource) (*corev1.ServiceAccount, error) { +func (r *Reconciler) reconcileServiceAccount(ctx context.Context, source *v1beta1.PingSource) (*corev1.ServiceAccount, error) { saName := resources.CreateReceiveAdapterName(source.Name, source.UID) sa, err := r.serviceAccountLister.ServiceAccounts(source.Namespace).Get(saName) if err != nil { @@ -215,7 +211,7 @@ func (r *Reconciler) reconcileServiceAccount(ctx context.Context, source *v1alph return sa, nil } -func (r *Reconciler) reconcileRoleBinding(ctx context.Context, source *v1alpha2.PingSource) (*rbacv1.RoleBinding, error) { +func (r *Reconciler) reconcileRoleBinding(ctx context.Context, source *v1beta1.PingSource) (*rbacv1.RoleBinding, error) { rbName := resources.CreateReceiveAdapterName(source.Name, source.UID) rb, err := r.roleBindingLister.RoleBindings(source.Namespace).Get(rbName) @@ -236,7 +232,7 @@ func (r *Reconciler) reconcileRoleBinding(ctx context.Context, source *v1alpha2. return rb, nil } -func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1alpha2.PingSource, sinkURI *apis.URL) (*appsv1.Deployment, error) { +func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1beta1.PingSource, sinkURI *apis.URL) (*appsv1.Deployment, error) { loggingConfig, err := pkgLogging.LoggingConfigToJson(r.configs.LoggingConfig()) if err != nil { logging.FromContext(ctx).Error("error while converting logging config to JSON", zap.Any("receiveAdapter", err)) @@ -292,7 +288,7 @@ func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1alpha2.Pin return ra, nil } -func (r *Reconciler) reconcileMTReceiveAdapter(ctx context.Context, source *v1alpha2.PingSource) (*appsv1.Deployment, error) { +func (r *Reconciler) reconcileMTReceiveAdapter(ctx context.Context, source *v1beta1.PingSource) (*appsv1.Deployment, error) { loggingConfig, err := pkgLogging.LoggingConfigToJson(r.configs.LoggingConfig()) if err != nil { logging.FromContext(ctx).Error("error while converting logging config to JSON", zap.Any("receiveAdapter", err)) diff --git a/pkg/reconciler/pingsource/pingsource_test.go b/pkg/reconciler/pingsource/pingsource_test.go index 9a775588b9e..35395d3224d 100644 --- a/pkg/reconciler/pingsource/pingsource_test.go +++ b/pkg/reconciler/pingsource/pingsource_test.go @@ -30,9 +30,9 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" clientgotesting "k8s.io/client-go/testing" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" - "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" + "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" "knative.dev/eventing/pkg/reconciler/pingsource/resources" recresources "knative.dev/eventing/pkg/reconciler/resources" "knative.dev/eventing/pkg/utils" @@ -105,36 +105,36 @@ func TestAllCases(t *testing.T) { }, { Name: "missing sink", Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), }, Key: testNS + "/" + sourceName, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithInitPingSourceV1A2Conditions, - WithPingSourceV1A2StatusObservedGeneration(generation), - WithPingSourceV1A2SinkNotFound, + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1StatusObservedGeneration(generation), + WithPingSourceV1B1SinkNotFound, ), }}, WantEvents: []string{ @@ -144,17 +144,17 @@ func TestAllCases(t *testing.T) { }, { Name: "valid", Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -172,40 +172,39 @@ func TestAllCases(t *testing.T) { MakeRoleBinding(sourceName, sourceUID), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2StatusObservedGeneration(generation), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, }, { Name: "valid with sink URI", Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDestURI, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -223,40 +222,39 @@ func TestAllCases(t *testing.T) { MakeRoleBinding(sourceName, sourceUID), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDestURI, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2StatusObservedGeneration(generation), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, }, { Name: "valid, existing ra", Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -274,45 +272,43 @@ func TestAllCases(t *testing.T) { MakeRoleBinding(sourceName, sourceUID), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2StatusObservedGeneration(generation), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, }, { Name: "valid, no change", Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -324,40 +320,39 @@ func TestAllCases(t *testing.T) { }, Key: testNS + "/" + sourceName, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2StatusObservedGeneration(generation), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, }, { Name: "valid", Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -375,40 +370,39 @@ func TestAllCases(t *testing.T) { MakeRoleBinding(sourceName, sourceUID), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2StatusObservedGeneration(generation), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, }, { Name: "valid with cluster scope annotation", Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ClusterScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ClusterScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -418,42 +412,40 @@ func TestAllCases(t *testing.T) { }, Key: testNS + "/" + sourceName, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ClusterScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ClusterScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2StatusObservedGeneration(generation), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, }, { Name: "valid with cluster scope annotation, create deployment", SkipNamespaceValidation: true, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ClusterScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ClusterScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -468,41 +460,40 @@ func TestAllCases(t *testing.T) { MakeMTAdapter(), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ClusterScopeAnnotation, - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ClusterScopeAnnotation, + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithPingSourceV1A2NotDeployed(mtadapterName), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2StatusObservedGeneration(generation), + WithPingSourceV1B1NotDeployed(mtadapterName), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, }, { Name: "deprecated named adapter deployment found", SkipNamespaceValidation: true, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceNameLong, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceNameLong, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUIDLong), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUIDLong), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -522,24 +513,23 @@ func TestAllCases(t *testing.T) { makeReceiveAdapterWithSinkAndCustomData(sourceNameLong, sourceUIDLong, sinkDest), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceNameLong, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceNameLong, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2ResourceScopeAnnotation, - WithPingSourceV1A2UID(sourceUIDLong), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1ResourceScopeAnnotation, + WithPingSourceV1B1UID(sourceUIDLong), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithPingSourceV1A2NotDeployed(makeReceiveAdapterWithSinkAndCustomData(sourceNameLong, sourceUIDLong, sinkDest).Name), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2StatusObservedGeneration(generation), + WithPingSourceV1B1NotDeployed(makeReceiveAdapterWithSinkAndCustomData(sourceNameLong, sourceUIDLong, sinkDest).Name), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, WantDeletes: []clientgotesting.DeleteActionImpl{{ @@ -553,7 +543,7 @@ func TestAllCases(t *testing.T) { ctx = addressable.WithDuck(ctx) r := &Reconciler{ kubeClientSet: fakekubeclient.Get(ctx), - pingLister: listers.GetPingSourceV1alpha2Lister(), + pingLister: listers.GetPingSourceV1beta1Lister(), deploymentLister: listers.GetDeploymentLister(), serviceAccountLister: listers.GetServiceAccountLister(), roleBindingLister: listers.GetRoleBindingLister(), @@ -564,7 +554,7 @@ func TestAllCases(t *testing.T) { r.sinkResolver = resolver.NewURIResolver(ctx, func(types.NamespacedName) {}) return pingsource.NewReconciler(ctx, logging.FromContext(ctx), - fakeeventingclient.Get(ctx), listers.GetPingSourceV1alpha2Lister(), + fakeeventingclient.Get(ctx), listers.GetPingSourceV1beta1Lister(), controller.GetEventRecorder(ctx), r) }, true, @@ -581,7 +571,7 @@ func makeAvailableReceiveAdapter(dest duckv1.Destination) *appsv1.Deployment { // makeAvailableReceiveAdapterDeprecatedName needed to simulate pre 0.14 adapter whose name was generated using utils.GenerateFixedName func makeAvailableReceiveAdapterDeprecatedName(sourceName string, sourceUID string, dest duckv1.Destination) *appsv1.Deployment { ra := makeReceiveAdapterWithSink(dest) - src := &sourcesv1alpha2.PingSource{} + src := &sourcesv1beta1.PingSource{} src.UID = types.UID(sourceUID) ra.Name = utils.GenerateFixedName(src, fmt.Sprintf("pingsource-%s", sourceName)) WithDeploymentAvailable()(ra) @@ -589,8 +579,8 @@ func makeAvailableReceiveAdapterDeprecatedName(sourceName string, sourceUID stri } func makeReceiveAdapterWithSinkAndCustomData(sourceName, sourceUID string, dest duckv1.Destination) *appsv1.Deployment { - source := NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + source := NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ @@ -598,12 +588,11 @@ func makeReceiveAdapterWithSinkAndCustomData(sourceName, sourceUID string, dest }, }, ), - WithPingSourceV1A2UID(sourceUID), + WithPingSourceV1B1UID(sourceUID), // Status Update: - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), ) args := resources.Args{ @@ -636,13 +625,13 @@ func makeAvailableMTAdapter() *appsv1.Deployment { } func MakeServiceAccount(sourceName, sourceUID string) *corev1.ServiceAccount { - source := NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2UID(sourceUID)) + source := NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1UID(sourceUID)) return recresources.MakeServiceAccount(source, resources.CreateReceiveAdapterName(sourceName, types.UID(sourceUID))) } func MakeRoleBinding(sourceName, sourceUID string) *rbacv1.RoleBinding { - source := NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2UID(sourceUID)) + source := NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1UID(sourceUID)) return resources.MakeRoleBinding(source, resources.CreateReceiveAdapterName(sourceName, types.UID(sourceUID)), crName) } diff --git a/pkg/reconciler/pingsource/resources/receive_adapter.go b/pkg/reconciler/pingsource/resources/receive_adapter.go index 0b53166e0e2..91d16f1be41 100644 --- a/pkg/reconciler/pingsource/resources/receive_adapter.go +++ b/pkg/reconciler/pingsource/resources/receive_adapter.go @@ -28,7 +28,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" "knative.dev/pkg/kmeta" ) @@ -41,7 +41,7 @@ var ( // field is required. type Args struct { Image string - Source *v1alpha2.PingSource + Source *v1beta1.PingSource Labels map[string]string SinkURI *apis.URL MetricsConfig string diff --git a/pkg/reconciler/pingsource/resources/receive_adapter_test.go b/pkg/reconciler/pingsource/resources/receive_adapter_test.go index 538e7f8604f..2fdf1a02ef3 100644 --- a/pkg/reconciler/pingsource/resources/receive_adapter_test.go +++ b/pkg/reconciler/pingsource/resources/receive_adapter_test.go @@ -27,17 +27,17 @@ import ( "knative.dev/pkg/apis" "knative.dev/pkg/kmp" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func TestMakeReceiveAdapter(t *testing.T) { - src := &v1alpha2.PingSource{ + src := &v1beta1.PingSource{ ObjectMeta: metav1.ObjectMeta{ Name: "source-name", Namespace: "source-namespace", UID: "source-uid", }, - Spec: v1alpha2.PingSourceSpec{ + Spec: v1beta1.PingSourceSpec{ Schedule: "*/2 * * * *", JsonData: "data", }, @@ -66,7 +66,7 @@ func TestMakeReceiveAdapter(t *testing.T) { "test-key2": "test-value2", }, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "sources.knative.dev/v1alpha2", + APIVersion: "sources.knative.dev/v1beta1", Kind: "PingSource", Name: src.Name, UID: src.UID, diff --git a/pkg/reconciler/pingsource/resources/role_binding.go b/pkg/reconciler/pingsource/resources/role_binding.go index 138a3d9cb5f..fe8e82c6b61 100644 --- a/pkg/reconciler/pingsource/resources/role_binding.go +++ b/pkg/reconciler/pingsource/resources/role_binding.go @@ -21,12 +21,12 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/kmeta" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" ) // MakeRoleBinding creates a RoleBinding object for the single-tenant receive adapter // service account 'sa' in the Namespace 'ns'. -func MakeRoleBinding(source *v1alpha2.PingSource, name string, clusterRoleName string) *rbacv1.RoleBinding { +func MakeRoleBinding(source *v1beta1.PingSource, name string, clusterRoleName string) *rbacv1.RoleBinding { return &rbacv1.RoleBinding{ ObjectMeta: metav1.ObjectMeta{ Name: name, diff --git a/pkg/reconciler/pingsource/resources/role_binding_test.go b/pkg/reconciler/pingsource/resources/role_binding_test.go index a3ad7245fae..1f1f46ff8f6 100644 --- a/pkg/reconciler/pingsource/resources/role_binding_test.go +++ b/pkg/reconciler/pingsource/resources/role_binding_test.go @@ -24,7 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/kmeta" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func TestNewRoleBinding(t *testing.T) { @@ -33,13 +33,13 @@ func TestNewRoleBinding(t *testing.T) { crName = "my-test-cluster-role" testNS = "test-ns" ) - src := &v1alpha2.PingSource{ + src := &v1beta1.PingSource{ ObjectMeta: metav1.ObjectMeta{ Name: "source-name", Namespace: testNS, UID: "source-uid", }, - Spec: v1alpha2.PingSourceSpec{ + Spec: v1beta1.PingSourceSpec{ Schedule: "*/2 * * * *", JsonData: "data", }, diff --git a/pkg/reconciler/resources/service_account_test.go b/pkg/reconciler/resources/service_account_test.go index a9c13ef3d12..dea87165f91 100644 --- a/pkg/reconciler/resources/service_account_test.go +++ b/pkg/reconciler/resources/service_account_test.go @@ -24,13 +24,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/kmeta" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func TestNewServiceAccount(t *testing.T) { testNS := "test-ns" testName := "test-name" - obj := &v1alpha2.PingSource{ + obj := &v1beta1.PingSource{ ObjectMeta: metav1.ObjectMeta{ Name: testName, Namespace: testNS, diff --git a/pkg/reconciler/testing/listers.go b/pkg/reconciler/testing/listers.go index 22822b57342..ca24f2dc589 100644 --- a/pkg/reconciler/testing/listers.go +++ b/pkg/reconciler/testing/listers.go @@ -164,8 +164,8 @@ func (l *Listers) GetSinkBindingLister() sourcelisters.SinkBindingLister { return sourcelisters.NewSinkBindingLister(l.indexerFor(&sourcesv1alpha1.SinkBinding{})) } -func (l *Listers) GetPingSourceV1alpha2Lister() sourcev1alpha2listers.PingSourceLister { - return sourcev1alpha2listers.NewPingSourceLister(l.indexerFor(&sourcesv1alpha2.PingSource{})) +func (l *Listers) GetPingSourceV1beta1Lister() sourcev1beta1listers.PingSourceLister { + return sourcev1beta1listers.NewPingSourceLister(l.indexerFor(&sourcesv1beta1.PingSource{})) } func (l *Listers) GetContainerSourceV1alpha2Lister() sourcev1alpha2listers.ContainerSourceLister { diff --git a/pkg/reconciler/testing/pingsource.go b/pkg/reconciler/testing/pingsource.go index ff2b2551e54..cb4492da617 100644 --- a/pkg/reconciler/testing/pingsource.go +++ b/pkg/reconciler/testing/pingsource.go @@ -131,12 +131,6 @@ func WithPingSourceV1A2Spec(spec v1alpha2.PingSourceSpec) PingSourceV1A2Option { } } -func WithPingSourceV1B1Spec(spec v1beta1.PingSourceSpec) PingSourceV1B1Option { - return func(c *v1beta1.PingSource) { - c.Spec = spec - } -} - func WithPingSourceV1A2StatusObservedGeneration(generation int64) PingSourceV1A2Option { return func(c *v1alpha2.PingSource) { c.Status.ObservedGeneration = generation @@ -159,3 +153,83 @@ func WithPingSourceV1A2Deleted(c *v1alpha2.PingSource) { t := metav1.NewTime(time.Unix(1e9, 0)) c.SetDeletionTimestamp(&t) } + +func WithPingSourceV1B1UID(uid string) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.UID = types.UID(uid) + } +} + +func WithPingSourceV1B1ResourceScopeAnnotation(c *v1beta1.PingSource) { + if c.Annotations == nil { + c.Annotations = make(map[string]string) + } + c.Annotations[eventing.ScopeAnnotationKey] = eventing.ScopeResource +} + +func WithPingSourceV1B1ClusterScopeAnnotation(c *v1beta1.PingSource) { + if c.Annotations == nil { + c.Annotations = make(map[string]string) + } + c.Annotations[eventing.ScopeAnnotationKey] = eventing.ScopeCluster +} + +func WithInitPingSourceV1B1Conditions(s *v1beta1.PingSource) { + s.Status.InitializeConditions() +} + +func WithPingSourceV1B1SinkNotFound(s *v1beta1.PingSource) { + s.Status.MarkNoSink("NotFound", "") +} + +func WithPingSourceV1B1Sink(uri *apis.URL) PingSourceV1B1Option { + return func(s *v1beta1.PingSource) { + s.Status.MarkSink(uri) + } +} + +func WithPingSourceV1B1NotDeployed(name string) PingSourceV1B1Option { + return func(s *v1beta1.PingSource) { + s.Status.PropagateDeploymentAvailability(NewDeployment(name, "any")) + } +} + +func WithPingSourceV1B1Deployed(s *v1beta1.PingSource) { + s.Status.PropagateDeploymentAvailability(NewDeployment("any", "any", WithDeploymentAvailable())) +} + +func WithPingSourceV1B1CloudEventAttributes(s *v1beta1.PingSource) { + s.Status.CloudEventAttributes = []duckv1.CloudEventAttributes{{ + Type: v1beta1.PingSourceEventType, + Source: v1beta1.PingSourceSource(s.Namespace, s.Name), + }} +} + +func WithPingSourceV1B1Spec(spec v1beta1.PingSourceSpec) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.Spec = spec + } +} + +func WithPingSourceV1B1StatusObservedGeneration(generation int64) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.Status.ObservedGeneration = generation + } +} + +func WithPingSourceV1B1ObjectMetaGeneration(generation int64) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.ObjectMeta.Generation = generation + } +} + +func WithPingSourceV1B1Finalizers(finalizers ...string) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.Finalizers = finalizers + } +} + +func WithPingSourceV1B1Deleted(c *v1beta1.PingSource) { + t := metav1.NewTime(time.Unix(1e9, 0)) + c.SetDeletionTimestamp(&t) +} diff --git a/pkg/reconciler/testing/v1beta1/listers.go b/pkg/reconciler/testing/v1beta1/listers.go index 9c046b0df24..da0b0cea48d 100644 --- a/pkg/reconciler/testing/v1beta1/listers.go +++ b/pkg/reconciler/testing/v1beta1/listers.go @@ -162,8 +162,8 @@ func (l *Listers) GetSinkBindingLister() sourcelisters.SinkBindingLister { return sourcelisters.NewSinkBindingLister(l.indexerFor(&sourcesv1alpha1.SinkBinding{})) } -func (l *Listers) GetPingSourceV1alpha2Lister() sourcev1alpha2listers.PingSourceLister { - return sourcev1alpha2listers.NewPingSourceLister(l.indexerFor(&sourcesv1alpha2.PingSource{})) +func (l *Listers) GetPingSourceV1beta1Lister() sourcev1beta1listers.PingSourceLister { + return sourcev1beta1listers.NewPingSourceLister(l.indexerFor(&sourcesv1beta1.PingSource{})) } func (l *Listers) GetContainerSourceLister() sourcev1alpha2listers.ContainerSourceLister { diff --git a/test/conformance/main_test.go b/test/conformance/main_test.go index 09c8e230aaf..ff3c20c920f 100644 --- a/test/conformance/main_test.go +++ b/test/conformance/main_test.go @@ -83,7 +83,7 @@ func addSourcesInitializers() { ) sourcesTestRunner.AddComponentSetupClientOption( testlib.PingSourceTypeMeta, - setupclientoptions.PingSourceV1A2ClientSetupOption(pingSrcName, + setupclientoptions.PingSourceV1B1ClientSetupOption(pingSrcName, recordEventsPingPodName), ) } diff --git a/test/e2e/trigger_dependency_annotation_test.go b/test/e2e/trigger_dependency_annotation_test.go index efc65faa1f2..7fa76d7ae5c 100644 --- a/test/e2e/trigger_dependency_annotation_test.go +++ b/test/e2e/trigger_dependency_annotation_test.go @@ -30,7 +30,7 @@ import ( "knative.dev/pkg/apis" "knative.dev/eventing/pkg/apis/eventing" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" sugarresources "knative.dev/eventing/pkg/reconciler/sugar/resources" eventingtesting "knative.dev/eventing/pkg/reconciler/testing" testlib "knative.dev/eventing/test/lib" @@ -47,7 +47,7 @@ func TestTriggerDependencyAnnotation(t *testing.T) { defaultBrokerName = sugarresources.DefaultBrokerName triggerName = "trigger-annotation" subscriberName = "subscriber-annotation" - dependencyAnnotation = `{"kind":"PingSource","name":"test-ping-source-annotation","apiVersion":"sources.knative.dev/v1alpha2"}` + dependencyAnnotation = `{"kind":"PingSource","name":"test-ping-source-annotation","apiVersion":"sources.knative.dev/v1beta1"}` pingSourceName = "test-ping-source-annotation" // Every 1 minute starting from now schedule = "*/1 * * * *" @@ -74,10 +74,10 @@ func TestTriggerDependencyAnnotation(t *testing.T) { ) jsonData := fmt.Sprintf(`{"msg":"Test trigger-annotation %s"}`, uuid.NewUUID()) - pingSource := eventingtesting.NewPingSourceV1Alpha2( + pingSource := eventingtesting.NewPingSourceV1Beta1( pingSourceName, client.Namespace, - eventingtesting.WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + eventingtesting.WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: schedule, JsonData: jsonData, SourceSpec: duckv1.SourceSpec{ @@ -93,13 +93,13 @@ func TestTriggerDependencyAnnotation(t *testing.T) { } } - client.CreatePingSourceV1Alpha2OrFail(pingSource) + client.CreatePingSourceV1Beta1OrFail(pingSource) // Trigger should become ready after pingSource was created client.WaitForResourceReadyOrFail(triggerName, testlib.TriggerTypeMeta) eventTracker.AssertAtLeast(1, recordevents.MatchEvent( - HasSource(sourcesv1alpha2.PingSourceSource(client.Namespace, pingSourceName)), + HasSource(sourcesv1beta1.PingSourceSource(client.Namespace, pingSourceName)), HasData([]byte(jsonData)), )) } diff --git a/test/lib/setupclientoptions/sources.go b/test/lib/setupclientoptions/sources.go index f5ab1246a12..3f271af1a1e 100644 --- a/test/lib/setupclientoptions/sources.go +++ b/test/lib/setupclientoptions/sources.go @@ -22,7 +22,6 @@ import ( rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/util/uuid" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" eventingtesting "knative.dev/eventing/pkg/reconciler/testing" testlib "knative.dev/eventing/test/lib" @@ -68,10 +67,10 @@ func ApiServerSourceV1B1ClientSetupOption(name string, mode string, recordEvents } } -// PingSourceV1A2ClientSetupOption returns a ClientSetupOption that can be used +// PingSourceV1B1ClientSetupOption returns a ClientSetupOption that can be used // to create a new PingSource. It creates a RecordEvents pod and a // PingSource object with the RecordEvent pod as its sink. -func PingSourceV1A2ClientSetupOption(name string, recordEventsPodName string) testlib.SetupClientOption { +func PingSourceV1B1ClientSetupOption(name string, recordEventsPodName string) testlib.SetupClientOption { return func(client *testlib.Client) { // create event logger pod and service @@ -79,10 +78,10 @@ func PingSourceV1A2ClientSetupOption(name string, recordEventsPodName string) te // create cron job source data := fmt.Sprintf(`{"msg":"TestPingSource %s"}`, uuid.NewUUID()) - source := eventingtesting.NewPingSourceV1Alpha2( + source := eventingtesting.NewPingSourceV1Beta1( name, client.Namespace, - eventingtesting.WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + eventingtesting.WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ JsonData: data, SourceSpec: duckv1.SourceSpec{ Sink: duckv1.Destination{ @@ -91,7 +90,7 @@ func PingSourceV1A2ClientSetupOption(name string, recordEventsPodName string) te }, }), ) - client.CreatePingSourceV1Alpha2OrFail(source) + client.CreatePingSourceV1Beta1OrFail(source) // wait for all test resources to be ready client.WaitForAllTestResourcesReadyOrFail() From 0c988ece16d3ef7fc260edc3fe2a9560ab559878 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Thu, 27 Aug 2020 17:32:22 -0400 Subject: [PATCH 02/20] Merge updates Signed-off-by: Ansu Varghese --- config/pre-install/v0.18.0/storage-version-migration.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/config/pre-install/v0.18.0/storage-version-migration.yaml b/config/pre-install/v0.18.0/storage-version-migration.yaml index 290cd9aec80..0db8d5ae5e5 100644 --- a/config/pre-install/v0.18.0/storage-version-migration.yaml +++ b/config/pre-install/v0.18.0/storage-version-migration.yaml @@ -44,10 +44,7 @@ spec: - "triggers.eventing.knative.dev" - "channels.messaging.knative.dev" - "inmemorychannels.messaging.knative.dev" -<<<<<<< HEAD - "pingsources.sources.knative.dev" -======= - "subscriptions.messaging.knative.dev" - "parallels.flows.knative.dev" - "sequences.flows.knative.dev" ->>>>>>> origin/master From 3d57bb715a28a40a27bdc1e46d9550f1e7157fdf Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Thu, 27 Aug 2020 17:34:33 -0400 Subject: [PATCH 03/20] Removing trailing whitespace Signed-off-by: Ansu Varghese --- config/pre-install/v0.18.0/pingsource.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/pre-install/v0.18.0/pingsource.yaml b/config/pre-install/v0.18.0/pingsource.yaml index 5222eb55c1d..ac462088d97 100644 --- a/config/pre-install/v0.18.0/pingsource.yaml +++ b/config/pre-install/v0.18.0/pingsource.yaml @@ -43,7 +43,7 @@ spec: properties: spec: type: object - description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' properties: ceOverrides: description: 'CloudEventOverrides defines overrides to control the @@ -56,7 +56,7 @@ spec: pair are set on the event as an attribute extension independently.' type: object additionalProperties: - type: string + type: string x-kubernetes-preserve-unknown-fields: true jsonData: description: 'JsonData is json encoded data used as the body of the @@ -102,7 +102,7 @@ spec: timezone. Defaults to the system time zone. More general information about time zones: https://www.iana.org/time-zones List of valid timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' - type: string + type: string status: type: object description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' @@ -171,7 +171,7 @@ spec: sinkUri: description: 'SinkURI is the current active sink URI that has been configured for the Source.' - type: string + type: string additionalPrinterColumns: - name: Ready type: string From 790584a88899574495bc96291024dd6b840adbe4 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 11:25:23 -0400 Subject: [PATCH 04/20] Changes from review Signed-off-by: Ansu Varghese --- config/core/resources/pingsource.yaml | 2 +- config/pre-install/v0.18.0/pingsource.yaml | 173 ++++++++++++++++++--- 2 files changed, 152 insertions(+), 23 deletions(-) diff --git a/config/core/resources/pingsource.yaml b/config/core/resources/pingsource.yaml index fd13efd7b03..d50327d78de 100644 --- a/config/core/resources/pingsource.yaml +++ b/config/core/resources/pingsource.yaml @@ -32,7 +32,7 @@ spec: versions: - &version name: v1alpha2 - served: false + served: true storage: false subresources: status: {} diff --git a/config/pre-install/v0.18.0/pingsource.yaml b/config/pre-install/v0.18.0/pingsource.yaml index ac462088d97..d50327d78de 100644 --- a/config/pre-install/v0.18.0/pingsource.yaml +++ b/config/pre-install/v0.18.0/pingsource.yaml @@ -31,9 +31,9 @@ spec: group: sources.knative.dev versions: - &version - name: v1beta1 + name: v1alpha2 served: true - storage: true + storage: false subresources: status: {} schema: @@ -41,9 +41,9 @@ spec: type: object description: 'PingSource describes an event source with a fixed payload produced on a specified cron schedule.' properties: - spec: + spec: type: object - description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' properties: ceOverrides: description: 'CloudEventOverrides defines overrides to control the @@ -97,12 +97,6 @@ spec: Relative URIs will be resolved using the base URI retrieved from Ref.' type: string - timezone: - description: 'Timezone modifies the actual time relative to the specified - timezone. Defaults to the system time zone. More general information - about time zones: https://www.iana.org/time-zones List of valid - timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' - type: string status: type: object description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' @@ -171,29 +165,164 @@ spec: sinkUri: description: 'SinkURI is the current active sink URI that has been configured for the Source.' - type: string + type: string additionalPrinterColumns: - - name: Ready - type: string - jsonPath: ".status.conditions[?(@.type=='Ready')].status" - - name: Reason - type: string - jsonPath: ".status.conditions[?(@.type=='Ready')].reason" - name: Sink type: string jsonPath: .status.sinkUri - name: Age type: date jsonPath: .metadata.creationTimestamp - - << : *version - name: v1alpha2 - served: false - storage: false + - name: Ready + type: string + jsonPath: ".status.conditions[?(@.type=='Ready')].status" + - name: Reason + type: string + jsonPath: ".status.conditions[?(@.type=='Ready')].reason" + - <<: *version + name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + description: 'PingSource describes an event source with a fixed payload produced on a specified cron schedule.' + properties: + spec: + type: object + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + properties: + ceOverrides: + description: 'CloudEventOverrides defines overrides to control the + output format and modifications of the event sent to the sink.' + type: object + properties: + extensions: + description: 'Extensions specify what attribute are added or + overridden on the outbound event. Each `Extensions` key-value + pair are set on the event as an attribute extension independently.' + type: object + additionalProperties: + type: string + x-kubernetes-preserve-unknown-fields: true + jsonData: + description: 'JsonData is json encoded data used as the body of the + event posted to the sink. Default is empty. If set, datacontenttype + will also be set to "application/json".' + type: string + schedule: + description: 'Schedule is the cronjob schedule. Defaults to `* * * + * *`.' + type: string + sink: + description: 'Sink is a reference to an object that will resolve to + a uri to use as the sink.' + type: object + properties: + ref: + description: 'Ref points to an Addressable.' + type: object + properties: + apiVersion: + description: 'API version of the referent.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: + https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + This is optional field, it gets defaulted to the + object holding it if left out.' + type: string + uri: + description: 'URI can be an absolute URL(non-empty scheme and + non-empty host) pointing to the target or a relative URI. + Relative URIs will be resolved using the base URI retrieved + from Ref.' + type: string + timezone: + description: 'Timezone modifies the actual time relative to the specified + timezone. Defaults to the system time zone. More general information + about time zones: https://www.iana.org/time-zones List of valid + timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' + type: string + status: + type: object + description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' + properties: + annotations: + description: 'Annotations is additional Status fields for the Resource + to save some additional State as well as convey more information + to the user. This is roughly akin to Annotations on any k8s resource, + just the reconciler conveying richer information outwards.' + type: object + x-kubernetes-preserve-unknown-fields: true + ceAttributes: + description: 'CloudEventAttributes are the specific attributes that + the Source uses as part of its CloudEvents.' + type: array + items: + type: object + properties: + source: + description: 'Source is the CloudEvents source attribute.' + type: string + type: + description: 'Type refers to the CloudEvent type attribute.' + type: string + conditions: + description: 'Conditions the latest available observations of a resource''s + current state.' + type: array + items: + type: object + required: + - type + - status + properties: + lastTransitionTime: + description: 'LastTransitionTime is the last time the condition + transitioned from one status to another. We use VolatileTime + in place of metav1.Time to exclude this from creating + equality.Semantic differences (all other things held + constant).' + type: string + message: + description: 'A human readable message indicating details + about the transition.' + type: string + reason: + description: 'The reason for the condition''s last transition.' + type: string + severity: + description: 'Severity with which to treat failures of + this type of condition. When this is not specified, + it defaults to Error.' + type: string + status: + description: 'Status of the condition, one of True, False, + Unknown.' + type: string + type: + description: 'Type of condition.' + type: string + observedGeneration: + description: 'ObservedGeneration is the "Generation" of the Service + that was last processed by the controller.' + type: integer + format: int64 + sinkUri: + description: 'SinkURI is the current active sink URI that has been + configured for the Source.' + type: string names: categories: - all - knative - - eventing - sources kind: PingSource plural: pingsources From 2018418c871a58934a68a99bdc61f0245bb37bb7 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 12:13:07 -0400 Subject: [PATCH 05/20] Fixes from test errors Signed-off-by: Ansu Varghese --- config/pre-install/v0.18.0/storage-version-migration.yaml | 2 +- pkg/reconciler/pingsource/pingsource.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/config/pre-install/v0.18.0/storage-version-migration.yaml b/config/pre-install/v0.18.0/storage-version-migration.yaml index 0db8d5ae5e5..1e87d912543 100644 --- a/config/pre-install/v0.18.0/storage-version-migration.yaml +++ b/config/pre-install/v0.18.0/storage-version-migration.yaml @@ -1,4 +1,4 @@ -.# Copyright 2020 The Knative Authors +# Copyright 2020 The Knative Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/pkg/reconciler/pingsource/pingsource.go b/pkg/reconciler/pingsource/pingsource.go index af5ae76c58c..9ace3a3e899 100644 --- a/pkg/reconciler/pingsource/pingsource.go +++ b/pkg/reconciler/pingsource/pingsource.go @@ -48,7 +48,6 @@ import ( "knative.dev/eventing/pkg/apis/sources/v1beta1" pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" listers "knative.dev/eventing/pkg/client/listers/sources/v1beta1" - "knative.dev/eventing/pkg/logging" "knative.dev/eventing/pkg/reconciler/pingsource/resources" recresources "knative.dev/eventing/pkg/reconciler/resources" reconcilersource "knative.dev/eventing/pkg/reconciler/source" @@ -232,7 +231,7 @@ func (r *Reconciler) reconcileRoleBinding(ctx context.Context, source *v1beta1.P } func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1beta1.PingSource, sinkURI *apis.URL) (*appsv1.Deployment, error) { - loggingConfig, err := pkgLogging.LoggingConfigToJson(r.configs.LoggingConfig()) + loggingConfig, err := logging.LoggingConfigToJson(r.configs.LoggingConfig()) if err != nil { logging.FromContext(ctx).Errorw("error while converting logging config to JSON", zap.Any("receiveAdapter", err)) } @@ -288,7 +287,7 @@ func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1beta1.Ping } func (r *Reconciler) reconcileMTReceiveAdapter(ctx context.Context, source *v1beta1.PingSource) (*appsv1.Deployment, error) { - loggingConfig, err := pkgLogging.LoggingConfigToJson(r.configs.LoggingConfig()) + loggingConfig, err := logging.LoggingConfigToJson(r.configs.LoggingConfig()) if err != nil { logging.FromContext(ctx).Errorw("error while converting logging config to JSON", zap.Any("receiveAdapter", err)) } From 1d9351f727a29147a20ba80e6f91468f332c5956 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 12:15:58 -0400 Subject: [PATCH 06/20] Fixes from test errors Signed-off-by: Ansu Varghese --- config/pre-install/v0.18.0/pingsource.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config/pre-install/v0.18.0/pingsource.yaml b/config/pre-install/v0.18.0/pingsource.yaml index d50327d78de..df5f9e6175d 100644 --- a/config/pre-install/v0.18.0/pingsource.yaml +++ b/config/pre-install/v0.18.0/pingsource.yaml @@ -41,9 +41,9 @@ spec: type: object description: 'PingSource describes an event source with a fixed payload produced on a specified cron schedule.' properties: - spec: + spec: type: object - description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' properties: ceOverrides: description: 'CloudEventOverrides defines overrides to control the @@ -165,7 +165,7 @@ spec: sinkUri: description: 'SinkURI is the current active sink URI that has been configured for the Source.' - type: string + type: string additionalPrinterColumns: - name: Sink type: string @@ -190,7 +190,7 @@ spec: properties: spec: type: object - description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' properties: ceOverrides: description: 'CloudEventOverrides defines overrides to control the @@ -203,7 +203,7 @@ spec: pair are set on the event as an attribute extension independently.' type: object additionalProperties: - type: string + type: string x-kubernetes-preserve-unknown-fields: true jsonData: description: 'JsonData is json encoded data used as the body of the @@ -249,7 +249,7 @@ spec: timezone. Defaults to the system time zone. More general information about time zones: https://www.iana.org/time-zones List of valid timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' - type: string + type: string status: type: object description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' @@ -318,7 +318,7 @@ spec: sinkUri: description: 'SinkURI is the current active sink URI that has been configured for the Source.' - type: string + type: string names: categories: - all From ec79f6c1207e7aa368cbebd8b44dee4d62fae01c Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 13:34:35 -0400 Subject: [PATCH 07/20] Fixes after test errors Signed-off-by: Ansu Varghese --- pkg/adapter/mtping/controller.go | 4 +- pkg/adapter/mtping/controller_test.go | 2 +- pkg/adapter/mtping/pingsource.go | 12 ++--- pkg/adapter/mtping/pingsource_test.go | 70 +++++++++++++-------------- 4 files changed, 42 insertions(+), 46 deletions(-) diff --git a/pkg/adapter/mtping/controller.go b/pkg/adapter/mtping/controller.go index 4d1aa7f1c3d..699463ab234 100644 --- a/pkg/adapter/mtping/controller.go +++ b/pkg/adapter/mtping/controller.go @@ -22,8 +22,8 @@ import ( "github.com/robfig/cron/v3" eventingclient "knative.dev/eventing/pkg/client/injection/client" - pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource" - pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" + pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/pingsource" + pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" kubeclient "knative.dev/pkg/client/injection/kube/client" "knative.dev/pkg/controller" "knative.dev/pkg/logging" diff --git a/pkg/adapter/mtping/controller_test.go b/pkg/adapter/mtping/controller_test.go index df3010ef3e7..97562cf14a5 100644 --- a/pkg/adapter/mtping/controller_test.go +++ b/pkg/adapter/mtping/controller_test.go @@ -22,7 +22,7 @@ import ( . "knative.dev/pkg/reconciler/testing" // Fake injection informers - _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/pingsource/fake" ) func TestNew(t *testing.T) { diff --git a/pkg/adapter/mtping/pingsource.go b/pkg/adapter/mtping/pingsource.go index d01a2e18a82..270d0b29942 100644 --- a/pkg/adapter/mtping/pingsource.go +++ b/pkg/adapter/mtping/pingsource.go @@ -30,10 +30,10 @@ import ( pkgreconciler "knative.dev/pkg/reconciler" "knative.dev/eventing/pkg/apis/eventing" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" clientset "knative.dev/eventing/pkg/client/clientset/versioned" - pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" - sourceslisters "knative.dev/eventing/pkg/client/listers/sources/v1alpha2" + pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" + sourceslisters "knative.dev/eventing/pkg/client/listers/sources/v1beta1" ) // Reconciler reconciles PingSources @@ -53,7 +53,7 @@ var _ pingsourcereconciler.Interface = (*Reconciler)(nil) // Check that our Reconciler implements FinalizeKind. var _ pingsourcereconciler.Finalizer = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSource) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1beta1.PingSource) pkgreconciler.Event { scope, ok := source.Annotations[eventing.ScopeAnnotationKey] if ok && scope != eventing.ScopeCluster { // Not our responsibility @@ -74,7 +74,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSou return reconcileErr } -func (r *Reconciler) reconcile(ctx context.Context, source *v1alpha2.PingSource) error { +func (r *Reconciler) reconcile(ctx context.Context, source *v1beta1.PingSource) error { logging.FromContext(ctx).Info("synchronizing schedule") key := fmt.Sprintf("%s/%s", source.Namespace, source.Name) @@ -110,7 +110,7 @@ func (r *Reconciler) reconcile(ctx context.Context, source *v1alpha2.PingSource) return nil } -func (r *Reconciler) FinalizeKind(ctx context.Context, source *v1alpha2.PingSource) pkgreconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, source *v1beta1.PingSource) pkgreconciler.Event { key := fmt.Sprintf("%s/%s", source.Namespace, source.Name) r.entryidMu.RLock() diff --git a/pkg/adapter/mtping/pingsource_test.go b/pkg/adapter/mtping/pingsource_test.go index f149ef23550..5c21d04e593 100644 --- a/pkg/adapter/mtping/pingsource_test.go +++ b/pkg/adapter/mtping/pingsource_test.go @@ -28,10 +28,10 @@ import ( testclient "k8s.io/client-go/kubernetes/fake" clientgotesting "k8s.io/client-go/testing" adaptertesting "knative.dev/eventing/pkg/adapter/v2/test" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" eventingclient "knative.dev/eventing/pkg/client/injection/client" fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" - "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" + "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" . "knative.dev/eventing/pkg/reconciler/testing" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" @@ -75,8 +75,8 @@ func TestAllCases(t *testing.T) { Name: "valid schedule", Key: pingsourceKey, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(pingSourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(pingSourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ @@ -84,11 +84,10 @@ func TestAllCases(t *testing.T) { CloudEventOverrides: nil, }, }), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, ), }, WantEvents: []string{ @@ -102,8 +101,8 @@ func TestAllCases(t *testing.T) { Name: "valid schedule, with finalizer", Key: pingsourceKey, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(pingSourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(pingSourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ @@ -111,12 +110,11 @@ func TestAllCases(t *testing.T) { CloudEventOverrides: nil, }, }), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2Finalizers(defaultFinalizerName), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1Finalizers(defaultFinalizerName), ), }, WantErr: false, @@ -124,8 +122,8 @@ func TestAllCases(t *testing.T) { Name: "valid schedule, deleted with finalizer", Key: pingsourceKey, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(pingSourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(pingSourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ @@ -133,13 +131,12 @@ func TestAllCases(t *testing.T) { CloudEventOverrides: nil, }, }), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2Finalizers(defaultFinalizerName), - WithPingSourceV1A2Deleted, + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1Finalizers(defaultFinalizerName), + WithPingSourceV1B1Deleted, ), }, WantEvents: []string{ @@ -153,8 +150,8 @@ func TestAllCases(t *testing.T) { Name: "valid schedule, deleted without finalizer", Key: pingsourceKey, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(pingSourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(pingSourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ @@ -162,12 +159,11 @@ func TestAllCases(t *testing.T) { CloudEventOverrides: nil, }, }), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2Deleted, + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1Deleted, ), }, WantErr: false, @@ -181,13 +177,13 @@ func TestAllCases(t *testing.T) { r := &Reconciler{ kubeClient: testclient.NewSimpleClientset(), eventingClientSet: eventingclient.Get(ctx), - pingsourceLister: listers.GetPingSourceV1alpha2Lister(), + pingsourceLister: listers.GetPingSourceV1beta1Lister(), cronRunner: NewCronJobsRunner(ce, testclient.NewSimpleClientset(), logger), entryidMu: sync.RWMutex{}, entryids: make(map[string]cron.EntryID), } return pingsource.NewReconciler(ctx, logging.FromContext(ctx), - fakeeventingclient.Get(ctx), listers.GetPingSourceV1alpha2Lister(), + fakeeventingclient.Get(ctx), listers.GetPingSourceV1beta1Lister(), controller.GetEventRecorder(ctx), r) }, false, logger)) @@ -202,7 +198,7 @@ func patchFinalizers(namespace, name string, finalizers string) clientgotesting. ActionImpl: clientgotesting.ActionImpl{ Namespace: namespace, Verb: "patch", - Resource: schema.GroupVersionResource{Group: "sources.knative.dev", Version: "v1alpha2", Resource: "pingsources"}, + Resource: schema.GroupVersionResource{Group: "sources.knative.dev", Version: "v1beta1", Resource: "pingsources"}, Subresource: "", }, Name: name, From 1e550832d63cd7ecab988b9c840a4005029de236 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 14:14:24 -0400 Subject: [PATCH 08/20] Fixes after test errors Signed-off-by: Ansu Varghese --- pkg/reconciler/mtbroker/trigger/trigger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/reconciler/mtbroker/trigger/trigger_test.go b/pkg/reconciler/mtbroker/trigger/trigger_test.go index 19e2adabdf8..f904c486fe7 100644 --- a/pkg/reconciler/mtbroker/trigger/trigger_test.go +++ b/pkg/reconciler/mtbroker/trigger/trigger_test.go @@ -85,7 +85,7 @@ const ( testSchedule = "*/2 * * * *" testData = "data" sinkName = "testsink" - dependencyAnnotation = "{\"kind\":\"PingSource\",\"name\":\"test-ping-source\",\"apiVersion\":\"sources.knative.dev/v1alpha2\"}" + dependencyAnnotation = "{\"kind\":\"PingSource\",\"name\":\"test-ping-source\",\"apiVersion\":\"sources.knative.dev/v1beta1\"}" subscriberURIReference = "foo" subscriberResolvedTargetURI = "http://example.com/subscriber/foo" From 2a8e83e62d7395cab791dc530065ff4d16bf4406 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 16:46:06 -0400 Subject: [PATCH 09/20] Merge updates Signed-off-by: Ansu Varghese --- pkg/reconciler/pingsource/pingsource.go | 2 +- pkg/reconciler/pingsource/pingsource_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/reconciler/pingsource/pingsource.go b/pkg/reconciler/pingsource/pingsource.go index 2bab49171fa..a60b871491a 100644 --- a/pkg/reconciler/pingsource/pingsource.go +++ b/pkg/reconciler/pingsource/pingsource.go @@ -140,7 +140,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1beta1.PingSour return nil } -func (r *Reconciler) reconcileReceiveAdapter(ctx context.Context, source *v1alpha2.PingSource) (*appsv1.Deployment, error) { +func (r *Reconciler) reconcileReceiveAdapter(ctx context.Context, source *v1beta1.PingSource) (*appsv1.Deployment, error) { loggingConfig, err := logging.LoggingConfigToJson(r.configs.LoggingConfig()) if err != nil { logging.FromContext(ctx).Errorw("error while converting logging config to JSON", zap.Any("receiveAdapter", err)) diff --git a/pkg/reconciler/pingsource/pingsource_test.go b/pkg/reconciler/pingsource/pingsource_test.go index 75dd8ea047d..0f20a253569 100644 --- a/pkg/reconciler/pingsource/pingsource_test.go +++ b/pkg/reconciler/pingsource/pingsource_test.go @@ -229,8 +229,8 @@ func TestAllCases(t *testing.T) { table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler { ctx = addressable.WithDuck(ctx) r := &Reconciler{ - kubeClientSet: fakekubeclient.Get(ctx), - pingLister: listers.GetPingSourceV1beta1Lister(), + kubeClientSet: fakekubeclient.Get(ctx), + pingLister: listers.GetPingSourceV1beta1Lister(), deploymentLister: listers.GetDeploymentLister(), tracker: tracker.New(func(types.NamespacedName) {}, 0), receiveAdapterImage: mtimage, From e94904e347f9a8ee79b07e596bb536a22ae51356 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Thu, 27 Aug 2020 17:05:24 -0400 Subject: [PATCH 10/20] Make PingSource v1beta1 the stored version and add a migration tool Signed-off-by: Ansu Varghese --- config/core/resources/pingsource.yaml | 6 +- config/pre-install/v0.18.0/clusterrole.yaml | 3 +- config/pre-install/v0.18.0/pingsource.yaml | 208 ++++++++++++++++++ .../v0.18.0/storage-version-migration.yaml | 3 +- pkg/adapter/mtping/config.go | 4 +- pkg/adapter/mtping/config_test.go | 16 +- pkg/adapter/mtping/runner.go | 8 +- pkg/reconciler/mtbroker/broker_test.go | 32 ++- .../mtbroker/trigger/trigger_test.go | 28 ++- pkg/reconciler/pingsource/controller.go | 2 + pkg/reconciler/pingsource/controller_test.go | 2 +- pkg/reconciler/pingsource/pingsource.go | 18 +- pkg/reconciler/pingsource/pingsource_test.go | 86 ++++---- .../resources/receive_adapter_test.go | 36 ++- .../resources/service_account_test.go | 4 +- pkg/reconciler/testing/listers.go | 4 +- pkg/reconciler/testing/pingsource.go | 86 +++++++- pkg/reconciler/testing/v1beta1/listers.go | 4 +- test/conformance/main_test.go | 2 +- .../e2e/trigger_dependency_annotation_test.go | 12 +- test/lib/setupclientoptions/sources.go | 11 +- 21 files changed, 437 insertions(+), 138 deletions(-) create mode 100644 config/pre-install/v0.18.0/pingsource.yaml diff --git a/config/core/resources/pingsource.yaml b/config/core/resources/pingsource.yaml index 0b7fdf326dd..fd13efd7b03 100644 --- a/config/core/resources/pingsource.yaml +++ b/config/core/resources/pingsource.yaml @@ -32,8 +32,8 @@ spec: versions: - &version name: v1alpha2 - served: true - storage: true + served: false + storage: false subresources: status: {} schema: @@ -182,7 +182,7 @@ spec: - <<: *version name: v1beta1 served: true - storage: false + storage: true schema: openAPIV3Schema: type: object diff --git a/config/pre-install/v0.18.0/clusterrole.yaml b/config/pre-install/v0.18.0/clusterrole.yaml index 768303c4346..bd64982ed78 100644 --- a/config/pre-install/v0.18.0/clusterrole.yaml +++ b/config/pre-install/v0.18.0/clusterrole.yaml @@ -37,7 +37,8 @@ rules: resources: - "containersources" - "sinkbindings" - verbs: &everything + - "pingsources" + verbs: &everything - "get" - "list" - "create" diff --git a/config/pre-install/v0.18.0/pingsource.yaml b/config/pre-install/v0.18.0/pingsource.yaml new file mode 100644 index 00000000000..5222eb55c1d --- /dev/null +++ b/config/pre-install/v0.18.0/pingsource.yaml @@ -0,0 +1,208 @@ +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + labels: + eventing.knative.dev/release: devel + eventing.knative.dev/source: "true" + duck.knative.dev/source: "true" + knative.dev/crd-install: "true" + annotations: + # TODO add schemas and descriptions + registry.knative.dev/eventTypes: | + [ + { "type": "dev.knative.sources.ping" } + ] + name: pingsources.sources.knative.dev +spec: + group: sources.knative.dev + versions: + - &version + name: v1beta1 + served: true + storage: true + subresources: + status: {} + schema: + openAPIV3Schema: + type: object + description: 'PingSource describes an event source with a fixed payload produced on a specified cron schedule.' + properties: + spec: + type: object + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + properties: + ceOverrides: + description: 'CloudEventOverrides defines overrides to control the + output format and modifications of the event sent to the sink.' + type: object + properties: + extensions: + description: 'Extensions specify what attribute are added or + overridden on the outbound event. Each `Extensions` key-value + pair are set on the event as an attribute extension independently.' + type: object + additionalProperties: + type: string + x-kubernetes-preserve-unknown-fields: true + jsonData: + description: 'JsonData is json encoded data used as the body of the + event posted to the sink. Default is empty. If set, datacontenttype + will also be set to "application/json".' + type: string + schedule: + description: 'Schedule is the cronjob schedule. Defaults to `* * * + * *`.' + type: string + sink: + description: 'Sink is a reference to an object that will resolve to + a uri to use as the sink.' + type: object + properties: + ref: + description: 'Ref points to an Addressable.' + type: object + properties: + apiVersion: + description: 'API version of the referent.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: + https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + This is optional field, it gets defaulted to the + object holding it if left out.' + type: string + uri: + description: 'URI can be an absolute URL(non-empty scheme and + non-empty host) pointing to the target or a relative URI. + Relative URIs will be resolved using the base URI retrieved + from Ref.' + type: string + timezone: + description: 'Timezone modifies the actual time relative to the specified + timezone. Defaults to the system time zone. More general information + about time zones: https://www.iana.org/time-zones List of valid + timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' + type: string + status: + type: object + description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' + properties: + annotations: + description: 'Annotations is additional Status fields for the Resource + to save some additional State as well as convey more information + to the user. This is roughly akin to Annotations on any k8s resource, + just the reconciler conveying richer information outwards.' + type: object + x-kubernetes-preserve-unknown-fields: true + ceAttributes: + description: 'CloudEventAttributes are the specific attributes that + the Source uses as part of its CloudEvents.' + type: array + items: + type: object + properties: + source: + description: 'Source is the CloudEvents source attribute.' + type: string + type: + description: 'Type refers to the CloudEvent type attribute.' + type: string + conditions: + description: 'Conditions the latest available observations of a resource''s + current state.' + type: array + items: + type: object + required: + - type + - status + properties: + lastTransitionTime: + description: 'LastTransitionTime is the last time the condition + transitioned from one status to another. We use VolatileTime + in place of metav1.Time to exclude this from creating + equality.Semantic differences (all other things held + constant).' + type: string + message: + description: 'A human readable message indicating details + about the transition.' + type: string + reason: + description: 'The reason for the condition''s last transition.' + type: string + severity: + description: 'Severity with which to treat failures of + this type of condition. When this is not specified, + it defaults to Error.' + type: string + status: + description: 'Status of the condition, one of True, False, + Unknown.' + type: string + type: + description: 'Type of condition.' + type: string + observedGeneration: + description: 'ObservedGeneration is the "Generation" of the Service + that was last processed by the controller.' + type: integer + format: int64 + sinkUri: + description: 'SinkURI is the current active sink URI that has been + configured for the Source.' + type: string + additionalPrinterColumns: + - name: Ready + type: string + jsonPath: ".status.conditions[?(@.type=='Ready')].status" + - name: Reason + type: string + jsonPath: ".status.conditions[?(@.type=='Ready')].reason" + - name: Sink + type: string + jsonPath: .status.sinkUri + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + - << : *version + name: v1alpha2 + served: false + storage: false + names: + categories: + - all + - knative + - eventing + - sources + kind: PingSource + plural: pingsources + scope: Namespaced + conversion: + strategy: Webhook + webhook: + conversionReviewVersions: ["v1", "v1beta1"] + clientConfig: + service: + name: eventing-webhook + namespace: knative-eventing diff --git a/config/pre-install/v0.18.0/storage-version-migration.yaml b/config/pre-install/v0.18.0/storage-version-migration.yaml index 4933465ca78..fa34ee23e35 100644 --- a/config/pre-install/v0.18.0/storage-version-migration.yaml +++ b/config/pre-install/v0.18.0/storage-version-migration.yaml @@ -1,4 +1,4 @@ -# Copyright 2020 The Knative Authors +.# Copyright 2020 The Knative Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -47,3 +47,4 @@ spec: - "subscriptions.messaging.knative.dev" - "parallels.flows.knative.dev" - "sequences.flows.knative.dev" + - "pingsources.sources.knative.dev" diff --git a/pkg/adapter/mtping/config.go b/pkg/adapter/mtping/config.go index 2c14aa4a5ae..d24f9fc38ef 100644 --- a/pkg/adapter/mtping/config.go +++ b/pkg/adapter/mtping/config.go @@ -20,7 +20,7 @@ import ( corev1 "k8s.io/api/core/v1" "knative.dev/eventing/pkg/apis/eventing" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" ) type PingConfig struct { @@ -50,7 +50,7 @@ type PingConfigs map[string]PingConfig // Project creates a PingConfig for the given source func Project(i interface{}) interface{} { - obj := i.(*v1alpha2.PingSource) + obj := i.(*v1beta1.PingSource) if scope, ok := obj.Annotations[eventing.ScopeAnnotationKey]; ok && scope != eventing.ScopeCluster { return nil diff --git a/pkg/adapter/mtping/config_test.go b/pkg/adapter/mtping/config_test.go index 61d57dff932..a176697d7c8 100644 --- a/pkg/adapter/mtping/config_test.go +++ b/pkg/adapter/mtping/config_test.go @@ -26,28 +26,28 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" duckv1 "knative.dev/pkg/apis/duck/v1" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func TestProject(t *testing.T) { testCases := map[string]struct { - source sourcesv1alpha2.PingSource + source sourcesv1beta1.PingSource expected PingConfig }{ "TestAddRunRemoveSchedule": { - source: sourcesv1alpha2.PingSource{ + source: sourcesv1beta1.PingSource{ ObjectMeta: metav1.ObjectMeta{ Name: "test-name", Namespace: "test-ns"}, - Spec: sourcesv1alpha2.PingSourceSpec{ + Spec: sourcesv1beta1.PingSourceSpec{ SourceSpec: duckv1.SourceSpec{ CloudEventOverrides: nil, }, Schedule: "* * * * ?", JsonData: "some data", }, - Status: sourcesv1alpha2.PingSourceStatus{ + Status: sourcesv1beta1.PingSourceStatus{ SourceStatus: duckv1.SourceStatus{ SinkURI: &apis.URL{ Host: "asink", @@ -65,11 +65,11 @@ func TestProject(t *testing.T) { SinkURI: "//asink", }}, "TestAddRunRemoveScheduleWithExtensionOverride": { - source: sourcesv1alpha2.PingSource{ + source: sourcesv1beta1.PingSource{ ObjectMeta: metav1.ObjectMeta{ Name: "test-name", Namespace: "test-ns"}, - Spec: sourcesv1alpha2.PingSourceSpec{ + Spec: sourcesv1beta1.PingSourceSpec{ SourceSpec: duckv1.SourceSpec{ Sink: duckv1.Destination{}, CloudEventOverrides: &duckv1.CloudEventOverrides{ @@ -79,7 +79,7 @@ func TestProject(t *testing.T) { Schedule: "* * * * ?", JsonData: "some data", }, - Status: sourcesv1alpha2.PingSourceStatus{ + Status: sourcesv1beta1.PingSourceStatus{ SourceStatus: duckv1.SourceStatus{ SinkURI: &apis.URL{Host: "anothersink"}, }, diff --git a/pkg/adapter/mtping/runner.go b/pkg/adapter/mtping/runner.go index 5439deceb3a..41743ff525a 100644 --- a/pkg/adapter/mtping/runner.go +++ b/pkg/adapter/mtping/runner.go @@ -35,7 +35,7 @@ import ( kncloudevents "knative.dev/eventing/pkg/adapter/v2" "knative.dev/eventing/pkg/adapter/v2/util/crstatusevent" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" "knative.dev/eventing/pkg/utils/cache" ) @@ -77,8 +77,8 @@ func NewCronJobsRunner(ceClient cloudevents.Client, kubeClient kubernetes.Interf func (a *cronJobsRunner) AddSchedule(cfg PingConfig) cron.EntryID { event := cloudevents.NewEvent() - event.SetType(sourcesv1alpha2.PingSourceEventType) - event.SetSource(sourcesv1alpha2.PingSourceSource(cfg.Namespace, cfg.Name)) + event.SetType(sourcesv1beta1.PingSourceEventType) + event.SetSource(sourcesv1beta1.PingSourceSource(cfg.Namespace, cfg.Name)) event.SetData(cloudevents.ApplicationJSON, message(cfg.JsonData)) if cfg.Extensions != nil { for key, override := range cfg.Extensions { @@ -179,7 +179,7 @@ func (a *cronJobsRunner) updateFromConfigMap(cm *corev1.ConfigMap) { } for key, cfg := range cfgs { - cfg.APIVersion = sourcesv1alpha2.SchemeGroupVersion.String() + cfg.APIVersion = sourcesv1beta1.SchemeGroupVersion.String() cfg.Kind = "PingSource" // Is the schedule already cached? diff --git a/pkg/reconciler/mtbroker/broker_test.go b/pkg/reconciler/mtbroker/broker_test.go index 9d6a6b190a8..75e320953ad 100644 --- a/pkg/reconciler/mtbroker/broker_test.go +++ b/pkg/reconciler/mtbroker/broker_test.go @@ -33,7 +33,7 @@ import ( "knative.dev/eventing/pkg/apis/eventing" eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" "knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable" "knative.dev/eventing/pkg/client/injection/reconciler/eventing/v1/broker" @@ -85,7 +85,7 @@ const ( testSchedule = "*/2 * * * *" testData = "data" sinkName = "testsink" - dependencyAnnotation = "{\"kind\":\"PingSource\",\"name\":\"test-ping-source\",\"apiVersion\":\"sources.knative.dev/v1alpha2\"}" + dependencyAnnotation = "{\"kind\":\"PingSource\",\"name\":\"test-ping-source\",\"apiVersion\":\"sources.knative.dev/v1beta1\"}" subscriberURIReference = "foo" subscriberResolvedTargetURI = "http://example.com/subscriber/foo" @@ -724,39 +724,37 @@ func makeFalseStatusSubscription() *messagingv1.Subscription { return s } -func makeFalseStatusPingSource() *sourcesv1alpha2.PingSource { - return rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS, rtv1alpha1.WithPingSourceV1A2SinkNotFound) +func makeFalseStatusPingSource() *sourcesv1beta1.PingSource { + return rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS, rtv1alpha1.WithPingSourceV1B1SinkNotFound) } -func makeUnknownStatusCronJobSource() *sourcesv1alpha2.PingSource { - cjs := rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS) +func makeUnknownStatusCronJobSource() *sourcesv1beta1.PingSource { + cjs := rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS) cjs.Status.InitializeConditions() return cjs } -func makeGenerationNotEqualPingSource() *sourcesv1alpha2.PingSource { +func makeGenerationNotEqualPingSource() *sourcesv1beta1.PingSource { c := makeFalseStatusPingSource() c.Generation = currentGeneration c.Status.ObservedGeneration = outdatedGeneration return c } -func makeReadyPingSource() *sourcesv1alpha2.PingSource { - u := apis.HTTP(sinkURI) - return rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS, - rtv1alpha1.WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ +func makeReadyPingSource() *sourcesv1beta1.PingSource { + u, _ := apis.ParseURL(sinkURI) + return rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS, + rtv1alpha1.WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: brokerDestv1, }, }), - rtv1alpha1.WithInitPingSourceV1A2Conditions, - rtv1alpha1.WithValidPingSourceV1A2Schedule, - rtv1alpha1.WithValidPingSourceV1A2Resources, - rtv1alpha1.WithPingSourceV1A2Deployed, - rtv1alpha1.WithPingSourceV1A2CloudEventAttributes, - rtv1alpha1.WithPingSourceV1A2Sink(u), + rtv1alpha1.WithInitPingSourceV1B1Conditions, + rtv1alpha1.WithPingSourceV1B1Deployed, + rtv1alpha1.WithPingSourceV1B1CloudEventAttributes, + rtv1alpha1.WithPingSourceV1B1Sink(u), ) } func makeSubscriberKubernetesServiceAsUnstructured() *unstructured.Unstructured { diff --git a/pkg/reconciler/mtbroker/trigger/trigger_test.go b/pkg/reconciler/mtbroker/trigger/trigger_test.go index b319ba51fd2..19e2adabdf8 100644 --- a/pkg/reconciler/mtbroker/trigger/trigger_test.go +++ b/pkg/reconciler/mtbroker/trigger/trigger_test.go @@ -33,7 +33,7 @@ import ( "knative.dev/eventing/pkg/apis/eventing" eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" "knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable" "knative.dev/eventing/pkg/client/injection/reconciler/eventing/v1/trigger" @@ -946,39 +946,37 @@ func makeFalseStatusSubscription() *messagingv1.Subscription { return s } -func makeFalseStatusPingSource() *sourcesv1alpha2.PingSource { - return rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS, rtv1alpha1.WithPingSourceV1A2SinkNotFound) +func makeFalseStatusPingSource() *sourcesv1beta1.PingSource { + return rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS, rtv1alpha1.WithPingSourceV1B1SinkNotFound) } -func makeUnknownStatusCronJobSource() *sourcesv1alpha2.PingSource { - cjs := rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS) +func makeUnknownStatusCronJobSource() *sourcesv1beta1.PingSource { + cjs := rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS) cjs.Status.InitializeConditions() return cjs } -func makeGenerationNotEqualPingSource() *sourcesv1alpha2.PingSource { +func makeGenerationNotEqualPingSource() *sourcesv1beta1.PingSource { c := makeFalseStatusPingSource() c.Generation = currentGeneration c.Status.ObservedGeneration = outdatedGeneration return c } -func makeReadyPingSource() *sourcesv1alpha2.PingSource { +func makeReadyPingSource() *sourcesv1beta1.PingSource { u, _ := apis.ParseURL(sinkURI) - return rtv1alpha1.NewPingSourceV1Alpha2(pingSourceName, testNS, - rtv1alpha1.WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + return rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS, + rtv1alpha1.WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: brokerDestv1, }, }), - rtv1alpha1.WithInitPingSourceV1A2Conditions, - rtv1alpha1.WithValidPingSourceV1A2Schedule, - rtv1alpha1.WithValidPingSourceV1A2Resources, - rtv1alpha1.WithPingSourceV1A2Deployed, - rtv1alpha1.WithPingSourceV1A2CloudEventAttributes, - rtv1alpha1.WithPingSourceV1A2Sink(u), + rtv1alpha1.WithInitPingSourceV1B1Conditions, + rtv1alpha1.WithPingSourceV1B1Deployed, + rtv1alpha1.WithPingSourceV1B1CloudEventAttributes, + rtv1alpha1.WithPingSourceV1B1Sink(u), ) } func makeSubscriberKubernetesServiceAsUnstructured() *unstructured.Unstructured { diff --git a/pkg/reconciler/pingsource/controller.go b/pkg/reconciler/pingsource/controller.go index 1cfe2da6576..3aebd8dad01 100644 --- a/pkg/reconciler/pingsource/controller.go +++ b/pkg/reconciler/pingsource/controller.go @@ -37,6 +37,8 @@ import ( "knative.dev/eventing/pkg/adapter/v2" pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource" pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" + pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/pingsource" + pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" reconcilersource "knative.dev/eventing/pkg/reconciler/source" ) diff --git a/pkg/reconciler/pingsource/controller_test.go b/pkg/reconciler/pingsource/controller_test.go index 68691a713a8..6b30971477a 100644 --- a/pkg/reconciler/pingsource/controller_test.go +++ b/pkg/reconciler/pingsource/controller_test.go @@ -27,7 +27,7 @@ import ( // Fake injection informers _ "knative.dev/eventing/pkg/client/injection/informers/eventing/v1beta1/eventtype/fake" - _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/pingsource/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/core/v1/serviceaccount/fake" diff --git a/pkg/reconciler/pingsource/pingsource.go b/pkg/reconciler/pingsource/pingsource.go index 277e0ab1475..a60b871491a 100644 --- a/pkg/reconciler/pingsource/pingsource.go +++ b/pkg/reconciler/pingsource/pingsource.go @@ -39,9 +39,9 @@ import ( "knative.dev/pkg/tracker" "knative.dev/eventing/pkg/adapter/mtping" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" - pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" - listers "knative.dev/eventing/pkg/client/listers/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" + pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" + listers "knative.dev/eventing/pkg/client/listers/sources/v1beta1" "knative.dev/eventing/pkg/reconciler/pingsource/resources" reconcilersource "knative.dev/eventing/pkg/reconciler/source" ) @@ -84,7 +84,7 @@ type Reconciler struct { // Check that our Reconciler implements ReconcileKind var _ pingsourcereconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSource) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1beta1.PingSource) pkgreconciler.Event { // This Source attempts to reconcile three things. // 1. Determine the sink's URI. // - Nothing to delete. @@ -111,10 +111,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSou } source.Status.MarkSink(sinkURI) - // The webhook does not allow for invalid schedules to be posted. - // TODO: remove MarkSchedule - source.Status.MarkSchedule() - // Make sure the global mt receive adapter is running d, err := r.reconcileReceiveAdapter(ctx, source) if err != nil { @@ -137,14 +133,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSou } source.Status.CloudEventAttributes = []duckv1.CloudEventAttributes{{ - Type: v1alpha2.PingSourceEventType, - Source: v1alpha2.PingSourceSource(source.Namespace, source.Name), + Type: v1beta1.PingSourceEventType, + Source: v1beta1.PingSourceSource(source.Namespace, source.Name), }} return nil } -func (r *Reconciler) reconcileReceiveAdapter(ctx context.Context, source *v1alpha2.PingSource) (*appsv1.Deployment, error) { +func (r *Reconciler) reconcileReceiveAdapter(ctx context.Context, source *v1beta1.PingSource) (*appsv1.Deployment, error) { loggingConfig, err := logging.LoggingConfigToJson(r.configs.LoggingConfig()) if err != nil { logging.FromContext(ctx).Errorw("error while converting logging config to JSON", zap.Any("receiveAdapter", err)) diff --git a/pkg/reconciler/pingsource/pingsource_test.go b/pkg/reconciler/pingsource/pingsource_test.go index 83439ca8256..526baf0c857 100644 --- a/pkg/reconciler/pingsource/pingsource_test.go +++ b/pkg/reconciler/pingsource/pingsource_test.go @@ -28,9 +28,9 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" clientgotesting "k8s.io/client-go/testing" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" - "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" + "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" "knative.dev/eventing/pkg/reconciler/pingsource/resources" "knative.dev/eventing/pkg/utils" "knative.dev/pkg/apis" @@ -102,34 +102,34 @@ func TestAllCases(t *testing.T) { }, { Name: "missing sink", Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), }, Key: testNS + "/" + sourceName, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithInitPingSourceV1A2Conditions, - WithPingSourceV1A2StatusObservedGeneration(generation), - WithPingSourceV1A2SinkNotFound, + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1StatusObservedGeneration(generation), + WithPingSourceV1B1SinkNotFound, ), }}, WantEvents: []string{ @@ -139,16 +139,16 @@ func TestAllCases(t *testing.T) { }, { Name: "valid", Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -158,40 +158,38 @@ func TestAllCases(t *testing.T) { }, Key: testNS + "/" + sourceName, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2StatusObservedGeneration(generation), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, }, { Name: "valid with cluster scope annotation, create deployment", SkipNamespaceValidation: true, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), ), rtv1beta1.NewChannel(sinkName, testNS, rtv1beta1.WithInitChannelConditions, @@ -206,23 +204,22 @@ func TestAllCases(t *testing.T) { MakeMTAdapter(), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewPingSourceV1Alpha2(sourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + Object: NewPingSourceV1Beta1(sourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ Sink: sinkDest, }, }), - WithPingSourceV1A2UID(sourceUID), - WithPingSourceV1A2ObjectMetaGeneration(generation), + WithPingSourceV1B1UID(sourceUID), + WithPingSourceV1B1ObjectMetaGeneration(generation), // Status Update: - WithPingSourceV1A2NotDeployed(mtadapterName), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2StatusObservedGeneration(generation), + WithPingSourceV1B1NotDeployed(mtadapterName), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1StatusObservedGeneration(generation), ), }}, }, @@ -233,7 +230,7 @@ func TestAllCases(t *testing.T) { ctx = addressable.WithDuck(ctx) r := &Reconciler{ kubeClientSet: fakekubeclient.Get(ctx), - pingLister: listers.GetPingSourceV1alpha2Lister(), + pingLister: listers.GetPingSourceV1beta1Lister(), deploymentLister: listers.GetDeploymentLister(), tracker: tracker.New(func(types.NamespacedName) {}, 0), receiveAdapterImage: mtimage, @@ -241,7 +238,7 @@ func TestAllCases(t *testing.T) { r.sinkResolver = resolver.NewURIResolver(ctx, func(types.NamespacedName) {}) return pingsource.NewReconciler(ctx, logging.FromContext(ctx), - fakeeventingclient.Get(ctx), listers.GetPingSourceV1alpha2Lister(), + fakeeventingclient.Get(ctx), listers.GetPingSourceV1beta1Lister(), controller.GetEventRecorder(ctx), r) }, true, @@ -264,3 +261,4 @@ func makeAvailableMTAdapter() *appsv1.Deployment { WithDeploymentAvailable()(ma) return ma } + diff --git a/pkg/reconciler/pingsource/resources/receive_adapter_test.go b/pkg/reconciler/pingsource/resources/receive_adapter_test.go index 8195953a87e..ee054a1b578 100644 --- a/pkg/reconciler/pingsource/resources/receive_adapter_test.go +++ b/pkg/reconciler/pingsource/resources/receive_adapter_test.go @@ -24,12 +24,24 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/system" - _ "knative.dev/pkg/system/testing" + "knative.dev/pkg/apis" + "knative.dev/pkg/kmp" + + "knative.dev/eventing/pkg/apis/sources/v1beta1" ) -func TestMakePingAdapter(t *testing.T) { - replicas := int32(1) +func TestMakeReceiveAdapter(t *testing.T) { + src := &v1beta1.PingSource{ + ObjectMeta: metav1.ObjectMeta{ + Name: "source-name", + Namespace: "source-namespace", + UID: "source-uid", + }, + Spec: v1beta1.PingSourceSpec{ + Schedule: "*/2 * * * *", + JsonData: "data", + }, + } args := Args{ ServiceAccountName: "test-sa", @@ -46,8 +58,20 @@ func TestMakePingAdapter(t *testing.T) { Kind: "Deployments", }, ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace(), - Name: args.AdapterName, + Namespace: "source-namespace", + Name: fmt.Sprintf("pingsource-%s-%s", src.Name, src.UID), + Labels: map[string]string{ + "test-key1": "test-value1", + "test-key2": "test-value2", + }, + OwnerReferences: []metav1.OwnerReference{{ + APIVersion: "sources.knative.dev/v1beta1", + Kind: "PingSource", + Name: src.Name, + UID: src.UID, + Controller: &yes, + BlockOwnerDeletion: &yes, + }}, }, Spec: v1.DeploymentSpec{ Replicas: &replicas, diff --git a/pkg/reconciler/resources/service_account_test.go b/pkg/reconciler/resources/service_account_test.go index a9c13ef3d12..dea87165f91 100644 --- a/pkg/reconciler/resources/service_account_test.go +++ b/pkg/reconciler/resources/service_account_test.go @@ -24,13 +24,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/kmeta" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func TestNewServiceAccount(t *testing.T) { testNS := "test-ns" testName := "test-name" - obj := &v1alpha2.PingSource{ + obj := &v1beta1.PingSource{ ObjectMeta: metav1.ObjectMeta{ Name: testName, Namespace: testNS, diff --git a/pkg/reconciler/testing/listers.go b/pkg/reconciler/testing/listers.go index 22822b57342..ca24f2dc589 100644 --- a/pkg/reconciler/testing/listers.go +++ b/pkg/reconciler/testing/listers.go @@ -164,8 +164,8 @@ func (l *Listers) GetSinkBindingLister() sourcelisters.SinkBindingLister { return sourcelisters.NewSinkBindingLister(l.indexerFor(&sourcesv1alpha1.SinkBinding{})) } -func (l *Listers) GetPingSourceV1alpha2Lister() sourcev1alpha2listers.PingSourceLister { - return sourcev1alpha2listers.NewPingSourceLister(l.indexerFor(&sourcesv1alpha2.PingSource{})) +func (l *Listers) GetPingSourceV1beta1Lister() sourcev1beta1listers.PingSourceLister { + return sourcev1beta1listers.NewPingSourceLister(l.indexerFor(&sourcesv1beta1.PingSource{})) } func (l *Listers) GetContainerSourceV1alpha2Lister() sourcev1alpha2listers.ContainerSourceLister { diff --git a/pkg/reconciler/testing/pingsource.go b/pkg/reconciler/testing/pingsource.go index 5e235370d59..896ff883b34 100644 --- a/pkg/reconciler/testing/pingsource.go +++ b/pkg/reconciler/testing/pingsource.go @@ -116,12 +116,6 @@ func WithPingSourceV1A2Spec(spec v1alpha2.PingSourceSpec) PingSourceV1A2Option { } } -func WithPingSourceV1B1Spec(spec v1beta1.PingSourceSpec) PingSourceV1B1Option { - return func(c *v1beta1.PingSource) { - c.Spec = spec - } -} - func WithPingSourceV1A2StatusObservedGeneration(generation int64) PingSourceV1A2Option { return func(c *v1alpha2.PingSource) { c.Status.ObservedGeneration = generation @@ -144,3 +138,83 @@ func WithPingSourceV1A2Deleted(c *v1alpha2.PingSource) { t := metav1.NewTime(time.Unix(1e9, 0)) c.SetDeletionTimestamp(&t) } + +func WithPingSourceV1B1UID(uid string) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.UID = types.UID(uid) + } +} + +func WithPingSourceV1B1ResourceScopeAnnotation(c *v1beta1.PingSource) { + if c.Annotations == nil { + c.Annotations = make(map[string]string) + } + c.Annotations[eventing.ScopeAnnotationKey] = eventing.ScopeResource +} + +func WithPingSourceV1B1ClusterScopeAnnotation(c *v1beta1.PingSource) { + if c.Annotations == nil { + c.Annotations = make(map[string]string) + } + c.Annotations[eventing.ScopeAnnotationKey] = eventing.ScopeCluster +} + +func WithInitPingSourceV1B1Conditions(s *v1beta1.PingSource) { + s.Status.InitializeConditions() +} + +func WithPingSourceV1B1SinkNotFound(s *v1beta1.PingSource) { + s.Status.MarkNoSink("NotFound", "") +} + +func WithPingSourceV1B1Sink(uri *apis.URL) PingSourceV1B1Option { + return func(s *v1beta1.PingSource) { + s.Status.MarkSink(uri) + } +} + +func WithPingSourceV1B1NotDeployed(name string) PingSourceV1B1Option { + return func(s *v1beta1.PingSource) { + s.Status.PropagateDeploymentAvailability(NewDeployment(name, "any")) + } +} + +func WithPingSourceV1B1Deployed(s *v1beta1.PingSource) { + s.Status.PropagateDeploymentAvailability(NewDeployment("any", "any", WithDeploymentAvailable())) +} + +func WithPingSourceV1B1CloudEventAttributes(s *v1beta1.PingSource) { + s.Status.CloudEventAttributes = []duckv1.CloudEventAttributes{{ + Type: v1beta1.PingSourceEventType, + Source: v1beta1.PingSourceSource(s.Namespace, s.Name), + }} +} + +func WithPingSourceV1B1Spec(spec v1beta1.PingSourceSpec) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.Spec = spec + } +} + +func WithPingSourceV1B1StatusObservedGeneration(generation int64) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.Status.ObservedGeneration = generation + } +} + +func WithPingSourceV1B1ObjectMetaGeneration(generation int64) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.ObjectMeta.Generation = generation + } +} + +func WithPingSourceV1B1Finalizers(finalizers ...string) PingSourceV1B1Option { + return func(c *v1beta1.PingSource) { + c.Finalizers = finalizers + } +} + +func WithPingSourceV1B1Deleted(c *v1beta1.PingSource) { + t := metav1.NewTime(time.Unix(1e9, 0)) + c.SetDeletionTimestamp(&t) +} diff --git a/pkg/reconciler/testing/v1beta1/listers.go b/pkg/reconciler/testing/v1beta1/listers.go index 9c046b0df24..da0b0cea48d 100644 --- a/pkg/reconciler/testing/v1beta1/listers.go +++ b/pkg/reconciler/testing/v1beta1/listers.go @@ -162,8 +162,8 @@ func (l *Listers) GetSinkBindingLister() sourcelisters.SinkBindingLister { return sourcelisters.NewSinkBindingLister(l.indexerFor(&sourcesv1alpha1.SinkBinding{})) } -func (l *Listers) GetPingSourceV1alpha2Lister() sourcev1alpha2listers.PingSourceLister { - return sourcev1alpha2listers.NewPingSourceLister(l.indexerFor(&sourcesv1alpha2.PingSource{})) +func (l *Listers) GetPingSourceV1beta1Lister() sourcev1beta1listers.PingSourceLister { + return sourcev1beta1listers.NewPingSourceLister(l.indexerFor(&sourcesv1beta1.PingSource{})) } func (l *Listers) GetContainerSourceLister() sourcev1alpha2listers.ContainerSourceLister { diff --git a/test/conformance/main_test.go b/test/conformance/main_test.go index ffe913d02bc..b1880801ab9 100644 --- a/test/conformance/main_test.go +++ b/test/conformance/main_test.go @@ -86,7 +86,7 @@ func addSourcesInitializers() { ) sourcesTestRunner.AddComponentSetupClientOption( testlib.PingSourceTypeMeta, - setupclientoptions.PingSourceV1A2ClientSetupOption(pingSrcName, + setupclientoptions.PingSourceV1B1ClientSetupOption(pingSrcName, recordEventsPingPodName), ) } diff --git a/test/e2e/trigger_dependency_annotation_test.go b/test/e2e/trigger_dependency_annotation_test.go index efc65faa1f2..7fa76d7ae5c 100644 --- a/test/e2e/trigger_dependency_annotation_test.go +++ b/test/e2e/trigger_dependency_annotation_test.go @@ -30,7 +30,7 @@ import ( "knative.dev/pkg/apis" "knative.dev/eventing/pkg/apis/eventing" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" sugarresources "knative.dev/eventing/pkg/reconciler/sugar/resources" eventingtesting "knative.dev/eventing/pkg/reconciler/testing" testlib "knative.dev/eventing/test/lib" @@ -47,7 +47,7 @@ func TestTriggerDependencyAnnotation(t *testing.T) { defaultBrokerName = sugarresources.DefaultBrokerName triggerName = "trigger-annotation" subscriberName = "subscriber-annotation" - dependencyAnnotation = `{"kind":"PingSource","name":"test-ping-source-annotation","apiVersion":"sources.knative.dev/v1alpha2"}` + dependencyAnnotation = `{"kind":"PingSource","name":"test-ping-source-annotation","apiVersion":"sources.knative.dev/v1beta1"}` pingSourceName = "test-ping-source-annotation" // Every 1 minute starting from now schedule = "*/1 * * * *" @@ -74,10 +74,10 @@ func TestTriggerDependencyAnnotation(t *testing.T) { ) jsonData := fmt.Sprintf(`{"msg":"Test trigger-annotation %s"}`, uuid.NewUUID()) - pingSource := eventingtesting.NewPingSourceV1Alpha2( + pingSource := eventingtesting.NewPingSourceV1Beta1( pingSourceName, client.Namespace, - eventingtesting.WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + eventingtesting.WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: schedule, JsonData: jsonData, SourceSpec: duckv1.SourceSpec{ @@ -93,13 +93,13 @@ func TestTriggerDependencyAnnotation(t *testing.T) { } } - client.CreatePingSourceV1Alpha2OrFail(pingSource) + client.CreatePingSourceV1Beta1OrFail(pingSource) // Trigger should become ready after pingSource was created client.WaitForResourceReadyOrFail(triggerName, testlib.TriggerTypeMeta) eventTracker.AssertAtLeast(1, recordevents.MatchEvent( - HasSource(sourcesv1alpha2.PingSourceSource(client.Namespace, pingSourceName)), + HasSource(sourcesv1beta1.PingSourceSource(client.Namespace, pingSourceName)), HasData([]byte(jsonData)), )) } diff --git a/test/lib/setupclientoptions/sources.go b/test/lib/setupclientoptions/sources.go index f5ab1246a12..3f271af1a1e 100644 --- a/test/lib/setupclientoptions/sources.go +++ b/test/lib/setupclientoptions/sources.go @@ -22,7 +22,6 @@ import ( rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/util/uuid" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" eventingtesting "knative.dev/eventing/pkg/reconciler/testing" testlib "knative.dev/eventing/test/lib" @@ -68,10 +67,10 @@ func ApiServerSourceV1B1ClientSetupOption(name string, mode string, recordEvents } } -// PingSourceV1A2ClientSetupOption returns a ClientSetupOption that can be used +// PingSourceV1B1ClientSetupOption returns a ClientSetupOption that can be used // to create a new PingSource. It creates a RecordEvents pod and a // PingSource object with the RecordEvent pod as its sink. -func PingSourceV1A2ClientSetupOption(name string, recordEventsPodName string) testlib.SetupClientOption { +func PingSourceV1B1ClientSetupOption(name string, recordEventsPodName string) testlib.SetupClientOption { return func(client *testlib.Client) { // create event logger pod and service @@ -79,10 +78,10 @@ func PingSourceV1A2ClientSetupOption(name string, recordEventsPodName string) te // create cron job source data := fmt.Sprintf(`{"msg":"TestPingSource %s"}`, uuid.NewUUID()) - source := eventingtesting.NewPingSourceV1Alpha2( + source := eventingtesting.NewPingSourceV1Beta1( name, client.Namespace, - eventingtesting.WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + eventingtesting.WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ JsonData: data, SourceSpec: duckv1.SourceSpec{ Sink: duckv1.Destination{ @@ -91,7 +90,7 @@ func PingSourceV1A2ClientSetupOption(name string, recordEventsPodName string) te }, }), ) - client.CreatePingSourceV1Alpha2OrFail(source) + client.CreatePingSourceV1Beta1OrFail(source) // wait for all test resources to be ready client.WaitForAllTestResourcesReadyOrFail() From 9080da079deadf3be91265747a868c7c84692aeb Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Thu, 27 Aug 2020 17:34:33 -0400 Subject: [PATCH 11/20] Removing trailing whitespace Signed-off-by: Ansu Varghese --- config/pre-install/v0.18.0/pingsource.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/pre-install/v0.18.0/pingsource.yaml b/config/pre-install/v0.18.0/pingsource.yaml index 5222eb55c1d..ac462088d97 100644 --- a/config/pre-install/v0.18.0/pingsource.yaml +++ b/config/pre-install/v0.18.0/pingsource.yaml @@ -43,7 +43,7 @@ spec: properties: spec: type: object - description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' properties: ceOverrides: description: 'CloudEventOverrides defines overrides to control the @@ -56,7 +56,7 @@ spec: pair are set on the event as an attribute extension independently.' type: object additionalProperties: - type: string + type: string x-kubernetes-preserve-unknown-fields: true jsonData: description: 'JsonData is json encoded data used as the body of the @@ -102,7 +102,7 @@ spec: timezone. Defaults to the system time zone. More general information about time zones: https://www.iana.org/time-zones List of valid timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' - type: string + type: string status: type: object description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' @@ -171,7 +171,7 @@ spec: sinkUri: description: 'SinkURI is the current active sink URI that has been configured for the Source.' - type: string + type: string additionalPrinterColumns: - name: Ready type: string From ce82f26db0111aa15c44dfaf78c3f45265d5b0b5 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 11:25:23 -0400 Subject: [PATCH 12/20] Changes from review Signed-off-by: Ansu Varghese --- config/core/resources/pingsource.yaml | 2 +- config/pre-install/v0.18.0/pingsource.yaml | 173 ++++++++++++++++++--- 2 files changed, 152 insertions(+), 23 deletions(-) diff --git a/config/core/resources/pingsource.yaml b/config/core/resources/pingsource.yaml index fd13efd7b03..d50327d78de 100644 --- a/config/core/resources/pingsource.yaml +++ b/config/core/resources/pingsource.yaml @@ -32,7 +32,7 @@ spec: versions: - &version name: v1alpha2 - served: false + served: true storage: false subresources: status: {} diff --git a/config/pre-install/v0.18.0/pingsource.yaml b/config/pre-install/v0.18.0/pingsource.yaml index ac462088d97..d50327d78de 100644 --- a/config/pre-install/v0.18.0/pingsource.yaml +++ b/config/pre-install/v0.18.0/pingsource.yaml @@ -31,9 +31,9 @@ spec: group: sources.knative.dev versions: - &version - name: v1beta1 + name: v1alpha2 served: true - storage: true + storage: false subresources: status: {} schema: @@ -41,9 +41,9 @@ spec: type: object description: 'PingSource describes an event source with a fixed payload produced on a specified cron schedule.' properties: - spec: + spec: type: object - description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' properties: ceOverrides: description: 'CloudEventOverrides defines overrides to control the @@ -97,12 +97,6 @@ spec: Relative URIs will be resolved using the base URI retrieved from Ref.' type: string - timezone: - description: 'Timezone modifies the actual time relative to the specified - timezone. Defaults to the system time zone. More general information - about time zones: https://www.iana.org/time-zones List of valid - timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' - type: string status: type: object description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' @@ -171,29 +165,164 @@ spec: sinkUri: description: 'SinkURI is the current active sink URI that has been configured for the Source.' - type: string + type: string additionalPrinterColumns: - - name: Ready - type: string - jsonPath: ".status.conditions[?(@.type=='Ready')].status" - - name: Reason - type: string - jsonPath: ".status.conditions[?(@.type=='Ready')].reason" - name: Sink type: string jsonPath: .status.sinkUri - name: Age type: date jsonPath: .metadata.creationTimestamp - - << : *version - name: v1alpha2 - served: false - storage: false + - name: Ready + type: string + jsonPath: ".status.conditions[?(@.type=='Ready')].status" + - name: Reason + type: string + jsonPath: ".status.conditions[?(@.type=='Ready')].reason" + - <<: *version + name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + description: 'PingSource describes an event source with a fixed payload produced on a specified cron schedule.' + properties: + spec: + type: object + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + properties: + ceOverrides: + description: 'CloudEventOverrides defines overrides to control the + output format and modifications of the event sent to the sink.' + type: object + properties: + extensions: + description: 'Extensions specify what attribute are added or + overridden on the outbound event. Each `Extensions` key-value + pair are set on the event as an attribute extension independently.' + type: object + additionalProperties: + type: string + x-kubernetes-preserve-unknown-fields: true + jsonData: + description: 'JsonData is json encoded data used as the body of the + event posted to the sink. Default is empty. If set, datacontenttype + will also be set to "application/json".' + type: string + schedule: + description: 'Schedule is the cronjob schedule. Defaults to `* * * + * *`.' + type: string + sink: + description: 'Sink is a reference to an object that will resolve to + a uri to use as the sink.' + type: object + properties: + ref: + description: 'Ref points to an Addressable.' + type: object + properties: + apiVersion: + description: 'API version of the referent.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: + https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + This is optional field, it gets defaulted to the + object holding it if left out.' + type: string + uri: + description: 'URI can be an absolute URL(non-empty scheme and + non-empty host) pointing to the target or a relative URI. + Relative URIs will be resolved using the base URI retrieved + from Ref.' + type: string + timezone: + description: 'Timezone modifies the actual time relative to the specified + timezone. Defaults to the system time zone. More general information + about time zones: https://www.iana.org/time-zones List of valid + timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' + type: string + status: + type: object + description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' + properties: + annotations: + description: 'Annotations is additional Status fields for the Resource + to save some additional State as well as convey more information + to the user. This is roughly akin to Annotations on any k8s resource, + just the reconciler conveying richer information outwards.' + type: object + x-kubernetes-preserve-unknown-fields: true + ceAttributes: + description: 'CloudEventAttributes are the specific attributes that + the Source uses as part of its CloudEvents.' + type: array + items: + type: object + properties: + source: + description: 'Source is the CloudEvents source attribute.' + type: string + type: + description: 'Type refers to the CloudEvent type attribute.' + type: string + conditions: + description: 'Conditions the latest available observations of a resource''s + current state.' + type: array + items: + type: object + required: + - type + - status + properties: + lastTransitionTime: + description: 'LastTransitionTime is the last time the condition + transitioned from one status to another. We use VolatileTime + in place of metav1.Time to exclude this from creating + equality.Semantic differences (all other things held + constant).' + type: string + message: + description: 'A human readable message indicating details + about the transition.' + type: string + reason: + description: 'The reason for the condition''s last transition.' + type: string + severity: + description: 'Severity with which to treat failures of + this type of condition. When this is not specified, + it defaults to Error.' + type: string + status: + description: 'Status of the condition, one of True, False, + Unknown.' + type: string + type: + description: 'Type of condition.' + type: string + observedGeneration: + description: 'ObservedGeneration is the "Generation" of the Service + that was last processed by the controller.' + type: integer + format: int64 + sinkUri: + description: 'SinkURI is the current active sink URI that has been + configured for the Source.' + type: string names: categories: - all - knative - - eventing - sources kind: PingSource plural: pingsources From 3852107a4f015cf5126e950002097e6a97b9a8b6 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 12:13:07 -0400 Subject: [PATCH 13/20] Fixes from test errors Signed-off-by: Ansu Varghese --- config/pre-install/v0.18.0/storage-version-migration.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/pre-install/v0.18.0/storage-version-migration.yaml b/config/pre-install/v0.18.0/storage-version-migration.yaml index fa34ee23e35..24aaa2bed93 100644 --- a/config/pre-install/v0.18.0/storage-version-migration.yaml +++ b/config/pre-install/v0.18.0/storage-version-migration.yaml @@ -1,4 +1,4 @@ -.# Copyright 2020 The Knative Authors +# Copyright 2020 The Knative Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From f25cc3c09fa9810bf190b48f2055f89127ec4a1a Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 12:15:58 -0400 Subject: [PATCH 14/20] Fixes from test errors Signed-off-by: Ansu Varghese --- config/pre-install/v0.18.0/pingsource.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config/pre-install/v0.18.0/pingsource.yaml b/config/pre-install/v0.18.0/pingsource.yaml index d50327d78de..df5f9e6175d 100644 --- a/config/pre-install/v0.18.0/pingsource.yaml +++ b/config/pre-install/v0.18.0/pingsource.yaml @@ -41,9 +41,9 @@ spec: type: object description: 'PingSource describes an event source with a fixed payload produced on a specified cron schedule.' properties: - spec: + spec: type: object - description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' properties: ceOverrides: description: 'CloudEventOverrides defines overrides to control the @@ -165,7 +165,7 @@ spec: sinkUri: description: 'SinkURI is the current active sink URI that has been configured for the Source.' - type: string + type: string additionalPrinterColumns: - name: Sink type: string @@ -190,7 +190,7 @@ spec: properties: spec: type: object - description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' + description: 'PingSourceSpec defines the desired state of the PingSource (from the client).' properties: ceOverrides: description: 'CloudEventOverrides defines overrides to control the @@ -203,7 +203,7 @@ spec: pair are set on the event as an attribute extension independently.' type: object additionalProperties: - type: string + type: string x-kubernetes-preserve-unknown-fields: true jsonData: description: 'JsonData is json encoded data used as the body of the @@ -249,7 +249,7 @@ spec: timezone. Defaults to the system time zone. More general information about time zones: https://www.iana.org/time-zones List of valid timezone values: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' - type: string + type: string status: type: object description: 'PingSourceStatus defines the observed state of PingSource (from the controller).' @@ -318,7 +318,7 @@ spec: sinkUri: description: 'SinkURI is the current active sink URI that has been configured for the Source.' - type: string + type: string names: categories: - all From 4e1c56f8b7de38000a91bb4b49415b0e4e14b814 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 13:34:35 -0400 Subject: [PATCH 15/20] Fixes after test errors Signed-off-by: Ansu Varghese --- pkg/adapter/mtping/controller.go | 4 +- pkg/adapter/mtping/controller_test.go | 2 +- pkg/adapter/mtping/pingsource.go | 12 ++--- pkg/adapter/mtping/pingsource_test.go | 70 +++++++++++++-------------- 4 files changed, 42 insertions(+), 46 deletions(-) diff --git a/pkg/adapter/mtping/controller.go b/pkg/adapter/mtping/controller.go index 4d1aa7f1c3d..699463ab234 100644 --- a/pkg/adapter/mtping/controller.go +++ b/pkg/adapter/mtping/controller.go @@ -22,8 +22,8 @@ import ( "github.com/robfig/cron/v3" eventingclient "knative.dev/eventing/pkg/client/injection/client" - pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource" - pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" + pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/pingsource" + pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" kubeclient "knative.dev/pkg/client/injection/kube/client" "knative.dev/pkg/controller" "knative.dev/pkg/logging" diff --git a/pkg/adapter/mtping/controller_test.go b/pkg/adapter/mtping/controller_test.go index df3010ef3e7..97562cf14a5 100644 --- a/pkg/adapter/mtping/controller_test.go +++ b/pkg/adapter/mtping/controller_test.go @@ -22,7 +22,7 @@ import ( . "knative.dev/pkg/reconciler/testing" // Fake injection informers - _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/pingsource/fake" ) func TestNew(t *testing.T) { diff --git a/pkg/adapter/mtping/pingsource.go b/pkg/adapter/mtping/pingsource.go index d01a2e18a82..270d0b29942 100644 --- a/pkg/adapter/mtping/pingsource.go +++ b/pkg/adapter/mtping/pingsource.go @@ -30,10 +30,10 @@ import ( pkgreconciler "knative.dev/pkg/reconciler" "knative.dev/eventing/pkg/apis/eventing" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" clientset "knative.dev/eventing/pkg/client/clientset/versioned" - pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" - sourceslisters "knative.dev/eventing/pkg/client/listers/sources/v1alpha2" + pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" + sourceslisters "knative.dev/eventing/pkg/client/listers/sources/v1beta1" ) // Reconciler reconciles PingSources @@ -53,7 +53,7 @@ var _ pingsourcereconciler.Interface = (*Reconciler)(nil) // Check that our Reconciler implements FinalizeKind. var _ pingsourcereconciler.Finalizer = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSource) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1beta1.PingSource) pkgreconciler.Event { scope, ok := source.Annotations[eventing.ScopeAnnotationKey] if ok && scope != eventing.ScopeCluster { // Not our responsibility @@ -74,7 +74,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSou return reconcileErr } -func (r *Reconciler) reconcile(ctx context.Context, source *v1alpha2.PingSource) error { +func (r *Reconciler) reconcile(ctx context.Context, source *v1beta1.PingSource) error { logging.FromContext(ctx).Info("synchronizing schedule") key := fmt.Sprintf("%s/%s", source.Namespace, source.Name) @@ -110,7 +110,7 @@ func (r *Reconciler) reconcile(ctx context.Context, source *v1alpha2.PingSource) return nil } -func (r *Reconciler) FinalizeKind(ctx context.Context, source *v1alpha2.PingSource) pkgreconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, source *v1beta1.PingSource) pkgreconciler.Event { key := fmt.Sprintf("%s/%s", source.Namespace, source.Name) r.entryidMu.RLock() diff --git a/pkg/adapter/mtping/pingsource_test.go b/pkg/adapter/mtping/pingsource_test.go index f149ef23550..5c21d04e593 100644 --- a/pkg/adapter/mtping/pingsource_test.go +++ b/pkg/adapter/mtping/pingsource_test.go @@ -28,10 +28,10 @@ import ( testclient "k8s.io/client-go/kubernetes/fake" clientgotesting "k8s.io/client-go/testing" adaptertesting "knative.dev/eventing/pkg/adapter/v2/test" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" eventingclient "knative.dev/eventing/pkg/client/injection/client" fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" - "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource" + "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/pingsource" . "knative.dev/eventing/pkg/reconciler/testing" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" @@ -75,8 +75,8 @@ func TestAllCases(t *testing.T) { Name: "valid schedule", Key: pingsourceKey, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(pingSourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(pingSourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ @@ -84,11 +84,10 @@ func TestAllCases(t *testing.T) { CloudEventOverrides: nil, }, }), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, ), }, WantEvents: []string{ @@ -102,8 +101,8 @@ func TestAllCases(t *testing.T) { Name: "valid schedule, with finalizer", Key: pingsourceKey, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(pingSourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(pingSourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ @@ -111,12 +110,11 @@ func TestAllCases(t *testing.T) { CloudEventOverrides: nil, }, }), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2Finalizers(defaultFinalizerName), + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1Finalizers(defaultFinalizerName), ), }, WantErr: false, @@ -124,8 +122,8 @@ func TestAllCases(t *testing.T) { Name: "valid schedule, deleted with finalizer", Key: pingsourceKey, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(pingSourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(pingSourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ @@ -133,13 +131,12 @@ func TestAllCases(t *testing.T) { CloudEventOverrides: nil, }, }), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2Finalizers(defaultFinalizerName), - WithPingSourceV1A2Deleted, + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1Finalizers(defaultFinalizerName), + WithPingSourceV1B1Deleted, ), }, WantEvents: []string{ @@ -153,8 +150,8 @@ func TestAllCases(t *testing.T) { Name: "valid schedule, deleted without finalizer", Key: pingsourceKey, Objects: []runtime.Object{ - NewPingSourceV1Alpha2(pingSourceName, testNS, - WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{ + NewPingSourceV1Beta1(pingSourceName, testNS, + WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule, JsonData: testData, SourceSpec: duckv1.SourceSpec{ @@ -162,12 +159,11 @@ func TestAllCases(t *testing.T) { CloudEventOverrides: nil, }, }), - WithInitPingSourceV1A2Conditions, - WithValidPingSourceV1A2Schedule, - WithPingSourceV1A2Deployed, - WithPingSourceV1A2Sink(sinkURI), - WithPingSourceV1A2CloudEventAttributes, - WithPingSourceV1A2Deleted, + WithInitPingSourceV1B1Conditions, + WithPingSourceV1B1Deployed, + WithPingSourceV1B1Sink(sinkURI), + WithPingSourceV1B1CloudEventAttributes, + WithPingSourceV1B1Deleted, ), }, WantErr: false, @@ -181,13 +177,13 @@ func TestAllCases(t *testing.T) { r := &Reconciler{ kubeClient: testclient.NewSimpleClientset(), eventingClientSet: eventingclient.Get(ctx), - pingsourceLister: listers.GetPingSourceV1alpha2Lister(), + pingsourceLister: listers.GetPingSourceV1beta1Lister(), cronRunner: NewCronJobsRunner(ce, testclient.NewSimpleClientset(), logger), entryidMu: sync.RWMutex{}, entryids: make(map[string]cron.EntryID), } return pingsource.NewReconciler(ctx, logging.FromContext(ctx), - fakeeventingclient.Get(ctx), listers.GetPingSourceV1alpha2Lister(), + fakeeventingclient.Get(ctx), listers.GetPingSourceV1beta1Lister(), controller.GetEventRecorder(ctx), r) }, false, logger)) @@ -202,7 +198,7 @@ func patchFinalizers(namespace, name string, finalizers string) clientgotesting. ActionImpl: clientgotesting.ActionImpl{ Namespace: namespace, Verb: "patch", - Resource: schema.GroupVersionResource{Group: "sources.knative.dev", Version: "v1alpha2", Resource: "pingsources"}, + Resource: schema.GroupVersionResource{Group: "sources.knative.dev", Version: "v1beta1", Resource: "pingsources"}, Subresource: "", }, Name: name, From e5f98bb04ccfb64c8ed9b7e093e05e1af9d7b8c9 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 14:14:24 -0400 Subject: [PATCH 16/20] Fixes after test errors Signed-off-by: Ansu Varghese --- pkg/reconciler/mtbroker/trigger/trigger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/reconciler/mtbroker/trigger/trigger_test.go b/pkg/reconciler/mtbroker/trigger/trigger_test.go index 19e2adabdf8..f904c486fe7 100644 --- a/pkg/reconciler/mtbroker/trigger/trigger_test.go +++ b/pkg/reconciler/mtbroker/trigger/trigger_test.go @@ -85,7 +85,7 @@ const ( testSchedule = "*/2 * * * *" testData = "data" sinkName = "testsink" - dependencyAnnotation = "{\"kind\":\"PingSource\",\"name\":\"test-ping-source\",\"apiVersion\":\"sources.knative.dev/v1alpha2\"}" + dependencyAnnotation = "{\"kind\":\"PingSource\",\"name\":\"test-ping-source\",\"apiVersion\":\"sources.knative.dev/v1beta1\"}" subscriberURIReference = "foo" subscriberResolvedTargetURI = "http://example.com/subscriber/foo" From 0512bd2e0f81f6da33c14f5ba4866d8a824f2946 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 18:17:28 -0400 Subject: [PATCH 17/20] Git rebase Signed-off-by: Ansu Varghese --- pkg/reconciler/pingsource/pingsource_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/reconciler/pingsource/pingsource_test.go b/pkg/reconciler/pingsource/pingsource_test.go index 526baf0c857..0f20a253569 100644 --- a/pkg/reconciler/pingsource/pingsource_test.go +++ b/pkg/reconciler/pingsource/pingsource_test.go @@ -261,4 +261,3 @@ func makeAvailableMTAdapter() *appsv1.Deployment { WithDeploymentAvailable()(ma) return ma } - From d16a525d8c8285d28efc68599e25b0efe4117070 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Mon, 31 Aug 2020 18:25:11 -0400 Subject: [PATCH 18/20] Merge updates Signed-off-by: Ansu Varghese --- .../resources/receive_adapter_test.go | 36 ++++--------------- pkg/reconciler/testing/pingsource.go | 14 -------- 2 files changed, 6 insertions(+), 44 deletions(-) diff --git a/pkg/reconciler/pingsource/resources/receive_adapter_test.go b/pkg/reconciler/pingsource/resources/receive_adapter_test.go index ee054a1b578..8195953a87e 100644 --- a/pkg/reconciler/pingsource/resources/receive_adapter_test.go +++ b/pkg/reconciler/pingsource/resources/receive_adapter_test.go @@ -24,24 +24,12 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" - "knative.dev/pkg/kmp" - - "knative.dev/eventing/pkg/apis/sources/v1beta1" + "knative.dev/pkg/system" + _ "knative.dev/pkg/system/testing" ) -func TestMakeReceiveAdapter(t *testing.T) { - src := &v1beta1.PingSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "source-name", - Namespace: "source-namespace", - UID: "source-uid", - }, - Spec: v1beta1.PingSourceSpec{ - Schedule: "*/2 * * * *", - JsonData: "data", - }, - } +func TestMakePingAdapter(t *testing.T) { + replicas := int32(1) args := Args{ ServiceAccountName: "test-sa", @@ -58,20 +46,8 @@ func TestMakeReceiveAdapter(t *testing.T) { Kind: "Deployments", }, ObjectMeta: metav1.ObjectMeta{ - Namespace: "source-namespace", - Name: fmt.Sprintf("pingsource-%s-%s", src.Name, src.UID), - Labels: map[string]string{ - "test-key1": "test-value1", - "test-key2": "test-value2", - }, - OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "sources.knative.dev/v1beta1", - Kind: "PingSource", - Name: src.Name, - UID: src.UID, - Controller: &yes, - BlockOwnerDeletion: &yes, - }}, + Namespace: system.Namespace(), + Name: args.AdapterName, }, Spec: v1.DeploymentSpec{ Replicas: &replicas, diff --git a/pkg/reconciler/testing/pingsource.go b/pkg/reconciler/testing/pingsource.go index 896ff883b34..dec22bf5c10 100644 --- a/pkg/reconciler/testing/pingsource.go +++ b/pkg/reconciler/testing/pingsource.go @@ -145,20 +145,6 @@ func WithPingSourceV1B1UID(uid string) PingSourceV1B1Option { } } -func WithPingSourceV1B1ResourceScopeAnnotation(c *v1beta1.PingSource) { - if c.Annotations == nil { - c.Annotations = make(map[string]string) - } - c.Annotations[eventing.ScopeAnnotationKey] = eventing.ScopeResource -} - -func WithPingSourceV1B1ClusterScopeAnnotation(c *v1beta1.PingSource) { - if c.Annotations == nil { - c.Annotations = make(map[string]string) - } - c.Annotations[eventing.ScopeAnnotationKey] = eventing.ScopeCluster -} - func WithInitPingSourceV1B1Conditions(s *v1beta1.PingSource) { s.Status.InitializeConditions() } From 78abec5d9036069934c85be8ab2d54806383cfd8 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Tue, 1 Sep 2020 08:53:40 -0400 Subject: [PATCH 19/20] Changes from Review comments Signed-off-by: Ansu Varghese --- config/pre-install/v0.18.0/storage-version-migration.yaml | 1 - test/e2e-conformance-tests.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config/pre-install/v0.18.0/storage-version-migration.yaml b/config/pre-install/v0.18.0/storage-version-migration.yaml index 5bff577ba80..24aaa2bed93 100644 --- a/config/pre-install/v0.18.0/storage-version-migration.yaml +++ b/config/pre-install/v0.18.0/storage-version-migration.yaml @@ -44,7 +44,6 @@ spec: - "triggers.eventing.knative.dev" - "channels.messaging.knative.dev" - "inmemorychannels.messaging.knative.dev" - - "pingsources.sources.knative.dev" - "subscriptions.messaging.knative.dev" - "parallels.flows.knative.dev" - "sequences.flows.knative.dev" diff --git a/test/e2e-conformance-tests.sh b/test/e2e-conformance-tests.sh index 92fe9c0a4b6..13bba73cebd 100755 --- a/test/e2e-conformance-tests.sh +++ b/test/e2e-conformance-tests.sh @@ -33,6 +33,6 @@ source "$(dirname "$0")/e2e-common.sh" initialize $@ --skip-istio-addon echo "Running tests with Multi Tenant Channel Based Broker" -go_test_e2e -timeout=30m -parallel=12 ./test/conformance -brokers=eventing.knative.dev/v1beta1:MTChannelBasedBroker -channels=messaging.knative.dev/v1beta1:Channel,messaging.knative.dev/v1beta1:InMemoryChannel,messaging.knative.dev/v1:Channel,messaging.knative.dev/v1:InMemoryChannel -sources=sources.knative.dev/v1beta1:ApiServerSource,sources.knative.dev/v1alpha2:ContainerSource,sources.knative.dev/v1alpha2:PingSource || fail_test +go_test_e2e -timeout=30m -parallel=12 ./test/conformance -brokers=eventing.knative.dev/v1beta1:MTChannelBasedBroker -channels=messaging.knative.dev/v1beta1:Channel,messaging.knative.dev/v1beta1:InMemoryChannel,messaging.knative.dev/v1:Channel,messaging.knative.dev/v1:InMemoryChannel -sources=sources.knative.dev/v1beta1:ApiServerSource,sources.knative.dev/v1alpha2:ContainerSource,sources.knative.dev/v1beta1:PingSource || fail_test success From e7f5fdd856be66fc39355e5ae323ce30f3a81ae6 Mon Sep 17 00:00:00 2001 From: Ansu Varghese Date: Tue, 1 Sep 2020 12:06:57 -0400 Subject: [PATCH 20/20] One nit from rebase Signed-off-by: Ansu Varghese --- pkg/reconciler/mtbroker/broker_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/reconciler/mtbroker/broker_test.go b/pkg/reconciler/mtbroker/broker_test.go index 75e320953ad..72a81ea3d72 100644 --- a/pkg/reconciler/mtbroker/broker_test.go +++ b/pkg/reconciler/mtbroker/broker_test.go @@ -742,7 +742,7 @@ func makeGenerationNotEqualPingSource() *sourcesv1beta1.PingSource { } func makeReadyPingSource() *sourcesv1beta1.PingSource { - u, _ := apis.ParseURL(sinkURI) + u := apis.HTTP(sinkURI) return rtv1alpha1.NewPingSourceV1Beta1(pingSourceName, testNS, rtv1alpha1.WithPingSourceV1B1Spec(sourcesv1beta1.PingSourceSpec{ Schedule: testSchedule,