strategicpatch

package
v1.10.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDeleteDirective added in v1.7.1

func CreateDeleteDirective(mergeKey string, mergeKeyValue interface{}) map[string]interface{}

func CreateThreeWayMergePatch

func CreateThreeWayMergePatch(original, modified, current []byte, schema LookupPatchMeta, overwrite bool, fns ...mergepatch.PreconditionFunc) ([]byte, error)

CreateThreeWayMergePatch reconciles a modified configuration with an original configuration, while preserving any changes or deletions made to the original configuration in the interim, and not overridden by the current configuration. All three documents must be passed to the method as json encoded content. It will return a strategic merge patch, or an error if any of the documents is invalid, or if there are any preconditions that fail against the modified configuration, or, if overwrite is false and there are conflicts between the modified and current configurations. Conflicts are defined as keys changed differently from original to modified than from original to current. In other words, a conflict occurs if modified changes any key in a way that is different from how it is changed in current (e.g., deleting it, changing its value). We also propagate values fields that do not exist in original but are explicitly defined in modified.

func CreateTwoWayMergePatch

func CreateTwoWayMergePatch(original, modified []byte, dataStruct interface{}, fns ...mergepatch.PreconditionFunc) ([]byte, error)

CreateTwoWayMergePatch creates a patch that can be passed to StrategicMergePatch from an original document and a modified document, which are passed to the method as json encoded content. It will return a patch that yields the modified document when applied to the original document, or an error if either of the two documents is invalid.

func CreateTwoWayMergePatchUsingLookupPatchMeta added in v1.9.1

func CreateTwoWayMergePatchUsingLookupPatchMeta(
	original, modified []byte, schema LookupPatchMeta, fns ...mergepatch.PreconditionFunc) ([]byte, error)

func GetTagStructTypeOrDie added in v1.9.1

func GetTagStructTypeOrDie(dataStruct interface{}) reflect.Type

func ItemAddedToModifiedSlice added in v1.7.1

func ItemAddedToModifiedSlice(original, modified string) bool

func ItemMatchesOriginalAndModifiedSlice added in v1.7.1

func ItemMatchesOriginalAndModifiedSlice(original, modified string) bool

func ItemRemovedFromModifiedSlice added in v1.7.1

func ItemRemovedFromModifiedSlice(original, modified string) bool

func MergingMapsHaveConflicts

func MergingMapsHaveConflicts(left, right map[string]interface{}, schema LookupPatchMeta) (bool, error)

MergingMapsHaveConflicts returns true if the left and right JSON interface objects overlap with different values in any key. All keys are required to be strings. Since patches of the same Type have congruent keys, this is valid for multiple patch types. This method supports strategic merge patch semantics.

func NewKindItem added in v1.9.1

func NewKindItem(key string, path *openapi.Path) *kindItem

func NewSliceItem added in v1.9.1

func NewSliceItem(key string, path *openapi.Path) *sliceItem

func StrategicMergePatch

func StrategicMergePatch(original, patch []byte, dataStruct interface{}) ([]byte, error)

StrategicMergePatch applies a strategic merge patch. The patch and the original document must be json encoded content. A patch can be created from an original and a modified document by calling CreateStrategicMergePatch.

func StrategicMergePatchUsingLookupPatchMeta added in v1.9.1

func StrategicMergePatchUsingLookupPatchMeta(original, patch []byte, schema LookupPatchMeta) ([]byte, error)

Types

type DiffOptions added in v1.7.1

type DiffOptions struct {
	// SetElementOrder determines whether we generate the $setElementOrder parallel list.
	SetElementOrder bool
	// IgnoreChangesAndAdditions indicates if we keep the changes and additions in the patch.
	IgnoreChangesAndAdditions bool
	// IgnoreDeletions indicates if we keep the deletions in the patch.
	IgnoreDeletions bool
	// We introduce a new value retainKeys for patchStrategy.
	// It indicates that all fields needing to be preserved must be
	// present in the `retainKeys` list.
	// And the fields that are present will be merged with live object.
	// All the missing fields will be cleared when patching.
	BuildRetainKeysDirective bool
}

type FieldNotFoundError added in v1.9.1

type FieldNotFoundError struct {
	Path  string
	Field string
}

func (FieldNotFoundError) Error added in v1.9.1

func (e FieldNotFoundError) Error() string

type InvalidTypeError added in v1.9.1

type InvalidTypeError struct {
	Path     string
	Expected string
	Actual   string
}

func (InvalidTypeError) Error added in v1.9.1

func (e InvalidTypeError) Error() string

type JSONMap

type JSONMap map[string]interface{}

JSONMap is a representations of JSON object encoded as map[string]interface{} where the children can be either map[string]interface{}, []interface{} or primitive type). Operating on JSONMap representation is much faster as it doesn't require any json marshaling and/or unmarshaling operations.

func CreateTwoWayMergeMapPatch

func CreateTwoWayMergeMapPatch(original, modified JSONMap, dataStruct interface{}, fns ...mergepatch.PreconditionFunc) (JSONMap, error)

CreateTwoWayMergeMapPatch creates a patch from an original and modified JSON objects, encoded JSONMap. The serialized version of the map can then be passed to StrategicMergeMapPatch.

func CreateTwoWayMergeMapPatchUsingLookupPatchMeta added in v1.9.1

func CreateTwoWayMergeMapPatchUsingLookupPatchMeta(original, modified JSONMap, schema LookupPatchMeta, fns ...mergepatch.PreconditionFunc) (JSONMap, error)

func StrategicMergeMapPatch

func StrategicMergeMapPatch(original, patch JSONMap, dataStruct interface{}) (JSONMap, error)

StrategicMergeMapPatch applies a strategic merge patch. The original and patch documents must be JSONMap. A patch can be created from an original and modified document by calling CreateTwoWayMergeMapPatch. Warning: the original and patch JSONMap objects are mutated by this function and should not be reused.

func StrategicMergeMapPatchUsingLookupPatchMeta added in v1.9.1

func StrategicMergeMapPatchUsingLookupPatchMeta(original, patch JSONMap, schema LookupPatchMeta) (JSONMap, error)

type LookupPatchItem added in v1.9.1

type LookupPatchItem interface {
	openapi.SchemaVisitor

	Error() error
	Path() *openapi.Path
}

type LookupPatchMeta added in v1.9.1

type LookupPatchMeta interface {
	// LookupPatchMetadataForStruct gets subschema and the patch metadata (e.g. patch strategy and merge key) for map.
	LookupPatchMetadataForStruct(key string) (LookupPatchMeta, PatchMeta, error)
	// LookupPatchMetadataForSlice get subschema and the patch metadata for slice.
	LookupPatchMetadataForSlice(key string) (LookupPatchMeta, PatchMeta, error)
	// Get the type name of the field
	Name() string
}

type LookupPatchMetaError added in v1.9.1

type LookupPatchMetaError struct {
	Path string
	Err  error
}

func (LookupPatchMetaError) Error added in v1.9.1

func (e LookupPatchMetaError) Error() string

type MergeOptions added in v1.7.1

type MergeOptions struct {
	// MergeParallelList indicates if we are merging the parallel list.
	// We don't merge parallel list when calling mergeMap() in CreateThreeWayMergePatch()
	// which is called client-side.
	// We merge parallel list iff when calling mergeMap() in StrategicMergeMapPatch()
	// which is called server-side
	MergeParallelList bool
	// IgnoreUnmatchedNulls indicates if we should process the unmatched nulls.
	IgnoreUnmatchedNulls bool
}

type PatchMeta added in v1.9.1

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

func (PatchMeta) GetPatchMergeKey added in v1.9.1

func (pm PatchMeta) GetPatchMergeKey() string

func (PatchMeta) GetPatchStrategies added in v1.9.1

func (pm PatchMeta) GetPatchStrategies() []string

func (PatchMeta) SetPatchMergeKey added in v1.9.1

func (pm PatchMeta) SetPatchMergeKey(pmk string)

func (PatchMeta) SetPatchStrategies added in v1.9.1

func (pm PatchMeta) SetPatchStrategies(ps []string)

type PatchMetaFromOpenAPI added in v1.9.1

type PatchMetaFromOpenAPI struct {
	Schema openapi.Schema
}

func NewPatchMetaFromOpenAPI added in v1.9.1

func NewPatchMetaFromOpenAPI(s openapi.Schema) PatchMetaFromOpenAPI

func (PatchMetaFromOpenAPI) LookupPatchMetadataForSlice added in v1.9.1

func (s PatchMetaFromOpenAPI) LookupPatchMetadataForSlice(key string) (LookupPatchMeta, PatchMeta, error)

func (PatchMetaFromOpenAPI) LookupPatchMetadataForStruct added in v1.9.1

func (s PatchMetaFromOpenAPI) LookupPatchMetadataForStruct(key string) (LookupPatchMeta, PatchMeta, error)

func (PatchMetaFromOpenAPI) Name added in v1.9.1

func (s PatchMetaFromOpenAPI) Name() string

type PatchMetaFromStruct added in v1.9.1

type PatchMetaFromStruct struct {
	T reflect.Type
}

func NewPatchMetaFromStruct added in v1.9.1

func NewPatchMetaFromStruct(dataStruct interface{}) (PatchMetaFromStruct, error)

func (PatchMetaFromStruct) LookupPatchMetadataForSlice added in v1.9.1

func (s PatchMetaFromStruct) LookupPatchMetadataForSlice(key string) (LookupPatchMeta, PatchMeta, error)

func (PatchMetaFromStruct) LookupPatchMetadataForStruct added in v1.9.1

func (s PatchMetaFromStruct) LookupPatchMetadataForStruct(key string) (LookupPatchMeta, PatchMeta, error)

func (PatchMetaFromStruct) Name added in v1.9.1

func (s PatchMetaFromStruct) Name() string

type SortableSliceOfMaps

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

func (SortableSliceOfMaps) Len

func (ss SortableSliceOfMaps) Len() int

func (SortableSliceOfMaps) Less

func (ss SortableSliceOfMaps) Less(i, j int) bool

func (SortableSliceOfMaps) Swap

func (ss SortableSliceOfMaps) Swap(i, j int)

type SortableSliceOfScalars

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

func (SortableSliceOfScalars) Len

func (ss SortableSliceOfScalars) Len() int

func (SortableSliceOfScalars) Less

func (ss SortableSliceOfScalars) Less(i, j int) bool

func (SortableSliceOfScalars) Swap

func (ss SortableSliceOfScalars) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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