Skip to content

Commit 7301d90

Browse files
committed
Address comments
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
1 parent da20c8e commit 7301d90

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pkg/resource/api.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ func (a *APIPatchingApplicator) WithLogger(l logging.Logger) *APIPatchingApplica
6767
// not exist, or patched if it does. If the object does exist, it will only be
6868
// patched if the passed object has the same or an empty resource version.
6969
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
70+
log := a.log.WithValues(logging.ForResource(obj))
71+
7072
if obj.GetName() == "" && obj.GetGenerateName() != "" {
71-
log := a.log.WithValues(logging.ForResource(obj))
7273
log.Info("creating object")
7374
return a.client.Create(ctx, obj)
7475
}
@@ -107,7 +108,6 @@ func (a *APIPatchingApplicator) Apply(ctx context.Context, obj client.Object, ao
107108
if err != nil {
108109
return errors.Wrapf(err, "failed to diff %s", HumanReadableReference(a.client, obj))
109110
}
110-
log := a.log.WithValues(logging.ForResource(obj))
111111
log.WithValues("diff", string(patchBytes)).Info("patching object")
112112

113113
return a.client.Patch(ctx, obj, client.RawPatch(patch.Type(), patchBytes))
@@ -132,7 +132,7 @@ func groupResource(c client.Client, o client.Object) (schema.GroupResource, erro
132132
// This only works with a desired object of type *unstructured.Unstructured.
133133
//
134134
// Deprecated: replace with Server Side Apply.
135-
func AdditiveMergePatchApplyOption(ctx context.Context, current, desired runtime.Object) error {
135+
func AdditiveMergePatchApplyOption(_ context.Context, current, desired runtime.Object) error {
136136
u, ok := desired.(*unstructured.Unstructured)
137137
if !ok {
138138
return errors.New("desired object is not an unstructured.Unstructured")
@@ -181,8 +181,9 @@ func (a *APIUpdatingApplicator) WithLogger(l logging.Logger) *APIUpdatingApplica
181181
// Apply changes to the supplied object. The object will be created if it does
182182
// not exist, or updated if it does.
183183
func (a *APIUpdatingApplicator) Apply(ctx context.Context, obj client.Object, ao ...ApplyOption) error {
184+
log := a.log.WithValues(logging.ForResource(obj))
185+
184186
if obj.GetName() == "" && obj.GetGenerateName() != "" {
185-
log := a.log.WithValues(logging.ForResource(obj))
186187
log.Info("creating object")
187188
return a.client.Create(ctx, obj)
188189
}
@@ -209,7 +210,9 @@ func (a *APIUpdatingApplicator) Apply(ctx context.Context, obj client.Object, ao
209210
if err != nil {
210211
return errors.Wrapf(err, "failed to diff %s", HumanReadableReference(a.client, obj))
211212
}
212-
log := a.log.WithValues(logging.ForResource(obj))
213+
if len(patchBytes) == 0 {
214+
return nil
215+
}
213216
log.WithValues("diff", string(patchBytes)).Info("updating object")
214217

215218
return a.client.Update(ctx, obj)

0 commit comments

Comments
 (0)