Skip to content

Commit cc43a2d

Browse files
authored
Merge pull request #3342 from Shell32-Natsu/wnode-slice
fix wnode get slice issue
2 parents 4011187 + d25e1ef commit cc43a2d

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

api/internal/wrappy/wnode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ func (wn *WNode) GetFieldValue(path string) (interface{}, error) {
9191
// Return value as slice for SequenceNode kind
9292
if yn.Kind == yaml.SequenceNode {
9393
var result []interface{}
94-
for _, node := range yn.Content {
95-
result = append(result, node.Value)
94+
if err := yn.Decode(&result); err != nil {
95+
return nil, err
9696
}
9797
return result, nil
9898
}

api/internal/wrappy/wnode_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,39 @@ func TestGetFieldValueReturnsSlice(t *testing.T) {
377377
}
378378
}
379379

380+
func TestGetFieldValueReturnsSliceOfMappings(t *testing.T) {
381+
bytes, err := yaml.Marshal(makeBigMap())
382+
if err != nil {
383+
t.Fatalf("unexpected yaml.Marshal err: %v", err)
384+
}
385+
rNode, err := kyaml.Parse(string(bytes))
386+
if err != nil {
387+
t.Fatalf("unexpected yaml.Marshal err: %v", err)
388+
}
389+
wn := FromRNode(rNode)
390+
expected := []interface{}{
391+
map[string]interface{}{
392+
"field1": "idx0foo",
393+
"field2": "idx0bar",
394+
},
395+
map[string]interface{}{
396+
"field1": "idx1foo",
397+
"field2": "idx1bar",
398+
},
399+
map[string]interface{}{
400+
"field1": "idx2foo",
401+
"field2": "idx2bar",
402+
},
403+
}
404+
actual, err := wn.GetFieldValue("those")
405+
if err != nil {
406+
t.Fatalf("error getting slice: %v", err)
407+
}
408+
if diff := cmp.Diff(expected, actual); diff != "" {
409+
t.Fatalf("actual slice does not deep equal expected slice:\n%v", diff)
410+
}
411+
}
412+
380413
func TestGetFieldValueReturnsString(t *testing.T) {
381414
wn := NewWNode()
382415
if err := wn.UnmarshalJSON([]byte(deploymentBiggerJson)); err != nil {

kustomize/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ exclude (
1919
sigs.k8s.io/kustomize/api v0.2.0
2020
sigs.k8s.io/kustomize/cmd/config v0.2.0
2121
)
22+
23+
replace sigs.k8s.io/kustomize/api v0.7.0 => ../api

kustomize/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,6 @@ k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl
623623
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
624624
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
625625
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
626-
sigs.k8s.io/kustomize/api v0.7.0 h1:djxH9k1izeU1BvdP1i23qqKwhmWu2BuKNEKr/Da7Dpw=
627-
sigs.k8s.io/kustomize/api v0.7.0/go.mod h1:3TxKEyaxwOIfHmRbQF14hDUSRmVQI0iSn8qDA5zaO/0=
628626
sigs.k8s.io/kustomize/cmd/config v0.8.6 h1:Rr7eyD+h32OfruN6V+cgUqHRpC2Y5ZnjjAPbjhKFLGE=
629627
sigs.k8s.io/kustomize/cmd/config v0.8.6/go.mod h1:e4PgdLUNnkf+Iapvjyb6gTG9DZQkDZIR6uS1Bv4YA6s=
630628
sigs.k8s.io/kustomize/kyaml v0.10.3 h1:ARSJUMN/c3k31DYxRfZ+vp/UepUQjg9zCwny7Oj908I=

0 commit comments

Comments
 (0)