diff --git a/libbeat/autodiscover/providers/kubernetes/kubernetes.go b/libbeat/autodiscover/providers/kubernetes/kubernetes.go index 3a6d5738dc4a..646638402cfa 100644 --- a/libbeat/autodiscover/providers/kubernetes/kubernetes.go +++ b/libbeat/autodiscover/providers/kubernetes/kubernetes.go @@ -70,6 +70,9 @@ func AutodiscoverBuilder(bus bus.Bus, c *common.Config) (autodiscover.Provider, }, nil } +// Start the autodiscover provider. Start and stop listeners work the +// conventional way. Update listener triggers a stop and then a start +// to simulate an update. func (p *Provider) Start() { go func() { for { @@ -166,10 +169,12 @@ func (p *Provider) publish(event bus.Event) { p.bus.Publish(event) } +// Stop signals the stop channel to force the watch loop routine to stop. func (p *Provider) Stop() { close(p.stop) } +// String returns a description of kubernetes autodiscover provider. func (p *Provider) String() string { return "kubernetes" } diff --git a/libbeat/common/kubernetes/types.go b/libbeat/common/kubernetes/types.go index ccadf17651db..134c13d4826b 100644 --- a/libbeat/common/kubernetes/types.go +++ b/libbeat/common/kubernetes/types.go @@ -108,6 +108,7 @@ type Pod struct { Status PodStatus `json:"status"` } +// GetContainerID parses the container ID to get the actual ID string func (s *PodContainerStatus) GetContainerID() string { cID := s.ContainerID if cID != "" { diff --git a/libbeat/common/kubernetes/util.go b/libbeat/common/kubernetes/util.go index 6c767632770c..88c1c37048af 100644 --- a/libbeat/common/kubernetes/util.go +++ b/libbeat/common/kubernetes/util.go @@ -12,6 +12,9 @@ import ( "github.com/elastic/beats/libbeat/logp" ) +// 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 { client, err = k8s.NewInClusterClient() @@ -38,6 +41,9 @@ func GetKubernetesClient(inCluster bool, kubeConfig string) (client *k8s.Client, return client, nil } +// DiscoverKubernetesNode figures out the Kubernetes host to use. If host is provided in the config +// use it directly. Else use hostname of the pod which is the Pod ID to query the Pod and get the Node +// name from the specification. Else, return localhost as a default. func DiscoverKubernetesNode(host string, client *k8s.Client) string { ctx := context.Background() if host == "" {