Skip to content

Commit

Permalink
Ensure that init containers are no longer tailed after they stop (#14394
Browse files Browse the repository at this point in the history
) (#14477)

(cherry picked from commit aaca48b)
  • Loading branch information
Pablo Mercado authored Nov 12, 2019
1 parent 58680e7 commit 63bd05a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- GA the `script` processor. {pull}14325[14325]
- Add `fingerprint` processor. {issue}11173[11173] {pull}14205[14205]
- Add support for API keys in Elasticsearch outputs. {pull}14324[14324]
- Ensure that init containers are no longer tailed after they stop {pull}14394[14394]

*Auditbeat*

Expand Down
11 changes: 8 additions & 3 deletions libbeat/autodiscover/providers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,14 @@ func (p *Provider) emitEvents(pod *kubernetes.Pod, flag string, containers []kub
containerIDs := map[string]string{}
runtimes := map[string]string{}
for _, c := range containerstatuses {
cid, runtime := kubernetes.ContainerIDWithRuntime(c)
containerIDs[c.Name] = cid
runtimes[c.Name] = runtime
// If the container is not being stopped then add the container only if it is in running state.
// This makes sure that we dont keep tailing init container logs after they have stopped.
// Emit the event in case that the pod is being stopped.
if flag == "stop" || c.State.Running != nil {
cid, runtime := kubernetes.ContainerIDWithRuntime(c)
containerIDs[c.Name] = cid
runtimes[c.Name] = runtime
}
}

// Emit container and port information
Expand Down
3 changes: 3 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ func TestEmitEvent(t *testing.T) {
{
Name: name,
ContainerID: containerID,
State: v1.ContainerState{
Running: &v1.ContainerStateRunning{},
},
},
},
},
Expand Down

0 comments on commit 63bd05a

Please sign in to comment.