pod

package
v0.0.0-...-cb2e96d Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: Apache-2.0 Imports: 27 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllowedSCList list of allowed SecurityCapabilities.
	AllowedSCList = []string{"NET_RAW", "NET_ADMIN", "SYS_ADMIN", "IPC_LOCK", "ALL"}
)

Functions

func GetGVR

GetGVR returns pod's GroupVersionResource which could be used for Clean function.

func StaticAnnotation

func StaticAnnotation(name string) *multus.NetworkSelectionElement

StaticAnnotation defines network annotation for pod object.

func StaticIPAnnotation

func StaticIPAnnotation(name string, ipAddr []string) []*multus.NetworkSelectionElement

StaticIPAnnotation defines static ip address network annotation for pod object.

func StaticIPAnnotationWithInterfaceAndNamespace

func StaticIPAnnotationWithInterfaceAndNamespace(
	name, namespace, intName string, ipAddr []string) []*multus.NetworkSelectionElement

StaticIPAnnotationWithInterfaceAndNamespace defines static ip address, interface name and namespace network annotation for pod object.

func StaticIPAnnotationWithInterfaceMacAndNamespace

func StaticIPAnnotationWithInterfaceMacAndNamespace(
	name, namespace, intName, macAddr string) []*multus.NetworkSelectionElement

StaticIPAnnotationWithInterfaceMacAndNamespace defines static ip address and namespace, interface name, mac address network annotation for pod object.

func StaticIPAnnotationWithMacAddress

func StaticIPAnnotationWithMacAddress(name string, ipAddr []string, macAddr string) []*multus.NetworkSelectionElement

StaticIPAnnotationWithMacAddress defines static ip address and static macaddress network annotation for pod object.

func StaticIPAnnotationWithMacAndNamespace

func StaticIPAnnotationWithMacAndNamespace(name, namespace, macAddr string) []*multus.NetworkSelectionElement

StaticIPAnnotationWithMacAndNamespace defines static ip address and namespace, mac address network annotation for pod object.

func StaticIPAnnotationWithNamespace

func StaticIPAnnotationWithNamespace(name, namespace string, ipAddr []string) []*multus.NetworkSelectionElement

StaticIPAnnotationWithNamespace defines static ip address and namespace network annotation for pod object.

func StaticIPBondAnnotationWithInterface

func StaticIPBondAnnotationWithInterface(
	bondNadName, bondIntName string, sriovNetworkNameList, ipAddrBond []string) []*multus.NetworkSelectionElement

StaticIPBondAnnotationWithInterface defines static name for bonded interfaces and name, interface and IP for the main bond int.

func StaticIPMultiNetDualStackAnnotation

func StaticIPMultiNetDualStackAnnotation(sriovNets, ipAddr []string) ([]*multus.NetworkSelectionElement, error)

StaticIPMultiNetDualStackAnnotation defines network annotation for multiple interfaces with dual stack addresses.

func WaitForAllPodsInNamespaceRunning

func WaitForAllPodsInNamespaceRunning(
	apiClient *clients.Settings,
	nsname string,
	timeout time.Duration,
	options ...metav1.ListOptions) (bool, error)

WaitForAllPodsInNamespaceRunning wait until all pods in namespace that match options are in running state.

func WaitForAllPodsInNamespacesHealthy

func WaitForAllPodsInNamespacesHealthy(
	apiClient *clients.Settings,
	nsNames []string,
	timeout time.Duration,
	includeSucceeded bool,
	skipReadinessCheck bool,
	ignoreRestartPolicyNever bool,
	ignoreNamespaces []string,
	options ...metav1.ListOptions,
) error

WaitForAllPodsInNamespacesHealthy waits until: - all pods in a list of namespaces that match options are in healthy state. - a pod in a healthy state is in running phase and optionally in ready condition.

nsNames passes the list of namespaces to monitor. Monitors all namespaces when empty. timeout is the duration in seconds to wait for the pods to be healthy includeSucceeded when true, considers that pods in succeeded phase are healthy. skipReadiness when false, checks that the podCondition is ready. ignoreRestartPolicyNever when true, ignores failed pods with restart policy set to never. ignoreNamespaces is a list of namespaces to ignore. options reduces the list of namespace to only the ones matching options.

Types

type AdditionalOptions

type AdditionalOptions func(builder *Builder) (*Builder, error)

AdditionalOptions additional options for pod object.

type Builder

type Builder struct {
	// Pod definition, used to create the pod object.
	Definition *corev1.Pod
	// Created pod object.
	Object *corev1.Pod
	// contains filtered or unexported fields
}

Builder provides a struct for pod object from the cluster and a pod definition.

func List

func List(apiClient *clients.Settings, nsname string, options ...metav1.ListOptions) ([]*Builder, error)

List returns pod inventory in the given namespace.

func ListByNamePattern

func ListByNamePattern(apiClient *clients.Settings, namePattern, nsname string) ([]*Builder, error)

ListByNamePattern returns pod inventory in the given namespace filtered by name pattern.

func ListInAllNamespaces

func ListInAllNamespaces(apiClient *clients.Settings, options ...metav1.ListOptions) ([]*Builder, error)

ListInAllNamespaces returns a cluster-wide pod inventory.

func NewBuilder

func NewBuilder(apiClient *clients.Settings, name, nsname, image string) *Builder

NewBuilder creates a new instance of Builder.

func Pull

func Pull(apiClient *clients.Settings, name, nsname string) (*Builder, error)

Pull loads an existing pod into the Builder struct.

func (*Builder) Copy

func (builder *Builder) Copy(path, containerName string, tar bool) (bytes.Buffer, error)

Copy returns the contents of a file or path from a specified container into a buffer. Setting the tar option returns a tar archive of the specified path.

func (*Builder) Create

func (builder *Builder) Create() (*Builder, error)

Create makes a pod according to the pod definition and stores the created object in the pod builder.

func (*Builder) CreateAndWaitUntilRunning

func (builder *Builder) CreateAndWaitUntilRunning(timeout time.Duration) (*Builder, error)

CreateAndWaitUntilRunning creates the pod object and waits until the pod is running.

func (*Builder) DefineOnNode

func (builder *Builder) DefineOnNode(nodeName string) *Builder

DefineOnNode adds nodeName to the pod's definition.

func (*Builder) Delete

func (builder *Builder) Delete() (*Builder, error)

Delete removes the pod object and resets the builder object.

func (*Builder) DeleteAndWait

func (builder *Builder) DeleteAndWait(timeout time.Duration) (*Builder, error)

DeleteAndWait deletes the pod object and waits until the pod is deleted.

func (*Builder) DeleteImmediate

func (builder *Builder) DeleteImmediate() (*Builder, error)

DeleteImmediate removes the pod immediately and resets the builder object.

func (*Builder) ExecCommand

func (builder *Builder) ExecCommand(command []string, containerName ...string) (bytes.Buffer, error)

ExecCommand runs command in the pod and returns the buffer output.

func (*Builder) Exists

func (builder *Builder) Exists() bool

Exists checks whether the given pod exists.

func (*Builder) GetFullLog

func (builder *Builder) GetFullLog(containerName string) (string, error)

GetFullLog connects to a pod and fetches the full log since pod creation.

func (*Builder) GetLog

func (builder *Builder) GetLog(logStartTime time.Duration, containerName string) (string, error)

GetLog connects to a pod and fetches log.

func (*Builder) PullImage

func (builder *Builder) PullImage(timeout time.Duration, testCmd []string) error

PullImage pulls image for given pod's container and removes it.

func (*Builder) RedefineDefaultCMD

func (builder *Builder) RedefineDefaultCMD(command []string) *Builder

RedefineDefaultCMD redefines default command in pod's definition.

func (*Builder) RedefineDefaultContainer

func (builder *Builder) RedefineDefaultContainer(container corev1.Container) *Builder

RedefineDefaultContainer redefines default container with the new one.

func (*Builder) WaitUntilCondition

func (builder *Builder) WaitUntilCondition(condition corev1.PodConditionType, timeout time.Duration) error

WaitUntilCondition waits for the duration of the defined timeout or until the pod gets to a specific condition.

func (*Builder) WaitUntilDeleted

func (builder *Builder) WaitUntilDeleted(timeout time.Duration) error

WaitUntilDeleted waits for the duration of the defined timeout or until the pod is deleted.

func (*Builder) WaitUntilHealthy

func (builder *Builder) WaitUntilHealthy(timeout time.Duration, includeSucceeded, skipReadinessCheck,
	ignoreRestartPolicyNever bool) error

WaitUntilHealthy waits for the duration of the defined timeout or until the pod is healthy. A healthy pod is in running phase and optionally in ready condition.

timeout is the duration to wait for the pod to be healthy includeSucceeded when true, implies that pod in succeeded phase is running. skipReadinessCheck when false, checks that the podCondition is ready. ignoreRestartPolicyNever when true, Ignores failed pods with restart policy set to never.

func (*Builder) WaitUntilInOneOfStatuses

func (builder *Builder) WaitUntilInOneOfStatuses(statuses []corev1.PodPhase,
	timeout time.Duration) (*corev1.PodPhase, error)

WaitUntilInOneOfStatuses waits for the duration of the defined timeout or until the pod gets to any specific status in a list of statues.

func (*Builder) WaitUntilInStatus

func (builder *Builder) WaitUntilInStatus(status corev1.PodPhase, timeout time.Duration) error

WaitUntilInStatus waits for the duration of the defined timeout or until the pod gets to a specific status.

func (*Builder) WaitUntilReady

func (builder *Builder) WaitUntilReady(timeout time.Duration) error

WaitUntilReady waits for the duration of the defined timeout or until the pod reaches the Ready condition.

func (*Builder) WaitUntilRunning

func (builder *Builder) WaitUntilRunning(timeout time.Duration) error

WaitUntilRunning waits for the duration of the defined timeout or until the pod is running.

func (*Builder) WithAdditionalContainer

func (builder *Builder) WithAdditionalContainer(container *corev1.Container) *Builder

WithAdditionalContainer appends additional container to pod.

func (*Builder) WithAdditionalInitContainer

func (builder *Builder) WithAdditionalInitContainer(container *corev1.Container) *Builder

WithAdditionalInitContainer appends additional init container to pod.

func (*Builder) WithHostNetwork

func (builder *Builder) WithHostNetwork() *Builder

WithHostNetwork applies HostNetwork to pod's definition.

func (*Builder) WithHostPid

func (builder *Builder) WithHostPid(hostPid bool) *Builder

WithHostPid configures a pod's access to the host process ID namespace based on a boolean parameter.

func (*Builder) WithHugePages

func (builder *Builder) WithHugePages() *Builder

WithHugePages sets hugePages on all containers inside the pod.

func (*Builder) WithLabel

func (builder *Builder) WithLabel(labelKey, labelValue string) *Builder

WithLabel applies label to pod's definition.

func (*Builder) WithLabels

func (builder *Builder) WithLabels(labels map[string]string) *Builder

WithLabels applies a set of labels to a Pod's definition.

func (*Builder) WithLocalVolume

func (builder *Builder) WithLocalVolume(volumeName, mountPath string) *Builder

WithLocalVolume attaches given volume to all pod's containers.

func (*Builder) WithNodeSelector

func (builder *Builder) WithNodeSelector(nodeSelector map[string]string) *Builder

WithNodeSelector adds a nodeSelector configuration inside the pod.

func (*Builder) WithOptions

func (builder *Builder) WithOptions(options ...AdditionalOptions) *Builder

WithOptions creates pod with generic mutation options.

func (*Builder) WithPrivilegedFlag

func (builder *Builder) WithPrivilegedFlag() *Builder

WithPrivilegedFlag sets privileged flag on all containers.

func (*Builder) WithRestartPolicy

func (builder *Builder) WithRestartPolicy(restartPolicy corev1.RestartPolicy) *Builder

WithRestartPolicy applies restart policy to pod's definition.

func (*Builder) WithSecondaryNetwork

func (builder *Builder) WithSecondaryNetwork(network []*multus.NetworkSelectionElement) *Builder

WithSecondaryNetwork applies Multus secondary network on pod definition.

func (*Builder) WithSecurityContext

func (builder *Builder) WithSecurityContext(securityContext *corev1.PodSecurityContext) *Builder

WithSecurityContext sets SecurityContext on pod definition.

func (*Builder) WithTerminationGracePeriodSeconds

func (builder *Builder) WithTerminationGracePeriodSeconds(terminationGracePeriodSeconds int64) *Builder

WithTerminationGracePeriodSeconds configures TerminationGracePeriodSeconds on the pod.

func (*Builder) WithToleration

func (builder *Builder) WithToleration(toleration corev1.Toleration) *Builder

WithToleration adds a toleration configuration inside the pod.

func (*Builder) WithTolerationToControlPlane

func (builder *Builder) WithTolerationToControlPlane() *Builder

WithTolerationToControlPlane sets toleration policy which allows pod to be running on control plane node.

func (*Builder) WithTolerationToMaster

func (builder *Builder) WithTolerationToMaster() *Builder

WithTolerationToMaster sets toleration policy which allows pod to be running on master node.

func (*Builder) WithVolume

func (builder *Builder) WithVolume(volume corev1.Volume) *Builder

WithVolume attaches given volume to a pod.

type ContainerBuilder

type ContainerBuilder struct {
	// contains filtered or unexported fields
}

ContainerBuilder provides a struct for container's object definition.

func NewContainerBuilder

func NewContainerBuilder(name, image string, cmd []string) *ContainerBuilder

NewContainerBuilder creates a new instance of ContainerBuilder.

func (*ContainerBuilder) GetContainerCfg

func (builder *ContainerBuilder) GetContainerCfg() (*corev1.Container, error)

GetContainerCfg returns Container struct.

func (*ContainerBuilder) WithCustomResourcesLimits

func (builder *ContainerBuilder) WithCustomResourcesLimits(resourceList corev1.ResourceList) *ContainerBuilder

WithCustomResourcesLimits applies custom resource limit struct on container.

func (*ContainerBuilder) WithCustomResourcesRequests

func (builder *ContainerBuilder) WithCustomResourcesRequests(resourceList corev1.ResourceList) *ContainerBuilder

WithCustomResourcesRequests applies custom resource requests struct on container.

func (*ContainerBuilder) WithDropSecurityCapabilities

func (builder *ContainerBuilder) WithDropSecurityCapabilities(sCapabilities []string, redefine bool) *ContainerBuilder

WithDropSecurityCapabilities drops SecurityCapabilities from the container definition.

func (*ContainerBuilder) WithEnvVar

func (builder *ContainerBuilder) WithEnvVar(name, value string) *ContainerBuilder

WithEnvVar adds environment variables to container.

func (*ContainerBuilder) WithImagePullPolicy

func (builder *ContainerBuilder) WithImagePullPolicy(pullPolicy corev1.PullPolicy) *ContainerBuilder

WithImagePullPolicy applies specific image pull policy on container.

func (*ContainerBuilder) WithPorts

func (builder *ContainerBuilder) WithPorts(ports []corev1.ContainerPort) *ContainerBuilder

WithPorts adds a list of ports to expose from the container.

func (*ContainerBuilder) WithResourceLimit

func (builder *ContainerBuilder) WithResourceLimit(hugePages, memory string, cpu int64) *ContainerBuilder

WithResourceLimit applies resource limit on container.

func (*ContainerBuilder) WithResourceRequest

func (builder *ContainerBuilder) WithResourceRequest(hugePages, memory string, cpu int64) *ContainerBuilder

WithResourceRequest applies resource request on container.

func (*ContainerBuilder) WithSecurityCapabilities

func (builder *ContainerBuilder) WithSecurityCapabilities(sCapabilities []string, redefine bool) *ContainerBuilder

WithSecurityCapabilities applies SecurityCapabilities to the container definition.

func (*ContainerBuilder) WithSecurityContext

func (builder *ContainerBuilder) WithSecurityContext(securityContext *corev1.SecurityContext) *ContainerBuilder

WithSecurityContext applies security Context on container.

func (*ContainerBuilder) WithVolumeMount

func (builder *ContainerBuilder) WithVolumeMount(volMount corev1.VolumeMount) *ContainerBuilder

WithVolumeMount adds a pod volume mount inside the container.

Jump to

Keyboard shortcuts

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