Skip to content

Commit 52c74ee

Browse files
committed
use yamlpath with gopkg.in instead of goccy
Signed-off-by: Chris Randles <[email protected]>
1 parent 5589cbd commit 52c74ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2965
-14133
lines changed

go.mod

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ toolchain go1.23.4
66

77
require (
88
github.com/evanphx/json-patch v5.6.0+incompatible
9-
github.com/goccy/go-yaml v1.12.0
109
github.com/spf13/cobra v1.8.1
1110
github.com/stretchr/testify v1.9.0
11+
github.com/vmware-labs/yaml-jsonpath v0.3.2
1212
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
13+
gopkg.in/yaml.v3 v3.0.1
1314
k8s.io/apiextensions-apiserver v0.32.1
1415
k8s.io/apimachinery v0.32.1
1516
k8s.io/apiserver v0.32.1
@@ -30,8 +31,8 @@ require (
3031
github.com/coreos/go-semver v0.3.1 // indirect
3132
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
3233
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
34+
github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960 // indirect
3335
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
34-
github.com/fatih/color v1.10.0 // indirect
3536
github.com/felixge/httpsnoop v1.0.4 // indirect
3637
github.com/fsnotify/fsnotify v1.7.0 // indirect
3738
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
@@ -54,8 +55,6 @@ require (
5455
github.com/josharian/intern v1.0.0 // indirect
5556
github.com/json-iterator/go v1.1.12 // indirect
5657
github.com/mailru/easyjson v0.7.7 // indirect
57-
github.com/mattn/go-colorable v0.1.8 // indirect
58-
github.com/mattn/go-isatty v0.0.12 // indirect
5958
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6059
github.com/modern-go/reflect2 v1.0.2 // indirect
6160
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@@ -90,14 +89,12 @@ require (
9089
golang.org/x/term v0.25.0 // indirect
9190
golang.org/x/text v0.19.0 // indirect
9291
golang.org/x/time v0.7.0 // indirect
93-
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
9492
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
9593
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect
9694
google.golang.org/grpc v1.65.0 // indirect
9795
google.golang.org/protobuf v1.35.1 // indirect
9896
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
9997
gopkg.in/inf.v0 v0.9.1 // indirect
100-
gopkg.in/yaml.v3 v3.0.1 // indirect
10198
k8s.io/api v0.32.1 // indirect
10299
k8s.io/component-base v0.32.1 // indirect
103100
k8s.io/klog/v2 v2.130.1 // indirect

go.sum

+29-20
Large diffs are not rendered by default.

pkg/cmd/lint.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"slices"
88
"strings"
99

10-
"github.com/goccy/go-yaml"
11-
"github.com/goccy/go-yaml/parser"
10+
"github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath"
1211
"golang.org/x/exp/maps"
12+
yamlv3 "gopkg.in/yaml.v3"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414
)
1515

@@ -103,20 +103,25 @@ func (e lintError) String() string {
103103
}
104104

105105
func getPosition(field string, source []byte) (position, error) {
106-
path, err := yaml.PathString(fmt.Sprintf("$.%s", field))
106+
path, err := yamlpath.NewPath(fmt.Sprintf("$.%s", field))
107107
if err != nil {
108108
return position{}, err
109109
}
110-
file, err := parser.ParseBytes([]byte(source), 0)
110+
node := yamlv3.Node{}
111+
err = yamlv3.Unmarshal(source, &node)
111112
if err != nil {
112113
return position{}, err
113114
}
114-
node, err := path.FilterFile(file)
115+
116+
nodes, err := path.Find(&node)
115117
if err != nil {
116118
return position{}, err
117119
}
120+
if len(nodes) == 0 {
121+
return position{}, fmt.Errorf("no node found for field %q", field)
122+
}
118123
return position{
119-
Line: node.GetToken().Position.Line,
120-
Column: node.GetToken().Position.Column,
124+
Line: nodes[0].Line,
125+
Column: nodes[0].Column,
121126
}, nil
122127
}

pkg/cmd/lint_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestLintMarshal(t *testing.T) {
122122
}},
123123
},
124124
},
125-
expected: `../../testcases/manifests/error_x_list_map_duplicate_key.yaml:51:19: field "spec.containers[0].ports[2]": (reason: "FieldValueDuplicate"; Duplicate value: map[string]interface{}{"key":"value"})`,
125+
expected: `../../testcases/manifests/error_x_list_map_duplicate_key.yaml:51:11: field "spec.containers[0].ports[2]": (reason: "FieldValueDuplicate"; Duplicate value: map[string]interface{}{"key":"value"})`,
126126
},
127127
}
128128
for _, tc := range cases {

vendor/github.com/dprotaso/go-yit/.gitignore

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/goccy/go-yaml/LICENSE vendor/github.com/dprotaso/go-yit/LICENSE

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/dprotaso/go-yit/README.md

+54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/dprotaso/go-yit/aggregates.go

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)