kubernetes

package
v6.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverKubernetesNode

func DiscoverKubernetesNode(host string, client *k8s.Client) string

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 GetKubernetesClient

func GetKubernetesClient(inCluster bool, kubeConfig string) (client *k8s.Client, err 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.

Types

type Client

type Client interface {
	ListPods(ctx context.Context, namespace string, options ...k8s.Option) (*corev1.PodList, error)
	WatchPods(ctx context.Context, namespace string, options ...k8s.Option) (*k8s.CoreV1PodWatcher, error)
}

Client for Kubernetes interface

type Container

type Container struct {
	Image                  string          `json:"image"`
	ImagePullPolicy        string          `json:"imagePullPolicy"`
	Name                   string          `json:"name"`
	Ports                  []ContainerPort `json:"ports"`
	Resources              struct{}        `json:"resources"`
	TerminationMessagePath string          `json:"terminationMessagePath"`
	VolumeMounts           []struct {
		MountPath string `json:"mountPath"`
		Name      string `json:"name"`
		ReadOnly  bool   `json:"readOnly"`
	} `json:"volumeMounts"`
}

type ContainerPort

type ContainerPort struct {
	Name          string `json:"name"`
	ContainerPort int64  `json:"containerPort"`
	Protocol      string `json:"protocol"`
}

type MetaGenerator

type MetaGenerator interface {
	// PodMetadata generates metadata for the given pod taking to account certain filters
	PodMetadata(pod *Pod) common.MapStr

	// Containermetadata generates metadata for the given container of a pod
	ContainerMetadata(pod *Pod, container string) common.MapStr
}

MetaGenerator builds metadata objects for pods and containers

func NewMetaGenerator

func NewMetaGenerator(annotations, labels, labelsExclude []string) MetaGenerator

NewMetaGenerator initializes and returns a new kubernetes metadata generator

type ObjectMeta

type ObjectMeta struct {
	Annotations       map[string]string `json:"annotations"`
	CreationTimestamp string            `json:"creationTimestamp"`
	DeletionTimestamp string            `json:"deletionTimestamp"`
	GenerateName      string            `json:"generateName"`
	Labels            map[string]string `json:"labels"`
	Name              string            `json:"name"`
	Namespace         string            `json:"namespace"`
	OwnerReferences   []struct {
		APIVersion string `json:"apiVersion"`
		Controller bool   `json:"controller"`
		Kind       string `json:"kind"`
		Name       string `json:"name"`
		UID        string `json:"uid"`
	} `json:"ownerReferences"`
	ResourceVersion string `json:"resourceVersion"`
	SelfLink        string `json:"selfLink"`
	UID             string `json:"uid"`
}

type Pod

type Pod struct {
	APIVersion string     `json:"apiVersion"`
	Kind       string     `json:"kind"`
	Metadata   ObjectMeta `json:"metadata"`
	Spec       PodSpec    `json:"spec"`
	Status     PodStatus  `json:"status"`
}

func GetPod

func GetPod(pod *corev1.Pod) *Pod

GetPod converts Pod to our own type

type PodContainerStatus

type PodContainerStatus struct {
	ContainerID string `json:"containerID"`
	Image       string `json:"image"`
	ImageID     string `json:"imageID"`
	LastState   struct {
		Terminated struct {
			ContainerID string `json:"containerID"`
			ExitCode    int64  `json:"exitCode"`
			FinishedAt  string `json:"finishedAt"`
			Reason      string `json:"reason"`
			StartedAt   string `json:"startedAt"`
		} `json:"terminated"`
	} `json:"lastState"`
	Name         string `json:"name"`
	Ready        bool   `json:"ready"`
	RestartCount int64  `json:"restartCount"`
	State        struct {
		Running struct {
			StartedAt string `json:"startedAt"`
		} `json:"running"`
	} `json:"state"`
}

func (*PodContainerStatus) GetContainerID

func (s *PodContainerStatus) GetContainerID() string

GetContainerID parses the container ID to get the actual ID string

type PodSpec

type PodSpec struct {
	Containers                    []Container `json:"containers"`
	DNSPolicy                     string      `json:"dnsPolicy"`
	NodeName                      string      `json:"nodeName"`
	RestartPolicy                 string      `json:"restartPolicy"`
	SecurityContext               struct{}    `json:"securityContext"`
	ServiceAccount                string      `json:"serviceAccount"`
	ServiceAccountName            string      `json:"serviceAccountName"`
	TerminationGracePeriodSeconds int64       `json:"terminationGracePeriodSeconds"`
}

type PodStatus

type PodStatus struct {
	Conditions            []PodStatusCondition `json:"conditions"`
	ContainerStatuses     []PodContainerStatus `json:"containerStatuses"`
	InitContainerStatuses []PodContainerStatus `json:"initContainerStatuses"`
	HostIP                string               `json:"hostIP"`
	Phase                 string               `json:"phase"`
	PodIP                 string               `json:"podIP"`
	StartTime             string               `json:"startTime"`
}

type PodStatusCondition

type PodStatusCondition struct {
	LastProbeTime      interface{} `json:"lastProbeTime"`
	LastTransitionTime string      `json:"lastTransitionTime"`
	Status             string      `json:"status"`
	Type               string      `json:"type"`
}

type Watcher

type Watcher interface {
	// Start watching Kubernetes API for new containers
	Start() error

	// Stop watching Kubernetes API for new containers
	Stop()

	// ListenStart returns a bus listener to receive pod started events, with a `pod` key holding it
	ListenStart() bus.Listener

	// ListenUpdate returns a bus listener to receive pod updated events, with a `pod` key holding it
	ListenUpdate() bus.Listener

	// ListenStop returns a bus listener to receive pod stopped events, with a `pod` key holding it
	ListenStop() bus.Listener
}

Watcher reads Kubernetes events and keeps a list of known pods

func NewWatcher

func NewWatcher(client Client, syncPeriod, cleanupTimeout time.Duration, host string) Watcher

NewWatcher initializes the watcher client to provide a local state of pods from the cluster (filtered to the given host)

Jump to

Keyboard shortcuts

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