diff --git a/runtime/kubernetes/build.go b/runtime/kubernetes/build.go index 0bd75402..86be2246 100644 --- a/runtime/kubernetes/build.go +++ b/runtime/kubernetes/build.go @@ -194,7 +194,7 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error { } // Populate the PodTracker caches before creating the pipeline pod - c.PodTracker.Start(ctx.Done()) + c.PodTracker.Start(ctx) if ok := cache.WaitForCacheSync(ctx.Done(), c.PodTracker.PodSynced); !ok { return fmt.Errorf("failed to wait for caches to sync") diff --git a/runtime/kubernetes/container_test.go b/runtime/kubernetes/container_test.go index 105a4d93..9ed4556d 100644 --- a/runtime/kubernetes/container_test.go +++ b/runtime/kubernetes/container_test.go @@ -398,7 +398,7 @@ func TestKubernetes_WaitContainer(t *testing.T) { // run tests for _, test := range tests { - // anonymous function to allow "defer close(stopCh)" on each iteration + // anonymous function to allow "defer done()" on each iteration func() { // set up the fake k8s clientset so that it returns the final/updated state _engine, err := NewMock(test.updated) @@ -406,11 +406,11 @@ func TestKubernetes_WaitContainer(t *testing.T) { t.Errorf("unable to create runtime engine: %v", err) } - stopCh := make(chan struct{}) - defer close(stopCh) + ctx, done := context.WithCancel(context.Background()) + defer done() // enable the add/update/delete funcs for pod changes - _engine.PodTracker.Start(stopCh) + _engine.PodTracker.Start(ctx) go func() { // revert the cached pod to an "older" version diff --git a/runtime/kubernetes/pod_tracker.go b/runtime/kubernetes/pod_tracker.go index df708469..1eee100d 100644 --- a/runtime/kubernetes/pod_tracker.go +++ b/runtime/kubernetes/pod_tracker.go @@ -5,6 +5,7 @@ package kubernetes import ( + "context" "fmt" "sync" "time" @@ -133,11 +134,11 @@ func (p podTracker) getTrackedPod(obj interface{}) *v1.Pod { // Start kicks off the API calls to start populating the cache. // There is no need to run this in a separate goroutine (ie go podTracker.Start(stopCh)). -func (p podTracker) Start(stopCh <-chan struct{}) { +func (p podTracker) Start(ctx context.Context) { p.Logger.Tracef("starting PodTracker for pod %s", p.TrackedPod) // Start method is non-blocking and runs all registered informers in a dedicated goroutine. - p.informerFactory.Start(stopCh) + p.informerFactory.Start(ctx.Done()) } // newPodTracker initializes a podTracker with a given clientset for a given pod.