Skip to content

Commit

Permalink
refactor: introduce matching package in core (#502)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Sep 20, 2024
1 parent f0e8ec8 commit 7faca6c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/core/assertion/assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"github.com/jmespath-community/go-jmespath/pkg/binding"
"github.com/kyverno/kyverno-json/pkg/core/expression"
"github.com/kyverno/kyverno-json/pkg/core/matching"
"github.com/kyverno/kyverno-json/pkg/core/projection"
"github.com/kyverno/kyverno-json/pkg/core/templating"
"github.com/kyverno/kyverno-json/pkg/engine/match"
reflectutils "github.com/kyverno/kyverno-json/pkg/utils/reflect"
"k8s.io/apimachinery/pkg/util/validation/field"
)
Expand Down Expand Up @@ -206,7 +206,7 @@ func parseScalar(assertion any, compiler templating.Compiler) (node, error) {
expected = projected
}
var errs field.ErrorList
if match, err := match.Match(expected, value); err != nil {
if match, err := matching.Match(expected, value); err != nil {
return nil, field.InternalError(path, err)
} else if !match {
errs = append(errs, field.Invalid(path, value, expectValueMessage(expected)))
Expand Down
8 changes: 5 additions & 3 deletions pkg/utils/reflect/match.go → pkg/core/matching/equal.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package reflect
package matching

import (
"fmt"
"reflect"

reflectutils "github.com/kyverno/kyverno-json/pkg/utils/reflect"
)

func MatchScalar(expected, actual any) (bool, error) {
func Equal(expected, actual any) (bool, error) {
if actual == nil && expected == nil {
return true, nil
} else if actual == nil && expected != nil {
Expand Down Expand Up @@ -42,5 +44,5 @@ func MatchScalar(expected, actual any) (bool, error) {
return a == e, nil
}
}
return false, fmt.Errorf("types are not comparable, %s - %s", GetKind(expected), GetKind(actual))
return false, fmt.Errorf("types are not comparable, %s - %s", reflectutils.GetKind(expected), reflectutils.GetKind(actual))
}
4 changes: 2 additions & 2 deletions pkg/engine/match/match.go → pkg/core/matching/match.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package match
package matching

import (
"fmt"
Expand Down Expand Up @@ -44,5 +44,5 @@ func Match(expected, actual any) (bool, error) {
return true, nil
}
}
return reflectutils.MatchScalar(expected, actual)
return Equal(expected, actual)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reflect
package matching

import (
"reflect"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reflect
package matching

import (
"reflect"
Expand Down

0 comments on commit 7faca6c

Please sign in to comment.