Skip to content

Commit

Permalink
feat: export deep copy utils (#525)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly authored Sep 27, 2024
1 parent e1fdbfa commit 7bc2053
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pkg/apis/policy/v1alpha1/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/policy/v1alpha1/assertion_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 7bc2053

Please sign in to comment.