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

Fix tkn p start --showlog by handling informer ResourceEventHandler #2048

Merged
merged 1 commit into from
Jun 8, 2023
Merged
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
39 changes: 34 additions & 5 deletions pkg/pipelinerun/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package pipelinerun

import (
"context"
"sync"
"time"

"github.com/tektoncd/cli/pkg/actions"
Expand Down Expand Up @@ -67,10 +68,9 @@ func (t *Tracker) Monitor(allowed []string) <-chan []taskrunpkg.Run {

genericInformer, _ := factory.ForResource(*gvr)
informer := genericInformer.Informer()

mu := &sync.Mutex{}
stopC := make(chan struct{})
trC := make(chan []taskrunpkg.Run)

go func() {
<-stopC
close(trC)
Expand All @@ -97,7 +97,6 @@ func (t *Tracker) Monitor(allowed []string) <-chan []taskrunpkg.Run {
return
}
pr.DeepCopyInto(&pipelinerunConverted)

trC <- t.findNewTaskruns(&pipelinerunConverted, allowed, trsMap)

if hasCompleted(&pipelinerunConverted) {
Expand All @@ -107,8 +106,38 @@ func (t *Tracker) Monitor(allowed []string) <-chan []taskrunpkg.Run {

informer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: eventHandler,
UpdateFunc: func(_, newObj interface{}) { eventHandler(newObj) },
AddFunc: func(obj interface{}) {
// To ensure synchonization and checks is the stopC channel has received a signal to stop
// If it receives a signal then return and does nothing
mu.Lock()
defer mu.Unlock()
select {
case <-stopC:
return
default:
eventHandler(obj)
}
},
UpdateFunc: func(_, newObj interface{}) {
mu.Lock()
defer mu.Unlock()
select {
case <-stopC:
return
default:
eventHandler(newObj)
}
},
DeleteFunc: func(obj interface{}) {
mu.Lock()
defer mu.Unlock()
select {
case <-stopC:
return
default:
eventHandler(obj)
}
},
},
)

Expand Down