engine

package
v3.114.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 44 Imported by: 8

Documentation

Overview

Package engine contains the core logic for the Pulumi engine, which includes the following:

- Handle resource management and query operations by configuring and spawning goroutines to run the specified operations asynchronously. - Define events and their associated handlers. - Manage journal entries for resource operations. - Manage plugins, including installation, version handling, and loading.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertLocalPolicyPacksToPaths

func ConvertLocalPolicyPacksToPaths(localPolicyPack []LocalPolicyPack) []string

ConvertLocalPolicyPacksToPaths is a helper function for converting the list of LocalPolicyPacks to a list of paths.

func Destroy

func Destroy(
	u UpdateInfo,
	ctx *Context,
	opts UpdateOptions,
	dryRun bool,
) (*deploy.Plan, display.ResourceChanges, error)

func GetLocalPolicyPackInfoFromEventName added in v3.88.0

func GetLocalPolicyPackInfoFromEventName(name string) (string, string)

GetLocalPolicyPackInfoFromEventName round trips the NameForEvents back into a name/path pair.

func HasChanges added in v3.35.2

func HasChanges(changes display.ResourceChanges) bool

HasChanges returns true if there are any non-same changes in the resulting summary.

func Import

func Import(u UpdateInfo, ctx *Context, opts UpdateOptions, imports []deploy.Import,
	dryRun bool,
) (*deploy.Plan, display.ResourceChanges, error)

func ProjectInfoContext

func ProjectInfoContext(projinfo *Projinfo, host plugin.Host,
	diag, statusDiag diag.Sink, disableProviderPreview bool,
	tracingSpan opentracing.Span, config map[config.Key]string,
) (string, string, *plugin.Context, error)

ProjectInfoContext returns information about the current project, including its pwd, main, and plugin context.

func Query

func Query(ctx *Context, q QueryInfo, opts UpdateOptions) error

func Refresh

func Refresh(
	u UpdateInfo,
	ctx *Context,
	opts UpdateOptions,
	dryRun bool,
) (*deploy.Plan, display.ResourceChanges, error)

func RunInstallPlugins

func RunInstallPlugins(
	proj *workspace.Project, pwd, main string, target *deploy.Target, plugctx *plugin.Context,
) error

RunInstallPlugins calls installPlugins and just returns the error (avoids having to export pluginSet).

func ShouldRecordReadStep

func ShouldRecordReadStep(step deploy.Step) bool

func TranslateDetailedDiff added in v3.29.0

func TranslateDetailedDiff(step *StepEventMetadata) *resource.ObjectDiff

TranslateDetailedDiff converts the detailed diff stored in the step event into an ObjectDiff that is appropriate for display.

func Update

func Update(u UpdateInfo, ctx *Context, opts UpdateOptions, dryRun bool) (
	*deploy.Plan, display.ResourceChanges, error,
)

Types

type CombinedManager added in v3.113.0

type CombinedManager struct {
	Managers []SnapshotManager
}

CombinedManager combines multiple SnapshotManagers into one, it simply forwards on each call to every manager.

func (*CombinedManager) BeginMutation added in v3.113.0

func (c *CombinedManager) BeginMutation(step deploy.Step) (SnapshotMutation, error)

func (*CombinedManager) Close added in v3.113.0

func (c *CombinedManager) Close() error

func (*CombinedManager) RegisterResourceOutputs added in v3.113.0

func (c *CombinedManager) RegisterResourceOutputs(step deploy.Step) error

type CombinedMutation added in v3.113.0

type CombinedMutation struct {
	Mutations []SnapshotMutation
}

func (*CombinedMutation) End added in v3.113.0

func (c *CombinedMutation) End(step deploy.Step, success bool) error

type Context

type Context struct {
	Cancel          *cancel.Context
	Events          chan<- Event
	SnapshotManager SnapshotManager
	BackendClient   deploy.BackendClient
	ParentSpan      opentracing.SpanContext
}

Context provides cancellation, termination, and eventing options for an engine operation. It also provides a way for the engine to persist snapshots, using the `SnapshotManager`.

type DecryptError

type DecryptError struct {
	Key config.Key // The configuration key whose value couldn't be decrypted
	Err error      // The error that occurred while decrypting
}

DecryptError is the type of errors that arise when the engine can't decrypt a configuration key. The most common reason why this happens is that this key is being decrypted in a stack that's not the same one that encrypted it.

func (DecryptError) Error

func (d DecryptError) Error() string

type DiagEventPayload

type DiagEventPayload struct {
	URN       resource.URN
	Prefix    string
	Message   string
	Color     colors.Colorization
	Severity  diag.Severity
	StreamID  int32
	Ephemeral bool
}

DiagEventPayload is the payload for an event with type `diag`

type Event

type Event struct {
	Type EventType
	// contains filtered or unexported fields
}

Event represents an event generated by the engine during an operation. The underlying type for the `Payload` field will differ depending on the value of the `Type` field

func NewCancelEvent added in v3.94.2

func NewCancelEvent() Event

func NewEvent

func NewEvent[T EventPayload](payload T) Event

func (Event) Internal added in v3.95.0

func (e Event) Internal() bool

Returns true if this is a ResourcePreEvent or ResourceOutputsEvent with the internal flag set.

func (Event) Payload

func (e Event) Payload() interface{}

type EventType

type EventType string

EventType is the kind of event being emitted.

const (
	CancelEvent             EventType = "cancel"
	StdoutColorEvent        EventType = "stdoutcolor"
	DiagEvent               EventType = "diag"
	PreludeEvent            EventType = "prelude"
	SummaryEvent            EventType = "summary"
	ResourcePreEvent        EventType = "resource-pre"
	ResourceOutputsEvent    EventType = "resource-outputs"
	ResourceOperationFailed EventType = "resource-operationfailed"
	PolicyViolationEvent    EventType = "policy-violation"
	PolicyRemediationEvent  EventType = "policy-remediation"
	PolicyLoadEvent         EventType = "policy-load"
)

type Journal

type Journal struct {
	// contains filtered or unexported fields
}

func NewJournal

func NewJournal() *Journal

func (*Journal) BeginMutation

func (j *Journal) BeginMutation(step deploy.Step) (SnapshotMutation, error)

func (*Journal) Close

func (j *Journal) Close() error

func (*Journal) End

func (j *Journal) End(step deploy.Step, success bool) error

func (*Journal) Entries

func (j *Journal) Entries() JournalEntries

func (*Journal) RecordPlugin

func (j *Journal) RecordPlugin(plugin workspace.PluginInfo) error

func (*Journal) RegisterResourceOutputs

func (j *Journal) RegisterResourceOutputs(step deploy.Step) error

func (*Journal) Snap

func (j *Journal) Snap(base *deploy.Snapshot) (*deploy.Snapshot, error)

type JournalEntries

type JournalEntries []JournalEntry

func (JournalEntries) Snap

func (entries JournalEntries) Snap(base *deploy.Snapshot) (*deploy.Snapshot, error)

type JournalEntry

type JournalEntry struct {
	Kind JournalEntryKind
	Step deploy.Step
}

type JournalEntryKind

type JournalEntryKind int
const (
	JournalEntryBegin   JournalEntryKind = 0
	JournalEntrySuccess JournalEntryKind = 1
	JournalEntryFailure JournalEntryKind = 2
	JournalEntryOutputs JournalEntryKind = 4
)

type LocalPolicyPack

type LocalPolicyPack struct {
	// Name provides the user-specified name of the Policy Pack.
	Name string
	// Version of the local Policy Pack.
	Version string
	// Path of the local Policy Pack.
	Path string
	// Path of the local Policy Pack's JSON config file.
	Config string
}

LocalPolicyPack represents a set of local Policy Packs to apply during an update.

func MakeLocalPolicyPacks

func MakeLocalPolicyPacks(localPaths []string, configPaths []string) []LocalPolicyPack

MakeLocalPolicyPacks is a helper function for converting the list of local Policy Pack paths to list of LocalPolicyPack. The name of the Local Policy Pack is not set since we must load up the Policy Pack plugin to determine its name.

func (LocalPolicyPack) NameForEvents added in v3.88.0

func (pack LocalPolicyPack) NameForEvents() string

NameForEvents encodes a local policy pack's information in a single string which can be used for engine events. It is done this way so we don't lose path information.

type PolicyLoadEventPayload added in v3.94.1

type PolicyLoadEventPayload struct{}

PolicyLoadEventPayload is the payload for an event with type `policy-load`.

type PolicyPackInfo

type PolicyPackInfo struct {
	Proj *workspace.PolicyPackProject
	Root string
}

func (*PolicyPackInfo) GetPwdMain

func (projinfo *PolicyPackInfo) GetPwdMain() (string, string, error)

GetPwdMain returns the working directory and main entrypoint to use for this package.

type PolicyRemediationEventPayload added in v3.88.0

type PolicyRemediationEventPayload struct {
	ResourceURN       resource.URN
	Color             colors.Colorization
	PolicyName        string
	PolicyPackName    string
	PolicyPackVersion string
	Before            resource.PropertyMap
	After             resource.PropertyMap
}

PolicyRemediationEventPayload is the payload for an event with type `policy-remediation`.

type PolicyViolationEventPayload

type PolicyViolationEventPayload struct {
	ResourceURN       resource.URN
	Message           string
	Color             colors.Colorization
	PolicyName        string
	PolicyPackName    string
	PolicyPackVersion string
	EnforcementLevel  apitype.EnforcementLevel
	Prefix            string
}

PolicyViolationEventPayload is the payload for an event with type `policy-violation`.

type PreludeEventPayload

type PreludeEventPayload struct {
	IsPreview bool              // true if this prelude is for a plan operation
	Config    map[string]string // the keys and values for config. For encrypted config, the values may be blinded
}

type Projinfo

type Projinfo struct {
	Proj *workspace.Project
	Root string
}

func (*Projinfo) GetPwdMain

func (projinfo *Projinfo) GetPwdMain() (string, string, error)

GetPwdMain returns the working directory and main entrypoint to use for this package.

type QueryInfo

type QueryInfo interface {
	// GetRoot returns the root directory for this update. This defines the scope for any filesystem resources
	// accessed by this update.
	GetRoot() string
	// GetProject returns information about the project associated with this update. This includes information such as
	// the runtime that will be used to execute the Pulumi program and the program's relative working directory.
	GetProject() *workspace.Project
}

QueryInfo handles information common to query operations (list, watch).

type QueryOptions

type QueryOptions struct {
	Events     eventEmitter // the channel to write events from the engine to.
	Diag       diag.Sink    // the sink to use for diag'ing.
	StatusDiag diag.Sink    // the sink to use for diag'ing status messages.
	// contains filtered or unexported fields
}

type RequiredPolicy

type RequiredPolicy interface {
	// Name provides the user-specified name of the PolicyPack.
	Name() string
	// Version of the PolicyPack.
	Version() string
	// Install will install the PolicyPack locally, returning the path it was installed to.
	Install(ctx context.Context) (string, error)
	// Config returns the PolicyPack's configuration.
	Config() map[string]*json.RawMessage
}

RequiredPolicy represents a set of policies to apply during an update.

type ResourceOperationFailedPayload

type ResourceOperationFailedPayload struct {
	Metadata StepEventMetadata
	Status   resource.Status
	Steps    int
}

type ResourceOutputsEventPayload

type ResourceOutputsEventPayload struct {
	Metadata StepEventMetadata
	Planning bool
	Debug    bool
	// Internal is set for events that should not be shown to a user but are expected to be used in other parts of the
	// Pulumi system.
	Internal bool
}

type ResourcePreEventPayload

type ResourcePreEventPayload struct {
	Metadata StepEventMetadata
	Planning bool
	Debug    bool
	// Internal is set for events that should not be shown to a user but are expected to be used in other parts of the
	// Pulumi system.
	Internal bool
}

type SnapshotManager

type SnapshotManager interface {
	io.Closer

	// BeginMutation signals to the SnapshotManager that the planner intends to mutate the global
	// snapshot. It provides the step that it intends to execute. Based on that step, BeginMutation
	// will record this intent in the global snapshot and return a `SnapshotMutation` that, when ended,
	// will complete the transaction.
	BeginMutation(step deploy.Step) (SnapshotMutation, error)

	// RegisterResourceOutputs registers the set of resource outputs generated by performing the
	// given step. These outputs are persisted in the snapshot.
	RegisterResourceOutputs(step deploy.Step) error
}

SnapshotManager manages an in-memory resource graph.

type SnapshotMutation

type SnapshotMutation interface {
	// End terminates the transaction and commits the results to the snapshot, returning an error if this
	// failed to complete.
	End(step deploy.Step, successful bool) error
}

SnapshotMutation represents an outstanding mutation that is yet to be completed. When the engine completes a mutation, it must call `End` in order to record the successful completion of the mutation.

type StdoutEventPayload

type StdoutEventPayload struct {
	Message string
	Color   colors.Colorization
}

type StepEventMetadata

type StepEventMetadata struct {
	Op           display.StepOp                 // the operation performed by this step.
	URN          resource.URN                   // the resource URN (for before and after).
	Type         tokens.Type                    // the type affected by this step.
	Old          *StepEventStateMetadata        // the state of the resource before performing this step.
	New          *StepEventStateMetadata        // the state of the resource after performing this step.
	Res          *StepEventStateMetadata        // the latest state for the resource that is known (worst case, old).
	Keys         []resource.PropertyKey         // the keys causing replacement (only for CreateStep and ReplaceStep).
	Diffs        []resource.PropertyKey         // the keys causing diffs
	DetailedDiff map[string]plugin.PropertyDiff // the rich, structured diff
	Logical      bool                           // true if this step represents a logical operation in the program.
	Provider     string                         // the provider that performed this step.
}

StepEventMetadata contains the metadata associated with a step the engine is performing.

type StepEventStateMetadata

type StepEventStateMetadata struct {
	// State contains the raw, complete state, for this resource.
	State *resource.State
	// the resource's type.
	Type tokens.Type
	// the resource's object urn, a human-friendly, unique name for the resource.
	URN resource.URN
	// true if the resource is custom, managed by a plugin.
	Custom bool
	// true if this resource is pending deletion due to a replacement.
	Delete bool
	// the resource's unique ID, assigned by the resource provider (or blank if none/uncreated).
	ID resource.ID
	// an optional parent URN that this resource belongs to.
	Parent resource.URN
	// true to "protect" this resource (protected resources cannot be deleted).
	Protect bool
	// RetainOnDelete is true if the resource is not physically deleted when it is logically deleted.
	RetainOnDelete bool `json:"retainOnDelete"`
	// the resource's input properties (as specified by the program). Note: because this will cross
	// over rpc boundaries it will be slightly different than the Inputs found in resource_state.
	// Specifically, secrets will have been filtered out, and large values (like assets) will be
	// have a simple hash-based representation.  This allows clients to display this information
	// properly, without worrying about leaking sensitive data, and without having to transmit huge
	// amounts of data.
	Inputs resource.PropertyMap
	// the resource's complete output state (as returned by the resource provider).  See "Inputs"
	// for additional details about how data will be transformed before going into this map.
	Outputs resource.PropertyMap
	// the resource's provider reference
	Provider string
	// InitErrors is the set of errors encountered in the process of initializing resource (i.e.,
	// during create or update).
	InitErrors []string
}

StepEventStateMetadata contains detailed metadata about a resource's state pertaining to a given step.

type SummaryEventPayload

type SummaryEventPayload struct {
	IsPreview       bool                    // true if this summary is for a plan operation
	MaybeCorrupt    bool                    // true if one or more resources may be corrupt
	Duration        time.Duration           // the duration of the entire update operation (zero values for previews)
	ResourceChanges display.ResourceChanges // count of changed resources, useful for reporting
	PolicyPacks     map[string]string       // {policy-pack: version} for each policy pack applied
}

type UpdateInfo

type UpdateInfo interface {
	// GetRoot returns the root directory for this update. This defines the scope for any filesystem resources
	// accessed by this update.
	GetRoot() string
	// GetProject returns information about the project associated with this update. This includes information such as
	// the runtime that will be used to execute the Pulumi program and the program's relative working directory.
	GetProject() *workspace.Project
	// GetTarget returns information about the target of this update. This includes the name of the stack being
	// updated, the configuration values associated with the target and the target's latest snapshot.
	GetTarget() *deploy.Target
}

UpdateInfo handles information common to resource operations (update, preview, destroy, import, refresh).

type UpdateOptions

type UpdateOptions struct {
	// LocalPolicyPacks contains an optional set of policy packs to run as part of this deployment.
	LocalPolicyPacks []LocalPolicyPack

	// RequiredPolicies is the set of policies that are required to run as part of the update.
	RequiredPolicies []RequiredPolicy

	// the degree of parallelism for resource operations (<=1 for serial).
	Parallel int

	// true if debugging output it enabled
	Debug bool

	// true if the plan should refresh before executing.
	Refresh bool

	// Specific resources to replace during an update operation.
	ReplaceTargets deploy.UrnTargets

	// Specific resources to update during a deployment.
	Targets deploy.UrnTargets

	// true if we're allowing dependent targets to change, even if not specified in one of the above
	// XXXTargets lists.
	TargetDependents bool

	// true if the engine should use legacy diffing behavior during an update.
	UseLegacyDiff bool

	// true if the engine should disable provider previews.
	DisableProviderPreview bool

	// true if the engine should disable resource reference support.
	DisableResourceReferences bool

	// true if the engine should disable output value support.
	DisableOutputValues bool

	// the plugin host to use for this update
	Host plugin.Host

	// The plan to use for the update, if any.
	Plan *deploy.Plan

	// GeneratePlan when true cause plans to be generated, we skip this if we know their not needed (e.g. during up)
	GeneratePlan bool

	// Experimental is true if the engine is in experimental mode (i.e. PULUMI_EXPERIMENTAL was set)
	Experimental bool

	// ContinueOnError is true if the engine should continue processing resources after an error is encountered.
	ContinueOnError bool
}

UpdateOptions contains all the settings for customizing how an update (deploy, preview, or destroy) is performed.

This structure is embedded in another which uses some of the unexported fields, which trips up the `structcheck` linter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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