-
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
Changes from 6 commits
5a6ce23
4e25ed8
39c9898
3cfff44
bf9317f
972ceeb
1d79f50
a8a3305
38ba23c
d0d575a
604d2bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
package kubernetes | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/gofrs/uuid" | ||
|
@@ -145,28 +146,23 @@ func (p *Provider) emitEvents(pod *kubernetes.Pod, flag string, containers []*ku | |
host := pod.Status.GetPodIP() | ||
|
||
// Do not emit events without host (container is still being configured) | ||
if host == "" { | ||
if host == "" && flag != "stop" { | ||
return | ||
} | ||
|
||
// Collect all container IDs and runtimes from status information. | ||
containerIDs := map[string]string{} | ||
// Collect all runtimes from status information. | ||
runtimes := map[string]string{} | ||
for _, c := range containerstatuses { | ||
cid, runtime := kubernetes.ContainerIDWithRuntime(c) | ||
containerIDs[c.GetName()] = cid | ||
_, runtime := kubernetes.ContainerIDWithRuntime(c) | ||
runtimes[c.GetName()] = runtime | ||
} | ||
|
||
// Emit container and port information | ||
for _, c := range containers { | ||
cid := containerIDs[c.GetName()] | ||
// 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 stopped. | ||
cid := fmt.Sprintf("%s.%s", pod.Metadata.GetUid(), 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 == "" { | ||
continue | ||
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. what about the case where the container is still starting? 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. 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! |
||
} | ||
cmeta := common.MapStr{ | ||
"id": cid, | ||
"name": c.GetName(), | ||
|
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.
Extending the comment here as I had to read this line multiple times. The part that wondered me here is if should be
flag == start
or something like that to dismiss the start state but not all others. Not sure what the available flags are.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.
Comments extended.
Regarding flags, we only have
start
andstop
at the moment, but I only wanted to change the behaviour of stop, and this is why explicitly check for that.