Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.24.3

require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/gdt-dev/core v1.10.3
github.com/gdt-dev/core v1.10.5
github.com/samber/lo v1.51.0
github.com/stretchr/testify v1.11.1
github.com/theory/jsonpath v0.10.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjT
github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM=
github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
github.com/gdt-dev/core v1.10.3 h1:4cl8h8/SeL5oBzDFyg7WhZbRcLRBb6SUY57L5Swju2A=
github.com/gdt-dev/core v1.10.3/go.mod h1:Bw8J6kUW0b7MUL8qW5e7qSbxb4SI9EAWQ0a4cAoPVpo=
github.com/gdt-dev/core v1.10.5 h1:plVO6WegOEuJTopnmTRQTIwyvHY2iG4xXDax2OP4fO8=
github.com/gdt-dev/core v1.10.5/go.mod h1:Bw8J6kUW0b7MUL8qW5e7qSbxb4SI9EAWQ0a4cAoPVpo=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
Expand Down
24 changes: 14 additions & 10 deletions var.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"

"github.com/gdt-dev/core/api"
gdtjson "github.com/gdt-dev/core/assertion/json"
"github.com/gdt-dev/core/debug"
"github.com/theory/jsonpath"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -38,7 +37,7 @@ func saveVars(
) error {
for varName, entry := range vars {
path := entry.From
extracted, err := extractFrom(path, out)
extracted, err := extractFrom(varName, path, out)
if err != nil {
return err
}
Expand All @@ -48,7 +47,11 @@ func saveVars(
return nil
}

func extractFrom(path string, out any) (any, error) {
func extractFrom(
varName string,
path string,
out any,
) (any, error) {
var normalized any
switch out := out.(type) {
case *unstructured.Unstructured:
Expand All @@ -66,15 +69,16 @@ func extractFrom(path string, out any) (any, error) {
default:
return nil, fmt.Errorf("unhandled extract type %T", out)
}
p, err := jsonpath.Parse(path)
if err != nil {
// Not terminal because during parse we validate the JSONPath
// expression is valid.
return nil, gdtjson.JSONPathNotFound(path, err)
}
// Ignore error because during parse we validate the JSONPath expression is
// valid.
p, _ := jsonpath.Parse(path)
nodes := p.Select(normalized)
if len(nodes) == 0 {
return nil, gdtjson.JSONPathNotFound(path, err)
// This IS terminal because it means that the returned results of the
// kube.get call did not match the expected JSONPath and that's a
// RuntimeError because we cannot continue execution if we don't match
// the JSONPath query.
return nil, api.JSONPathVarFromNotMatched(varName, path)
}
got := nodes[0]
return got, nil
Expand Down
Loading