Skip to content

Commit

Permalink
Unmarshal FollowUp (#508)
Browse files Browse the repository at this point in the history
* small follow-up

* add cheangelog
  • Loading branch information
sam-heilbron authored Jul 15, 2022
1 parent 889e87f commit b9fdea5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ verify-envoy-protos:
.PHONY: test
test:
ifneq ($(RELEASE), "true")
PATH=$(DEPSGOBIN):$$PATH ginkgo -r -v -race -tags solokit -compilers=2 -skip multicluster -regexScansFilePath $(TEST_PKG)
PATH=$(DEPSGOBIN):$$PATH ginkgo -r -v -race -p -tags solokit -compilers=2 -skip multicluster -regexScansFilePath $(TEST_PKG)
endif

#----------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions changelog/v0.20.11/kube-client-improvements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
changelog:
- type: NON_USER_FACING
description: |
Ensure that UnmarshalResource performs a strict unmarshal and does not allow unknown fields.
This method is used by the validation webhook in Gloo Edge.
7 changes: 3 additions & 4 deletions pkg/utils/protoutils/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"bytes"
"encoding/json"

"github.com/solo-io/solo-kit/pkg/utils/specutils"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
structpb "github.com/golang/protobuf/ptypes/struct"
Expand Down Expand Up @@ -183,7 +181,8 @@ func MapStringInterfaceToMapStringString(interfaceMap map[string]interface{}) (m
return stringMap, nil
}

// convert raw Kube JSON to a Solo-Kit resource
// UnmarshalResource convert raw Kube JSON to a Solo-Kit resource
// Returns an error if unknown fields are present in the raw json
func UnmarshalResource(kubeJson []byte, resource resources.Resource) error {
var resourceCrd v1.Resource
if err := json.Unmarshal(kubeJson, &resourceCrd); err != nil {
Expand Down Expand Up @@ -211,7 +210,7 @@ func UnmarshalResource(kubeJson []byte, resource resources.Resource) error {
}

if resourceCrd.Spec != nil {
if err := specutils.UnmarshalSpecMapToResource(*resourceCrd.Spec, resource); err != nil {
if err := UnmarshalMap(*resourceCrd.Spec, resource); err != nil {
return errors.Wrapf(err, "parsing resource from crd spec %v in namespace %v into %T", resourceCrd.Name, resourceCrd.Namespace, resource)
}
}
Expand Down

0 comments on commit b9fdea5

Please sign in to comment.