config

package
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config provides the functions to load default or user provided configurations for different transformers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

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

Factory makes instances of TransformerConfig.

func NewFactory

func NewFactory(l ifc.Loader) *Factory

func (*Factory) FromFiles

func (tf *Factory) FromFiles(
	paths []string) (*TransformerConfig, error)

FromFiles returns a TranformerConfig object from a list of files

type FieldSpec

type FieldSpec struct {
	gvk.Gvk            `json:",inline,omitempty" yaml:",inline,omitempty"`
	Path               string `json:"path,omitempty" yaml:"path,omitempty"`
	CreateIfNotPresent bool   `json:"create,omitempty" yaml:"create,omitempty"`
}

FieldSpec completely specifies a kustomizable field in an unstructured representation of a k8s API object. It helps define the operands of transformations.

For example, a directive to add a common label to objects will need to know that a 'Deployment' object (in API group 'apps', any version) can have labels at field path 'spec/template/metadata/labels', and further that it is OK (or not OK) to add that field path to the object if the field path doesn't exist already.

This would look like

{
  group: apps
  kind: Deployment
  path: spec/template/metadata/labels
  create: true
}

func (FieldSpec) PathSlice

func (fs FieldSpec) PathSlice() []string

PathSlice converts the path string to a slice of strings, separated by a '/'. Forward slash can be contained in a fieldname. such as ingress.kubernetes.io/auth-secret in Ingress annotations. To deal with this special case, the path to this field should be formatted as

metadata/annotations/ingress.kubernetes.io\/auth-secret

Then PathSlice will return

[]string{
   "metadata",
   "annotations",
   "ingress.auth-secretkubernetes.io/auth-secret"
}

func (FieldSpec) String

func (fs FieldSpec) String() string

type NameBackReferences

type NameBackReferences struct {
	gvk.Gvk    `json:",inline,omitempty" yaml:",inline,omitempty"`
	FieldSpecs fsSlice `json:"FieldSpecs,omitempty" yaml:"FieldSpecs,omitempty"`
}

NameBackReferences is an association between a gvk.GVK and a list of FieldSpec instances that could refer to it.

It is used to handle name changes, and can be thought of as a a contact list. If you change your own contact info (name, phone number, etc.), you must tell your contacts or they won't know about the change.

For example, ConfigMaps can be used by Pods and everything that contains a Pod; Deployment, Job, StatefulSet, etc. To change the name of a ConfigMap instance from 'alice' to 'bob', one must visit all objects that could refer to the ConfigMap, see if they mention 'alice', and if so, change the reference to 'bob'.

The NameBackReferences instance to aid in this could look like

{
  kind: ConfigMap
  version: v1
  FieldSpecs:
  - kind: Pod
    version: v1
    path: spec/volumes/configMap/name
  - kind: Deployment
    path: spec/template/spec/volumes/configMap/name
  - kind: Job
    path: spec/template/spec/volumes/configMap/name
    (etc.)
}

func (NameBackReferences) String

func (n NameBackReferences) String() string

type TransformerConfig

type TransformerConfig struct {
	NamePrefix        fsSlice  `json:"namePrefix,omitempty" yaml:"namePrefix,omitempty"`
	NameSuffix        fsSlice  `json:"nameSuffix,omitempty" yaml:"nameSuffix,omitempty"`
	NameSpace         fsSlice  `json:"namespace,omitempty" yaml:"namespace,omitempty"`
	CommonLabels      fsSlice  `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"`
	CommonAnnotations fsSlice  `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"`
	NameReference     nbrSlice `json:"nameReference,omitempty" yaml:"nameReference,omitempty"`
	VarReference      fsSlice  `json:"varReference,omitempty" yaml:"varReference,omitempty"`
}

TransformerConfig holds the data needed to perform transformations.

func LoadConfigFromCRDs

func LoadConfigFromCRDs(
	ldr ifc.Loader, paths []string) (*TransformerConfig, error)

LoadConfigFromCRDs parse CRD schemas from paths into a TransformerConfig

func MakeDefaultConfig

func MakeDefaultConfig() *TransformerConfig

MakeDefaultConfig returns a default TransformerConfig.

func MakeEmptyConfig

func MakeEmptyConfig() *TransformerConfig

MakeEmptyConfig returns an empty TransformerConfig object

func MakeTransformerConfig

func MakeTransformerConfig(
	ldr ifc.Loader, paths []string) (*TransformerConfig, error)

MakeTransformerConfig returns a merger of custom config, if any, with default config.

func (*TransformerConfig) AddAnnotationFieldSpec

func (t *TransformerConfig) AddAnnotationFieldSpec(fs FieldSpec) (err error)

AddAnnotationFieldSpec adds a FieldSpec to CommonAnnotations

func (*TransformerConfig) AddLabelFieldSpec

func (t *TransformerConfig) AddLabelFieldSpec(fs FieldSpec) (err error)

AddLabelFieldSpec adds a FieldSpec to CommonLabels

func (*TransformerConfig) AddNamereferenceFieldSpec

func (t *TransformerConfig) AddNamereferenceFieldSpec(
	nbrs NameBackReferences) (err error)

AddNamereferenceFieldSpec adds a NameBackReferences to NameReference

func (*TransformerConfig) AddPrefixFieldSpec

func (t *TransformerConfig) AddPrefixFieldSpec(fs FieldSpec) (err error)

AddPrefixFieldSpec adds a FieldSpec to NamePrefix

func (*TransformerConfig) AddSuffixFieldSpec added in v1.0.11

func (t *TransformerConfig) AddSuffixFieldSpec(fs FieldSpec) (err error)

AddSuffixFieldSpec adds a FieldSpec to NameSuffix

func (*TransformerConfig) Merge

func (t *TransformerConfig) Merge(input *TransformerConfig) (
	merged *TransformerConfig, err error)

Merge merges two TransformerConfigs objects into a new TransformerConfig object

Directories

Path Synopsis
Package defaultconfig provides the default transformer configurations
Package defaultconfig provides the default transformer configurations

Jump to

Keyboard shortcuts

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