Skip to content

Commit

Permalink
refactor: move jp extensions in a top level package
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 committed Sep 19, 2024
1 parent 42154f1 commit ec12054
Show file tree
Hide file tree
Showing 22 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/commands/jp/function/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

jpfunctions "github.com/jmespath-community/go-jmespath/pkg/functions"
"github.com/kyverno/kyverno-json/pkg/command"
"github.com/kyverno/kyverno-json/pkg/engine/template"
"github.com/kyverno/kyverno-json/pkg/jp"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/util/sets"
)
Expand Down Expand Up @@ -59,7 +59,7 @@ func functionString(f jpfunctions.FunctionEntry) string {
}

func printFunctions(out io.Writer, names ...string) {
funcs := template.GetFunctions(context.Background())
funcs := jp.GetFunctions(context.Background())
slices.SortFunc(funcs, func(a, b jpfunctions.FunctionEntry) int {
return cmp.Compare(functionString(a), functionString(b))
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/engine/assert/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (

"github.com/jmespath-community/go-jmespath/pkg/binding"
"github.com/kyverno/kyverno-json/pkg/engine/template"
"github.com/kyverno/kyverno-json/pkg/jp"
"k8s.io/apimachinery/pkg/util/validation/field"
)

func NewContextBinding(path *field.Path, bindings binding.Bindings, value any, entry any, opts ...template.Option) binding.Binding {
return template.NewLazyBinding(
return jp.NewLazyBinding(

Check warning on line 13 in pkg/engine/assert/binding.go

View check run for this annotation

Codecov / codecov/patch

pkg/engine/assert/binding.go#L13

Added line #L13 was not covered by tests
func() (any, error) {
expression := parseExpression(context.TODO(), entry)
if expression != nil && expression.engine != "" {
Expand Down
3 changes: 2 additions & 1 deletion pkg/engine/template/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"

"github.com/jmespath-community/go-jmespath/pkg/interpreter"
"github.com/kyverno/kyverno-json/pkg/jp"
)

var (
funcs = GetFunctions(context.Background())
funcs = jp.GetFunctions(context.Background())
defaultCaller = interpreter.NewFunctionCaller(funcs...)
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/template/binding.go → pkg/jp/binding.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package template
package jp

import (
"sync"
Expand Down
6 changes: 3 additions & 3 deletions pkg/engine/template/functions.go → pkg/jp/functions.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package template
package jp

import (
"context"

jpfunctions "github.com/jmespath-community/go-jmespath/pkg/functions"
"github.com/kyverno/kyverno-json/pkg/engine/template/functions"
kyvernofunctions "github.com/kyverno/kyverno-json/pkg/engine/template/kyverno"
"github.com/kyverno/kyverno-json/pkg/jp/functions"
kyvernofunctions "github.com/kyverno/kyverno-json/pkg/jp/kyverno"
)

func GetFunctions(ctx context.Context) []jpfunctions.FunctionEntry {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions website/jp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"

jpfunctions "github.com/jmespath-community/go-jmespath/pkg/functions"
"github.com/kyverno/kyverno-json/pkg/engine/template/functions"
kyvernofunctions "github.com/kyverno/kyverno-json/pkg/engine/template/kyverno"
"github.com/kyverno/kyverno-json/pkg/jp/functions"
kyvernofunctions "github.com/kyverno/kyverno-json/pkg/jp/kyverno"
)

func main() {
Expand Down

0 comments on commit ec12054

Please sign in to comment.