Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateChecksumOfDirectory(dir string) (string, error)
- func CalculateChecksumOfFile(path string) (string, error)
- func CalculateChecksumOfPaths(paths ...string) (string, error)
- func CalculateStringsChecksum(stringArr ...string) string
- func FilesFromRoot(root string, filterFn func(dir string, name string, info os.FileInfo) bool) (files map[string]map[string]string, err error)
- func FindExecutableFilesInPath(dir string) (executables []string, nonExecutables []string, err error)
- func IsNonExistentPathError(err error) bool
- func JSONEqual(a, b []byte) bool
- func KeysSortedByReference(m map[string]struct{}, ref []string) []string
- func LabelsToLogFields(labelsMaps ...map[string]string) log.Fields
- func ListFullyIn(arr []string, ref []string) bool
- func ListIntersection(arrs ...[]string) (result []string)
- func ListSubtract(src []string, ignored ...[]string) (result []string)
- func ListToMapStringStruct(items []string) map[string]struct{}
- func ListUnion(src []string, more ...[]string) []string
- func MapStringStructKeys(m map[string]struct{}) []string
- func MergeLabels(labelsMaps ...map[string]string) map[string]string
- func ModuleEnabledValue(i interface{}) (*bool, error)
- func ModuleNameFromValuesKey(moduleValuesKey string) string
- func ModuleNameToValuesKey(moduleName string) string
- func SortByReference(in []string, ref []string) []string
- func SortReverse(in []string) []string
- func SortReverseByReference(in []string, ref []string) []string
- func SymlinkInfo(path string, info os.FileInfo) (target string, isDir bool, err error)
- func ValidateHookValuesPatch(valuesPatch ValuesPatch, permittedRootKey string) error
- func WalkSymlinks(target string, linkName string, files map[string]map[string]string, ...) (symlinkedDirectories map[string]string, err error)
- type ApplyPatchMode
- type ModuleConfig
- func (mc *ModuleConfig) Checksum() string
- func (mc *ModuleConfig) FromYaml(yamlString []byte) (*ModuleConfig, error)
- func (mc *ModuleConfig) GetEnabled() string
- func (mc *ModuleConfig) GetValues() Values
- func (mc *ModuleConfig) LoadFromValues(values Values) (*ModuleConfig, error)
- func (mc *ModuleConfig) ModuleConfigKey() string
- func (mc *ModuleConfig) ModuleEnabledKey() string
- func (mc *ModuleConfig) String() string
- type Operation
- type Patch
- type Values
- func ApplyValuesPatch(values Values, valuesPatch ValuesPatch, mode ApplyPatchMode) (Values, bool, error)
- func MergeValues(values ...Values) Values
- func NewGlobalValues(globalSectionContent string) (Values, error)
- func NewValues(data map[string]interface{}) (Values, error)
- func NewValuesFromBytes(data []byte) (Values, error)
- func (v Values) AsBytes(format string) ([]byte, error)
- func (v Values) AsConfigMapData() (map[string]string, error)
- func (v Values) AsString(format string) (string, error)
- func (v Values) Checksum() string
- func (v Values) DebugString() string
- func (v Values) Global() Values
- func (v Values) HasGlobal() bool
- func (v Values) HasKey(key string) bool
- func (v Values) IsEmpty() bool
- func (v Values) JsonBytes() ([]byte, error)
- func (v Values) JsonString() (string, error)
- func (v Values) SectionByKey(key string) Values
- func (v Values) YamlBytes() ([]byte, error)
- func (v Values) YamlString() (string, error)
- type ValuesPatch
- func AppendValuesPatch(valuesPatches []ValuesPatch, newValuesPatch ValuesPatch) []ValuesPatch
- func CompactPatches(existedOperations []*ValuesPatchOperation, ...) ValuesPatch
- func CompactValuesPatches(valuesPatches []ValuesPatch, newValuesPatch ValuesPatch) []ValuesPatch
- func EnabledFromValuesPatch(valuesPatch ValuesPatch) ValuesPatch
- func FilterValuesPatch(valuesPatch ValuesPatch, rootPath string) ValuesPatch
- func NewValuesPatch() *ValuesPatch
- func ValuesPatchFromBytes(data []byte) (*ValuesPatch, error)
- func ValuesPatchFromFile(filePath string) (*ValuesPatch, error)
- type ValuesPatchOperation
- type ValuesPatchType
Constants ¶
const ( NonExistentPathErrorMsg = "error in remove for path:" MissingPathErrorMsg = "remove operation does not apply: doc is missing path" )
Error messages to distinguish non-typed errors from the 'json-patch' library.
const (
GlobalValuesKey = "global"
)
Variables ¶
var ( ErrTestFailed = errors.New("test failed") ErrMissing = errors.New("missing value") ErrUnknownType = errors.New("unknown object type") ErrInvalid = errors.New("invalid state detected") ErrInvalidIndex = errors.New("invalid index referenced") )
var ( ModuleEnabled = true ModuleDisabled = false )
Functions ¶
func CalculateChecksumOfFile ¶
func FilesFromRoot ¶
func FilesFromRoot(root string, filterFn func(dir string, name string, info os.FileInfo) bool) (files map[string]map[string]string, err error)
FilesFromRoot returns a map with path and array of files under it
func FindExecutableFilesInPath ¶
func FindExecutableFilesInPath(dir string) (executables []string, nonExecutables []string, err error)
FindExecutableFilesInPath returns a list of executable and a list of non-executable files in path
func IsNonExistentPathError ¶
func JSONEqual ¶ added in v1.1.3
JSONEqual indicates if 2 JSON documents have the same structural equality.
func KeysSortedByReference ¶ added in v1.0.6
KeysSortedByReference returns keys from map sorted by the order of 'ref' array. Note: keys not in ref are ignored.
func ListFullyIn ¶
ListFullyIn returns whether all 'arr' items contains in `ref` array.
func ListIntersection ¶
ListIntersection returns an array with items that are present in all 'arrs' arrays.
func ListSubtract ¶
ListSubtract creates a new array from 'src' array with items that are not present in 'ignored' arrays.
func ListToMapStringStruct ¶ added in v1.0.6
func MapStringStructKeys ¶ added in v1.0.6
func MergeLabels ¶
MergeLabels merges several maps into one. Last map keys overrides keys from first maps.
Can be used to copy a map if just one argument is used.
func ModuleEnabledValue ¶
func ModuleNameFromValuesKey ¶
ModuleNameFromValuesKey returns kebab-cased name from camelCased (verySimpleModule become ver-simple-module)
func ModuleNameToValuesKey ¶
ModuleNameToValuesKey returns camelCased name from kebab-cased (very-simple-module become verySimpleModule)
func SortByReference ¶
SortByReference returns a new array with items sorted by the order of 'ref' array.
func SortReverse ¶
SortReverse creates a copy of 'in' array and sort it in a reverse order.
func SortReverseByReference ¶
SortReverseByReference returns a new array with items, reverse sorted by the order of 'ref' array.
func SymlinkInfo ¶
func ValidateHookValuesPatch ¶
func ValidateHookValuesPatch(valuesPatch ValuesPatch, permittedRootKey string) error
func WalkSymlinks ¶
func WalkSymlinks(target string, linkName string, files map[string]map[string]string, filterFn func(dir string, name string, info os.FileInfo) bool) (symlinkedDirectories map[string]string, err error)
WalkSymlinks walks a directory, updates files map and returns symlinked directories
Types ¶
type ApplyPatchMode ¶
type ApplyPatchMode string
const ( Strict ApplyPatchMode = "strict" IgnoreNonExistentPaths ApplyPatchMode = "ignore-non-existent-paths" )
type ModuleConfig ¶
type ModuleConfig struct { ModuleName string IsEnabled *bool // contains filtered or unexported fields }
func NewModuleConfig ¶
func NewModuleConfig(moduleName string, values Values) *ModuleConfig
func (*ModuleConfig) Checksum ¶
func (mc *ModuleConfig) Checksum() string
func (*ModuleConfig) FromYaml ¶
func (mc *ModuleConfig) FromYaml(yamlString []byte) (*ModuleConfig, error)
FromYaml loads module config from a yaml string.
Example:
simpleModule:
param1: 10 param2: 120
simpleModuleEnabled: true
func (*ModuleConfig) GetEnabled ¶
func (mc *ModuleConfig) GetEnabled() string
GetEnabled returns string description of enabled status.
func (*ModuleConfig) GetValues ¶ added in v1.3.0
func (mc *ModuleConfig) GetValues() Values
GetValues enrich module values with module's name top level key if key is already present - returns values as it module: test-module with values {"a": "b", "c": "d} will return:
testModule: a: b c: d TODO: since we have specified struct for module values, we don't need to encapsulate them into the map {"<moduleName>": ... } we have to change this behavior somewhere in the module-manager
func (*ModuleConfig) LoadFromValues ¶
func (mc *ModuleConfig) LoadFromValues(values Values) (*ModuleConfig, error)
LoadFromValues loads module config from a map.
Values for module in `values` map are addressed by a key. This key should be produced with ModuleNameToValuesKey.
func (*ModuleConfig) ModuleConfigKey ¶
func (mc *ModuleConfig) ModuleConfigKey() string
ModuleConfigKey transforms module kebab-case name to the config camelCase name
func (*ModuleConfig) ModuleEnabledKey ¶
func (mc *ModuleConfig) ModuleEnabledKey() string
ModuleEnabledKey transforms module kebab-case name to the config camelCase name with 'Enabled' suffix
func (*ModuleConfig) String ¶
func (mc *ModuleConfig) String() string
String returns description of ModuleConfig values.
type Operation ¶ added in v1.1.3
type Operation map[string]*json.RawMessage
Operation is a single JSON-Patch step, such as a single 'add' operation.
func (Operation) ValueInterface ¶ added in v1.1.3
ValueInterface decodes the operation value into an interface.
type Patch ¶ added in v1.1.3
type Patch []Operation
Patch is an ordered collection of Operations.
func DecodePatch ¶ added in v1.1.3
DecodePatch decodes the passed JSON document as an RFC 6902 patch.
func JsonPatchFromBytes ¶
func JsonPatchFromString ¶
type Values ¶
type Values map[string]interface{}
Values stores values for modules or hooks by name.
func ApplyValuesPatch ¶
func ApplyValuesPatch(values Values, valuesPatch ValuesPatch, mode ApplyPatchMode) (Values, bool, error)
ApplyValuesPatch uses patched jsonpatch library to make the behavior of ApplyIgnoreNonExistentPaths as fast as ApplyStrict.
func MergeValues ¶
func NewGlobalValues ¶
NewGlobalValues creates Values with global section loaded from input string.
func NewValues ¶
NewValues load all sections from input data and makes sure that input map can be marshaled to yaml and that yaml is compatible with json.
func NewValuesFromBytes ¶
NewValuesFromBytes loads values sections from maps in yaml or json format
func (Values) AsConfigMapData ¶
AsConfigMapData returns values as map that can be used as a 'data' field in the ConfigMap.
func (Values) DebugString ¶
DebugString returns values as yaml or an error line if dump is failed
func (Values) JsonString ¶
func (Values) SectionByKey ¶
func (Values) YamlString ¶
type ValuesPatch ¶
type ValuesPatch struct {
Operations []*ValuesPatchOperation
}
func AppendValuesPatch ¶
func AppendValuesPatch(valuesPatches []ValuesPatch, newValuesPatch ValuesPatch) []ValuesPatch
func CompactPatches ¶
func CompactPatches(existedOperations []*ValuesPatchOperation, newOperations []*ValuesPatchOperation) ValuesPatch
CompactPatches modifies an array of existed patch operations according to the new array of patch operations. The rule is: only last operation for the path should be stored.
func CompactValuesPatches ¶
func CompactValuesPatches(valuesPatches []ValuesPatch, newValuesPatch ValuesPatch) []ValuesPatch
func EnabledFromValuesPatch ¶
func EnabledFromValuesPatch(valuesPatch ValuesPatch) ValuesPatch
func FilterValuesPatch ¶
func FilterValuesPatch(valuesPatch ValuesPatch, rootPath string) ValuesPatch
func NewValuesPatch ¶
func NewValuesPatch() *ValuesPatch
func ValuesPatchFromBytes ¶
func ValuesPatchFromBytes(data []byte) (*ValuesPatch, error)
ValuesPatchFromBytes reads a JSON stream of json patches and single operations from bytes and returns a ValuesPatch with all json patch operations. TODO do we need a separate ValuesPatchOperation type??
func ValuesPatchFromFile ¶
func ValuesPatchFromFile(filePath string) (*ValuesPatch, error)
func (*ValuesPatch) ApplyIgnoreNonExistentPaths ¶
func (p *ValuesPatch) ApplyIgnoreNonExistentPaths(doc []byte) ([]byte, error)
ApplyIgnoreNonExistentPaths calls jsonpatch.Apply to transform an input JSON document.
- errors from "remove" operations are ignored.
func (*ValuesPatch) ApplyStrict ¶
func (p *ValuesPatch) ApplyStrict(doc []byte) ([]byte, error)
ApplyStrict calls jsonpatch.Apply to transform a JSON document according to the patch.
- "remove" operation errors are not ignored. - absent paths are not ignored.
func (*ValuesPatch) MergeOperations ¶
func (p *ValuesPatch) MergeOperations(src *ValuesPatch)
func (*ValuesPatch) ToJsonPatch ¶
func (p *ValuesPatch) ToJsonPatch() (Patch, error)
ToJsonPatch returns a jsonpatch.Patch with all operations.
type ValuesPatchOperation ¶
type ValuesPatchOperation struct { Op string `json:"op,omitempty"` Path string `json:"path,omitempty"` Value json.RawMessage `json:"value,omitempty"` }
func (*ValuesPatchOperation) ToJsonPatch ¶
func (op *ValuesPatchOperation) ToJsonPatch() (Patch, error)
ToJsonPatch returns a jsonpatch.Patch with one operation.
func (*ValuesPatchOperation) ToString ¶
func (op *ValuesPatchOperation) ToString() string
type ValuesPatchType ¶
type ValuesPatchType string
const ( ConfigMapPatch ValuesPatchType = "CONFIG_MAP_PATCH" MemoryValuesPatch ValuesPatchType = "MEMORY_VALUES_PATCH" )