diff --git a/pkg/adapter/apiserver/config.go b/pkg/adapter/apiserver/config.go index 9f65d6ea5eb..d4174e7db1c 100644 --- a/pkg/adapter/apiserver/config.go +++ b/pkg/adapter/apiserver/config.go @@ -17,7 +17,7 @@ package apiserver import ( "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" ) type ResourceWatch struct { @@ -44,7 +44,7 @@ type Config struct { // owned by a specific resource type. If ResourceOwner matches Resources[n] // then Resources[n] is allowed to pass the ResourceOwner filter. // +optional - ResourceOwner *v1alpha2.APIVersionKind `json:"owner,omitempty"` + ResourceOwner *v1beta1.APIVersionKind `json:"owner,omitempty"` // EventMode controls the format of the event. // `Reference` sends a dataref event type for the resource under watch. diff --git a/pkg/adapter/apiserver/delegate_test.go b/pkg/adapter/apiserver/delegate_test.go index f01c7dc8230..38100764291 100644 --- a/pkg/adapter/apiserver/delegate_test.go +++ b/pkg/adapter/apiserver/delegate_test.go @@ -18,43 +18,43 @@ package apiserver import ( "testing" - sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func TestResourceAddEvent(t *testing.T) { d, ce := makeResourceAndTestingClient() d.Add(simplePod("unit", "test")) - validateSent(t, ce, sourcesv1alpha1.ApiServerSourceAddEventType) + validateSent(t, ce, sourcesv1beta1.ApiServerSourceAddEventType) } func TestResourceUpdateEvent(t *testing.T) { d, ce := makeResourceAndTestingClient() d.Update(simplePod("unit", "test")) - validateSent(t, ce, sourcesv1alpha1.ApiServerSourceUpdateEventType) + validateSent(t, ce, sourcesv1beta1.ApiServerSourceUpdateEventType) } func TestResourceDeleteEvent(t *testing.T) { d, ce := makeResourceAndTestingClient() d.Delete(simplePod("unit", "test")) - validateSent(t, ce, sourcesv1alpha1.ApiServerSourceDeleteEventType) + validateSent(t, ce, sourcesv1beta1.ApiServerSourceDeleteEventType) } func TestResourceAddEventNil(t *testing.T) { d, ce := makeResourceAndTestingClient() d.Add(nil) - validateNotSent(t, ce, sourcesv1alpha1.ApiServerSourceAddEventType) + validateNotSent(t, ce, sourcesv1beta1.ApiServerSourceAddEventType) } func TestResourceUpdateEventNil(t *testing.T) { d, ce := makeResourceAndTestingClient() d.Update(nil) - validateNotSent(t, ce, sourcesv1alpha1.ApiServerSourceUpdateEventType) + validateNotSent(t, ce, sourcesv1beta1.ApiServerSourceUpdateEventType) } func TestResourceDeleteEventNil(t *testing.T) { d, ce := makeResourceAndTestingClient() d.Delete(nil) - validateNotSent(t, ce, sourcesv1alpha1.ApiServerSourceDeleteEventType) + validateNotSent(t, ce, sourcesv1beta1.ApiServerSourceDeleteEventType) } // HACKHACKHACK For test coverage. diff --git a/pkg/adapter/apiserver/events/events.go b/pkg/adapter/apiserver/events/events.go index b5fd810ce30..0aa6c55ee68 100644 --- a/pkg/adapter/apiserver/events/events.go +++ b/pkg/adapter/apiserver/events/events.go @@ -24,7 +24,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func MakeAddEvent(source string, obj interface{}, ref bool) (cloudevents.Event, error) { @@ -37,10 +37,10 @@ func MakeAddEvent(source string, obj interface{}, ref bool) (cloudevents.Event, var eventType string if ref { data = getRef(object) - eventType = sourcesv1alpha2.ApiServerSourceAddRefEventType + eventType = sourcesv1beta1.ApiServerSourceAddRefEventType } else { data = object - eventType = sourcesv1alpha2.ApiServerSourceAddEventType + eventType = sourcesv1beta1.ApiServerSourceAddEventType } return makeEvent(source, eventType, object, data) @@ -56,10 +56,10 @@ func MakeUpdateEvent(source string, obj interface{}, ref bool) (cloudevents.Even var eventType string if ref { data = getRef(object) - eventType = sourcesv1alpha2.ApiServerSourceUpdateRefEventType + eventType = sourcesv1beta1.ApiServerSourceUpdateRefEventType } else { data = object - eventType = sourcesv1alpha2.ApiServerSourceUpdateEventType + eventType = sourcesv1beta1.ApiServerSourceUpdateEventType } return makeEvent(source, eventType, object, data) @@ -74,10 +74,10 @@ func MakeDeleteEvent(source string, obj interface{}, ref bool) (cloudevents.Even var eventType string if ref { data = getRef(object) - eventType = sourcesv1alpha2.ApiServerSourceDeleteRefEventType + eventType = sourcesv1beta1.ApiServerSourceDeleteRefEventType } else { data = object - eventType = sourcesv1alpha2.ApiServerSourceDeleteEventType + eventType = sourcesv1beta1.ApiServerSourceDeleteEventType } return makeEvent(source, eventType, object, data) diff --git a/pkg/adapter/apiserver/filter_test.go b/pkg/adapter/apiserver/filter_test.go index cb43c3bd00e..790f295cc72 100644 --- a/pkg/adapter/apiserver/filter_test.go +++ b/pkg/adapter/apiserver/filter_test.go @@ -20,79 +20,79 @@ import ( "testing" adaptertest "knative.dev/eventing/pkg/adapter/v2/test" - sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func TestControllerAddEventWithNoController(t *testing.T) { c, tc := makeController("v1", "Pod") c.Add(simplePod("unit", "test")) - validateNotSent(t, tc, sourcesv1alpha1.ApiServerSourceAddRefEventType) + validateNotSent(t, tc, sourcesv1beta1.ApiServerSourceAddRefEventType) } func TestControllerAddEventWithWrongController(t *testing.T) { c, tc := makeController("v1", "Pod") c.Add(simpleOwnedPod("unit", "test")) - validateNotSent(t, tc, sourcesv1alpha1.ApiServerSourceAddRefEventType) + validateNotSent(t, tc, sourcesv1beta1.ApiServerSourceAddRefEventType) } func TestControllerAddEventWithGoodController(t *testing.T) { c, tc := makeController("apps/v1", "ReplicaSet") c.Add(simpleOwnedPod("unit", "test")) - validateSent(t, tc, sourcesv1alpha1.ApiServerSourceAddRefEventType) + validateSent(t, tc, sourcesv1beta1.ApiServerSourceAddRefEventType) } func TestControllerAddEventWithGoodControllerNoAPIVersion(t *testing.T) { c, tc := makeController("", "ReplicaSet") c.Add(simpleOwnedPod("unit", "test")) - validateSent(t, tc, sourcesv1alpha1.ApiServerSourceAddRefEventType) + validateSent(t, tc, sourcesv1beta1.ApiServerSourceAddRefEventType) } func TestControllerUpdateEventWithNoController(t *testing.T) { c, tc := makeController("v1", "Pod") c.Update(simplePod("unit", "test")) - validateNotSent(t, tc, sourcesv1alpha1.ApiServerSourceUpdateRefEventType) + validateNotSent(t, tc, sourcesv1beta1.ApiServerSourceUpdateRefEventType) } func TestControllerUpdateEventWithWrongController(t *testing.T) { c, tc := makeController("v1", "Pod") c.Update(simpleOwnedPod("unit", "test")) - validateNotSent(t, tc, sourcesv1alpha1.ApiServerSourceUpdateRefEventType) + validateNotSent(t, tc, sourcesv1beta1.ApiServerSourceUpdateRefEventType) } func TestControllerUpdateEventWithGoodController(t *testing.T) { c, tc := makeController("apps/v1", "ReplicaSet") c.Update(simpleOwnedPod("unit", "test")) - validateSent(t, tc, sourcesv1alpha1.ApiServerSourceUpdateRefEventType) + validateSent(t, tc, sourcesv1beta1.ApiServerSourceUpdateRefEventType) } func TestControllerUpdateEventWithGoodControllerNoAPIVersion(t *testing.T) { c, tc := makeController("", "ReplicaSet") c.Update(simpleOwnedPod("unit", "test")) - validateSent(t, tc, sourcesv1alpha1.ApiServerSourceUpdateRefEventType) + validateSent(t, tc, sourcesv1beta1.ApiServerSourceUpdateRefEventType) } func TestControllerDeleteEventWithNoController(t *testing.T) { c, tc := makeController("v1", "Pod") c.Delete(simplePod("unit", "test")) - validateNotSent(t, tc, sourcesv1alpha1.ApiServerSourceDeleteRefEventType) + validateNotSent(t, tc, sourcesv1beta1.ApiServerSourceDeleteRefEventType) } func TestControllerDeleteEventWithWrongController(t *testing.T) { c, tc := makeController("v1", "Pod") c.Delete(simpleOwnedPod("unit", "test")) - validateNotSent(t, tc, sourcesv1alpha1.ApiServerSourceDeleteRefEventType) + validateNotSent(t, tc, sourcesv1beta1.ApiServerSourceDeleteRefEventType) } func TestControllerDeleteEventWithGoodController(t *testing.T) { c, tc := makeController("apps/v1", "ReplicaSet") c.Delete(simpleOwnedPod("unit", "test")) - validateSent(t, tc, sourcesv1alpha1.ApiServerSourceDeleteRefEventType) + validateSent(t, tc, sourcesv1beta1.ApiServerSourceDeleteRefEventType) } func TestControllerDeleteEventWithGoodControllerNoAPIVersion(t *testing.T) { c, tc := makeController("", "ReplicaSet") c.Delete(simpleOwnedPod("unit", "test")) - validateSent(t, tc, sourcesv1alpha1.ApiServerSourceDeleteRefEventType) + validateSent(t, tc, sourcesv1beta1.ApiServerSourceDeleteRefEventType) } func makeController(apiVersion, kind string) (*controllerFilter, *adaptertest.TestCloudEventsClient) { diff --git a/pkg/adapter/apiserver/ref_test.go b/pkg/adapter/apiserver/ref_test.go index 30ecfc8b3f1..cf4f21d1153 100644 --- a/pkg/adapter/apiserver/ref_test.go +++ b/pkg/adapter/apiserver/ref_test.go @@ -18,44 +18,44 @@ package apiserver import ( "testing" - sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" ) func TestRefAddEvent(t *testing.T) { d, ce := makeRefAndTestingClient() d.Add(simplePod("unit", "test")) - validateSent(t, ce, sourcesv1alpha1.ApiServerSourceAddRefEventType) + validateSent(t, ce, sourcesv1beta1.ApiServerSourceAddRefEventType) } func TestRefUpdateEvent(t *testing.T) { d, ce := makeRefAndTestingClient() d.Update(simplePod("unit", "test")) - validateSent(t, ce, sourcesv1alpha1.ApiServerSourceUpdateRefEventType) + validateSent(t, ce, sourcesv1beta1.ApiServerSourceUpdateRefEventType) } func TestRefDeleteEvent(t *testing.T) { d, ce := makeRefAndTestingClient() d.Delete(simplePod("unit", "test")) - validateSent(t, ce, sourcesv1alpha1.ApiServerSourceDeleteRefEventType) + validateSent(t, ce, sourcesv1beta1.ApiServerSourceDeleteRefEventType) } func TestRefAddEventNil(t *testing.T) { d, ce := makeRefAndTestingClient() d.Add(nil) - validateNotSent(t, ce, sourcesv1alpha1.ApiServerSourceAddRefEventType) + validateNotSent(t, ce, sourcesv1beta1.ApiServerSourceAddRefEventType) } func TestRefUpdateEventNil(t *testing.T) { d, ce := makeRefAndTestingClient() d.Update(nil) - validateNotSent(t, ce, sourcesv1alpha1.ApiServerSourceUpdateRefEventType) + validateNotSent(t, ce, sourcesv1beta1.ApiServerSourceUpdateRefEventType) } func TestRefDeleteEventNil(t *testing.T) { d, ce := makeRefAndTestingClient() d.Delete(nil) - validateNotSent(t, ce, sourcesv1alpha1.ApiServerSourceDeleteRefEventType) + validateNotSent(t, ce, sourcesv1beta1.ApiServerSourceDeleteRefEventType) } // HACKHACKHACK For test coverage. diff --git a/pkg/reconciler/apiserversource/apiserversource.go b/pkg/reconciler/apiserversource/apiserversource.go index 68c8db52e5d..2b7067960d7 100644 --- a/pkg/reconciler/apiserversource/apiserversource.go +++ b/pkg/reconciler/apiserversource/apiserversource.go @@ -37,9 +37,9 @@ import ( pkgreconciler "knative.dev/pkg/reconciler" "knative.dev/pkg/resolver" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" - apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/apiserversource" - listers "knative.dev/eventing/pkg/client/listers/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" + apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/apiserversource" + listers "knative.dev/eventing/pkg/client/listers/sources/v1beta1" "knative.dev/eventing/pkg/logging" "knative.dev/eventing/pkg/reconciler/apiserversource/resources" reconcilersource "knative.dev/eventing/pkg/reconciler/source" @@ -84,7 +84,7 @@ type Reconciler struct { var _ apiserversourcereconciler.Interface = (*Reconciler)(nil) -func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.ApiServerSource) pkgreconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1beta1.ApiServerSource) pkgreconciler.Event { // This Source attempts to reconcile three things. // 1. Determine the sink's URI. // - Nothing to delete. @@ -128,7 +128,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.ApiServ return newReconciledNormal(source.Namespace, source.Name) } -func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1alpha2.ApiServerSource, sinkURI string) (*appsv1.Deployment, error) { +func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1beta1.ApiServerSource, sinkURI string) (*appsv1.Deployment, error) { // TODO: missing. // if err := checkResourcesStatus(src); err != nil { // return nil, err @@ -196,7 +196,7 @@ func (r *Reconciler) podSpecChanged(oldPodSpec corev1.PodSpec, newPodSpec corev1 return false } -func (r *Reconciler) runAccessCheck(src *v1alpha2.ApiServerSource) error { +func (r *Reconciler) runAccessCheck(src *v1beta1.ApiServerSource) error { if src.Spec.Resources == nil || len(src.Spec.Resources) == 0 { src.Status.MarkSufficientPermissions() return nil @@ -263,8 +263,8 @@ func (r *Reconciler) runAccessCheck(src *v1alpha2.ApiServerSource) error { } func (r *Reconciler) createCloudEventAttributes() []duckv1.CloudEventAttributes { - ceAttributes := make([]duckv1.CloudEventAttributes, 0, len(v1alpha2.ApiServerSourceEventTypes)) - for _, apiServerSourceType := range v1alpha2.ApiServerSourceEventTypes { + ceAttributes := make([]duckv1.CloudEventAttributes, 0, len(v1beta1.ApiServerSourceEventTypes)) + for _, apiServerSourceType := range v1beta1.ApiServerSourceEventTypes { ceAttributes = append(ceAttributes, duckv1.CloudEventAttributes{ Type: apiServerSourceType, Source: r.ceSource, diff --git a/pkg/reconciler/apiserversource/apiserversource_test.go b/pkg/reconciler/apiserversource/apiserversource_test.go index 86a610726f4..bb2a45a31dc 100644 --- a/pkg/reconciler/apiserversource/apiserversource_test.go +++ b/pkg/reconciler/apiserversource/apiserversource_test.go @@ -30,9 +30,9 @@ import ( "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/apiserversource" + "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/apiserversource" "knative.dev/eventing/pkg/reconciler/apiserversource/resources" reconcilersource "knative.dev/eventing/pkg/reconciler/source" "knative.dev/eventing/pkg/utils" @@ -47,7 +47,7 @@ import ( logtesting "knative.dev/pkg/logging/testing" "knative.dev/pkg/resolver" - rttestingv1alpha1 "knative.dev/eventing/pkg/reconciler/testing" + rttesting "knative.dev/eventing/pkg/reconciler/testing" . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" . "knative.dev/pkg/reconciler/testing" ) @@ -96,16 +96,16 @@ func TestReconcile(t *testing.T) { table := TableTest{{ Name: "not enough permissions", Objects: []runtime.Object{ - rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -115,21 +115,21 @@ func TestReconcile(t *testing.T) { }, Key: testNS + "/" + sourceName, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + Object: rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), - rttestingv1alpha1.WithApiServerSourceSink(sinkURI), - rttestingv1alpha1.WithApiServerSourceNoSufficientPermissions, + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceStatusObservedGenerationV1B1(generation), + rttesting.WithApiServerSourceSinkV1B1(sinkURI), + rttesting.WithApiServerSourceNoSufficientPermissionsV1B1, ), }}, WantCreates: []runtime.Object{ @@ -146,16 +146,16 @@ func TestReconcile(t *testing.T) { }, { Name: "valid", Objects: []runtime.Object{ - rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -168,23 +168,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + Object: rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceDeployed, - rttestingv1alpha1.WithApiServerSourceSink(sinkURI), - rttestingv1alpha1.WithApiServerSourceSufficientPermissions, - rttestingv1alpha1.WithApiServerSourceEventTypes(source), - rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceDeployedV1B1, + rttesting.WithApiServerSourceSinkV1B1(sinkURI), + rttesting.WithApiServerSourceSufficientPermissionsV1B1, + rttesting.WithApiServerSourceEventTypesV1B1(source), + rttesting.WithApiServerSourceStatusObservedGenerationV1B1(generation), ), }}, WantCreates: []runtime.Object{ @@ -197,16 +197,16 @@ func TestReconcile(t *testing.T) { }, { Name: "valid with sink URI", Objects: []runtime.Object{ - rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -219,23 +219,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + Object: rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceDeployed, - rttestingv1alpha1.WithApiServerSourceSink(sinkURI), - rttestingv1alpha1.WithApiServerSourceSufficientPermissions, - rttestingv1alpha1.WithApiServerSourceEventTypes(source), - rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceDeployedV1B1, + rttesting.WithApiServerSourceSinkV1B1(sinkURI), + rttesting.WithApiServerSourceSufficientPermissionsV1B1, + rttesting.WithApiServerSourceEventTypesV1B1(source), + rttesting.WithApiServerSourceStatusObservedGenerationV1B1(generation), ), }}, WantCreates: []runtime.Object{ @@ -248,9 +248,9 @@ func TestReconcile(t *testing.T) { }, { Name: "valid with relative uri reference", Objects: []runtime.Object{ - rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, @@ -261,8 +261,8 @@ func TestReconcile(t *testing.T) { }, }, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -275,9 +275,9 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + Object: rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, @@ -288,15 +288,15 @@ func TestReconcile(t *testing.T) { }, }, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceDeployed, - rttestingv1alpha1.WithApiServerSourceSink(sinkTargetURI), - rttestingv1alpha1.WithApiServerSourceSufficientPermissions, - rttestingv1alpha1.WithApiServerSourceEventTypes(source), - rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceDeployedV1B1, + rttesting.WithApiServerSourceSinkV1B1(sinkTargetURI), + rttesting.WithApiServerSourceSufficientPermissionsV1B1, + rttesting.WithApiServerSourceEventTypesV1B1(source), + rttesting.WithApiServerSourceStatusObservedGenerationV1B1(generation), ), }}, WantCreates: []runtime.Object{ @@ -309,16 +309,16 @@ func TestReconcile(t *testing.T) { }, { Name: "deployment update due to env", Objects: []runtime.Object{ - rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -332,23 +332,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + Object: rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceSink(sinkURI), - rttestingv1alpha1.WithApiServerSourceSufficientPermissions, - rttestingv1alpha1.WithApiServerSourceEventTypes(source), - rttestingv1alpha1.WithApiServerSourceDeploymentUnavailable, - rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceSinkV1B1(sinkURI), + rttesting.WithApiServerSourceSufficientPermissionsV1B1, + rttesting.WithApiServerSourceEventTypesV1B1(source), + rttesting.WithApiServerSourceDeploymentUnavailableV1B1, + rttesting.WithApiServerSourceStatusObservedGenerationV1B1(generation), ), }}, WantUpdates: []clientgotesting.UpdateActionImpl{{ @@ -364,9 +364,9 @@ func TestReconcile(t *testing.T) { }, { Name: "deployment update due to service account", Objects: []runtime.Object{ - rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, @@ -375,8 +375,8 @@ func TestReconcile(t *testing.T) { }, ServiceAccountName: "malin", }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -390,9 +390,9 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + Object: rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, @@ -401,15 +401,15 @@ func TestReconcile(t *testing.T) { }, ServiceAccountName: "malin", }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceDeploymentUnavailable, - rttestingv1alpha1.WithApiServerSourceSink(sinkURI), - rttestingv1alpha1.WithApiServerSourceSufficientPermissions, - rttestingv1alpha1.WithApiServerSourceEventTypes(source), - rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceDeploymentUnavailableV1B1, + rttesting.WithApiServerSourceSinkV1B1(sinkURI), + rttesting.WithApiServerSourceSufficientPermissionsV1B1, + rttesting.WithApiServerSourceEventTypesV1B1(source), + rttesting.WithApiServerSourceStatusObservedGenerationV1B1(generation), ), }}, WantUpdates: []clientgotesting.UpdateActionImpl{{ @@ -425,16 +425,16 @@ func TestReconcile(t *testing.T) { }, { Name: "deployment update due to container count", Objects: []runtime.Object{ - rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -448,23 +448,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + Object: rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceDeploymentUnavailable, - rttestingv1alpha1.WithApiServerSourceSink(sinkURI), - rttestingv1alpha1.WithApiServerSourceSufficientPermissions, - rttestingv1alpha1.WithApiServerSourceEventTypes(source), - rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceDeploymentUnavailableV1B1, + rttesting.WithApiServerSourceSinkV1B1(sinkURI), + rttesting.WithApiServerSourceSufficientPermissionsV1B1, + rttesting.WithApiServerSourceEventTypesV1B1(source), + rttesting.WithApiServerSourceStatusObservedGenerationV1B1(generation), ), }}, WantUpdates: []clientgotesting.UpdateActionImpl{{ @@ -480,16 +480,16 @@ func TestReconcile(t *testing.T) { }, { Name: "valid with broker sink", Objects: []runtime.Object{ - rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: brokerDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), ), NewBroker(sinkName, testNS, WithInitBrokerConditions, @@ -502,23 +502,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + Object: rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: brokerDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), - rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), + rttesting.WithApiServerSourceObjectMetaGenerationV1B1(generation), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceDeployed, - rttestingv1alpha1.WithApiServerSourceSink(sinkURI), - rttestingv1alpha1.WithApiServerSourceSufficientPermissions, - rttestingv1alpha1.WithApiServerSourceEventTypes(source), - rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceDeployedV1B1, + rttesting.WithApiServerSourceSinkV1B1(sinkURI), + rttesting.WithApiServerSourceSufficientPermissionsV1B1, + rttesting.WithApiServerSourceEventTypesV1B1(source), + rttesting.WithApiServerSourceStatusObservedGenerationV1B1(generation), ), }}, WantCreates: []runtime.Object{ @@ -535,7 +535,7 @@ func TestReconcile(t *testing.T) { ctx = addressable.WithDuck(ctx) r := &Reconciler{ kubeClientSet: fakekubeclient.Get(ctx), - apiserversourceLister: listers.GetApiServerSourceV1alpha2Lister(), + apiserversourceLister: listers.GetApiServerSourceV1beta1Lister(), ceSource: source, receiveAdapterImage: image, sinkResolver: resolver.NewURIResolver(ctx, func(types.NamespacedName) {}), @@ -543,7 +543,7 @@ func TestReconcile(t *testing.T) { configs: &reconcilersource.EmptyVarsGenerator{}, } return apiserversource.NewReconciler(ctx, logger, - fakeeventingclient.Get(ctx), listers.GetApiServerSourceV1alpha2Lister(), + fakeeventingclient.Get(ctx), listers.GetApiServerSourceV1beta1Lister(), controller.GetEventRecorder(ctx), r) }, true, @@ -558,19 +558,19 @@ func makeReceiveAdapter(t *testing.T) *appsv1.Deployment { func makeReceiveAdapterWithName(t *testing.T, sourceName string) *appsv1.Deployment { t.Helper() - src := rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + src := rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceDeployed, - rttestingv1alpha1.WithApiServerSourceSink(sinkURI), + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceDeployedV1B1, + rttesting.WithApiServerSourceSinkV1B1(sinkURI), ) args := resources.ReceiveAdapterArgs{ @@ -589,26 +589,26 @@ func makeReceiveAdapterWithName(t *testing.T, sourceName string) *appsv1.Deploym func makeAvailableReceiveAdapter(t *testing.T) *appsv1.Deployment { ra := makeReceiveAdapter(t) - rttestingv1alpha1.WithDeploymentAvailable()(ra) + rttesting.WithDeploymentAvailable()(ra) return ra } func makeAvailableReceiveAdapterWithTargetURI(t *testing.T) *appsv1.Deployment { t.Helper() - src := rttestingv1alpha1.NewApiServerSource(sourceName, testNS, - rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ - Resources: []sourcesv1alpha2.APIVersionKindSelector{{ + src := rttesting.NewApiServerSourceV1Beta1(sourceName, testNS, + rttesting.WithApiServerSourceSpecV1B1(sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttesting.WithApiServerSourceUIDV1B1(sourceUID), // Status Update: - rttestingv1alpha1.WithInitApiServerSourceConditions, - rttestingv1alpha1.WithApiServerSourceDeployed, - rttestingv1alpha1.WithApiServerSourceSink(sinkURI), + rttesting.WithInitApiServerSourceConditionsV1B1, + rttesting.WithApiServerSourceDeployedV1B1, + rttesting.WithApiServerSourceSinkV1B1(sinkURI), ) args := resources.ReceiveAdapterArgs{ @@ -622,7 +622,7 @@ func makeAvailableReceiveAdapterWithTargetURI(t *testing.T) *appsv1.Deployment { ra, err := resources.MakeReceiveAdapter(&args) require.NoError(t, err) - rttestingv1alpha1.WithDeploymentAvailable()(ra) + rttesting.WithDeploymentAvailable()(ra) return ra } diff --git a/pkg/reconciler/apiserversource/controller.go b/pkg/reconciler/apiserversource/controller.go index 65d1d01f1b9..3cf103e8804 100644 --- a/pkg/reconciler/apiserversource/controller.go +++ b/pkg/reconciler/apiserversource/controller.go @@ -32,8 +32,8 @@ import ( kubeclient "knative.dev/pkg/client/injection/kube/client" deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment" - apiserversourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/apiserversource" - apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/apiserversource" + apiserversourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/apiserversource" + apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/apiserversource" ) // envConfig will be used to extract the required environment variables using diff --git a/pkg/reconciler/apiserversource/controller_test.go b/pkg/reconciler/apiserversource/controller_test.go index c39e7b6b71a..9ee036ff9d9 100644 --- a/pkg/reconciler/apiserversource/controller_test.go +++ b/pkg/reconciler/apiserversource/controller_test.go @@ -30,7 +30,7 @@ import ( _ "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment/fake" // Fake injection informers - _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/apiserversource/fake" + _ "knative.dev/eventing/pkg/client/injection/informers/sources/v1beta1/apiserversource/fake" ) func TestNew(t *testing.T) { diff --git a/pkg/reconciler/apiserversource/resources/receive_adapter.go b/pkg/reconciler/apiserversource/resources/receive_adapter.go index 5ef753536be..bb90469380a 100644 --- a/pkg/reconciler/apiserversource/resources/receive_adapter.go +++ b/pkg/reconciler/apiserversource/resources/receive_adapter.go @@ -29,7 +29,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/eventing/pkg/adapter/apiserver" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" reconcilersource "knative.dev/eventing/pkg/reconciler/source" "knative.dev/pkg/kmeta" "knative.dev/pkg/system" @@ -39,7 +39,7 @@ import ( // Every field is required. type ReceiveAdapterArgs struct { Image string - Source *v1alpha2.ApiServerSource + Source *v1beta1.ApiServerSource Labels map[string]string SinkURI string Configs reconcilersource.ConfigAccessor diff --git a/pkg/reconciler/apiserversource/resources/receive_adapter_test.go b/pkg/reconciler/apiserversource/resources/receive_adapter_test.go index c3dcaf0fece..d5f7778f9e2 100644 --- a/pkg/reconciler/apiserversource/resources/receive_adapter_test.go +++ b/pkg/reconciler/apiserversource/resources/receive_adapter_test.go @@ -26,7 +26,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/eventing/pkg/apis/sources/v1alpha2" + "knative.dev/eventing/pkg/apis/sources/v1beta1" "knative.dev/eventing/pkg/reconciler/source" duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/kmeta" @@ -40,14 +40,14 @@ func TestMakeReceiveAdapters(t *testing.T) { one := int32(1) trueValue := true - src := &v1alpha2.ApiServerSource{ + src := &v1beta1.ApiServerSource{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: "source-namespace", UID: "1234", }, - Spec: v1alpha2.ApiServerSourceSpec{ - Resources: []v1alpha2.APIVersionKindSelector{{ + Spec: v1beta1.ApiServerSourceSpec{ + Resources: []v1beta1.APIVersionKindSelector{{ APIVersion: "", Kind: "Namespace", }, { @@ -60,7 +60,7 @@ func TestMakeReceiveAdapters(t *testing.T) { MatchLabels: map[string]string{"test-key1": "test-value1"}, }, }}, - ResourceOwner: &v1alpha2.APIVersionKind{ + ResourceOwner: &v1beta1.APIVersionKind{ APIVersion: "custom/v1", Kind: "Parent", }, @@ -79,7 +79,7 @@ func TestMakeReceiveAdapters(t *testing.T) { }, OwnerReferences: []metav1.OwnerReference{ { - APIVersion: "sources.knative.dev/v1alpha2", + APIVersion: "sources.knative.dev/v1beta1", Kind: "ApiServerSource", Name: name, UID: "1234", @@ -167,7 +167,7 @@ func TestMakeReceiveAdapters(t *testing.T) { testCases := map[string]struct { want *appsv1.Deployment - src *v1alpha2.ApiServerSource + src *v1beta1.ApiServerSource }{ "TestMakeReceiveAdapter": { diff --git a/pkg/reconciler/testing/apiserversource.go b/pkg/reconciler/testing/apiserversource.go index 943394000f9..a229ca7d432 100644 --- a/pkg/reconciler/testing/apiserversource.go +++ b/pkg/reconciler/testing/apiserversource.go @@ -24,16 +24,20 @@ import ( 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/apis" duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/kmeta" ) -// ApiServerSourceOption enables further configuration of a ApiServer. -type ApiServerSourceOption func(*v1alpha2.ApiServerSource) +// V1Alpha2ApiServerSourceOption enables further configuration of a v1alpha2 ApiServer. +type V1Alpha2ApiServerSourceOption func(*v1alpha2.ApiServerSource) -// NewApiServerSource creates a ApiServer with ApiServerOptions -func NewApiServerSource(name, namespace string, o ...ApiServerSourceOption) *v1alpha2.ApiServerSource { +// V1Beta1ApiServerSourceOption enables further configuration of a v1beta1 ApiServer. +type V1Beta1ApiServerSourceOption func(*v1beta1.ApiServerSource) + +// NewApiServerSourceV1Alpha2 creates a v1alpha2 ApiServer with ApiServerOptions +func NewApiServerSourceV1Alpha2(name, namespace string, o ...V1Alpha2ApiServerSourceOption) *v1alpha2.ApiServerSource { c := &v1alpha2.ApiServerSource{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -47,41 +51,56 @@ func NewApiServerSource(name, namespace string, o ...ApiServerSourceOption) *v1a return c } -func WithApiServerSourceUID(uid string) ApiServerSourceOption { - return func(a *v1alpha2.ApiServerSource) { +// NewApiServerSourceV1Beta1 creates a v1beta1 ApiServer with ApiServerOptions +func NewApiServerSourceV1Beta1(name, namespace string, o ...V1Beta1ApiServerSourceOption) *v1beta1.ApiServerSource { + c := &v1beta1.ApiServerSource{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + } + for _, opt := range o { + opt(c) + } + //c.SetDefaults(context.Background()) // TODO: We should add defaults and validation. + return c +} + +func WithApiServerSourceUIDV1B1(uid string) V1Beta1ApiServerSourceOption { + return func(a *v1beta1.ApiServerSource) { a.UID = types.UID(uid) } } -// WithInitApiServerSourceConditions initializes the ApiServerSource's conditions. -func WithInitApiServerSourceConditions(s *v1alpha2.ApiServerSource) { +// WithInitApiServerSourceConditionsV1B1 initializes the v1beta1 ApiServerSource's conditions. +func WithInitApiServerSourceConditionsV1B1(s *v1beta1.ApiServerSource) { s.Status.InitializeConditions() } -func WithApiServerSourceSinkNotFound(s *v1alpha2.ApiServerSource) { +func WithApiServerSourceSinkNotFoundV1B1(s *v1beta1.ApiServerSource) { s.Status.MarkNoSink("NotFound", "") } -func WithApiServerSourceSink(uri *apis.URL) ApiServerSourceOption { - return func(s *v1alpha2.ApiServerSource) { +func WithApiServerSourceSinkV1B1(uri *apis.URL) V1Beta1ApiServerSourceOption { + return func(s *v1beta1.ApiServerSource) { s.Status.MarkSink(uri) } } -func WithApiServerSourceDeploymentUnavailable(s *v1alpha2.ApiServerSource) { +func WithApiServerSourceDeploymentUnavailableV1B1(s *v1beta1.ApiServerSource) { // The Deployment uses GenerateName, so its name is empty. name := kmeta.ChildName(fmt.Sprintf("apiserversource-%s-", s.Name), string(s.GetUID())) s.Status.PropagateDeploymentAvailability(NewDeployment(name, "any")) } -func WithApiServerSourceDeployed(s *v1alpha2.ApiServerSource) { +func WithApiServerSourceDeployedV1B1(s *v1beta1.ApiServerSource) { s.Status.PropagateDeploymentAvailability(NewDeployment("any", "any", WithDeploymentAvailable())) } -func WithApiServerSourceEventTypes(source string) ApiServerSourceOption { - return func(s *v1alpha2.ApiServerSource) { - ceAttributes := make([]duckv1.CloudEventAttributes, 0, len(v1alpha2.ApiServerSourceEventTypes)) - for _, apiServerSourceType := range v1alpha2.ApiServerSourceEventTypes { +func WithApiServerSourceEventTypesV1B1(source string) V1Beta1ApiServerSourceOption { + return func(s *v1beta1.ApiServerSource) { + ceAttributes := make([]duckv1.CloudEventAttributes, 0, len(v1beta1.ApiServerSourceEventTypes)) + for _, apiServerSourceType := range v1beta1.ApiServerSourceEventTypes { ceAttributes = append(ceAttributes, duckv1.CloudEventAttributes{ Type: apiServerSourceType, Source: source, @@ -91,34 +110,41 @@ func WithApiServerSourceEventTypes(source string) ApiServerSourceOption { } } -func WithApiServerSourceSufficientPermissions(s *v1alpha2.ApiServerSource) { +func WithApiServerSourceSufficientPermissionsV1B1(s *v1beta1.ApiServerSource) { s.Status.MarkSufficientPermissions() } -func WithApiServerSourceNoSufficientPermissions(s *v1alpha2.ApiServerSource) { +func WithApiServerSourceNoSufficientPermissionsV1B1(s *v1beta1.ApiServerSource) { s.Status.MarkNoSufficientPermissions("", `User system:serviceaccount:testnamespace:default cannot get, list, watch resource "namespaces" in API group ""`) } -func WithApiServerSourceDeleted(c *v1alpha2.ApiServerSource) { +func WithApiServerSourceDeletedV1B1(c *v1beta1.ApiServerSource) { t := metav1.NewTime(time.Unix(1e9, 0)) c.ObjectMeta.SetDeletionTimestamp(&t) } -func WithApiServerSourceSpec(spec v1alpha2.ApiServerSourceSpec) ApiServerSourceOption { +func WithApiServerSourceSpecV1A2(spec v1alpha2.ApiServerSourceSpec) V1Alpha2ApiServerSourceOption { return func(c *v1alpha2.ApiServerSource) { c.Spec = spec c.Spec.SetDefaults(context.Background()) } } -func WithApiServerSourceStatusObservedGeneration(generation int64) ApiServerSourceOption { - return func(c *v1alpha2.ApiServerSource) { +func WithApiServerSourceSpecV1B1(spec v1beta1.ApiServerSourceSpec) V1Beta1ApiServerSourceOption { + return func(c *v1beta1.ApiServerSource) { + c.Spec = spec + c.Spec.SetDefaults(context.Background()) + } +} + +func WithApiServerSourceStatusObservedGenerationV1B1(generation int64) V1Beta1ApiServerSourceOption { + return func(c *v1beta1.ApiServerSource) { c.Status.ObservedGeneration = generation } } -func WithApiServerSourceObjectMetaGeneration(generation int64) ApiServerSourceOption { - return func(c *v1alpha2.ApiServerSource) { +func WithApiServerSourceObjectMetaGenerationV1B1(generation int64) V1Beta1ApiServerSourceOption { + return func(c *v1beta1.ApiServerSource) { c.ObjectMeta.Generation = generation } } diff --git a/pkg/reconciler/testing/v1beta1/listers.go b/pkg/reconciler/testing/v1beta1/listers.go index a36927e107b..fb79144b2b6 100644 --- a/pkg/reconciler/testing/v1beta1/listers.go +++ b/pkg/reconciler/testing/v1beta1/listers.go @@ -38,6 +38,7 @@ import ( messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" fakeeventingclientset "knative.dev/eventing/pkg/client/clientset/versioned/fake" configslisters "knative.dev/eventing/pkg/client/listers/configs/v1alpha1" eventingv1beta1listers "knative.dev/eventing/pkg/client/listers/eventing/v1beta1" @@ -45,6 +46,7 @@ import ( messaginglistersv1beta1 "knative.dev/eventing/pkg/client/listers/messaging/v1beta1" sourcelisters "knative.dev/eventing/pkg/client/listers/sources/v1alpha1" sourcev1alpha2listers "knative.dev/eventing/pkg/client/listers/sources/v1alpha2" + sourcev1beta1listers "knative.dev/eventing/pkg/client/listers/sources/v1beta1" duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/reconciler/testing" ) @@ -180,6 +182,10 @@ func (l *Listers) GetApiServerSourceV1alpha2Lister() sourcev1alpha2listers.ApiSe return sourcev1alpha2listers.NewApiServerSourceLister(l.indexerFor(&sourcesv1alpha2.ApiServerSource{})) } +func (l *Listers) GetApiServerSourceV1beta1Lister() sourcev1beta1listers.ApiServerSourceLister { + return sourcev1beta1listers.NewApiServerSourceLister(l.indexerFor(&sourcesv1beta1.ApiServerSource{})) +} + func (l *Listers) GetDeploymentLister() appsv1listers.DeploymentLister { return appsv1listers.NewDeploymentLister(l.indexerFor(&appsv1.Deployment{})) } diff --git a/test/e2e/source_api_server_test.go b/test/e2e/source_api_server_v1alpha2_test.go similarity index 95% rename from test/e2e/source_api_server_test.go rename to test/e2e/source_api_server_v1alpha2_test.go index 0c96f1f29a0..561a459a6d3 100644 --- a/test/e2e/source_api_server_test.go +++ b/test/e2e/source_api_server_v1alpha2_test.go @@ -41,7 +41,7 @@ import ( "knative.dev/eventing/test/lib/resources" ) -func TestApiServerSource(t *testing.T) { +func TestApiServerSourceV1Alpha2(t *testing.T) { const ( baseApiServerSourceName = "e2e-api-server-source" @@ -152,13 +152,13 @@ func TestApiServerSource(t *testing.T) { spec := tc.spec spec.Sink = duckv1.Destination{Ref: resources.ServiceKRef(recordEventPodName)} - apiServerSource := eventingtesting.NewApiServerSource( + apiServerSource := eventingtesting.NewApiServerSourceV1Alpha2( fmt.Sprintf("%s-%s", baseApiServerSourceName, tc.name), client.Namespace, - eventingtesting.WithApiServerSourceSpec(spec), + eventingtesting.WithApiServerSourceSpecV1A2(spec), ) - client.CreateApiServerSourceOrFail(apiServerSource) + client.CreateApiServerSourceV1Alpha2OrFail(apiServerSource) // wait for all test resources to be ready client.WaitForAllTestResourcesReadyOrFail() @@ -218,10 +218,10 @@ func TestApiServerSourceV1Alpha2EventTypes(t *testing.T) { client.WaitForResourceReadyOrFail(sugarresources.DefaultBrokerName, testlib.BrokerTypeMeta) // Create the api server source - apiServerSource := eventingtesting.NewApiServerSource( + apiServerSource := eventingtesting.NewApiServerSourceV1Alpha2( sourceName, client.Namespace, - eventingtesting.WithApiServerSourceSpec( + eventingtesting.WithApiServerSourceSpecV1A2( sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", @@ -234,7 +234,7 @@ func TestApiServerSourceV1Alpha2EventTypes(t *testing.T) { ) apiServerSource.Spec.Sink = duckv1.Destination{Ref: &duckv1.KReference{APIVersion: "eventing.knative.dev/v1beta1", Kind: "Broker", Name: sugarresources.DefaultBrokerName, Namespace: client.Namespace}} - client.CreateApiServerSourceOrFail(apiServerSource) + client.CreateApiServerSourceV1Alpha2OrFail(apiServerSource) // wait for all test resources to be ready client.WaitForAllTestResourcesReadyOrFail() diff --git a/test/e2e/source_api_server_v1beta1_test.go b/test/e2e/source_api_server_v1beta1_test.go new file mode 100644 index 00000000000..80c00635127 --- /dev/null +++ b/test/e2e/source_api_server_v1beta1_test.go @@ -0,0 +1,257 @@ +// +build e2e + +/* +Copyright 2020 The Knative Authors +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package e2e + +import ( + "fmt" + "testing" + "time" + + "knative.dev/eventing/pkg/reconciler/sugar" + + sugarresources "knative.dev/eventing/pkg/reconciler/sugar/resources" + + cetest "github.com/cloudevents/sdk-go/v2/test" + corev1 "k8s.io/api/core/v1" + rbacv1 "k8s.io/api/rbac/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/sets" + + duckv1 "knative.dev/pkg/apis/duck/v1" + + sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1" + eventingtesting "knative.dev/eventing/pkg/reconciler/testing" + testlib "knative.dev/eventing/test/lib" + "knative.dev/eventing/test/lib/recordevents" + "knative.dev/eventing/test/lib/resources" +) + +func TestApiServerSourceV1Beta1(t *testing.T) { + const ( + baseApiServerSourceName = "e2e-api-server-source" + + roleName = "event-watcher-r" + serviceAccountName = "event-watcher-sa" + baseHelloworldPodName = "e2e-api-server-source-helloworld-pod" + baseLoggerPodName = "e2e-api-server-source-logger-pod" + ) + + mode := "Reference" + table := []struct { + name string + spec sourcesv1beta1.ApiServerSourceSpec + pod func(name string) *corev1.Pod + expected string + }{ + { + name: "event-ref", + spec: sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ + APIVersion: "v1", + Kind: "Event", + }}, + EventMode: mode, + ServiceAccountName: serviceAccountName, + }, + pod: func(name string) *corev1.Pod { return resources.HelloWorldPod(name) }, + expected: "Event", + }, + { + name: "event-ref-unmatch-label", + spec: sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ + APIVersion: "v1", + Kind: "Pod", + LabelSelector: &metav1.LabelSelector{MatchLabels: map[string]string{"e2e": "testing"}}, + }}, + EventMode: mode, + ServiceAccountName: serviceAccountName, + }, + pod: func(name string) *corev1.Pod { return resources.HelloWorldPod(name) }, + }, + { + name: "event-ref-match-label", + spec: sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ + APIVersion: "v1", + Kind: "Pod", + LabelSelector: &metav1.LabelSelector{MatchLabels: map[string]string{"e2e": "testing"}}, + }}, + EventMode: mode, + ServiceAccountName: serviceAccountName, + }, + pod: func(name string) *corev1.Pod { + return resources.HelloWorldPod(name, resources.WithLabelsForPod(map[string]string{"e2e": "testing"})) + }, + expected: "Pod", + }, + { + name: "event-ref-match-label-expr", + spec: sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ + APIVersion: "v1", + Kind: "Pod", + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{"e2e": "testing"}, + MatchExpressions: []metav1.LabelSelectorRequirement{{Key: "e2e", Operator: "Exists"}}, + }, + }}, + EventMode: mode, + ServiceAccountName: serviceAccountName, + }, + pod: func(name string) *corev1.Pod { + return resources.HelloWorldPod(name, resources.WithLabelsForPod(map[string]string{"e2e": "testing"})) + }, + expected: "Pod", + }, + } + + for _, tc := range table { + tc := tc // capture range variable + t.Run(tc.name, func(t *testing.T) { + // Setup client + client := setup(t, true) + defer tearDown(client) + + // creates ServiceAccount and RoleBinding with a role for reading pods and events + r := resources.Role(roleName, + resources.WithRuleForRole(&rbacv1.PolicyRule{ + APIGroups: []string{""}, + Resources: []string{"events", "pods"}, + Verbs: []string{"get", "list", "watch"}})) + client.CreateServiceAccountOrFail(serviceAccountName) + client.CreateRoleOrFail(r) + client.CreateRoleBindingOrFail( + serviceAccountName, + testlib.RoleKind, + roleName, + fmt.Sprintf("%s-%s", serviceAccountName, roleName), + client.Namespace, + ) + + // create event record + recordEventPodName := fmt.Sprintf("%s-%s", baseLoggerPodName, tc.name) + eventTracker, _ := recordevents.StartEventRecordOrFail(client, recordEventPodName) + defer eventTracker.Cleanup() + + spec := tc.spec + spec.Sink = duckv1.Destination{Ref: resources.ServiceKRef(recordEventPodName)} + + apiServerSource := eventingtesting.NewApiServerSourceV1Beta1( + fmt.Sprintf("%s-%s", baseApiServerSourceName, tc.name), + client.Namespace, + eventingtesting.WithApiServerSourceSpecV1B1(spec), + ) + + client.CreateApiServerSourceV1Beta1OrFail(apiServerSource) + + // wait for all test resources to be ready + client.WaitForAllTestResourcesReadyOrFail() + + helloworldPod := tc.pod(fmt.Sprintf("%s-%s", baseHelloworldPodName, tc.name)) + client.CreatePodOrFail(helloworldPod) + + // verify the logger service receives the event(s) + // TODO(chizhg): right now it's only doing a very basic check by looking for the tc.data word, + // we can add a json matcher to improve it in the future. + + // Run asserts + if tc.expected == "" { + time.Sleep(10 * time.Second) + eventTracker.AssertNot(recordevents.Any()) + } else { + eventTracker.AssertAtLeast(1, recordevents.MatchEvent( + cetest.DataContains(tc.expected), + )) + } + }) + } +} + +func TestApiServerSourceV1Beta1EventTypes(t *testing.T) { + const ( + sourceName = "e2e-apiserver-source-eventtypes" + serviceAccountName = "event-watcher-sa" + roleName = "event-watcher-r" + ) + + client := setup(t, true) + defer tearDown(client) + + // creates ServiceAccount and RoleBinding with a role for reading pods and events + r := resources.Role(roleName, + resources.WithRuleForRole(&rbacv1.PolicyRule{ + APIGroups: []string{""}, + Resources: []string{"events", "pods"}, + Verbs: []string{"get", "list", "watch"}})) + client.CreateServiceAccountOrFail(serviceAccountName) + client.CreateRoleOrFail(r) + client.CreateRoleBindingOrFail( + serviceAccountName, + testlib.RoleKind, + roleName, + fmt.Sprintf("%s-%s", serviceAccountName, roleName), + client.Namespace, + ) + + // Label namespace so that it creates the default broker. + if err := client.LabelNamespace(map[string]string{sugar.InjectionLabelKey: sugar.InjectionEnabledLabelValue}); err != nil { + t.Fatalf("Error annotating namespace: %v", err) + } + + // Wait for default broker ready. + client.WaitForResourceReadyOrFail(sugarresources.DefaultBrokerName, testlib.BrokerTypeMeta) + + // Create the api server source + apiServerSource := eventingtesting.NewApiServerSourceV1Beta1( + sourceName, + client.Namespace, + eventingtesting.WithApiServerSourceSpecV1B1( + sourcesv1beta1.ApiServerSourceSpec{ + Resources: []sourcesv1beta1.APIVersionKindSelector{{ + APIVersion: "v1", + Kind: "Event", + }}, + EventMode: "Reference", + ServiceAccountName: serviceAccountName, + // TODO change sink to be a non-Broker one once we revisit EventType https://github.com/knative/eventing/issues/2750 + }), + ) + apiServerSource.Spec.Sink = duckv1.Destination{Ref: &duckv1.KReference{APIVersion: "eventing.knative.dev/v1beta1", Kind: "Broker", Name: sugarresources.DefaultBrokerName, Namespace: client.Namespace}} + + client.CreateApiServerSourceV1Beta1OrFail(apiServerSource) + + // wait for all test resources to be ready + client.WaitForAllTestResourcesReadyOrFail() + + // verify that EventTypes were created. + eventTypes, err := client.Eventing.EventingV1beta1().EventTypes(client.Namespace).List(metav1.ListOptions{}) + if err != nil { + t.Fatalf("Error retrieving EventTypes: %v", err) + } + if len(eventTypes.Items) != len(sourcesv1beta1.ApiServerSourceEventTypes) { + t.Fatalf("Invalid number of EventTypes registered for ApiServerSource: %s/%s, expected: %d, got: %d", client.Namespace, sourceName, len(sourcesv1beta1.ApiServerSourceEventTypes), len(eventTypes.Items)) + } + + expectedCeTypes := sets.NewString(sourcesv1beta1.ApiServerSourceEventTypes...) + for _, et := range eventTypes.Items { + if !expectedCeTypes.Has(et.Spec.Type) { + t.Fatalf("Invalid spec.type for ApiServerSource EventType, expected one of: %v, got: %s", sourcesv1beta1.ApiServerSourceEventTypes, et.Spec.Type) + } + } +} diff --git a/test/lib/creation.go b/test/lib/creation.go index 078192a34a0..7258d1e6d79 100644 --- a/test/lib/creation.go +++ b/test/lib/creation.go @@ -333,8 +333,8 @@ func (c *Client) CreateSinkBindingV1Beta1OrFail(sb *sourcesv1beta1.SinkBinding) c.Tracker.AddObj(sb) } -// CreateApiServerSourceOrFail will create an ApiServerSource -func (c *Client) CreateApiServerSourceOrFail(apiServerSource *sourcesv1alpha2.ApiServerSource) { +// CreateApiServerSourceV1Alpha2OrFail will create an v1alpha2 ApiServerSource +func (c *Client) CreateApiServerSourceV1Alpha2OrFail(apiServerSource *sourcesv1alpha2.ApiServerSource) { c.T.Logf("Creating apiserversource %+v", apiServerSource) apiServerInterface := c.Eventing.SourcesV1alpha2().ApiServerSources(c.Namespace) _, err := apiServerInterface.Create(apiServerSource) @@ -344,6 +344,17 @@ func (c *Client) CreateApiServerSourceOrFail(apiServerSource *sourcesv1alpha2.Ap c.Tracker.AddObj(apiServerSource) } +// CreateApiServerSourceV1Beta1OrFail will create an v1beta1 ApiServerSource +func (c *Client) CreateApiServerSourceV1Beta1OrFail(apiServerSource *sourcesv1beta1.ApiServerSource) { + c.T.Logf("Creating apiserversource %+v", apiServerSource) + apiServerInterface := c.Eventing.SourcesV1beta1().ApiServerSources(c.Namespace) + _, err := apiServerInterface.Create(apiServerSource) + if err != nil { + c.T.Fatalf("Failed to create apiserversource %q: %v", apiServerSource.Name, err) + } + c.Tracker.AddObj(apiServerSource) +} + // CreateContainerSourceV1Alpha2OrFail will create a ContainerSource. func (c *Client) CreateContainerSourceV1Alpha2OrFail(containerSource *sourcesv1alpha2.ContainerSource) { c.T.Logf("Creating containersource %+v", containerSource)