Add UpdateFn for mutating ApplyOptions

Add an UpdateFn wrapper around ApplyOption that simplifies
the interface for passing a mutating function to
APIUpdatingApplicator.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
This commit is contained in:
hasheddan 2020-05-12 15:35:54 -05:00
parent 3420b651d6
commit a964b65a29
No known key found for this signature in database
GPG Key ID: BD68BC686A14C271
1 changed files with 9 additions and 0 deletions

View File

@ -273,6 +273,15 @@ func (fn ApplyFn) Apply(ctx context.Context, o runtime.Object, ao ...ApplyOption
// desired object. ApplyOptions are not called if no current object exists.
type ApplyOption func(ctx context.Context, current, desired runtime.Object) error
// UpdateFn returns an ApplyOption that is used to modify the current object to
// match fields of the desired.
func UpdateFn(fn func(current, desired runtime.Object)) ApplyOption {
return func(_ context.Context, c, d runtime.Object) error {
fn(c, d)
return nil
}
}
// MustBeControllableBy requires that the current object is controllable by an
// object with the supplied UID. An object is controllable if its controller
// reference matches the supplied UID, or it has no controller reference.