integrationtests

package
v0.2023.21 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

ITest is the globally accessible integration test "context"

Functions

func StandardFileRequest added in v0.9.0

func StandardFileRequest(namePrefix string) *api.SPIFileContentRequest

func StandardTestBinding added in v0.9.0

func StandardTestBinding(namePrefix string) *api.SPIAccessTokenBinding

StandardTestBinding creates an SPIAccessTokenBinding with the configuration commonly used in the tests.

func StandardTestToken added in v0.9.0

func StandardTestToken(namePrefix string) *api.SPIAccessToken

StandardTestToken creates an SPIAccessToken with the configuration commonly used in the tests.

func TriggerReconciliation added in v0.9.0

func TriggerReconciliation(object client.Object)

TriggerReconciliation updates the provided object with a "random-annon-to-trigger-reconcile" annotation (with a random value) so that a new reconciliation is performed.

Types

type ITestBehavior added in v0.9.0

type ITestBehavior struct {
	// BeforeObjectsCreated sets up the behavior before any of the desired objects specified in TestSetup.ToCreate are
	// actually created.
	BeforeObjectsCreated func()
	// AfterObjectsCreated sets up the behavior after the objects from TestSetup.ToCreate (and possibly others, like
	// auto-created tokens for the bindings) have been created. The objects currently existing in the cluster are passed
	// in as an argument.
	AfterObjectsCreated func(TestObjects)
	// DontTriggerReconcileAfterObjectsCreated in the unlikely event, where you DON'T want to trigger the reconciliation
	// of the objects in the cluster after the ITest behavior was changed in AfterObjectsCreated, set this to true.
	DontTriggerReconcileAfterObjectsCreated bool
}

ITestBehavior configures the ITest for the tests.

type ITestTiming added in v0.9.0

type ITestTiming struct {
	// Tokens is the TTL of the tokens
	Tokens time.Duration
	// Bindings is the TTL of the bindings
	Bindings time.Duration
	// Checks is the TTL of the SPIAccessChecks
	Checks time.Duration
	// FileRequests is the TTL of the SPIFileContentRequests
	FileRequests time.Duration
	// TokenLookupCache is the TTL of the token metadata
	TokenLookupCache time.Duration
	// DeletionGracePeriod is the grace period before tokens in awaiting state are deleted
	DeletionGracePeriod time.Duration
}

ITestTiming collects all the timing configuration. The changes made in ITestBehavior methods (if any) take precedence over what is configured here.

type IntegrationTest added in v0.9.0

type IntegrationTest struct {
	// Client is the Kubernetes client to use to talk to the Kubernetes cluster
	Client client.Client
	// NoPrivsClient is a Kubernetes client to use to talk to the Kubernetes cluster that doesn't have any permissions
	NoPrivsClient client.Client
	// TestEnvironment is the Kubernetes API abstraction that we're using to simulate a full-blown cluster
	TestEnvironment *envtest.Environment
	// Context is the context to use with various API requests. It is set up with timeout cancelling to correctly handle
	// the testsuite timeouts. Use Cancel to force the cancellation of the context yourself, if ever needed.
	Context context.Context
	// TokenStorage is the token storage instance that the controllers are using to store the token data. By default,
	// this is backed the VaultTestCluster.
	TokenStorage tokenstorage.TokenStorage
	// Cancel can be used to forcefully cancel the Context, interrupting all the future requests and thus short-circuiting
	// the testsuite as a whole.
	Cancel context.CancelFunc
	// TestServiceProviderProbe is the probing function to identify the service provider to use. This is automagically
	// setup to recognize the URLs starting with "test-provider://" as handled by the TestServiceProvider.
	TestServiceProviderProbe serviceprovider.Probe
	// TestServiceProvider is the service provider that the controllers are set up to use. You can modify its behavior
	// in the before-each of the tests.
	TestServiceProvider serviceprovider.TestServiceProvider
	// Capabilities is a pluggable implementation of the capabilities that can implemented by the service providers.
	// Note that by default the TestServiceProvider is NOT set up to return this instance (i.e. by default, the test
	// service provider doesn't support any additional capabilities).
	// This instance is set up with the default implementations of the methods so that the callers don't have to set
	// them up if they don't need to.
	Capabilities serviceprovider.TestCapabilities
	// HostCredsServiceProvider is the fallback provider used when no other service provider is detected for given URL.
	HostCredsServiceProvider serviceprovider.TestServiceProvider
	// VaultTestCluster is Vault's in-memory test cluster instance.
	VaultTestCluster *vault.TestCluster
	// OperatorConfiguration is the "live" configuration used by the controllers. Changing the values here has direct
	// effect in the controllers as long as they don't cache the values somehow (by storing them in an instance field
	// for example).
	OperatorConfiguration *opconfig.OperatorConfiguration
	// MetricsRegistry is the metrics registry the controllers are configured with. This can be used to check that the
	// metrics are being collected.
	MetricsRegistry *prometheus.Registry
	// Custom validation options to register
	ValidationOptions config.CustomValidationOptions
}

IntegrationTest is meant to be used through the ITest global variable to inspect and configure the behavior of the various subsystems of SPI.

type LoggingKubernetesClient added in v0.2023.21

type LoggingKubernetesClient struct {
	Client             client.Client
	LogReads           bool
	LogWrites          bool
	IncludeStacktraces bool
}

LoggingKubernetesClient is a wrapper aroung a Kubernetes client that is capable of logging the calls to the Kubernetes API. It is meant to be used only in tests and integration tests!

func (*LoggingKubernetesClient) Create added in v0.2023.21

Create implements client.Client

func (*LoggingKubernetesClient) Delete added in v0.2023.21

Delete implements client.Client

func (*LoggingKubernetesClient) DeleteAllOf added in v0.2023.21

DeleteAllOf implements client.Client

func (*LoggingKubernetesClient) Get added in v0.2023.21

Get implements client.Client

func (*LoggingKubernetesClient) List added in v0.2023.21

List implements client.Client

func (*LoggingKubernetesClient) Patch added in v0.2023.21

Patch implements client.Client

func (*LoggingKubernetesClient) RESTMapper added in v0.2023.21

func (c *LoggingKubernetesClient) RESTMapper() meta.RESTMapper

RESTMapper implements client.Client

func (*LoggingKubernetesClient) Scheme added in v0.2023.21

func (c *LoggingKubernetesClient) Scheme() *runtime.Scheme

Scheme implements client.Client

func (*LoggingKubernetesClient) Status added in v0.2023.21

Status implements client.Client

func (*LoggingKubernetesClient) SubResource added in v0.2023.21

func (c *LoggingKubernetesClient) SubResource(subResource string) client.SubResourceClient

SubResource implements client.Client

func (*LoggingKubernetesClient) Update added in v0.2023.21

Update implements client.Client

type TestObjects added in v0.9.0

type TestObjects struct {
	Tokens              []*api.SPIAccessToken
	Bindings            []*api.SPIAccessTokenBinding
	Checks              []*api.SPIAccessCheck
	FileContentRequests []*api.SPIFileContentRequest
	DataUpdates         []*api.SPIAccessTokenDataUpdate
}

TestObjects collects the objects of interest as they are required or exist in the cluster

func (TestObjects) GetBinding added in v0.9.0

func (TestObjects) GetBindingsByNamePrefix added in v0.9.0

func (to TestObjects) GetBindingsByNamePrefix(key client.ObjectKey) []*api.SPIAccessTokenBinding

func (TestObjects) GetCheck added in v0.9.0

func (to TestObjects) GetCheck(key client.ObjectKey) *api.SPIAccessCheck

func (TestObjects) GetChecksByNamePrefix added in v0.9.0

func (to TestObjects) GetChecksByNamePrefix(key client.ObjectKey) []*api.SPIAccessCheck

func (TestObjects) GetDataUpdate added in v0.9.0

func (to TestObjects) GetDataUpdate(key client.ObjectKey) *api.SPIAccessTokenDataUpdate

func (TestObjects) GetDataUpdatesByNamePrefix added in v0.9.0

func (to TestObjects) GetDataUpdatesByNamePrefix(key client.ObjectKey) []*api.SPIAccessTokenDataUpdate

func (TestObjects) GetFileContentRequest added in v0.9.0

func (to TestObjects) GetFileContentRequest(key client.ObjectKey) *api.SPIFileContentRequest

func (TestObjects) GetFileContentRequestsByNamePrefix added in v0.9.0

func (to TestObjects) GetFileContentRequestsByNamePrefix(key client.ObjectKey) []*api.SPIFileContentRequest

func (TestObjects) GetToken added in v0.9.0

func (to TestObjects) GetToken(key client.ObjectKey) *api.SPIAccessToken

func (TestObjects) GetTokensByNamePrefix added in v0.9.0

func (to TestObjects) GetTokensByNamePrefix(key client.ObjectKey) []*api.SPIAccessToken

type TestSetup added in v0.9.0

type TestSetup struct {
	// ToCreate is a list of objects that are expected to be present in the cluster. Once BeforeEach is called, the
	// true state of those objects is stored in the InCluster field.
	ToCreate TestObjects
	// InCluster references all the objects (that we're interested in) that exist in the cluster. It is filled in during
	// the BeforeEach method and represents the true state of the objects (no need to load them again after BeforeEach
	// completes).
	InCluster TestObjects
	// Behavior is used to set up the behavior of the ITest at various stages (you can modify the service providers,
	// configuration, etc.)
	Behavior ITestBehavior
	// Timing configures the different periods and TTLs desired. By default, everything is set up to never expire so
	// that the test methods don't need to take into account the disappearance of objects due to unpredictable timing
	// issues.
	Timing ITestTiming
	// contains filtered or unexported fields
}

TestSetup is used to express the requirements on the state of the K8s Cluster before the tests. Once an instance with the desired configuration is produced, its BeforeEach and AfterEach methods can be called to bring the cluster to the desired state and tear it back down.

func (*TestSetup) AfterEach added in v0.9.0

func (ts *TestSetup) AfterEach()

AfterEach cleans up all the objects from the cluster and reverts the behavior of ITest to what it was before the test started (to what BeforeEach stored).

func (*TestSetup) BeforeEach added in v0.9.0

func (ts *TestSetup) BeforeEach(postCondition func(Gomega))

BeforeEach is where the magic happens. It first checks that the cluster is empty, then stores the configuration of the ITest, resets it, creates the required objects, re-configures the ITest and waits for the cluster state to settle (i.e. wait for the controllers to create all the additional objects and finish all the reconciles). Once this method returns, the TestSetup.InCluster contains the objects of interest as they exist in the cluster after all the reconciliation has been performed at least once with the reconfigured ITest.

The `postCondition` is a (potentially `nil`) check that needs to succeed before we can claim the cluster reached the desired state. If it is `nil`, then only the best effort is made to wait for the controllers to finish the reconciliation (basically the only thing guaranteed is that the objects will have a status, i.e. the reconciliation happened at least once).

NOTE we're not doing anything with the metrics registry so far here...

func (*TestSetup) ReconcileWithCluster added in v0.9.0

func (ts *TestSetup) ReconcileWithCluster(postCondition func(Gomega))

ReconcileWithCluster triggers the reconciliation and waits for the cluster to settle again. This can be used after a test or a nested Gomega.BeforeEach modifies the behavior and we need to re-sync and wait for the controllers to accommodate for the changed behavior.

The `postCondition` is a (potentially `nil`) check that needs to succeed before we can claim the cluster reached the desired state. If it is `nil`, then only the best effort is made to wait for the controllers to finish the reconciliation (basically the only thing guaranteed is that the objects will have a status, i.e. the reconciliation happened at least once).

The `postCondition` can use the `testSetup.InCluster` to access the current state of the objects (which is being updated during this call).

Jump to

Keyboard shortcuts

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