render

package
v0.4.1 Latest Latest
Warning

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

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

README

Values

A Value in valet is a key value pair which can be defined in quite a few ways, and is accessible during more parts of a valet configuration to aid in customization.

Explanation

Values are a map (string -> string) that most commonly contains values that are string constants, as demonstrated below:

values:
  VirtualServiceName: smh
  Namespace: sm-marketplace
  UpstreamName: sm-marketplace-smm-apiserver-8080
  UpstreamNamespace: gloo-system

Conventionally, values are written in CamelCase, as demonstrated here.

An application may specify certain values are required, to help validate an input when trying to render an application.

Values work in order of precedence.

  1. user values passed in via CLI or via file.
  2. default values on the workflow/application.
  3. localized values to a resource.

Semantics

As shown above, values can be a simple set of (string -> string), but valet allows for much more customization.

values:
  EnvExample: "env:EXAMPLE_ONE" # This populates the value by reading this environment variable
  CmdExample: "cmd:minikube ip" # This populates the value by running this command
  KeyExample: "key:EnvExample" # This creates a value that is an alias for another key
  TemplateExample: "template:{{ .KeyExample }}" # This creates a value by executing a go template using the other values
  FileExample: "file:$HOME/a/file/on/my/{{ .FileName }}" # This executes the template, expands the env, and then gets the content of the file 

These are the 5 special keywords that can be prefixed to values to get special behavior from valet. They are the following:

  • env:
    • this prefix tells valet to expand the value by looking it up as an environment variable
  • cmd:
    • this prefix tells valet to execute the cmd and place stdout in place of the value
  • key:
    • this prefix tells valet to replace this value with that of another one, identified by the key provided
  • template:
    • this prefix tells valet to template out the string using the other values as inputs
  • file:
    • this prefix is a combination of the others, with additional capability. It will expand env vars, template the value, and then retrieve the contents of the file which is pointed to. That file contents will then be used as the value.

Tags

Valet takes advantage of a go concept called struct tags. These are used when evaluating the struct values. They can be accessed similarly to json tags.

type ExampleResource struct {
	InnerValue string `yaml:"innerValue" valet:"key=Value"`
}

The available tags are:

  • default
    • this tag sets a default value
  • key
    • this tag sets the value of the field by getting the value in values using the provided key
  • template
    • This tag specifies that the value of this struct should be templated using the available values

As these tags use the string related functions, they must be strings in order to function properly.

These tags are executed in the order listed above. If there is no value in the field, then the default gets added. If there is still no default value, and there is a key present, a value is looked up for that key. After that the string is templated. This has the potential for nested templating, but that is not recommended as other struct fields may break if passed templates.

Documentation

Index

Constants

View Source
const (
	VersionKey    = "Version"
	NamespaceKey  = "Namespace"
	DomainKey     = "Domain"
	HostedZoneKey = "HostedZone"
	PathKey       = "Path"
	NameKey       = "Name"

	EnvPrefix      = "env:"
	TemplatePrefix = "template:"
	KeyPrefix      = "key:"
	CmdPrefix      = "cmd:"
	FilePrefix     = "file:"

	ValetField  = "valet"
	TemplateTag = "template"
	DefaultTag  = "default"
	KeyTag      = "key"
)
View Source
const (
	DefaultRegistry = "default"
)

Variables

View Source
var (
	UnableToParseParameterError = func(err error, key, value string) error {
		return errors.Wrapf(err, "Unable to parse parameter with key '%s' and value '%s'", key, value)
	}

	UnableToParseYamlError = func(err error, input string) error {
		return errors.Wrapf(err, "Unable to parse yaml string: %s", input)
	}

	UnableToMarshalYamlError = func(err error, input map[string]interface{}) error {
		return errors.Wrapf(err, "Unable to marshal map to yaml: %v", input)
	}
)
View Source
var (
	ValueNotFoundError = func(key string) error {
		return errors.Errorf("Value %s not provided", key)
	}
	RequiredValueNotProvidedError = func(key string) error {
		return errors.Errorf("Required value %s not found", key)
	}
)
View Source
var (
	UnknownRegistryError = func(name string) error {
		return errors.Errorf("Unknown registry %s", name)
	}
)

Functions

func CoalesceValuesMap

func CoalesceValuesMap(ctx context.Context, initial map[string]interface{}, overrides map[string]interface{}) map[string]interface{}

func ConvertNestedMapToYaml

func ConvertNestedMapToYaml(nestedMap map[string]interface{}) (string, error)

func ConvertParamsToNestedMap

func ConvertParamsToNestedMap(params map[string]string) (map[string]interface{}, error)

func ConvertYamlStringToNestedMap

func ConvertYamlStringToNestedMap(yamlString string) (map[string]interface{}, error)

func LoadBytesFromUrl

func LoadBytesFromUrl(path string) ([]byte, error)

func LoadTemplate

func LoadTemplate(tmpl string, values Values, runner cmd.Runner) (string, error)

func YamlToResources

func YamlToResources(yamlBytes []byte) (kuberesource.UnstructuredResources, error)

Types

type DirectoryRegistry added in v0.4.1

type DirectoryRegistry struct {
	Path string `yaml:"path"`
}

func (*DirectoryRegistry) LoadFile added in v0.4.1

func (l *DirectoryRegistry) LoadFile(path string) (string, error)

type Flags

type Flags []string

func (Flags) ToString

func (f Flags) ToString() string

type InputParams

type InputParams struct {
	Values        Values
	Flags         Flags
	Step          bool
	Registries    map[string]Registry
	CommandRunner cmd.Runner
	IngressClient client.IngressClient
	DnsClient     client.AwsDnsClient
}

func (*InputParams) DeepCopy

func (i *InputParams) DeepCopy() InputParams

func (*InputParams) GetDnsClient

func (i *InputParams) GetDnsClient() (client.AwsDnsClient, error)

func (*InputParams) GetIngressClient

func (i *InputParams) GetIngressClient() client.IngressClient

func (*InputParams) GetRegistry

func (i *InputParams) GetRegistry(name string) (Registry, error)

func (*InputParams) LoadFile

func (i *InputParams) LoadFile(registryName, path string) (string, error)

func (*InputParams) MergeFlags

func (i *InputParams) MergeFlags(flags Flags) InputParams

func (*InputParams) MergeValues

func (i *InputParams) MergeValues(values Values) InputParams

func (*InputParams) RenderFields

func (i *InputParams) RenderFields(input interface{}) error

func (*InputParams) Runner

func (i *InputParams) Runner() cmd.Runner

func (*InputParams) SetRegistry

func (i *InputParams) SetRegistry(name string, registry Registry)

type Registry

type Registry interface {
	LoadFile(path string) (string, error)
}

type Values

type Values map[string]string

func (Values) ContainsKey

func (v Values) ContainsKey(key string) bool

func (Values) DeepCopy

func (v Values) DeepCopy() Values

func (Values) GetValue

func (v Values) GetValue(key string, runner cmd_runner.Runner) (string, error)

func (Values) Load

func (v Values) Load(tmpl string, runner cmd_runner.Runner) (string, error)

func (Values) Render

func (v Values) Render(runner cmd_runner.Runner) (map[string]interface{}, error)

func (Values) RenderFields

func (v Values) RenderFields(input interface{}, runner cmd_runner.Runner) error

func (Values) RenderStringValues

func (v Values) RenderStringValues(runner cmd_runner.Runner) (map[string]string, error)

func (Values) RenderValues

func (v Values) RenderValues(runner cmd_runner.Runner) (map[string]interface{}, error)

func (Values) ToString

func (v Values) ToString() string

Directories

Path Synopsis
Package mock_render is a generated GoMock package.
Package mock_render is a generated GoMock package.

Jump to

Keyboard shortcuts

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