pod

package
v0.0.0-...-fd96df4 Latest Latest
Warning

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

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

Documentation

Overview

Package pod models a single pod (a group of containers), which can run container tasks.

Index

Constants

View Source
const (
	// PodIDEnvVar is the name of the environment variable containing the pod
	// ID.
	PodIDEnvVar = "POD_ID"
	// PodIDEnvVar is the name of the environment variable containing the shared
	// secret between the server and the pod.
	PodSecretEnvVar = "POD_SECRET"
)
View Source
const (
	Collection = "pods"
)

Variables

View Source
var (
	IDKey                        = bsonutil.MustHaveTag(Pod{}, "ID")
	TypeKey                      = bsonutil.MustHaveTag(Pod{}, "Type")
	StatusKey                    = bsonutil.MustHaveTag(Pod{}, "Status")
	TaskContainerCreationOptsKey = bsonutil.MustHaveTag(Pod{}, "TaskContainerCreationOpts")
	FamilyKey                    = bsonutil.MustHaveTag(Pod{}, "Family")
	TimeInfoKey                  = bsonutil.MustHaveTag(Pod{}, "TimeInfo")
	ResourcesKey                 = bsonutil.MustHaveTag(Pod{}, "Resources")
	TaskRuntimeInfoKey           = bsonutil.MustHaveTag(Pod{}, "TaskRuntimeInfo")

	TaskContainerCreationOptsImageKey    = bsonutil.MustHaveTag(TaskContainerCreationOptions{}, "Image")
	TaskContainerCreationOptsMemoryMBKey = bsonutil.MustHaveTag(TaskContainerCreationOptions{}, "MemoryMB")
	TaskContainerCreationOptsCPUKey      = bsonutil.MustHaveTag(TaskContainerCreationOptions{}, "CPU")
	TaskContainerCreationOptsOSKey       = bsonutil.MustHaveTag(TaskContainerCreationOptions{}, "OS")
	TaskContainerCreationOptsArchKey     = bsonutil.MustHaveTag(TaskContainerCreationOptions{}, "Arch")
	TaskContainerCreationOptsEnvVarsKey  = bsonutil.MustHaveTag(TaskContainerCreationOptions{}, "EnvVars")
	TaskContainerCreationOptsSecretsKey  = bsonutil.MustHaveTag(TaskContainerCreationOptions{}, "EnvSecrets")

	TimeInfoInitializingKey     = bsonutil.MustHaveTag(TimeInfo{}, "Initializing")
	TimeInfoStartingKey         = bsonutil.MustHaveTag(TimeInfo{}, "Starting")
	TimeInfoLastCommunicatedKey = bsonutil.MustHaveTag(TimeInfo{}, "LastCommunicated")
	TimeInfoAgentStartedKey     = bsonutil.MustHaveTag(TimeInfo{}, "AgentStarted")

	ResourceInfoExternalIDKey   = bsonutil.MustHaveTag(ResourceInfo{}, "ExternalID")
	ResourceInfoDefinitionIDKey = bsonutil.MustHaveTag(ResourceInfo{}, "DefinitionID")
	ResourceInfoClusterKey      = bsonutil.MustHaveTag(ResourceInfo{}, "Cluster")
	ResourceInfoContainersKey   = bsonutil.MustHaveTag(ResourceInfo{}, "Containers")

	TaskRuntimeInfoRunningTaskIDKey        = bsonutil.MustHaveTag(TaskRuntimeInfo{}, "RunningTaskID")
	TaskRuntimeInfoRunningTaskExecutionKey = bsonutil.MustHaveTag(TaskRuntimeInfo{}, "RunningTaskExecution")

	ContainerResourceInfoExternalIDKey = bsonutil.MustHaveTag(ContainerResourceInfo{}, "ExternalID")
	ContainerResourceInfoNameKey       = bsonutil.MustHaveTag(ContainerResourceInfo{}, "Name")
	ContainerResourceInfoSecretIDsKey  = bsonutil.MustHaveTag(ContainerResourceInfo{}, "SecretIDs")

	SecretExternalIDKey = bsonutil.MustHaveTag(Secret{}, "ExternalID")
	SecretValueKey      = bsonutil.MustHaveTag(Secret{}, "Value")
)

Functions

func ByExternalID

func ByExternalID(id string) bson.M

func ByID

func ByID(id string) bson.M

func Count

func Count(q db.Q) (int, error)

Count counts the number of pods matching the given query.

func CountByInitializing

func CountByInitializing() (int, error)

CountByInitializing counts the number of pods that are initializing but have not started any containers.

func UpdateOne

func UpdateOne(query interface{}, update interface{}) error

UpdateOne updates one pod.

func UpdateOneStatus

func UpdateOneStatus(id string, current, updated Status, ts time.Time, reason string) error

UpdateOneStatus updates a pod's status by ID along with any relevant metadata information about the status update. If the current status is identical to the updated one, this will no-op. If the current status does not match the stored status, this will error.

Types

type Arch

type Arch string

Arch represents recognized architectures for pods.

const (
	ArchAMD64 Arch = "amd64"
	ArchARM64 Arch = "arm64"
)

func ImportArch

func ImportArch(arch evergreen.ContainerArch) (Arch, error)

ImportArch converts the container CPU architecture into its equivalent pod CPU architecture.

func (Arch) Matches

func (a Arch) Matches(arch evergreen.ECSArch) bool

Matches returns whether or not the pod CPU architecture matches the given Evergreen ECS config CPU architecture.

func (Arch) Validate

func (a Arch) Validate() error

Validate checks that the pod architecture is recognized.

type ContainerResourceInfo

type ContainerResourceInfo struct {
	// ExternalID is the unique resource identifier for the container running in
	// the container service.
	ExternalID string `bson:"external_id,omitempty" json:"external_id,omitempty"`
	// Name is the friendly name of the container.
	Name string `bson:"name,omitempty" json:"name,omitempty"`
	// SecretIDs are the resource identifiers for the secrets owned by this
	// container.
	SecretIDs []string `bson:"secret_ids,omitempty" json:"secret_ids,omitempty"`
}

ContainerResourceInfo represents information about external resources associated with a container.

func (ContainerResourceInfo) IsZero

func (i ContainerResourceInfo) IsZero() bool

IsZero implements the bsoncodec.Zeroer interface for the sake of defining the zero value for BSON marshalling.

type OS

type OS string

OS represents a recognized operating system for pods.

const (
	// OSLinux indicates that the pods will run with Linux containers.
	OSLinux OS = "linux"
	// OSWindows indicates that the pods will run with Windows containers.
	OSWindows OS = "windows"
)

func ImportOS

func ImportOS(os evergreen.ContainerOS) (OS, error)

ImportOS converts the container OS into its equivalent pod OS.

func (OS) Matches

func (os OS) Matches(other evergreen.ECSOS) bool

Matches returns whether or not the pod OS matches the given Evergreen ECS config OS.

func (OS) Validate

func (os OS) Validate() error

Validate checks that the pod OS is recognized.

type Pod

type Pod struct {
	// ID is the unique identifier for the metadata document.
	ID string `bson:"_id" json:"id"`
	// Type indicates the type of pod that this is.
	Type Type `bson:"type" json:"type"`
	// Status is the current state of the pod.
	Status Status `bson:"status"`
	// TaskCreationOpts are options to configure how a task should be
	// containerized and run in a pod.
	TaskContainerCreationOpts TaskContainerCreationOptions `bson:"task_creation_opts,omitempty" json:"task_creation_opts,omitempty"`
	// Family is the family name of the pod definition stored in the cloud
	// provider.
	Family string `bson:"family,omitempty" json:"family,omitempty"`
	// TimeInfo contains timing information for the pod's lifecycle.
	TimeInfo TimeInfo `bson:"time_info,omitempty" json:"time_info,omitempty"`
	// Resources are external resources that are owned and managed by this pod.
	Resources ResourceInfo `bson:"resource_info,omitempty" json:"resource_info,omitempty"`
	// TaskRuntimeInfo contains information about the tasks that a pod is
	// assigned.
	TaskRuntimeInfo TaskRuntimeInfo `bson:"task_runtime_info,omitempty" json:"task_runtime_info,omitempty"`
	// AgentVersion is the version of the agent running on this pod if it's a
	// pod that runs tasks.
	AgentVersion string `bson:"agent_version,omitempty" json:"agent_version,omitempty"`
}

Pod represents a related collection of containers. This model holds metadata about containers running in a container orchestration system.

func Find

func Find(q db.Q) ([]Pod, error)

Find finds all pods matching the given query.

func FindByInitializing

func FindByInitializing() ([]Pod, error)

FindByInitializing find all pods that are initializing but have not started any containers.

func FindByLastCommunicatedBefore

func FindByLastCommunicatedBefore(ts time.Time) ([]Pod, error)

FindByLastCommunicatedBefore finds all active pods whose last communication was before the given threshold.

func FindByNeedsTermination

func FindByNeedsTermination() ([]Pod, error)

FindByNeedsTermination finds all pods running agents that need to be terminated, which includes: * Pods that have been provisioning for too long. * Pods that are decommissioned and have no running task.

func FindIntentByFamily

func FindIntentByFamily(family string) ([]Pod, error)

FindIntentByFamily finds intent pods that have a matching family name.

func FindOne

func FindOne(q db.Q) (*Pod, error)

FindOne finds one pod by the given query.

func FindOneByExternalID

func FindOneByExternalID(id string) (*Pod, error)

FindOneByExternalID finds a pod that has a matching external identifier.

func FindOneByID

func FindOneByID(id string) (*Pod, error)

FindOneByID finds one pod by its ID.

func NewTaskIntentPod

func NewTaskIntentPod(ecsConf evergreen.ECSConfig, opts TaskIntentPodOptions) (*Pod, error)

NewTaskIntentPod creates a new intent pod to run container tasks from the given initialization options.

func (*Pod) ClearRunningTask

func (p *Pod) ClearRunningTask() error

ClearRunningTask clears the current task dispatched to the pod, if one is set.

func (*Pod) GetSecret

func (p *Pod) GetSecret() (*Secret, error)

GetSecret returns the shared secret between the server and the pod. If the secret is unset, this will return an error.

func (*Pod) Insert

func (p *Pod) Insert() error

Insert inserts a new pod into the collection. This relies on the global Anser DB session.

func (*Pod) InsertWithContext

func (p *Pod) InsertWithContext(ctx context.Context, env evergreen.Environment) error

InsertWithContext is the same as Insert, but it respects the given context by avoiding the global Anser DB session.

func (*Pod) Remove

func (p *Pod) Remove() error

Remove removes the pod from the collection.

func (*Pod) SetRunningTask

func (p *Pod) SetRunningTask(ctx context.Context, env evergreen.Environment, taskID string, taskExecution int) error

SetRunningTask sets the task to dispatch to the pod.

func (*Pod) UpdateAgentStartTime

func (p *Pod) UpdateAgentStartTime() error

UpdateAgentStartTime updates the time when the pod's agent started to now.

func (*Pod) UpdateLastCommunicated

func (p *Pod) UpdateLastCommunicated() error

UpdateLastCommunicated updates the last time that the pod and app server successfully communicated to now, indicating that the pod is currently alive.

func (*Pod) UpdateResources

func (p *Pod) UpdateResources(info ResourceInfo) error

UpdateResources updates the pod resources.

func (*Pod) UpdateStatus

func (p *Pod) UpdateStatus(s Status, reason string) error

UpdateStatus updates the pod status.

type ResourceInfo

type ResourceInfo struct {
	// ExternalID is the unique resource identifier for the aggregate collection
	// of containers running for the pod in the container service.
	ExternalID string `bson:"external_id,omitempty" json:"external_id,omitempty"`
	// DefinitionID is the resource identifier for the pod definition template.
	DefinitionID string `bson:"definition_id,omitempty" json:"definition_id,omitempty"`
	// Cluster is the namespace where the containers are running.
	Cluster string `bson:"cluster,omitempty" json:"cluster,omitempty"`
	// Containers include resource information about containers running in the
	// pod.
	Containers []ContainerResourceInfo `bson:"containers,omitempty" json:"containers,omitempty"`
}

ResourceInfo represents information about external resources associated with a pod.

func (ResourceInfo) IsZero

func (i ResourceInfo) IsZero() bool

IsZero implements the bsoncodec.Zeroer interface for the sake of defining the zero value for BSON marshalling.

type Secret

type Secret struct {
	// ExternalID is the unique external resource identifier for a secret that
	// already exists in the secrets storage service.
	ExternalID string `bson:"external_id,omitempty" json:"external_id,omitempty"`
	// Value is the value of the secret. This is a cached copy of the actual
	// secret value stored in the secrets storage service.
	Value string `bson:"value,omitempty" json:"value,omitempty"`
}

Secret is a sensitive secret that a pod can access. The secret is managed in an integrated secrets storage service.

func (Secret) IsZero

func (s Secret) IsZero() bool

IsZero implements the bsoncodec.Zeroer interface for the sake of defining the zero value for BSON marshalling.

type Status

type Status string

Status represents a possible state for a pod.

const (
	// StatusInitializing indicates that a pod is waiting to be created.
	StatusInitializing Status = "initializing"
	// StatusStarting indicates that a pod's containers are starting.
	StatusStarting Status = "starting"
	// StatusRunning indicates that the pod's containers are running.
	StatusRunning Status = "running"
	// StatusDecommissioned indicates that the pod is currently running but will
	// be terminated shortly.
	StatusDecommissioned Status = "decommissioned"
	// StatusTerminated indicates that all of the pod's containers and
	// associated resources have been deleted.
	StatusTerminated Status = "terminated"
)

func (Status) Validate

func (s Status) Validate() error

Validate checks that the pod status is recognized.

type StatusCount

type StatusCount struct {
	Status          Status `bson:"status"`
	Count           int    `bson:"count"`
	NumRunningTasks int    `bson:"num_running_tasks"`
}

StatusCount contains the total number of pods and total number of running tasks for a particular pod status.

func GetStatsByStatus

func GetStatsByStatus(statuses ...Status) ([]StatusCount, error)

GetStatsByStatus gets aggregate usage statistics on pods that are intended for running tasks. For each pod status, it returns the counts for the number of pods and number of running tasks in that particular status. Terminated pods are excluded from these statistics.

type TaskContainerCreationOptions

type TaskContainerCreationOptions struct {
	// Image is the image that the task's container will run.
	Image string `bson:"image" json:"image"`
	// RepoCredsExternalID is the external identifier for the repository
	// credentials.
	RepoCredsExternalID string `bson:"repo_creds_external_id,omitempty" json:"repo_creds_external_id,omitempty"`
	// MemoryMB is the memory (in MB) that the task's container will be
	// allocated.
	MemoryMB int `bson:"memory_mb" json:"memory_mb"`
	// CPU is the CPU units that the task will be allocated. 1024 CPU units is
	// equivalent to 1vCPU.
	CPU int `bson:"cpu" json:"cpu"`
	// OS indicates which particular operating system the pod's containers run
	// on.
	OS OS `bson:"os" json:"os"`
	// Arch indicates the particular architecture that the pod's containers run
	// on.
	Arch Arch `bson:"arch" json:"arch"`
	// WindowsVersion specifies the particular version of Windows the container
	// should run in. This only applies if OS is OSWindows.
	WindowsVersion WindowsVersion `bson:"windows_version,omitempty" json:"windows_version,omitempty"`
	// EnvVars is a mapping of the non-secret environment variables to expose in
	// the task's container environment.
	EnvVars map[string]string `bson:"env_vars,omitempty" json:"env_vars,omitempty"`
	// EnvSecrets are secret values to expose in the task's container
	// environment variables. The key is the name of the environment variable
	// and the value is the configuration for the secret value.
	EnvSecrets map[string]Secret `bson:"env_secrets,omitempty" json:"env_secrets,omitempty"`
	// WorkingDir is the working directory for the task's container.
	WorkingDir string `bson:"working_dir,omitempty" json:"working_dir,omitempty"`
}

TaskContainerCreationOptions are options to apply to the task's container when creating a pod in the container orchestration service.

func (*TaskContainerCreationOptions) GetFamily

GetFamily returns the family name for the cloud pod definition to be used for these container creation options.

func (*TaskContainerCreationOptions) Hash

Hash returns the hash digest of the creation options for the container. This is used to create a pod definition, which acts as a template for the actual pod that will run the container.

func (TaskContainerCreationOptions) IsZero

IsZero implements the bsoncodec.Zeroer interface for the sake of defining the zero value for BSON marshalling.

type TaskIntentPodOptions

type TaskIntentPodOptions struct {
	// ID is the pod identifier. If unspecified, it defaults to a new BSON
	// object ID.
	ID string

	CPU                 int
	MemoryMB            int
	OS                  OS
	Arch                Arch
	WindowsVersion      WindowsVersion
	Image               string
	RepoCredsExternalID string
	WorkingDir          string
	PodSecretExternalID string
	PodSecretValue      string
}

TaskIntentPodOptions represents options to create an intent pod that runs container tasks.

func (*TaskIntentPodOptions) Validate

func (o *TaskIntentPodOptions) Validate(ecsConf evergreen.ECSConfig) error

Validate checks that the options to create a task intent pod are valid and sets defaults if possible.

type TaskRuntimeInfo

type TaskRuntimeInfo struct {
	// RunningTaskID is the ID of the task currently running on the pod.
	RunningTaskID string `bson:"running_task_id,omitempty" json:"running_task_id,omitempty"`
	// RunningTaskExecution is the execution number of the task currently
	// running on the pod.
	RunningTaskExecution int `bson:"running_task_execution,omitempty" json:"running_task_execution,omitempty"`
}

TaskRuntimeInfo contains information for pods running tasks about the tasks that it is running or has run previously.

func (TaskRuntimeInfo) IsZero

func (i TaskRuntimeInfo) IsZero() bool

IsZero implements the bsoncodec.Zeroer interface for the sake of defining the zero value for BSON marshalling.

type TimeInfo

type TimeInfo struct {
	// Initializing is the time when this pod was initialized and is waiting to
	// be created in the container orchestration service. This should correspond
	// with the time when the pod transitions to the "initializing" status.
	Initializing time.Time `bson:"initializing,omitempty" json:"initializing,omitempty"`
	// Starting is the time when this pod was actually requested to start its
	// containers. This should correspond with the time when the pod transitions
	// to the "starting" status.
	Starting time.Time `bson:"starting,omitempty" json:"starting,omitempty"`
	// LastCommunicated is the last time that the pod connected to the
	// application server or the application server connected to the pod. This
	// is used as one indicator of liveliness.
	LastCommunicated time.Time `bson:"last_communicated,omitempty" json:"last_communicated,omitempty"`
	// AgentStarted is the time that the agent initiated first contact with the
	// application server. This only applies to agent pods.
	AgentStarted time.Time `bson:"agent_started,omitempty" json:"agent_started,omitempty"`
}

TimeInfo represents timing information about the pod.

func (TimeInfo) IsZero

func (i TimeInfo) IsZero() bool

IsZero implements the bsoncodec.Zeroer interface for the sake of defining the zero value for BSON marshalling.

type Type

type Type string

Type is the type of pod.

const (
	// TypeAgent indicates that it is a pod that is running the Evergreen agent
	// in a container.
	TypeAgent Type = "agent"
)

type WindowsVersion

type WindowsVersion string

WindowsVersion represents a specific version of Windows that a pod is allowed to run on. This only applies to pods running Windows containers.

const (
	// WindowsVersionServer2016 indicates that a pod is compatible to run on an
	// instance that is running Windows Server 2016.
	WindowsVersionServer2016 WindowsVersion = "SERVER_2016"
	// WindowsVersionServer2016 indicates that a pod is compatible to run on an
	// instance that is running Windows Server 2019.
	WindowsVersionServer2019 WindowsVersion = "SERVER_2019"
	// WindowsVersionServer2016 indicates that a pod is compatible to run on an
	// instance that is running Windows Server 2022.
	WindowsVersionServer2022 WindowsVersion = "SERVER_2022"
)

func ImportWindowsVersion

func ImportWindowsVersion(winVer evergreen.WindowsVersion) (WindowsVersion, error)

ImportWindowsVersion converts the container Windows version into its equivalent pod Windows version.

func (WindowsVersion) Matches

Matches returns whether or not the pod Windows Version matches the given Evergreen ECS config Windows version.

func (WindowsVersion) Validate

func (v WindowsVersion) Validate() error

Validate checks that the pod Windows version is recognized.

Directories

Path Synopsis
Package definition contains the data model for the pod definition cache.
Package definition contains the data model for the pod definition cache.
Package dispatcher models a queue of tasks that are dispatched to a group of pods.
Package dispatcher models a queue of tasks that are dispatched to a group of pods.

Jump to

Keyboard shortcuts

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