pod

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package pod tracks the current pods from the kubelet read-only port.

Index

Constants

View Source
const (
	StateNamePod = "pod"

	StateKeyPodData           = "data"
	StateKeyPodEncoding       = "encoding"
	StateValuePodEncodingJSON = "json"
)
View Source
const DefaultKubeletReadOnlyPort = 10255
View Source
const Name = "k8s-pod"

Variables

This section is empty.

Functions

func CheckKubeletReadOnlyPort

func CheckKubeletReadOnlyPort(ctx context.Context, port int) error

func CreateGet

func CreateGet(cfg Config) query.GetFunc

func DefaultPollerReady

func DefaultPollerReady() <-chan any

func GetDefaultPoller

func GetDefaultPoller() query.Poller

func ListFromKubeletReadOnlyPort

func ListFromKubeletReadOnlyPort(ctx context.Context, port int) (*corev1.PodList, error)

func New

Types

type Config

type Config struct {
	Query query_config.Config `json:"query"`
	Port  int                 `json:"port"`

	// In case the kubelet does not open the read-only port, we ignore such errors as
	// 'Get "http://localhost:10255/pods": dial tcp 127.0.0.1:10255: connect: connection refused'.
	IgnoreConnectionErrors bool `json:"ignore_connection_errors"`
}

func ParseConfig

func ParseConfig(b any, db *sql.DB) (*Config, error)

func (Config) Validate

func (cfg Config) Validate() error

type ContainerStatus

type ContainerStatus struct {
	Name         string                `json:"name,omitempty"`
	State        corev1.ContainerState `json:"state,omitempty"`
	Ready        bool                  `json:"ready"`
	RestartCount int32                 `json:"restartCount"`
	Image        string                `json:"image,omitempty"`
	ContainerID  string                `json:"containerId,omitempty"`
}

ref. https://pkg.go.dev/k8s.io/api/core/v1#ContainerStatus ref. https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-and-container-status

type Output

type Output struct {
	NodeName string      `json:"node_name,omitempty"`
	Pods     []PodStatus `json:"pods,omitempty"`

	KubeletPidFound bool   `json:"kubelet_pid_found"`
	ConnectionError string `json:"connection_error,omitempty"`
	Message         string `json:"message,omitempty"`
}

func ParseOutputJSON

func ParseOutputJSON(data []byte) (*Output, error)

func ParseStatePod

func ParseStatePod(m map[string]string) (*Output, error)

func ParseStatesToOutput

func ParseStatesToOutput(states ...components.State) (*Output, error)

func (*Output) JSON

func (o *Output) JSON() ([]byte, error)

func (*Output) States

func (o *Output) States(cfg Config) ([]components.State, error)

type PodCondition

type PodCondition struct {
	Type               string      `json:"type,omitempty"`
	Status             string      `json:"status,omitempty"`
	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
	Reason             string      `json:"reason,omitempty"`
	Message            string      `json:"message,omitempty"`
}

ref. https://pkg.go.dev/k8s.io/api/core/v1#PodCondition

type PodStatus

type PodStatus struct {
	ID                    string            `json:"id,omitempty"`
	Namespace             string            `json:"namespace,omitempty"`
	Name                  string            `json:"name,omitempty"`
	Phase                 string            `json:"phase,omitempty"`
	Conditions            []PodCondition    `json:"conditions,omitempty"`
	Message               string            `json:"message,omitempty"`
	Reason                string            `json:"reason,omitempty"`
	StartTime             *metav1.Time      `json:"startTime,omitempty"`
	InitContainerStatuses []ContainerStatus `json:"initContainerStatuses,omitempty"`
	ContainerStatuses     []ContainerStatus `json:"containerStatuses,omitempty"`
}

PodStatus represents the simpler pod status from kubelet API. ref. https://pkg.go.dev/k8s.io/api/core/v1#PodStatus

func ConvertToPodsStatus

func ConvertToPodsStatus(pods ...corev1.Pod) []PodStatus

Converts the original pod status to the simpler one.

func ParsePodStatusJSON

func ParsePodStatusJSON(b []byte) (*PodStatus, error)

func (PodStatus) JSON

func (s PodStatus) JSON() ([]byte, error)

Jump to

Keyboard shortcuts

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