changes

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// ErrorReasonCodeMaxReverseDepthExceeded is provided when the reason for an error
	// during reverse changeset generation is due to the maximum recursion depth being exceeded.
	// This protects against infinite recursion from cyclic child blueprint references.
	ErrorReasonCodeMaxReverseDepthExceeded errors.ErrorReasonCode = "max_reverse_depth_exceeded"

	// MaxReverseChangesetDepth is the maximum depth allowed for recursion when reversing
	// a changeset. This matches the MaxBlueprintDepth used elsewhere in the blueprint library
	// to protect against cycles in nested blueprint structures.
	MaxReverseChangesetDepth = 5
)
View Source
const MaxRemovalChangesDepth = 10

MaxRemovalChangesDepth is the maximum depth for recursive child blueprint processing.

Variables

This section is empty.

Functions

func AnyEmptyString

func AnyEmptyString(values ...string) bool

AnyEmptyString returns true if any of the given strings are empty or contain only whitespace.

func CollectMetadataChanges

func CollectMetadataChanges(
	collectIn *MetadataChanges,
	resolveResult *subengine.ResolveInMappingNodeResult,
	currentMetadata map[string]*core.MappingNode,
)

func GetArraySchema

GetArraySchema returns the first array schema in a list of schemas.

func GetResourceTypeFromResolved

func GetResourceTypeFromResolved(resourceWithResolvedSubs *provider.ResolvedResource) string

GetResourceTypeFromResolved extracts a resource type from a resolved resource if possible. An empty string is returned if the resolved resource is nil or the type is nil.

func IsResourceSafeToDestroy added in v0.37.0

func IsResourceSafeToDestroy(resource *state.ResourceState) bool

IsResourceSafeToDestroy checks if a resource is in a safe state to be destroyed during rollback. A resource is safe to destroy if it was successfully created (Created status) or at least reached config-complete state.

Types

type BlueprintChanges

type BlueprintChanges struct {
	// NewResources contains the resources that will be created
	// when deploying the changes.
	NewResources map[string]provider.Changes `json:"newResources"`
	// ResourceChanges contains the changes that will be made to
	// existing resources when deploying the changes.
	ResourceChanges map[string]provider.Changes `json:"resourceChanges"`
	// RemovedResources contains the name of the resources that will be removed
	// when deploying the changes.
	RemovedResources []string `json:"removedResources"`
	// RemovedLinks contains the name of the links that will be removed
	// when deploying the changes.
	// These will be in the format "resourceAName::resourceBName".
	RemovedLinks []string `json:"removedLinks"`
	// NewChildren contains the child blueprints that will be created
	// when deploying the changes.
	NewChildren map[string]NewBlueprintDefinition `json:"newChildren"`
	// ChildChanges contains the changes that will be made to the child blueprints
	// when deploying the changes.
	ChildChanges map[string]BlueprintChanges `json:"childChanges"`
	// RecreateChildren contains the name of the child blueprints that will be recreated
	// when deploying the changes.
	// The reason for this will primarily be due to a dependency of a child blueprint
	// being removed from the latest version of the host blueprint.
	RecreateChildren []string `json:"recreateChildren"`
	// RemovedChildren contains the name of the child blueprints that will be removed
	// when deploying the changes.
	RemovedChildren []string `json:"removedChildren"`
	// NewExports contains new fields that will be exported from the blueprint.
	NewExports map[string]provider.FieldChange `json:"newExports"`
	// ExportChanges contains changes to exported fields.
	ExportChanges map[string]provider.FieldChange `json:"exportChanges"`
	// UnchangedExports contains the names of fields that will not be changed.
	UnchangedExports []string `json:"unchangedExports"`
	// RemovedExports contains the names of fields that will no longer be exported.
	RemovedExports []string `json:"removedExports"`
	// MetadataChanges contains changes to blueprint-wide metadata.
	MetadataChanges MetadataChanges `json:"metadataChanges"`
	// ResolveOnDeploy contains paths to properties in blueprint elements
	// that contain substitutions that can not be resolved until the blueprint
	// is deployed.
	// This includes properties in resources, data sources, blueprint-wide metadata
	// and exported fields.
	ResolveOnDeploy []string `json:"resolveOnDeploy"`
}

BlueprintChanges provides a set of changes that will be made to a blueprint instance when deploying a new version of the source blueprint. This contains a mapping of resource name to the changes that will come into effect upon deploying the currently loaded version of a blueprint for a given instance ID. This also contains a mapping of child blueprint names to the changes that will come into effect upon deploying the child blueprint. Changes takes the type parameter interface{} as we can't know the exact range of resource types for a blueprint at compile time. We must check the resource types associated with a set of changes at runtime.

func ReverseChangeset added in v0.36.4

func ReverseChangeset(
	original *BlueprintChanges,
	previousState *state.InstanceState,
) (*BlueprintChanges, error)

ReverseChangeset generates a changeset that would undo the original changes. This is used for rolling back failed updates and destroys to restore the previous state.

For update rollback: reverses field changes by swapping PrevValue/NewValue For destroy rollback: recreates removed resources from previousState

Returns nil, nil if the original changeset or previous state is nil. Returns an error if the maximum recursion depth is exceeded.

type IntermediaryBlueprintChanges

type IntermediaryBlueprintChanges struct {
	NewResources     map[string]*provider.Changes
	ResourceChanges  map[string]*provider.Changes
	RemovedResources []string
	RemovedLinks     []string
	NewChildren      map[string]*NewBlueprintDefinition
	ChildChanges     map[string]*BlueprintChanges
	RemovedChildren  []string
	NewExports       map[string]*provider.FieldChange
	ExportChanges    map[string]*provider.FieldChange
	RemovedExports   []string
	MetadataChanges  *MetadataChanges
	UnchangedExports []string
	ResolveOnDeploy  []string
}

IntermediaryBlueprintChanges holds changes to a blueprint that are not yet finalised but are stored in temporary state for the duration of the change staging process. This differs from blueprint changes in that it holds pointers to change items that makes it more efficient to update the changes as the staging process progresses.

type MappingNodeTypeMatchInfo

type MappingNodeTypeMatchInfo struct {
	TypeMatches bool
	Schema      *provider.ResourceDefinitionsSchema
}

MappingNodeTypeMatchInfo contains information about whether the types of two mapping nodes match and the schema to be used for value comparisons.

func CheckMappingNodeTypesForFields

func CheckMappingNodeTypesForFields(
	fieldsA, fieldsB map[string]*bpcore.MappingNode,
	unionSchema *provider.ResourceDefinitionsSchema,
) *MappingNodeTypeMatchInfo

CheckMappingNodeTypesForFields compares the fields in two mapping nodes to determine whether the types of the fields match the types in the union schema.

type MetadataChanges

type MetadataChanges struct {
	// NewFields contains new fields that will be added to the blueprint-wide metadata.
	NewFields []provider.FieldChange `json:"newFields"`
	// ModifiedFields contains changes to existing fields in the blueprint-wide metadata.
	ModifiedFields []provider.FieldChange `json:"modifiedFields"`
	// UnchangedFields contains the names of fields that will not be changed.
	UnchangedFields []string `json:"unchangedFields"`
	// RemovedFields contains the names of fields that will no longer be present.
	RemovedFields []string `json:"removedFields"`
}

MetadataChanges holds information about changes to blueprint-wide metadata.

type NewBlueprintDefinition

type NewBlueprintDefinition struct {
	NewResources    map[string]provider.Changes       `json:"newResources"`
	NewChildren     map[string]NewBlueprintDefinition `json:"newChildren"`
	NewExports      map[string]provider.FieldChange   `json:"newExports"`
	ResolveOnDeploy []string                          `json:"resolveOnDeploy,omitempty"`
}

NewBlueprintDefinition provides a definition for a new child blueprint that will be created when deploying a blueprint instance.

type RemovalChangesResult added in v0.37.0

type RemovalChangesResult struct {
	// Changes contains the removal changes for resources, links, children, and exports
	// that are safe to destroy.
	Changes *BlueprintChanges
	// SkippedItems lists resources and links that were not in a safe state
	// to destroy and were therefore excluded from the removal changes.
	SkippedItems []SkippedRollbackItem
	// HasSkippedItems is true if any items were skipped.
	HasSkippedItems bool
}

RemovalChangesResult contains the removal changes and any items that were skipped because they were not in a safe state to be destroyed during rollback.

func CreateRemovalChangesFromInstanceState added in v0.37.0

func CreateRemovalChangesFromInstanceState(
	instanceState *state.InstanceState,
) *RemovalChangesResult

CreateRemovalChangesFromInstanceState creates removal changes from the current instance state. This is used for auto-rollback of new deployments where we need to destroy resources that were being created but the deployment failed.

Only resources and links in a safe state (Created, ConfigComplete) are included in the removal changes. Items in failed or in-progress states are skipped because they cannot be reliably destroyed.

Returns the removal changes and any items that were skipped due to unsafe state.

type ResourceChangeGenerator

type ResourceChangeGenerator interface {
	GenerateChanges(
		ctx context.Context,
		resourceInfo *provider.ResourceInfo,
		resourceImplementation provider.Resource,
		resolveOnDeploy []string,
		params bpcore.BlueprintParams,
	) (*provider.Changes, error)
}

ResourceChangeGenerator is an interface for a service that handles generating changes for a resource based on the current state of the resource, the resolved replacement resource spec and the spec definition provided by the resource plugin implementation.

func NewDefaultResourceChangeGenerator

func NewDefaultResourceChangeGenerator() ResourceChangeGenerator

NewDefaultResourceChangeGenerator returns a new instance of the default implementation of a resource change generator.

type RollbackFilterResult added in v0.37.0

type RollbackFilterResult struct {
	// FilteredChanges contains only the changes that are safe to rollback.
	FilteredChanges *BlueprintChanges
	// SkippedItems lists resources and links that were not in a safe state
	// to rollback and were therefore excluded from the changeset.
	SkippedItems []SkippedRollbackItem
	// HasSkippedItems is true if any items were skipped.
	HasSkippedItems bool
}

RollbackFilterResult contains the filtered changeset and information about any items that were skipped because they were not in a safe state to rollback.

func FilterReverseChangesetByCurrentState added in v0.37.0

func FilterReverseChangesetByCurrentState(
	reverseChanges *BlueprintChanges,
	currentState *state.InstanceState,
) *RollbackFilterResult

FilterReverseChangesetByCurrentState filters a reverse changeset to only include resources and links that are in a safe state to rollback based on the current instance state.

Resources and links are considered safe to rollback when they have completed their operation successfully (Created, Updated, Destroyed, or ConfigComplete states). Items in failed, in-progress, or interrupted states are skipped because attempting to rollback an incomplete operation could lead to unpredictable behavior.

The function returns both the filtered changeset and a list of skipped items so that the rollback operation can report partial rollback status to the user.

type SkippedRollbackItem added in v0.37.0

type SkippedRollbackItem struct {
	// Name is the resource or link name.
	Name string
	// Type indicates whether this is a "resource" or "link".
	Type string
	// ChildPath is the path to the child blueprint containing this item,
	// empty string for root-level items.
	ChildPath string
	// Status is the current status that prevented rollback.
	Status string
	// Reason explains why the item was skipped.
	Reason string
}

SkippedRollbackItem represents a resource or link that was skipped during rollback because it was not in a safe state to roll back.

Jump to

Keyboard shortcuts

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