utils

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TestAPIInternalErr is an API internal server error meant to be used to mimic HTTP response code 500 for tests.
	TestAPIInternalErr = apierrors.NewInternalError(errors.New("fake internal error"))
)

Functions

func CheckGroveError

func CheckGroveError(t *testing.T, expectedError *groveerr.GroveError, actualErr error)

CheckGroveError checks that an actual error is a Grove error and further checks its underline cause, error code and operation.

func CreateDefaultFakeClient

func CreateDefaultFakeClient(existingObjects []client.Object) client.Client

CreateDefaultFakeClient creates a default client.Client without any configured reactions to errors.

func CreateFakeClientForObjects

func CreateFakeClientForObjects(getErr, createErr, patchErr, deleteErr *apierrors.StatusError, existingObjects []client.Object)

CreateFakeClientForObjects creates a fake client.Client with initial set of existing objects along with any expected errors for the Get, Create, Patch, and Delete client methods.

func CreateFakeClientForObjectsMatchingLabels

func CreateFakeClientForObjectsMatchingLabels(deleteErr, listErr *apierrors.StatusError, namespace string, targetObjectsGVK schema.GroupVersionKind, matchingLabels map[string]string, existingObjects ...client.Object) client.Client

CreateFakeClientForObjectsMatchingLabels creates a fake client.Client with initial set of existing objects along with any expected list and/or deleteAll errors for objects matching the given matching labels for the given GVK. If the matchingLabels is nil or empty then the deleteAll/list error will be recorded for all objects matching the GVK in the given namespace.

func SetupFakeClient

func SetupFakeClient(objects ...client.Object) client.WithWatch

SetupFakeClient creates a fake Kubernetes client with Grove CRDs and status subresources.

Types

type ClientMethod

type ClientMethod string

ClientMethod is a name of the method on client.Client for which an error is recorded.

const (
	// ClientMethodGet is the name of the Get method on client.Client.
	ClientMethodGet ClientMethod = "Get"
	// ClientMethodList is the name of the List method on client.Client.
	ClientMethodList ClientMethod = "List"
	// ClientMethodCreate is the name of the Create method on client.Client.
	ClientMethodCreate ClientMethod = "Create"
	// ClientMethodDelete is the name of the Delete method on client.Client.
	ClientMethodDelete ClientMethod = "Delete"
	// ClientMethodDeleteAll is the name of the DeleteAllOf method on client.Client.
	ClientMethodDeleteAll ClientMethod = "DeleteAll"
	// ClientMethodPatch is the name of the Patch method on client.Client.
	ClientMethodPatch ClientMethod = "Patch"
	// ClientMethodUpdate is the name of the Update method on client.Client.
	ClientMethodUpdate ClientMethod = "Update"
	// ClientMethodStatus is the name of the Status method on client.Client.StatusClient.
	ClientMethodStatus ClientMethod = "Status"
)

type FakeManager

type FakeManager struct {
	manager.Manager
	Client client.Client
	Scheme *runtime.Scheme
	Logger logr.Logger
}

FakeManager is a fake controller-runtime manager

func (*FakeManager) GetClient

func (f *FakeManager) GetClient() client.Client

GetClient returns the client registered with the fake manager

func (*FakeManager) GetLogger

func (f *FakeManager) GetLogger() logr.Logger

GetLogger returns the logger registered with the fake manager

func (FakeManager) GetScheme

func (f FakeManager) GetScheme() *runtime.Scheme

GetScheme returns the scheme registered with the fake manager

type PCLQOption

type PCLQOption func(*grovecorev1alpha1.PodClique)

PCLQOption is a function that modifies a PodClique for testing.

func WithPCLQAvailable

func WithPCLQAvailable() PCLQOption

WithPCLQAvailable sets the PodClique to a healthy state with MinAvailableBreached=False and PodCliqueScheduled=True.

func WithPCLQCurrentPCSGenerationHash

func WithPCLQCurrentPCSGenerationHash(pcsGenerationHash string) PCLQOption

WithPCLQCurrentPCSGenerationHash sets the CurrentPodCliqueSetGenerationHash in the PodClique status.

func WithPCLQMinAvailableBreached

func WithPCLQMinAvailableBreached() PCLQOption

WithPCLQMinAvailableBreached sets the PodClique to have MinAvailableBreached=True but scheduled.

func WithPCLQNoConditions

func WithPCLQNoConditions() PCLQOption

WithPCLQNoConditions removes all conditions from the PodClique status.

func WithPCLQNotScheduled

func WithPCLQNotScheduled() PCLQOption

WithPCLQNotScheduled sets the PodClique to be not scheduled.

func WithPCLQReplicaReadyStatus

func WithPCLQReplicaReadyStatus(ready int32) PCLQOption

WithPCLQReplicaReadyStatus sets specific ReadyReplicas count for PodClique without touching conditions.

func WithPCLQScheduledAndAvailable

func WithPCLQScheduledAndAvailable() PCLQOption

WithPCLQScheduledAndAvailable sets the PodClique to be both scheduled and available.

func WithPCLQScheduledButBreached

func WithPCLQScheduledButBreached() PCLQOption

WithPCLQScheduledButBreached sets the PodClique to be scheduled but with breached availability.

func WithPCLQTerminating

func WithPCLQTerminating() PCLQOption

WithPCLQTerminating marks the PodClique for termination with a DeletionTimestamp.

type PCSGOption

type PCSGOption func(*grovecorev1alpha1.PodCliqueScalingGroup)

PCSGOption is a function that modifies a PodCliqueScalingGroup for testing.

func WithPCSGAvailableReplicas

func WithPCSGAvailableReplicas(available int32) PCSGOption

WithPCSGAvailableReplicas sets specific AvailableReplicas count for PCSG without touching conditions.

func WithPCSGCurrentPCSGenerationHash

func WithPCSGCurrentPCSGenerationHash(pcsGenerationHash string) PCSGOption

WithPCSGCurrentPCSGenerationHash sets the CurrentPodCliqueSetGenerationHash in the PCSG status.

func WithPCSGMinAvailableBreached

func WithPCSGMinAvailableBreached() PCSGOption

WithPCSGMinAvailableBreached sets the PCSG to have MinAvailableBreached=True.

func WithPCSGObservedGeneration

func WithPCSGObservedGeneration(generation int64) PCSGOption

WithPCSGObservedGeneration sets the PCSG ObservedGeneration to enable status mutations.

func WithPCSGUnknownCondition

func WithPCSGUnknownCondition() PCSGOption

WithPCSGUnknownCondition sets the PCSG to have MinAvailableBreached=Unknown.

type PCSOption

type PCSOption func(*grovecorev1alpha1.PodCliqueSet)

PCSOption is a function that modifies a PodCliqueSet for testing.

type PodBuilder

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

PodBuilder is a builder for Pod objects.

func NewPodBuilder

func NewPodBuilder(name, namespace string) *PodBuilder

NewPodBuilder creates a new PodBuilder with the given name and namespace.

func NewPodWithBuilderWithDefaultSpec

func NewPodWithBuilderWithDefaultSpec(name, namespace string) *PodBuilder

NewPodWithBuilderWithDefaultSpec creates a new PodBuilder with a default spec.

func (*PodBuilder) Build

func (b *PodBuilder) Build() *corev1.Pod

Build builds and returns the Pod.

func (*PodBuilder) MarkForTermination

func (b *PodBuilder) MarkForTermination() *PodBuilder

MarkForTermination sets the DeletionTimestamp on the Pod.

func (*PodBuilder) WithCondition

func (b *PodBuilder) WithCondition(cond corev1.PodCondition) *PodBuilder

WithCondition adds a condition to the Pod's status.

func (*PodBuilder) WithLabels

func (b *PodBuilder) WithLabels(labels map[string]string) *PodBuilder

WithLabels adds labels to the Pod.

func (*PodBuilder) WithOwner

func (b *PodBuilder) WithOwner(ownerName string) *PodBuilder

WithOwner adds an owner reference to the Pod.

func (*PodBuilder) WithPhase

func (b *PodBuilder) WithPhase(phase corev1.PodPhase) *PodBuilder

WithPhase adds a pod phase to the Pod's status.

type PodCliqueBuilder

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

PodCliqueBuilder is a builder for creating PodClique objects. This should primarily be used for tests.

func NewPCSGPodCliqueBuilder

func NewPCSGPodCliqueBuilder(name, namespace, pcsName, pcsgName string, pcsReplicaIndex, pcsgReplicaIndex int) *PodCliqueBuilder

NewPCSGPodCliqueBuilder creates a PodClique that belongs to a PodCliqueScalingGroup.

func NewPodCliqueBuilder

func NewPodCliqueBuilder(pcsName string, pcsUID types.UID, pclqTemplateName, namespace string, pcsReplicaIndex int32) *PodCliqueBuilder

NewPodCliqueBuilder creates a new PodCliqueBuilder.

func (*PodCliqueBuilder) Build

Build creates a PodClique object.

func (*PodCliqueBuilder) WithAutoScaleMaxReplicas

func (b *PodCliqueBuilder) WithAutoScaleMaxReplicas(maximum int32) *PodCliqueBuilder

WithAutoScaleMaxReplicas sets the maximum replicas in ScaleConfig for the PodClique.

func (*PodCliqueBuilder) WithLabels

func (b *PodCliqueBuilder) WithLabels(labels map[string]string) *PodCliqueBuilder

WithLabels merges the passed labels with default labels. Passed in labels will overwrite default labels with the same keys.

func (*PodCliqueBuilder) WithOptions

func (b *PodCliqueBuilder) WithOptions(opts ...PCLQOption) *PodCliqueBuilder

WithOptions applies option functions to customize the PodClique.

func (*PodCliqueBuilder) WithOwnerReference

func (b *PodCliqueBuilder) WithOwnerReference(kind, name string, uid types.UID) *PodCliqueBuilder

WithOwnerReference sets the owner reference for the PodClique from individual values.

func (*PodCliqueBuilder) WithReplicas

func (b *PodCliqueBuilder) WithReplicas(replicas int32) *PodCliqueBuilder

WithReplicas sets the number of replicas for the PodClique. Default is set to 1.

func (*PodCliqueBuilder) WithStartsAfter

func (b *PodCliqueBuilder) WithStartsAfter(pclqTemplateNames []string) *PodCliqueBuilder

WithStartsAfter sets the StartsAfter field for the PodClique.

type PodCliqueScalingGroupBuilder

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

PodCliqueScalingGroupBuilder provides a fluent interface for building test PodCliqueScalingGroup objects.

func NewPodCliqueScalingGroupBuilder

func NewPodCliqueScalingGroupBuilder(name, namespace, pcsName string, pcsReplicaIndex int) *PodCliqueScalingGroupBuilder

NewPodCliqueScalingGroupBuilder creates a new PodCliqueScalingGroupBuilder with basic configuration.

func (*PodCliqueScalingGroupBuilder) Build

Build returns the constructed PodCliqueScalingGroup.

func (*PodCliqueScalingGroupBuilder) WithCliqueNames

func (b *PodCliqueScalingGroupBuilder) WithCliqueNames(cliqueNames []string) *PodCliqueScalingGroupBuilder

WithCliqueNames sets the CliqueNames field for the PodCliqueScalingGroup.

func (*PodCliqueScalingGroupBuilder) WithLabels

WithLabels adds labels to the PodCliqueScalingGroup.

func (*PodCliqueScalingGroupBuilder) WithMinAvailable

func (b *PodCliqueScalingGroupBuilder) WithMinAvailable(minAvailable int32) *PodCliqueScalingGroupBuilder

WithMinAvailable sets the MinAvailable field for the PodCliqueScalingGroup.

func (*PodCliqueScalingGroupBuilder) WithOptions

WithOptions applies option functions to customize the PodCliqueScalingGroup.

func (*PodCliqueScalingGroupBuilder) WithOwnerReference

func (b *PodCliqueScalingGroupBuilder) WithOwnerReference(kind, name, uid string) *PodCliqueScalingGroupBuilder

WithOwnerReference adds an owner reference to the PodCliqueScalingGroup.

func (*PodCliqueScalingGroupBuilder) WithReplicas

WithReplicas sets the number of replicas for the PodCliqueScalingGroup.

type PodCliqueSetBuilder

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

PodCliqueSetBuilder is a builder for PodCliqueSet objects.

func NewPodCliqueSetBuilder

func NewPodCliqueSetBuilder(name, namespace string, uid types.UID) *PodCliqueSetBuilder

NewPodCliqueSetBuilder creates a new PodCliqueSetBuilder.

func (*PodCliqueSetBuilder) Build

Build creates a PodCliqueSet object.

func (*PodCliqueSetBuilder) WithCliqueStartupType

func (b *PodCliqueSetBuilder) WithCliqueStartupType(startupType *grovecorev1alpha1.CliqueStartupType) *PodCliqueSetBuilder

WithCliqueStartupType sets the StartupType for the PodCliqueSet.

func (*PodCliqueSetBuilder) WithPodCliqueParameters

func (b *PodCliqueSetBuilder) WithPodCliqueParameters(name string, replicas int32, startsAfter []string) *PodCliqueSetBuilder

WithPodCliqueParameters is a convenience function that creates a PodCliqueTemplateSpec given the parameters and adds it to the PodCliqueSet.

func (*PodCliqueSetBuilder) WithPodCliqueScalingGroupConfig

func (b *PodCliqueSetBuilder) WithPodCliqueScalingGroupConfig(config grovecorev1alpha1.PodCliqueScalingGroupConfig) *PodCliqueSetBuilder

WithPodCliqueScalingGroupConfig adds a PodCliqueScalingGroupConfig to the PodCliqueSet.

func (*PodCliqueSetBuilder) WithPodCliqueSetGenerationHash

func (b *PodCliqueSetBuilder) WithPodCliqueSetGenerationHash(pcsGenerationHash *string) *PodCliqueSetBuilder

WithPodCliqueSetGenerationHash sets the CurrentGenerationHash in the PodCliqueSet status.

func (*PodCliqueSetBuilder) WithPodCliqueTemplateSpec

WithPodCliqueTemplateSpec sets the PodCliqueTemplateSpec for the PodCliqueSet. Consumers can use PodCliqueBuilder to create a PodCliqueTemplateSpec and then use this method to add it to the PodCliqueSet.

func (*PodCliqueSetBuilder) WithPriorityClassName

func (b *PodCliqueSetBuilder) WithPriorityClassName(priorityClassName string) *PodCliqueSetBuilder

WithPriorityClassName sets the PriorityClassName for the PodCliqueSet.

func (*PodCliqueSetBuilder) WithReplicas

func (b *PodCliqueSetBuilder) WithReplicas(replicas int32) *PodCliqueSetBuilder

WithReplicas sets the number of replicas for the PodCliqueSet.

func (*PodCliqueSetBuilder) WithScalingGroup

func (b *PodCliqueSetBuilder) WithScalingGroup(name string, cliqueNames []string) *PodCliqueSetBuilder

WithScalingGroup adds a scaling group with the specified cliques.

func (*PodCliqueSetBuilder) WithScalingGroupConfig

func (b *PodCliqueSetBuilder) WithScalingGroupConfig(name string, cliqueNames []string, replicas, minAvailable int32) *PodCliqueSetBuilder

WithScalingGroupConfig adds a scaling group with custom replicas and minAvailable.

func (*PodCliqueSetBuilder) WithStandaloneClique

func (b *PodCliqueSetBuilder) WithStandaloneClique(name string) *PodCliqueSetBuilder

WithStandaloneClique adds a standalone clique (not part of any scaling group).

func (*PodCliqueSetBuilder) WithStandaloneCliqueReplicas

func (b *PodCliqueSetBuilder) WithStandaloneCliqueReplicas(name string, replicas int32) *PodCliqueSetBuilder

WithStandaloneCliqueReplicas adds a standalone clique with specific replica count.

func (*PodCliqueSetBuilder) WithTerminationDelay

func (b *PodCliqueSetBuilder) WithTerminationDelay(duration time.Duration) *PodCliqueSetBuilder

WithTerminationDelay sets the TerminationDelay for the PodCliqueSet.

type PodCliqueTemplateSpecBuilder

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

PodCliqueTemplateSpecBuilder is a builder for creating PodCliqueTemplateSpec objects.

func NewPodCliqueTemplateSpecBuilder

func NewPodCliqueTemplateSpecBuilder(name string) *PodCliqueTemplateSpecBuilder

NewPodCliqueTemplateSpecBuilder creates a new PodCliqueTemplateSpecBuilder.

func (*PodCliqueTemplateSpecBuilder) Build

Build creates a PodCliqueTemplateSpec object.

func (*PodCliqueTemplateSpecBuilder) WithAutoScaleMaxReplicas

func (b *PodCliqueTemplateSpecBuilder) WithAutoScaleMaxReplicas(maximum int32) *PodCliqueTemplateSpecBuilder

WithAutoScaleMaxReplicas sets the maximum replicas in ScaleConfig for the PodClique.

func (*PodCliqueTemplateSpecBuilder) WithAutoScaleMinReplicas

func (b *PodCliqueTemplateSpecBuilder) WithAutoScaleMinReplicas(minimum int32) *PodCliqueTemplateSpecBuilder

WithAutoScaleMinReplicas sets the minimum replicas in ScaleConfig for the PodClique.

func (*PodCliqueTemplateSpecBuilder) WithLabels

WithLabels sets the labels for the PodCliqueTemplateSpec.

func (*PodCliqueTemplateSpecBuilder) WithMinAvailable

func (b *PodCliqueTemplateSpecBuilder) WithMinAvailable(minAvailable int32) *PodCliqueTemplateSpecBuilder

WithMinAvailable sets the MinAvailable field for the PodCliqueTemplateSpec.

func (*PodCliqueTemplateSpecBuilder) WithPodSpec

WithPodSpec sets a custom PodSpec for the PodCliqueTemplateSpec.

func (*PodCliqueTemplateSpecBuilder) WithReplicas

WithReplicas sets the number of replicas for the PodCliqueTemplateSpec.

func (*PodCliqueTemplateSpecBuilder) WithRoleName

WithRoleName sets the RoleName for the PodCliqueTemplateSpec.

func (*PodCliqueTemplateSpecBuilder) WithScaleConfig

func (b *PodCliqueTemplateSpecBuilder) WithScaleConfig(minReplicas *int32, maxReplicas int32) *PodCliqueTemplateSpecBuilder

WithScaleConfig sets the complete ScaleConfig for the PodCliqueTemplateSpec.

func (*PodCliqueTemplateSpecBuilder) WithStartsAfter

func (b *PodCliqueTemplateSpecBuilder) WithStartsAfter(startsAfter []string) *PodCliqueTemplateSpecBuilder

WithStartsAfter sets the StartsAfter field for the PodCliqueTemplateSpec.

type TestClientBuilder

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

TestClientBuilder is a builder for creating a test client.Client which is capable of recording and replaying errors.

func NewTestClientBuilder

func NewTestClientBuilder() *TestClientBuilder

NewTestClientBuilder creates a new TestClientBuilder with a default scheme.

func (*TestClientBuilder) Build

func (b *TestClientBuilder) Build() client.Client

Build creates a test client.Client with the configured reactions to errors.

func (*TestClientBuilder) RecordErrorForObjects

func (b *TestClientBuilder) RecordErrorForObjects(method ClientMethod, err *apierrors.StatusError, objectKeys ...client.ObjectKey) *TestClientBuilder

RecordErrorForObjects records an error for a specific client.Client method and object keys.

func (*TestClientBuilder) RecordErrorForObjectsMatchingLabels

func (b *TestClientBuilder) RecordErrorForObjectsMatchingLabels(method ClientMethod, objectKey client.ObjectKey, targetObjectsGVK schema.GroupVersionKind, matchingLabels map[string]string, err *apierrors.StatusError) *TestClientBuilder

RecordErrorForObjectsMatchingLabels records an error for a specific client.Client method and object keys matching the given labels for a given GVK.

func (*TestClientBuilder) WithClient

func (b *TestClientBuilder) WithClient(cl client.Client) *TestClientBuilder

WithClient sets the delegating client for the TestClientBuilder.

func (*TestClientBuilder) WithObjects

func (b *TestClientBuilder) WithObjects(objects ...client.Object) *TestClientBuilder

WithObjects initializes the delegating fake client builder with objects.

Jump to

Keyboard shortcuts

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