config

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const Annotation = "x-kubernetes-annotation"

Annotation is to mark a field as annotations. "x-kubernetes-annotation": ""

View Source
const Identity = "x-kubernetes-identity"

Identity is to mark a field as Identity "x-kubernetes-identity": ""

View Source
const Kind = "x-kubernetes-object-ref-kind"

Kind marks the type name of an object ref field "x-kubernetes-object-ref-kind": <kind name>

View Source
const LabelSelector = "x-kubernetes-label-selector"

LabelSelector is to mark a field as LabelSelector "x-kubernetes-label-selector": ""

View Source
const NameKey = "x-kubernetes-object-ref-name-key"

NameKey marks the field key that refers to an object of an object ref field "x-kubernetes-object-ref-name-key": "name" default is "name"

View Source
const Version = "x-kubernetes-object-ref-api-version"

Version marks the type version of an object ref field "x-kubernetes-object-ref-api-version": <apiVersion name>

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) DefaultConfig

func (tf *Factory) DefaultConfig() *TransformerConfig

DefaultConfig returns a default TransformerConfig. This should never fail, hence the Fatal panic.

func (*Factory) EmptyConfig

func (tf *Factory) EmptyConfig() *TransformerConfig

EmptyConfig returns an empty TransformerConfig object

func (*Factory) FromFiles

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

FromFiles returns a TranformerConfig object from a list of files

func (*Factory) LoadCRDs

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

LoadCRDs parse CRD schemas from paths into a TransformerConfig

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 []FieldSpec `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"`
	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 (*TransformerConfig) AddAnnotationFieldSpec

func (t *TransformerConfig) AddAnnotationFieldSpec(fs FieldSpec)

AddAnnotationFieldSpec adds a FieldSpec to CommonAnnotations

func (*TransformerConfig) AddLabelFieldSpec

func (t *TransformerConfig) AddLabelFieldSpec(fs FieldSpec)

AddLabelFieldSpec adds a FieldSpec to CommonLabels

func (*TransformerConfig) AddNamereferenceFieldSpec

func (t *TransformerConfig) AddNamereferenceFieldSpec(nbrs NameBackReferences)

AddNamereferenceFieldSpec adds a NameBackReferences to NameReference

func (*TransformerConfig) AddPrefixFieldSpec

func (t *TransformerConfig) AddPrefixFieldSpec(fs FieldSpec)

AddPrefixFieldSpec adds a FieldSpec to NamePrefix

func (*TransformerConfig) Merge

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