Skip to content

Commit b203edc

Browse files
committed
refactor(k8s): podTracker.Start takes a ctx
1 parent 7c4f885 commit b203edc

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

runtime/kubernetes/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error {
194194
}
195195

196196
// Populate the PodTracker caches before creating the pipeline pod
197-
c.PodTracker.Start(ctx.Done())
197+
c.PodTracker.Start(ctx)
198198

199199
if ok := cache.WaitForCacheSync(ctx.Done(), c.PodTracker.PodSynced); !ok {
200200
return fmt.Errorf("failed to wait for caches to sync")

runtime/kubernetes/container_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,19 +398,19 @@ func TestKubernetes_WaitContainer(t *testing.T) {
398398

399399
// run tests
400400
for _, test := range tests {
401-
// anonymous function to allow "defer close(stopCh)" on each iteration
401+
// anonymous function to allow "defer done()" on each iteration
402402
func() {
403403
// set up the fake k8s clientset so that it returns the final/updated state
404404
_engine, err := NewMock(test.updated)
405405
if err != nil {
406406
t.Errorf("unable to create runtime engine: %v", err)
407407
}
408408

409-
stopCh := make(chan struct{})
410-
defer close(stopCh)
409+
ctx, done := context.WithCancel(context.Background())
410+
defer done()
411411

412412
// enable the add/update/delete funcs for pod changes
413-
_engine.PodTracker.Start(stopCh)
413+
_engine.PodTracker.Start(ctx)
414414

415415
go func() {
416416
// revert the cached pod to an "older" version

runtime/kubernetes/pod_tracker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ func (p podTracker) getTrackedPod(obj interface{}) *v1.Pod {
133133

134134
// Start kicks off the API calls to start populating the cache.
135135
// There is no need to run this in a separate goroutine (ie go podTracker.Start(stopCh)).
136-
func (p podTracker) Start(stopCh <-chan struct{}) {
136+
func (p podTracker) Start(ctx context.Context) {
137137
p.Logger.Tracef("starting PodTracker for pod %s", p.TrackedPod)
138138

139139
// Start method is non-blocking and runs all registered informers in a dedicated goroutine.
140-
p.informerFactory.Start(stopCh)
140+
p.informerFactory.Start(ctx.Done())
141141
}
142142

143143
// newPodTracker initializes a podTracker with a given clientset for a given pod.

0 commit comments

Comments
 (0)