Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #14394 to 7.5: Ensure that init containers are no longer tailed after they stop #14476

Merged
merged 2 commits into from Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Expand Up @@ -83,6 +83,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Affecting all Beats*

- 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 @@ -198,9 +198,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 @@ -192,6 +192,9 @@ func TestEmitEvent(t *testing.T) {
{
Name: name,
ContainerID: containerID,
State: v1.ContainerState{
Running: &v1.ContainerStateRunning{},
},
},
},
},
Expand Down