Documentation ¶
Index ¶
- Constants
- func BuildConfig(kubeconfigPath string) (*restclient.Config, error)
- func ContainerID(s PodContainerStatus) string
- func ContainerIDWithRuntime(s PodContainerStatus) (string, string)
- func DiscoverKubernetesNode(log *logp.Logger, nd *DiscoverKubernetesNodeParams) (string, error)
- func GetKubeConfigEnvironmentVariable() string
- func GetKubernetesClient(kubeconfig string, opt KubeClientOptions) (kubernetes.Interface, error)
- func InClusterNamespace() (string, error)
- func IsInCluster(kubeconfig string) bool
- func MicroTime(t *metav1.MicroTime) time.Time
- func NewInformer(client kubernetes.Interface, resource Resource, opts WatchOptions, ...) (cache.SharedInformer, string, error)
- func NewNamespacePodUpdater(handler podUpdaterHandlerFunc, store podUpdaterStore, locker sync.Locker) *namespacePodUpdater
- func NewNodePodUpdater(handler podUpdaterHandlerFunc, store podUpdaterStore, locker sync.Locker) *nodePodUpdater
- func PodAnnotations(pod *Pod) mapstr.M
- func PodLabels(pod *Pod) mapstr.M
- func PodNamespaceAnnotations(pod *Pod, watcher Watcher) mapstr.M
- func PodTerminated(pod *Pod, containers []*ContainerInPod) bool
- func PodTerminating(pod *Pod) bool
- func Time(t *metav1.Time) time.Time
- type ClusterRole
- type ClusterRoleBinding
- type Container
- type ContainerInPod
- type ContainerPort
- type CronJob
- type DaemonSet
- type DefaultDiscoveryUtils
- type Deployment
- type DiscoverKubernetesNodeParams
- type Event
- type FilteringResourceEventHandler
- type HostDiscoveryUtils
- type Job
- type KubeClientOptions
- type Namespace
- type NetworkPolicy
- type NoOpEventHandlerFuncs
- type Node
- type ObjectMeta
- type PersistentVolume
- type PersistentVolumeClaim
- type Pod
- type PodContainerStatus
- type PodSecurityPolicy
- type PodSpec
- type PodStatus
- type ReplicaSet
- type Resource
- type ResourceEventHandler
- type ResourceEventHandlerFuncs
- type Role
- type RoleBinding
- type Service
- type ServiceAccount
- type StatefulSet
- type StorageClass
- type WatchOptions
- type Watcher
Constants ¶
const ( // PodPending phase PodPending = v1.PodPending // PodRunning phase PodRunning = v1.PodRunning // PodSucceeded phase PodSucceeded = v1.PodSucceeded // PodFailed phase PodFailed = v1.PodFailed // PodUnknown phase PodUnknown = v1.PodUnknown )
Variables ¶
This section is empty.
Functions ¶
func BuildConfig ¶
func BuildConfig(kubeconfigPath string) (*restclient.Config, error)
BuildConfig is a helper function that builds configs from a kubeconfig filepath. If kubeconfigPath is not passed in we fallback to inClusterConfig. If inClusterConfig fails, we fallback to the default config. This is a copy of `clientcmd.BuildConfigFromFlags` of `client-go` but without the annoying klog messages that are not possible to be disabled.
func ContainerID ¶
func ContainerID(s PodContainerStatus) string
ContainerID parses the container ID to get the actual ID string
func ContainerIDWithRuntime ¶
func ContainerIDWithRuntime(s PodContainerStatus) (string, string)
ContainerIDWithRuntime parses the container ID to get the actual ID string
func DiscoverKubernetesNode ¶
func DiscoverKubernetesNode(log *logp.Logger, nd *DiscoverKubernetesNodeParams) (string, error)
DiscoverKubernetesNode figures out the Kubernetes node to use. If host is provided in the config use it directly. If it is empty then try 1. If beat is deployed in k8s cluster, use hostname of pod as the pod name to query pod metadata for node name. 2. If step 1 fails or beat is deployed outside k8s cluster, use NODE_NAME env var. 3. If node cannot be discovered with step 1,2, use machine-id to match against k8s nodes for node name. In case it is not set return error. Note: There have been cases where machine-id reported by compute instances of some cloud providers where k8s nodes run on, has the wrong value.
func GetKubeConfigEnvironmentVariable ¶
func GetKubeConfigEnvironmentVariable() string
func GetKubernetesClient ¶
func GetKubernetesClient(kubeconfig string, opt KubeClientOptions) (kubernetes.Interface, error)
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 InClusterNamespace ¶
InClusterNamespace gets namespace from serviceaccount when beat is in cluster. // code borrowed from client-go with some changes.
func IsInCluster ¶
IsInCluster takes a kubeconfig file path as input and deduces if Beats is running in cluster or not, taking into consideration the existence of KUBECONFIG variable
func NewInformer ¶
func NewInformer(client kubernetes.Interface, resource Resource, opts WatchOptions, indexers cache.Indexers) (cache.SharedInformer, string, error)
NewInformer creates an informer for a given resource
func NewNamespacePodUpdater ¶
func NewNamespacePodUpdater(handler podUpdaterHandlerFunc, store podUpdaterStore, locker sync.Locker) *namespacePodUpdater
NewNamespacePodUpdater creates a namespacePodUpdater
func NewNodePodUpdater ¶
func NewNodePodUpdater(handler podUpdaterHandlerFunc, store podUpdaterStore, locker sync.Locker) *nodePodUpdater
NewNodePodUpdater creates a nodePodUpdater
func PodAnnotations ¶
PodAnnotations returns the annotations in a pod
func PodNamespaceAnnotations ¶
PodNamespaceAnnotations returns the annotations of the namespace of the pod
func PodTerminated ¶
func PodTerminated(pod *Pod, containers []*ContainerInPod) bool
PodTerminated returns true if a pod is terminated, this method considers a pod as terminated if none of its containers are running (or going to be running).
func PodTerminating ¶
PodTerminating returns true if a pod is marked for deletion or is in a phase beyond running.
Types ¶
type ClusterRoleBinding ¶
type ClusterRoleBinding = rbacv1.ClusterRoleBinding
ClusterRoleBinding data
type ContainerInPod ¶
type ContainerInPod struct { ID string Runtime string Spec Container Status PodContainerStatus }
func GetContainersInPod ¶
func GetContainersInPod(pod *Pod) []*ContainerInPod
GetContainersInPod returns all the containers defined in a pod and their statuses. It includes init and ephemeral containers.
type DefaultDiscoveryUtils ¶
type DefaultDiscoveryUtils struct{}
DefaultDiscoveryUtils implements functions of HostDiscoveryUtils interface
func (*DefaultDiscoveryUtils) GetMachineID ¶
func (hd *DefaultDiscoveryUtils) GetMachineID() string
GetMachineID returns the machine-idadd_kubernetes_metadata/indexers_test.go borrowed from machineID of cadvisor.
func (*DefaultDiscoveryUtils) GetNamespace ¶
func (hd *DefaultDiscoveryUtils) GetNamespace() (string, error)
GetNamespace gets namespace from serviceaccount when beat is in cluster.
func (*DefaultDiscoveryUtils) GetPodName ¶
func (hd *DefaultDiscoveryUtils) GetPodName() (string, error)
GetPodName returns the hostname of the pod
type DiscoverKubernetesNodeParams ¶
type DiscoverKubernetesNodeParams struct { ConfigHost string Client kubernetes.Interface IsInCluster bool HostUtils HostDiscoveryUtils }
DiscoverKubernetesNodeParams includes parameters for discovering kubernetes node
type FilteringResourceEventHandler ¶
type FilteringResourceEventHandler struct { FilterFunc func(obj interface{}) bool Handler ResourceEventHandler }
FilteringResourceEventHandler applies the provided filter to all events coming in, ensuring the appropriate nested handler method is invoked. An object that starts passing the filter after an update is considered an add, and an object that stops passing the filter after an update is considered a delete.
func (FilteringResourceEventHandler) OnAdd ¶
func (r FilteringResourceEventHandler) OnAdd(obj interface{})
OnAdd calls the nested handler only if the filter succeeds
func (FilteringResourceEventHandler) OnDelete ¶
func (r FilteringResourceEventHandler) OnDelete(obj interface{})
OnDelete calls the nested handler only if the filter succeeds
func (FilteringResourceEventHandler) OnUpdate ¶
func (r FilteringResourceEventHandler) OnUpdate(obj interface{})
OnUpdate ensures the proper handler is called depending on whether the filter matches
type HostDiscoveryUtils ¶
type KubeClientOptions ¶
type NoOpEventHandlerFuncs ¶
type NoOpEventHandlerFuncs struct { }
NoOpEventHandlerFuncs ensures that watcher reconciliation can happen even without the required funcs
func (NoOpEventHandlerFuncs) OnAdd ¶
func (n NoOpEventHandlerFuncs) OnAdd(obj interface{})
OnAdd does a no-op on an add event
func (NoOpEventHandlerFuncs) OnDelete ¶
func (n NoOpEventHandlerFuncs) OnDelete(obj interface{})
OnDelete does a no-op on a delete event
func (NoOpEventHandlerFuncs) OnUpdate ¶
func (n NoOpEventHandlerFuncs) OnUpdate(obj interface{})
OnUpdate does a no-op on an update event
type PersistentVolume ¶ added in v0.1.1
type PersistentVolume = v1.PersistentVolume
PersistentVolume data
type PersistentVolumeClaim ¶ added in v0.1.1
type PersistentVolumeClaim = v1.PersistentVolumeClaim
PersistentVolumeClaim data
type PodSecurityPolicy ¶
type PodSecurityPolicy = policyv1beta1.PodSecurityPolicy
PodSecurityPolicy data
type ResourceEventHandler ¶
type ResourceEventHandler interface { OnAdd(obj interface{}) OnUpdate(obj interface{}) OnDelete(obj interface{}) }
ResourceEventHandler can handle notifications for events that happen to a resource. The events are informational only, so you can't return an error.
- OnAdd is called when an object is added.
- OnUpdate is called when an object is modified. Note that oldObj is the last known state of the object-- it is possible that several changes were combined together, so you can't use this to see every single change. OnUpdate is also called when a re-list happens, and it will get called even if nothing changed. This is useful for periodically evaluating or syncing something.
- OnDelete will get the final state of the item if it is known, otherwise it will get an object of type DeletedFinalStateUnknown. This can happen if the watch is closed and misses the delete event and we don't notice the deletion until the subsequent re-list.
idea: allow the On* methods to return an error so that the RateLimited WorkQueue idea: can requeue the failed event processing.
type ResourceEventHandlerFuncs ¶
type ResourceEventHandlerFuncs struct { AddFunc func(obj interface{}) UpdateFunc func(obj interface{}) DeleteFunc func(obj interface{}) }
ResourceEventHandlerFuncs is an adaptor to let you easily specify as many or as few of the notification functions as you want while still implementing ResourceEventHandler.
func (ResourceEventHandlerFuncs) OnAdd ¶
func (r ResourceEventHandlerFuncs) OnAdd(obj interface{})
OnAdd calls AddFunc if it's not nil.
func (ResourceEventHandlerFuncs) OnDelete ¶
func (r ResourceEventHandlerFuncs) OnDelete(obj interface{})
OnDelete calls DeleteFunc if it's not nil.
func (ResourceEventHandlerFuncs) OnUpdate ¶
func (r ResourceEventHandlerFuncs) OnUpdate(obj interface{})
OnUpdate calls UpdateFunc if it's not nil.
type WatchOptions ¶
type WatchOptions struct { // SyncTimeout is a timeout for listing historical resources SyncTimeout time.Duration // Node is used for filtering watched resource to given node, use "" for all nodes Node string // Namespace is used for filtering watched resource to given namespace, use "" for all namespaces Namespace string // IsUpdated allows registering a func that allows the invoker of the Watch to decide what amounts to an update // vs what does not. IsUpdated func(old, new interface{}) bool // HonorReSyncs allows resync events to be requeued on the worker HonorReSyncs bool }
WatchOptions controls watch behaviors
type Watcher ¶
type Watcher interface { // Start watching Kubernetes API for new events after resources were listed Start() error // Stop watching Kubernetes API for new events Stop() // AddEventHandler add event handlers for corresponding event type watched AddEventHandler(ResourceEventHandler) // Store returns the store object for the watcher Store() cache.Store // Client returns the kubernetes client object used by the watcher Client() kubernetes.Interface }
Watcher watches Kubernetes resources events
func NewNamedWatcher ¶
func NewNamedWatcher(name string, client kubernetes.Interface, resource Resource, opts WatchOptions, indexers cache.Indexers) (Watcher, error)
NewNamedWatcher initializes the watcher client to provide an events handler for resource from the cluster (filtered to the given node) and also allows to name the k8s client's workqueue that is used by the watcher. Workqueue name is important for exposing workqueue metrics, if it is empty, its metrics will not be logged by the k8s client.
func NewWatcher ¶
func NewWatcher(client kubernetes.Interface, resource Resource, opts WatchOptions, indexers cache.Indexers) (Watcher, error)
NewWatcher initializes the watcher client to provide a events handler for resource from the cluster (filtered to the given node)