resourcehelpers

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ErrorReasonCodeProviderResourceTypeNotFound is provided when the
	// reason for a blueprint spec load error is due to
	// the resource provider missing an implementation for a
	// specific resource type.
	ErrorReasonCodeProviderResourceTypeNotFound errors.ErrorReasonCode = "resource_type_not_found"
	// ErrorReasonCodeItemTypeProviderNotFound is provided when the
	// reason for a blueprint run error is due to the provider
	// for a specific resource type not being found.
	ErrorReasonCodeEmptyResourceSpecDefinition errors.ErrorReasonCode = "empty_resource_spec_definition"
	// ErrorReasonCodeMultipleRunErrors is provided when the reason
	// for a blueprint run error is due to multiple errors
	// occurring during the run.
	ErrorReasonCodeMultipleRunErrors errors.ErrorReasonCode = "multiple_run_errors"
	// ErrorReasonCodeAbstractResourceTypeNotFound is provided when the
	// reason for a blueprint run error is due to an abstract resource
	// type not being found in any of the loaded transformers.
	ErrorReasonCodeAbstractResourceTypeNotFound errors.ErrorReasonCode = "abstract_resource_type_not_found"
)
View Source
const (
	// DefaultResourceLockTimeout is the default timeout for acquiring a resource lock.
	DefaultResourceLockTimeout = 3 * time.Minute
	// DefaultResourceLockCheckInterval is the default interval at which the resource lock
	// will be checked for availability when acquiring a lock.
	DefaultResourceLockCheckInterval = 100 * time.Millisecond
)

Variables

This section is empty.

Functions

func IsComputedField

func IsComputedField(changes *provider.Changes, fieldPath string) bool

IsComputedField returns whether the given field path is a computed field in the given set of resource changes.

func IsComputedFieldInList

func IsComputedFieldInList(expectedComputedFields []string, fieldPath string) bool

IsComputedFieldInList returns whether the given field path is a computed field in the given list of computed fields.

This allows for matching "[0]" and "[\"<key>\"]" placeholders in the expectedComputedFields list to match any array item or map key-value pair in the computed field path.

Types

type Registry

type Registry interface {
	// GetSpecDefinition returns the definition of a resource spec
	// in the registry.
	GetSpecDefinition(
		ctx context.Context,
		resourceType string,
		input *provider.ResourceGetSpecDefinitionInput,
	) (*provider.ResourceGetSpecDefinitionOutput, error)

	// GetTypeDescription returns the description of a resource type
	// in the registry.
	GetTypeDescription(
		ctx context.Context,
		resourceType string,
		input *provider.ResourceGetTypeDescriptionInput,
	) (*provider.ResourceGetTypeDescriptionOutput, error)

	// HasResourceType checks if a resource type is available in the registry.
	HasResourceType(ctx context.Context, resourceType string) (bool, error)

	// ListResourceTypes returns a list of all resource types available in the registry.
	ListResourceTypes(ctx context.Context) ([]string, error)

	// CustomValidate allows for custom validation of a resource of a given type.
	CustomValidate(
		ctx context.Context,
		resourceType string,
		input *provider.ResourceValidateInput,
	) (*provider.ResourceValidateOutput, error)

	// Deploy deals with the deployment of a resource of a given type.
	// The caller can specify whether or not to wait until the resource is considered
	// stable.
	Deploy(
		ctx context.Context,
		resourceType string,
		input *provider.ResourceDeployServiceInput,
	) (*provider.ResourceDeployOutput, error)

	// Destroy deals with the destruction of a resource of a given type.
	Destroy(
		ctx context.Context,
		resourceType string,
		input *provider.ResourceDestroyInput,
	) error

	// StabilisedDependencies lists the resource types that are required to be stable
	// when a resource that is a dependency of the given resource type is being deployed.
	GetStabilisedDependencies(
		ctx context.Context,
		resourceType string,
		input *provider.ResourceStabilisedDependenciesInput,
	) (*provider.ResourceStabilisedDependenciesOutput, error)

	// LookupResourceInState retrieves a resource of a given type
	// from the blueprint state.
	LookupResourceInState(
		ctx context.Context,
		input *provider.ResourceLookupInput,
	) (*state.ResourceState, error)

	// HasResourceInState checks if a resource of a given type
	// exists in the blueprint state.
	HasResourceInState(
		ctx context.Context,
		input *provider.ResourceLookupInput,
	) (bool, error)

	// AcquireResourceLock acquires a lock on a resource
	// in the blueprint state to ensure that no other operations
	// are modifying the resource at the same time.
	// This is useful for links that need to update existing resources
	// in the same blueprint as a part of the intermediary resources update phase.
	// The blueprint container will ensure that the lock is released after the
	// update intermediary resources phase is complete for the current link.
	// The lock will be released if the link update fails or by the resource registry
	// if a lock timeout occurs.
	AcquireResourceLock(
		ctx context.Context,
		input *provider.AcquireResourceLockInput,
	) error

	// ReleaseResourceLock releases a lock on a resource of a given type
	// in the blueprint state.
	// This is to be used by the deployment orchestrator to release the lock
	// after the link update phase is complete or the link update fails.
	ReleaseResourceLock(
		ctx context.Context,
		instanceID string,
		resourceName string,
	)

	// ReleaseResourceLocks releases all resource locks
	// that have been acquired for the given instance ID.
	ReleaseResourceLocks(ctx context.Context, instanceID string)

	// ReleaseResourceLocksAcquiredBy releases all resource locks
	// that have been acquired by a specific caller (e.g. a link).
	// This is useful for releasing locks proactively instead of waiting
	// for the lock timeout to occur.
	ReleaseResourceLocksAcquiredBy(ctx context.Context, instanceID string, acquiredBy string)

	// WithParams creates a new registry derived from the current registry
	// with the given parameters.
	WithParams(
		params core.BlueprintParams,
	) Registry
}

Registry provides a way to retrieve resource plugins across multiple providers and transformers for tasks such as resource spec validation.

func NewRegistry

func NewRegistry(
	providers map[string]provider.Provider,
	transformers map[string]transform.SpecTransformer,
	stabilisationPollingInterval time.Duration,
	stateContainer state.Container,
	params core.BlueprintParams,
	opts ...RegistryOption,
) Registry

NewRegistry creates a new resource registry from a map of providers, matching against providers based on the resource type prefix.

type RegistryOption added in v0.30.0

type RegistryOption func(*registryFromProviders)

RegistryOption is a function that modifies the registryFromProviders to allow for additional configuration options when creating a new registry.

func WithClock added in v0.30.0

func WithClock(clock core.Clock) RegistryOption

WithClock sets the clock to be used by the registry.

func WithResourceLockCheckInterval added in v0.30.0

func WithResourceLockCheckInterval(interval time.Duration) RegistryOption

WithResourceLockCheckInterval sets the interval at which the resource lock will be checked for availability when acquiring a lock. If not provided, the default interval is 100 milliseconds.

func WithResourceLockTimeout added in v0.30.0

func WithResourceLockTimeout(timeout time.Duration) RegistryOption

WithResourceLockTimeout sets the timeout for acquiring a resource lock. If not provided, the default timeout is 180 seconds (3 minutes).

Jump to

Keyboard shortcuts

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