templateprocessor

package
v0.0.0-...-beceb34 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Deprecated: Use github.com/stolostron/applier/pkg/templateprocessor project

Index

Constants

View Source
const KubernetesYamlsDelimiter = "(?m)^-{3}$"

KubernetesYamlsDelimiter regular expression for yaml delimiter

View Source
const KubernetesYamlsDelimiterString = "---\n"

KubernetesYamlsDelimiterString default yaml delimiter

Variables

This section is empty.

Functions

func ApplierFuncMap

func ApplierFuncMap() template.FuncMap

ApplierFuncMap adds the function map

func ConvertArrayOfBytesToArrayOfString

func ConvertArrayOfBytesToArrayOfString(in [][]byte) (out []string)

ConvertArrayOfBytesToArrayOfString converts an [][]byte to []string

func ConvertArrayOfBytesToString

func ConvertArrayOfBytesToString(in [][]byte) (out string)

ConvertArrayOfBytesToString converts an [][]byte to string

func ConvertStringToArrayOfBytes

func ConvertStringToArrayOfBytes(in, delimiter string) (out [][]byte)

ConvertStringToArrayOfBytes converts a string into a [][]byte using a given delimiter

func GenericFuncMap

func GenericFuncMap() map[string]interface{}

GenericFuncMap returns a copy of the basic function map as a map[string]interface{}.

func TemplateFuncMap

func TemplateFuncMap(tmpl *template.Template) (funcMap template.FuncMap)

TemplateFuncMap generates function map for "include"

func ToYAMLUnstructured

func ToYAMLUnstructured(u *unstructured.Unstructured) ([]byte, error)

ToYAMLUnstructured converts *unstructured.Unstructured to []byte yaml format

func ToYAMLsUnstructured

func ToYAMLsUnstructured(us []*unstructured.Unstructured) ([][]byte, error)

ToYAMLsUnstructured converts []*unstructured.Unstructured to [][]byte yaml format

Types

type KindsOrder

type KindsOrder []string

KindsOrder ...

type MapReader

type MapReader struct {
	// contains filtered or unexported fields
}

YamlFileReader defines a reader for map of string

func NewTestReader

func NewTestReader(assets map[string]string) *MapReader

NewTestReader constructs a new YamlFileReader

func (*MapReader) Asset

func (r *MapReader) Asset(name string) ([]byte, error)

Asset returns an asset

func (*MapReader) AssetNames

func (r *MapReader) AssetNames() ([]string, error)

AssetNames returns the name of all assets

func (*MapReader) ToJSON

func (r *MapReader) ToJSON(b []byte) ([]byte, error)

ToJSON converts to JSON

type MissingKeyType

type MissingKeyType string

MissingKeyType defines the type missing keys for redering

const (
	//MissingKeyTypeZero ...
	MissingKeyTypeZero MissingKeyType = "missingkey=zero"
	//MissingKeyTypeError ...
	MissingKeyTypeError MissingKeyType = "missingkey=error"
	//MissingKeyTypeInvalid ...
	MissingKeyTypeInvalid MissingKeyType = "missingkey=invalid"
	//MissingKeyTypeDefault ...
	MissingKeyTypeDefault MissingKeyType = "missingkey=default"
)

type Options

type Options struct {
	KindsOrder      SortType
	DelimiterString string
	Delimiter       string
	//Override the default order, it contains the kind order which the templateProcess must use to sort all resources.
	CreateUpdateKindsOrder KindsOrder
	DeleteKindsOrder       KindsOrder
	MissingKeyType         MissingKeyType
}

Options defines for the available options for the templateProcessor

type SortType

type SortType string

SortType ...

type TemplateProcessor

type TemplateProcessor struct {
	// contains filtered or unexported fields
}

TemplateProcessor this structure holds all objects for the TemplateProcessor

func NewTemplateProcessor

func NewTemplateProcessor(
	reader TemplateReader,
	options *Options,
) (*TemplateProcessor, error)

NewTemplateProcessor creates a new applier reader: The TemplateReader to use to read the templates options: The possible options for the templateprocessor

func (*TemplateProcessor) AssetNamesInPath

func (tp *TemplateProcessor) AssetNamesInPath(
	path string,
	excluded []string,
	recursive bool,
) ([]string, error)

AssetNamesInPath returns all asset names with a given path and subpath if recursive is set to true, it excludes the assets contained in the excluded parameter

func (*TemplateProcessor) Assets

func (tp *TemplateProcessor) Assets(
	path string,
	excluded []string,
	recursive bool,
) (payloads [][]byte, err error)

Assets returns all assets with a given path and subpath if recursive set to true, it excludes the assets contained in the excluded parameter

func (*TemplateProcessor) BytesArrayToUnstructured

func (tp *TemplateProcessor) BytesArrayToUnstructured(assets [][]byte) (us []*unstructured.Unstructured, err error)

BytesArrayToUnstructured transform a [][]byte to an []*unstructured.Unstructured using the TemplateProcessor reader

func (*TemplateProcessor) BytesToUnstructured

func (tp *TemplateProcessor) BytesToUnstructured(asset []byte) (*unstructured.Unstructured, error)

BytesToUnstructured transform a []byte to an *unstructured.Unstructured using the TemplateProcessor reader

func (*TemplateProcessor) SetCreateUpdateOrder

func (tp *TemplateProcessor) SetCreateUpdateOrder()

SetCreateUpdateOrder used to set the kind order for create or update

func (*TemplateProcessor) SetDeleteOrder

func (tp *TemplateProcessor) SetDeleteOrder()

SetDeleteOrder used to set the kind order for deletion

func (*TemplateProcessor) TemplateBytes

func (tp *TemplateProcessor) TemplateBytes(
	tmpl *template.Template,
	b []byte,
	values interface{},
) ([]byte, error)

TemplateBytes render the given template with the provided values

func (*TemplateProcessor) TemplateResource

func (tp *TemplateProcessor) TemplateResource(
	templateName string,
	values interface{},
) ([]byte, error)

TemplateResource render the given template with the provided values

func (*TemplateProcessor) TemplateResources

func (tp *TemplateProcessor) TemplateResources(
	templateNames []string,
	values interface{},
) ([][]byte, error)

TemplateResources render the given templates with the provided values The resources are not sorted and returned in the same template provided order

func (*TemplateProcessor) TemplateResourcesInPathUnstructured

func (tp *TemplateProcessor) TemplateResourcesInPathUnstructured(
	path string,
	excluded []string,
	recursive bool,
	values interface{}) (us []*unstructured.Unstructured, err error)

TemplateResourcesInPathUnstructured returns all assets in a []unstructured.Unstructured and sort them The []unstructured.Unstructured are sorted following the order defined in variable kindsOrder

func (*TemplateProcessor) TemplateResourcesInPathYaml

func (tp *TemplateProcessor) TemplateResourcesInPathYaml(
	path string,
	excluded []string,
	recursive bool,
	values interface{},
) ([][]byte, error)

TemplateResourcesInPathYaml returns all assets in a path using the provided config. The resources are sorted following the order defined in variable kindsOrder

func (*TemplateProcessor) TemplateResourcesUnstructured

func (tp *TemplateProcessor) TemplateResourcesUnstructured(
	templateNames []string,
	values interface{}) (us []*unstructured.Unstructured, err error)

TemplateResourcesUnstructured returns all assets in a []unstructured.Unstructured and sort them The []unstructured.Unstructured are sorted following the order defined in variable kindsOrder

type TemplateReader

type TemplateReader interface {
	//Retreive an asset from the data source
	Asset(templatePath string) ([]byte, error)
	//List all available assets in the data source
	AssetNames() ([]string, error)
	//Transform the assets into a JSON. This is used to transform the asset into an unstructrued.Unstructured object.
	//For example: if the asset is a yaml, you can use yaml.YAMLToJSON(b []byte) as implementation as it is shown in
	//testread_test.go
	ToJSON(b []byte) ([]byte, error)
}

TemplateReader defines the needed functions

type YamlFileReader

type YamlFileReader struct {
	// contains filtered or unexported fields
}

YamlFileReader defines a reader for yaml files

func NewYamlFileReader

func NewYamlFileReader(
	path string,
) *YamlFileReader

NewYamlFileReader constructs a new YamlFileReader

func (*YamlFileReader) Asset

func (r *YamlFileReader) Asset(
	name string,
) ([]byte, error)

Asset returns an asset

func (*YamlFileReader) AssetNames

func (r *YamlFileReader) AssetNames() ([]string, error)

AssetNames returns the name of all assets

func (*YamlFileReader) ToJSON

func (*YamlFileReader) ToJSON(
	b []byte,
) ([]byte, error)

ToJSON converts to JSON

type YamlStringReader

type YamlStringReader struct {
	Yamls []string
}

YamlStringReader defines a reader for yaml string

func NewYamlStringReader

func NewYamlStringReader(
	yamls string,
	delimiter string,
) *YamlStringReader

NewYamlStringReader returns a YamlStringReader yamls: a string of yaml, separeted by the delimiter. Usually "---\n" delimiter: the delimiter

func (*YamlStringReader) Asset

func (r *YamlStringReader) Asset(
	name string,
) ([]byte, error)

Asset returns an asset

func (*YamlStringReader) AssetNames

func (r *YamlStringReader) AssetNames() ([]string, error)

AssetNames returns the name of all assets

func (*YamlStringReader) ToJSON

func (*YamlStringReader) ToJSON(
	b []byte,
) ([]byte, error)

ToJSON converts to JSON

Jump to

Keyboard shortcuts

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