Skip to content
Closed
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
2 changes: 1 addition & 1 deletion pkg/adapter/apiserver/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func makeEvent(source, eventType string, obj *unstructured.Unstructured, data in
Namespace: obj.GetNamespace(),
})

event := cloudevents.NewEvent(cloudevents.VersionV03)
event := cloudevents.NewEvent(cloudevents.VersionV1)
event.SetType(eventType)
event.SetSource(source)
event.SetSubject(subject)
Expand Down
18 changes: 9 additions & 9 deletions pkg/adapter/apiserver/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestMakeAddEvent(t *testing.T) {
Extensions: map[string]interface{}{
"subject": "/apis/v1/namespaces/test/pods/unit",
},
}.AsV03(),
}.AsV1(),
},
wantData: `{"apiVersion":"v1","kind":"Pod","metadata":{"name":"unit","namespace":"test"}}`,
},
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestMakeUpdateEvent(t *testing.T) {
Extensions: map[string]interface{}{
"subject": "/apis/v1/namespaces/test/pods/unit",
},
}.AsV03(),
}.AsV1(),
},
wantData: `{"apiVersion":"v1","kind":"Pod","metadata":{"name":"unit","namespace":"test"}}`,
},
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestMakeDeleteEvent(t *testing.T) {
Extensions: map[string]interface{}{
"subject": "/apis/v1/namespaces/test/pods/unit",
},
}.AsV03(),
}.AsV1(),
},
wantData: `{"apiVersion":"v1","kind":"Pod","metadata":{"name":"unit","namespace":"test"}}`,
},
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestMakeAddRefEvent(t *testing.T) {
Extensions: map[string]interface{}{
"subject": "/apis/v1/namespaces/test/pods/unit",
},
}.AsV03(),
}.AsV1(),
},
wantData: `{"kind":"Pod","namespace":"test","name":"unit","apiVersion":"v1"}`,
},
Expand All @@ -222,7 +222,7 @@ func TestMakeAddRefEvent(t *testing.T) {
Extensions: map[string]interface{}{
"subject": "/apis/v1/namespaces/test/pods/owned",
},
}.AsV03(),
}.AsV1(),
},
wantData: `{"kind":"ReplicaSet","namespace":"test","name":"unit","apiVersion":"apps/v1"}`,
},
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestMakeUpdateRefEvent(t *testing.T) {
Extensions: map[string]interface{}{
"subject": "/apis/v1/namespaces/test/pods/unit",
},
}.AsV03(),
}.AsV1(),
},
wantData: `{"kind":"Pod","namespace":"test","name":"unit","apiVersion":"v1"}`,
},
Expand All @@ -277,7 +277,7 @@ func TestMakeUpdateRefEvent(t *testing.T) {
Extensions: map[string]interface{}{
"subject": "/apis/v1/namespaces/test/pods/owned",
},
}.AsV03(),
}.AsV1(),
},
wantData: `{"kind":"ReplicaSet","namespace":"test","name":"unit","apiVersion":"apps/v1"}`,
},
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestMakeDeleteRefEvent(t *testing.T) {
Extensions: map[string]interface{}{
"subject": "/apis/v1/namespaces/test/pods/unit",
},
}.AsV03(),
}.AsV1(),
},
wantData: `{"kind":"Pod","namespace":"test","name":"unit","apiVersion":"v1"}`,
},
Expand All @@ -332,7 +332,7 @@ func TestMakeDeleteRefEvent(t *testing.T) {
Extensions: map[string]interface{}{
"subject": "/apis/v1/namespaces/test/pods/owned",
},
}.AsV03(),
}.AsV1(),
},
wantData: `{"kind":"ReplicaSet","namespace":"test","name":"unit","apiVersion":"apps/v1"}`,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/adapter/cronjobevents/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (a *cronJobAdapter) Start(stopCh <-chan struct{}) error {
func (a *cronJobAdapter) cronTick() {
logger := logging.FromContext(context.TODO())

event := cloudevents.NewEvent(cloudevents.VersionV03)
event := cloudevents.NewEvent(cloudevents.VersionV1)
event.SetType(sourcesv1alpha1.CronJobEventType)
event.SetSource(sourcesv1alpha1.CronJobEventSource(a.Namespace, a.Name))
event.SetData(message(a.Data))
Expand Down
6 changes: 3 additions & 3 deletions pkg/broker/filter/filter_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp *
}

// Remove the TTL attribute that is used by the Broker.
originalV3 := event.Context.AsV03()
originalV1 := event.Context.AsV1()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this file as this has been now fixed correctly.
/hold

ttl, ttlKey := broker.GetTTL(event.Context)
if ttl == nil {
// Only messages sent by the Broker should be here. If the attribute isn't here, then the
Expand All @@ -182,8 +182,8 @@ func (r *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp *
// framework returns a 500 to the caller, so the Channel would send this repeatedly.
return nil
}
delete(originalV3.Extensions, ttlKey)
event.Context = originalV3
delete(originalV1.Extensions, ttlKey)
event.Context = originalV1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there are reason why we bump all events to V1? Can't broker/trigger be just pass through?


r.logger.Debug("Received message", zap.Any("triggerRef", triggerRef))

Expand Down
12 changes: 6 additions & 6 deletions pkg/broker/filter/filter_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func TestReceiver(t *testing.T) {

// The TTL will be added again.
expectedResponseEvent := addTTLToEvent(*tc.returnedEvent)
if diff := cmp.Diff(expectedResponseEvent.Context.AsV03(), resp.Event.Context.AsV03()); diff != "" {
if diff := cmp.Diff(expectedResponseEvent.Context.AsV1(), resp.Event.Context.AsV1()); diff != "" {
t.Errorf("Incorrect response event context (-want +got): %s", diff)
}
if diff := cmp.Diff(expectedResponseEvent.Data, resp.Event.Data); diff != "" {
Expand Down Expand Up @@ -422,7 +422,7 @@ func (h *fakeHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
h.requestReceived = true

for n, v := range h.headers {
if strings.Contains(strings.ToLower(n), strings.ToLower(broker.V03TTLAttribute)) {
if strings.Contains(strings.ToLower(n), strings.ToLower(broker.V1TTLAttribute)) {
h.t.Errorf("Broker TTL should not be seen by the subscriber: %s", n)
}
if diff := cmp.Diff(v, req.Header[n]); diff != "" {
Expand All @@ -439,7 +439,7 @@ func (h *fakeHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
return
}

c := &cehttp.CodecV03{}
c := &cehttp.CodecV1{}
m, err := c.Encode(context.Background(), *h.returnedEvent)
if err != nil {
h.t.Fatalf("Could not encode message: %v", err)
Expand Down Expand Up @@ -555,7 +555,7 @@ func makeEventWithoutTTL() *cloudevents.Event {
},
},
ContentType: cloudevents.StringOfApplicationJSON(),
}.AsV03(),
}.AsV1(),
}
}

Expand All @@ -580,7 +580,7 @@ func makeDifferentEvent() *cloudevents.Event {
},
},
ContentType: cloudevents.StringOfApplicationJSON(),
}.AsV03(),
}.AsV1(),
}
}

Expand All @@ -597,7 +597,7 @@ func makeEventWithExtension(extName, extValue string) *cloudevents.Event {
Extensions: map[string]interface{}{
extName: extValue,
},
}.AsV03(),
}.AsV1(),
}
e := addTTLToEvent(*noTTL)
return &e
Expand Down
4 changes: 2 additions & 2 deletions pkg/broker/ingress/ingress_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestIngressHandler_ServeHTTP_FAIL(t *testing.T) {
Namespace: namespace,
Reporter: reporter,
}
event := cloudevents.NewEvent()
event := cloudevents.NewEvent(cloudevents.VersionV1)
resp := new(cloudevents.EventResponse)
tctx := http.TransportContext{Header: nethttp.Header{}, Method: tc.httpmethod, URI: tc.URI}
ctx := http.WithTransportContext(context.Background(), tctx)
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestIngressHandler_ServeHTTP_Succeed(t *testing.T) {
Namespace: namespace,
Reporter: reporter,
}
event := cloudevents.NewEvent()
event := cloudevents.NewEvent(cloudevents.VersionV1)
resp := new(cloudevents.EventResponse)
tctx := http.TransportContext{Header: nethttp.Header{}, Method: validHTTPMethod, URI: validURI}
ctx := http.WithTransportContext(context.Background(), tctx)
Expand Down
12 changes: 6 additions & 6 deletions pkg/broker/ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ import (
)

const (
// V03TTLAttribute is the name of the CloudEvents 0.3 extension attribute used to store the
// V1TTLAttribute is the name of the CloudEvents 1.0 extension attribute used to store the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this file too. This has been now fixed correctly. refer to #2244

// Broker's TTL (number of times a single event can reply through a Broker continuously). All
// interactions with the attribute should be done through the GetTTL and SetTTL functions.
V03TTLAttribute = "knativebrokerttl"
V1TTLAttribute = "knativebrokerttl"
)

// GetTTL finds the TTL in the EventContext using a case insensitive comparison
// for the key. The second return param, is the case preserved key that matched.
// Depending on the encoding/transport, the extension case could be changed.
func GetTTL(ctx cloudevents.EventContext) (interface{}, string) {
for k, v := range ctx.AsV03().Extensions {
if lower := strings.ToLower(k); lower == V03TTLAttribute {
for k, v := range ctx.AsV1().Extensions {
if lower := strings.ToLower(k); lower == V1TTLAttribute {
return v, k
}
}
return nil, V03TTLAttribute
return nil, V1TTLAttribute
}

// SetTTL sets the TTL into the EventContext. ttl should be a positive integer.
func SetTTL(ctx cloudevents.EventContext, ttl interface{}) (cloudevents.EventContext, error) {
err := ctx.SetExtension(V03TTLAttribute, ttl)
err := ctx.SetExtension(V1TTLAttribute, ttl)
return ctx, err
}
Loading