From 77d777d5537e072368a4794a1abb92e24925b0dd Mon Sep 17 00:00:00 2001 From: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:41:00 +0530 Subject: [PATCH] Do not DeepCopy resources in constructors if the resources are already getting deep copied later on Signed-off-by: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com> --- pkg/kapp/diff/masked_resource.go | 2 +- pkg/kapp/diff/rebased_resource.go | 7 ------- pkg/kapp/diff/resource_with_removed_fields.go | 3 --- pkg/kapp/resources/resource_with_managed_fields.go | 3 --- 4 files changed, 1 insertion(+), 14 deletions(-) diff --git a/pkg/kapp/diff/masked_resource.go b/pkg/kapp/diff/masked_resource.go index 66415d16f..da06eaba2 100644 --- a/pkg/kapp/diff/masked_resource.go +++ b/pkg/kapp/diff/masked_resource.go @@ -21,7 +21,7 @@ func NewMaskedResource(res ctlres.Resource, rules []ctlconf.DiffMaskRule) Masked if res == nil { panic("Expected res be non-nil") } - return MaskedResource{res.DeepCopy(), rules} + return MaskedResource{res, rules} } func (r MaskedResource) Resource() (ctlres.Resource, error) { diff --git a/pkg/kapp/diff/rebased_resource.go b/pkg/kapp/diff/rebased_resource.go index 7833a68d8..1ad53d027 100644 --- a/pkg/kapp/diff/rebased_resource.go +++ b/pkg/kapp/diff/rebased_resource.go @@ -19,13 +19,6 @@ func NewRebasedResource(existingRes, newRes ctlres.Resource, mods []ctlres.Resou panic("Expected either existingRes or newRes be non-nil") } - if existingRes != nil { - existingRes = existingRes.DeepCopy() - } - if newRes != nil { - newRes = newRes.DeepCopy() - } - return RebasedResource{existingRes: existingRes, newRes: newRes, mods: mods} } diff --git a/pkg/kapp/diff/resource_with_removed_fields.go b/pkg/kapp/diff/resource_with_removed_fields.go index 4fef24b40..c40dd9fea 100644 --- a/pkg/kapp/diff/resource_with_removed_fields.go +++ b/pkg/kapp/diff/resource_with_removed_fields.go @@ -13,9 +13,6 @@ type ResourceWithRemovedFields struct { } func NewResourceWithRemovedFields(res ctlres.Resource, mods []ctlres.FieldRemoveMod) ResourceWithRemovedFields { - if res != nil { - res = res.DeepCopy() - } return ResourceWithRemovedFields{res: res, mods: mods} } diff --git a/pkg/kapp/resources/resource_with_managed_fields.go b/pkg/kapp/resources/resource_with_managed_fields.go index c37bd099a..2aefa458e 100644 --- a/pkg/kapp/resources/resource_with_managed_fields.go +++ b/pkg/kapp/resources/resource_with_managed_fields.go @@ -9,9 +9,6 @@ type ResourceWithManagedFields struct { } func NewResourceWithManagedFields(res Resource, managedFields bool) ResourceWithManagedFields { - if res != nil { - res = res.DeepCopy() - } return ResourceWithManagedFields{res: res, managedFields: managedFields} }