project

package
v0.11.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultRelativeStateDirectory = ".score-compose"
	StateFileName                 = "state.yaml"
	MountsDirectoryName           = "mounts"
)

Variables

This section is empty.

Functions

func BuildSubstitutionFunction

func BuildSubstitutionFunction(metadata map[string]interface{}, resources map[string]OutputLookupFunc) func(string) (string, error)

func SplitRefParts

func SplitRefParts(ref string) []string

func Substitute

func Substitute(source interface{}, inner func(string) (string, error)) (interface{}, error)

Substitute does the same thing as SubstituteString but recursively through a map. It returns a copy of the original map.

func SubstituteString

func SubstituteString(src string, inner func(string) (string, error)) (string, error)

SubstituteString replaces all matching '${...}' templates in a source string with whatever is returned from the inner function.

Types

type OutputLookupFunc

type OutputLookupFunc func(keys ...string) (interface{}, error)

type ResourceUid

type ResourceUid string

func NewResourceUid

func NewResourceUid(workloadName string, resName string, resType string, resClass *string, resId *string) ResourceUid

func (ResourceUid) Class

func (r ResourceUid) Class() string

func (ResourceUid) Id

func (r ResourceUid) Id() string

func (ResourceUid) Type

func (r ResourceUid) Type() string

type ScoreResourceState

type ScoreResourceState struct {
	// Type is the resource type.
	Type string `yaml:"type"`
	// Class is the resource class or 'default' if not provided.
	Class string `yaml:"class"`
	// Id is the generated id for the resource, either <workload>.<resName> or <shared>.<id>. This is tracked so that
	// we can deduplicate and work out where a resource came from.
	Id string `yaml:"id"`

	Metadata map[string]interface{} `yaml:"metadata"`
	Params   map[string]interface{} `yaml:"params"`
	// SourceWorkload holds the workload name that had the best definition for this resource. "best" is either the
	// first one or the one with params defined.
	SourceWorkload string `yaml:"source_workload"`

	// ProvisionerUri is the resolved provisioner uri that should be found in the config. This is tracked so that
	// we identify which provisioner was used for a particular instance of the resource.
	ProvisionerUri string `yaml:"provisioner"`
	// State is the internal state local to this resource. It will be persisted to disk when possible.
	State map[string]interface{} `yaml:"state"`

	// Outputs is the current set of outputs for the resource. This is the output of calling the provider. It doesn't
	// get persisted to disk.
	Outputs map[string]interface{} `yaml:"-"`
	// OutputLookupFunc is function that allows certain in-process providers to defer any output generation. If this is
	// not provided, it will fallback to using what's in the outputs.
	OutputLookupFunc OutputLookupFunc `yaml:"-"`
}

func (*ScoreResourceState) OutputLookup

func (s *ScoreResourceState) OutputLookup(keys ...string) (interface{}, error)

OutputLookup is a function which can traverse an outputs tree to find a resulting key, this defers to the embedded output function if it exists.

type ScoreWorkloadState

type ScoreWorkloadState struct {
	// Spec is the final score spec after all overrides and images have been set. This is a validated score file.
	Spec score.Workload `yaml:"spec"`
	// File is the source score file if known.
	File *string `yaml:"file,omitempty"`
	// BuildConfigs is a stored set of container build configs for this workload. Any known container should inherit
	// the appropriate config when being converted.
	BuildConfigs map[string]compose.BuildConfig `yaml:"build_configs,omitempty"`
}

type State

type State struct {
	Workloads          map[string]ScoreWorkloadState      `yaml:"workloads"`
	Resources          map[ResourceUid]ScoreResourceState `yaml:"resources"`
	SharedState        map[string]interface{}             `yaml:"shared_state"`
	ComposeProjectName string                             `yaml:"compose_project"`
	MountsDirectory    string                             `yaml:"mounts_directory"`

	// IsDeprecatedPortPublishingEnabled enables the old score-compose run mechanism of publishing service ports
	IsDeprecatedPortPublishingEnabled bool `yaml:"-"`
}

State is the mega-structure that contains the state of our workload specifications and resources. Score specs are added to this structure and it stores the current resource set.

func (*State) GetResourceOutputForWorkload

func (s *State) GetResourceOutputForWorkload(workloadName string) (map[string]OutputLookupFunc, error)

GetResourceOutputForWorkload returns an output function per resource name in the given workload. This is for passing into the compose translation context to resolve placeholder references. This does not modify the state.

func (*State) GetSortedResourceUids

func (s *State) GetSortedResourceUids() ([]ResourceUid, error)

GetSortedResourceUids returns a topological sorting of the resource uids. The output order is deterministic and ensures that any resource output placeholder statements are strictly evaluated after their referenced resource. If cycles are detected an error will be thrown.

func (*State) GetSubstitutionContextForWorkload

func (s *State) GetSubstitutionContextForWorkload(workloadName string) (map[string]interface{}, error)

func (*State) WithPrimedResources

func (s *State) WithPrimedResources() (*State, error)

WithPrimedResources returns a new copy of State with all workload resources resolved to at least their initial type, class and id. New resources will have an empty provider set. Existing resources will not be touched. This is not a deep copy, but any writes are executed in a copy-on-write manner to avoid modifying the source.

func (*State) WithWorkload

func (s *State) WithWorkload(spec *score.Workload, filePath *string, contexts map[string]compose.BuildConfig) (*State, error)

WithWorkload returns a new copy of State with the workload added, if the workload already exists with the same name then it will be replaced. This is not a deep copy, but any writes are executed in a copy-on-write manner to avoid modifying the source.

type StateDirectory

type StateDirectory struct {
	// The path to the .score-compose directory
	Path string
	// The current state file
	State State
}

The StateDirectory holds the local state of the score-compose project, including any configuration, extensions, plugins, or resource provisioning state when possible.

func LoadStateDirectory

func LoadStateDirectory(directory string) (*StateDirectory, bool, error)

LoadStateDirectory loads the state directory for the given directory (usually PWD).

func (*StateDirectory) Persist

func (sd *StateDirectory) Persist() error

Persist ensures that the directory is created and that the current config file has been written with the latest settings.

Jump to

Keyboard shortcuts

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