Skip to content

Commit

Permalink
Added code for fields with dots(.) in their names work as needed
Browse files Browse the repository at this point in the history
Co-authored-by: sarjamil <sjamil@salesforce.com>
  • Loading branch information
annelau21 and sarjamil committed Apr 19, 2022
1 parent 9d5491c commit 12f06d1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api/filters/fieldspec/fieldspec.go
Expand Up @@ -5,10 +5,10 @@ package fieldspec

import (
"fmt"
"sigs.k8s.io/kustomize/kyaml/pathsplitterutil"
"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"
Expand Down Expand Up @@ -49,7 +49,7 @@ func (fltr Filter) Filter(obj *yaml.RNode) (*yaml.RNode, error) {
if match := isMatchGVK(fltr.FieldSpec, obj); !match {
return obj, nil
}
fltr.path = utils.PathSplitter(fltr.FieldSpec.Path, "/")
fltr.path = pathsplitterutil.PathSplitter(fltr.FieldSpec.Path, "/")
if err := fltr.filter(obj); err != nil {
return nil, errors.WrapPrefixf(err,
"considering field '%s' of object %s", fltr.FieldSpec.Path, resid.FromRNode(obj))
Expand Down
5 changes: 3 additions & 2 deletions api/filters/replacement/replacement.go
Expand Up @@ -6,6 +6,7 @@ package replacement
import (
"errors"
"fmt"
"sigs.k8s.io/kustomize/kyaml/pathsplitterutil"
"strings"

"sigs.k8s.io/kustomize/api/internal/utils"
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 := pathsplitterutil.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 := pathsplitterutil.SmarterPathSplitter(r.Source.FieldPath, ".")

rn, err := source.Pipe(yaml.Lookup(fieldPath...))
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions api/internal/builtins/AnnotationsTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,7 +1,7 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

package utils
package pathsplitterutil

import "strings"

Expand Down
@@ -1,13 +1,13 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

package utils_test
package pathsplitterutil_test

import (
. "sigs.k8s.io/kustomize/kyaml/pathsplitterutil"
"testing"

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

func TestPathSplitter(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion kyaml/yaml/rnode.go
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"log"
"regexp"
"sigs.k8s.io/kustomize/kyaml/pathsplitterutil"
"strconv"
"strings"

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 := pathsplitterutil.SmarterPathSplitter(path, ".")
rn, err := rn.Pipe(Lookup(fields...))
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion kyaml/yaml/rnode_test.go
Expand Up @@ -2310,7 +2310,7 @@ func TestGetAnnotations(t *testing.T) {
}

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

const input = `
kind: Pod
Expand Down

0 comments on commit 12f06d1

Please sign in to comment.