utils

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestEtcdName = "etcd-test"
	// TestNamespace is a test namespace to be used in tests.
	TestNamespace = "test-ns"
)
View Source
const (
	// TestImageRepo is a constant for image repository name
	TestImageRepo = "test-repo"
	// ETCDImageSourceTag is the ImageSource tag for etcd image.
	ETCDImageSourceTag = "etcd-test-tag"
	// ETCDWrapperImageTag is the ImageSource tag for etcd-wrapper image.
	ETCDWrapperImageTag = "etcd-wrapper-test-tag"
	// ETCDBRImageTag is the ImageSource tag for etcd-backup-restore image.
	ETCDBRImageTag = "backup-restore-test-tag"
	// ETCDBRDistrolessImageTag is the ImageSource tag for etc-backup-restore distroless image.
	ETCDBRDistrolessImageTag = "backup-restore-distroless-test-tag"
	// InitContainerTag is the ImageSource tag for the init container image.
	InitContainerTag = "init-container-test-tag"
)

Image vector constants

View Source
const (
	// TestConfigMapCheckSum is a test check-sum for the configmap which is stored as a value against checksum/etcd-configmap annotation put on the etcd sts pods.
	TestConfigMapCheckSum = "08ee0a880e10172e337ac57fb20411980a987405a0eaf9a05b8err69ca0f0d69"
)

Variables

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

Functions

func CheckDruidError added in v0.23.0

func CheckDruidError(g *WithT, expectedError *druiderr.DruidError, actualError error)

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

func CheckEtcdOwnerReference

func CheckEtcdOwnerReference(refs []metav1.OwnerReference, etcdOwnerUID types.UID) bool

CheckEtcdOwnerReference checks if one of the owner references points to etcd owner UID.

func CmdIterator

func CmdIterator(element interface{}) string

func ContainerIterator

func ContainerIterator(element interface{}) string

func CreateDefaultFakeClient added in v0.23.0

func CreateDefaultFakeClient() client.Client

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

func CreateEtcdCopyBackupsJob

func CreateEtcdCopyBackupsJob(taskName, namespace string) *batchv1.Job

CreateEtcdCopyBackupsJob creates an instance of a Job owned by a EtcdCopyBackupsTask with the given name.

func CreateEtcdCopyBackupsTask

func CreateEtcdCopyBackupsTask(name, namespace string, provider druidv1alpha1.StorageProvider, withOptionalFields bool) *druidv1alpha1.EtcdCopyBackupsTask

CreateEtcdCopyBackupsTask creates an instance of EtcdCopyBackupsTask for the given provider and optional fields boolean.

func CreateEvent added in v0.23.0

func CreateEvent(name, namespace, reason, message, eventType string, involvedObject client.Object, involvedObjectGVK schema.GroupVersionKind) *corev1.Event

CreateEvent creates an event with the given parameters.

func CreateImageVector added in v0.23.0

func CreateImageVector(withEtcdImage, withBackupRestoreImage, withEtcdWrapperImage, withBackupRestoreDistrolessImage bool) imagevector.ImageVector

CreateImageVector creates an image vector initializing it will different image sources.

func CreateLease

func CreateLease(name, namespace, etcdName string, etcdUID types.UID, componentName string) *coordinationv1.Lease

CreateLease creates a lease with its owner reference set to etcd.

func CreatePVC added in v0.23.0

CreatePVC creates a PVC for the given StatefulSet pod.

func CreateSecrets

func CreateSecrets(ctx context.Context, c client.Client, namespace string, secrets ...string) error

CreateSecrets creates all the given secrets

func CreateStatefulSet

func CreateStatefulSet(name, namespace string, etcdUID types.UID, replicas int32) *appsv1.StatefulSet

CreateStatefulSet creates a statefulset with its owner reference set to etcd.

func CreateTestFakeClientForAllObjectsInNamespace added in v0.23.0

func CreateTestFakeClientForAllObjectsInNamespace(deleteAllErr, listErr *apierrors.StatusError, namespace string, matchingLabels map[string]string, existingObjects ...client.Object) client.Client

CreateTestFakeClientForAllObjectsInNamespace is a convenience function which creates a test client which uses a fake client as a delegate and reacts to the configured errors for all objects in the given namespace matching the given labels.

func CreateTestFakeClientForObjects added in v0.23.0

func CreateTestFakeClientForObjects(getErr, createErr, patchErr, deleteErr *apierrors.StatusError, existingObjects []client.Object, objKeys ...client.ObjectKey) client.Client

CreateTestFakeClientForObjects is a convenience function which creates a test client which uses a fake client as a delegate and reacts to the configured errors for the given object key.

func CreateTestFakeClientForObjectsInNamespaceWithGVK added in v0.23.0

func CreateTestFakeClientForObjectsInNamespaceWithGVK(errors []ErrorsForGVK, namespace string, existingObjects ...client.Object) client.Client

CreateTestFakeClientForObjectsInNamespaceWithGVK is a convenience function which creates a test client which uses a fake client as a delegate and reacts to the configured errors for all objects in the given namespace for the given GroupVersionKinds.

func CreateTestFakeClientWithSchemeForObjects added in v0.23.0

func CreateTestFakeClientWithSchemeForObjects(scheme *runtime.Scheme, getErr, createErr, patchErr, deleteErr *apierrors.StatusError, existingObjects []client.Object, objKeys ...client.ObjectKey) client.Client

CreateTestFakeClientWithSchemeForObjects is a convenience function which creates a test client which uses a fake client with the given scheme as a delegate and reacts to the configured errors for the given object keys.

func EnvIterator

func EnvIterator(element interface{}) string

func GenerateRandomAlphanumericString added in v0.23.0

func GenerateRandomAlphanumericString(g *WithT, length int) string

GenerateRandomAlphanumericString generates a random alphanumeric string of the given length.

func IsEtcdRemoved

func IsEtcdRemoved(c client.Client, name, namespace string, timeout time.Duration) error

IsEtcdRemoved checks if the given etcd object is removed

func IsLeaseRemoved

func IsLeaseRemoved(c client.Client, name, namespace string, timeout time.Duration) error

IsLeaseRemoved checks if the given etcd object is removed

func MatchEtcdOwnerReference added in v0.23.0

func MatchEtcdOwnerReference(etcdName string, etcdUID types.UID) gomegatypes.GomegaMatcher

MatchEtcdOwnerReference is a custom gomega matcher which creates a matcher for ObjectMeta.OwnerReferences

func MatchFinalizer

func MatchFinalizer(finalizer string) gomegatypes.GomegaMatcher

func MatchResourceAnnotations added in v0.23.0

func MatchResourceAnnotations(expected map[string]string) gomegatypes.GomegaMatcher

MatchResourceAnnotations returns a custom gomega matcher which matches annotations set on a resource against the expected annotations.

func MatchResourceLabels added in v0.23.0

func MatchResourceLabels(expected map[string]string) gomegatypes.GomegaMatcher

MatchResourceLabels returns a custom gomega matcher which matches labels set on the resource against the expected labels.

func MatchSpecLabelSelector added in v0.23.0

func MatchSpecLabelSelector(expected map[string]string) gomegatypes.GomegaMatcher

MatchSpecLabelSelector returns a custom gomega matcher which matches label selector on a resource against the expected labels.

func MergeMaps added in v0.23.0

func MergeMaps[K comparable, V any](sourceMaps ...map[K]V) map[K]V

MergeMaps merges the contents of maps. All maps will be processed in the order in which they are sent. For overlapping keys across source maps, value in the merged map for this key will be from the last occurrence of the key-value.

func OwnerRefIterator

func OwnerRefIterator(element interface{}) string

func ParseQuantity

func ParseQuantity(q string) resource.Quantity

func VolumeIterator

func VolumeIterator(element interface{}) string

func VolumeMountIterator

func VolumeMountIterator(element interface{}) string

Types

type ClientMethod added in v0.23.0

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"
)

type ErrorsForGVK added in v0.23.0

type ErrorsForGVK struct {
	GVK          schema.GroupVersionKind
	DeleteAllErr *apierrors.StatusError
	ListErr      *apierrors.StatusError
}

type EtcdBuilder

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

func EtcdBuilderWithDefaults

func EtcdBuilderWithDefaults(name, namespace string) *EtcdBuilder

func EtcdBuilderWithoutDefaults

func EtcdBuilderWithoutDefaults(name, namespace string) *EtcdBuilder

func (*EtcdBuilder) Build

func (eb *EtcdBuilder) Build() *druidv1alpha1.Etcd

func (*EtcdBuilder) WithAnnotations added in v0.23.0

func (eb *EtcdBuilder) WithAnnotations(annotations map[string]string) *EtcdBuilder

WithAnnotations merges the existing annotations if any with the annotations passed. Any existing entry will be replaced by the one that is present in the annotations passed to this method.

func (*EtcdBuilder) WithBackupPort added in v0.23.0

func (eb *EtcdBuilder) WithBackupPort(port *int32) *EtcdBuilder

func (*EtcdBuilder) WithClientTLS added in v0.23.0

func (eb *EtcdBuilder) WithClientTLS() *EtcdBuilder

func (*EtcdBuilder) WithDefaultBackup added in v0.23.0

func (eb *EtcdBuilder) WithDefaultBackup() *EtcdBuilder

WithDefaultBackup creates a default backup spec and initializes etcd with it.

func (*EtcdBuilder) WithEtcdClientPort added in v0.23.0

func (eb *EtcdBuilder) WithEtcdClientPort(clientPort *int32) *EtcdBuilder

func (*EtcdBuilder) WithEtcdClientServiceAnnotations added in v0.23.0

func (eb *EtcdBuilder) WithEtcdClientServiceAnnotations(annotations map[string]string) *EtcdBuilder

func (*EtcdBuilder) WithEtcdClientServiceLabels added in v0.23.0

func (eb *EtcdBuilder) WithEtcdClientServiceLabels(labels map[string]string) *EtcdBuilder

func (*EtcdBuilder) WithEtcdServerPort added in v0.23.0

func (eb *EtcdBuilder) WithEtcdServerPort(serverPort *int32) *EtcdBuilder

func (*EtcdBuilder) WithLabels added in v0.23.0

func (eb *EtcdBuilder) WithLabels(labels map[string]string) *EtcdBuilder

WithLabels merges the labels that already exists with the ones that are passed to this method. If an entry is already present in the existing labels then it gets overwritten with the new value present in the passed in labels.

func (*EtcdBuilder) WithLastOperation added in v0.23.0

func (eb *EtcdBuilder) WithLastOperation(operation *druidv1alpha1.LastOperation) *EtcdBuilder

func (*EtcdBuilder) WithPeerTLS added in v0.23.0

func (eb *EtcdBuilder) WithPeerTLS() *EtcdBuilder

func (*EtcdBuilder) WithProviderABS

func (eb *EtcdBuilder) WithProviderABS() *EtcdBuilder

func (*EtcdBuilder) WithProviderGCS

func (eb *EtcdBuilder) WithProviderGCS() *EtcdBuilder

func (*EtcdBuilder) WithProviderLocal added in v0.21.0

func (eb *EtcdBuilder) WithProviderLocal() *EtcdBuilder

func (*EtcdBuilder) WithProviderOSS

func (eb *EtcdBuilder) WithProviderOSS() *EtcdBuilder

func (*EtcdBuilder) WithProviderS3

func (eb *EtcdBuilder) WithProviderS3() *EtcdBuilder

func (*EtcdBuilder) WithProviderSwift

func (eb *EtcdBuilder) WithProviderSwift() *EtcdBuilder

func (*EtcdBuilder) WithReadyStatus

func (eb *EtcdBuilder) WithReadyStatus() *EtcdBuilder

func (*EtcdBuilder) WithReplicas

func (eb *EtcdBuilder) WithReplicas(replicas int32) *EtcdBuilder

func (*EtcdBuilder) WithStorageProvider

func (eb *EtcdBuilder) WithStorageProvider(provider druidv1alpha1.StorageProvider) *EtcdBuilder

type FakeManager added in v0.23.0

type FakeManager struct {
	manager.Manager
	Client        client.Client
	Cache         cache.Cache
	EventRecorder record.EventRecorder
	APIReader     client.Reader
	Logger        logr.Logger
	Scheme        *runtime.Scheme
}

FakeManager fakes a manager.Manager.

func (FakeManager) GetAPIReader added in v0.23.0

func (f FakeManager) GetAPIReader() client.Reader

func (FakeManager) GetCache added in v0.23.0

func (f FakeManager) GetCache() cache.Cache

func (FakeManager) GetClient added in v0.23.0

func (f FakeManager) GetClient() client.Client

func (FakeManager) GetEventRecorderFor added in v0.23.0

func (f FakeManager) GetEventRecorderFor(_ string) record.EventRecorder

func (FakeManager) GetLogger added in v0.23.0

func (f FakeManager) GetLogger() logr.Logger

func (FakeManager) GetScheme added in v0.23.0

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

type TestClientBuilder added in v0.23.0

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

TestClientBuilder builds a client.Client which will also react to the configured errors.

func NewTestClientBuilder added in v0.23.0

func NewTestClientBuilder() *TestClientBuilder

NewTestClientBuilder creates a new instance of TestClientBuilder.

func (*TestClientBuilder) Build added in v0.23.0

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

Build creates a new instance of client.Client which will react to the configured errors.

func (*TestClientBuilder) RecordErrorForObjects added in v0.23.0

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 added in v0.23.0

func (b *TestClientBuilder) RecordErrorForObjectsMatchingLabels(method ClientMethod, namespace string, matchingLabels map[string]string, err *apierrors.StatusError) *TestClientBuilder

RecordErrorForObjectsMatchingLabels records an error for a specific client.Client method and objects in a given namespace matching the given labels.

func (*TestClientBuilder) RecordErrorForObjectsWithGVK added in v0.23.0

func (b *TestClientBuilder) RecordErrorForObjectsWithGVK(method ClientMethod, namespace string, gvk schema.GroupVersionKind, err *apierrors.StatusError) *TestClientBuilder

RecordErrorForObjectsWithGVK records an error for a specific client.Client method and objects in a given namespace of a given GroupVersionKind.

func (*TestClientBuilder) WithClient added in v0.23.0

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

WithClient initializes the delegating fake client builder with the given client.

func (*TestClientBuilder) WithObjects added in v0.23.0

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

WithObjects initializes the delegating fake client builder with objects.

func (*TestClientBuilder) WithScheme added in v0.23.0

func (b *TestClientBuilder) WithScheme(scheme *runtime.Scheme) *TestClientBuilder

WithScheme initializes the delegating fake client builder with the given scheme.

Jump to

Keyboard shortcuts

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