kubernetes

package
v0.6.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 31 Imported by: 27

Documentation

Index

Constants

View Source
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

func InClusterNamespace() (string, error)

InClusterNamespace gets namespace from serviceaccount when beat is in cluster. // code borrowed from client-go with some changes.

func IsInCluster

func IsInCluster(kubeconfig string) bool

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 MicroTime

func MicroTime(t *metav1.MicroTime) time.Time

MicroTime extracts time from k8s.MicroTime type

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, namespaceWatcher Watcher, locker sync.Locker) *namespacePodUpdater

NewNamespacePodUpdater creates a namespacePodUpdater

func NewNodePodUpdater

func NewNodePodUpdater(handler podUpdaterHandlerFunc, store podUpdaterStore, nodeWatcher Watcher, locker sync.Locker) *nodePodUpdater

NewNodePodUpdater creates a nodePodUpdater

func PodAnnotations

func PodAnnotations(pod *Pod) mapstr.M

PodAnnotations returns the annotations in a pod

func PodLabels added in v0.4.0

func PodLabels(pod *Pod) mapstr.M

PodLabels returns the labels in a pod

func PodNamespaceAnnotations

func PodNamespaceAnnotations(pod *Pod, watcher Watcher) mapstr.M

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

func PodTerminating(pod *Pod) bool

PodTerminating returns true if a pod is marked for deletion or is in a phase beyond running.

func Time

func Time(t *metav1.Time) time.Time

Time extracts time from k8s.Time type

Types

type ClusterRole

type ClusterRole = rbacv1.ClusterRole

ClusterRole data

type ClusterRoleBinding

type ClusterRoleBinding = rbacv1.ClusterRoleBinding

ClusterRoleBinding data

type Container

type Container = v1.Container

Container 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 ContainerPort

type ContainerPort = v1.ContainerPort

ContainerPort data

type CronJob

type CronJob = batchv1.CronJob

CronJob data

type DaemonSet added in v0.1.1

type DaemonSet = appsv1.DaemonSet

DaemonSet data

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 Deployment

type Deployment = appsv1.Deployment

Deployment data

type DiscoverKubernetesNodeParams

type DiscoverKubernetesNodeParams struct {
	ConfigHost  string
	Client      kubernetes.Interface
	IsInCluster bool
	HostUtils   HostDiscoveryUtils
}

DiscoverKubernetesNodeParams includes parameters for discovering kubernetes node

type Event

type Event = v1.Event

Event data

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 HostDiscoveryUtils interface {
	GetNamespace() (string, error)
	GetPodName() (string, error)
	GetMachineID() string
}

type Job

type Job = batchv1.Job

Job data

type KubeClientOptions

type KubeClientOptions struct {
	QPS   float32 `config:"qps"`
	Burst int     `config:"burst"`
}

type Namespace

type Namespace = v1.Namespace

Namespace data

type NetworkPolicy

type NetworkPolicy = networkingv1.NetworkPolicy

NetworkPolicy data

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 Node

type Node = v1.Node

Node data

type ObjectMeta

type ObjectMeta = metav1.ObjectMeta

ObjectMeta data

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 Pod

type Pod = v1.Pod

Pod data

type PodContainerStatus

type PodContainerStatus = v1.ContainerStatus

PodContainerStatus data

type PodSecurityPolicy

type PodSecurityPolicy = policyv1beta1.PodSecurityPolicy

PodSecurityPolicy data

type PodSpec

type PodSpec = v1.PodSpec

PodSpec data

type PodStatus

type PodStatus = v1.PodStatus

PodStatus data

type ReplicaSet

type ReplicaSet = appsv1.ReplicaSet

ReplicaSet data

type Resource

type Resource = runtime.Object

Resource 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 Role

type Role = rbacv1.Role

Role data

type RoleBinding

type RoleBinding = rbacv1.RoleBinding

RoleBinding data

type Service

type Service = v1.Service

Service data

type ServiceAccount added in v0.1.0

type ServiceAccount = v1.ServiceAccount

ServiceAccount data

type StatefulSet

type StatefulSet = appsv1.StatefulSet

StatefulSet data

type StorageClass added in v0.3.0

type StorageClass = storagev1.StorageClass

StorageClass data

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)

	// GetEventHandler returns the event handlers for corresponding event type watched
	GetEventHandler() 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

	// CachedObject returns the old object before change during the last updated event
	CachedObject() runtime.Object
}

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL