Skip to content

Commit

Permalink
Close the podWatch in WaitContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Mar 14, 2022
1 parent 73fdd29 commit 5d72207
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions runtime/kubernetes/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ func (c *client) WaitContainer(ctx context.Context, ctn *pipeline.Container) err
return err
}

defer podWatch.Stop()

for {
// capture new result from the channel
//
Expand Down
14 changes: 7 additions & 7 deletions runtime/kubernetes/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@ func TestKubernetes_TailContainer(t *testing.T) {
}

func TestKubernetes_WaitContainer(t *testing.T) {
// setup types
_engine, _watch, err := newMockWithWatch(_pod, "pods")
if err != nil {
t.Errorf("unable to create runtime engine: %v", err)
}

// setup tests
tests := []struct {
failure bool
Expand Down Expand Up @@ -288,12 +282,18 @@ func TestKubernetes_WaitContainer(t *testing.T) {

// run tests
for _, test := range tests {
// setup types
_engine, _watch, err := newMockWithWatch(_pod, "pods")
if err != nil {
t.Errorf("unable to create runtime engine: %v", err)
}

go func() {
// simulate adding a pod to the watcher
_watch.Add(test.object)
}()

err := _engine.WaitContainer(context.Background(), test.container)
err = _engine.WaitContainer(context.Background(), test.container)

if test.failure {
if err == nil {
Expand Down

0 comments on commit 5d72207

Please sign in to comment.