extras

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package extras contains additional utility transformers and generators.

GitConfigMapGeneratorPlugin is identical to ConfigMapGeneratorPlugin but automatically creates two properties when run inside a git repository:

  • repoURL gives the URL of the origin remote.
  • targetRevision gives the current branch.

ExtendedReplacementTransformerPlugin is a copy of ReplacementTransformerPlugin that provides extended target paths into embedded data structures. For instance, consider the following resource snippet:

helm:
  parameters:
    - name: common.targetRevision
      # This resource is accessible by traditional transformer
      value: deploy/citest
    - name: common.repoURL
      value: https://github.com/antoinemartin/autocloud.git
  values: |
    uninode: true
    apps:
      enabled: true
    common:
      # This embedded resource is not accessible
      targetRevision: deploy/citest
      repoURL: https://github.com/antoinemartin/autocloud.git

In the above, the common.targetRevision property of the yaml embedded in the spec.source.helm.values property is not accessible with the traditional ReplacementTransformerPlugin. With the extended transformer, you can target it with:

fieldPaths:
- spec.source.helm.parameters.[name=common.targetRevision].value
- spec.source.helm.values.!!yaml.common.targetRevision

Note the use of !!yaml to designate the encoding of the embedded structure. The extended transformer supports the following encodings:

  • YAML
  • JSON
  • TOML
  • INI
  • base64
  • Plain text (with Regexp)

Index

Constants

This section is empty.

Variables

EncoderFactories register the Encoder factory functions for each [EncoderType].

ExtenderFactories register the Extender factory functions for each ExtenderType.

Functions

func Decrypt added in v0.4.0

func Decrypt(b []byte, format formats.Format, file string, ignoreMac bool) (nodes []*yaml.RNode, err error)

func EncodeBase64 added in v0.4.2

func EncodeBase64(value string) (string, error)

EncodeBase64 encodes value in base64

func EncodeBcrypt added in v0.4.2

func EncodeBcrypt(value string) (string, error)

EncodeBcrypt generates the bcrypt hash of value.

func EncodeHex added in v0.4.2

func EncodeHex(value string) (string, error)

EncodeHex returns the hex string of value

func GetEncodedValue added in v0.4.2

func GetEncodedValue(value string, encoding string) (string, error)

func Lookup added in v0.2.0

func Lookup(node *yaml.RNode, path []string, kind yaml.Kind) (*yaml.RNode, error)

Lookup looks for the specified path in node and return the matching node. If kind is a valid node kind and the node doesn't exist, create it.

func NewExtendedReplacementTransformerPlugin added in v0.2.0

func NewExtendedReplacementTransformerPlugin() resmap.TransformerPlugin

NewExtendedReplacementTransformerPlugin returns a newly created ExtendedReplacementTransformerPlugin

func NewGitConfigMapGeneratorPlugin

func NewGitConfigMapGeneratorPlugin() resmap.GeneratorPlugin

NewGitConfigMapGeneratorPlugin returns a newly created GitConfigMapGenerator.

func NewKustomizationGeneratorPlugin added in v0.3.1

func NewKustomizationGeneratorPlugin() resmap.GeneratorPlugin

NewKustomizationGeneratorPlugin returns a newly Created KustomizationGenerator

func NewRemoveTransformerPlugin added in v0.3.0

func NewRemoveTransformerPlugin() resmap.TransformerPlugin

func NewSopsGeneratorPlugin added in v0.4.0

func NewSopsGeneratorPlugin() resmap.GeneratorPlugin

NewSopsGeneratorPlugin returns a newly Created SopsGenerator

Types

type Encoder added in v0.4.2

type Encoder func(value string) (string, error)

Encoder is an encoder function

type EncodingType added in v0.4.2

type EncodingType int

EncodingType enumerates the existing encoding types.

const (
	UnknownEncoding EncodingType = iota
	Base64Encoding
	BCryptEncoding
	HexEncoding
)

func (EncodingType) String added in v0.4.2

func (i EncodingType) String() string

type ExtendedPath added in v0.2.0

type ExtendedPath struct {
	// ResourcePath is The KRM portion of the path
	ResourcePath []string
	// ExtendedSegments contains all extended path segments
	ExtendedSegments *[]*ExtendedSegment
}

ExtendedPath contains all the paths segments of a path. The path is composed by:

  • a KRM resource path, the prefix (ResourcePath)
  • 0 or more [ExtendedSegment]s.

For instance, for the following path:

data.secretConfiguration.!!base64.!!yaml.common.URL

ResourcePath would be ["data", "secretConfiguration"] and ExtendedSegments:

*[]*ExtendedSegment{
     &ExtendedSegment{Encoding: "base64", Path: []string{}},
     &ExtendedSegment{Encoding: "yaml", Path: []string{"common", "URL"}},
 }

func NewExtendedPath added in v0.2.0

func NewExtendedPath(path []string) (*ExtendedPath, error)

NewExtendedPath creates an ExtendedPath from the split path segments in paths.

func (*ExtendedPath) Apply added in v0.2.0

func (ep *ExtendedPath) Apply(target *yaml.RNode, value *yaml.RNode) error

Apply applies value to target. target is the KRM resource specified by ResourcePrefix.

Apply creates the appropriate Extender for each extended segment and traverse it until the last. When reaching the last, it sets value in the appropriate path. It then unwinds the paths and save the modified value in the target.

func (*ExtendedPath) HasExtensions added in v0.2.0

func (ep *ExtendedPath) HasExtensions() bool

HasExtensions returns true if the path contains extended segments.

func (*ExtendedPath) String added in v0.2.0

func (ep *ExtendedPath) String() string

String returns a string representation of the extended path.

type ExtendedReplacementTransformerPlugin added in v0.2.0

type ExtendedReplacementTransformerPlugin struct {
	ReplacementList []types.ReplacementField `json:"replacements,omitempty" yaml:"replacements,omitempty"`
	Replacements    []types.Replacement      `json:"omitempty" yaml:"omitempty"`
	Source          string                   `json:"source,omitempty" yaml:"source,omitempty"`
	// contains filtered or unexported fields
}

Replace values in targets with values from a source. This transformer is "extended" because it allows structured replacement in properties containing a string representation of some structured content. It currently supports the following structured formats:

  • Yaml
  • Json
  • Toml
  • Ini

It also provides helpers for changing content in base64 encoded properties as well as a simple regexp based replacer for edge cases.

Configuration of replacements can be found in the kustomize doc.

func (*ExtendedReplacementTransformerPlugin) Config added in v0.2.0

Config configures the plugin

func (*ExtendedReplacementTransformerPlugin) Transform added in v0.2.0

Transform performs the configured replacements in the specified resource map

type ExtendedSegment added in v0.2.0

type ExtendedSegment struct {
	Encoding string   // The encoding of the embedded data structure
	Path     []string // The path inside the embedded data structure
}

ExtendedSegment contains the path segment of a resource inside an embedded data structure.

func (*ExtendedSegment) Extender added in v0.2.0

func (path *ExtendedSegment) Extender(payload []byte) (Extender, error)

Extender returns a newly created Extender for the appropriate encoding. uses ExtenderFactories.

func (*ExtendedSegment) String added in v0.2.0

func (e *ExtendedSegment) String() string

String returns a string representation of the ExtendedSegment.

For instance:

!!yaml.common.targetRevision

type Extender added in v0.2.0

type Extender interface {
	// SetPayload initialize the embedded data structure with payload.
	SetPayload(payload []byte) error
	// GetPayload returns the current data structure in the appropriate encoding.
	GetPayload() ([]byte, error)
	// Get returns the subset of the structure at path in the appropriate encoding.
	Get(path []string) ([]byte, error)
	// Set modifies the data structure at path with value. Value can either be
	// in the appropriate encoding or can be encoded by the Extender. Please
	// see the Extender documentation to see how the the value is treated.
	Set(path []string, value any) error
}

Extender allows both traversing and modifying hierarchical opaque data structures like yaml, toml or ini files. Part of the structure is addressed through a path that is an array of string symbols.

  • It is first initialized with SetPayload with the data structure payload.
  • Traversal is done with Get
  • Modification of part of the structure is done through Set
  • After modification, the modified payload is retrieved with GetPayload

func NewBase64Extender added in v0.2.0

func NewBase64Extender() Extender

NewBase64Extender returns a newly created Base64 extender.

This extender doesn't allow structured traversal and modification. It just passes its decoded payload downstream. Example of usage:

prefix.!!base64.!!yaml.inside.path

The above means that we want to modify inside.path in the YAML payload that is stored in base64 in the prefix property.

func NewIniExtender added in v0.2.0

func NewIniExtender() Extender

NewIniExtender returns a newly created Extender for modifying INI files like properties.

Some tools may use ini type configuration files. This extender allows modification of the values. At this point, it doesn't allow inserting complete sections. If paths have one element, it will set the corresponding property at the root level. If path have two elements, the first one contains the section name and the second the property name.

Please be aware that this Extender doesn't preserve the source ordering nor the comments in the content.

func NewJsonExtender added in v0.2.0

func NewJsonExtender() Extender

NewJsonExtender returns a newly created Extender to modify JSON content.

As with the YAML extender (see NewYamlExtender), modifications are not limited to scalar values but the source can be a mapping or a sequence.

func NewRegexExtender added in v0.2.0

func NewRegexExtender() Extender

NewRegexExtender returns a newly created Regexp Extender.

This extender allows text replacement in pure text properties. It is useful in the case the content of the KRM property is not structured.

We don't recommend using it too much as it weakens the transformation.

The paths to use with this extender are always composed of two elements:

  • The regexp to look for in the text.
  • The capture group index to replace with the source value.

Examples:

^\s+HostName\s+(\S+)\s*$.1

Changes the value after HostName with value.

^\s+HostName\s+\S+\s*$.0

Replace the whole line with value.

func NewTomlExtender added in v0.2.0

func NewTomlExtender() Extender

NewTomlExtender returns a newly created Extender for modifying properties containing TOML.

Please be aware that this Extender doesn't preserve the source ordering nor the comments in the content.

func NewYamlExtender added in v0.2.0

func NewYamlExtender() Extender

NewYamlExtender returns a newly created YAML Extender.

With this encoding, you can set scalar values (strings, numbers) as well as mapping values.

type ExtenderType added in v0.2.0

type ExtenderType int

ExtenderType enumerates the existing extender types.

const (
	Unknown ExtenderType = iota
	YamlExtender
	Base64Extender
	RegexExtender
	JsonExtender
	TomlExtender
	IniExtender
)

func (ExtenderType) String added in v0.2.0

func (i ExtenderType) String() string

type GitConfigMapGeneratorPlugin

type GitConfigMapGeneratorPlugin struct {
	types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
	types.ConfigMapArgs
	// The name of the remote which URL to include. defaults to "origin".
	RemoteName string `json:"remoteName,omitempty" yaml:"remoteName,omitempty"`
	// contains filtered or unexported fields
}

GitConfigMapGeneratorPlugin generates a config map that includes two properties of the current git repository:

  • repoURL contains the URL or the remote specified by remoteName. by default, it takes the URL of the remote named "origin".
  • targetRevision contains the name of the current branch.

This generator is useful in transformations that use those values, like for instance Argo CD application customization.

Information about the configuration can be found in the kustomize doc.

func (*GitConfigMapGeneratorPlugin) Config

func (p *GitConfigMapGeneratorPlugin) Config(h *resmap.PluginHelpers, config []byte) (err error)

Config configures the generator with the functionConfig passed in config.

func (*GitConfigMapGeneratorPlugin) Generate

Generate generates the config map

type KustomizationGeneratorPlugin added in v0.3.1

type KustomizationGeneratorPlugin struct {
	Directory string `json:"kustomizeDirectory,omitempty" yaml:"kustomizeDirectory,omitempty"`
}

KustomizationGeneratorPlugin configures the KustomizationGenerator.

func (*KustomizationGeneratorPlugin) Config added in v0.3.1

func (p *KustomizationGeneratorPlugin) Config(
	h *resmap.PluginHelpers, c []byte) (err error)

Config reads the function configuration, i.e. the kustomizeDirectory

func (*KustomizationGeneratorPlugin) Generate added in v0.3.1

Generate generates the resources of the directory

type RemoveTransformerPlugin added in v0.3.0

type RemoveTransformerPlugin struct {
	Targets []*types.Selector `json:"targets,omitempty" yaml:"targets,omitempty"`
}

func (*RemoveTransformerPlugin) Config added in v0.3.0

func (p *RemoveTransformerPlugin) Config(
	h *resmap.PluginHelpers, c []byte) (err error)

func (*RemoveTransformerPlugin) Transform added in v0.3.0

func (p *RemoveTransformerPlugin) Transform(m resmap.ResMap) error

type SopsGeneratorPlugin added in v0.4.0

type SopsGeneratorPlugin struct {
	yaml.ResourceMeta

	Files []string `yaml:"files,omitempty"`

	Sops map[string]interface{} `json:"sops,omitempty" yaml:"spec,omitempty"`
	// contains filtered or unexported fields
}

SopsGeneratorPlugin configures the SopsGenerator.

func (*SopsGeneratorPlugin) Config added in v0.4.0

func (p *SopsGeneratorPlugin) Config(h *resmap.PluginHelpers, c []byte) (err error)

Config reads the function configuration, i.e. the kustomizeDirectory

func (*SopsGeneratorPlugin) Generate added in v0.4.0

func (p *SopsGeneratorPlugin) Generate() (resmap.ResMap, error)

Generate generates the resources of the directory

Jump to

Keyboard shortcuts

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