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

Short term fix for Cloud Event Source #3761

Merged
merged 1 commit into from
Feb 24, 2021
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
13 changes: 12 additions & 1 deletion pkg/reconciler/events/cloudevent/cloudevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,18 @@ func EventForObjectWithCondition(runObject objectWithCondition) (*cloudevents.Ev
event := cloudevents.NewEvent()
event.SetID(uuid.New().String())
event.SetSubject(runObject.GetObjectMeta().GetName())
event.SetSource(runObject.GetObjectMeta().GetSelfLink()) // TODO: SelfLink is deprecated https://github.com/tektoncd/pipeline/issues/2676
// TODO: SelfLink is deprecated https://github.com/tektoncd/pipeline/issues/2676
source := runObject.GetObjectMeta().GetSelfLink()
if source == "" {
gvk := runObject.GetObjectKind().GroupVersionKind()
source = fmt.Sprintf("/apis/%s/%s/namespaces/%s/%s/%s",
gvk.Group,
gvk.Version,
runObject.GetObjectMeta().GetNamespace(),
gvk.Kind,
runObject.GetObjectMeta().GetName())
}
event.SetSource(source)
eventType, err := getEventType(runObject)
if err != nil {
return nil, err
Expand Down
9 changes: 9 additions & 0 deletions pkg/reconciler/events/cloudevent/cloudevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ func TestEventForTaskRun(t *testing.T) {
desc: "send a cloud event with successful status taskrun",
taskRun: getTaskRunByCondition(corev1.ConditionTrue, "yay"),
wantEventType: TaskRunSuccessfulEventV1,
}, {
desc: "send a cloud event with successful status taskrun, empty selflink",
taskRun: func() *v1beta1.TaskRun {
tr := getTaskRunByCondition(corev1.ConditionTrue, "yay")
// v1.20 does not set selfLink in controller
tr.ObjectMeta.SelfLink = ""
return tr
}(),
wantEventType: TaskRunSuccessfulEventV1,
}}

for _, c := range taskRunTests {
Expand Down