podtest

package
v0.0.0-...-86fc13e Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	MockDefaultCpu    = "1m"
	MockDefaultMemory = "1M"
)
View Source
const (
	PodAnnotationCpuStartup             = "3m"
	PodAnnotationCpuPostStartupRequests = "1m"
	PodAnnotationCpuPostStartupLimits   = "2m"

	PodAnnotationMemoryStartup             = "3M"
	PodAnnotationMemoryPostStartupRequests = "1M"
	PodAnnotationMemoryPostStartupLimits   = "2M"

	PodAnnotationCpuUnknown    = "999m"
	PodAnnotationMemoryUnknown = "999M"
)
View Source
const (
	DefaultPodNamespace                  = "namespace"
	DefaultPodName                       = "name"
	DefaultLabelEnabledValue             = "true"
	DefaultAnnotationTargetContainerName = DefaultContainerName
	DefaultStatusContainerName           = DefaultContainerName
)
View Source
const (
	DefaultContainerName = "container"
)

Variables

View Source
var (
	DefaultContainerCpuResizePolicy    = v1.NotRequired
	DefaultContainerMemoryResizePolicy = v1.NotRequired
)
View Source
var (
	MockDefaultCpuQuantity    = resource.MustParse(MockDefaultCpu)
	MockDefaultMemoryQuantity = resource.MustParse(MockDefaultMemory)
)
View Source
var (
	PodAnnotationCpuStartupQuantity             = resource.MustParse(PodAnnotationCpuStartup)
	PodAnnotationCpuPostStartupRequestsQuantity = resource.MustParse(PodAnnotationCpuPostStartupRequests)
	PodAnnotationCpuPostStartupLimitsQuantity   = resource.MustParse(PodAnnotationCpuPostStartupLimits)

	PodAnnotationMemoryStartupQuantity             = resource.MustParse(PodAnnotationMemoryStartup)
	PodAnnotationMemoryPostStartupRequestsQuantity = resource.MustParse(PodAnnotationMemoryPostStartupRequests)
	PodAnnotationMemoryPostStartupLimitsQuantity   = resource.MustParse(PodAnnotationMemoryPostStartupLimits)

	PodAnnotationCpuUnknownQuantity    = resource.MustParse(PodAnnotationCpuUnknown)
	PodAnnotationMemoryUnknownQuantity = resource.MustParse(PodAnnotationMemoryUnknown)
)
View Source
var (
	DefaultPodNamespacedName = types.NamespacedName{
		Namespace: DefaultPodNamespace,
		Name:      DefaultPodName,
	}
	DefaultPodStatusContainerState = corev1.ContainerState{Running: &corev1.ContainerStateRunning{}}
	DefaultPodStatusResize         = corev1.PodResizeStatus("")
)

Functions

func ControllerRuntimeFakeClientWithKubeFake

func ControllerRuntimeFakeClientWithKubeFake(
	fakeClientFunc func() *kubefake.Clientset,
	interceptorFuncsFunc func() interceptor.Funcs,
) client.WithWatch

ControllerRuntimeFakeClientWithKubeFake returns a fake client configured using the clientset and interceptor.Funcs as built from the supplied fakeClientFunc and interceptorFuncsFunc.

func InterceptorFuncGetFail

func InterceptorFuncGetFail(withError ...error) func(_ context.Context, _ client.WithWatch, _ client.ObjectKey, _ client.Object, _ ...client.GetOption) error

InterceptorFuncGetFail returns an interceptor get function that fails. Returns withError if supplied, otherwise an error with an empty message.

func InterceptorFuncGetFailFirstOnly

func InterceptorFuncGetFailFirstOnly(withFirstError ...error) func(_ context.Context, _ client.WithWatch, _ client.ObjectKey, _ client.Object, _ ...client.GetOption) error

InterceptorFuncGetFailFirstOnly returns an interceptor get function that fails on the first invocation only. Returns withError if supplied, otherwise an error with an empty message.

func InterceptorFuncPatchFail

func InterceptorFuncPatchFail(withError ...error) func(_ context.Context, _ client.WithWatch, _ client.Object, _ client.Patch, _ ...client.PatchOption) error

InterceptorFuncPatchFail returns an interceptor patch function that fails. Returns withError if supplied, otherwise an error with an empty message.

func InterceptorFuncPatchFailFirstOnly

func InterceptorFuncPatchFailFirstOnly(withFirstError ...error) func(_ context.Context, _ client.WithWatch, _ client.Object, _ client.Patch, _ ...client.PatchOption) error

InterceptorFuncPatchFailFirstOnly returns an interceptor patch function that fails on the first invocation only. Returns withError if supplied, otherwise an error with an empty message.

func InterceptorFuncSubResourcePatchFail

func InterceptorFuncSubResourcePatchFail(withError ...error) func(_ context.Context, _ client.Client, _ string, _ client.Object, _ client.Patch, _ ...client.SubResourcePatchOption) error

InterceptorFuncSubResourcePatchFail returns an interceptor subresource patch function that fails. Returns withError if supplied, otherwise an error with an empty message.

func InterceptorFuncSubResourcePatchFailFirstOnly

func InterceptorFuncSubResourcePatchFailFirstOnly(withFirstError ...error) func(_ context.Context, _ client.Client, _ string, _ client.Object, _ client.Patch, _ ...client.SubResourcePatchOption) error

InterceptorFuncSubResourcePatchFailFirstOnly returns an interceptor subresource patch function that fails on the first invocation only. Returns withError if supplied, otherwise an error with an empty message.

func NewContainerBuilder

func NewContainerBuilder(config containerConfig) *containerBuilder

func NewPodBuilder

func NewPodBuilder(config podConfig) *podBuilder

func NewPostStartupContainerConfig

func NewPostStartupContainerConfig() containerConfig

func NewPostStartupPodConfig

func NewPostStartupPodConfig(stateStarted podcommon.StateBool, stateReady podcommon.StateBool) podConfig

func NewStartupContainerConfig

func NewStartupContainerConfig() containerConfig

func NewStartupPodConfig

func NewStartupPodConfig(stateStarted podcommon.StateBool, stateReady podcommon.StateBool) podConfig

func NewUnknownContainerConfig

func NewUnknownContainerConfig() containerConfig

func NewUnknownPodConfig

func NewUnknownPodConfig(stateStarted podcommon.StateBool, stateReady podcommon.StateBool) podConfig

Types

type MockContainerKubeHelper

type MockContainerKubeHelper struct {
	mock.Mock
}

MockContainerKubeHelper is a generic mock for pod.ContainerKubeHelper.

func NewMockContainerKubeHelper

func NewMockContainerKubeHelper(configFunc func(*MockContainerKubeHelper)) *MockContainerKubeHelper

func (*MockContainerKubeHelper) CurrentLimits

func (m *MockContainerKubeHelper) CurrentLimits(
	pod *v1.Pod,
	containerName string,
	resourceName v1.ResourceName,
) (resource.Quantity, error)

func (*MockContainerKubeHelper) CurrentLimitsDefault

func (m *MockContainerKubeHelper) CurrentLimitsDefault()

func (*MockContainerKubeHelper) CurrentRequests

func (m *MockContainerKubeHelper) CurrentRequests(
	pod *v1.Pod,
	containerName string,
	resourceName v1.ResourceName,
) (resource.Quantity, error)

func (*MockContainerKubeHelper) CurrentRequestsDefault

func (m *MockContainerKubeHelper) CurrentRequestsDefault()

func (*MockContainerKubeHelper) Get

func (m *MockContainerKubeHelper) Get(pod *v1.Pod, containerName string) (*v1.Container, error)

func (*MockContainerKubeHelper) GetDefault

func (m *MockContainerKubeHelper) GetDefault()

func (*MockContainerKubeHelper) HasReadinessProbe

func (m *MockContainerKubeHelper) HasReadinessProbe(container *v1.Container) bool

func (*MockContainerKubeHelper) HasReadinessProbeDefault

func (m *MockContainerKubeHelper) HasReadinessProbeDefault()

func (*MockContainerKubeHelper) HasStartupProbe

func (m *MockContainerKubeHelper) HasStartupProbe(container *v1.Container) bool

func (*MockContainerKubeHelper) HasStartupProbeDefault

func (m *MockContainerKubeHelper) HasStartupProbeDefault()

func (*MockContainerKubeHelper) IsReady

func (m *MockContainerKubeHelper) IsReady(pod *v1.Pod, containerName string) (bool, error)

func (*MockContainerKubeHelper) IsReadyDefault

func (m *MockContainerKubeHelper) IsReadyDefault()

func (*MockContainerKubeHelper) IsStarted

func (m *MockContainerKubeHelper) IsStarted(pod *v1.Pod, containerName string) (bool, error)

func (*MockContainerKubeHelper) IsStartedDefault

func (m *MockContainerKubeHelper) IsStartedDefault()

func (*MockContainerKubeHelper) Limits

func (m *MockContainerKubeHelper) Limits(container *v1.Container, resourceName v1.ResourceName) resource.Quantity

func (*MockContainerKubeHelper) LimitsDefault

func (m *MockContainerKubeHelper) LimitsDefault()

func (*MockContainerKubeHelper) Requests

func (m *MockContainerKubeHelper) Requests(container *v1.Container, resourceName v1.ResourceName) resource.Quantity

func (*MockContainerKubeHelper) RequestsDefault

func (m *MockContainerKubeHelper) RequestsDefault()

func (*MockContainerKubeHelper) ResizePolicy

func (m *MockContainerKubeHelper) ResizePolicy(
	container *v1.Container,
	resourceName v1.ResourceName,
) (v1.ResourceResizeRestartPolicy, error)

func (*MockContainerKubeHelper) ResizePolicyDefault

func (m *MockContainerKubeHelper) ResizePolicyDefault()

func (*MockContainerKubeHelper) State

func (m *MockContainerKubeHelper) State(pod *v1.Pod, containerName string) (v1.ContainerState, error)

func (*MockContainerKubeHelper) StateDefault

func (m *MockContainerKubeHelper) StateDefault()

type MockKubeHelper

type MockKubeHelper struct {
	mock.Mock
}

MockKubeHelper is a generic mock for pod.KubeHelper.

func NewMockKubeHelper

func NewMockKubeHelper(configFunc func(*MockKubeHelper)) *MockKubeHelper

func (*MockKubeHelper) ExpectedAnnotationValueAs

func (m *MockKubeHelper) ExpectedAnnotationValueAs(pod *v1.Pod, name string, as podcommon.Type) (any, error)

func (*MockKubeHelper) ExpectedAnnotationValueAsDefault

func (m *MockKubeHelper) ExpectedAnnotationValueAsDefault()

func (*MockKubeHelper) ExpectedLabelValueAs

func (m *MockKubeHelper) ExpectedLabelValueAs(pod *v1.Pod, name string, as podcommon.Type) (any, error)

func (*MockKubeHelper) ExpectedLabelValueAsDefault

func (m *MockKubeHelper) ExpectedLabelValueAsDefault()

func (*MockKubeHelper) Get

func (*MockKubeHelper) GetDefault

func (m *MockKubeHelper) GetDefault()

func (*MockKubeHelper) HasAnnotation

func (m *MockKubeHelper) HasAnnotation(pod *v1.Pod, name string) (bool, string)

func (*MockKubeHelper) HasAnnotationDefault

func (m *MockKubeHelper) HasAnnotationDefault()

func (*MockKubeHelper) IsContainerInSpec

func (m *MockKubeHelper) IsContainerInSpec(pod *v1.Pod, containerName string) bool

func (*MockKubeHelper) IsContainerInSpecDefault

func (m *MockKubeHelper) IsContainerInSpecDefault()

func (*MockKubeHelper) Patch

func (m *MockKubeHelper) Patch(
	ctx context.Context,
	originalPod *v1.Pod,
	mutatePodFunc func(*v1.Pod) (bool, *v1.Pod, error),
	patchResize bool,
	mustSyncCache bool,
) (*v1.Pod, error)

func (*MockKubeHelper) PatchDefault

func (m *MockKubeHelper) PatchDefault()

func (*MockKubeHelper) ResizeStatus

func (m *MockKubeHelper) ResizeStatus(pod *v1.Pod) v1.PodResizeStatus

func (*MockKubeHelper) ResizeStatusDefault

func (m *MockKubeHelper) ResizeStatusDefault()

func (*MockKubeHelper) UpdateContainerResources

func (m *MockKubeHelper) UpdateContainerResources(
	ctx context.Context,
	pod *v1.Pod,
	containerName string,
	cpuRequests resource.Quantity, cpuLimits resource.Quantity,
	memoryRequests resource.Quantity, memoryLimits resource.Quantity,
	addPodMutationFunc func(pod *v1.Pod) (bool, *v1.Pod, error),
	addPodMutationMustSyncCache bool,
) (*v1.Pod, error)

func (*MockKubeHelper) UpdateContainerResourcesDefault

func (m *MockKubeHelper) UpdateContainerResourcesDefault()

type MockScaleConfig

type MockScaleConfig struct {
	mock.Mock
}

MockScaleConfig is a generic mock for podcommon.ScaleConfig.

func NewMockScaleConfig

func NewMockScaleConfig(configFunc func(*MockScaleConfig)) *MockScaleConfig

func (*MockScaleConfig) GetCpuConfig

func (m *MockScaleConfig) GetCpuConfig() podcommon.CpuConfig

func (*MockScaleConfig) GetCpuConfigDefault

func (m *MockScaleConfig) GetCpuConfigDefault()

func (*MockScaleConfig) GetMemoryConfig

func (m *MockScaleConfig) GetMemoryConfig() podcommon.MemoryConfig

func (*MockScaleConfig) GetMemoryConfigDefault

func (m *MockScaleConfig) GetMemoryConfigDefault()

func (*MockScaleConfig) GetTargetContainerName

func (m *MockScaleConfig) GetTargetContainerName() string

func (*MockScaleConfig) GetTargetContainerNameDefault

func (m *MockScaleConfig) GetTargetContainerNameDefault()

func (*MockScaleConfig) StoreFromAnnotations

func (m *MockScaleConfig) StoreFromAnnotations(pod *v1.Pod) error

func (*MockScaleConfig) StoreFromAnnotationsDefault

func (m *MockScaleConfig) StoreFromAnnotationsDefault()

func (*MockScaleConfig) String

func (m *MockScaleConfig) String() string

func (*MockScaleConfig) StringDefault

func (m *MockScaleConfig) StringDefault()

func (*MockScaleConfig) Validate

func (m *MockScaleConfig) Validate() error

func (*MockScaleConfig) ValidateDefault

func (m *MockScaleConfig) ValidateDefault()

type MockStatus

type MockStatus struct {
	mock.Mock
}

MockStatus is a generic mock for pod.Status.

func NewMockStatus

func NewMockStatus(configFunc func(*MockStatus)) *MockStatus

func NewMockStatusWithRun

func NewMockStatusWithRun(configFunc func(*MockStatus, func()), run func()) *MockStatus

func (*MockStatus) PodMutationFunc

func (m *MockStatus) PodMutationFunc(
	ctx context.Context,
	status string,
	states podcommon.States,
	scaleState podcommon.StatusScaleState,
) func(pod *v1.Pod) (bool, *v1.Pod, error)

func (*MockStatus) PodMutationFuncDefault

func (m *MockStatus) PodMutationFuncDefault()

func (*MockStatus) PodMutationFuncDefaultAndRun

func (m *MockStatus) PodMutationFuncDefaultAndRun(run func())

func (*MockStatus) Update

func (m *MockStatus) Update(
	ctx context.Context,
	pod *v1.Pod,
	status string,
	states podcommon.States,
	scaleState podcommon.StatusScaleState,
) (*v1.Pod, error)

func (*MockStatus) UpdateDefault

func (m *MockStatus) UpdateDefault()

func (*MockStatus) UpdateDefaultAndRun

func (m *MockStatus) UpdateDefaultAndRun(run func())

type MockTargetContainerAction

type MockTargetContainerAction struct {
	mock.Mock
}

MockTargetContainerAction is a generic mock for pod.TargetContainerAction.

func NewMockTargetContainerAction

func NewMockTargetContainerAction(configFunc func(*MockTargetContainerAction)) *MockTargetContainerAction

func (*MockTargetContainerAction) Execute

func (m *MockTargetContainerAction) Execute(
	ctx context.Context,
	states podcommon.States,
	pod *v1.Pod,
	config podcommon.ScaleConfig,
) error

func (*MockTargetContainerAction) ExecuteDefault

func (m *MockTargetContainerAction) ExecuteDefault()

type MockTargetContainerState

type MockTargetContainerState struct {
	mock.Mock
}

MockTargetContainerState is a generic mock for pod.TargetContainerState.

func NewMockTargetContainerState

func NewMockTargetContainerState(configFunc func(*MockTargetContainerState)) *MockTargetContainerState

func (*MockTargetContainerState) States

func (*MockTargetContainerState) StatesDefault

func (m *MockTargetContainerState) StatesDefault()

type MockValidation

type MockValidation struct {
	mock.Mock
}

MockValidation is a generic mock for pod.Validation.

func NewMockValidation

func NewMockValidation(configFunc func(*MockValidation)) *MockValidation

func (*MockValidation) Validate

func (m *MockValidation) Validate(
	ctx context.Context,
	pod *v1.Pod,
	scaleConfigToPopulate podcommon.ScaleConfig,
	afterScaleConfigPopulatedFunc func(podcommon.ScaleConfig),
) error

func (*MockValidation) ValidateDefault

func (m *MockValidation) ValidateDefault()

Jump to

Keyboard shortcuts

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