Documentation ¶
Index ¶
- Constants
- Variables
- func AsARMIDOwner(id string) *genruntime.KnownResourceReference
- func AsKubernetesOwner(obj client.Object) *genruntime.KubernetesOwnerReference
- func AsOwner(obj client.Object) *genruntime.KnownResourceReference
- func CreateClient(scheme *runtime.Scheme) client.Client
- func CreateDummyResource() *batch.BatchAccount
- func CreateResolver(scheme *runtime.Scheme, testClient client.Client) (*resolver.Resolver, error)
- func CreateResourceGroup() *resources.ResourceGroup
- func CreateScheme() (*runtime.Scheme, error)
- func CreateTestResourceGroupDefaultTags() map[string]string
- func EqualsIgnoreCase(expected string) types.GomegaMatcher
- func IsSampleExcluded(path string, exclusions []string) bool
- func NewClient(client client.Client, indexer *Indexer) client.Client
- func NewTestClient(config *rest.Config, options client.Options) (client.Client, error)
- func NewTestLogger(t *testing.T) logr.Logger
- func PathContains(path string, matches []string) bool
- func ReadFromEnvironmentForTest() (config.Values, error)
- func SetupTeardownTestMain(m *testing.M, setup func() error, teardown func() error) int
- func WaitFor(ctx context.Context, timeout time.Duration, ...) error
- type ARMMatcher
- type AzureBeDeletedMatcher
- func (m *AzureBeDeletedMatcher) FailureMessage(actual interface{}) string
- func (m *AzureBeDeletedMatcher) Match(actual interface{}) (bool, error)
- func (m *AzureBeDeletedMatcher) MatchMayChangeInTheFuture(actual interface{}) bool
- func (m *AzureBeDeletedMatcher) NegatedFailureMessage(actual interface{}) string
- type AzureBeProvisionedMatcher
- func (m *AzureBeProvisionedMatcher) FailureMessage(actual interface{}) string
- func (m *AzureBeProvisionedMatcher) Match(actual interface{}) (bool, error)
- func (m *AzureBeProvisionedMatcher) MatchMayChangeInTheFuture(actual interface{}) bool
- func (m *AzureBeProvisionedMatcher) NegatedFailureMessage(actual interface{}) string
- type BaseTestContextFactory
- type BeDeletedMatcher
- type DesiredStateMatcher
- func (m *DesiredStateMatcher) FailureMessage(actual interface{}) string
- func (m *DesiredStateMatcher) Match(actual interface{}) (bool, error)
- func (m *DesiredStateMatcher) MatchMayChangeInTheFuture(actual interface{}) bool
- func (m *DesiredStateMatcher) NegatedFailureMessage(actual interface{}) string
- type Indexer
- type KubeBaseTestContext
- type KubeGlobalContext
- type KubeMatcher
- func (m *KubeMatcher) BeDeleted() types.GomegaMatcher
- func (m *KubeMatcher) BeFailed(originalGeneration int64) types.GomegaMatcher
- func (m *KubeMatcher) BeInState(status metav1.ConditionStatus, severity conditions.ConditionSeverity, ...) types.GomegaMatcher
- func (m *KubeMatcher) BeProvisioned(originalGeneration int64) types.GomegaMatcher
- type KubePerTestContext
- func (tc *KubePerTestContext) AsExtensionOwner(obj client.Object) *genruntime.ArbitraryOwnerReference
- func (tc *KubePerTestContext) CheckIfResourceExists(obj client.Object) error
- func (tc *KubePerTestContext) CreateResource(obj client.Object)
- func (tc *KubePerTestContext) CreateResourceAndWait(obj client.Object)
- func (tc *KubePerTestContext) CreateResourceAndWaitForFailure(obj client.Object)
- func (tc *KubePerTestContext) CreateResourceAndWaitForState(obj client.Object, status metav1.ConditionStatus, ...)
- func (tc *KubePerTestContext) CreateResourceAndWaitWithoutCleanup(obj client.Object)
- func (tc *KubePerTestContext) CreateResourceExpectRequestFailure(obj client.Object) error
- func (tc *KubePerTestContext) CreateResourceUntracked(obj client.Object)
- func (tc *KubePerTestContext) CreateResourcesAndWait(objs ...client.Object)
- func (tc *KubePerTestContext) CreateResourcesAndWaitWithoutCleanup(objs ...client.Object)
- func (tc *KubePerTestContext) CreateSimpleSecret(name string, key string, secretData string) genruntime.SecretReference
- func (tc KubePerTestContext) CreateTestNamespace(namespaceName string) error
- func (tc *KubePerTestContext) CreateTestNamespaces(names ...string) error
- func (tc *KubePerTestContext) CreateTestResourceGroupAndWait() *resources.ResourceGroup
- func (tc *KubePerTestContext) DefaultOperationTimeout() time.Duration
- func (tc *KubePerTestContext) DeleteResource(obj client.Object)
- func (tc *KubePerTestContext) DeleteResourceAndWait(obj client.Object)
- func (tc *KubePerTestContext) DeleteResourcesAndWait(objs ...client.Object)
- func (tc *KubePerTestContext) Eventually(actual interface{}, intervals ...interface{}) gomega.AsyncAssertion
- func (tc *KubePerTestContext) Expect(actual interface{}) gomega.Assertion
- func (tc *KubePerTestContext) ExpectConfigMapHasKeys(name string, expectedKeys ...string)
- func (tc *KubePerTestContext) ExpectConfigMapHasKeysAndValues(name string, expectedKeysAndValues ...string)
- func (tc *KubePerTestContext) ExpectResourceDoesNotExist(key types.NamespacedName, obj client.Object)
- func (tc *KubePerTestContext) ExpectResourceIsDeletedInAzure(armId string, apiVersion string)
- func (tc *KubePerTestContext) ExpectSecretHasKeys(name string, expectedKeys ...string)
- func (tc *KubePerTestContext) ExportAsSample(resource client.Object)
- func (tc *KubePerTestContext) ExportAsSampleNamed(resource client.Object, name string)
- func (tc *KubePerTestContext) GetResource(key types.NamespacedName, obj client.Object)
- func (tc *KubePerTestContext) GetScheme() *runtime.Scheme
- func (tc *KubePerTestContext) GetSecret(name string) *corev1.Secret
- func (tc *KubePerTestContext) KubeClient() client.Client
- func (tc *KubePerTestContext) ListResources(list client.ObjectList, opts ...client.ListOption)
- func (tc *KubePerTestContext) LogSectionf(section string, args ...any)
- func (tc *KubePerTestContext) LogSubsectionf(subsection string, args ...any)
- func (tc KubePerTestContext) MakeObjectMeta(prefix string) ctrl.ObjectMeta
- func (tc KubePerTestContext) MakeObjectMetaWithName(name string) ctrl.ObjectMeta
- func (tc KubePerTestContext) MakeObjectMetaWithNameAndCredentialFrom(name string, credentialFrom string) ctrl.ObjectMeta
- func (tc KubePerTestContext) MakeReferenceFromResource(resource client.Object) *genruntime.ResourceReference
- func (tc KubePerTestContext) NewTestResourceGroup() *resources.ResourceGroup
- func (tc *KubePerTestContext) OperationTimeout() time.Duration
- func (tc *KubePerTestContext) Patch(old client.Object, new client.Object)
- func (tc *KubePerTestContext) PatchAndExpectError(old client.Object, new client.Object) error
- func (tc *KubePerTestContext) PatchResourceAndWait(old client.Object, new client.Object)
- func (tc *KubePerTestContext) PatchResourceAndWaitForState(old client.Object, new client.Object, status metav1.ConditionStatus, ...)
- func (tc *KubePerTestContext) PatchStatus(old client.Object, new client.Object)
- func (tc *KubePerTestContext) PollingInterval() time.Duration
- func (tc *KubePerTestContext) RunParallelSubtests(tests ...Subtest)
- func (tc *KubePerTestContext) RunSubtests(tests ...Subtest)
- func (tc *KubePerTestContext) Subtest(t *testing.T) *KubePerTestContext
- func (tc *KubePerTestContext) UpdateResource(obj client.Object)
- type PerTestContext
- func (tc PerTestContext) GenerateSSHKey(size int) (*string, error)
- func (tc PerTestContext) NewTestResourceGroup() *resources.ResourceGroup
- func (tc PerTestContext) WithLiteralRedaction(redactionValue string, replacementValue string)
- func (tc PerTestContext) WithRegexpRedaction(pattern string, replacementValue string)
- type ResourceNameConfig
- type ResourceNamer
- func (n ResourceNamer) GenerateName(prefix string) string
- func (n ResourceNamer) GenerateNameOfLength(length int) string
- func (n ResourceNamer) GeneratePassword() string
- func (n ResourceNamer) GeneratePasswordOfLength(length int) string
- func (n ResourceNamer) GenerateSecretOfLength(length int) string
- func (n ResourceNamer) GenerateUUID() (uuid.UUID, error)
- func (n ResourceNamer) WithNumRandomChars(num int) ResourceNamer
- func (n ResourceNamer) WithSeparator(separator string) ResourceNamer
- func (n ResourceNamer) WithTestName(testName string) ResourceNamer
- type ResourceNamerMode
- type ResourceTracker
- type SampleObject
- type SamplesTester
- type SimpleExtensionResource
- func (r *SimpleExtensionResource) AzureName() string
- func (r *SimpleExtensionResource) DeepCopyObject() runtime.Object
- func (r *SimpleExtensionResource) Default()
- func (r *SimpleExtensionResource) GetAPIVersion() string
- func (r *SimpleExtensionResource) GetConditions() conditions.Conditions
- func (r *SimpleExtensionResource) GetResourceScope() genruntime.ResourceScope
- func (r *SimpleExtensionResource) GetSpec() genruntime.ConvertibleSpec
- func (r *SimpleExtensionResource) GetStatus() genruntime.ConvertibleStatus
- func (r *SimpleExtensionResource) GetSupportedOperations() []genruntime.ResourceOperation
- func (r *SimpleExtensionResource) GetType() string
- func (r *SimpleExtensionResource) NewEmptyStatus() genruntime.ConvertibleStatus
- func (r *SimpleExtensionResource) Owner() *genruntime.ResourceReference
- func (r *SimpleExtensionResource) SetConditions(conditions conditions.Conditions)
- func (r *SimpleExtensionResource) SetStatus(status genruntime.ConvertibleStatus) error
- type SimpleExtensionResourceSpec
- type SimpleExtensionResourceStatus
- type Subtest
- type TestContext
- type TestLogger
- func (t *TestLogger) Enabled(_level int) bool
- func (t *TestLogger) Error(err error, msg string, keysAndValues ...interface{})
- func (t *TestLogger) Info(level int, msg string, keysAndValues ...interface{})
- func (_ TestLogger) Init(info logr.RuntimeInfo)
- func (t *TestLogger) V(level int) logr.Logger
- func (t *TestLogger) WithName(name string) logr.LogSink
- func (t *TestLogger) WithValues(keysAndValues ...interface{}) logr.LogSink
- type Verify
- type WaitCondition
Constants ¶
const ( ResourceNamerModeRandomBasedOnTestName = ResourceNamerMode("basedOnTestName") ResourceNamerModeRandom = ResourceNamerMode("random") )
const LiveResourcePrefix = "asolivetest"
LiveResourcePrefix is the prefix reserved for resources used in tests that cannot be recorded. These resources must support parallel runs (can be triggered by multiple parallel PRs), so deleting existing resources any time a new run starts is not allowed. Instead, deletion should be time-based - delete any leaked resources older than X hours. These are generally run against either a real cluster or a kind cluster.
const ResourcePrefix = "asotest"
ResourcePrefix is for resources which are used in the record/replay test infrastructure using envtest. These tests are not expected to be run live in parallel. In parallel runs should be done from the recordings. As such, for cleanup, we can delete any resources with this prefix without fear of disrupting an existing test pass. Again, this is ok because there's a single Github Action that runs with MaxParallelism == 1.
Variables ¶
var DefaultTestRegion = "westus2" // Could make this an env variable if we wanted
Use WestUS2 as some things (such as VM quota) are hard to get in West US.
var LogLevel = 5
TODO: I'm not sure the best way to configure this so for now I'm just going to set it to 5
var OperationTimeoutRecording = 30 * time.Minute
OperationTimeoutRecording is the default timeout for a single operation when recording. This is so high because the following operations are slow:
- Deleting an AKS cluster.
- Creating a Redis Enterprise Database.
- Deleting a CosmosDB MongoDB.
- Creating a Virtual Network Gateway Controller.
var OperationTimeoutReplaying = 2 * time.Minute
OperationTimeoutReplaying is the default timeout for a single operation when replaying.
var PollingIntervalRecording = 5 * time.Second
PollingIntervalRecording is the polling interval to use when recording.
var PollingIntervalReplaying = 100 * time.Millisecond
PollingIntervalReplaying is the polling interval to use when replaying. TODO: Setting this really low sometimes seems to cause TODO: updating resource: Operation cannot be fulfilled: the object has been modified; please apply your changes to the latest version and try again. TODO: This happens when the test sees a Status update and makes an update to the resource while racing with the Spec update TODO: in azure_deployment_reconciler CommitUpdate. If we fix https://github.com/Azure/azure-service-operator/issues/1744 we can TODO: shorten this interval.
var SimpleExtensionResourceGroupVersion = schema.GroupVersion{Group: "microsoft.test.azure.com", Version: "v1apitest"}
Functions ¶
func AsARMIDOwner ¶ added in v2.3.0
func AsARMIDOwner(id string) *genruntime.KnownResourceReference
func AsKubernetesOwner ¶ added in v2.3.0
func AsKubernetesOwner(obj client.Object) *genruntime.KubernetesOwnerReference
func AsOwner ¶
func AsOwner(obj client.Object) *genruntime.KnownResourceReference
func CreateDummyResource ¶
func CreateDummyResource() *batch.BatchAccount
func CreateResolver ¶
func CreateResourceGroup ¶
func CreateResourceGroup() *resources.ResourceGroup
func CreateScheme ¶
func EqualsIgnoreCase ¶
func EqualsIgnoreCase(expected string) types.GomegaMatcher
func IsSampleExcluded ¶
func NewTestClient ¶
NewTestClient is a thin wrapper around controller-runtime client.New, except that we repopulate the objects GVK since for some reason they do that in the cached client and not in the direct one...
func PathContains ¶ added in v2.10.0
func SetupTeardownTestMain ¶
Types ¶
type ARMMatcher ¶
type ARMMatcher struct {
// contains filtered or unexported fields
}
func NewARMMatcher ¶
func NewARMMatcher(client *genericarmclient.GenericClient) *ARMMatcher
func (*ARMMatcher) BeDeleted ¶
func (m *ARMMatcher) BeDeleted(ctx context.Context) types.GomegaMatcher
func (*ARMMatcher) BeProvisioned ¶
func (m *ARMMatcher) BeProvisioned(ctx context.Context) types.GomegaMatcher
type AzureBeDeletedMatcher ¶
type AzureBeDeletedMatcher struct {
// contains filtered or unexported fields
}
func (*AzureBeDeletedMatcher) FailureMessage ¶
func (m *AzureBeDeletedMatcher) FailureMessage(actual interface{}) string
func (*AzureBeDeletedMatcher) Match ¶
func (m *AzureBeDeletedMatcher) Match(actual interface{}) (bool, error)
func (*AzureBeDeletedMatcher) MatchMayChangeInTheFuture ¶
func (m *AzureBeDeletedMatcher) MatchMayChangeInTheFuture(actual interface{}) bool
MatchMayChangeInTheFuture implements OracleMatcher which of course isn't exported so we can't type-assert we implement it
func (*AzureBeDeletedMatcher) NegatedFailureMessage ¶
func (m *AzureBeDeletedMatcher) NegatedFailureMessage(actual interface{}) string
type AzureBeProvisionedMatcher ¶
type AzureBeProvisionedMatcher struct {
// contains filtered or unexported fields
}
func (*AzureBeProvisionedMatcher) FailureMessage ¶
func (m *AzureBeProvisionedMatcher) FailureMessage(actual interface{}) string
func (*AzureBeProvisionedMatcher) Match ¶
func (m *AzureBeProvisionedMatcher) Match(actual interface{}) (bool, error)
func (*AzureBeProvisionedMatcher) MatchMayChangeInTheFuture ¶
func (m *AzureBeProvisionedMatcher) MatchMayChangeInTheFuture(actual interface{}) bool
MatchMayChangeInTheFuture implements OracleMatcher which of course isn't exported so we can't type-assert we implement it
func (*AzureBeProvisionedMatcher) NegatedFailureMessage ¶
func (m *AzureBeProvisionedMatcher) NegatedFailureMessage(actual interface{}) string
type BaseTestContextFactory ¶
type BaseTestContextFactory func(PerTestContext, config.Values) (*KubeBaseTestContext, error)
type BeDeletedMatcher ¶
type BeDeletedMatcher struct {
// contains filtered or unexported fields
}
func (*BeDeletedMatcher) FailureMessage ¶
func (m *BeDeletedMatcher) FailureMessage(actual interface{}) string
func (*BeDeletedMatcher) Match ¶
func (m *BeDeletedMatcher) Match(actual interface{}) (bool, error)
func (*BeDeletedMatcher) MatchMayChangeInTheFuture ¶
func (m *BeDeletedMatcher) MatchMayChangeInTheFuture(actual interface{}) bool
MatchMayChangeInTheFuture implements OracleMatcher which of course isn't exported so we can't type-assert we implement it
func (*BeDeletedMatcher) NegatedFailureMessage ¶
func (m *BeDeletedMatcher) NegatedFailureMessage(actual interface{}) string
type DesiredStateMatcher ¶
type DesiredStateMatcher struct {
// contains filtered or unexported fields
}
func (*DesiredStateMatcher) FailureMessage ¶
func (m *DesiredStateMatcher) FailureMessage(actual interface{}) string
func (*DesiredStateMatcher) Match ¶
func (m *DesiredStateMatcher) Match(actual interface{}) (bool, error)
func (*DesiredStateMatcher) MatchMayChangeInTheFuture ¶
func (m *DesiredStateMatcher) MatchMayChangeInTheFuture(actual interface{}) bool
MatchMayChangeInTheFuture implements OracleMatcher which of course isn't exported so we can't type-assert we implement it
func (*DesiredStateMatcher) NegatedFailureMessage ¶
func (m *DesiredStateMatcher) NegatedFailureMessage(actual interface{}) string
type KubeBaseTestContext ¶
type KubeBaseTestContext struct { PerTestContext KubeConfig *rest.Config }
type KubeGlobalContext ¶
type KubeGlobalContext struct { TestContext // contains filtered or unexported fields }
func NewKubeContext ¶
func NewKubeContext( useEnvTest bool, recordReplay bool, region string, nameConfig *ResourceNameConfig, ) (KubeGlobalContext, error)
func (KubeGlobalContext) Cleanup ¶
func (ctx KubeGlobalContext) Cleanup() error
func (KubeGlobalContext) ForTest ¶
func (ctx KubeGlobalContext) ForTest(t *testing.T) *KubePerTestContext
func (KubeGlobalContext) ForTestWithConfig ¶
func (ctx KubeGlobalContext) ForTestWithConfig(t *testing.T, cfg config.Values) *KubePerTestContext
type KubeMatcher ¶
type KubeMatcher struct {
// contains filtered or unexported fields
}
TODO: Put this into a subpackage TODO: Would we rather these just be on testcontext? Might read better
func NewKubeMatcher ¶
func NewKubeMatcher(verify *Verify, ctx context.Context) *KubeMatcher
func (*KubeMatcher) BeDeleted ¶
func (m *KubeMatcher) BeDeleted() types.GomegaMatcher
func (*KubeMatcher) BeFailed ¶
func (m *KubeMatcher) BeFailed(originalGeneration int64) types.GomegaMatcher
func (*KubeMatcher) BeInState ¶
func (m *KubeMatcher) BeInState(status metav1.ConditionStatus, severity conditions.ConditionSeverity, originalGeneration int64) types.GomegaMatcher
func (*KubeMatcher) BeProvisioned ¶
func (m *KubeMatcher) BeProvisioned(originalGeneration int64) types.GomegaMatcher
type KubePerTestContext ¶
type KubePerTestContext struct { *KubeGlobalContext KubeBaseTestContext G gomega.Gomega Verify *Verify Match *KubeMatcher MatchAzure *matchers.Azure // contains filtered or unexported fields }
func (*KubePerTestContext) AsExtensionOwner ¶
func (tc *KubePerTestContext) AsExtensionOwner(obj client.Object) *genruntime.ArbitraryOwnerReference
func (*KubePerTestContext) CheckIfResourceExists ¶
func (tc *KubePerTestContext) CheckIfResourceExists(obj client.Object) error
CheckIfResourceExists tries to get the current state of the resource from K8s (not from Azure), and if it does not exist, returns an error.
func (*KubePerTestContext) CreateResource ¶
func (tc *KubePerTestContext) CreateResource(obj client.Object)
CreateResource creates a resource and registers it for cleanup. It does not wait for the resource to be created, use CreateResourceAndWait for that
func (*KubePerTestContext) CreateResourceAndWait ¶
func (tc *KubePerTestContext) CreateResourceAndWait(obj client.Object)
CreateResourceAndWait creates the resource in K8s and waits for it to change into the Provisioned state.
func (*KubePerTestContext) CreateResourceAndWaitForFailure ¶
func (tc *KubePerTestContext) CreateResourceAndWaitForFailure(obj client.Object)
CreateResourceAndWaitForFailure creates the resource in K8s and waits for it to change into the Failed state.
func (*KubePerTestContext) CreateResourceAndWaitForState ¶
func (tc *KubePerTestContext) CreateResourceAndWaitForState( obj client.Object, status metav1.ConditionStatus, severity conditions.ConditionSeverity, )
CreateResourceAndWaitForState creates the resource in K8s and waits for the Ready condition to change into the specified state
func (*KubePerTestContext) CreateResourceAndWaitWithoutCleanup ¶
func (tc *KubePerTestContext) CreateResourceAndWaitWithoutCleanup(obj client.Object)
CreateResourceAndWaitWithoutCleanup creates the resource in K8s, waits for it to change into the Provisioned state and does not register cleanup for the resource.
func (*KubePerTestContext) CreateResourceExpectRequestFailure ¶
func (tc *KubePerTestContext) CreateResourceExpectRequestFailure(obj client.Object) error
CreateResourceExpectRequestFailure attempts to create a resource and asserts that the resource was NOT created (an error was returned). That error is returned for further assertions. This can be used to perform negative tests
func (*KubePerTestContext) CreateResourceUntracked ¶
func (tc *KubePerTestContext) CreateResourceUntracked(obj client.Object)
CreateResourceUntracked creates a resource. This does not register the resource for cleanup. This should only be used with resources like Namespaces that cannot be deleted in envtest. See the documentation on registerCleanup for more details.
func (*KubePerTestContext) CreateResourcesAndWait ¶
func (tc *KubePerTestContext) CreateResourcesAndWait(objs ...client.Object)
CreateResourcesAndWait creates the resources in K8s and waits for them to change into the Provisioned state.
func (*KubePerTestContext) CreateResourcesAndWaitWithoutCleanup ¶ added in v2.6.0
func (tc *KubePerTestContext) CreateResourcesAndWaitWithoutCleanup(objs ...client.Object)
func (*KubePerTestContext) CreateSimpleSecret ¶ added in v2.9.0
func (tc *KubePerTestContext) CreateSimpleSecret( name string, key string, secretData string, ) genruntime.SecretReference
func (KubePerTestContext) CreateTestNamespace ¶
func (tc KubePerTestContext) CreateTestNamespace(namespaceName string) error
func (*KubePerTestContext) CreateTestNamespaces ¶
func (tc *KubePerTestContext) CreateTestNamespaces(names ...string) error
func (*KubePerTestContext) CreateTestResourceGroupAndWait ¶
func (tc *KubePerTestContext) CreateTestResourceGroupAndWait() *resources.ResourceGroup
func (*KubePerTestContext) DefaultOperationTimeout ¶
func (tc *KubePerTestContext) DefaultOperationTimeout() time.Duration
func (*KubePerTestContext) DeleteResource ¶
func (tc *KubePerTestContext) DeleteResource(obj client.Object)
DeleteResource deletes the given resource in K8s
func (*KubePerTestContext) DeleteResourceAndWait ¶
func (tc *KubePerTestContext) DeleteResourceAndWait(obj client.Object)
DeleteResourceAndWait deletes the given resource in K8s and waits for it to update to the Deleted state.
func (*KubePerTestContext) DeleteResourcesAndWait ¶
func (tc *KubePerTestContext) DeleteResourcesAndWait(objs ...client.Object)
DeleteResourcesAndWait deletes the resources in K8s and waits for them to be deleted. Take care to avoid calling this method with incomplete resource hierarchies. For example, if resource A owns B and B owns C, call this with [A], [A, B], or [A, B, C], but NOT with [A, C].
Note that this protects against deleting resources that have a parent-child relationship in the same request. This is perfectly fine in the real world, but in many of our recording envtests we can get into a situation where there's a race during deletion that causes HTTP replay issues. The sequence of events is:
- Delete parent resource and child resource at the same time.
- During recording, child deletion never sees a successful (finished) DELETE request because parent is deleted so soon after the child that we just record a successful DELETE for the parent and don't bother sending the final child DELETE that would return success.
- During replay, the race is how quickly the parent deletes and how many requests the child has a chance to send in that time. If the parent deletes slowly the child might try to send more requests than we actually have recorded (because none of them represent a terminal "actually deleted" state), which will cause a test failure.
In envtest it's still critical to delete everything, because ownership based deletion isn't enabled in envtest and we can't leave resources around or they will continue to attempt to log to a closed test logger. To avoid this we carefully delete resources starting with the root and working our way down one rank at a time. This shouldn't be much slower than just deleting everything all at once. Once the root resources are deleted (first) each child resource will delete immediately as it realizes that its parent is already gone.
func (*KubePerTestContext) Eventually ¶
func (tc *KubePerTestContext) Eventually(actual interface{}, intervals ...interface{}) gomega.AsyncAssertion
func (*KubePerTestContext) Expect ¶
func (tc *KubePerTestContext) Expect(actual interface{}) gomega.Assertion
func (*KubePerTestContext) ExpectConfigMapHasKeys ¶
func (tc *KubePerTestContext) ExpectConfigMapHasKeys(name string, expectedKeys ...string)
ExpectConfigMapHasKeys checks if the config map with the given name has the expected keys. If the config map does not exist, or it is missing keys, the test fails.
func (*KubePerTestContext) ExpectConfigMapHasKeysAndValues ¶
func (tc *KubePerTestContext) ExpectConfigMapHasKeysAndValues(name string, expectedKeysAndValues ...string)
ExpectConfigMapHasKeysAndValues checks if the config map with the given name has the expected keys with the expected values. The keys and values should be alternating If the config map does not exist, or it is missing keys, the test fails.
func (*KubePerTestContext) ExpectResourceDoesNotExist ¶
func (tc *KubePerTestContext) ExpectResourceDoesNotExist(key types.NamespacedName, obj client.Object)
ExpectResourceDoesNotExist ensures the resource doesn't exist
func (*KubePerTestContext) ExpectResourceIsDeletedInAzure ¶
func (tc *KubePerTestContext) ExpectResourceIsDeletedInAzure(armId string, apiVersion string)
func (*KubePerTestContext) ExpectSecretHasKeys ¶
func (tc *KubePerTestContext) ExpectSecretHasKeys(name string, expectedKeys ...string)
ExpectSecretHasKeys checks if the secret with the given name has the expected keys. If the secret does not exist, or it is missing keys, the test fails.
func (*KubePerTestContext) ExportAsSample ¶
func (tc *KubePerTestContext) ExportAsSample(resource client.Object)
func (*KubePerTestContext) ExportAsSampleNamed ¶ added in v2.6.0
func (tc *KubePerTestContext) ExportAsSampleNamed(resource client.Object, name string)
func (*KubePerTestContext) GetResource ¶
func (tc *KubePerTestContext) GetResource(key types.NamespacedName, obj client.Object)
GetResource retrieves the current state of the resource from K8s (not from Azure).
func (*KubePerTestContext) GetScheme ¶
func (tc *KubePerTestContext) GetScheme() *runtime.Scheme
GetScheme returns the scheme for kubeclient
func (*KubePerTestContext) GetSecret ¶
func (tc *KubePerTestContext) GetSecret(name string) *corev1.Secret
GetSecret retrieves the specified secret from K8s. The namespace used is the default tc.Namespace.
func (*KubePerTestContext) KubeClient ¶
func (tc *KubePerTestContext) KubeClient() client.Client
KubeClient returns the KubeClient for the test context. The existing TestContext helpers (tc.Resource(), etc) should be used unless you need a raw KubeClient.
func (*KubePerTestContext) ListResources ¶
func (tc *KubePerTestContext) ListResources(list client.ObjectList, opts ...client.ListOption)
ListResources retrieves list of objects for a given namespace and list options. On a successful call, Items field in the list will be populated with the result returned from the server.
func (*KubePerTestContext) LogSectionf ¶ added in v2.4.0
func (tc *KubePerTestContext) LogSectionf(section string, args ...any)
LogSection creates a distinctive header in the log to aid scanning
func (*KubePerTestContext) LogSubsectionf ¶ added in v2.4.0
func (tc *KubePerTestContext) LogSubsectionf(subsection string, args ...any)
LogSection creates a distinctive header in the log to aid scanning
func (KubePerTestContext) MakeObjectMeta ¶
func (tc KubePerTestContext) MakeObjectMeta(prefix string) ctrl.ObjectMeta
func (KubePerTestContext) MakeObjectMetaWithName ¶
func (tc KubePerTestContext) MakeObjectMetaWithName(name string) ctrl.ObjectMeta
func (KubePerTestContext) MakeObjectMetaWithNameAndCredentialFrom ¶ added in v2.6.0
func (tc KubePerTestContext) MakeObjectMetaWithNameAndCredentialFrom(name string, credentialFrom string) ctrl.ObjectMeta
func (KubePerTestContext) MakeReferenceFromResource ¶
func (tc KubePerTestContext) MakeReferenceFromResource(resource client.Object) *genruntime.ResourceReference
func (KubePerTestContext) NewTestResourceGroup ¶
func (tc KubePerTestContext) NewTestResourceGroup() *resources.ResourceGroup
func (*KubePerTestContext) OperationTimeout ¶
func (tc *KubePerTestContext) OperationTimeout() time.Duration
OperationTimeout returns a “nice” operation timeout. It will return DefaultOperationTimeout() unless we are close to test termination (deadline timeout), in which case we will return that. This improves the behaviour in the case where we are about to hit the deadline.
(If you hit the deadline 'go test' aborts everything and dumps the current task stacks to output. If gomega.Eventually hits its timeout it will produce a nicer error message and stack trace.)
func (*KubePerTestContext) Patch ¶
func (tc *KubePerTestContext) Patch(old client.Object, new client.Object)
func (*KubePerTestContext) PatchAndExpectError ¶
func (*KubePerTestContext) PatchResourceAndWait ¶
func (tc *KubePerTestContext) PatchResourceAndWait(old client.Object, new client.Object)
PatchResourceAndWait patches the resource in K8s and waits for it to change into the Provisioned state from the provided previousState.
func (*KubePerTestContext) PatchResourceAndWaitForState ¶ added in v2.3.0
func (tc *KubePerTestContext) PatchResourceAndWaitForState( old client.Object, new client.Object, status metav1.ConditionStatus, severity conditions.ConditionSeverity, )
PatchResourceAndWaitForState patches the resource in K8s and waits for the Ready condition to change into the specified state
func (*KubePerTestContext) PatchStatus ¶
func (tc *KubePerTestContext) PatchStatus(old client.Object, new client.Object)
PatchStatus should be used sparingly but can be helpful to make a change to Status so that we can detect subsequent reconciles even if there was no change to generation or resourceVersion
func (*KubePerTestContext) PollingInterval ¶
func (tc *KubePerTestContext) PollingInterval() time.Duration
PollingInterval returns the polling interval to use for Gomega Eventually
func (*KubePerTestContext) RunParallelSubtests ¶
func (tc *KubePerTestContext) RunParallelSubtests(tests ...Subtest)
RunParallelSubtests runs the given tests in parallel. They are given their own KubePerTestContext.
func (*KubePerTestContext) RunSubtests ¶
func (tc *KubePerTestContext) RunSubtests(tests ...Subtest)
RunSubtests runs the given subtests in sequence. They are given their own KubePerTestContext. This does NOT run the tests in parallel. In most cases, RunParallelSubtests should be used instead of this.
func (*KubePerTestContext) Subtest ¶
func (tc *KubePerTestContext) Subtest(t *testing.T) *KubePerTestContext
Subtest replaces any testing.T-specific types with new values
func (*KubePerTestContext) UpdateResource ¶
func (tc *KubePerTestContext) UpdateResource(obj client.Object)
UpdateResource updates the given resource in K8s.
type PerTestContext ¶
type PerTestContext struct { TestContext T *testing.T AzureClientRecorder vcr.Interface AzureClient *genericarmclient.GenericClient AzureSubscription string AzureTenant string AzureBillingInvoiceID string AzureMatch *ARMMatcher HttpClient *http.Client Namer ResourceNamer NoSpaceNamer ResourceNamer TestName string Namespace string Ctx context.Context // CountsTowardsParallelLimits true means that the envtest (if any) started for this test pass counts towards the limit of // concurrent envtests running at once. If this is false, it doesn't count towards the limit. CountsTowardsParallelLimits bool // contains filtered or unexported fields }
func (PerTestContext) GenerateSSHKey ¶
func (tc PerTestContext) GenerateSSHKey(size int) (*string, error)
GenerateSSHKey generates an SSH key.
func (PerTestContext) NewTestResourceGroup ¶
func (tc PerTestContext) NewTestResourceGroup() *resources.ResourceGroup
func (PerTestContext) WithLiteralRedaction ¶ added in v2.9.0
func (tc PerTestContext) WithLiteralRedaction(redactionValue string, replacementValue string)
WithLiteralRedaction method is used to add literal redaction values based on the requirements of each test. The method takes in redactValue to be `redacted` and replacement value to which the value should be `replaced`.
func (PerTestContext) WithRegexpRedaction ¶ added in v2.9.0
func (tc PerTestContext) WithRegexpRedaction(pattern string, replacementValue string)
WithRegexpRedaction method is used to add regexp redaction values based on the requirements of each test. The method takes in regexp pattern to be `redacted` and replacement value to which the value should be `replaced`.
type ResourceNameConfig ¶
type ResourceNameConfig struct {
// contains filtered or unexported fields
}
func NewResourceNameConfig ¶
func NewResourceNameConfig(prefix string, separator string, randomChars int, mode ResourceNamerMode) *ResourceNameConfig
func (ResourceNameConfig) NewResourceNamer ¶
func (rnc ResourceNameConfig) NewResourceNamer(testName string) ResourceNamer
NewResourceNamer returns a ResourceNamer that generates random suffixes based upon the test name
type ResourceNamer ¶
type ResourceNamer struct { ResourceNameConfig // contains filtered or unexported fields }
func (ResourceNamer) GenerateName ¶
func (n ResourceNamer) GenerateName(prefix string) string
func (ResourceNamer) GenerateNameOfLength ¶ added in v2.9.0
func (n ResourceNamer) GenerateNameOfLength(length int) string
func (ResourceNamer) GeneratePassword ¶
func (n ResourceNamer) GeneratePassword() string
func (ResourceNamer) GeneratePasswordOfLength ¶
func (n ResourceNamer) GeneratePasswordOfLength(length int) string
GeneratePasswordOfLength generates and returns a non-deterministic password. This method does not use any seed value, so the returned password is never stable.
func (ResourceNamer) GenerateSecretOfLength ¶ added in v2.9.0
func (n ResourceNamer) GenerateSecretOfLength(length int) string
GenerateSecretOfLength generates and returns a non-deterministic secret. This method does not use any seed value, so the returned password is never stable.
func (ResourceNamer) GenerateUUID ¶
func (n ResourceNamer) GenerateUUID() (uuid.UUID, error)
func (ResourceNamer) WithNumRandomChars ¶
func (n ResourceNamer) WithNumRandomChars(num int) ResourceNamer
WithNumRandomChars returns a copy of the ResourceNamer which will generate names with a random string of the given length included
func (ResourceNamer) WithSeparator ¶
func (n ResourceNamer) WithSeparator(separator string) ResourceNamer
WithSeparator returns a copy of the ResourceNamer with the given separator
func (ResourceNamer) WithTestName ¶
func (n ResourceNamer) WithTestName(testName string) ResourceNamer
WithTestName returns a new ResourceNamer configured based on the provided test name. The mode of the original resource namer is preserved.
type ResourceNamerMode ¶
type ResourceNamerMode string
type ResourceTracker ¶
type ResourceTracker struct {
// contains filtered or unexported fields
}
func (*ResourceTracker) Resources ¶
func (r *ResourceTracker) Resources() []client.Object
func (*ResourceTracker) Track ¶
func (r *ResourceTracker) Track(obj client.Object)
type SampleObject ¶
func NewSampleObject ¶
func NewSampleObject() *SampleObject
func (*SampleObject) HasSamples ¶ added in v2.1.0
func (s *SampleObject) HasSamples() bool
type SamplesTester ¶
type SamplesTester struct {
// contains filtered or unexported fields
}
func NewSamplesTester ¶
func NewSamplesTester( noSpaceNamer ResourceNamer, scheme *runtime.Scheme, groupVersionPath string, namespace string, useRandomName bool, rgName string, azureSubscription string, azureTenant string, ) *SamplesTester
func (*SamplesTester) LoadSamples ¶
func (t *SamplesTester) LoadSamples() (*SampleObject, error)
type SimpleExtensionResource ¶
type SimpleExtensionResource struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` Spec SimpleExtensionResourceSpec `json:"spec,omitempty"` Status SimpleExtensionResourceStatus `json:"status,omitempty"` }
func (*SimpleExtensionResource) AzureName ¶
func (r *SimpleExtensionResource) AzureName() string
AzureName returns the Azure name of the resource
func (*SimpleExtensionResource) DeepCopyObject ¶
func (r *SimpleExtensionResource) DeepCopyObject() runtime.Object
func (*SimpleExtensionResource) Default ¶
func (r *SimpleExtensionResource) Default()
Default defaults the Azure name of the resource to the Kubernetes name
func (*SimpleExtensionResource) GetAPIVersion ¶
func (r *SimpleExtensionResource) GetAPIVersion() string
func (*SimpleExtensionResource) GetConditions ¶
func (r *SimpleExtensionResource) GetConditions() conditions.Conditions
GetConditions returns the conditions of the resource
func (*SimpleExtensionResource) GetResourceScope ¶
func (r *SimpleExtensionResource) GetResourceScope() genruntime.ResourceScope
GetResourceScope returns the scope of the resource
func (*SimpleExtensionResource) GetSpec ¶
func (r *SimpleExtensionResource) GetSpec() genruntime.ConvertibleSpec
func (*SimpleExtensionResource) GetStatus ¶
func (r *SimpleExtensionResource) GetStatus() genruntime.ConvertibleStatus
func (*SimpleExtensionResource) GetSupportedOperations ¶ added in v2.4.0
func (r *SimpleExtensionResource) GetSupportedOperations() []genruntime.ResourceOperation
func (*SimpleExtensionResource) GetType ¶
func (r *SimpleExtensionResource) GetType() string
func (*SimpleExtensionResource) NewEmptyStatus ¶
func (r *SimpleExtensionResource) NewEmptyStatus() genruntime.ConvertibleStatus
func (*SimpleExtensionResource) Owner ¶
func (r *SimpleExtensionResource) Owner() *genruntime.ResourceReference
Owner returns the ResourceReference of the owner, or nil if there is no owner
func (*SimpleExtensionResource) SetConditions ¶
func (r *SimpleExtensionResource) SetConditions(conditions conditions.Conditions)
SetConditions sets the conditions on the resource status
func (*SimpleExtensionResource) SetStatus ¶
func (r *SimpleExtensionResource) SetStatus(status genruntime.ConvertibleStatus) error
type SimpleExtensionResourceSpec ¶
type SimpleExtensionResourceSpec struct { AzureName string `json:"azureName,omitempty"` Owner genruntime.ArbitraryOwnerReference `json:"owner"` }
func (SimpleExtensionResourceSpec) ConvertSpecFrom ¶
func (s SimpleExtensionResourceSpec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error
func (SimpleExtensionResourceSpec) ConvertSpecTo ¶
func (s SimpleExtensionResourceSpec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error
type SimpleExtensionResourceStatus ¶
type SimpleExtensionResourceStatus struct {
Conditions []conditions.Condition `json:"conditions,omitempty"`
}
func (SimpleExtensionResourceStatus) ConvertStatusFrom ¶
func (s SimpleExtensionResourceStatus) ConvertStatusFrom(source genruntime.ConvertibleStatus) error
func (SimpleExtensionResourceStatus) ConvertStatusTo ¶
func (s SimpleExtensionResourceStatus) ConvertStatusTo(destination genruntime.ConvertibleStatus) error
type Subtest ¶
type Subtest struct { Name string Test func(testContext *KubePerTestContext) }
type TestContext ¶
type TestContext struct { AzureRegion *string NameConfig *ResourceNameConfig RecordReplay bool }
func NewTestContext ¶
func NewTestContext( region string, recordReplay bool, nameConfig *ResourceNameConfig, ) TestContext
func (TestContext) ForTest ¶
func (tc TestContext) ForTest(t *testing.T, cfg config.Values) (PerTestContext, error)
type TestLogger ¶
type TestLogger struct {
// contains filtered or unexported fields
}
TestLogger is a logr.Logger wrapper around t.Log, so that we can use it in the controller
func (*TestLogger) Enabled ¶
func (t *TestLogger) Enabled(_level int) bool
func (*TestLogger) Error ¶
func (t *TestLogger) Error(err error, msg string, keysAndValues ...interface{})
func (*TestLogger) Info ¶
func (t *TestLogger) Info(level int, msg string, keysAndValues ...interface{})
func (TestLogger) Init ¶
func (_ TestLogger) Init(info logr.RuntimeInfo)
func (*TestLogger) WithValues ¶
func (t *TestLogger) WithValues(keysAndValues ...interface{}) logr.LogSink
type Verify ¶
type Verify struct {
// contains filtered or unexported fields
}
func (*Verify) AllDeleted ¶
AllDeleted verifies that all of the specified objects are deleted
func (*Verify) HasState ¶
func (e *Verify) HasState( ctx context.Context, obj client.Object, desiredState metav1.ConditionStatus, desiredSeverity conditions.ConditionSeverity, oldGeneration int64, ) (bool, error)
HasState verifies that the provisioning state of the resource is in the target state.
type WaitCondition ¶
type WaitCondition bool
const ( WaitForCreation WaitCondition = true DoNotWait WaitCondition = false )
Source Files ¶
- arm_matcher.go
- azure_be_deleted_matcher.go
- azure_be_provisioned_matcher.go
- be_deleted_matcher.go
- be_provisioned_matcher.go
- client.go
- credential_provider_wrapper.go
- direct_client.go
- equal_ignore_case_matcher.go
- kube_client_no_cache.go
- kube_matcher.go
- kube_per_test_context.go
- kube_test_context.go
- kube_test_context_envtest.go
- kube_test_context_real.go
- owner_lookup.go
- resolver.go
- resource_groups.go
- resource_namer.go
- resources.go
- sample_resource.go
- samples_tester.go
- scheme.go
- test_context.go
- test_logger.go
- test_recorder.go
- verify.go
- wait.go