shared

package
v1.40.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModeManaged is mode value for managed resources.
	ModeManaged = "managed"
	// AttributeKeyId is the key for the id attribute
	AttributeKeyId = "id"
	// AttributeKeyName is the key for the name attribute
	AttributeKeyName = "name"
)
View Source
const (
	// Separator is used to on translating keys to/from flat maps
	Separator = "/"
)

Variables

This section is empty.

Functions

func AttributeAsString

func AttributeAsString(attributes map[string]interface{}, key string) (svalue string, found bool)

AttributeAsString returns the string value for the given key. `found` is only true if the map contains the key and the value is a string.

func FromContext added in v1.35.0

func FromContext(ctx context.Context) *waiter

FromContext retrieves a waiter from the current context or returns nil if it is not found.

func InformOnWaiting added in v1.30.0

func InformOnWaiting(log logr.Logger, period time.Duration, message string, keysAndValues ...any) *waiter

InformOnWaiting does

func IsValidValue added in v1.30.0

func IsValidValue(value string) bool

IsValidValue returns true if an exported value is valid, i.e. not empty and not special value for deleted.

func LogFromContext added in v1.35.0

func LogFromContext(ctx context.Context) logr.Logger

LogFromContext returns the log from the context when called within a task function added with the `AddTask` method. If no logger is present, a new noop-logger will be returned.

Types

type BasicFlowContext added in v1.30.0

type BasicFlowContext struct {
	PersistInterval time.Duration
	// contains filtered or unexported fields
}

BasicFlowContext provides logic for persisting the state and add tasks to the flow graph.

func NewBasicFlowContext added in v1.30.0

func NewBasicFlowContext() *BasicFlowContext

NewBasicFlowContext creates a new `BasicFlowContext`.

func (*BasicFlowContext) AddTask added in v1.30.0

func (c *BasicFlowContext) AddTask(g *flow.Graph, name string, fn flow.TaskFn, options ...TaskOption) flow.TaskIDer

AddTask adds a wrapped task for the given task function and options.

func (*BasicFlowContext) PersistState added in v1.30.0

func (c *BasicFlowContext) PersistState(ctx context.Context) error

PersistState persists the internal state to the provider status.

func (*BasicFlowContext) WithLogger added in v1.35.0

func (c *BasicFlowContext) WithLogger(log logr.Logger) *BasicFlowContext

WithLogger is the logger that gets injected into the context for each node.

func (*BasicFlowContext) WithPersist added in v1.35.0

func (c *BasicFlowContext) WithPersist(task flow.TaskFn) *BasicFlowContext

WithPersist is Task that will be called after each successful node directly after the node execution. It's used to store information in the state.

func (*BasicFlowContext) WithSpan added in v1.35.0

func (c *BasicFlowContext) WithSpan() *BasicFlowContext

WithSpan when enabled will log the total execution time for the task on Info level.

type FlatMap added in v1.30.0

type FlatMap map[string]string

FlatMap is a semantic name for string map used for importing and exporting

type TFInstance

type TFInstance struct {
	SchemaVersion       int                    `json:"schema_version"`
	Attributes          map[string]interface{} `json:"attributes,omitempty"`
	SensitiveAttributes []string               `json:"sensitive_attributes,omitempty"`
	Private             string                 `json:"private,omitempty"`
	Dependencies        []string               `json:"dependencies"`
}

TFInstance holds the attributes of a terraformer state resource instance.

type TFOutput

type TFOutput struct {
	Value string `json:"value"`
	Type  string `json:"type"`
}

TFOutput holds the value and type for a terraformer state output variable.

type TFResource

type TFResource struct {
	Mode      string `json:"mode"`
	Type      string `json:"type"`
	Name      string `json:"name"`
	Provider  string `json:"provider"`
	Instances []TFInstance
}

TFResource holds the attributes of a terraformer state resource.

type TaskOption added in v1.30.0

type TaskOption struct {
	Dependencies []flow.TaskIDer
	Timeout      time.Duration
	DoIf         *bool
}

TaskOption contains options for created flow tasks

func Dependencies added in v1.30.0

func Dependencies(dependencies ...flow.TaskIDer) TaskOption

Dependencies creates a TaskOption for dependencies

func DoIf added in v1.30.0

func DoIf(condition bool) TaskOption

DoIf creates a TaskOption for DoIf

func Timeout added in v1.30.0

func Timeout(timeout time.Duration) TaskOption

Timeout creates a TaskOption for Timeout

type TerraformState

type TerraformState struct {
	Version          int                 `json:"version"`
	TerraformVersion string              `json:"terraform_version"`
	Serial           int                 `json:"serial"`
	Lineage          string              `json:"lineage"`
	Outputs          map[string]TFOutput `json:"outputs,omitempty"`
	Resources        []TFResource        `json:"resources,omitempty"`
}

TerraformState holds the unmarshalled terraformer state.

func LoadTerraformStateFromConfigMapData

func LoadTerraformStateFromConfigMapData(data map[string]string) (*TerraformState, error)

LoadTerraformStateFromConfigMapData loads and unmarshalls the state from a config map data.

func UnmarshalTerraformState

func UnmarshalTerraformState(data []byte) (*TerraformState, error)

UnmarshalTerraformState unmarshalls the terraformer state from a byte array.

func UnmarshalTerraformStateFromTerraformer

func UnmarshalTerraformStateFromTerraformer(state *terraformer.RawState) (*TerraformState, error)

UnmarshalTerraformStateFromTerraformer unmarshalls the Terraformer state from the raw state.

func (*TerraformState) FindManagedResourceInstances

func (ts *TerraformState) FindManagedResourceInstances(tfType, resourceName string) []TFInstance

FindManagedResourceInstances finds all instances for a resource identified by type and name.

func (*TerraformState) FindManagedResourcesByType

func (ts *TerraformState) FindManagedResourcesByType(tfType string) []*TFResource

FindManagedResourcesByType finds all instances for all resources of the given type.

func (*TerraformState) GetManagedResourceInstanceAttribute

func (ts *TerraformState) GetManagedResourceInstanceAttribute(tfType, resourceName, attributeKey string) *string

GetManagedResourceInstanceAttribute returns the value of the given attribute keys of the only instance of a resource identified by type and name. It returns nil if either the resource is not found or the resource has not exactly one instance or the attribute key is not existing.

func (*TerraformState) GetManagedResourceInstanceID

func (ts *TerraformState) GetManagedResourceInstanceID(tfType, resourceName string) *string

GetManagedResourceInstanceID returns the value of the id attribute of the only instance of a resource identified by type and name. It returns nil if either the resource is not found or the resource has not exactly one instance.

func (*TerraformState) GetManagedResourceInstanceName

func (ts *TerraformState) GetManagedResourceInstanceName(tfType, resourceName string) *string

GetManagedResourceInstanceName returns the value of the name attribute of the only instance of a resource identified by type and name. It returns nil if either the resource is not found or the resource has not exactly one instance.

func (*TerraformState) GetManagedResourceInstances

func (ts *TerraformState) GetManagedResourceInstances(tfType string) map[string]string

GetManagedResourceInstances returns a map resource name to instance id for all resources of the given type. Only resources are included which have exactly one instance.

type Timestamper added in v1.35.0

type Timestamper interface {
	Now() time.Time
}

Timestamper is an interface around time package.

var DefaultTimer Timestamper = TimestamperFn(time.Now)

DefaultTimer is the default implementation for Timestamper used in the package.

type TimestamperFn added in v1.35.0

type TimestamperFn func() time.Time

TimestamperFn is an implementation of the Timestamper interface using a function.

func (TimestamperFn) Now added in v1.35.0

func (t TimestamperFn) Now() time.Time

Now returns the value of time.Now().

type Whiteboard added in v1.30.0

type Whiteboard interface {
	IsEmpty() bool

	// GetChild returns a sub-whiteboard for the given key. If no child exists with this name, it is created automatically.
	// Each child has its own lock.
	GetChild(key string) Whiteboard
	// HasChild returns true if there is a non-empty child for that key
	HasChild(key string) bool
	// GetChildrenKeys returns all children keys
	GetChildrenKeys() []string

	// Get returns a valid value or nil (never "" or special deleted value)
	Get(key string) *string
	Set(key, id string)
	Delete(key string)
	SetPtr(key string, id *string)
	IsAlreadyDeleted(key string) bool
	SetAsDeleted(key string)
	// Keys returns all stored keys, even for deleted ones
	Keys() []string
	// AsMap returns a map with all valid key/values
	AsMap() map[string]string

	GetObject(key string) any
	SetObject(key string, obj any)
	DeleteObject(key string)
	HasObject(key string) bool
	ObjectKeys() []string

	// ImportFromFlatMap reconstructs the hierarchical structure from a flat map containing path-like keys
	ImportFromFlatMap(data FlatMap)
	// ExportAsFlatMap exports the hierarchical structure to a flat map with path-like keys. Objects are ignored.
	ExportAsFlatMap() FlatMap

	// CurrentGeneration returns current generation, which increments with any change
	CurrentGeneration() int64
}

Whiteboard is a hierarchical key/value store for the internal state. It is safe to be used concurrently. Additionally, it can cache objects for use in subsequent flow task.

func NewWhiteboard added in v1.30.0

func NewWhiteboard() Whiteboard

NewWhiteboard creates an empty whiteboard.

Jump to

Keyboard shortcuts

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