-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix stopping of modules started by kubernetes autodiscover #10476
Merged
jsoriano
merged 11 commits into
elastic:master
from
jsoriano:kubernetes-autodiscover-terminating
Feb 7, 2019
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5a6ce23
Fix stop of kubernetes autodiscovered modules
jsoriano 4e25ed8
Use an id for containers that don't depend on its state
jsoriano 39c9898
Use a better id
jsoriano 3cfff44
Revert uneeded change
jsoriano bf9317f
Fix changelog
jsoriano 972ceeb
Fix
jsoriano 1d79f50
Keep skipping containers on start if they don't exist, and extend com…
jsoriano a8a3305
Merge remote-tracking branch 'origin/master' into kubernetes-autodisc…
jsoriano 38ba23c
Maintain container.id value as before, and fix test
jsoriano d0d575a
Make hound happy
jsoriano 604d2bd
Add test cases for stop
jsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
package kubernetes | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/gofrs/uuid" | ||
|
@@ -144,12 +145,16 @@ func (p *Provider) emitEvents(pod *kubernetes.Pod, flag string, containers []*ku | |
containerstatuses []*kubernetes.PodContainerStatus) { | ||
host := pod.Status.GetPodIP() | ||
|
||
// Do not emit events without host (container is still being configured) | ||
if host == "" { | ||
// If the container doesn't exist in the runtime or its network | ||
// is not configured, it won't have an IP. Skip it as we cannot | ||
// generate configs without host, and an update will arrive when | ||
// the container is ready. | ||
// If stopping, emit the event in any case to ensure cleanup. | ||
if host == "" && flag != "stop" { | ||
return | ||
} | ||
|
||
// Collect all container IDs and runtimes from status information. | ||
// Collect all runtimes from status information. | ||
containerIDs := map[string]string{} | ||
runtimes := map[string]string{} | ||
for _, c := range containerstatuses { | ||
|
@@ -160,13 +165,18 @@ func (p *Provider) emitEvents(pod *kubernetes.Pod, flag string, containers []*ku | |
|
||
// Emit container and port information | ||
for _, c := range containers { | ||
// If it doesn't have an ID, container doesn't exist in | ||
// the runtime, emit only an event if we are stopping, so | ||
// we are sure of cleaning up configurations. | ||
cid := containerIDs[c.GetName()] | ||
|
||
// If there is a container ID that is empty then ignore it. It either means that the container is still starting | ||
// up or the container is shutting down. | ||
if cid == "" { | ||
if cid == "" && flag != "stop" { | ||
continue | ||
} | ||
|
||
// This must be an id that doesn't depend on the state of the container | ||
// so it works also on `stop` if containers have been already deleted. | ||
eventId := fmt.Sprintf("%s.%s", pod.Metadata.GetUid(), c.GetName()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. var eventId should be eventID |
||
|
||
cmeta := common.MapStr{ | ||
"id": cid, | ||
"name": c.GetName(), | ||
|
@@ -190,7 +200,7 @@ func (p *Provider) emitEvents(pod *kubernetes.Pod, flag string, containers []*ku | |
if len(c.Ports) == 0 { | ||
event := bus.Event{ | ||
"provider": p.uuid, | ||
"id": cid, | ||
"id": eventId, | ||
flag: true, | ||
"host": host, | ||
"kubernetes": kubemeta, | ||
|
@@ -204,7 +214,7 @@ func (p *Provider) emitEvents(pod *kubernetes.Pod, flag string, containers []*ku | |
for _, port := range c.Ports { | ||
event := bus.Event{ | ||
"provider": p.uuid, | ||
"id": cid, | ||
"id": eventId, | ||
flag: true, | ||
"host": host, | ||
"port": port.GetContainerPort(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about the case where the container is still starting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that just checking for the ID doesn't ensure that the container is ready, so it wouldn't matter so much. But the truth is that there is no need to change this here. I will keep the check for non-stop events.
Thanks for taking the time to review this!