This commit is contained in:
Jeffrey Regan
2019-06-27 17:05:58 -07:00
parent dd0334536b
commit a60d99fdc9
4 changed files with 25 additions and 47 deletions

View File

@@ -23,7 +23,6 @@ import (
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/pkg/transformers"
"sigs.k8s.io/yaml"
)
@@ -66,7 +65,7 @@ func newPatchJson6902JSONTransformer(
// Transform apply the json patches on top of the base resources.
func (t *patchJson6902JSONTransformer) Transform(m resmap.ResMap) error {
obj, err := t.findTargetObj(m)
obj, err := m.GetById(t.target)
if err != nil {
return err
}
@@ -84,30 +83,3 @@ func (t *patchJson6902JSONTransformer) Transform(m resmap.ResMap) error {
}
return nil
}
func (t *patchJson6902JSONTransformer) findTargetObj(
m resmap.ResMap) (*resource.Resource, error) {
var matched []*resource.Resource
// TODO(monopole): namespace bug in json patch?
// Since introduction in PR #300
// (see pkg/patch/transformer/util.go),
// this code has treated an empty namespace like a wildcard
// rather than like an additional restriction to match
// only the empty namespace. No test coverage to confirm.
// Not sure if desired, keeping it for now.
if t.target.Namespace != "" {
matched = m.GetMatchingResourcesByOriginalId(t.target.Equals)
} else {
matched = m.GetMatchingResourcesByOriginalId(t.target.GvknEquals)
}
if len(matched) == 0 {
return nil, fmt.Errorf(
"couldn't find target %v for json patch", t.target)
}
if len(matched) > 1 {
return nil, fmt.Errorf(
"found multiple targets %v matching %v for json patch",
matched, t.target)
}
return matched[0], nil
}