Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
  • Loading branch information
sttts committed Sep 2, 2023
1 parent da20c8e commit bf9437f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/resource/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ func (a *APIPatchingApplicator) WithLogger(l logging.Logger) *APIPatchingApplica
// not exist, or patched if it does. If the object does exist, it will only be
// patched if the passed object has the same or an empty resource version.
func (a *APIPatchingApplicator) Apply(ctx context.Context, obj client.Object, ao ...ApplyOption) error { //nolint:gocyclo // the logic here is crucial and deserves to stay in one method
log := a.log.WithValues(logging.ForResource(obj))

if obj.GetName() == "" && obj.GetGenerateName() != "" {
log := a.log.WithValues(logging.ForResource(obj))
log.Info("creating object")
return a.client.Create(ctx, obj)
}
Expand Down Expand Up @@ -107,7 +108,9 @@ func (a *APIPatchingApplicator) Apply(ctx context.Context, obj client.Object, ao
if err != nil {
return errors.Wrapf(err, "failed to diff %s", HumanReadableReference(a.client, obj))
}
log := a.log.WithValues(logging.ForResource(obj))
if len(patchBytes) == 0 {
return nil
}
log.WithValues("diff", string(patchBytes)).Info("patching object")

return a.client.Patch(ctx, obj, client.RawPatch(patch.Type(), patchBytes))
Expand All @@ -132,7 +135,7 @@ func groupResource(c client.Client, o client.Object) (schema.GroupResource, erro
// This only works with a desired object of type *unstructured.Unstructured.
//
// Deprecated: replace with Server Side Apply.
func AdditiveMergePatchApplyOption(ctx context.Context, current, desired runtime.Object) error {
func AdditiveMergePatchApplyOption(_ context.Context, current, desired runtime.Object) error {
u, ok := desired.(*unstructured.Unstructured)
if !ok {
return errors.New("desired object is not an unstructured.Unstructured")
Expand Down Expand Up @@ -181,8 +184,9 @@ func (a *APIUpdatingApplicator) WithLogger(l logging.Logger) *APIUpdatingApplica
// Apply changes to the supplied object. The object will be created if it does
// not exist, or updated if it does.
func (a *APIUpdatingApplicator) Apply(ctx context.Context, obj client.Object, ao ...ApplyOption) error {
log := a.log.WithValues(logging.ForResource(obj))

if obj.GetName() == "" && obj.GetGenerateName() != "" {
log := a.log.WithValues(logging.ForResource(obj))
log.Info("creating object")
return a.client.Create(ctx, obj)
}
Expand All @@ -209,7 +213,9 @@ func (a *APIUpdatingApplicator) Apply(ctx context.Context, obj client.Object, ao
if err != nil {
return errors.Wrapf(err, "failed to diff %s", HumanReadableReference(a.client, obj))
}
log := a.log.WithValues(logging.ForResource(obj))
if len(patchBytes) == 0 {
return nil
}
log.WithValues("diff", string(patchBytes)).Info("updating object")

return a.client.Update(ctx, obj)
Expand Down

0 comments on commit bf9437f

Please sign in to comment.