common

package
v0.7.19 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateFileRepresentation

type CreateFileRepresentation struct {
	FileName string      `yaml:"file"`
	FileMode fs.FileMode `yaml:"file_mode,omitempty"`
	Content  string      `yaml:"content"`
}

CreateFileRepresentation describes the unit's file that will be saved in the unit's working directory when building.

type Factory

type Factory struct {
}

Factory factory for s3 backends.

func (*Factory) New

func (f *Factory) New(spec map[string]interface{}, stack *project.Stack) (project.Unit, error)

New creates new units driver factory.

func (*Factory) NewFromState

func (f *Factory) NewFromState(spec map[string]interface{}, modKey string, p *project.StateProject) (project.Unit, error)

NewFromState creates new units from state data.

type FilesListT

type FilesListT []*CreateFileRepresentation

FilesListT describes all unit's files will be write to the unit's working directory when building.

func (*FilesListT) Add

func (l *FilesListT) Add(fileName string, content string, mode fs.FileMode) error

Add insert the new file with name fileName, returns error if file with this name already exists.

func (*FilesListT) Delete

func (l *FilesListT) Delete(fileName string)

Delete delete file with name fileName, do nothing if not found.

func (*FilesListT) Find

func (l *FilesListT) Find(fileName string) int

Find searchs file and returns a pointer to it or nil if not found.

func (*FilesListT) IsEmpty

func (l *FilesListT) IsEmpty() bool

func (*FilesListT) Len

func (l *FilesListT) Len() int

func (*FilesListT) ReadDir

func (l *FilesListT) ReadDir(path, baseDir string, pattern ...string) (err error)

ReadDir recursively reads files in path, saving relative pathes from baseDir.

func (*FilesListT) ReadFile

func (l *FilesListT) ReadFile(path, baseDir string) (err error)

ReadFile reads file to list.

func (*FilesListT) SPrintLs

func (l *FilesListT) SPrintLs() string

func (*FilesListT) WriteFiles

func (l *FilesListT) WriteFiles(path string) (err error)

WriteFiles write all files to path.

type HookSpec

type HookSpec struct {
	Command   string `json:"command"`
	OnDestroy bool   `yaml:"on_destroy,omitempty" json:"on_destroy,omitempty"`
	OnApply   bool   `yaml:"on_apply,omitempty" json:"on_apply,omitempty"`
	OnPlan    bool   `yaml:"on_plan,omitempty" json:"on_plan,omitempty"`
}

HookSpec describes pre/post hooks configuration in unit YAML.

type OperationConfig

type OperationConfig struct {
	Commands []interface{} `yaml:"commands" json:"commands"`
}

OperationConfig type that describe apply, plan and destroy operations.

type OutputParser

type OutputParser func(string, *project.UnitLinksT) error

OutputParser represents function for parsing unit output.

type OutputsConfigSpec

type OutputsConfigSpec struct {
	Command   string `yaml:"command,omitempty" json:"command,omitempty"`
	Type      string `yaml:"type" json:"type"`
	Regexp    string `yaml:"regexp,omitempty" json:"regexp,omitempty"`
	Separator string `yaml:"separator,omitempty" json:"separator,omitempty"`
}

OutputsConfigSpec describe how to retrive parse unit outputs.

type OutputsT

type OutputsT struct {
	List map[string]*project.ULinkT `json:"outputs_list,omitempty"`
}

type Unit

type Unit struct {
	StackPtr         *project.Stack          `yaml:"-" json:"-"`
	ProjectPtr       *project.Project        `yaml:"-" json:"-"`
	DependenciesList *project.UnitLinksT     `yaml:"-" json:"-"`
	SpecRaw          map[string]interface{}  `yaml:"-" json:"-"`
	OutputRaw        []byte                  `yaml:"-" json:"-"`
	CacheDir         string                  `yaml:"-" json:"-"`
	MyName           string                  `yaml:"name" json:"name"`
	WorkDir          string                  `yaml:"work_dir,omitempty" json:"work_dir,omitempty"`
	Env              map[string]string       `yaml:"env,omitempty" json:"env,omitempty"`
	CreateFiles      *FilesListT             `yaml:"create_files,omitempty" json:"create_files,omitempty"`
	InitConf         *OperationConfig        `yaml:"init,omitempty" json:"init,omitempty"`
	ApplyConf        *OperationConfig        `yaml:"apply,omitempty" json:"apply,omitempty"`
	PlanConf         *OperationConfig        `yaml:"plan,omitempty" json:"plan,omitempty"`
	DestroyConf      *OperationConfig        `yaml:"destroy,omitempty" json:"destroy,omitempty"`
	GetOutputsConf   *OutputsConfigSpec      `yaml:"outputs,omitempty" json:"outputs_config,omitempty"`
	OutputParsers    map[string]OutputParser `yaml:"-" json:"-"`
	Applied          bool                    `yaml:"-" json:"-"`
	PreHook          *HookSpec               `yaml:"-" json:"pre_hook,omitempty"`
	PostHook         *HookSpec               `yaml:"-" json:"post_hook,omitempty"`
	UnitKind         string                  `yaml:"type" json:"type"`
	BackendPtr       *project.Backend        `yaml:"-" json:"-"`
	BackendName      string                  `yaml:"-" json:"backend_name"`
	SavedState       interface{}             `yaml:"-" json:"-"`
	DependsOn        interface{}             `yaml:"depends_on,omitempty" json:"depends_on,omitempty"`
	FApply           bool                    `yaml:"force_apply" json:"force_apply"`
	// contains filtered or unexported fields
}

Unit describe cluster.dev shell unit.

func NewEmptyUnit

func NewEmptyUnit() *Unit

NewEmptyUnit creates new unit.

func NewUnit

func NewUnit(spec map[string]interface{}, stack *project.Stack) (*Unit, error)

NewUnit creates new unit and load config.

func (*Unit) Apply

func (u *Unit) Apply() error

Apply runs unit apply procedure.

func (*Unit) ApplyOutput

func (u *Unit) ApplyOutput() []byte

ApplyOutput return output of unit applying.

func (*Unit) Backend

func (u *Unit) Backend() project.Backend

Backend return unit backend.

func (*Unit) Build

func (u *Unit) Build() error

func (*Unit) CodeDir

func (u *Unit) CodeDir() string

CodeDir return path to unit code directory.

func (*Unit) Dependencies

func (u *Unit) Dependencies() *project.UnitLinksT

Dependencies return slice of unit dependencies.

func (*Unit) Destroy

func (u *Unit) Destroy() error

Destroy unit.

func (*Unit) EnvSlice added in v0.7.1

func (u *Unit) EnvSlice() []string

EnvSlice returns the list of unit environment variables as slice in a format ENV_NAME=ENV_VALUE

func (*Unit) ForceApply

func (u *Unit) ForceApply() bool

ForceApply return true if unit need apply regardless of state.

func (*Unit) GetDiffData

func (u *Unit) GetDiffData() interface{}

GetDiffData return unit representation as a data set for diff and reapply.

func (*Unit) GetState

func (u *Unit) GetState() interface{}

func (*Unit) GetStateDiffData

func (u *Unit) GetStateDiffData() interface{}

GetStateDiffData return unit representation as a data set for diff only update state.

func (*Unit) GetStateUnit

func (u *Unit) GetStateUnit() *Unit

func (*Unit) GetUnitDiff

func (u *Unit) GetUnitDiff() UnitDiffSpec

func (*Unit) Init

func (u *Unit) Init() error

Init runs init procedure for unit.

func (*Unit) JSONOutputParser

func (u *Unit) JSONOutputParser(in string, out *project.UnitLinksT) error

JSONOutputParser parse in (expected JSON string) and stores it in the value pointed to by out.

func (*Unit) Key

func (u *Unit) Key() string

Key return uniq unit index (stackName.unitName).

func (*Unit) KindKey

func (u *Unit) KindKey() string

KindKey returns unit kind.

func (*Unit) LoadState

func (u *Unit) LoadState(spec interface{}, modKey string, p *project.StateProject) error

func (*Unit) Mux

func (u *Unit) Mux() *sync.Mutex

Mux return unit mutex to lock apply.

func (*Unit) Name

func (u *Unit) Name() string

Name return unit name.

func (*Unit) Plan

func (u *Unit) Plan() error

Plan unit.

func (*Unit) Prepare

func (u *Unit) Prepare() error

Prepare scan all markers in unit, and build project unit links, and unit dependencies.

func (*Unit) Project

func (u *Unit) Project() *project.Project

Project return ptr to unit project.

func (*Unit) ReadConfig

func (u *Unit) ReadConfig(spec map[string]interface{}, stack *project.Stack) error

ReadConfig reads unit spec (unmarshaled YAML) and init the unit.

func (*Unit) RegexOutputParser

func (u *Unit) RegexOutputParser(in string, out *project.UnitLinksT) error

RegexOutputParser parse each line od in string with key/value regexp and stores result as a map in the value pointed to by out.

func (*Unit) ReplaceOutputsForDiff

func (u *Unit) ReplaceOutputsForDiff(in, out interface{}) error

ReplaceOutputsForDiff replace remote state markers in struct to <remote state stack.mod.output> to show in diff.

func (*Unit) ScanData

func (u *Unit) ScanData(scanner project.MarkerScanner) error

func (*Unit) SeparatorOutputParser

func (u *Unit) SeparatorOutputParser(in string, out *project.UnitLinksT) error

SeparatorOutputParser split each line of in string with using separator and stores result as a map in the value pointed to by out.

func (*Unit) Stack

func (u *Unit) Stack() *project.Stack

Stack return ptr to unit stack.

func (*Unit) StackName

func (u *Unit) StackName() string

StackName return unit stack name.

func (*Unit) UpdateProjectRuntimeData

func (u *Unit) UpdateProjectRuntimeData(p *project.Project) error

UpdateProjectRuntimeData update project runtime dataset, adds unit outputs. TODO: get unit outputs and write to project runtime dataset. Now this function is only for printer's unit interface.

func (*Unit) WasApplied

func (u *Unit) WasApplied() bool

WasApplied return true if unit's method Apply was runned.

type UnitDiffSpec

type UnitDiffSpec struct {
	Outputs map[string]string `json:"outputs,omitempty"`
	// CreateFiles     *FilesListT            `json:"create_files,omitempty"`
	CreateFilesDiff map[string][]string    `json:"-"`
	ApplyConf       *OperationConfig       `json:"apply,omitempty"`
	Env             map[string]interface{} `json:"env,omitempty"`
	OutputsConfig   *OutputsConfigSpec     `json:"outputs_config,omitempty"`
	PreHook         *HookSpec              `json:"pre_hook,omitempty"`
	PostHook        *HookSpec              `json:"post_hook,omitempty"`
}

UnitDiffSpec describe the pieces of StateSpec data, that will be compered in "plan" diff and should affect the unit redeployment.

Jump to

Keyboard shortcuts

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