renderer

package
v0.14.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CommonLabelPaths is a list of locations in an object type where labels should be added.
	// Taken from here: https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/commonlabels.go
	CommonLabelPaths = []ResourcePath{
		{Group: "", Kind: "", /* contains filtered or unexported fields */},
		{Group: "apps", Kind: "StatefulSet", /* contains filtered or unexported fields */},
		{Group: "apps", Kind: "StatefulSet", /* contains filtered or unexported fields */},
		{Group: "apps", Kind: "Deployment", /* contains filtered or unexported fields */},
		{Group: "", Kind: "ReplicaSet", /* contains filtered or unexported fields */},
		{Group: "", Kind: "ReplicationController", /* contains filtered or unexported fields */},
		{Group: "", Kind: "DaemonSet", /* contains filtered or unexported fields */},
		{Group: "batch", Kind: "Job", /* contains filtered or unexported fields */},
		{Group: "batch", Kind: "CronJob", /* contains filtered or unexported fields */},
		{Group: "batch", Kind: "CronJob", /* contains filtered or unexported fields */},
	}

	// CommonAnnotationPaths is a list of locations for annotations to add in all resources
	CommonAnnotationPaths = []ResourcePath{
		{Group: "", Kind: "", /* contains filtered or unexported fields */},
	}

	// TemplateAnnotationPaths is a list of locations specific to objects where annotations should be added in
	// templates. Taken from here https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/commonannotations.go
	TemplateAnnotationPaths = []ResourcePath{
		{Group: "", Kind: "ReplicationController", /* contains filtered or unexported fields */},
		{Group: "apps", Kind: "StatefulSet", /* contains filtered or unexported fields */},
		{Group: "apps", Kind: "Deployment", /* contains filtered or unexported fields */},
		{Group: "", Kind: "ReplicaSet", /* contains filtered or unexported fields */},
		{Group: "", Kind: "DaemonSet", /* contains filtered or unexported fields */},
		{Group: "batch", Kind: "Job", /* contains filtered or unexported fields */},
		{Group: "batch", Kind: "CronJob", /* contains filtered or unexported fields */},
		{Group: "batch", Kind: "CronJob", /* contains filtered or unexported fields */},
	}
)

Functions

func ToYaml added in v0.11.0

func ToYaml(v interface{}) (string, error)

ToYaml takes any value, and returns its YAML representation as a string.

func YamlToObject

func YamlToObject(yaml string) (objs []runtime.Object, err error)

YamlToObject parses a list of runtime.Objects from the provided yaml If the type is not known in the scheme, it tries to parse it as Unstructured We used to use 'apimachiner/pkg/util/yaml' for splitting the input into multiple yamls, however under the covers it uses bufio.NewScanner with token defaults with no option to modify. see: https://github.com/kubernetes/apimachinery/blob/release-1.6/pkg/util/yaml/decoder.go#L94 The YAML input can be too large for the default scan token size used by these packages. For more detail read: https://github.com/kudobuilder/kudo/pull/1400 TODO(av) could we use something else than a global scheme here? Should we somehow inject it?

Types

type DefaultEnhancer added in v0.10.0

type DefaultEnhancer struct {
	Scheme    *runtime.Scheme
	Client    client.Client
	Discovery discovery.CachedDiscoveryInterface
}

DefaultEnhancer is implementation of Enhancer that applies the defined conventions by directly editing runtime.Objects (Unstructured).

func (*DefaultEnhancer) Apply added in v0.10.0

func (de *DefaultEnhancer) Apply(templates map[string]string, metadata Metadata) (objsToAdd []runtime.Object, err error)

Apply accepts templates to be rendered in kubernetes and enhances them with our own KUDO conventions These include the way we name our objects and what labels we apply to them

type Engine

type Engine struct {
	FuncMap template.FuncMap
}

Engine is the control struct for parsing and templating Kubernetes resources in an ordered fashion

func New

func New() *Engine

New creates an engine with a default function map, using a modified Sprig func map. Because these templates are rendered by the operator, we delete any functions that potentially access the environment the controller is running in.

func (*Engine) Render

func (e *Engine) Render(tplName string, tpl string, vals map[string]interface{}) (string, error)

Render creates a fully rendered template based on a set of values. It parses these in strict mode, returning errors when keys are missing.

func (Engine) Template added in v0.9.0

func (e Engine) Template(name string) *template.Template

Template provides access to the engines template engine.

type Enhancer

type Enhancer interface {
	Apply(templates map[string]string, metadata Metadata) ([]runtime.Object, error)
}

Enhancer takes your kubernetes template and kudo related Metadata and applies them to all resources in form of labels and annotations it also takes care of setting an owner of all the resources to the provided object

type Metadata

type Metadata struct {
	engine.Metadata

	PlanName  string
	PlanUID   types.UID
	PhaseName string
	StepName  string
	TaskName  string
}

Metadata contains Metadata along with specific fields associated with current plan being executed like current plan, phase, step or task names.

type ResourcePath added in v0.13.0

type ResourcePath struct {
	Group   string
	Version string
	Kind    string
	// contains filtered or unexported fields
}

type VariableMap added in v0.14.0

type VariableMap map[string]interface{}

VariableMap is the map of variables which are used in templates like map["OperatorName"]

func NewVariableMap added in v0.14.0

func NewVariableMap() VariableMap

NewVariableMap creates variable map necessary for template rendering it uses a builder pattern to create the desired map of variables for a map of default values `renderer.NewVariableMap().WithDefaults()` as a builder pattern, when chaining latter methods in the chain take precedence `renderer.NewVariableMap().WithDefaults().WithResource(pkg.Resources)` will have default values overwritten with resource data

func (VariableMap) WithDefaults added in v0.14.0

func (m VariableMap) WithDefaults() VariableMap

WithDefaults defines variables which are potentially required by any operator. By defaulting to this map, all templates should pass, even if values are not expected.

func (VariableMap) WithInstance added in v0.14.0

func (m VariableMap) WithInstance(operatorName, instanceName, namespace, appVersion, operatorVersion string) VariableMap

WithInstance provides a convince for add instance information.

func (VariableMap) WithMetadata added in v0.14.0

func (m VariableMap) WithMetadata(meta Metadata) VariableMap

WithMetadata overrides the map with metadata data

func (VariableMap) WithParameterStrings added in v0.14.0

func (m VariableMap) WithParameterStrings(parameters map[string]string) VariableMap

WithParameterStrings overrides the map with parameter map which uses `string values

func (VariableMap) WithParameters added in v0.14.0

func (m VariableMap) WithParameters(parameters map[string]interface{}) VariableMap

WithParameters overrides the map with parameter map which uses `interface{}` values

func (VariableMap) WithPipes added in v0.14.0

func (m VariableMap) WithPipes(pipes map[string]string) VariableMap

WithPipes overrides the map with a pipe map

func (VariableMap) WithResource added in v0.14.0

func (m VariableMap) WithResource(resources *packages.Resources) VariableMap

WithResource overrides map with resource data

Jump to

Keyboard shortcuts

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