conversion

package
v0.11.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertAndRestore

func ConvertAndRestore[S pointerToObject[SO], SO any, D metav1.Object](src S, dst D, convert func(S, D, conversion.Scope) error, unconvert func(D, S, conversion.Scope) error, srcRestorer RestorerFor[S], dstRestorer RestorerFor[D]) error

ConvertAndRestore converts src to dst. During conversion is reads and uses any restore data in the src annotation, and writes new restore data to the dst annotation.

func HashedFilterField added in v0.10.0

func HashedFilterField[T, F any](f func(*F) *F) func(*hashedFieldRestorer[T, F])

HashedFilterField adds a field filter to a HashedFieldRestorer. The field filter returns a modified copy of the field to be used for comparison. This can be used to ignore certain changes during comparison.

Types

type FieldRestorerFor added in v0.10.0

type FieldRestorerFor[T any] interface {
	// contains filtered or unexported methods
}

func HashedFieldRestorer

func HashedFieldRestorer[T, F any](getField func(T) *F, restoreField func(*F, *F), opts ...HashedFieldRestorerOpt[T, F]) FieldRestorerFor[T]

HashedFieldRestorer restores a field to its original pre-conversion state only if it was not modified while converted. It does this by doing a full round-trip conversion before saving its state, and storing the hash of an unmodified round-trip converted object.

HashedFieldRestorer takes 2 type arguments:

T: The type of the object being converted. This is a pointer type.
F: The type of the field in T which is being restored. This is not a
   pointer type.

The type arguments can usually be omitted, as they can be inferred from the arguments.

HashedFieldRestorer takes 2 arguments:

getField: A function which takes the object being converted (of type T) and returns a pointer to the field being restored (of type *F).
restoreField: Described below.

restoreField is used to restore parts of the field to their original pre-conversion state which were not restored by the normal conversion functions. This is to preserve idempotency when the normal conversion functions are lossy, so it is only called if the field was not modified during conversion.

restoreField takes 2 arguments:

previous: A pointer to the saved original state of the field before conversion.
dst: A pointer to the field which needs to be updated.

The normal conversion functions should do as much work as possible, so restoreField should only be used to restore state which cannot be restored any other way.

func UnconditionalFieldRestorer

func UnconditionalFieldRestorer[T, F any](getField func(T) *F) FieldRestorerFor[T]

UnconditionalFieldRestorer restores a field to its previous value without checking to see if it was modified during conversion.

type HashedFieldRestorerOpt added in v0.10.0

type HashedFieldRestorerOpt[T, F any] func(*hashedFieldRestorer[T, F])

HashedFieldRestorerOpt is a modifier which adds optional behaviour to a HashedFieldRestorer. It can be passed as an argument to HashedFieldRestorer().

type RestorerFor

type RestorerFor[T metav1.Object] map[string]FieldRestorerFor[T]

RestorerFor holds all field restorers for a given type T.

Jump to

Keyboard shortcuts

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