kube

package
v0.0.0-...-e889ff3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 46 Imported by: 8

Documentation

Overview

Copyright 2023 The Kanister Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// DefaultPodReadyWaitTimeout is the time to wait for pod to be ready
	DefaultPodReadyWaitTimeout = 15 * time.Minute
	// PodReadyWaitTimeoutEnv is the env var to get pod ready wait timeout
	PodReadyWaitTimeoutEnv = "KANISTER_POD_READY_WAIT_TIMEOUT"

	DefaultContainerName = "container"
)
View Source
const (
	PodNSEnvVar = "POD_NAMESPACE"
	PodSAEnvVar = "POD_SERVICE_ACCOUNT"
)
View Source
const (
	// FDZoneLabelName is a known k8s label. used to specify volume zone
	FDZoneLabelName = "failure-domain.beta.kubernetes.io/zone"
	// TopologyZoneLabelName is a known k8s label. used to specify volume zone for kubernetes 1.17 onwards
	TopologyZoneLabelName = "topology.kubernetes.io/zone"
	// FDRegionLabelName is a known k8s label
	FDRegionLabelName = "failure-domain.beta.kubernetes.io/region"
	// TopologyRegionLabelName is a known k8s label. used to specify volume region for kubernetes 1.17 onwards
	TopologyRegionLabelName = "topology.kubernetes.io/region"

	// LocationSecretVolumeMountName is the name of location secret volume mount
	LocationSecretVolumeMountName = "location-secret"
	// LocationSecretMountPath is the path where location secret would be mounted
	LocationSecretMountPath = "/mnt/secrets/location"
)
View Source
const (
	// RevisionAnnotation is the revision annotation of a deployment's replica sets which records its rollout sequence
	RevisionAnnotation = "deployment.kubernetes.io/revision"

	// ReplicationControllerRevisionAnnotation is annotation of deploymentconfig's repliationcontroller
	ReplicationControllerRevisionAnnotation = "openshift.io/deployment-config.latest-version"
)

Variables

View Source
var (
	ErrPodControllerNotInitialized    = errors.New("pod has not been initialized")
	ErrPodControllerPodAlreadyStarted = errors.New("pod has already been started")
	ErrPodControllerPodNotReady       = errors.New("pod is not yet ready")
	ErrPodControllerPodNotStarted     = errors.New("pod is not yet started")
	PodControllerDefaultStopTime      = 30 * time.Second
	PodControllerInfiniteStopTime     = 0 * time.Second
)

Functions

func AddLabelsToPodOptionsFromContext

func AddLabelsToPodOptionsFromContext(
	ctx context.Context,
	options *PodOptions,
	targetKey string,
)

AddLabelsToPodOptionsFromContext adds a label to `PodOptions`. It extracts the value from the context if targetKey is present and assigns to the options.

func ConfigNamespace

func ConfigNamespace() (string, error)

ConfigNamespace returns the namespace from config

func ContainerNameFromPodOptsOrDefault

func ContainerNameFromPodOptsOrDefault(po *PodOptions) string

ContainerNameFromPodOptsOrDefault returns the container name if it's set in the passed `podOptions` value. If not, it's returns the default container name. This should be used whenever we create pods for Kanister functions.

func CreateAndMergeJsonPatch

func CreateAndMergeJsonPatch(original, override crv1alpha1.JSONMap) (crv1alpha1.JSONMap, error)

CreateAndMergeJsonPatch uses Strategic Merge to merge two Pod spec configuration

func CreateConfigMap

func CreateConfigMap(ctx context.Context, cli kubernetes.Interface, namespace string, spec string) (*corev1.ConfigMap, error)

CreateConfigMap creates a configmap set from a yaml spec.

func CreateDeployment

func CreateDeployment(ctx context.Context, cli kubernetes.Interface, namespace string, spec string) (*appsv1.Deployment, error)

CreateDeployment creates a deployment set from a yaml spec.

func CreatePod

func CreatePod(ctx context.Context, cli kubernetes.Interface, opts *PodOptions) (*corev1.Pod, error)

CreatePod creates a pod with a single container based on the specified image

func CreateStatefulSet

func CreateStatefulSet(ctx context.Context, cli kubernetes.Interface, namespace string, spec string) (*appsv1.StatefulSet, error)

CreateStatefulSet creates a stateful set from a yaml spec.

func DeletePod

func DeletePod(ctx context.Context, cli kubernetes.Interface, pod *corev1.Pod) error

DeletePod deletes the specified pod

func DeploymentConfigPods

func DeploymentConfigPods(ctx context.Context, osCli osversioned.Interface, kubeCli kubernetes.Interface, namespace, name string) ([]corev1.Pod, []corev1.Pod, error)

DeploymentConfigPods return list of running and not running pod created by this/name deployment config

func DeploymentConfigReady

func DeploymentConfigReady(ctx context.Context, osCli osversioned.Interface, cli kubernetes.Interface, namespace, name string) (bool, error)

DeploymentConfigReady checks to see the deploymentconfig has desired number of available replicas.

func DeploymentConfigReplicas

func DeploymentConfigReplicas(ctx context.Context, osCli osversioned.Interface, namespace, name string) (int32, error)

func DeploymentConfigVolumes

func DeploymentConfigVolumes(osCli osversioned.Interface, depConfig *osAppsv1.DeploymentConfig, pod *corev1.Pod) (volNameToPvc map[string]string)

DeploymentConfigVolumes returns the PVCs references by a pod in this deployment config as a [pod spec volume name]-> [PVC name] map will mostly be used for the applications running in open shift clusters

func DeploymentPods

func DeploymentPods(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) ([]corev1.Pod, []corev1.Pod, error)

DeploymentPods returns list of running and notrunning pods created by the deployment.

func DeploymentReady

func DeploymentReady(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) (bool, string, error)

DeploymentReady checks to see if the deployment has the desired number of available replicas.

func DeploymentReplicas

func DeploymentReplicas(ctx context.Context, kubeCli kubernetes.Interface, namespace, name string) (int32, error)

func DeploymentVolumes

func DeploymentVolumes(cli kubernetes.Interface, d *appsv1.Deployment) (volNameToPvc map[string]string)

DeploymentVolumes returns the PVCs referenced by this deployment as a [pods spec volume name]->[PVC name] map

func Exec

func Exec(cli kubernetes.Interface, namespace, pod, container string, command []string, stdin io.Reader) (string, string, error)

Exec is our version of the call to `kubectl exec` that does not depend on k8s.io/kubernetes.

func ExecOutput

func ExecOutput(cli kubernetes.Interface, namespace, pod, container string, command []string, stdin io.Reader, stdout, stderr io.Writer) error

ExecOutput is similar to Exec, except that inbound outputs are written to the provided stdout and stderr. Unlike Exec, the outputs are not returned to the caller.

func ExecWithOptions

func ExecWithOptions(kubeCli kubernetes.Interface, options ExecOptions) error

ExecWithOptions executes a command in the specified container, returning an error. `options` allowed for additional parameters to be passed.

func FetchPods

func FetchPods(cli kubernetes.Interface, namespace string, uid types.UID) (runningPods []corev1.Pod, notRunningPods []corev1.Pod, err error)

FetchPods fetches the pods matching the specified owner UID and splits them into 2 groups (running/not-running)

func FetchReplicaSet

func FetchReplicaSet(cli kubernetes.Interface, namespace string, uid types.UID, revision string) (*appsv1.ReplicaSet, error)

FetchReplicaSet fetches the replicaset matching the specified owner UID

func FetchReplicationController

func FetchReplicationController(cli kubernetes.Interface, namespace string, uid types.UID, revision string) (*corev1.ReplicationController, error)

FetchReplicationController fetches the replication controller that has owner with UID provided uid

func FetchUnstructuredObject

func FetchUnstructuredObject(ctx context.Context, resource schema.GroupVersionResource, namespace, name string) (runtime.Unstructured, error)

FetchUnstructuredObject returns the referenced API object as a map[string]interface{}

func FetchUnstructuredObjectWithCli

func FetchUnstructuredObjectWithCli(ctx context.Context, cli dynamic.Interface, resource schema.GroupVersionResource, namespace, name string) (runtime.Unstructured, error)

FetchUnstructuredObjectWithCli returns the referenced API object as a map[string]interface{} using the specified CLI TODO: deprecate `FetchUnstructuredObject`

func GetControllerNamespace

func GetControllerNamespace() (string, error)

GetControllerNamespace returns controller namespace

func GetControllerPodName

func GetControllerPodName() (string, error)

GetControllerPodName returns controller pod name

func GetControllerServiceAccount

func GetControllerServiceAccount(k8sclient kubernetes.Interface) (string, error)

GetControllerServiceAccount returns controller ServiceAccount

func GetPodContainerFromDeployment

func GetPodContainerFromDeployment(ctx context.Context, cli kubernetes.Interface, namespace, deployName string) (podName string, containerName string, err error)

GetPodContainerFromDeployment returns a pod and container running the deployment

func GetPodContainerFromDeploymentConfig

func GetPodContainerFromDeploymentConfig(ctx context.Context, osCli osversioned.Interface, cli kubernetes.Interface, namespace, deployConfigName string) (podName, containerName string, err error)

GetPodContainerFromDeploymentConfig returns a pod and container that is running from the provided deployment config

func GetPodContainerFromStatefulSet

func GetPodContainerFromStatefulSet(ctx context.Context, cli kubernetes.Interface, namespace, ssName string) (podName string, containerName string, err error)

GetPodContainerFromStatefulSet returns a pod and container running the stateful set

func GetPodLogs

func GetPodLogs(ctx context.Context, cli kubernetes.Interface, namespace, podName, containerName string) (string, error)

GetPodLogs fetches the logs from the given pod

func GetPodObjectFromPodOptions

func GetPodObjectFromPodOptions(ctx context.Context, cli kubernetes.Interface, opts *PodOptions) (*corev1.Pod, error)

func GetPodReadyWaitTimeout

func GetPodReadyWaitTimeout() time.Duration

GetPodReadyWaitTimeout returns the pod ready wait timeout from ENV if configured returns the default of 15 minutes otherwise

func GetRegionFromLabels

func GetRegionFromLabels(labels map[string]string) string

func GetRegionFromNode

func GetRegionFromNode(node corev1.Node) string

func GetRegionFromPV

func GetRegionFromPV(pv corev1.PersistentVolume) string

func GetZoneFromLabels

func GetZoneFromLabels(labels map[string]string) string

func GetZoneFromNode

func GetZoneFromNode(node corev1.Node) string

func GetZoneFromPV

func GetZoneFromPV(pv corev1.PersistentVolume) string

func IsGroupVersionAvailable

func IsGroupVersionAvailable(ctx context.Context, cli discovery.DiscoveryInterface, groupName, version string) (bool, error)

IsGroupVersionAvailable returns true if given group/version is registered.

func IsNodeReady

func IsNodeReady(node *corev1.Node) bool

IsNodeReady returns true if it's Ready condition is set to true Derived from "k8s.io/kubernetes/test/e2e/framework/node"

func IsNodeSchedulable

func IsNodeSchedulable(node *corev1.Node) bool

IsNodeSchedulable returns true if it doesn't have "unschedulable" field set Derived from "k8s.io/kubernetes/test/e2e/framework/node"

func IsOSAppsGroupAvailable

func IsOSAppsGroupAvailable(ctx context.Context, cli discovery.DiscoveryInterface) (bool, error)

IsOSAppsGroupAvailable returns true if the openshift apps group is registered in service discovery.

func IsOSRouteGroupAvailable

func IsOSRouteGroupAvailable(ctx context.Context, cli discovery.DiscoveryInterface) (bool, error)

IsOSRouteGroupAvailable returns true is the openshift route group is registered in service discovery

func IsPodRunning

func IsPodRunning(cli kubernetes.Interface, podName, podNamespace string) (bool, error)

IsPodRunning checks if the provided pod is ready or not

func IsResAvailableInGroupVersion

func IsResAvailableInGroupVersion(ctx context.Context, cli discovery.DiscoveryInterface, groupName, version, resource string) (bool, error)

IsResAvailableInGroupVersion takes a resource and checks if that exists in the passed group and version

func ListUnstructuredObject

func ListUnstructuredObject(resource schema.GroupVersionResource, namespace string) (runtime.Unstructured, error)

ListUnstructuredObject returns the referenced API objects as a map[string]interface{}

func ListUnstructuredObjectWithCli

func ListUnstructuredObjectWithCli(cli dynamic.Interface, resource schema.GroupVersionResource, namespace string) (runtime.Unstructured, error)

ListUnstructuredObjectWithCli returns the referenced API objects as a map[string]interface{} using the specified CLI TODO: deprecate `ListUnstructuredObject`

func LoadConfig

func LoadConfig() (*rest.Config, error)

LoadConfig returns a kubernetes client config based on global settings.

func NewCRDClient

func NewCRDClient() (crdclient.Interface, error)

NewCRDClient returns a Dynamic client configured by the Kanister environment.

func NewClient

func NewClient() (kubernetes.Interface, error)

NewClient returns a k8 client configured by the kanister environment.

func NewDynamicClient

func NewDynamicClient() (dynamic.Interface, error)

NewDynamicClient returns a Dynamic client configured by the Kanister environment.

func PVCContainsReadOnlyAccessMode

func PVCContainsReadOnlyAccessMode(pvc *corev1.PersistentVolumeClaim) bool

PVCContainsReadOnlyAccessMode return true if AccessModes of PVC contain `ReadOnlyMany`

func PodContainers

func PodContainers(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) ([]corev1.Container, error)

PodContainers returns list of containers specified by the pod

func ScaleDeployment

func ScaleDeployment(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string, replicas int32, waitForReady bool) error

func ScaleDeploymentConfig

func ScaleDeploymentConfig(ctx context.Context, kubeCli kubernetes.Interface, osCli osversioned.Interface, namespace string, name string, replicas int32, waitForReady bool) error

func ScaleStatefulSet

func ScaleStatefulSet(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string, replicas int32, waitForReady bool) error

func StatefulSetPods

func StatefulSetPods(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) ([]corev1.Pod, []corev1.Pod, error)

StatefulSetPods returns list of running and notrunning pods created by the deployment.

func StatefulSetReady

func StatefulSetReady(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) (bool, string, error)

StatefulSetReady checks if a statefulset has the desired number of ready replicas.

func StatefulSetReplicas

func StatefulSetReplicas(ctx context.Context, kubeCli kubernetes.Interface, namespace, name string) (int32, error)

func StatefulSetVolumes

func StatefulSetVolumes(cli kubernetes.Interface, sset *appsv1.StatefulSet, pod *corev1.Pod) (volNameToPvc map[string]string)

StatefulSetVolumes returns the PVCs referenced by a pod in this statefulset as a [pod spec volume name]->[PVC name] map

func StreamPodLogs

func StreamPodLogs(ctx context.Context, cli kubernetes.Interface, namespace, podName, containerName string) (io.ReadCloser, error)

func WaitForPodCompletion

func WaitForPodCompletion(ctx context.Context, cli kubernetes.Interface, namespace, name string) error

WaitForPodCompletion waits for a pod to reach a terminal state, or timeout

func WaitForPodReady

func WaitForPodReady(ctx context.Context, cli kubernetes.Interface, namespace, name string) error

WaitForPodReady waits for a pod to exit the pending state

func WaitOnDeploymentConfigReady

func WaitOnDeploymentConfigReady(ctx context.Context, osCli osversioned.Interface, kubeCli kubernetes.Interface, namespace, name string) error

WaitOnDeploymentConfigReady waits for deploymentconfig to be ready

func WaitOnDeploymentReady

func WaitOnDeploymentReady(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) error

WaitOnDeploymentReady waits for the deployment to be ready

func WaitOnStatefulSetReady

func WaitOnStatefulSetReady(ctx context.Context, kubeCli kubernetes.Interface, namespace string, name string) error

WaitOnStatefulSetReady waits for the stateful set to be ready

Types

type ExecError

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

ExecError is an error returned by kube.Exec, kube.ExecOutput and kube.ExecWithOptions. It contains not only error happened during an execution, but also keeps tails of stdout/stderr streams. These tails could be used by the invoker to construct more precise error.

func NewExecError

func NewExecError(err error, stdout, stderr LogTail) *ExecError

NewExecError creates an instance of ExecError

func (*ExecError) Error

func (e *ExecError) Error() string

func (*ExecError) Stderr

func (e *ExecError) Stderr() string

func (*ExecError) Stdout

func (e *ExecError) Stdout() string

func (*ExecError) Unwrap

func (e *ExecError) Unwrap() error

type ExecOptions

type ExecOptions struct {
	Command []string

	Namespace     string
	PodName       string
	ContainerName string

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

ExecOptions passed to ExecWithOptions

type FakePodCommandExecutor

type FakePodCommandExecutor struct {
	ExecErr error

	ExecStdout string
	ExecStderr string
	// contains filtered or unexported fields
}

func (*FakePodCommandExecutor) Exec

func (fce *FakePodCommandExecutor) Exec(_ context.Context, command []string, stdin io.Reader, stdout, stderr io.Writer) error

Exec

type FakePodController

type FakePodController struct {
	Podname string
	PodObj  *corev1.Pod

	StartPodCalled bool
	StartPodErr    error

	WaitForPodReadyCalled bool
	WaitForPodReadyErr    error

	GetCommandExecutorRet PodCommandExecutor
	GetCommandExecutorErr error

	GetFileWriterCalled bool
	GetFileWriterRet    *FakePodFileWriter
	GetFileWriterErr    error

	StopPodCalled        bool
	StopPodErr           error
	InStopPodStopTimeout time.Duration
	InStopPodGracePeriod int64
}

func (*FakePodController) GetCommandExecutor

func (fpc *FakePodController) GetCommandExecutor() (PodCommandExecutor, error)

func (*FakePodController) GetFileWriter

func (fpc *FakePodController) GetFileWriter() (PodFileWriter, error)

func (*FakePodController) Pod

func (fpc *FakePodController) Pod() *corev1.Pod

func (*FakePodController) PodName

func (fpc *FakePodController) PodName() string

func (*FakePodController) Run

func (fpc *FakePodController) Run(ctx context.Context, fn func(context.Context, *corev1.Pod) (map[string]interface{}, error)) (map[string]interface{}, error)

func (*FakePodController) StartPod

func (fpc *FakePodController) StartPod(_ context.Context) error

func (*FakePodController) StopPod

func (fpc *FakePodController) StopPod(ctx context.Context, stopTimeout time.Duration, gracePeriodSeconds int64) error

func (*FakePodController) StreamPodLogs

func (fpc *FakePodController) StreamPodLogs(_ context.Context) (io.ReadCloser, error)

func (*FakePodController) WaitForPodCompletion

func (fpc *FakePodController) WaitForPodCompletion(_ context.Context) error

func (*FakePodController) WaitForPodReady

func (fpc *FakePodController) WaitForPodReady(_ context.Context) error

type FakePodControllerProcessor

type FakePodControllerProcessor struct {
	InWaitForPodReadyNamespace string
	InWaitForPodReadyPodName   string
	WaitForPodReadyErr         error

	InWaitForPodCompletionNamespace string
	InWaitForPodCompletionPodName   string
	WaitForPodCompletionErr         error

	InDeletePodNamespace string
	InDeletePodPodName   string
	InDeletePodOptions   metav1.DeleteOptions
	DeletePodErr         error

	InCreatePodOptions *PodOptions
	CreatePodRet       *corev1.Pod
	CreatePodErr       error
}

FakePodControllerProcessor implements PodControllerProcessor

func (*FakePodControllerProcessor) CreatePod

func (f *FakePodControllerProcessor) CreatePod(_ context.Context, options *PodOptions) (*corev1.Pod, error)

func (*FakePodControllerProcessor) DeletePod

func (f *FakePodControllerProcessor) DeletePod(_ context.Context, namespace string, podName string, opts metav1.DeleteOptions) error

func (*FakePodControllerProcessor) WaitForPodCompletion

func (f *FakePodControllerProcessor) WaitForPodCompletion(_ context.Context, namespace, podName string) error

func (*FakePodControllerProcessor) WaitForPodReady

func (f *FakePodControllerProcessor) WaitForPodReady(_ context.Context, namespace, podName string) error

type FakePodFileRemover

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

func (*FakePodFileRemover) Path

func (fr *FakePodFileRemover) Path() string

func (*FakePodFileRemover) Remove

func (fr *FakePodFileRemover) Remove(_ context.Context) error

type FakePodFileWriter

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

func (*FakePodFileWriter) Write

func (fpfw *FakePodFileWriter) Write(_ context.Context, filePath string, content io.Reader) (PodFileRemover, error)

type KubectlOperation

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

KubectlOperation implements methods to perform kubectl operations

func NewKubectlOperations

func NewKubectlOperations(dynCli dynamic.Interface) *KubectlOperation

NewKubectlOperations returns new KubectlOperations object

func (*KubectlOperation) Create

func (k *KubectlOperation) Create(spec io.Reader, namespace string) (*crv1alpha1.ObjectReference, error)

Create k8s resource from spec manifest

func (*KubectlOperation) Delete

Delete k8s resource referred by objectReference. Waits for the resource to be deleted

type LogTail

type LogTail interface {
	Write(p []byte) (int, error)
	ToString() string
}

LogTail interface allows to store last N lines of log written to it

func NewLogTail

func NewLogTail(len int) LogTail

NewLogTail creates logTail struct containing circular buffer for storing `len` last lines of log written through Write method

type Operation

type Operation string

Operation represents kubectl operation

const (
	// CreateOperation represents kubectl create operation
	CreateOperation Operation = "create"
	// DeleteOperation represents kubectl delete operation
	DeleteOperation Operation = "delete"
)

type PodCommandExecutor

type PodCommandExecutor interface {
	Exec(ctx context.Context, command []string, stdin io.Reader, stdout, stderr io.Writer) error
}

PodCommandExecutor provides a way to execute a command within the pod. Is intended to be returned by PodController and works with pod controlled by it.

type PodCommandExecutorProcessor

type PodCommandExecutorProcessor interface {
	ExecWithOptions(opts ExecOptions) error
}

PodCommandExecutorProcessor is an interface wrapping kubernetes API invocation it is purposed to be replaced by fake implementation in tests

type PodController

type PodController interface {
	PodName() string
	Pod() *corev1.Pod
	StartPod(ctx context.Context) error
	WaitForPodReady(ctx context.Context) error
	WaitForPodCompletion(ctx context.Context) error
	StopPod(ctx context.Context, timeout time.Duration, gracePeriodSeconds int64) error

	StreamPodLogs(ctx context.Context) (io.ReadCloser, error)

	GetCommandExecutor() (PodCommandExecutor, error)
	GetFileWriter() (PodFileWriter, error)
}

PodController specifies interface needed for starting, stopping pod and operations with it

The purpose of this interface is to provide single mechanism of pod manipulation, reduce number of parameters which caller needs to pass (since we keep pod related things internally) and eliminate human errors.

func NewPodController

func NewPodController(cli kubernetes.Interface, options *PodOptions, opts ...PodControllerOption) PodController

NewPodController returns a new PodController given Kubernetes Client and PodOptions

func NewPodControllerForExistingPod

func NewPodControllerForExistingPod(cli kubernetes.Interface, pod *corev1.Pod) (PodController, error)

NewPodControllerForExistingPod returns a new PodController for the given running pod. Invocation of StartPod of returned PodController instance will fail, since the pod is expected to be running already. Note: If the pod is not in the ready state, it will wait for up to KANISTER_POD_READY_WAIT_TIMEOUT (15 minutes by default) until the pod becomes ready.

type PodControllerOption

type PodControllerOption func(p *podController)

func WithPodControllerProcessor

func WithPodControllerProcessor(processor PodControllerProcessor) PodControllerOption

WithPodControllerProcessor provides mechanism for passing fake implementation of PodControllerProcessor for testing purposes.

type PodControllerProcessor

type PodControllerProcessor interface {
	CreatePod(ctx context.Context, options *PodOptions) (*corev1.Pod, error)
	WaitForPodReady(ctx context.Context, namespace, podName string) error
	WaitForPodCompletion(ctx context.Context, namespace, podName string) error
	DeletePod(ctx context.Context, namespace string, podName string, opts metav1.DeleteOptions) error
}

PodControllerProcessor is an interface wrapping kubernetes API invocation it is purposed to be replaced by fake implementation in tests

type PodFileRemover

type PodFileRemover interface {
	Remove(ctx context.Context) error
	Path() string
}

PodFileRemover provides mechanism for removing particular file written to the pod by PodFileWriter.

type PodFileWriter

type PodFileWriter interface {
	Write(ctx context.Context, filePath string, content io.Reader) (PodFileRemover, error)
}

PodFileWriter provides a way to write a file to the pod. Is intended to be returned by PodController and works with pod controlled by it.

type PodFileWriterProcessor

type PodFileWriterProcessor interface {
	NewPodWriter(filePath string, content io.Reader) PodWriter
}

PodFileWriterProcessor is an interface wrapping kubernetes API invocation it is purposed to be replaced by fake implementation in tests

type PodOptions

type PodOptions struct {
	Annotations        map[string]string
	Command            []string
	ContainerName      string
	Name               string
	GenerateName       string
	Image              string
	Labels             map[string]string
	Namespace          string
	ServiceAccountName string
	Volumes            map[string]VolumeMountOptions
	BlockVolumes       map[string]string
	// PodSecurityContext and ContainerSecurityContext can be used to set the security context
	// at the pod level and container level respectively.
	// You can still use podOverride to set the pod security context, but these fields will take precedence.
	// We chose these fields to specify security context instead of just using podOverride because
	// the merge behaviour of the pods spec is confusing in case of podOverride, and this is more readable.
	PodSecurityContext       *corev1.PodSecurityContext
	ContainerSecurityContext *corev1.SecurityContext
	PodOverride              crv1alpha1.JSONMap
	Resources                corev1.ResourceRequirements
	RestartPolicy            corev1.RestartPolicy
	OwnerReferences          []metav1.OwnerReference
	EnvironmentVariables     []corev1.EnvVar
	Lifecycle                *corev1.Lifecycle
}

PodOptions specifies options for `CreatePod`

type PodRunner

type PodRunner interface {
	// Run creates pod using the PodController interface and forwards it to the functor.
	// Pod will be deleted as soon as functor exits.
	Run(ctx context.Context, fn func(context.Context, PodController) (map[string]interface{}, error)) (map[string]interface{}, error)
}

PodRunner allows us to start / stop pod, write file to pod and execute command within it

func NewPodRunner

func NewPodRunner(cli kubernetes.Interface, options *PodOptions) PodRunner

NewPodRunner returns a new PodRunner given Kubernetes Client and PodOptions

func NewPodRunnerWithPodController

func NewPodRunnerWithPodController(pc PodController) PodRunner

NewPodRunnerWithPodController returns a new PodRunner given PodController object This provides mechanism for passing fake PodControllerProcessor through PodController for testing purposes.

type PodWriter

type PodWriter interface {
	// Write will create a new file(if not present) and write the provided content to the file
	Write(ctx context.Context, namespace, podName, containerName string) error
	// Remove will delete the file created by Write() func
	Remove(ctx context.Context, namespace, podName, containerName string) error
}

PodWriter specifies interface needed for manipulating files in a pod

func NewPodWriter

func NewPodWriter(cli kubernetes.Interface, path string, content io.Reader) PodWriter

NewPodWriter returns a new PodWriter given Kubernetes Client, path of file and content

type VolumeMountOptions

type VolumeMountOptions struct {
	MountPath string
	ReadOnly  bool
}

Directories

Path Synopsis
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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