testpredicates

package
v1.19.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedPredicate = errors.New("failed predicate")

ErrFailedPredicate indicates the the object on the API server does not match the Predicate.

View Source
var ErrObjectNotFound = errors.New("object not found")

ErrObjectNotFound indicates that the caller passed a nil object, indicating the object was deleted or never existed.

View Source
var ErrWrongType = errors.New("wrong type")

ErrWrongType indicates that the caller passed an object of the incorrect type to the Predicate.

Functions

func ClusterRoleBindingSubjectNamesEqual added in v1.17.0

func ClusterRoleBindingSubjectNamesEqual(subjects ...string) func(o client.Object) error

ClusterRoleBindingSubjectNamesEqual checks that the ClusterRoleBinding has a list of subjects whose names match the specified list of names.

func ContainerByName added in v1.16.0

func ContainerByName(obj *appsv1.Deployment, containerName string) *corev1.Container

ContainerByName returns a copy of the container with the specified name, found in the specified Deployment.

func EvaluatePredicates

func EvaluatePredicates(obj client.Object, predicates []Predicate) []error

EvaluatePredicates evaluates a list of predicates and returns any errors

func HasDeletionTimestamp

func HasDeletionTimestamp(o client.Object) error

HasDeletionTimestamp is a predicate that tests that an Object has a DeletionTimestamp.

func MissingDeletionTimestamp

func MissingDeletionTimestamp(o client.Object) error

MissingDeletionTimestamp is a predicate that tests that an Object does NOT have a DeletionTimestamp.

func NotPendingDeletion

func NotPendingDeletion(o client.Object) error

NotPendingDeletion ensures o is not pending deletion.

Check this when the object could be scheduled for deletion, to avoid flaky behavior when we're ensuring we don't want something to be deleted.

func ObjectFoundPredicate

func ObjectFoundPredicate(o client.Object) error

ObjectFoundPredicate returns ErrObjectNotFound if the object is nil (not found).

func ValidateError added in v1.17.2

func ValidateError(errs []v1beta1.ConfigSyncError, code, message string, resources []v1beta1.ResourceRef) error

ValidateError returns true if the specified errors contain an error with the specified error code, (partial) message, and resources.

func WrongTypeErr

func WrongTypeErr(got, want interface{}) error

WrongTypeErr reports that the passed type was not equivalent to the wanted type.

Types

type Predicate

type Predicate func(o client.Object) error

Predicate evaluates a client.Object, returning an error if it fails validation. The object will be nil if the object was deleted or never existed.

func AllResourcesAreCurrent

func AllResourcesAreCurrent() Predicate

AllResourcesAreCurrent ensures that the managed resources are all Current in the ResourceGroup CR.

func DeploymentContainerArgsContains added in v1.17.0

func DeploymentContainerArgsContains(containerName, args string) Predicate

DeploymentContainerArgsContains verifies a container in reconciler deployment has the expected arg

func DeploymentContainerImageEquals added in v1.16.0

func DeploymentContainerImageEquals(containerName, image string) Predicate

DeploymentContainerImageEquals returns a predicate that errors if the deployment does not have a container with the specified name and image.

func DeploymentContainerPullPolicyEquals added in v1.16.0

func DeploymentContainerPullPolicyEquals(containerName string, policy corev1.PullPolicy) Predicate

DeploymentContainerPullPolicyEquals returns a predicate that errors if the deployment does not have a container with the specified name and imagePullPolicy.

func DeploymentContainerResourcesAllEqual added in v1.17.0

func DeploymentContainerResourcesAllEqual(scheme *runtime.Scheme, logger *testlogger.TestLogger, expectedByName map[string]v1beta1.ContainerResourcesSpec) Predicate

DeploymentContainerResourcesAllEqual verifies all reconciler deployment containers have the expected resource requests and limits.

func DeploymentContainerResourcesEqual added in v1.17.0

func DeploymentContainerResourcesEqual(expectedSpec v1beta1.ContainerResourcesSpec) Predicate

DeploymentContainerResourcesEqual verifies a reconciler deployment container has the expected resource requests and limits.

func DeploymentHasContainer added in v1.16.0

func DeploymentHasContainer(containerName string) Predicate

DeploymentHasContainer check whether the deployment has the container with the specified name.

func DeploymentHasEnvVar

func DeploymentHasEnvVar(containerName, key, value string) Predicate

DeploymentHasEnvVar check whether the deployment contains environment variable with specified name and value

func DeploymentMissingContainer added in v1.16.0

func DeploymentMissingContainer(containerName string) Predicate

DeploymentMissingContainer check whether the deployment does not have the container with the specified name.

func DeploymentMissingEnvVar

func DeploymentMissingEnvVar(containerName, key string) Predicate

DeploymentMissingEnvVar check whether the deployment does not contain environment variable with specified name and value

func GenerationEquals added in v1.17.0

func GenerationEquals(generation int64) Predicate

GenerationEquals checks that the object's generation equals the specified value.

func GenerationNotEquals added in v1.17.0

func GenerationNotEquals(generation int64) Predicate

GenerationNotEquals checks that the object's Generation does not equal the specified value.

func HasAllAnnotationKeys

func HasAllAnnotationKeys(keys ...string) Predicate

HasAllAnnotationKeys returns a predicate that tests if an Object has the specified annotation keys.

func HasAllNomosMetadata

func HasAllNomosMetadata() Predicate

HasAllNomosMetadata ensures that the object contains the expected nomos labels and annotations.

func HasAnnotation

func HasAnnotation(key, value string) Predicate

HasAnnotation returns a predicate that tests if an Object has the specified annotation key/value pair.

func HasAnnotationKey

func HasAnnotationKey(key string) Predicate

HasAnnotationKey returns a predicate that tests if an Object has the specified annotation key.

func HasBeenManagedBy added in v1.19.0

func HasBeenManagedBy(scheme *runtime.Scheme, logger *testlogger.TestLogger, managers ...string) Predicate

HasBeenManagedBy validates that an object has been managed by all of the specified managers, one at a time.

func HasConditionStatus added in v1.19.0

func HasConditionStatus(scheme *runtime.Scheme, conditionType string, expectedStatus corev1.ConditionStatus) Predicate

HasConditionStatus returns a Predicate that errors if the object does not have the specified condition or does but the status does not match the expected status.

func HasExactlyAnnotationKeys

func HasExactlyAnnotationKeys(wantKeys ...string) Predicate

HasExactlyAnnotationKeys ensures the Object has exactly the passed set of annotations, ignoring values.

func HasExactlyImage

func HasExactlyImage(containerName, expectImageName, expectImageTag, expectImageDigest string) Predicate

HasExactlyImage ensures a container has the expected image.

func HasExactlyLabelKeys

func HasExactlyLabelKeys(wantKeys ...string) Predicate

HasExactlyLabelKeys ensures the Object has exactly the passed set of labels, ignoring values.

func HasFinalizer

func HasFinalizer(name string) Predicate

HasFinalizer returns a predicate that tests that an Object has the specified finalizer.

func HasGenerationAtLeast

func HasGenerationAtLeast(minGeneration int64) Predicate

HasGenerationAtLeast checks that the object's Generation is greater than or equal to the specified value.

func HasLabel

func HasLabel(key, value string) Predicate

HasLabel returns a predicate that tests if an Object has the specified label key/value pair.

func HasObservedLatestGeneration added in v1.16.0

func HasObservedLatestGeneration(scheme *runtime.Scheme) Predicate

HasObservedLatestGeneration returns an error if the object status.observedGeneration does not equal the metadata.generation.

func IsManagedBy

func IsManagedBy(scheme *runtime.Scheme, scope declared.Scope, syncName string) Predicate

IsManagedBy checks that the object is managed by configsync, has the expected resource manager, and has a valid resource-id. Use diff.IsManager if you just need a boolean without errors.

func IsNotManaged

func IsNotManaged(scheme *runtime.Scheme) Predicate

IsNotManaged checks that the object is NOT managed by configsync. Use differ.ManagedByConfigSync if you just need a boolean without errors.

func MissingAnnotation

func MissingAnnotation(key string) Predicate

MissingAnnotation returns a predicate that tests that an object does not have a specified annotation.

func MissingFinalizer

func MissingFinalizer(name string) Predicate

MissingFinalizer returns a predicate that tests that an Object does NOT have the specified finalizer.

func MissingLabel

func MissingLabel(key string) Predicate

MissingLabel returns a predicate that tests that an object does not have a specified label.

func NoConfigSyncMetadata

func NoConfigSyncMetadata() Predicate

NoConfigSyncMetadata ensures that the object doesn't contain configsync labels and annotations.

func ObjectNotFoundPredicate

func ObjectNotFoundPredicate(scheme *runtime.Scheme) Predicate

ObjectNotFoundPredicate returns an error unless the object is nil (not found).

func Or added in v1.19.0

func Or(logger *testlogger.TestLogger, predicates ...Predicate) Predicate

Or returns a Predicate that errors only if all of the Predicates errored. If any one of the specified Predicates succeeds, the Or Predicate succeeds. Logs the index of the first successful predicates.

func RepoSyncHasCondition added in v1.17.0

func RepoSyncHasCondition(expected *v1beta1.RepoSyncCondition) Predicate

RepoSyncHasCondition returns a Predicate that errors if the RepoSync does not have the specified RepoSyncCondition. Fields such as timestamps are ignored.

func RepoSyncHasRenderingError

func RepoSyncHasRenderingError(errCode, errMessage string) Predicate

RepoSyncHasRenderingError returns an error if the RootSync does not have the specified Rendering error code and (optional, partial) message.

func RepoSyncHasSourceError

func RepoSyncHasSourceError(errCode, errMessage string) Predicate

RepoSyncHasSourceError returns an error if the RootSync does not have the specified Source error code and (optional, partial) message.

func RepoSyncHasSyncError

func RepoSyncHasSyncError(errCode, errMessage string) Predicate

RepoSyncHasSyncError returns an error if the RootSync does not have the specified Sync error code and (optional, partial) message.

func ResourceGroupHasObjects added in v1.17.0

func ResourceGroupHasObjects(objects []client.Object) Predicate

ResourceGroupHasObjects checks whether the objects are in the ResourceGroup's inventory.

func ResourceGroupMissingObjects added in v1.17.0

func ResourceGroupMissingObjects(objects []client.Object) Predicate

ResourceGroupMissingObjects checks whether the objects are NOT in the ResourceGroup's inventory.

func ResourceGroupStatusEquals added in v1.17.0

func ResourceGroupStatusEquals(expected v1alpha1.ResourceGroupStatus) Predicate

ResourceGroupStatusEquals checks that the RootSync's spec.override matches the specified RootSyncOverrideSpec.

func ResourceVersionEquals

func ResourceVersionEquals(scheme *runtime.Scheme, expected string) Predicate

ResourceVersionEquals checks that the object's ResourceVersion matches the specified value.

func ResourceVersionNotEquals

func ResourceVersionNotEquals(scheme *runtime.Scheme, unexpected string) Predicate

ResourceVersionNotEquals checks that the object's ResourceVersion does NOT match specified value.

func RoleBindingHasName

func RoleBindingHasName(expectedName string) Predicate

RoleBindingHasName will check the Rolebindings name and compare it with expected value

func RootSyncHasCondition added in v1.16.0

func RootSyncHasCondition(expected *v1beta1.RootSyncCondition) Predicate

RootSyncHasCondition returns a Predicate that errors if the RootSync does not have the specified RootSyncCondition. Fields such as timestamps are ignored.

func RootSyncHasNomosStatus added in v1.19.0

func RootSyncHasNomosStatus(expectedCommit, expectedStatus string) Predicate

RootSyncHasNomosStatus returns an error if the RootSync does not have the specified commit or status according to `nomos status` (RootRepoStatus).

func RootSyncHasObservedGenerationNoLessThan

func RootSyncHasObservedGenerationNoLessThan(generation int64) Predicate

RootSyncHasObservedGenerationNoLessThan returns an error if the RootSync has the observedGeneration less than the expected generation.

func RootSyncHasRenderingError

func RootSyncHasRenderingError(errCode, errMessage string) Predicate

RootSyncHasRenderingError returns an error if the RootSync does not have the specified Rendering error code and (optional, partial) message.

func RootSyncHasSourceError

func RootSyncHasSourceError(errCode, errMessage string) Predicate

RootSyncHasSourceError returns an error if the RootSync does not have the specified Source error code and (optional, partial) message.

func RootSyncHasSyncError

func RootSyncHasSyncError(errCode, errMessage string) Predicate

RootSyncHasSyncError returns an error if the RootSync does not have the specified Sync error code and (optional, partial) message.

func RootSyncSpecEquals added in v1.19.0

func RootSyncSpecEquals(expected v1beta1.RootSyncSpec) Predicate

RootSyncSpecEquals returns a Predicate that errors if the RootSync does not have the specified RootSyncCondition. Fields such as timestamps are ignored.

func RootSyncSpecOverrideEquals added in v1.17.0

func RootSyncSpecOverrideEquals(expected *v1beta1.RootSyncOverrideSpec) Predicate

RootSyncSpecOverrideEquals checks that the RootSync's spec.override matches the specified RootSyncOverrideSpec.

func SecretHasKey

func SecretHasKey(key, value string) Predicate

SecretHasKey checks that the secret contains key with value

func SecretMissingKey

func SecretMissingKey(key string) Predicate

SecretMissingKey checks that the secret does not contain key

func StatusEquals

func StatusEquals(scheme *runtime.Scheme, expected status.Status) Predicate

StatusEquals checks that the object's computed status matches the specified status.

func WatchSyncPredicate

func WatchSyncPredicate() (Predicate, <-chan struct{})

WatchSyncPredicate returns a predicate and a channel. The channel will be closed when the predicate is first called. Use this to block until WatchObject has completed its first LIST call. This will help avoid missed events when WatchObject is run asynchronously.

Jump to

Keyboard shortcuts

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