Skip to content

Commit

Permalink
Ensure that init containers are no longer tailed after they stop (ela…
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel authored and Pablo Mercado committed Nov 12, 2019
1 parent d84d85d commit aaca48b
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
Expand Up @@ -321,6 +321,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
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
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 aaca48b

Please sign in to comment.