-
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
Update kubernetes watcher to use official client-go libraries #13051
Conversation
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? |
1 similar comment
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? |
3b2c86e
to
878b3a7
Compare
ok to test |
6689e91
to
9b74f99
Compare
@@ -36,27 +35,15 @@ const defaultNode = "localhost" | |||
// GetKubernetesClient returns a kubernetes client. If inCluster is true, it returns an | |||
// in cluster configuration based on the secrets mounted in the Pod. If kubeConfig is passed, | |||
// it parses the config file to get the config required to build a client. | |||
func GetKubernetesClient(inCluster bool, kubeConfig string) (client *k8s.Client, err error) { | |||
if inCluster == true { |
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.
it sems you don't use inCluster
anymore, how would this be used now? We would need to update the comment and some docs
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.
the official kube client deduces if it runs in cluster or not and hence to get a kube client we dont really need it.
if kubeconfigPath == "" && masterUrl == "" {
klog.Warningf("Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.")
kubeconfig, err := restclient.InClusterConfig()
if err == nil {
return kubeconfig, nil
}
klog.Warning("error creating inClusterConfig, falling back to default config: ", err)
}
if kubeconfig path is provided then it just tries to create an out of cluster configuration.
That said. let me fix the discover node to just follow the same thing.
w.handler.OnAdd(obj) | ||
} | ||
func (w *watcher) enqueue(obj interface{}, state string) { | ||
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj) |
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 is this line for? a comment could help here
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.
this just makes sure that it gets the namespace/name combination only for resources where state is not Unknown
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.
Thank you for opening this @vjsamuel, this is REALLY appreciated! 🎉
I left a few comments and questions, I'm wondering about the changes in user configurations and backwards compatibility
…e close to Stop()
not sure if the failures are related. I have done manual testing on all flows and things look file. Lets have action items to now have fake client based test cases on the autodiscover/processor paths so that it is easier to find failures. there were a few issues that i fixed in the last commit one of which is to increase the default resync period. with the new client, it is no longer necessary to sync every minute. the resync period forces all items on the cache to be replayed. this is undesirable at a 1 minute interval. i have also gone ahead and removed the |
Thank you so much for this contribution @vjsamuel! it's a real enabler for future features |
This configuration was removed by elastic/beats#13051 and elastic/beats#13651
This configuration was removed by elastic/beats#13051 and elastic/beats#13651
This PR moves away from using the Eric Chang client-go for Kubernetes interaction in favor of the official kube client. As a result, we now use
SharedInformer
s. This makes sure that at any given time there is only 1 connection to the API server per resource that is requested. Moving to the client-go also makes sure that we no longer need to check ResourceVersion while watching. It is implicitly done under the hood.This change now allows the watcher to be testable and as a follow up we could add test cases.