Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apiseversource reconciler and e2e for v1beta1 #3627

Merged
4 changes: 3 additions & 1 deletion cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ var ourTypes = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
sourcesv1alpha2.SchemeGroupVersion.WithKind("SinkBinding"): &sourcesv1alpha2.SinkBinding{},
sourcesv1alpha2.SchemeGroupVersion.WithKind("ContainerSource"): &sourcesv1alpha2.ContainerSource{},
// v1beta1
sourcesv1beta1.SchemeGroupVersion.WithKind("ApiServerSource"): &sourcesv1beta1.ApiServerSource{},
sourcesv1beta1.SchemeGroupVersion.WithKind("SinkBinding"): &sourcesv1beta1.SinkBinding{},
sourcesv1beta1.SchemeGroupVersion.WithKind("ContainerSource"): &sourcesv1beta1.ContainerSource{},

Expand Down Expand Up @@ -310,12 +311,13 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro
},

// Sources
sourcesv1alpha2.Kind("ApiServerSource"): {
sourcesv1beta1.Kind("ApiServerSource"): {
DefinitionName: sources.ApiServerSourceResource.String(),
HubVersion: sourcesv1alpha1_,
Zygotes: map[string]conversion.ConvertibleObject{
sourcesv1alpha1_: &sourcesv1alpha1.ApiServerSource{},
sourcesv1alpha2_: &sourcesv1alpha2.ApiServerSource{},
sourcesv1beta1_: &sourcesv1beta1.ApiServerSource{},
},
},
sourcesv1alpha2.Kind("PingSource"): {
Expand Down
12 changes: 8 additions & 4 deletions config/core/resources/apiserversource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ spec:
name: v1alpha2
served: true
storage: false
- <<: *version
name: v1beta1
served: true
storage: false
names:
categories:
- all
- knative
- eventing
- sources
- all
- knative
- eventing
- sources
kind: ApiServerSource
plural: apiserversources
scope: Namespaced
Expand Down
4 changes: 2 additions & 2 deletions pkg/adapter/apiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions pkg/adapter/apiserver/delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
nachocano marked this conversation as resolved.
Show resolved Hide resolved
}

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.
Expand Down
14 changes: 7 additions & 7 deletions pkg/adapter/apiserver/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions pkg/adapter/apiserver/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/adapter/apiserver/ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions pkg/apis/sources/v1alpha1/apiserver_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha1

import (
"context"
"fmt"
"reflect"

"github.com/google/go-cmp/cmp"
Expand All @@ -32,7 +31,7 @@ import (
)

// ConvertTo implements apis.Convertible.
// Converts source (from v1alpha1.ApiServerSource) into v1alpha2.ApiServerSource
// Converts source (from v1alpha1.ApiServerSource) into into a higher version.
func (source *ApiServerSource) ConvertTo(ctx context.Context, obj apis.Convertible) error {
switch sink := obj.(type) {
case *v1alpha2.ApiServerSource:
Expand Down Expand Up @@ -95,12 +94,12 @@ func (source *ApiServerSource) ConvertTo(ctx context.Context, obj apis.Convertib
source.Status.SourceStatus.DeepCopyInto(&sink.Status.SourceStatus)
return nil
default:
return fmt.Errorf("Unknown conversion, got: %T", sink)
return apis.ConvertToViaProxy(ctx, source, &v1alpha2.ApiServerSource{}, sink)
}
}

// ConvertFrom implements apis.Convertible.
// Converts obj from v1alpha2.ApiServerSource into v1alpha1.ApiServerSource
// Converts obj from a higher version into v1alpha1.ApiServerSource.
func (sink *ApiServerSource) ConvertFrom(ctx context.Context, obj apis.Convertible) error {
switch source := obj.(type) {
case *v1alpha2.ApiServerSource:
Expand Down Expand Up @@ -158,6 +157,6 @@ func (sink *ApiServerSource) ConvertFrom(ctx context.Context, obj apis.Convertib

return nil
default:
return fmt.Errorf("Unknown conversion, got: %T", source)
return apis.ConvertFromViaProxy(ctx, source, &v1alpha2.ApiServerSource{}, sink)
}
}
Loading