Skip to content

Commit

Permalink
Short term fix for #2676
Browse files Browse the repository at this point in the history
SelfLink is deprecated and is causing an error on Kubernetes v1.20
clusters as outlined in the issue. This is a short term fix that
would set the source field to a value that should match the current
source URI without the value of the auto-populated selfLink field.

Another field could be used for the source field without issue, but
could cause concerns about backwards compatibility.
  • Loading branch information
jmcshane authored and tekton-robot committed Feb 24, 2021
1 parent 0a08cdc commit 5354579
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit 5354579

Please sign in to comment.