Skip to content

Commit

Permalink
Seal dies to enable diff and patch operations (#142)
Browse files Browse the repository at this point in the history
DieSeal stashes the current value of the die for later use in DieDiff
and DiePatch operations. DieDiff use cmp.Diff to generate a textual diff
of changes made to the die since it was seeled. DiePatch generates patch
bytes to go from the sealed to current value.

Note: diff and patch operations are only meaningful from the root die.
Dies used while stamping do not contain the original sealed value.

Individual patch implementation must be dynamically registered before
use. For the known patch types, this can be done by importing the
respective package. A meaningful error is provided if the type is not
imported. Users may implement additional or alternative patch types.

Signed-off-by: Scott Andrews <scott@andrews.me>
  • Loading branch information
scothis authored Jun 19, 2024
1 parent b4c0177 commit 04fcf15
Show file tree
Hide file tree
Showing 44 changed files with 19,572 additions and 447 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ type MyResourceDie interface {
// function. The passed die is mutable.
DieWith(fn ...func(d *MyResourceDie)) *MyResourceDie

// DieSeal returns a new die for the current die's state that is sealed for comparison in future diff and patch operations.
DieSeal() *MyResourceDie

// DieSealFeed returns a new die for the current die's state that uses a specific resource for comparison in future diff and patch operations.
DieSealFeed(r MyResource) *MyResourceDie

// DieSealFeedPtr returns a new die for the current die's state that uses a specific resource for comparison in future diff and patch operations.
DieSealFeedPtr(r *MyResource) *MyResourceDie

// DieSealRelease returns the sealed resource managed by the die.
DieSealRelease() MyResource

// DieSealReleasePtr returns the sealed resource pointer managed by the die.
DieSealReleasePtr() *MyResource

// DieDiff uses cmp.Diff to compare the current value of the die with the sealed value.
DieDiff(opts ...cmp.Option) string

// DiePatch generates a patch between the current value of the die and the sealed value.
DiePatch(patchType types.PatchType) ([]byte, error)

// DeepCopy returns a new die with equivalent state. Useful for
// snapshotting a mutable die.
DeepCopy() *MyResourceDie
Expand Down
142 changes: 141 additions & 1 deletion apis/admission/v1/zz_generated.die.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 04fcf15

Please sign in to comment.