Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"knative.dev/eventing/pkg/reconciler/parallel"
pingsource "knative.dev/eventing/pkg/reconciler/pingsource/controller"
"knative.dev/eventing/pkg/reconciler/sequence"
sourcecrd "knative.dev/eventing/pkg/reconciler/source/crd"
"knative.dev/eventing/pkg/reconciler/subscription"
"knative.dev/eventing/pkg/reconciler/trigger"
)
Expand All @@ -50,5 +51,7 @@ func main() {
// Sources
apiserversource.NewController,
pingsource.NewController,
// Sources CRD
sourcecrd.NewController,
)
}
1 change: 1 addition & 0 deletions config/core/resources/eventtype.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ spec:
- name: Description
type: string
JSONPath: ".spec.description"
# TODO remove Status https://github.com/knative/eventing/issues/2750
- name: Ready
type: string
JSONPath: ".status.conditions[?(@.type==\"Ready\")].status"
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/eventing/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const (
// ScopeCluster indicates the resource must be
// handled by the cluster-scoped component
ScopeCluster = "cluster"

// EventTypesAnnotationKey is the annotation key to specify
// if a Source has event types defines in its CRD.
EventTypesAnnotationKey = "registry.knative.dev/eventTypes"
Comment thread
nachocano marked this conversation as resolved.
)

var (
Expand Down
8 changes: 6 additions & 2 deletions pkg/apis/eventing/v1alpha1/eventtype_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type EventType struct {
// Status represents the current state of the EventType.
// This data may be out of date.
// +optional
// TODO might be removed https://github.com/knative/eventing/issues/2750
Status EventTypeStatus `json:"status,omitempty"`
}

Expand All @@ -61,13 +62,16 @@ type EventTypeSpec struct {
// Type represents the CloudEvents type. It is authoritative.
Type string `json:"type"`
// Source is a URI, it represents the CloudEvents source.
Source string `json:"source"`
// +optional
Source string `json:"source,omitempty"`
// Schema is a URI, it represents the CloudEvents schemaurl extension attribute.
// It may be a JSON schema, a protobuf schema, etc. It is optional.
// +optional
Schema string `json:"schema,omitempty"`
// TODO remove https://github.com/knative/eventing/issues/2750
// Broker refers to the Broker that can provide the EventType.
Broker string `json:"broker"`
// +optional
Broker string `json:"broker,omitempty"`
// Description is an optional field used to describe the EventType, in any meaningful way.
// +optional
Description string `json:"description,omitempty"`
Expand Down
16 changes: 2 additions & 14 deletions pkg/apis/eventing/v1alpha1/eventtype_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package v1alpha1
import (
"context"

"github.com/google/go-cmp/cmp/cmpopts"

"knative.dev/pkg/apis"
"knative.dev/pkg/kmp"
)
Expand All @@ -35,15 +33,6 @@ func (ets *EventTypeSpec) Validate(ctx context.Context) *apis.FieldError {
fe := apis.ErrMissingField("type")
errs = errs.Also(fe)
}
if ets.Source == "" {
// TODO validate is a valid URI.
fe := apis.ErrMissingField("source")
errs = errs.Also(fe)
}
if ets.Broker == "" {
fe := apis.ErrMissingField("broker")
errs = errs.Also(fe)
}
// TODO validate Schema is a valid URI.
return errs
}
Expand All @@ -53,9 +42,8 @@ func (et *EventType) CheckImmutableFields(ctx context.Context, original *EventTy
return nil
}

// All but Description field immutable.
ignoreArguments := cmpopts.IgnoreFields(EventTypeSpec{}, "Description")
if diff, err := kmp.ShortDiff(original.Spec, et.Spec, ignoreArguments); err != nil {
// All fields immutable
if diff, err := kmp.ShortDiff(original.Spec, et.Spec); err != nil {
return &apis.FieldError{
Message: "Failed to diff EventType",
Paths: []string{"spec"},
Expand Down
54 changes: 15 additions & 39 deletions pkg/apis/eventing/v1alpha1/eventtype_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ import (
)

func TestEventTypeValidation(t *testing.T) {
name := "invalid type and source and broker"
broker := &EventType{Spec: EventTypeSpec{}}
name := "invalid type"
et := &EventType{Spec: EventTypeSpec{}}

want := &apis.FieldError{
Paths: []string{"spec.type", "spec.source", "spec.broker"},
Paths: []string{"spec.type"},
Message: "missing field(s)",
}

t.Run(name, func(t *testing.T) {
got := broker.Validate(context.TODO())
got := et.Validate(context.TODO())
if diff := cmp.Diff(want.Error(), got.Error()); diff != "" {
t.Errorf("EventType.Validate (-want, +got) = %v", diff)
}
Expand All @@ -47,42 +47,12 @@ func TestEventTypeSpecValidation(t *testing.T) {
ets *EventTypeSpec
want *apis.FieldError
}{{
name: "invalid eventtype spec",
ets: &EventTypeSpec{},
want: func() *apis.FieldError {
fe := apis.ErrMissingField("type", "source", "broker")
return fe
}(),
}, {
name: "invalid eventtype type",
ets: &EventTypeSpec{
Source: "test-source",
Broker: "test-broker",
},
ets: &EventTypeSpec{},
want: func() *apis.FieldError {
fe := apis.ErrMissingField("type")
return fe
}(),
}, {
name: "invalid eventtype source",
ets: &EventTypeSpec{
Type: "test-type",
Broker: "test-broker",
},
want: func() *apis.FieldError {
fe := apis.ErrMissingField("source")
return fe
}(),
}, {
name: "invalid eventtype broker",
ets: &EventTypeSpec{
Type: "test-type",
Source: "test-source",
},
want: func() *apis.FieldError {
fe := apis.ErrMissingField("broker")
return fe
}(),
},
}

Expand Down Expand Up @@ -232,7 +202,7 @@ func TestEventTypeImmutableFields(t *testing.T) {
`,
},
}, {
name: "good (description change)",
name: "bad (description change)",
current: &EventType{
Spec: EventTypeSpec{
Type: "test-type",
Expand All @@ -251,9 +221,15 @@ func TestEventTypeImmutableFields(t *testing.T) {
Description: "original-description",
},
},
want: nil,
},
}
want: &apis.FieldError{
Message: "Immutable fields changed (-old +new)",
Paths: []string{"spec"},
Details: `{v1alpha1.EventTypeSpec}.Description:
-: "original-description"
+: "test-description"
`,
},
}}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/eventing/v1alpha1/trigger_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (ts *TriggerStatus) MarkDependencyUnknown(reason, messageFormat string, mes
}

func (ts *TriggerStatus) MarkDependencyNotConfigured() {
triggerCondSet.Manage(ts).MarkUnknown(EventTypeConditionBrokerReady,
triggerCondSet.Manage(ts).MarkUnknown(TriggerConditionDependency,
"DependencyNotConfigured", "Dependency has not yet been reconciled.")
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/eventing/v1beta1/eventtype_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func TestEventTypeDefaults(t *testing.T) {
initial: EventType{
Spec: EventTypeSpec{
Type: "test-type",
Source: *testSource,
Source: testSource,
Broker: "",
Schema: testSchema,
},
},
expected: EventType{
Spec: EventTypeSpec{
Type: "test-type",
Source: *testSource,
Source: testSource,
Broker: "default",
Schema: testSchema,
},
Expand All @@ -62,14 +62,14 @@ func TestEventTypeDefaults(t *testing.T) {
initial: EventType{
Spec: EventTypeSpec{
Type: "test-type",
Source: *testSource,
Source: testSource,
Schema: testSchema,
},
},
expected: EventType{
Spec: EventTypeSpec{
Type: "test-type",
Source: *testSource,
Source: testSource,
Broker: "default",
Schema: testSchema,
},
Expand Down
8 changes: 6 additions & 2 deletions pkg/apis/eventing/v1beta1/eventtype_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type EventType struct {
// Status represents the current state of the EventType.
// This data may be out of date.
// +optional
// TODO might be removed https://github.com/knative/eventing/issues/2750
Status EventTypeStatus `json:"status,omitempty"`
}

Expand All @@ -60,7 +61,8 @@ type EventTypeSpec struct {
// Type represents the CloudEvents type. It is authoritative.
Type string `json:"type"`
// Source is a URI, it represents the CloudEvents source.
Source apis.URL `json:"source"`
// +optional
Source *apis.URL `json:"source,omitempty"`
// Schema is a URI, it represents the CloudEvents schemaurl extension attribute.
// It may be a JSON schema, a protobuf schema, etc. It is optional.
// +optional
Expand All @@ -70,8 +72,10 @@ type EventTypeSpec struct {
// The contents are not validated or manipulated by the system.
// +optional
SchemaData string `json:"schemaData,omitempty"`
// TODO remove https://github.com/knative/eventing/issues/2750
// Broker refers to the Broker that can provide the EventType.
Broker string `json:"broker"`
// +optional
Broker string `json:"broker,omitempty"`
// Description is an optional field used to describe the EventType, in any meaningful way.
// +optional
Description string `json:"description,omitempty"`
Expand Down
17 changes: 3 additions & 14 deletions pkg/apis/eventing/v1beta1/eventtype_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package v1beta1
import (
"context"

"github.com/google/go-cmp/cmp/cmpopts"

"knative.dev/pkg/apis"
"knative.dev/pkg/kmp"
)
Expand All @@ -35,15 +33,7 @@ func (ets *EventTypeSpec) Validate(ctx context.Context) *apis.FieldError {
fe := apis.ErrMissingField("type")
errs = errs.Also(fe)
}
if ets.Source.IsEmpty() {
// TODO validate is a valid URI.
fe := apis.ErrMissingField("source")
errs = errs.Also(fe)
}
if ets.Broker == "" {
fe := apis.ErrMissingField("broker")
errs = errs.Also(fe)
}
// TODO validate Source is a valid URI.
// TODO validate Schema is a valid URI.
// There is no validation of the SchemaData, it is application specific data.
return errs
Expand All @@ -54,9 +44,8 @@ func (et *EventType) CheckImmutableFields(ctx context.Context, original *EventTy
return nil
}

// All but Description field immutable.
ignoreArguments := cmpopts.IgnoreFields(EventTypeSpec{}, "Description")
if diff, err := kmp.ShortDiff(original.Spec, et.Spec, ignoreArguments); err != nil {
// All fields are immutable.
if diff, err := kmp.ShortDiff(original.Spec, et.Spec); err != nil {
return &apis.FieldError{
Message: "Failed to diff EventType",
Paths: []string{"spec"},
Expand Down
Loading