Documentation ¶
Index ¶
- Constants
- Variables
- func AssertRunForEnvironment(t *testing.T, dir string, environment string, result_dir string)
- func AssertVarsChain(t *testing.T, p *Processor, dir string, environment string)
- func CloneFuncMap() template.FuncMap
- func LoadConfigFile(path string) util.AnyMap
- func RegisterSource(name string, factory SourceFactory, order int, force bool)
- func RegisterTemplateFunc(name string, fn interface{})
- func RunTests(t *testing.T, test_fn func(t *testing.T, dir string))
- type BaseSource
- type Deployables
- type DeployablesSource
- type EnvForPrefix
- type EnvVarsSource
- type EnvironmentDeployables
- type EnvironmentsSource
- type ExpectedVarsChains
- type FileSystemSource
- type MergeEvent
- type MergeHistory
- type Processor
- func (p *Processor) Get(name string) SourceInterface
- func (p *Processor) ListEnvironments() []string
- func (p *Processor) ListTemplates() []map[string]string
- func (p *Processor) MergeConfig(origin string, config util.AnyMap)
- func (p *Processor) RunForEnvironment(environment string, target_base_dir string)
- func (p *Processor) Specs(environment string) Specs
- func (p *Processor) Template(name string) *Template
- type RegisteredSource
- type RegisteredSources
- type SourceFactory
- type SourceInstance
- type SourceInterface
- type Spec
- type Specs
- type Template
- type Templates
- type Vars
- type VarsChain
- type VarsLink
Constants ¶
const ( ConfigSuffix = ".yaml" ConfigFname = "common" + ConfigSuffix ConfigD = "config.d" EnvironmentsSubdir = "environments" TemplatesSubdir = "templates" )
const GlobalVarsKey = "_vars"
Variables ¶
var FuncMap = template.FuncMap{ "iadd": func(x, y int) int { return x + y }, "imul": func(x, y int) int { return x * y }, "idiv": func(x, y int) int { return x / y }, "imod": func(x, m int) int { return x % m }, "tostr": util.ToString, "strtoi": util.AtoI, "safe": util.SafeValue, "coalesce": util.Coalesce, "tolower": util.SafeToLower, "match": util.SafeMatch, "regexrepl": util.SafeReplaceAllString, "quotedlist": util.QuotedList, "sequence": util.Sequence, "timeoffset": util.TimeOffset, "isfile": util.IsFile, "decode64": func(in string) string { data, err := base64.StdEncoding.DecodeString(in) if err != nil { panic(err) } return string(data) }, }
Default functions set available to templates.
var TestEnvVars = map[string]string{
"x": "v_from_env_x",
}
Env vars that will be set for each run
var (
TestsDefBaseDir = filepath.Join(base_dir, "test-run")
)
Functions ¶
func AssertRunForEnvironment ¶
Assert that processed templates match expectations storet in the results/ dir
func AssertVarsChain ¶
Assert that Processor vars chains for environment templates match expectations. Expectations are stored in vars_chain/<environment>.yaml files. What we are testing here is that config.d/ values superseed common.yaml, and environments/* superseed common,yaml environments
func CloneFuncMap ¶
Returns a FuncMap clone, so parallel processing does not complain.
func LoadConfigFile ¶
Config file loader. Loads Yaml into a map.
func RegisterSource ¶
func RegisterSource(name string, factory SourceFactory, order int, force bool)
Register Source point
func RegisterTemplateFunc ¶
func RegisterTemplateFunc(name string, fn interface{})
Register additional function.
Types ¶
type BaseSource ¶
type BaseSource struct {
MergeHistory
}
A basic SourceInterface implementation, with nil returns.
func MakeBaseSource ¶
func MakeBaseSource() BaseSource
func (*BaseSource) AllEnvironments ¶
func (s *BaseSource) AllEnvironments() []string
func (*BaseSource) AllTemplates ¶
func (s *BaseSource) AllTemplates() Templates
func (*BaseSource) DeployablesForEnvironment ¶
func (s *BaseSource) DeployablesForEnvironment(environment string) *Deployables
func (*BaseSource) Template ¶
func (s *BaseSource) Template(n string) *Template
type Deployables ¶
A set of Vars and Specs, used per environment or default
func MakeDeployables ¶
func MakeDeployables(m util.AnyMap) *Deployables
Turns a map into Deployables.
func (*Deployables) Merge ¶
func (ds *Deployables) Merge(ds1 *Deployables)
Applies an overriding set.
func (*Deployables) Overlay ¶
func (ds *Deployables) Overlay(ds1 *Deployables)
Applies an overriding set, overlaying the new default Vars over the existing Specs first.
func (*Deployables) PreparedSpecs ¶
func (ds *Deployables) PreparedSpecs() Specs
Returns the Specs with applied default Vars where appropriate
type DeployablesSource ¶
type DeployablesSource struct { *Deployables BaseSource }
Generic DeployablesSource type and SourceInterface implementation
func (*DeployablesSource) DeployablesForEnvironment ¶
func (d *DeployablesSource) DeployablesForEnvironment(environment string) *Deployables
func (*DeployablesSource) MergeConfig ¶
func (d *DeployablesSource) MergeConfig(origin string, deployables interface{})
type EnvForPrefix ¶
type EnvForPrefix string
Helper type to set/clear env vars
func FindEnvVarsPrefix ¶
func FindEnvVarsPrefix(dir string) EnvForPrefix
Find suitable env_vars_prefix in config(s)
func (*EnvForPrefix) Clear ¶
func (ep *EnvForPrefix) Clear()
func (*EnvForPrefix) Set ¶
func (ep *EnvForPrefix) Set(v, val string)
type EnvVarsSource ¶
type EnvVarsSource struct {
*DeployablesSource
}
An env vars version of DeployablesSource type. NOSpecs, just Vars.
func (*EnvVarsSource) MergeConfig ¶
func (v *EnvVarsSource) MergeConfig(origin string, prefix interface{})
type EnvironmentDeployables ¶
type EnvironmentDeployables map[string]*Deployables
A Deployables per environment version of DeployablesSource type
type EnvironmentsSource ¶
type EnvironmentsSource struct { EnvironmentDeployables BaseSource }
func (*EnvironmentsSource) AllEnvironments ¶
func (e *EnvironmentsSource) AllEnvironments() []string
func (*EnvironmentsSource) DeployablesForEnvironment ¶
func (e *EnvironmentsSource) DeployablesForEnvironment(environment string) *Deployables
func (*EnvironmentsSource) MergeConfig ¶
func (e *EnvironmentsSource) MergeConfig(origin string, es interface{})
type ExpectedVarsChains ¶
type FileSystemSource ¶
type FileSystemSource struct { *EnvironmentsSource Templates }
A EnvironmentsSource type upgrade with Templates
func (*FileSystemSource) AllTemplates ¶
func (f *FileSystemSource) AllTemplates() Templates
func (*FileSystemSource) MergeConfig ¶
func (f *FileSystemSource) MergeConfig(origin string, d interface{})
func (*FileSystemSource) Template ¶
func (f *FileSystemSource) Template(name string) *Template
type MergeEvent ¶
type MergeEvent struct { Origin string Loaded interface{} }
Forensic helpers, merge events audit
type MergeHistory ¶
type MergeHistory []*MergeEvent
func (*MergeHistory) AddHistory ¶
func (h *MergeHistory) AddHistory(origin string, values interface{})
type Processor ¶
type Processor struct { DefaultEnvironment string Sources []*SourceInstance }
The main workhorse - a collection of SourceInstances that applies Vars hierarchically to Templates
func LoadConfigsFromDir ¶
Config dir loader. Creates a new Processor and loads it with config maps. Calls LoadConfigFile() for each file to get those maps.
func NewProcessor ¶
func NewProcessor() *Processor
Gives a Processor, based on the RegisteredSources
func (*Processor) Get ¶
func (p *Processor) Get(name string) SourceInterface
func (*Processor) ListEnvironments ¶
List all environments known to the Sources
func (*Processor) ListTemplates ¶
List all templates known to the Sources
func (*Processor) MergeConfig ¶
Load Sources from a map. Map keys match RegisteredSource names. Unknow source names are reported and skipped.
func (*Processor) RunForEnvironment ¶
Process Templates for a given environment. Deliver files to the target_base_dir if specified. Templates are processed in parallel.
type RegisteredSource ¶
type RegisteredSource struct { SourceFactory // contains filtered or unexported fields }
Infrastructure for registering sources in order. RegisteredSource is astructure that can potentially be loaded with config values/templates.
type RegisteredSources ¶
type RegisteredSources map[string]*RegisteredSource
func (*RegisteredSources) NewProcessor ¶
func (rs *RegisteredSources) NewProcessor() *Processor
Makes a Processor and loads it with SourceInstances
func (*RegisteredSources) Register ¶
func (rs *RegisteredSources) Register(name string, factory SourceFactory, order int, force bool)
type SourceFactory ¶
type SourceFactory func() SourceInterface
type SourceInstance ¶
type SourceInstance struct { Name string SourceInterface }
A named Source - type that implements SourceInterface
type SourceInterface ¶
type SourceInterface interface { MergeConfig(origin string, values interface{}) DeployablesForEnvironment(environment string) *Deployables Template(string) *Template AllEnvironments() []string AllTemplates() Templates }
Source interface
func MakeDeployablesSource ¶
func MakeDeployablesSource() SourceInterface
func MakeEnvVarsSource ¶
func MakeEnvVarsSource() SourceInterface
func MakeEnvironmentsSource ¶
func MakeEnvironmentsSource() SourceInterface
func MakeFileSystemSource ¶
func MakeFileSystemSource() SourceInterface
type Spec ¶
Template deployment Spec storage type.