Documentation ¶
Index ¶
- Constants
- func BuildPodFullName(name, namespace string) string
- func GetContainerName(labels map[string]string) string
- func GetPodName(labels map[string]string) string
- func GetPodNamespace(labels map[string]string) string
- func GetPodUID(labels map[string]string) string
- func GetSandboxIDByPodUID(cri pod.CRI, podUID string, state *runtimeapi.PodSandboxState) ([]string, error)
- type Cache
- type Container
- type ContainerExtraInfo
- type ContainerID
- type ContainerRuntimeSpec
- type Pod
- type PodStatus
- type Pods
- type Runtime
- type State
- type Status
Constants ¶
const ( PodNameLabel = "io.yunion.pod.name" PodNamespaceLabel = "io.yunion.pod.namespace" PodUIDLabel = "io.yunion.pod.uid" ContainerNameLabel = "io.yunion.container.name" ContainerRestartCountLabel = "io.yunion.container.restart_count" )
const ( ContainerNameAnnotation = "io.kubernetes.cri.container-name" ContainerTypeAnnotation = "io.kubernetes.cri.container-type" ImageNameAnnotation = "io.kubernetes.cri.image-name" SandboxIdAnnotation = "io.kubernetes.cri.sandbox-id" SandboxNameAnnotation = "io.kubernetes.cri.sandbox-name" SandboxNamespaceAnnotation = "io.kubernetes.cri.sandbox-namespace" SandboxUidAnnotation = "io.kubernetes.cri.sandbox-uid" )
Variables ¶
This section is empty.
Functions ¶
func BuildPodFullName ¶
BuildPodFullName builds the pod full name from pod name and namespace.
func GetContainerName ¶
func GetPodName ¶
func GetPodNamespace ¶
func GetSandboxIDByPodUID ¶
func GetSandboxIDByPodUID(cri pod.CRI, podUID string, state *runtimeapi.PodSandboxState) ([]string, error)
Types ¶
type Cache ¶
type Cache interface { Get(string) (*PodStatus, error) Set(string, *PodStatus, error, time.Time) // GetNewerThan is a blocking call that only returns the status // when it is newer than the given time. GetNewerThan(string, time.Time) (*PodStatus, error) Delete(string) UpdateTime(time.Time) }
Cache stores the PodStatus for the pods. It represents *all* the visible pods/containers in the container runtime. All cache entries are at least as new or newer than the global timestamp (set by UpdateTime()), while individual entries may be slightly newer than the global timestamp. If a pod has no states known by the runtime, Cache returns an empty PodStatus object with ID populated.
Cache provides two methods to retrieve the PodStatus: the non-blocking Get() and the blocking GetNewerThan() method. The component responsible for populating the cache is expected to call Delete() to explicitly free the cache entries.
type Container ¶
type Container struct { // The ID of the container, used by the container runtime to identify // a container. ID ContainerID // The name of the container, which should be the same as specified by // v1.Container. Name string // The image name of the container, this also includes the tag of the image, // the expected form is "NAME:TAG". Image string // The id of the image used by the container. ImageID string // State is the state of the container. State State }
Container provides the runtime information for a container, such as ID, hash, state of the container.
type ContainerExtraInfo ¶
type ContainerExtraInfo struct { SandboxID string `json:"sandbox_id"` Pid int `json:"pid"` RuntimeSpec ContainerRuntimeSpec `json:"runtimeSpec"` }
type ContainerID ¶
type ContainerID struct { // The type of the container runtime. e.g. 'docker'. Type string // The identification of the container, this is comsumable by // the underlying container runtime. (Note that the container // runtime interface still takes the whole struct as input). ID string }
ContainerID is a type that identifies a container.
type ContainerRuntimeSpec ¶
type Pod ¶
type Pod struct { // The ID of the pod, which can be used to retrieve a particular pod // from the pod list returned by GetPods(). Id string CRIId string // The name and namespace of the pod, which is readable by human. Name string Namespace string // List of containers that belongs to the pod. It may contain only // running containers, or mixed with dead ones (when GetPods(true)). Containers []*Container // List of sandboxes associated with this pod. The sandboxes are converted // to Container temporarily to avoid substantial changes to other // components. This is only populated by kuberuntime. Sandboxes []*Container }
Pod is a group of containers.
func (*Pod) FindContainerByID ¶
func (p *Pod) FindContainerByID(id ContainerID) *Container
FindContainerByID returns a container in the pod with the given ContainerID.
func (*Pod) FindContainerByName ¶
FindContainerByName returns a container in the pod with the given name. When there are multiple containers with the same name, the first match will be returned.
func (*Pod) FindSandboxByID ¶
func (p *Pod) FindSandboxByID(id ContainerID) *Container
FindSandboxByID returns a sandbox in the pod with the given ContainerID.
type PodStatus ¶
type PodStatus struct { ID string Name string Namespace string IPs []string ContainerStatuses []*Status SandboxStatuses []*runtimeapi.PodSandboxStatus }
func (PodStatus) GetContainerStatus ¶
type Pods ¶
type Pods []*Pod
Pods represents the list of pods
func (Pods) FindPod ¶
FindPod combines FindPodByID and FindPodByFullName, it finds and returns a pod in the pod list either by the full name or the pod ID. It will return an empty pod if not found.
func (Pods) FindPodByFullName ¶
FindPodByFullName finds and returns a pod in the pod list by the full name. It will return an empty pod if not found.
func (Pods) FindPodByID ¶
FindPodByID finds and returns a pod in the pod list by UID. It will return an empty pod if not found.
type Runtime ¶
type Runtime interface { // Type returns the type of the container runtime. Type() string // GetPods returns a list of containers grouped by pods. The boolean parameter // specifies whether the runtime returns all containers including those already // exited and dead containers (used for garbage collection). GetPods(all bool) ([]*Pod, error) // GetPodStatus retrieves the status of the pod, including the // information of all containers in the pod that are visible in Runtime. GetPodStatus(uid, name, namespace string) (*PodStatus, error) }
Runtime interface defines the interfaces that should be implemented by a container runtime. Thread safety is required from implementations of this interface.
type State ¶
type State string
State represents the state of a container
const ( // ContainerStateCreated indicates a container that has been created (e.g. with docker create) but not started. ContainerStateCreated State = "created" // ContainerStateRunning indicates a currently running container. ContainerStateRunning State = "running" // ContainerStateExited indicates a container that ran and completed ("stopped" in other contexts, although a created container is technically also "stopped"). ContainerStateExited State = "exited" // ContainerStateUnknown encompasses all the states that we currently don't care about (like restarting, paused, dead). ContainerStateUnknown State = "unknown" )
func SandboxToContainerState ¶
func SandboxToContainerState(state runtimeapi.PodSandboxState) State
type Status ¶
type Status struct { // ID of the container. ID ContainerID // Name of the container. Name string // ID of the sandbox to which this container belongs. PodSandboxID string // Status of the container. State State // Creation time of the container. CreatedAt time.Time // Start time of the container. StartedAt time.Time // Finish time of the container. FinishedAt time.Time // Exit code of the container. ExitCode int // Name of the image, this also includes the tag of the image, // the expected form is "NAME:TAG". Image string // ID of the image. ImageID string // Hash of the container, used for comparison. Hash uint64 // Number of times that the container has been restarted. RestartCount int // A string explains why container is in such a status. Reason string // Message written by the container before exiting (stored in // TerminationMessagePath). Message string }
Status represents the status of a container.
func ToContainerStatus ¶
func ToContainerStatus(status *runtimeapi.ContainerStatus, runtimeName string) *Status