resourcehelpers

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 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"
	// ErrorReasonCodeResourceLockTimeout is provided when a lock on a resource
	// could not be acquired before the acquire timeout elapsed, because another
	// link still holds it.
	ErrorReasonCodeResourceLockTimeout errors.ErrorReasonCode = "resource_lock_timeout"
)
View Source
const (
	// DefaultResourceLockTimeout is the default time a caller waits for a resource lock
	// before giving up. It bounds waiting only: the holder is never interrupted, and a
	// caller that times out fails rather than proceeding without the lock.
	//
	// The value balances two things that pull in opposite directions.
	//
	// It has to exceed the longest legitimate hold, because exceeding it fails a
	// deployment that was doing nothing wrong. A link can hold a lock across a slow
	// upstream operation: waiting for a cloud provider to release network interfaces,
	// or deploying an intermediary resource that takes minutes to become available.
	// Locks are released at the end of every link deployment phase, including on the
	// failure path, so a hold spans a single attempt rather than a whole retry chain
	// with its backoff.
	//
	// It also should not be unbounded, because it is what turns a lock cycle into a
	// diagnosable error naming both links rather than a deployment that hangs with no
	// explanation. Fifteen minutes leaves generous room above the slow operations above
	// while still surfacing a genuine deadlock within a single run.
	DefaultResourceLockTimeout = 15 * 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)

	// IsAbstractResourceType checks if a resource type is an abstract resource type defined in a transformer plugin.
	IsAbstractResourceType(ctx context.Context, resourceType string) (bool, 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 releases the lock when the phase that acquired it
	// finishes, including when the link update fails. A held lock is never taken from
	// its holder, so a caller that cannot acquire one within the lock timeout fails
	// with an error naming the holder rather than proceeding without it.
	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 how a link's locks are released when its phase ends, and the only way
	// they are released: nothing expires a lock on age. A lock recorded under a
	// different acquirer than the one passed here is therefore never released by it.
	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

	// ListTransformers returns a list of all transformer names available in the registry.
	ListTransformers(ctx context.Context) ([]string, error)
}

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 how long a caller waits for a resource lock before giving up with an error naming the holder. The holder is never interrupted, so this must be longer than the slowest operation a link performs while holding a lock. If not provided, the default is 15 minutes.

Jump to

Keyboard shortcuts

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