From 8a9981faa40d79d8904add7839b3d2c4adbe12e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Fri, 27 Sep 2024 13:35:52 +0200 Subject: [PATCH] feat: export deep copy utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- pkg/apis/policy/v1alpha1/any.go | 3 ++- pkg/apis/policy/v1alpha1/assertion_tree.go | 3 ++- pkg/{apis/policy/v1alpha1 => utils/copy}/deep_copy.go | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) rename pkg/{apis/policy/v1alpha1 => utils/copy}/deep_copy.go (82%) diff --git a/pkg/apis/policy/v1alpha1/any.go b/pkg/apis/policy/v1alpha1/any.go index 221d7276..8629ddbb 100644 --- a/pkg/apis/policy/v1alpha1/any.go +++ b/pkg/apis/policy/v1alpha1/any.go @@ -3,6 +3,7 @@ package v1alpha1 import ( "github.com/kyverno/kyverno-json/pkg/core/compilers" "github.com/kyverno/kyverno-json/pkg/core/projection" + "github.com/kyverno/kyverno-json/pkg/utils/copy" "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/validation/field" ) @@ -40,7 +41,7 @@ func (a *Any) UnmarshalJSON(data []byte) error { } func (in *Any) DeepCopyInto(out *Any) { - out._value = deepCopy(in._value) + out._value = copy.DeepCopy(in._value) } func (in *Any) DeepCopy() *Any { diff --git a/pkg/apis/policy/v1alpha1/assertion_tree.go b/pkg/apis/policy/v1alpha1/assertion_tree.go index 2b005b69..2540e8e7 100644 --- a/pkg/apis/policy/v1alpha1/assertion_tree.go +++ b/pkg/apis/policy/v1alpha1/assertion_tree.go @@ -3,6 +3,7 @@ package v1alpha1 import ( "github.com/kyverno/kyverno-json/pkg/core/assertion" "github.com/kyverno/kyverno-json/pkg/core/compilers" + "github.com/kyverno/kyverno-json/pkg/utils/copy" "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/validation/field" ) @@ -40,7 +41,7 @@ func (a *AssertionTree) UnmarshalJSON(data []byte) error { } func (in *AssertionTree) DeepCopyInto(out *AssertionTree) { - out._tree = deepCopy(in._tree) + out._tree = copy.DeepCopy(in._tree) } func (in *AssertionTree) DeepCopy() *AssertionTree { diff --git a/pkg/apis/policy/v1alpha1/deep_copy.go b/pkg/utils/copy/deep_copy.go similarity index 82% rename from pkg/apis/policy/v1alpha1/deep_copy.go rename to pkg/utils/copy/deep_copy.go index 63837d6f..be56451a 100644 --- a/pkg/apis/policy/v1alpha1/deep_copy.go +++ b/pkg/utils/copy/deep_copy.go @@ -1,10 +1,10 @@ -package v1alpha1 +package copy import ( "fmt" ) -func deepCopy(in any) any { +func DeepCopy(in any) any { if in == nil { return nil } @@ -26,13 +26,13 @@ func deepCopy(in any) any { case []any: var out []any for _, in := range in { - out = append(out, deepCopy(in)) + out = append(out, DeepCopy(in)) } return out case map[string]any: out := map[string]any{} for k, in := range in { - out[k] = deepCopy(in) + out[k] = DeepCopy(in) } return out }