Skip to content

Commit

Permalink
Added code for fields with dots(.) in their names work as needed (#4591)
Browse files Browse the repository at this point in the history
* Added code for fields with dots(.) in their names work as needed

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Fixed imports

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Removed comments

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Fix filter method

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Fixed failing tests

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Remove comments

Add co-author to PR.

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Add co-author to PR.

Co-authored-by: sarjamil sjamil@salesforce.com

Co-authored-by: sarjamil <sjamil@salesforce.com>
  • Loading branch information
annelau21 and sarjamil committed May 2, 2022
1 parent 233b6ad commit 188e35f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/filters/fieldspec/fieldspec.go
Expand Up @@ -8,10 +8,10 @@ import (
"strings"

"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/utils"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand Down
5 changes: 3 additions & 2 deletions api/filters/replacement/replacement.go
Expand Up @@ -12,6 +12,7 @@ import (
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"
kyaml_utils "sigs.k8s.io/kustomize/kyaml/utils"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand Down Expand Up @@ -114,7 +115,7 @@ func rejectId(rejects []*types.Selector, id *resid.ResId) bool {

func applyToNode(node *yaml.RNode, value *yaml.RNode, target *types.TargetSelector) error {
for _, fp := range target.FieldPaths {
fieldPath := utils.SmarterPathSplitter(fp, ".")
fieldPath := kyaml_utils.SmarterPathSplitter(fp, ".")
var t *yaml.RNode
var err error
if target.Options != nil && target.Options.Create {
Expand Down Expand Up @@ -199,7 +200,7 @@ func getReplacement(nodes []*yaml.RNode, r *types.Replacement) (*yaml.RNode, err
if r.Source.FieldPath == "" {
r.Source.FieldPath = types.DefaultReplacementFieldPath
}
fieldPath := utils.SmarterPathSplitter(r.Source.FieldPath, ".")
fieldPath := kyaml_utils.SmarterPathSplitter(r.Source.FieldPath, ".")

rn, err := source.Pipe(yaml.Lookup(fieldPath...))
if err != nil {
Expand Down
File renamed without changes.
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
. "sigs.k8s.io/kustomize/api/internal/utils"
. "sigs.k8s.io/kustomize/kyaml/utils"
)

func TestPathSplitter(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion kyaml/yaml/rnode.go
Expand Up @@ -15,6 +15,7 @@ import (
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
"sigs.k8s.io/kustomize/kyaml/sliceutil"
"sigs.k8s.io/kustomize/kyaml/utils"
"sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/labels"
)

Expand Down Expand Up @@ -1207,7 +1208,7 @@ func (rn *RNode) GetString(path string) (string, error) {
// assuming we keep the var feature in kustomize.
// The other end of this is: refvar.go:updateNodeValue.
func (rn *RNode) GetFieldValue(path string) (interface{}, error) {
fields := convertSliceIndex(strings.Split(path, "."))
fields := convertSliceIndex(utils.SmarterPathSplitter(path, "."))
rn, err := rn.Pipe(Lookup(fields...))
if err != nil {
return nil, err
Expand Down
4 changes: 0 additions & 4 deletions kyaml/yaml/rnode_test.go
Expand Up @@ -2310,8 +2310,6 @@ func TestGetAnnotations(t *testing.T) {
}

func TestGetFieldValueWithDot(t *testing.T) {
t.Skip()

const input = `
kind: Pod
metadata:
Expand All @@ -2330,8 +2328,6 @@ metadata:
require.NoError(t, err)
require.Equal(t, "hello-world-app", app)

// TODO: doesn't currently work; we expect to be able to escape the dot in future
// https://github.com/kubernetes-sigs/kustomize/issues/4487
fooAppName, err := labelRNode.GetFieldValue(`foo\.appname`)
require.NoError(t, err)
require.Equal(t, "hello-world-foo", fooAppName) // no field named 'foo.appname'
Expand Down

0 comments on commit 188e35f

Please sign in to comment.