-
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
[Discuss&POC] refactor k8s client to k8s.io/client-go #6117
Conversation
Now beat can detect host by itself when outside cluster It also fixes 2 bugs: * query pod meta won't refrese deleted map timeout * delete event for k8s autodiscovery will be delayed since watcher delay the event push
@@ -0,0 +1,69 @@ | |||
package add_kubernetes_metadata |
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.
don't use an underscore in package name
|
||
return po | ||
func (e *Event) GetMetadata() *ObjectMeta { |
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.
exported method Event.GetMetadata should have comment or be unexported
logp.Warn("Unable to marshal %v", pod.String()) | ||
return nil | ||
} | ||
type Event struct { |
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.
exported type Event should have comment or be unexported
@@ -108,6 +108,10 @@ type Pod struct { | |||
Status PodStatus `json:"status"` | |||
} | |||
|
|||
func (p *Pod) GetMetadata() *ObjectMeta { |
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.
exported method Pod.GetMetadata should have comment or be unexported
) | ||
|
||
type Resource interface { |
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.
exported type Resource should have comment or be unexported
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
@walktall Thanks for taking a stab at this. I haven't looked much at the code yet but I saw you mentioned that you discovered / solved two issue. I'm wondering if these could go into a separate PR to have them in rather soon or these depend on changing the library? |
@ruflin Yes, I will make another PR about two issues only. |
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.
Overall I like very much how this is looking, thank you for taking this!! 🎉
These changes are tackling different concerns, so I think they should go on different PRs, at least 4:
- [bugfix] query pod meta won't refresh deleted map timeout
- Switch to
client-go
(is the size still +30MB?) - Watcher API refactor
- Node discovery improvements
About: "delete event for k8s autodiscovery will be delayed since watcher delay the event push", this is not a bug but a feature :)
Especially when handling logs, but also with some metrics, you want to delay the shutdown of the module to ensure you get the latest events from the pod. If we stop reading the log just after the pod dies, last lines won't be read.
func inClusterNamespace() string { | ||
// This way assumes you've set the POD_NAMESPACE environment variable using the downward API. | ||
// This check has to be done first for backwards compatibility with the way InClusterConfig was originally set up | ||
if ns := os.Getenv("POD_NAMESPACE"); ns != "" { |
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.
We stopped using this, in favor of client.Namespace
, what's the motivation for this change?
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.
Since k8s.io/client-go
doesn't have a field Namespace
in clientset, so client.Namespace
is kind like a tricky in ericchiang/k8s
I think. This func is borrowed from client-go, and after rethink about it, I think user should not need to set namespace by downward API since if beat is in cluster, then it should be auto detected.
return defaultNode | ||
} | ||
for _, n := range nodes.Items { | ||
if n.Status.NodeInfo.MachineID == mid { |
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.
Cool addition, I guess all the fallback mechanisms make node discovery bulletproof :)
|
||
// ListenStop returns a bus listener to receive pod stopped events, with a `pod` key holding it | ||
ListenStop() bus.Listener | ||
AddEventHandler(ResourceEventHandler) |
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.
💯 to this approach, I've been wanting to change it to this since I wrote the current one 😅
@exekias Thank you for your comments! I will make PRs step by step. And sorry for misunderstanding the feature in auto discovery as a bug 😅 |
@exekias For switching client-go: With go 1.9.2, build with With go 1.9.2, build with Anyway, I will put the switching pr the last one, since it is only imported by |
@walktall Did you ever investigate if we could sligthly tweak the import to massively reduce the dependency. I had a similar experience with docker. |
i think that might be a good exercise to see if it works but the Kube client as is does a lot of things in addition to just making API calls. |
Close due to no further plan for this right now since library currently used works well. |
Ref: #6068
I didn't update vendor and fully test it yet, just open this PR for discuss.
Will be very happy if you can take a look! @exekias @vjsamuel @ruflin
Maybe it's still too big for bin to change client, but I abstract the
common/kubernetes
pkg and make it easier to use hopefully.And also, found 2 bugs while refactoring.
With one another enhancement: beat can auto discovery correct k8s node now. So host in config might only be useful when you are testing...