pods

package
v0.0.0-...-a4d1c61 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RestartPolicyNever is used to indicate that a pod won't be restarted.
	RestartPolicyNever = RestartPolicy(corev1.RestartPolicyNever)

	// RestartPolicyAlways is used to indicate that a pod always will be restarted.
	RestartPolicyAlways = RestartPolicy(corev1.RestartPolicyAlways)

	// RestartPolicyOnFailure is used to indicate that a pod will be restarted only on failures.
	RestartPolicyOnFailure = RestartPolicy(corev1.RestartPolicyOnFailure)
)
View Source
const (
	// HostPathUnset is used for backwards compatibility, leave it empty if unset.
	HostPathUnset = HostPathType(corev1.HostPathUnset)

	// HostPathDirectoryOrCreate should be set if nothing exists at the given path, an empty directory will be created
	// there as needed with file mode 0755.
	HostPathDirectoryOrCreate = HostPathType(corev1.HostPathDirectoryOrCreate)
)
View Source
const (
	// EnvVarSourcePodIP is used to identify the Pod IP source when getting env vars.
	EnvVarSourcePodIP = "status.podIP"
)
View Source
const (
	// ResourceMemory represents a Memory resource for a container.
	// (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
	ResourceMemory = ResourceName(corev1.ResourceMemory)
)

Variables

View Source
var (
	// ErrPodHasNoIP is returned when Pods.GetIP method is called and there's no IP assigned to the pod.
	ErrPodHasNoIP = errors.New("pod has no ip")

	// ErrMissingPods is returned when an empty list of pods is returned while waiting for them to be ready.
	ErrMissingPods = errors.New("missing pods")
)

Functions

This section is empty.

Types

type Container

type Container struct {
	// Name is the container's name.
	Name string

	// Image is the OCI image that this container will run.
	Image string

	// Command is the entrypoint array. It's not executed within a shell.
	// The docker image's ENTRYPOINT is used if this is not provided. Cannot be updated.
	Command []string

	// Args passed to the Command. Cannot be updated.
	Args []string

	// Privileged defines if the container should run in privileged mode.
	Privileged *bool

	// AllowPrivilegeEscalation is used to define if the container is allowed to scale its privileges.
	AllowPrivilegeEscalation *bool

	// Ports is the list of ports that should be opened.
	Ports []int32

	// Volumes is the list of volumes that should be mounted in the container.
	Volumes []Volume

	// EnvVars is the list of env vars that should be passed into the container.
	EnvVars map[string]string

	// EnvVars is the list of env vars that should be gotten before passing them into the container.
	EnvVarsFrom map[string]string

	// ResourceRequests defines the minimum resources required for this container to run.
	ResourceRequests map[ResourceName]string

	// ResourceLimits defines the maximum amount of resources this container can use.
	ResourceLimits map[ResourceName]string
}

Container is a represents of a standard unit of software.

func NewChownContainer

func NewChownContainer(uid, gid uint, volumes ...Volume) Container

NewChownContainer generates an init container that sets the owner of volume mount directories to a specific user and group.

type CreatePodInput

type CreatePodInput struct {
	// Name is the name of the pod that will be created.
	Name string

	// Namespace is the namespace where the pod will live in.
	Namespace string

	// Labels are the map of labels that will be applied to the pod.
	Labels map[string]string

	// ImagePullCredentials contains the names or paths of credentials used to pull OCI images from a container
	// registry.
	// For Kubernetes, this is equivalent to a pod's ImagePullSecrets.
	ImagePullCredentials []string

	// RestartPolicy defines how the pod should react after an error.
	RestartPolicy RestartPolicy

	// TerminationGracePeriodSeconds is the time duration in seconds the pod needs to terminate gracefully.
	TerminationGracePeriodSeconds time.Duration

	// NodeSelector defines the node where the pod should run in.
	NodeSelector resource.Selector

	// InitContainers is the list of containers that are created during pod initialization.
	// Init containers are launched before Containers, and are typically used to initialize the pod.
	InitContainers []Container

	// Containers is the list of containers that should be created inside the pod.
	Containers []Container

	// Volumes are the list of volumes that will be created to persist the data from the Container.Volumes.
	Volumes []Volume

	// Nameservers are the list of DNS Nameservers that will be used to expose the pod to the internet.
	Nameservers []string
}

CreatePodInput is the input of Pods.Create method.

type Executor

type Executor interface {
	// Cmd runs a command inside a container.
	Cmd(container string, command []string) error
	// Script runs a script inside a container.
	// Could be used to run copy_to_s3.sh
	Script(container, path string) error
}

Executor groups a set of methods to run commands and scripts inside a Pod.

type HostPathType

type HostPathType corev1.HostPathType

HostPathType defines the host path type used for volumes.

type PodResource

PodResource is a Resource used to represent pods. It's composed by a set of interfaces to expose data about a pod.

type Pods

type Pods interface {
	Create(ctx context.Context, input CreatePodInput) (*PodResource, error)
	Exec(ctx context.Context, resource resource.Resource) Executor
	Reader(ctx context.Context, resource resource.Resource) Reader
	WaitForCondition(ctx context.Context, resource resource.Resource, condition ...resource.Condition) waiter.Waiter
	Delete(ctx context.Context, resource resource.Resource) (resource.Resource, error)
	Get(ctx context.Context, name, namespace string) (*PodResource, error)
	GetIP(ctx context.Context, name string, namespace string) (string, error)
	List(ctx context.Context, namespace string, selector resource.Selector) ([]PodResource, error)
}

Pods groups a set of methods to perform an operation with a Pod.

type Reader

type Reader interface {
	File(ctx context.Context, container string, paths ...string) (*bytes.Buffer, error)
	Logs(ctx context.Context, container string, lines int64) (string, error)
}

Reader groups a set of methods to read files and logs from a Pod.

type ResourceName

type ResourceName corev1.ResourceName

ResourceName is the name of a certain pod resource like memory or cpu.

type RestartPolicy

type RestartPolicy corev1.RestartPolicy

RestartPolicy defines a restart policy used for pods.

type Volume

type Volume interface {
	// Base contains generic information about the volume.
	Base() VolumeBase
}

Volume is a storage that can be mounted to allow a Container to access its data.

type VolumeBase

type VolumeBase struct {
	// Name contains the name of the volume.
	Name string

	// MountPath is the path within the container at which the volume should be mounted.
	MountPath string

	// SubPath is an optional path within the mounted volume from which the container's volume should be mounted.
	// If not defined, the volume root will be used.
	SubPath string

	// ReadOnly indicates whether the volume should be mounted in read-only mode. Defaults to false.
	ReadOnly bool
}

VolumeBase implements a base Volume. It is intended to be embedded in Volume type implementations.

func (VolumeBase) Base

func (v VolumeBase) Base() VolumeBase

Base contains generic information about the volume.

type VolumeConfiguration

type VolumeConfiguration struct {
	VolumeBase

	// ConfigurationName is the name of the configuration file to mount.
	ConfigurationName string

	// Items optionally defines the specific set of configuration entries to mount.
	// Keys indicate the items to mount, while values indicate where to mount them inside the volume.
	// If not defined the configuration will be mounted as a directory, with a file for each entry where the key of the
	// entry is the file name and the value the contents of the file.
	Items map[string]string
}

VolumeConfiguration is a Volume implementation that mounts the contents of a configuration inside a container.

type VolumeHostPath

type VolumeHostPath struct {
	VolumeBase

	// HostPath represents a pre-existing file or directory on the host machine that is directly exposed to the
	// container.
	HostPath string

	// HostPathType defines the mount type and mounting behavior.
	HostPathType HostPathType
}

VolumeHostPath is a Volume implementation that mounts a directory in the host machine inside a container.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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